Manual pages: mcmcdiffmceditmcview

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

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