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