This source file includes following definitions.
- setup
- teardown
- START_PARAMETRIZED_TEST
- START_PARAMETRIZED_TEST
- START_TEST
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 #define TEST_SUITE_NAME "/lib/vfs"
27
28 #include "tests/mctest.h"
29
30 #ifdef HAVE_CHARSET
31 # include "lib/charsets.h"
32 #endif
33
34 #include "lib/strutil.h"
35 #include "lib/vfs/xdirentry.h"
36 #include "lib/vfs/path.c"
37
38 #include "src/vfs/local/local.c"
39
40 static struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3;
41
42 #define ETALON_PATH_STR "/#test1/bla-bla/some/path/#test2/bla-bla/some/path#test3/111/22/33"
43 #define ETALON_PATH_URL_STR "/test1://bla-bla/some/path/test2://bla-bla/some/path/test3://111/22/33"
44
45
46
47
48 static void
49 setup (void)
50 {
51 str_init_strings ("UTF-8");
52
53 vfs_init ();
54 vfs_init_localfs ();
55 vfs_setup_work_dir ();
56
57 vfs_init_class (&vfs_test_ops1, "testfs1", VFSF_NOLINKS, "test1");
58 vfs_register_class (&vfs_test_ops1);
59
60 vfs_init_class (&vfs_test_ops2, "testfs2", VFSF_REMOTE, "test2");
61 vfs_register_class (&vfs_test_ops2);
62
63 vfs_init_class (&vfs_test_ops3, "testfs3", VFSF_UNKNOWN, "test3");
64 vfs_register_class (&vfs_test_ops3);
65
66 #ifdef HAVE_CHARSET
67 mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
68 load_codepages_list ();
69 #endif
70 }
71
72
73
74
75 static void
76 teardown (void)
77 {
78 #ifdef HAVE_CHARSET
79 free_codepages_list ();
80 #endif
81
82 vfs_shut ();
83 str_uninit_strings ();
84 }
85
86
87
88 static const struct test_from_to_string_ds
89 {
90 const char *input_string;
91 const char *expected_result;
92 const char *expected_element_path;
93 const size_t expected_elements_count;
94 struct vfs_class *expected_vfs_class;
95 } test_from_to_string_ds[] = {
96 {
97
98 ETALON_PATH_STR,
99 ETALON_PATH_URL_STR,
100 "111/22/33",
101 4,
102 &vfs_test_ops3,
103 },
104 {
105
106 "/",
107 "/",
108 "/",
109 1,
110 VFS_CLASS (&local_subclass),
111 },
112 {
113
114 "/test1://bla-bla/some/path/test2://user:passwd@some.host:1234/bla-bla/some/path/"
115 "test3://111/22/33",
116 "/test1://bla-bla/some/path/test2://user:passwd@some.host:1234/bla-bla/some/path/"
117 "test3://111/22/33",
118 "111/22/33",
119 4,
120 &vfs_test_ops3,
121 },
122 #ifdef HAVE_CHARSET
123 {
124
125 "/#test1/bla-bla1/some/path/#test2/bla-bla2/#enc:KOI8-R/some/path#test3/111/22/33",
126 "/test1://bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/test3://111/22/33",
127 "111/22/33",
128 4,
129 &vfs_test_ops3,
130 },
131 {
132
133 "/#test1/bla-bla1/#enc:CP866/some/path/#test2/bla-bla2/#enc:KOI8-R/some/path"
134 "#test3/111/22/33",
135 "/test1://#enc:CP866/bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/"
136 "test3://111/22/33",
137 "111/22/33",
138 4,
139 &vfs_test_ops3,
140 },
141 {
142
143 "/#test1/bla-bla1/some/path/#test2/bla-bla2/#enc:CP866/#enc:KOI8-R/some/path"
144 "#test3/111/22/33",
145 "/test1://bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/"
146 "test3://111/22/33",
147 "111/22/33",
148 4,
149 &vfs_test_ops3,
150 },
151 {
152
153 "/#test1/bla-bla1/some/path/#test2/bla-bla2/#enc:CP866/some/#enc:KOI8-R/path"
154 "#test3/111/22/33",
155 "/test1://bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/"
156 "test3://111/22/33",
157 "111/22/33",
158 4,
159 &vfs_test_ops3,
160 },
161 {
162
163 "/#test1/bla-bla1/some/path/#test2/#enc:CP866/bla-bla2/#enc:KOI8-R/some/path"
164 "#test3/111/22/33",
165 "/test1://bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/"
166 "test3://111/22/33",
167 "111/22/33",
168 4,
169 &vfs_test_ops3,
170 },
171 {
172
173 "/#test1/bla-bla1/some/path/#enc:CP866/#test2/bla-bla2/#enc:KOI8-R/some/path"
174 "#test3/111/22/33",
175 "/test1://#enc:CP866/bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/"
176 "test3://111/22/33",
177 "111/22/33",
178 4,
179 &vfs_test_ops3,
180 },
181 #endif
182 };
183
184
185 START_PARAMETRIZED_TEST (test_from_to_string, test_from_to_string_ds)
186 {
187
188 vfs_path_t *vpath;
189 size_t vpath_len;
190 const vfs_path_element_t *path_element;
191 const char *actual_result;
192
193 vpath = vfs_path_from_str_flags (data->input_string, VPF_USE_DEPRECATED_PARSER);
194
195
196 vpath_len = vfs_path_elements_count (vpath);
197 actual_result = vfs_path_as_str (vpath);
198 path_element = vfs_path_get_by_index (vpath, -1);
199
200
201 ck_assert_int_eq (vpath_len, data->expected_elements_count);
202 mctest_assert_str_eq (actual_result, data->expected_result);
203 mctest_assert_ptr_eq (path_element->class, data->expected_vfs_class);
204 mctest_assert_str_eq (path_element->path, data->expected_element_path);
205
206 vfs_path_free (vpath, TRUE);
207 }
208 END_PARAMETRIZED_TEST
209
210
211
212
213 static const struct test_partial_string_by_index_ds
214 {
215 const char *input_string;
216 const off_t element_index;
217 const char *expected_result;
218 } test_partial_string_by_index_ds[] = {
219 {
220
221 ETALON_PATH_STR,
222 -1,
223 "/test1://bla-bla/some/path/test2://bla-bla/some/path",
224 },
225 {
226
227 ETALON_PATH_STR,
228 -2,
229 "/test1://bla-bla/some/path/",
230 },
231 {
232
233 ETALON_PATH_STR,
234 -3,
235 "/",
236 },
237 {
238
239 ETALON_PATH_STR,
240 -4,
241 "",
242 },
243 {
244
245 ETALON_PATH_STR,
246 1,
247 "/",
248 },
249 {
250
251 ETALON_PATH_STR,
252 2,
253 "/test1://bla-bla/some/path/",
254 },
255 {
256
257 ETALON_PATH_STR,
258 3,
259 "/test1://bla-bla/some/path/test2://bla-bla/some/path",
260 },
261 {
262
263 ETALON_PATH_STR,
264 4,
265 ETALON_PATH_URL_STR,
266 },
267 {
268
269 ETALON_PATH_STR,
270 5,
271 ETALON_PATH_URL_STR,
272 },
273 };
274
275
276 START_PARAMETRIZED_TEST (test_partial_string_by_index, test_partial_string_by_index_ds)
277 {
278
279 vfs_path_t *vpath;
280 char *actual_result;
281 vpath = vfs_path_from_str_flags (data->input_string, VPF_USE_DEPRECATED_PARSER);
282
283
284 actual_result = vfs_path_to_str_elements_count (vpath, data->element_index);
285
286
287 mctest_assert_str_eq (actual_result, data->expected_result);
288 g_free (actual_result);
289
290 vfs_path_free (vpath, TRUE);
291 }
292 END_PARAMETRIZED_TEST
293
294
295 #ifdef HAVE_CHARSET
296
297
298 # define ETALON_STR "/path/to/file.ext/test1://#enc:KOI8-R"
299
300 START_TEST (test_vfs_path_encoding_at_end)
301 {
302
303 vfs_path_t *vpath;
304 const char *result;
305 const vfs_path_element_t *element;
306
307 vpath =
308 vfs_path_from_str_flags ("/path/to/file.ext#test1:/#enc:KOI8-R", VPF_USE_DEPRECATED_PARSER);
309
310
311 result = vfs_path_as_str (vpath);
312 element = vfs_path_get_by_index (vpath, -1);
313
314
315 mctest_assert_str_eq (element->path, "");
316 mctest_assert_not_null (element->encoding);
317 mctest_assert_str_eq (result, ETALON_STR);
318
319 vfs_path_free (vpath, TRUE);
320 }
321
322 END_TEST
323 #endif
324
325
326 int
327 main (void)
328 {
329 TCase *tc_core;
330
331 tc_core = tcase_create ("Core");
332
333 tcase_add_checked_fixture (tc_core, setup, teardown);
334
335
336 mctest_add_parameterized_test (tc_core, test_from_to_string, test_from_to_string_ds);
337 mctest_add_parameterized_test (tc_core, test_partial_string_by_index,
338 test_partial_string_by_index_ds);
339 #ifdef HAVE_CHARSET
340 tcase_add_test (tc_core, test_vfs_path_encoding_at_end);
341 #endif
342
343
344 return mctest_run_all (tc_core);
345 }
346
347