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