This source file includes following definitions.
- mc_config_get_home_dir
- setup
- teardown
- test_init_vfs
- test_deinit_vfs
- 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
26 #define TEST_SUITE_NAME "/lib/vfs"
27
28 #include "tests/mctest.h"
29
30 #include "lib/charsets.h"
31
32 #include "lib/strutil.h"
33 #include "lib/vfs/xdirentry.h"
34 #include "lib/vfs/path.h"
35
36 #include "src/vfs/local/local.c"
37
38
39
40
41 const char *
42 mc_config_get_home_dir (void)
43 {
44 return "/mock/home";
45 }
46
47
48
49
50 static void
51 setup (void)
52 {
53 }
54
55
56
57
58 static void
59 teardown (void)
60 {
61 }
62
63
64
65 static void
66 test_init_vfs (const char *encoding)
67 {
68 str_init_strings (encoding);
69
70 vfs_init ();
71 vfs_init_localfs ();
72 vfs_setup_work_dir ();
73
74 mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
75
76 mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
77 load_codepages_list ();
78 }
79
80
81
82 static void
83 test_deinit_vfs (void)
84 {
85 free_codepages_list ();
86 str_uninit_strings ();
87 vfs_shut ();
88 }
89
90
91
92
93
94 static const struct test_path_recode_ds
95 {
96 const char *input_codepage;
97 const char *input_path;
98 const char *expected_element_path;
99 const char *expected_recoded_path;
100 } test_path_recode_ds[] =
101 {
102 {
103 "UTF-8",
104 "//",
105 "//",
106 "//"
107 },
108 {
109 "UTF-8",
110 "/#enc:KOI8-R/тестовый/путь",
111 "//",
112 "/#enc:KOI8-R/тестовый/путь"
113 },
114 {
115 "KOI8-R",
116 "/тестовый/путь",
117 "/тестовый/путь",
118 "/тестовый/путь"
119 },
120 {
121 "KOI8-R",
122 "/#enc:UTF-8//",
123 "/тестовый/путь",
124 "/#enc:UTF-8//"
125 },
126 {
127 "UTF-8",
128 "#enc:KOI8-R/bla-bla/some/path",
129 "/bla-bla/some/path",
130 "/#enc:KOI8-R/bla-bla/some/path"
131 },
132 };
133
134
135
136
137 START_PARAMETRIZED_TEST (test_path_recode, test_path_recode_ds)
138
139 {
140
141 vfs_path_t *vpath;
142 const char *element_path;
143 const char *vpath_str;
144
145 test_init_vfs (data->input_codepage);
146
147
148 vpath = vfs_path_from_str (data->input_path);
149 element_path = vfs_path_get_last_path_str (vpath);
150
151
152 vpath_str = vfs_path_as_str (vpath);
153 mctest_assert_ptr_ne (vpath, NULL);
154 mctest_assert_str_eq (element_path, data->expected_element_path);
155 mctest_assert_str_eq (vpath_str, data->expected_recoded_path);
156
157 vfs_path_free (vpath, TRUE);
158 test_deinit_vfs ();
159 }
160
161 END_PARAMETRIZED_TEST
162
163
164
165
166
167 static struct vfs_class vfs_test_ops1;
168
169
170
171 static const struct test_path_to_str_flags_ds
172 {
173 const char *input_path;
174 const vfs_path_flag_t input_from_str_flags;
175 const vfs_path_flag_t input_to_str_flags;
176 const char *expected_path;
177 } test_path_to_str_flags_ds[] =
178 {
179 {
180 "test1://user:passwd@127.0.0.1",
181 VPF_NO_CANON,
182 VPF_STRIP_PASSWORD,
183 "test1://user@127.0.0.1/"
184 },
185 {
186 "/test1://user:passwd@host.name/#enc:KOI8-R/тестовый/путь",
187 VPF_NONE,
188 VPF_STRIP_PASSWORD,
189 "/test1://user@host.name/#enc:KOI8-R/тестовый/путь"
190 },
191 {
192 "/test1://user:passwd@host.name/#enc:KOI8-R/тестовый/путь",
193 VPF_NONE,
194 VPF_RECODE,
195 "/test1://user:passwd@host.name//"
196 },
197 {
198 "/test1://user:passwd@host.name/#enc:KOI8-R/тестовый/путь",
199 VPF_NONE,
200 VPF_RECODE | VPF_STRIP_PASSWORD,
201 "/test1://user@host.name//"
202 },
203 {
204 "/mock/home/test/dir",
205 VPF_NONE,
206 VPF_STRIP_HOME,
207 "~/test/dir"
208 },
209 {
210 "/mock/home/test1://user:passwd@host.name/#enc:KOI8-R/тестовый/путь",
211 VPF_NONE,
212 VPF_STRIP_HOME | VPF_STRIP_PASSWORD,
213 "~/test1://user@host.name/#enc:KOI8-R/тестовый/путь"
214 },
215 {
216 "/mock/home/test1://user:passwd@host.name/#enc:KOI8-R/тестовый/путь",
217 VPF_NONE,
218 VPF_STRIP_HOME | VPF_STRIP_PASSWORD | VPF_HIDE_CHARSET,
219 "~/test1://user@host.name/тестовый/путь"
220 },
221 {
222 "/mock/home/test1://user:passwd@host.name/#enc:KOI8-R/тестовый/путь",
223 VPF_NONE,
224 VPF_STRIP_HOME | VPF_RECODE,
225 "~/test1://user:passwd@host.name//"
226 },
227 {
228 "/mock/home/test1://user:passwd@host.name/#enc:KOI8-R/тестовый/путь",
229 VPF_NONE,
230 VPF_STRIP_HOME | VPF_RECODE | VPF_STRIP_PASSWORD,
231 "~/test1://user@host.name//"
232 },
233 };
234
235
236
237
238 START_PARAMETRIZED_TEST (test_path_to_str_flags, test_path_to_str_flags_ds)
239
240 {
241
242 vfs_path_t *vpath;
243 char *str_path;
244
245 test_init_vfs ("UTF-8");
246
247 vfs_init_class (&vfs_test_ops1, "testfs1", VFSF_NOLINKS | VFSF_REMOTE, "test1");
248 vfs_register_class (&vfs_test_ops1);
249
250
251
252 vpath = vfs_path_from_str_flags (data->input_path, data->input_from_str_flags);
253 str_path = vfs_path_to_str_flags (vpath, 0, data->input_to_str_flags);
254
255
256 mctest_assert_str_eq (str_path, data->expected_path);
257
258 g_free (str_path);
259 vfs_path_free (vpath, TRUE);
260 test_deinit_vfs ();
261 }
262
263 END_PARAMETRIZED_TEST
264
265
266
267
268 int
269 main (void)
270 {
271 TCase *tc_core;
272
273 tc_core = tcase_create ("Core");
274
275 tcase_add_checked_fixture (tc_core, setup, teardown);
276
277
278 mctest_add_parameterized_test (tc_core, test_path_recode, test_path_recode_ds);
279 mctest_add_parameterized_test (tc_core, test_path_to_str_flags, test_path_to_str_flags_ds);
280
281
282 return mctest_run_all (tc_core);
283 }
284
285