Update copyright years.
[midnight-commander.git] / tests / lib / vfs / path_cmp.c
blob2b025674e827f8c3ecc555047c778c58797a43aa
1 /* lib/vfs - vfs_path_t compare functions
3 Copyright (C) 2011-2016
4 Free Software Foundation, Inc.
6 Written by:
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"
29 #ifdef HAVE_CHARSET
30 #include "lib/charsets.h"
31 #endif
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 /* --------------------------------------------------------------------------------------------- */
41 /* @Before */
42 static void
43 setup (void)
45 str_init_strings (NULL);
47 vfs_init ();
48 init_localfs ();
49 vfs_setup_work_dir ();
51 mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
52 #ifdef HAVE_CHARSET
53 load_codepages_list ();
54 #endif
57 /* --------------------------------------------------------------------------------------------- */
59 /* @After */
60 static void
61 teardown (void)
63 #ifdef HAVE_CHARSET
64 free_codepages_list ();
65 #endif
67 vfs_shut ();
68 str_uninit_strings ();
71 /* --------------------------------------------------------------------------------------------- */
73 /* @DataSource("test_path_equal_ds") */
74 /* *INDENT-OFF* */
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[] =
82 { /* 0. */
83 NULL,
84 NULL,
85 FALSE
87 { /* 1. */
88 NULL,
89 "/test/path",
90 FALSE
92 { /* 2. */
93 "/test/path",
94 NULL,
95 FALSE
97 { /* 3. */
98 "/test/path",
99 "/test/path",
100 TRUE
102 #ifdef HAVE_CHARSET
103 { /* 4. */
104 "/#enc:KOI8-R/тестовый/путь",
105 "/тестовый/путь",
106 FALSE
108 { /* 5. */
109 "/тестовый/путь",
110 "/#enc:KOI8-R/тестовый/путь",
111 FALSE
113 { /* 6. */
114 "/#enc:KOI8-R/тестовый/путь",
115 "/#enc:KOI8-R/тестовый/путь",
116 TRUE
118 #endif
120 /* *INDENT-ON* */
122 /* @Test(dataSource = "test_path_equal_ds") */
123 /* *INDENT-OFF* */
124 START_PARAMETRIZED_TEST (test_path_equal, test_path_equal_ds)
125 /* *INDENT-ON* */
127 /* given */
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);
134 /* when */
135 actual_result = vfs_path_equal (vpath1, vpath2);
137 /* then */
138 mctest_assert_int_eq (actual_result, data->expected_result);
140 vfs_path_free (vpath1);
141 vfs_path_free (vpath2);
143 /* *INDENT-OFF* */
144 END_PARAMETRIZED_TEST
145 /* *INDENT-ON* */
147 /* --------------------------------------------------------------------------------------------- */
149 /* @DataSource("test_path_equal_len_ds") */
150 /* *INDENT-OFF* */
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[] =
159 { /* 0. */
160 NULL,
161 NULL,
163 FALSE
165 { /* 1. */
166 NULL,
167 NULL,
168 100,
169 FALSE
171 { /* 2. */
172 NULL,
173 "/тестовый/путь",
175 FALSE
177 { /* 3. */
178 "/тестовый/путь",
179 NULL,
181 FALSE
183 { /* 4. */
184 "/тестовый/путь",
185 "/тестовый/путь",
187 TRUE
189 { /* 5. */
190 "/тест/овый/путь",
191 "/тестовый/путь",
193 TRUE
195 { /* 6. */
196 "/тест/овый/путь",
197 "/тестовый/путь",
199 FALSE
201 { /* 7. */
202 "/тестовый/путь",
203 "/тест/овый/путь",
205 FALSE
208 /* *INDENT-ON* */
210 /* @Test(dataSource = "test_path_equal_len_ds") */
211 /* *INDENT-OFF* */
212 START_PARAMETRIZED_TEST (test_path_equal_len, test_path_equal_len_ds)
213 /* *INDENT-ON* */
215 /* given */
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);
222 /* when */
223 actual_result = vfs_path_equal_len (vpath1, vpath2, data->input_length);
225 /* then */
226 mctest_assert_int_eq (actual_result, data->expected_result);
228 vfs_path_free (vpath1);
229 vfs_path_free (vpath2);
231 /* *INDENT-OFF* */
232 END_PARAMETRIZED_TEST
233 /* *INDENT-ON* */
235 /* --------------------------------------------------------------------------------------------- */
238 main (void)
240 int number_failed;
242 Suite *s = suite_create (TEST_SUITE_NAME);
243 TCase *tc_core = tcase_create ("Core");
244 SRunner *sr;
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);
258 srunner_free (sr);
259 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
262 /* --------------------------------------------------------------------------------------------- */