This source file includes following definitions.
- init_test_classes
- setup
- teardown
- START_PARAMETRIZED_TEST
- START_PARAMETRIZED_TEST
- START_PARAMETRIZED_TEST
- START_PARAMETRIZED_TEST
- START_PARAMETRIZED_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 #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 static struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3;
40
41
42
43 static void
44 init_test_classes (void)
45 {
46 vfs_init_class (&vfs_test_ops1, "testfs1", VFSF_NOLINKS | VFSF_REMOTE, "test1");
47 vfs_register_class (&vfs_test_ops1);
48
49 vfs_init_class (&vfs_test_ops2, "testfs2", VFSF_UNKNOWN, "test2");
50 vfs_register_class (&vfs_test_ops2);
51
52 vfs_init_class (&vfs_test_ops3, "testfs3", VFSF_LOCAL, "test3");
53 vfs_register_class (&vfs_test_ops3);
54 }
55
56
57
58
59 static void
60 setup (void)
61 {
62 str_init_strings ("UTF-8");
63
64 vfs_init ();
65 vfs_init_localfs ();
66 vfs_setup_work_dir ();
67
68 init_test_classes ();
69
70 #ifdef HAVE_CHARSET
71 mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
72 load_codepages_list ();
73 #endif
74 }
75
76
77
78
79 static void
80 teardown (void)
81 {
82 #ifdef HAVE_CHARSET
83 free_codepages_list ();
84 #endif
85
86 vfs_shut ();
87 str_uninit_strings ();
88 }
89
90
91
92
93 static const struct test_vfs_path_tokens_count_ds
94 {
95 const char *input_path;
96 const vfs_path_flag_t input_flags;
97 const size_t expected_token_count;
98 } test_vfs_path_tokens_count_ds[] = {
99 {
100
101 "/",
102 VPF_NONE,
103 0,
104 },
105 {
106
107 "/path",
108 VPF_NONE,
109 1,
110 },
111 {
112
113 "/path1/path2/path3",
114 VPF_NONE,
115 3,
116 },
117 {
118
119 "test3://path1/path2/path3/path4",
120 VPF_NO_CANON,
121 4,
122 },
123 {
124
125 "path1/path2/path3",
126 VPF_NO_CANON,
127 3,
128 },
129 {
130
131 "/path1/path2/path3/",
132 VPF_NONE,
133 3,
134 },
135 {
136
137 "/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/",
138 VPF_NONE,
139 5,
140 },
141 #ifdef HAVE_CHARSET
142 {
143
144 "/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/"
145 "test2://#enc:KOI8-R/bla-bla/some/path/test3://111/22/33",
146 VPF_NONE,
147 11,
148 },
149 #endif
150 };
151
152
153 START_PARAMETRIZED_TEST (test_vfs_path_tokens_count, test_vfs_path_tokens_count_ds)
154 {
155
156 size_t tokens_count;
157 vfs_path_t *vpath;
158
159 vpath = vfs_path_from_str_flags (data->input_path, data->input_flags);
160
161
162 tokens_count = vfs_path_tokens_count (vpath);
163
164
165 ck_assert_int_eq (tokens_count, data->expected_token_count);
166
167 vfs_path_free (vpath, TRUE);
168 }
169 END_PARAMETRIZED_TEST
170
171
172
173
174 static const struct test_vfs_path_tokens_get_ds
175 {
176 const char *input_path;
177 const ssize_t input_start_position;
178 const ssize_t input_length;
179
180 const char *expected_path;
181 } test_vfs_path_tokens_get_ds[] = {
182 {
183
184 "/",
185 2,
186 1,
187 NULL,
188 },
189 {
190
191 "/path",
192 -3,
193 1,
194 NULL,
195 },
196 {
197
198 "/path",
199 0,
200 0,
201 "path",
202 },
203
204 {
205 "/path1/path2/path3/path4",
206 1,
207 2,
208 "path2/path3",
209 },
210
211 {
212 "test3://path1/path2/path3/path4",
213 1,
214 2,
215 "path2/path3",
216 },
217
218 {
219 "test2://path1/path2/path3/path4",
220 1,
221 2,
222 "test2://path2/path3",
223 },
224
225 {
226 "/path1/path2/test1://user:pass@some.host:12345/path3/path4",
227 1,
228 2,
229 "path2/test1://user:pass@some.host:12345/path3",
230 },
231
232 {
233 "test3://path1/path2/test2://path3/path4",
234 1,
235 2,
236 "path2/test2://path3",
237 },
238
239 {
240 "test2://path1/path2/test3://path3/path4",
241 1,
242 2,
243 "test2://path2/test3://path3",
244 },
245
246 {
247 "/path1/path2/path3/path4",
248 -1,
249 1,
250 "path4",
251 },
252
253 {
254 "/path1/path2/path3/path4",
255 -3,
256 0,
257 "path2/path3/path4",
258 },
259 #ifdef HAVE_CHARSET
260
261 {
262 "test3://path1/path2/test3://#enc:KOI8-R/path3/path4",
263 1,
264 2,
265 "path2/test3://#enc:KOI8-R/path3",
266 },
267
268 {
269 "#enc:KOI8-R/path1/path2/path3/path4",
270 1,
271 2,
272 "#enc:KOI8-R/path2/path3",
273 },
274 #endif
275
276
277
278
279
280
281
282
283
284
285 };
286
287
288 START_PARAMETRIZED_TEST (test_vfs_path_tokens_get, test_vfs_path_tokens_get_ds)
289 {
290
291 vfs_path_t *vpath;
292 char *actual_path;
293
294 vpath = vfs_path_from_str_flags (data->input_path, VPF_NO_CANON);
295
296
297 actual_path = vfs_path_tokens_get (vpath, data->input_start_position, data->input_length);
298
299
300 mctest_assert_str_eq (actual_path, data->expected_path);
301
302 g_free (actual_path);
303 vfs_path_free (vpath, TRUE);
304 }
305 END_PARAMETRIZED_TEST
306
307
308
309
310 static const struct test_vfs_path_append_vpath_ds
311 {
312 const char *input_path1;
313 const char *input_path2;
314 const int expected_element_count;
315 const char *expected_path;
316 } test_vfs_path_append_vpath_ds[] = {
317 {
318
319 "/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/test2://bla-bla/some/path/"
320 "test3://111/22/33",
321 "/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/",
322 6,
323 "/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/test2://bla-bla/some/path/"
324 "test3://111/22/33"
325 "/local/path/test1://user:pass@some.host:12345/bla-bla/some/path",
326 },
327 #ifdef HAVE_CHARSET
328 {
329
330 "/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/test2://#enc:KOI8-R/"
331 "bla-bla/some/path/test3://111/22/33",
332 "/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/",
333 6,
334 "/local/path/test1://user:pass@some.host:12345/bla-bla/some/path/test2://#enc:KOI8-R/"
335 "bla-bla/some/path/test3://111/22/33"
336 "/local/path/test1://user:pass@some.host:12345/bla-bla/some/path",
337 },
338 #endif
339 };
340
341
342 START_PARAMETRIZED_TEST (test_vfs_path_append_vpath, test_vfs_path_append_vpath_ds)
343 {
344
345 vfs_path_t *vpath1, *vpath2, *vpath3;
346
347 vpath1 = vfs_path_from_str (data->input_path1);
348 vpath2 = vfs_path_from_str (data->input_path2);
349
350
351 vpath3 = vfs_path_append_vpath_new (vpath1, vpath2, NULL);
352
353
354 ck_assert_int_eq (vfs_path_elements_count (vpath3), data->expected_element_count);
355 mctest_assert_str_eq (vfs_path_as_str (vpath3), data->expected_path);
356
357 vfs_path_free (vpath1, TRUE);
358 vfs_path_free (vpath2, TRUE);
359 vfs_path_free (vpath3, TRUE);
360 }
361 END_PARAMETRIZED_TEST
362
363
364
365
366 static const struct test_vfs_path_relative_ds
367 {
368 const char *input_path;
369 const char *expected_path;
370 const char *expected_last_path_in_element;
371 } test_vfs_path_relative_ds[] = {
372 {
373
374 "../bla-bla",
375 "../bla-bla",
376 "../bla-bla",
377 },
378 {
379
380 "../path/test1://user:pass@some.host:12345/bla-bla/some/path/",
381 "../path/test1://user:pass@some.host:12345/bla-bla/some/path/",
382 "bla-bla/some/path/",
383 },
384 };
385
386
387 START_PARAMETRIZED_TEST (test_vfs_path_relative, test_vfs_path_relative_ds)
388 {
389
390 vfs_path_t *vpath;
391
392
393
394 vpath = vfs_path_from_str_flags (data->input_path, VPF_NO_CANON);
395
396
397 mctest_assert_true (vpath->relative);
398 mctest_assert_str_eq (vfs_path_get_last_path_str (vpath), data->expected_last_path_in_element);
399 mctest_assert_str_eq (vfs_path_as_str (vpath), data->expected_path);
400
401 vfs_path_free (vpath, TRUE);
402 }
403 END_PARAMETRIZED_TEST
404
405
406
407
408 START_PARAMETRIZED_TEST (test_vfs_path_relative_clone, test_vfs_path_relative_ds)
409 {
410
411 vfs_path_t *vpath, *cloned_vpath;
412
413 vpath = vfs_path_from_str_flags (data->input_path, VPF_NO_CANON);
414
415
416
417 cloned_vpath = vfs_path_clone (vpath);
418
419
420 mctest_assert_true (cloned_vpath->relative);
421 mctest_assert_str_eq (vfs_path_get_last_path_str (cloned_vpath),
422 data->expected_last_path_in_element);
423 mctest_assert_str_eq (vfs_path_as_str (cloned_vpath), data->expected_path);
424
425 vfs_path_free (vpath, TRUE);
426 vfs_path_free (cloned_vpath, TRUE);
427 }
428 END_PARAMETRIZED_TEST
429
430
431
432 int
433 main (void)
434 {
435 TCase *tc_core;
436
437 tc_core = tcase_create ("Core");
438
439 tcase_add_checked_fixture (tc_core, setup, teardown);
440
441
442 mctest_add_parameterized_test (tc_core, test_vfs_path_tokens_count,
443 test_vfs_path_tokens_count_ds);
444 mctest_add_parameterized_test (tc_core, test_vfs_path_tokens_get, test_vfs_path_tokens_get_ds);
445 mctest_add_parameterized_test (tc_core, test_vfs_path_append_vpath,
446 test_vfs_path_append_vpath_ds);
447 mctest_add_parameterized_test (tc_core, test_vfs_path_relative, test_vfs_path_relative_ds);
448 mctest_add_parameterized_test (tc_core, test_vfs_path_relative_clone,
449 test_vfs_path_relative_ds);
450
451
452 return mctest_run_all (tc_core);
453 }
454
455