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-2025
   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 <https://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 ("UTF-8");
  46 
  47     vfs_init ();
  48     vfs_init_localfs ();
  49     vfs_setup_work_dir ();
  50 
  51 #ifdef HAVE_CHARSET
  52     mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
  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 static const struct test_path_equal_ds
  75 {
  76     const char *input_path1;
  77     const char *input_path2;
  78     const gboolean expected_result;
  79 } test_path_equal_ds[] = {
  80     {
  81         // 0.
  82         NULL,
  83         NULL,
  84         FALSE,
  85     },
  86     {
  87         // 1.
  88         NULL,
  89         "/test/path",
  90         FALSE,
  91     },
  92     {
  93         // 2.
  94         "/test/path",
  95         NULL,
  96         FALSE,
  97     },
  98     {
  99         // 3.
 100         "/test/path",
 101         "/test/path",
 102         TRUE,
 103     },
 104 #ifdef HAVE_CHARSET
 105     {
 106         // 4.
 107         "/#enc:KOI8-R/тестовый/путь",
 108         "/тестовый/путь",
 109         FALSE,
 110     },
 111     {
 112         // 5.
 113         "/тестовый/путь",
 114         "/#enc:KOI8-R/тестовый/путь",
 115         FALSE,
 116     },
 117     {
 118         // 6.
 119         "/#enc:KOI8-R/тестовый/путь",
 120         "/#enc:KOI8-R/тестовый/путь",
 121         TRUE,
 122     },
 123 #endif
 124 };
 125 
 126 /* @Test(dataSource = "test_path_equal_ds") */
 127 START_PARAMETRIZED_TEST (test_path_equal, test_path_equal_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 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     ck_assert_int_eq (actual_result, data->expected_result);
 141 
 142     vfs_path_free (vpath1, TRUE);
 143     vfs_path_free (vpath2, TRUE);
 144 }
 145 END_PARAMETRIZED_TEST
 146 
 147 /* --------------------------------------------------------------------------------------------- */
 148 
 149 /* @DataSource("test_path_equal_len_ds") */
 150 static const struct test_path_equal_len_ds
 151 {
 152     const char *input_path1;
 153     const char *input_path2;
 154     const size_t input_length;
 155     const gboolean expected_result;
 156 } test_path_equal_len_ds[] = {
 157     {
 158         // 0.
 159         NULL,
 160         NULL,
 161         0,
 162         FALSE,
 163     },
 164     {
 165         // 1.
 166         NULL,
 167         NULL,
 168         100,
 169         FALSE,
 170     },
 171     {
 172         // 2.
 173         NULL,
 174         "/тестовый/путь",
 175         10,
 176         FALSE,
 177     },
 178     {
 179         // 3.
 180         "/тестовый/путь",
 181         NULL,
 182         10,
 183         FALSE,
 184     },
 185     {
 186         // 4.
 187         "/тестовый/путь",
 188         "/тестовый/путь",
 189         10,
 190         TRUE,
 191     },
 192     {
 193         // 5.
 194         "/тест/овый/путь",
 195         "/тестовый/путь",
 196         8,
 197         TRUE,
 198     },
 199     {
 200         // 6.
 201         "/тест/овый/путь",
 202         "/тестовый/путь",
 203         10,
 204         FALSE,
 205     },
 206     {
 207         // 7.
 208         "/тестовый/путь",
 209         "/тест/овый/путь",
 210         10,
 211         FALSE,
 212     },
 213 };
 214 
 215 /* @Test(dataSource = "test_path_equal_len_ds") */
 216 START_PARAMETRIZED_TEST (test_path_equal_len, test_path_equal_len_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 217 {
 218     // given
 219     vfs_path_t *vpath1, *vpath2;
 220     gboolean actual_result;
 221 
 222     vpath1 = vfs_path_from_str (data->input_path1);
 223     vpath2 = vfs_path_from_str (data->input_path2);
 224 
 225     // when
 226     actual_result = vfs_path_equal_len (vpath1, vpath2, data->input_length);
 227 
 228     // then
 229     ck_assert_int_eq (actual_result, data->expected_result);
 230 
 231     vfs_path_free (vpath1, TRUE);
 232     vfs_path_free (vpath2, TRUE);
 233 }
 234 END_PARAMETRIZED_TEST
 235 
 236 /* --------------------------------------------------------------------------------------------- */
 237 
 238 int
 239 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 240 {
 241     TCase *tc_core;
 242 
 243     tc_core = tcase_create ("Core");
 244 
 245     tcase_add_checked_fixture (tc_core, setup, teardown);
 246 
 247     // Add new tests here: ***************
 248     mctest_add_parameterized_test (tc_core, test_path_equal, test_path_equal_ds);
 249     mctest_add_parameterized_test (tc_core, test_path_equal_len, test_path_equal_len_ds);
 250     // ***********************************
 251 
 252     return mctest_run_all (tc_core);
 253 }
 254 
 255 /* --------------------------------------------------------------------------------------------- */

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