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