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 load_codepages_list ();
76 }
77
78
79
80 static void
81 test_deinit_vfs (void)
82 {
83 free_codepages_list ();
84 str_uninit_strings ();
85 vfs_shut ();
86 }
87
88
89
90
91 static const struct test_path_recode_ds
92 {
93 const char *input_codepage;
94 const char *input_path;
95 const char *expected_element_path;
96 const char *expected_recoded_path;
97 } test_path_recode_ds[] = {
98 {
99
100 "UTF-8",
101 "/\xD4\xC5\xD3\xD4\xCF\xD7\xD9\xCA/\xD0\xD5\xD4\xD8",
102 "/\xD4\xC5\xD3\xD4\xCF\xD7\xD9\xCA/\xD0\xD5\xD4\xD8",
103 "/\xD4\xC5\xD3\xD4\xCF\xD7\xD9\xCA/\xD0\xD5\xD4\xD8",
104 },
105 {
106
107 "UTF-8",
108 "/#enc:KOI8-R/тестовый/путь",
109 "/\xD4\xC5\xD3\xD4\xCF\xD7\xD9\xCA/\xD0\xD5\xD4\xD8",
110 "/#enc:KOI8-R/тестовый/путь",
111 },
112 {
113
114 "KOI8-R",
115 "/тестовый/путь",
116 "/тестовый/путь",
117 "/тестовый/путь",
118 },
119 {
120
121 "KOI8-R",
122 "/#enc:UTF-8/\xD4\xC5\xD3\xD4\xCF\xD7\xD9\xCA/\xD0\xD5\xD4\xD8",
123 "/тестовый/путь",
124 "/#enc:UTF-8/\xD4\xC5\xD3\xD4\xCF\xD7\xD9\xCA/\xD0\xD5\xD4\xD8",
125 },
126 {
127
128 "UTF-8",
129 "#enc:KOI8-R/bla-bla/some/path",
130 "/bla-bla/some/path",
131 "/#enc:KOI8-R/bla-bla/some/path",
132 },
133 };
134
135
136 START_PARAMETRIZED_TEST (test_path_recode, test_path_recode_ds)
137 {
138
139 vfs_path_t *vpath;
140 const char *element_path;
141 const char *vpath_str;
142
143 test_init_vfs (data->input_codepage);
144
145
146 vpath = vfs_path_from_str (data->input_path);
147 element_path = vfs_path_get_last_path_str (vpath);
148
149
150 vpath_str = vfs_path_as_str (vpath);
151 mctest_assert_ptr_ne (vpath, NULL);
152 mctest_assert_str_eq (element_path, data->expected_element_path);
153 mctest_assert_str_eq (vpath_str, data->expected_recoded_path);
154
155 vfs_path_free (vpath, TRUE);
156 test_deinit_vfs ();
157 }
158 END_PARAMETRIZED_TEST
159
160
161
162 static struct vfs_class vfs_test_ops1;
163
164
165 static const struct test_path_to_str_flags_ds
166 {
167 const char *input_path;
168 const vfs_path_flag_t input_from_str_flags;
169 const vfs_path_flag_t input_to_str_flags;
170 const char *expected_path;
171 } test_path_to_str_flags_ds[] = {
172 {
173
174 "test1://user:passwd@127.0.0.1",
175 VPF_NO_CANON,
176 VPF_STRIP_PASSWORD,
177 "test1://user@127.0.0.1/",
178 },
179 {
180
181 "/test1://user:passwd@host.name/#enc:KOI8-R/тестовый/путь",
182 VPF_NONE,
183 VPF_STRIP_PASSWORD,
184 "/test1://user@host.name/#enc:KOI8-R/тестовый/путь",
185 },
186 {
187
188 "/test1://user:passwd@host.name/#enc:KOI8-R/тестовый/путь",
189 VPF_NONE,
190 VPF_RECODE,
191 "/test1://user:passwd@host.name/\xD4\xC5\xD3\xD4\xCF\xD7\xD9\xCA/\xD0\xD5\xD4\xD8",
192 },
193 {
194
195 "/test1://user:passwd@host.name/#enc:KOI8-R/тестовый/путь",
196 VPF_NONE,
197 VPF_RECODE | VPF_STRIP_PASSWORD,
198 "/test1://user@host.name/\xD4\xC5\xD3\xD4\xCF\xD7\xD9\xCA/\xD0\xD5\xD4\xD8",
199 },
200 {
201
202 "/mock/home/test/dir",
203 VPF_NONE,
204 VPF_STRIP_HOME,
205 "~/test/dir",
206 },
207 {
208
209 "/mock/home/test1://user:passwd@host.name/#enc:KOI8-R/тестовый/путь",
210 VPF_NONE,
211 VPF_STRIP_HOME | VPF_STRIP_PASSWORD,
212 "~/test1://user@host.name/#enc:KOI8-R/тестовый/путь",
213 },
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
223 "/mock/home/test1://user:passwd@host.name/#enc:KOI8-R/тестовый/путь",
224 VPF_NONE,
225 VPF_STRIP_HOME | VPF_RECODE,
226 "~/test1://user:passwd@host.name/\xD4\xC5\xD3\xD4\xCF\xD7\xD9\xCA/\xD0\xD5\xD4\xD8",
227 },
228 {
229
230 "/mock/home/test1://user:passwd@host.name/#enc:KOI8-R/тестовый/путь",
231 VPF_NONE,
232 VPF_STRIP_HOME | VPF_RECODE | VPF_STRIP_PASSWORD,
233 "~/test1://user@host.name/\xD4\xC5\xD3\xD4\xCF\xD7\xD9\xCA/\xD0\xD5\xD4\xD8",
234 },
235 };
236
237
238 START_PARAMETRIZED_TEST (test_path_to_str_flags, test_path_to_str_flags_ds)
239 {
240
241 vfs_path_t *vpath;
242 char *str_path;
243
244 test_init_vfs ("UTF-8");
245
246 vfs_init_class (&vfs_test_ops1, "testfs1", VFSF_NOLINKS | VFSF_REMOTE, "test1");
247 vfs_register_class (&vfs_test_ops1);
248
249
250
251 vpath = vfs_path_from_str_flags (data->input_path, data->input_from_str_flags);
252 str_path = vfs_path_to_str_flags (vpath, 0, data->input_to_str_flags);
253
254
255 mctest_assert_str_eq (str_path, data->expected_path);
256
257 g_free (str_path);
258 vfs_path_free (vpath, TRUE);
259 test_deinit_vfs ();
260 }
261 END_PARAMETRIZED_TEST
262
263
264
265 int
266 main (void)
267 {
268 TCase *tc_core;
269
270 tc_core = tcase_create ("Core");
271
272 tcase_add_checked_fixture (tc_core, setup, teardown);
273
274
275 mctest_add_parameterized_test (tc_core, test_path_recode, test_path_recode_ds);
276 mctest_add_parameterized_test (tc_core, test_path_to_str_flags, test_path_to_str_flags_ds);
277
278
279 return mctest_run_all (tc_core);
280 }
281
282