root/tests/lib/vfs/path_cmp.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. START_PARAMETRIZED_TEST
  5. main

   1 /* lib/vfs - vfs_path_t compare functions
   2 
   3    Copyright (C) 2011-2020
   4    Free Software Foundation, Inc.
   5 
   6    Written by:
   7    Slava Zanko <slavazanko@gmail.com>, 2011, 2013
   8 
   9    This file is part of the Midnight Commander.
  10 
  11    The Midnight Commander is free software: you can redistribute it
  12    and/or modify it under the terms of the GNU General Public License as
  13    published by the Free Software Foundation, either version 3 of the License,
  14    or (at your option) any later version.
  15 
  16    The Midnight Commander is distributed in the hope that it will be useful,
  17    but WITHOUT ANY WARRANTY; without even the implied warranty of
  18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19    GNU General Public License for more details.
  20 
  21    You should have received a copy of the GNU General Public License
  22    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  23  */
  24 
  25 #define TEST_SUITE_NAME "/lib/vfs"
  26 
  27 #include "tests/mctest.h"
  28 
  29 #ifdef HAVE_CHARSET
  30 #include "lib/charsets.h"
  31 #endif
  32 
  33 #include "lib/strutil.h"
  34 #include "lib/vfs/xdirentry.h"
  35 #include "lib/vfs/path.h"
  36 
  37 #include "src/vfs/local/local.c"
  38 
  39 /* --------------------------------------------------------------------------------------------- */
  40 
  41 /* @Before */
  42 static void
  43 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  44 {
  45     mc_global.timer = mc_timer_new ();
  46     str_init_strings (NULL);
  47 
  48     vfs_init ();
  49     vfs_init_localfs ();
  50     vfs_setup_work_dir ();
  51 
  52     mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
  53 #ifdef HAVE_CHARSET
  54     load_codepages_list ();
  55 #endif
  56 }
  57 
  58 /* --------------------------------------------------------------------------------------------- */
  59 
  60 /* @After */
  61 static void
  62 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  63 {
  64 #ifdef HAVE_CHARSET
  65     free_codepages_list ();
  66 #endif
  67 
  68     vfs_shut ();
  69     str_uninit_strings ();
  70     mc_timer_destroy (mc_global.timer);
  71 }
  72 
  73 /* --------------------------------------------------------------------------------------------- */
  74 
  75 /* @DataSource("test_path_equal_ds") */
  76 /* *INDENT-OFF* */
  77 static const struct test_path_equal_ds
  78 {
  79     const char *input_path1;
  80     const char *input_path2;
  81     const gboolean expected_result;
  82 } test_path_equal_ds[] =
  83 {
  84     { /* 0. */
  85         NULL,
  86         NULL,
  87         FALSE
  88     },
  89     { /* 1. */
  90         NULL,
  91         "/test/path",
  92         FALSE
  93     },
  94     { /* 2. */
  95         "/test/path",
  96         NULL,
  97         FALSE
  98     },
  99     { /* 3. */
 100         "/test/path",
 101         "/test/path",
 102         TRUE
 103     },
 104 #ifdef HAVE_CHARSET
 105     { /* 4. */
 106         "/#enc:KOI8-R/тестовый/путь",
 107         "/тестовый/путь",
 108         FALSE
 109     },
 110     { /* 5. */
 111         "/тестовый/путь",
 112         "/#enc:KOI8-R/тестовый/путь",
 113         FALSE
 114     },
 115     { /* 6. */
 116         "/#enc:KOI8-R/тестовый/путь",
 117         "/#enc:KOI8-R/тестовый/путь",
 118         TRUE
 119     },
 120 #endif
 121 };
 122 /* *INDENT-ON* */
 123 
 124 /* @Test(dataSource = "test_path_equal_ds") */
 125 /* *INDENT-OFF* */
 126 START_PARAMETRIZED_TEST (test_path_equal, test_path_equal_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 127 /* *INDENT-ON* */
 128 {
 129     /* given */
 130     vfs_path_t *vpath1, *vpath2;
 131     gboolean actual_result;
 132 
 133     vpath1 = vfs_path_from_str (data->input_path1);
 134     vpath2 = vfs_path_from_str (data->input_path2);
 135 
 136     /* when */
 137     actual_result = vfs_path_equal (vpath1, vpath2);
 138 
 139     /* then */
 140     mctest_assert_int_eq (actual_result, data->expected_result);
 141 
 142     vfs_path_free (vpath1);
 143     vfs_path_free (vpath2);
 144 }
 145 /* *INDENT-OFF* */
 146 END_PARAMETRIZED_TEST
 147 /* *INDENT-ON* */
 148 
 149 /* --------------------------------------------------------------------------------------------- */
 150 
 151 /* @DataSource("test_path_equal_len_ds") */
 152 /* *INDENT-OFF* */
 153 static const struct test_path_equal_len_ds
 154 {
 155     const char *input_path1;
 156     const char *input_path2;
 157     const size_t input_length;
 158     const gboolean expected_result;
 159 } test_path_equal_len_ds[] =
 160 {
 161     { /* 0. */
 162         NULL,
 163         NULL,
 164         0,
 165         FALSE
 166     },
 167     { /* 1. */
 168         NULL,
 169         NULL,
 170         100,
 171         FALSE
 172     },
 173     { /* 2. */
 174         NULL,
 175         "/тестовый/путь",
 176         10,
 177         FALSE
 178     },
 179     { /* 3. */
 180         "/тестовый/путь",
 181         NULL,
 182         10,
 183         FALSE
 184     },
 185     { /* 4. */
 186         "/тестовый/путь",
 187         "/тестовый/путь",
 188         10,
 189         TRUE
 190     },
 191     { /* 5. */
 192         "/тест/овый/путь",
 193         "/тестовый/путь",
 194         8,
 195         TRUE
 196     },
 197     { /* 6. */
 198         "/тест/овый/путь",
 199         "/тестовый/путь",
 200         10,
 201         FALSE
 202     },
 203     { /* 7. */
 204         "/тестовый/путь",
 205         "/тест/овый/путь",
 206         10,
 207         FALSE
 208     },
 209 };
 210 /* *INDENT-ON* */
 211 
 212 /* @Test(dataSource = "test_path_equal_len_ds") */
 213 /* *INDENT-OFF* */
 214 START_PARAMETRIZED_TEST (test_path_equal_len, test_path_equal_len_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 215 /* *INDENT-ON* */
 216 {
 217     /* given */
 218     vfs_path_t *vpath1, *vpath2;
 219     gboolean actual_result;
 220 
 221     vpath1 = vfs_path_from_str (data->input_path1);
 222     vpath2 = vfs_path_from_str (data->input_path2);
 223 
 224     /* when */
 225     actual_result = vfs_path_equal_len (vpath1, vpath2, data->input_length);
 226 
 227     /* then */
 228     mctest_assert_int_eq (actual_result, data->expected_result);
 229 
 230     vfs_path_free (vpath1);
 231     vfs_path_free (vpath2);
 232 }
 233 /* *INDENT-OFF* */
 234 END_PARAMETRIZED_TEST
 235 /* *INDENT-ON* */
 236 
 237 /* --------------------------------------------------------------------------------------------- */
 238 
 239 int
 240 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 241 {
 242     int number_failed;
 243 
 244     Suite *s = suite_create (TEST_SUITE_NAME);
 245     TCase *tc_core = tcase_create ("Core");
 246     SRunner *sr;
 247 
 248     tcase_add_checked_fixture (tc_core, setup, teardown);
 249 
 250     /* Add new tests here: *************** */
 251     mctest_add_parameterized_test (tc_core, test_path_equal, test_path_equal_ds);
 252     mctest_add_parameterized_test (tc_core, test_path_equal_len, test_path_equal_len_ds);
 253     /* *********************************** */
 254 
 255     suite_add_tcase (s, tc_core);
 256     sr = srunner_create (s);
 257     srunner_set_log (sr, "path_cmp.log");
 258     srunner_run_all (sr, CK_ENV);
 259     number_failed = srunner_ntests_failed (sr);
 260     srunner_free (sr);
 261     return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 262 }
 263 
 264 /* --------------------------------------------------------------------------------------------- */

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