This source file includes following definitions.
- test_chdir
- setup
- teardown
- 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 <string.h>
31
32 #include "lib/global.h"
33 #include "lib/strutil.h"
34 #include "lib/vfs/xdirentry.h"
35 #include "lib/util.h"
36
37 #include "src/vfs/local/local.c"
38
39 static struct vfs_s_subclass vfs_test_subclass;
40 static struct vfs_class *vfs_test_ops = VFS_CLASS (&vfs_test_subclass);
41
42
43
44
45 static int
46 test_chdir (const vfs_path_t *vpath)
47 {
48 (void) vpath;
49
50 return 0;
51 }
52
53
54
55
56 static void
57 setup (void)
58 {
59 str_init_strings (NULL);
60
61 vfs_init ();
62 vfs_init_localfs ();
63 vfs_setup_work_dir ();
64
65 memset (&vfs_test_subclass, 0, sizeof (vfs_test_subclass));
66 vfs_init_class (vfs_test_ops, "testfs", VFSF_UNKNOWN, "test");
67 vfs_test_ops->chdir = test_chdir;
68 }
69
70
71
72
73 static void
74 teardown (void)
75 {
76 vfs_shut ();
77 str_uninit_strings ();
78 }
79
80
81
82
83 static const struct test_cd_ds
84 {
85 const char *input_initial_path;
86 const char *input_cd_path;
87 const vfs_flags_t input_class_flags;
88
89 const char *expected_cd_path;
90 } test_cd_ds[] = {
91 {
92
93 "/",
94 "/dev/some.file/test://",
95 VFSF_NOLINKS,
96 "/dev/some.file/test://",
97 },
98 {
99
100 "/",
101 "/dev/some.file/test://bla-bla",
102 VFSF_NOLINKS,
103 "/dev/some.file/test://bla-bla",
104 },
105 {
106
107 "/dev/some.file/test://bla-bla",
108 "..",
109 VFSF_NOLINKS,
110 "/dev/some.file/test://",
111 },
112 {
113
114 "/dev/some.file/test://",
115 "..",
116 VFSF_NOLINKS,
117 "/dev",
118 },
119 {
120
121 "/dev",
122 "..",
123 VFSF_NOLINKS,
124 "/",
125 },
126 {
127
128 "/",
129 "..",
130 VFSF_NOLINKS,
131 "/",
132 },
133 {
134
135 "/",
136 "/test://user:pass@host.net/path",
137 VFSF_NOLINKS | VFSF_REMOTE,
138 "/test://user:pass@host.net/path",
139 },
140 {
141
142 "/test://user:pass@host.net/path",
143 "..",
144 VFSF_NOLINKS | VFSF_REMOTE,
145 "/test://user:pass@host.net/",
146 },
147 {
148
149 "/test://user:pass@host.net/",
150 "..",
151 VFSF_NOLINKS | VFSF_REMOTE,
152 "/",
153 },
154 };
155
156
157 START_PARAMETRIZED_TEST (test_cd, test_cd_ds)
158 {
159
160 vfs_path_t *vpath;
161
162 vfs_test_ops->flags = data->input_class_flags;
163 vfs_register_class (vfs_test_ops);
164
165 vfs_set_raw_current_dir (vfs_path_from_str (data->input_initial_path));
166
167 vpath = vfs_path_from_str (data->input_cd_path);
168
169
170 mc_chdir (vpath);
171
172
173 {
174 char *actual_cd_path;
175
176 actual_cd_path = vfs_get_cwd ();
177 mctest_assert_str_eq (actual_cd_path, data->expected_cd_path);
178 g_free (actual_cd_path);
179 }
180 vfs_path_free (vpath, TRUE);
181
182 vfs_unregister_class (vfs_test_ops);
183 }
184 END_PARAMETRIZED_TEST
185
186
187
188 int
189 main (void)
190 {
191 TCase *tc_core;
192 char *cwd;
193
194 tc_core = tcase_create ("Core");
195
196
197 cwd = my_get_current_dir ();
198 g_setenv ("TEMP", cwd, TRUE);
199 g_free (cwd);
200
201 tcase_add_checked_fixture (tc_core, setup, teardown);
202
203
204 mctest_add_parameterized_test (tc_core, test_cd, test_cd_ds);
205
206
207 return mctest_run_all (tc_core);
208 }
209
210