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-2018
   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     str_init_strings (NULL);
  46 
  47     vfs_init ();
  48     init_localfs ();
  49     vfs_setup_work_dir ();
  50 
  51     mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
  52 #ifdef HAVE_CHARSET
  53     load_codepages_list ();
  54 #endif
  55 }
  56 
  57 /* --------------------------------------------------------------------------------------------- */
  58 
  59 /* @After */
  60 static void
  61 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  62 {
  63 #ifdef HAVE_CHARSET
  64     free_codepages_list ();
  65 #endif
  66 
  67     vfs_shut ();
  68     str_uninit_strings ();
  69 }
  70 
  71 /* --------------------------------------------------------------------------------------------- */
  72 
  73 /* @DataSource("test_path_equal_ds") */
  74 /* *INDENT-OFF* */
  75 static const struct test_path_equal_ds
  76 {
  77     const char *input_path1;
  78     const char *input_path2;
  79     const gboolean expected_result;
  80 } test_path_equal_ds[] =
  81 {
  82     { /* 0. */
  83         NULL,
  84         NULL,
  85         FALSE
  86     },
  87     { /* 1. */
  88         NULL,
  89         "/test/path",
  90         FALSE
  91     },
  92     { /* 2. */
  93         "/test/path",
  94         NULL,
  95         FALSE
  96     },
  97     { /* 3. */
  98         "/test/path",
  99         "/test/path",
 100         TRUE
 101     },
 102 #ifdef HAVE_CHARSET
 103     { /* 4. */
 104         "/#enc:KOI8-R/тестовый/путь",
 105         "/тестовый/путь",
 106         FALSE
 107     },
 108     { /* 5. */
 109         "/тестовый/путь",
 110         "/#enc:KOI8-R/тестовый/путь",
 111         FALSE
 112     },
 113     { /* 6. */
 114         "/#enc:KOI8-R/тестовый/путь",
 115         "/#enc:KOI8-R/тестовый/путь",
 116         TRUE
 117     },
 118 #endif
 119 };
 120 /* *INDENT-ON* */
 121 
 122 /* @Test(dataSource = "test_path_equal_ds") */
 123 /* *INDENT-OFF* */
 124 START_PARAMETRIZED_TEST (test_path_equal, test_path_equal_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 125 /* *INDENT-ON* */
 126 {
 127     /* given */
 128     vfs_path_t *vpath1, *vpath2;
 129     gboolean actual_result;
 130 
 131     vpath1 = vfs_path_from_str (data->input_path1);
 132     vpath2 = vfs_path_from_str (data->input_path2);
 133 
 134     /* when */
 135     actual_result = vfs_path_equal (vpath1, vpath2);
 136 
 137     /* then */
 138     mctest_assert_int_eq (actual_result, data->expected_result);
 139 
 140     vfs_path_free (vpath1);
 141     vfs_path_free (vpath2);
 142 }
 143 /* *INDENT-OFF* */
 144 END_PARAMETRIZED_TEST
 145 /* *INDENT-ON* */
 146 
 147 /* --------------------------------------------------------------------------------------------- */
 148 
 149 /* @DataSource("test_path_equal_len_ds") */
 150 /* *INDENT-OFF* */
 151 static const struct test_path_equal_len_ds
 152 {
 153     const char *input_path1;
 154     const char *input_path2;
 155     const size_t input_length;
 156     const gboolean expected_result;
 157 } test_path_equal_len_ds[] =
 158 {
 159     { /* 0. */
 160         NULL,
 161         NULL,
 162         0,
 163         FALSE
 164     },
 165     { /* 1. */
 166         NULL,
 167         NULL,
 168         100,
 169         FALSE
 170     },
 171     { /* 2. */
 172         NULL,
 173         "/тестовый/путь",
 174         10,
 175         FALSE
 176     },
 177     { /* 3. */
 178         "/тестовый/путь",
 179         NULL,
 180         10,
 181         FALSE
 182     },
 183     { /* 4. */
 184         "/тестовый/путь",
 185         "/тестовый/путь",
 186         10,
 187         TRUE
 188     },
 189     { /* 5. */
 190         "/тест/овый/путь",
 191         "/тестовый/путь",
 192         8,
 193         TRUE
 194     },
 195     { /* 6. */
 196         "/тест/овый/путь",
 197         "/тестовый/путь",
 198         10,
 199         FALSE
 200     },
 201     { /* 7. */
 202         "/тестовый/путь",
 203         "/тест/овый/путь",
 204         10,
 205         FALSE
 206     },
 207 };
 208 /* *INDENT-ON* */
 209 
 210 /* @Test(dataSource = "test_path_equal_len_ds") */
 211 /* *INDENT-OFF* */
 212 START_PARAMETRIZED_TEST (test_path_equal_len, test_path_equal_len_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 213 /* *INDENT-ON* */
 214 {
 215     /* given */
 216     vfs_path_t *vpath1, *vpath2;
 217     gboolean actual_result;
 218 
 219     vpath1 = vfs_path_from_str (data->input_path1);
 220     vpath2 = vfs_path_from_str (data->input_path2);
 221 
 222     /* when */
 223     actual_result = vfs_path_equal_len (vpath1, vpath2, data->input_length);
 224 
 225     /* then */
 226     mctest_assert_int_eq (actual_result, data->expected_result);
 227 
 228     vfs_path_free (vpath1);
 229     vfs_path_free (vpath2);
 230 }
 231 /* *INDENT-OFF* */
 232 END_PARAMETRIZED_TEST
 233 /* *INDENT-ON* */
 234 
 235 /* --------------------------------------------------------------------------------------------- */
 236 
 237 int
 238 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 239 {
 240     int number_failed;
 241 
 242     Suite *s = suite_create (TEST_SUITE_NAME);
 243     TCase *tc_core = tcase_create ("Core");
 244     SRunner *sr;
 245 
 246     tcase_add_checked_fixture (tc_core, setup, teardown);
 247 
 248     /* Add new tests here: *************** */
 249     mctest_add_parameterized_test (tc_core, test_path_equal, test_path_equal_ds);
 250     mctest_add_parameterized_test (tc_core, test_path_equal_len, test_path_equal_len_ds);
 251     /* *********************************** */
 252 
 253     suite_add_tcase (s, tc_core);
 254     sr = srunner_create (s);
 255     srunner_set_log (sr, "path_cmp.log");
 256     srunner_run_all (sr, CK_ENV);
 257     number_failed = srunner_ntests_failed (sr);
 258     srunner_free (sr);
 259     return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 260 }
 261 
 262 /* --------------------------------------------------------------------------------------------- */

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