1 /* lib/vfs - vfs_path_t compare functions
3 Copyright (C) 2011-2016
4 Free Software Foundation, Inc.
7 Slava Zanko <slavazanko@gmail.com>, 2011, 2013
9 This file is part of the Midnight Commander.
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.
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.
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/>.
25 #define TEST_SUITE_NAME "/lib/vfs"
27 #include "tests/mctest.h"
30 #include "lib/charsets.h"
33 #include "lib/strutil.h"
34 #include "lib/vfs/xdirentry.h"
35 #include "lib/vfs/path.h"
37 #include "src/vfs/local/local.c"
39 /* --------------------------------------------------------------------------------------------- */
45 str_init_strings (NULL
);
49 vfs_setup_work_dir ();
51 mc_global
.sysconfig_dir
= (char *) TEST_SHARE_DIR
;
53 load_codepages_list ();
57 /* --------------------------------------------------------------------------------------------- */
64 free_codepages_list ();
68 str_uninit_strings ();
71 /* --------------------------------------------------------------------------------------------- */
73 /* @DataSource("test_path_equal_ds") */
75 static const struct test_path_equal_ds
77 const char *input_path1
;
78 const char *input_path2
;
79 const gboolean expected_result
;
80 } test_path_equal_ds
[] =
104 "/#enc:KOI8-R/тестовый/путь",
110 "/#enc:KOI8-R/тестовый/путь",
114 "/#enc:KOI8-R/тестовый/путь",
115 "/#enc:KOI8-R/тестовый/путь",
122 /* @Test(dataSource = "test_path_equal_ds") */
124 START_PARAMETRIZED_TEST (test_path_equal
, test_path_equal_ds
)
128 vfs_path_t
*vpath1
, *vpath2
;
129 gboolean actual_result
;
131 vpath1
= vfs_path_from_str (data
->input_path1
);
132 vpath2
= vfs_path_from_str (data
->input_path2
);
135 actual_result
= vfs_path_equal (vpath1
, vpath2
);
138 mctest_assert_int_eq (actual_result
, data
->expected_result
);
140 vfs_path_free (vpath1
);
141 vfs_path_free (vpath2
);
144 END_PARAMETRIZED_TEST
147 /* --------------------------------------------------------------------------------------------- */
149 /* @DataSource("test_path_equal_len_ds") */
151 static const struct test_path_equal_len_ds
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
[] =
210 /* @Test(dataSource = "test_path_equal_len_ds") */
212 START_PARAMETRIZED_TEST (test_path_equal_len
, test_path_equal_len_ds
)
216 vfs_path_t
*vpath1
, *vpath2
;
217 gboolean actual_result
;
219 vpath1
= vfs_path_from_str (data
->input_path1
);
220 vpath2
= vfs_path_from_str (data
->input_path2
);
223 actual_result
= vfs_path_equal_len (vpath1
, vpath2
, data
->input_length
);
226 mctest_assert_int_eq (actual_result
, data
->expected_result
);
228 vfs_path_free (vpath1
);
229 vfs_path_free (vpath2
);
232 END_PARAMETRIZED_TEST
235 /* --------------------------------------------------------------------------------------------- */
242 Suite
*s
= suite_create (TEST_SUITE_NAME
);
243 TCase
*tc_core
= tcase_create ("Core");
246 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
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 /* *********************************** */
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
);
259 return (number_failed
== 0) ? EXIT_SUCCESS
: EXIT_FAILURE
;
262 /* --------------------------------------------------------------------------------------------- */