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-2024
   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 <http://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 /* *INDENT-OFF* */
  74 static const struct test_vfs_split_ds
  75 {
  76     const char *input_string;
  77     const char *expected_path;
  78     const char *expected_local;
  79     const char *expected_op;
  80     const struct vfs_class *expected_result;
  81 } test_vfs_split_ds[] =
  82 {
  83     { /* 0. */
  84         "#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2/#test3:/qqq/www/eee.rr",
  85         "#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2/",
  86         "qqq/www/eee.rr",
  87         "test3:",
  88         &vfs_test_ops3
  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     { /* 2. */
  98         "#test1:/bla-bla/some/path/",
  99         "",
 100         "bla-bla/some/path/",
 101         "test1:",
 102         &vfs_test_ops1
 103     },
 104     { /* 3. */
 105         "",
 106         "",
 107         NULL,
 108         NULL,
 109         NULL
 110     },
 111     { /* 4. split with local */
 112         "/local/path/#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2#test3:/qqq/www/eee.rr",
 113         "/local/path/#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2",
 114         "qqq/www/eee.rr",
 115         "test3:",
 116         &vfs_test_ops3
 117     },
 118     { /* 5. split with local */
 119         "/local/path/#test1:/bla-bla/some/path/#test2:/bla-bla/some/path2",
 120         "/local/path/#test1:/bla-bla/some/path/",
 121         "bla-bla/some/path2",
 122         "test2:",
 123         &vfs_test_ops2
 124     },
 125     { /* 6. split with local */
 126         "/local/path/#test1:/bla-bla/some/path/",
 127         "/local/path/",
 128         "bla-bla/some/path/",
 129         "test1:",
 130         &vfs_test_ops1
 131     },
 132     { /* 7. split with local */
 133         "/local/path/",
 134         "/local/path/",
 135         NULL,
 136         NULL,
 137         NULL
 138     },
 139     { /* 8. split with URL */
 140         "#test2:username:passwd@somehost.net/bla-bla/some/path2",
 141         "",
 142         "bla-bla/some/path2",
 143         "test2:username:passwd@somehost.net",
 144         &vfs_test_ops2
 145     },
 146     { /* 9. split URL with semi */
 147         "/local/path/#test1:/bla-bla/some/path/#test2:username:p!a@s#s$w%d@somehost.net/bla-bla/some/path2",
 148         "/local/path/#test1:/bla-bla/some/path/",
 149         "bla-bla/some/path2",
 150         "test2:username:p!a@s#s$w%d@somehost.net",
 151         &vfs_test_ops2
 152     },
 153     { /* 10. split with semi in path */
 154         "#test2:/bl#a-bl#a/so#me/pa#th2",
 155         "",
 156         "bl#a-bl#a/so#me/pa#th2",
 157         "test2:",
 158         &vfs_test_ops2
 159     }
 160 };
 161 /* *INDENT-ON* */
 162 
 163 /* @Test(dataSource = "test_vfs_split_ds") */
 164 /* *INDENT-OFF* */
 165 START_PARAMETRIZED_TEST (test_vfs_split, test_vfs_split_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 166 /* *INDENT-ON* */
 167 {
 168     /* given */
 169     const char *local = NULL, *op = NULL;
 170     struct vfs_class *actual_result;
 171     char *path;
 172 
 173     path = g_strdup (data->input_string);
 174 
 175     /* when */
 176     actual_result = _vfs_split_with_semi_skip_count (path, &local, &op, 0);
 177 
 178     /* then */
 179     mctest_assert_ptr_eq (actual_result, data->expected_result);
 180     mctest_assert_str_eq (path, data->expected_path);
 181     mctest_assert_str_eq (local, data->expected_local);
 182     mctest_assert_str_eq (op, data->expected_op);
 183     g_free (path);
 184 }
 185 /* *INDENT-OFF* */
 186 END_PARAMETRIZED_TEST
 187 /* *INDENT-ON* */
 188 
 189 /* --------------------------------------------------------------------------------------------- */
 190 
 191 int
 192 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 193 {
 194     TCase *tc_core;
 195 
 196     tc_core = tcase_create ("Core");
 197 
 198     tcase_add_checked_fixture (tc_core, setup, teardown);
 199 
 200     /* Add new tests here: *************** */
 201     mctest_add_parameterized_test (tc_core, test_vfs_split, test_vfs_split_ds);
 202     /* *********************************** */
 203 
 204     return mctest_run_all (tc_core);
 205 }
 206 
 207 /* --------------------------------------------------------------------------------------------- */

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