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