This source file includes following definitions.
- test_chdir
- test_chdir__init
- test_chdir__deinit
- setup
- teardown
- 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 #define TEST_SUITE_NAME "/lib/vfs"
26
27 #include "tests/mctest.h"
28
29 #include <string.h>
30
31 #include "lib/strutil.h"
32 #include "lib/vfs/xdirentry.h"
33 #include "lib/vfs/path.h"
34
35 #include "src/vfs/local/local.c"
36
37
38 static struct vfs_s_subclass vfs_test_subclass1;
39 static struct vfs_class *vfs_test_ops1 = VFS_CLASS (&vfs_test_subclass1);
40
41 static int test_chdir (const vfs_path_t * vpath);
42
43
44
45
46 static vfs_path_t *test_chdir__vpath__captured;
47
48 static int test_chdir__return_value;
49
50
51 static int
52 test_chdir (const vfs_path_t * vpath)
53 {
54 test_chdir__vpath__captured = vfs_path_clone (vpath);
55 return test_chdir__return_value;
56 }
57
58 static void
59 test_chdir__init (void)
60 {
61 test_chdir__vpath__captured = NULL;
62 }
63
64 static void
65 test_chdir__deinit (void)
66 {
67 vfs_path_free (test_chdir__vpath__captured, TRUE);
68 }
69
70
71
72
73 static void
74 setup (void)
75 {
76 str_init_strings (NULL);
77
78 vfs_init ();
79 vfs_init_localfs ();
80 vfs_setup_work_dir ();
81
82 memset (&vfs_test_subclass1, 0, sizeof (vfs_test_subclass1));
83 vfs_init_class (vfs_test_ops1, "testfs1", VFSF_NOLINKS | VFSF_REMOTE, "test1");
84 vfs_test_ops1->chdir = test_chdir;
85 vfs_register_class (vfs_test_ops1);
86
87 mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
88
89 vfs_local_ops->chdir = test_chdir;
90
91 test_chdir__init ();
92 }
93
94
95
96
97 static void
98 teardown (void)
99 {
100 test_chdir__deinit ();
101
102 vfs_shut ();
103 str_uninit_strings ();
104 }
105
106
107
108
109 static const struct test_relative_cd_ds
110 {
111 const char *input_string;
112 const vfs_path_flag_t input_flags;
113 const char *expected_element_path;
114 } test_relative_cd_ds[] =
115 {
116 {
117 "/test1://user:pass@some.host:12345/path/to/dir",
118 VPF_NONE,
119 "path/to/dir"
120 },
121 {
122 "some-non-exists-dir",
123 VPF_NO_CANON,
124 "some-non-exists-dir"
125 },
126 };
127
128
129
130
131 START_PARAMETRIZED_TEST (test_relative_cd, test_relative_cd_ds)
132
133 {
134
135 vfs_path_t *vpath;
136 int actual_result;
137
138 test_chdir__return_value = 0;
139
140 vpath = vfs_path_from_str_flags (data->input_string, data->input_flags);
141
142
143 actual_result = mc_chdir (vpath);
144
145
146 {
147 const char *element_path;
148
149 ck_assert_int_eq (actual_result, 0);
150 element_path = vfs_path_get_last_path_str (vpath);
151 mctest_assert_str_eq (element_path, data->expected_element_path);
152 vfs_path_free (vpath, TRUE);
153 }
154 }
155
156 END_PARAMETRIZED_TEST
157
158
159
160
161
162
163
164
165 START_TEST (test_vpath_to_str_filter)
166
167 {
168
169 vfs_path_t *vpath, *last_vpath;
170 char *filtered_path;
171 const vfs_path_element_t *path_element;
172
173
174 vpath = vfs_path_from_str ("/test1://some.host/dir");
175 path_element = vfs_path_element_clone (vfs_path_get_by_index (vpath, -1));
176 vfs_path_free (vpath, TRUE);
177
178 last_vpath = vfs_path_new (TRUE);
179
180 vfs_path_add_element (last_vpath, path_element);
181
182 filtered_path = vfs_path_to_str_flags (last_vpath, 0,
183 VPF_STRIP_HOME | VPF_STRIP_PASSWORD | VPF_HIDE_CHARSET);
184
185
186 mctest_assert_str_eq (filtered_path, "test1://some.host/dir");
187
188 vfs_path_free (last_vpath, TRUE);
189 g_free (filtered_path);
190 }
191
192 END_TEST
193
194
195
196
197 int
198 main (void)
199 {
200 TCase *tc_core;
201 char *cwd;
202
203 tc_core = tcase_create ("Core");
204
205
206 cwd = g_get_current_dir ();
207 g_setenv ("TEMP", cwd, TRUE);
208 g_free (cwd);
209
210 tcase_add_checked_fixture (tc_core, setup, teardown);
211
212
213 mctest_add_parameterized_test (tc_core, test_relative_cd, test_relative_cd_ds);
214 tcase_add_test (tc_core, test_vpath_to_str_filter);
215
216
217 return mctest_run_all (tc_core);
218 }
219
220