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
89 static const struct test_from_to_string_ds
90 {
91 const char *input_string;
92 const char *expected_result;
93 const char *expected_element_path;
94 const size_t expected_elements_count;
95 struct vfs_class *expected_vfs_class;
96 } test_from_to_string_ds[] =
97 {
98 {
99 ETALON_PATH_STR,
100 ETALON_PATH_URL_STR,
101 "111/22/33",
102 4,
103 &vfs_test_ops3
104 },
105 {
106 "/",
107 "/",
108 "/",
109 1,
110 VFS_CLASS (&local_subclass)
111 },
112 {
113 "/test1://bla-bla/some/path/test2://user:passwd@some.host:1234/bla-bla/some/path/test3://111/22/33",
114 "/test1://bla-bla/some/path/test2://user:passwd@some.host:1234/bla-bla/some/path/test3://111/22/33",
115 "111/22/33",
116 4,
117 &vfs_test_ops3
118 },
119 #ifdef HAVE_CHARSET
120 {
121 "/#test1/bla-bla1/some/path/#test2/bla-bla2/#enc:KOI8-R/some/path#test3/111/22/33",
122 "/test1://bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/test3://111/22/33",
123 "111/22/33",
124 4,
125 &vfs_test_ops3
126 },
127 {
128 "/#test1/bla-bla1/#enc:CP866/some/path/#test2/bla-bla2/#enc:KOI8-R/some/path#test3/111/22/33",
129 "/test1://#enc:CP866/bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/test3://111/22/33",
130 "111/22/33",
131 4,
132 &vfs_test_ops3
133 },
134 {
135 "/#test1/bla-bla1/some/path/#test2/bla-bla2/#enc:CP866/#enc:KOI8-R/some/path#test3/111/22/33",
136 "/test1://bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/test3://111/22/33",
137 "111/22/33",
138 4,
139 &vfs_test_ops3
140 },
141 {
142 "/#test1/bla-bla1/some/path/#test2/bla-bla2/#enc:CP866/some/#enc:KOI8-R/path#test3/111/22/33",
143 "/test1://bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/test3://111/22/33",
144 "111/22/33",
145 4,
146 &vfs_test_ops3
147 },
148 {
149 "/#test1/bla-bla1/some/path/#test2/#enc:CP866/bla-bla2/#enc:KOI8-R/some/path#test3/111/22/33",
150 "/test1://bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/test3://111/22/33",
151 "111/22/33",
152 4,
153 &vfs_test_ops3
154 },
155 {
156 "/#test1/bla-bla1/some/path/#enc:CP866/#test2/bla-bla2/#enc:KOI8-R/some/path#test3/111/22/33",
157 "/test1://#enc:CP866/bla-bla1/some/path/test2://#enc:KOI8-R/bla-bla2/some/path/test3://111/22/33",
158 "111/22/33",
159 4,
160 &vfs_test_ops3
161 },
162 #endif
163 };
164
165
166
167
168 START_PARAMETRIZED_TEST (test_from_to_string, test_from_to_string_ds)
169
170 {
171
172 vfs_path_t *vpath;
173 size_t vpath_len;
174 const vfs_path_element_t *path_element;
175 const char *actual_result;
176
177 vpath = vfs_path_from_str_flags (data->input_string, VPF_USE_DEPRECATED_PARSER);
178
179
180 vpath_len = vfs_path_elements_count (vpath);
181 actual_result = vfs_path_as_str (vpath);
182 path_element = vfs_path_get_by_index (vpath, -1);
183
184
185 ck_assert_int_eq (vpath_len, data->expected_elements_count);
186 mctest_assert_str_eq (actual_result, data->expected_result);
187 mctest_assert_ptr_eq (path_element->class, data->expected_vfs_class);
188 mctest_assert_str_eq (path_element->path, data->expected_element_path);
189
190 vfs_path_free (vpath, TRUE);
191 }
192
193 END_PARAMETRIZED_TEST
194
195
196
197
198
199
200 static const struct test_partial_string_by_index_ds
201 {
202 const char *input_string;
203 const off_t element_index;
204 const char *expected_result;
205 } test_partial_string_by_index_ds[] =
206 {
207 {
208 ETALON_PATH_STR,
209 -1,
210 "/test1://bla-bla/some/path/test2://bla-bla/some/path"
211 },
212 {
213 ETALON_PATH_STR,
214 -2,
215 "/test1://bla-bla/some/path/"
216 },
217 {
218 ETALON_PATH_STR,
219 -3,
220 "/"
221 },
222 {
223 ETALON_PATH_STR,
224 -4,
225 ""
226 },
227 {
228 ETALON_PATH_STR,
229 1,
230 "/"
231 },
232 {
233 ETALON_PATH_STR,
234 2,
235 "/test1://bla-bla/some/path/"
236 },
237 {
238 ETALON_PATH_STR,
239 3,
240 "/test1://bla-bla/some/path/test2://bla-bla/some/path"
241 },
242 {
243 ETALON_PATH_STR,
244 4,
245 ETALON_PATH_URL_STR
246 },
247 {
248 ETALON_PATH_STR,
249 5,
250 ETALON_PATH_URL_STR
251 },
252 };
253
254
255
256
257 START_PARAMETRIZED_TEST (test_partial_string_by_index, test_partial_string_by_index_ds)
258
259 {
260
261 vfs_path_t *vpath;
262 char *actual_result;
263 vpath = vfs_path_from_str_flags (data->input_string, VPF_USE_DEPRECATED_PARSER);
264
265
266 actual_result = vfs_path_to_str_elements_count (vpath, data->element_index);
267
268
269 mctest_assert_str_eq (actual_result, data->expected_result);
270 g_free (actual_result);
271
272 vfs_path_free (vpath, TRUE);
273 }
274
275 END_PARAMETRIZED_TEST
276
277
278
279 #ifdef HAVE_CHARSET
280
281
282 #define ETALON_STR "/path/to/file.ext/test1://#enc:KOI8-R"
283
284
285 START_TEST (test_vfs_path_encoding_at_end)
286
287 {
288
289 vfs_path_t *vpath;
290 const char *result;
291 const vfs_path_element_t *element;
292
293 vpath =
294 vfs_path_from_str_flags ("/path/to/file.ext#test1:/#enc:KOI8-R", VPF_USE_DEPRECATED_PARSER);
295
296
297 result = vfs_path_as_str (vpath);
298 element = vfs_path_get_by_index (vpath, -1);
299
300
301 mctest_assert_str_eq (element->path, "");
302 mctest_assert_not_null (element->encoding);
303 mctest_assert_str_eq (result, ETALON_STR);
304
305 vfs_path_free (vpath, TRUE);
306 }
307
308
309 END_TEST
310
311 #endif
312
313
314 int
315 main (void)
316 {
317 TCase *tc_core;
318
319 tc_core = tcase_create ("Core");
320
321 tcase_add_checked_fixture (tc_core, setup, teardown);
322
323
324 mctest_add_parameterized_test (tc_core, test_from_to_string, test_from_to_string_ds);
325 mctest_add_parameterized_test (tc_core, test_partial_string_by_index,
326 test_partial_string_by_index_ds);
327 #ifdef HAVE_CHARSET
328 tcase_add_test (tc_core, test_vfs_path_encoding_at_end);
329 #endif
330
331
332 return mctest_run_all (tc_core);
333 }
334
335