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