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
92 static const struct test_path_recode_ds
93 {
94 const char *input_codepage;
95 const char *input_path;
96 const char *expected_element_path;
97 const char *expected_recoded_path;
98 } test_path_recode_ds[] =
99 {
100 {
101 "UTF-8",
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 "/\xD4\xC5\xD3\xD4\xCF\xD7\xD9\xCA/\xD0\xD5\xD4\xD8"
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 "KOI8-R",
114 "/тестовый/путь",
115 "/тестовый/путь",
116 "/тестовый/путь"
117 },
118 {
119 "KOI8-R",
120 "/#enc:UTF-8/\xD4\xC5\xD3\xD4\xCF\xD7\xD9\xCA/\xD0\xD5\xD4\xD8",
121 "/тестовый/путь",
122 "/#enc:UTF-8/\xD4\xC5\xD3\xD4\xCF\xD7\xD9\xCA/\xD0\xD5\xD4\xD8"
123 },
124 {
125 "UTF-8",
126 "#enc:KOI8-R/bla-bla/some/path",
127 "/bla-bla/some/path",
128 "/#enc:KOI8-R/bla-bla/some/path"
129 },
130 };
131
132
133
134
135 START_PARAMETRIZED_TEST (test_path_recode, test_path_recode_ds)
136
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
159 END_PARAMETRIZED_TEST
160
161
162
163
164
165 static struct vfs_class vfs_test_ops1;
166
167
168
169 static const struct test_path_to_str_flags_ds
170 {
171 const char *input_path;
172 const vfs_path_flag_t input_from_str_flags;
173 const vfs_path_flag_t input_to_str_flags;
174 const char *expected_path;
175 } test_path_to_str_flags_ds[] =
176 {
177 {
178 "test1://user:passwd@127.0.0.1",
179 VPF_NO_CANON,
180 VPF_STRIP_PASSWORD,
181 "test1://user@127.0.0.1/"
182 },
183 {
184 "/test1://user:passwd@host.name/#enc:KOI8-R/тестовый/путь",
185 VPF_NONE,
186 VPF_STRIP_PASSWORD,
187 "/test1://user@host.name/#enc:KOI8-R/тестовый/путь"
188 },
189 {
190 "/test1://user:passwd@host.name/#enc:KOI8-R/тестовый/путь",
191 VPF_NONE,
192 VPF_RECODE,
193 "/test1://user:passwd@host.name/\xD4\xC5\xD3\xD4\xCF\xD7\xD9\xCA/\xD0\xD5\xD4\xD8"
194 },
195 {
196 "/test1://user:passwd@host.name/#enc:KOI8-R/тестовый/путь",
197 VPF_NONE,
198 VPF_RECODE | VPF_STRIP_PASSWORD,
199 "/test1://user@host.name/\xD4\xC5\xD3\xD4\xCF\xD7\xD9\xCA/\xD0\xD5\xD4\xD8"
200 },
201 {
202 "/mock/home/test/dir",
203 VPF_NONE,
204 VPF_STRIP_HOME,
205 "~/test/dir"
206 },
207 {
208 "/mock/home/test1://user:passwd@host.name/#enc:KOI8-R/тестовый/путь",
209 VPF_NONE,
210 VPF_STRIP_HOME | VPF_STRIP_PASSWORD,
211 "~/test1://user@host.name/#enc:KOI8-R/тестовый/путь"
212 },
213 {
214 "/mock/home/test1://user:passwd@host.name/#enc:KOI8-R/тестовый/путь",
215 VPF_NONE,
216 VPF_STRIP_HOME | VPF_STRIP_PASSWORD | VPF_HIDE_CHARSET,
217 "~/test1://user@host.name/тестовый/путь"
218 },
219 {
220 "/mock/home/test1://user:passwd@host.name/#enc:KOI8-R/тестовый/путь",
221 VPF_NONE,
222 VPF_STRIP_HOME | VPF_RECODE,
223 "~/test1://user:passwd@host.name/\xD4\xC5\xD3\xD4\xCF\xD7\xD9\xCA/\xD0\xD5\xD4\xD8"
224 },
225 {
226 "/mock/home/test1://user:passwd@host.name/#enc:KOI8-R/тестовый/путь",
227 VPF_NONE,
228 VPF_STRIP_HOME | VPF_RECODE | VPF_STRIP_PASSWORD,
229 "~/test1://user@host.name/\xD4\xC5\xD3\xD4\xCF\xD7\xD9\xCA/\xD0\xD5\xD4\xD8"
230 },
231 };
232
233
234
235
236 START_PARAMETRIZED_TEST (test_path_to_str_flags, test_path_to_str_flags_ds)
237
238 {
239
240 vfs_path_t *vpath;
241 char *str_path;
242
243 test_init_vfs ("UTF-8");
244
245 vfs_init_class (&vfs_test_ops1, "testfs1", VFSF_NOLINKS | VFSF_REMOTE, "test1");
246 vfs_register_class (&vfs_test_ops1);
247
248
249
250 vpath = vfs_path_from_str_flags (data->input_path, data->input_from_str_flags);
251 str_path = vfs_path_to_str_flags (vpath, 0, data->input_to_str_flags);
252
253
254 mctest_assert_str_eq (str_path, data->expected_path);
255
256 g_free (str_path);
257 vfs_path_free (vpath, TRUE);
258 test_deinit_vfs ();
259 }
260
261 END_PARAMETRIZED_TEST
262
263
264
265
266 int
267 main (void)
268 {
269 TCase *tc_core;
270
271 tc_core = tcase_create ("Core");
272
273 tcase_add_checked_fixture (tc_core, setup, teardown);
274
275
276 mctest_add_parameterized_test (tc_core, test_path_recode, test_path_recode_ds);
277 mctest_add_parameterized_test (tc_core, test_path_to_str_flags, test_path_to_str_flags_ds);
278
279
280 return mctest_run_all (tc_core);
281 }
282
283