root/tests/lib/vfs/vfs_split.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. setup
  2. teardown
  3. START_PARAMETRIZED_TEST
  4. main

   1 /*
   2    lib/vfs - test vfs_split() functionality
   3 
   4    Copyright (C) 2011-2025
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Slava Zanko <slavazanko@gmail.com>, 2011, 2013
   9 
  10    This file is part of the Midnight Commander.
  11 
  12    The Midnight Commander is free software: you can redistribute it
  13    and/or modify it under the terms of the GNU General Public License as
  14    published by the Free Software Foundation, either version 3 of the License,
  15    or (at your option) any later version.
  16 
  17    The Midnight Commander is distributed in the hope that it will be useful,
  18    but WITHOUT ANY WARRANTY; without even the implied warranty of
  19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20    GNU General Public License for more details.
  21 
  22    You should have received a copy of the GNU General Public License
  23    along with this program.  If not, see <https://www.gnu.org/licenses/>.
  24  */
  25 
  26 #define TEST_SUITE_NAME "/lib/vfs"
  27 
  28 #include "tests/mctest.h"
  29 
  30 #include "lib/strutil.h"
  31 #include "lib/vfs/xdirentry.h"
  32 #include "lib/vfs/path.c"  // for testing static methods
  33 
  34 #include "src/vfs/local/local.c"
  35 
  36 static struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3;
  37 
  38 /* --------------------------------------------------------------------------------------------- */
  39 
  40 /* @Before */
  41 static void
  42 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  43 {
  44     str_init_strings (NULL);
  45 
  46     vfs_init ();
  47     vfs_init_localfs ();
  48     vfs_setup_work_dir ();
  49 
  50     vfs_init_class (&vfs_test_ops1, "testfs1", VFSF_NOLINKS | VFSF_REMOTE, "test1");
  51     vfs_register_class (&vfs_test_ops1);
  52 
  53     vfs_init_class (&vfs_test_ops2, "testfs2", VFSF_UNKNOWN, "test2");
  54     vfs_register_class (&vfs_test_ops2);
  55 
  56     vfs_init_class (&vfs_test_ops3, "testfs3", VFSF_UNKNOWN, "test3");
  57     vfs_register_class (&vfs_test_ops3);
  58 }
  59 
  60 /* --------------------------------------------------------------------------------------------- */
  61 
  62 /* @After */
  63 static void
  64 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  65 {
  66     vfs_shut ();
  67     str_uninit_strings ();
  68 }
  69 
  70 /* --------------------------------------------------------------------------------------------- */
  71 
  72 /* @DataSource("test_vfs_split_ds") */
  73 static const struct test_vfs_split_ds
  74 {
  75     const char *input_string;
  76     const char *expected_path;
  77     const char *expected_local;
  78     const char *expected_op;
  79     const struct vfs_class *expected_result;
  80 } test_vfs_split_ds[] = {
  81     {
  82         // 0.
  83         "#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2/#test3:/qqq/www/eee.rr",
  84         "#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2/",
  85         "qqq/www/eee.rr",
  86         "test3:",
  87         &vfs_test_ops3,
  88     },
  89     {
  90         // 1.
  91         "#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2/",
  92         "#test1:/bla-bla/some/path/",
  93         "bla-bla/some/path2/",
  94         "test2:",
  95         &vfs_test_ops2,
  96     },
  97     {
  98         // 2.
  99         "#test1:/bla-bla/some/path/",
 100         "",
 101         "bla-bla/some/path/",
 102         "test1:",
 103         &vfs_test_ops1,
 104     },
 105     {
 106         // 3.
 107         "",
 108         "",
 109         NULL,
 110         NULL,
 111         NULL,
 112     },
 113     {
 114         // 4. split with local
 115         "/local/path/#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2#test3:/qqq/www/eee.rr",
 116         "/local/path/#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2",
 117         "qqq/www/eee.rr",
 118         "test3:",
 119         &vfs_test_ops3,
 120     },
 121     {
 122         // 5. split with local
 123         "/local/path/#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2",
 124         "/local/path/#test1:/bla-bla/some/path/",
 125         "bla-bla/some/path2",
 126         "test2:",
 127         &vfs_test_ops2,
 128     },
 129     {
 130         // 6. split with local
 131         "/local/path/#test1:/bla-bla/some/path/",
 132         "/local/path/",
 133         "bla-bla/some/path/",
 134         "test1:",
 135         &vfs_test_ops1,
 136     },
 137     {
 138         // 7. split with local
 139         "/local/path/",
 140         "/local/path/",
 141         NULL,
 142         NULL,
 143         NULL,
 144     },
 145     {
 146         // 8. split with URL
 147         "#test2:username:passwd@somehost.net/bla-bla/some/path2",
 148         "",
 149         "bla-bla/some/path2",
 150         "test2:username:passwd@somehost.net",
 151         &vfs_test_ops2,
 152     },
 153     {
 154         // 9. split URL with semi
 155         "/local/path/#test1:/bla-bla/some/path/#test2:username:p!a@s#s$w%d@somehost.net/bla-bla/"
 156         "some/"
 157         "path2",
 158         "/local/path/#test1:/bla-bla/some/path/",
 159         "bla-bla/some/path2",
 160         "test2:username:p!a@s#s$w%d@somehost.net",
 161         &vfs_test_ops2,
 162     },
 163     {
 164         // 10. split with semi in path
 165         "#test2:/bl#a-bl#a/so#me/pa#th2",
 166         "",
 167         "bl#a-bl#a/so#me/pa#th2",
 168         "test2:",
 169         &vfs_test_ops2,
 170     }
 171 };
 172 
 173 /* @Test(dataSource = "test_vfs_split_ds") */
 174 START_PARAMETRIZED_TEST (test_vfs_split, test_vfs_split_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 175 {
 176     // given
 177     const char *local = NULL, *op = NULL;
 178     struct vfs_class *actual_result;
 179     char *path;
 180 
 181     path = g_strdup (data->input_string);
 182 
 183     // when
 184     actual_result = _vfs_split_with_semi_skip_count (path, &local, &op, 0);
 185 
 186     // then
 187     mctest_assert_ptr_eq (actual_result, data->expected_result);
 188     mctest_assert_str_eq (path, data->expected_path);
 189     mctest_assert_str_eq (local, data->expected_local);
 190     mctest_assert_str_eq (op, data->expected_op);
 191     g_free (path);
 192 }
 193 END_PARAMETRIZED_TEST
 194 
 195 /* --------------------------------------------------------------------------------------------- */
 196 
 197 int
 198 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 199 {
 200     TCase *tc_core;
 201 
 202     tc_core = tcase_create ("Core");
 203 
 204     tcase_add_checked_fixture (tc_core, setup, teardown);
 205 
 206     // Add new tests here: ***************
 207     mctest_add_parameterized_test (tc_core, test_vfs_split, test_vfs_split_ds);
 208     // ***********************************
 209 
 210     return mctest_run_all (tc_core);
 211 }
 212 
 213 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */