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
84 static const struct test_cd_ds
85 {
86 const char *input_initial_path;
87 const char *input_cd_path;
88 const vfs_flags_t input_class_flags;
89
90 const char *expected_cd_path;
91 } test_cd_ds[] =
92 {
93 {
94 "/",
95 "/dev/some.file/test://",
96 VFSF_NOLINKS,
97 "/dev/some.file/test://"
98 },
99 {
100 "/",
101 "/dev/some.file/test://bla-bla",
102 VFSF_NOLINKS,
103 "/dev/some.file/test://bla-bla"
104 },
105 {
106 "/dev/some.file/test://bla-bla",
107 "..",
108 VFSF_NOLINKS,
109 "/dev/some.file/test://"
110 },
111 {
112 "/dev/some.file/test://",
113 "..",
114 VFSF_NOLINKS,
115 "/dev"
116 },
117 {
118 "/dev",
119 "..",
120 VFSF_NOLINKS,
121 "/"
122 },
123 {
124 "/",
125 "..",
126 VFSF_NOLINKS,
127 "/"
128 },
129 {
130 "/",
131 "/test://user:pass@host.net/path",
132 VFSF_NOLINKS | VFSF_REMOTE,
133 "/test://user:pass@host.net/path"
134 },
135 {
136 "/test://user:pass@host.net/path",
137 "..",
138 VFSF_NOLINKS | VFSF_REMOTE,
139 "/test://user:pass@host.net/"
140 },
141 {
142 "/test://user:pass@host.net/",
143 "..",
144 VFSF_NOLINKS | VFSF_REMOTE,
145 "/"
146 },
147 };
148
149
150
151
152 START_PARAMETRIZED_TEST (test_cd, test_cd_ds)
153
154 {
155
156 vfs_path_t *vpath;
157
158 vfs_test_ops->flags = data->input_class_flags;
159 vfs_register_class (vfs_test_ops);
160
161 vfs_set_raw_current_dir (vfs_path_from_str (data->input_initial_path));
162
163 vpath = vfs_path_from_str (data->input_cd_path);
164
165
166 mc_chdir (vpath);
167
168
169 {
170 char *actual_cd_path;
171
172 actual_cd_path = vfs_get_cwd ();
173 mctest_assert_str_eq (actual_cd_path, data->expected_cd_path);
174 g_free (actual_cd_path);
175 }
176 vfs_path_free (vpath, TRUE);
177
178 vfs_unregister_class (vfs_test_ops);
179 }
180
181 END_PARAMETRIZED_TEST
182
183
184
185
186 int
187 main (void)
188 {
189 TCase *tc_core;
190 char *cwd;
191
192 tc_core = tcase_create ("Core");
193
194
195 cwd = my_get_current_dir ();
196 g_setenv ("TEMP", cwd, TRUE);
197 g_free (cwd);
198
199 tcase_add_checked_fixture (tc_core, setup, teardown);
200
201
202 mctest_add_parameterized_test (tc_core, test_cd, test_cd_ds);
203
204
205 return mctest_run_all (tc_core);
206 }
207
208