This source file includes following definitions.
- test_which
- 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 "lib/strutil.h"
31 #include "lib/vfs/xdirentry.h"
32 #include "lib/vfs/vfs.c"
33
34 #include "src/vfs/local/local.c"
35
36 static struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3;
37
38
39
40 static int
41 test_which (struct vfs_class *me, const char *path)
42 {
43 (void) me;
44
45 if ((strcmp (path, "test_1:") == 0) ||
46 (strcmp (path, "test_2:") == 0) ||
47 (strcmp (path, "test_3:") == 0) || (strcmp (path, "test_4:") == 0))
48 return 1;
49 return -1;
50 }
51
52
53
54
55 static void
56 setup (void)
57 {
58 str_init_strings (NULL);
59
60 vfs_init ();
61 vfs_init_localfs ();
62 vfs_setup_work_dir ();
63
64 vfs_init_class (&vfs_test_ops1, "testfs1", VFSF_NOLINKS | VFSF_REMOTE, "test1");
65 vfs_test_ops1.which = test_which;
66 vfs_register_class (&vfs_test_ops1);
67
68 vfs_init_class (&vfs_test_ops2, "testfs2", VFSF_UNKNOWN, "test2");
69 vfs_register_class (&vfs_test_ops2);
70
71 vfs_init_class (&vfs_test_ops3, "testfs3", VFSF_UNKNOWN, "test3");
72 vfs_register_class (&vfs_test_ops3);
73 }
74
75
76
77
78 static void
79 teardown (void)
80 {
81 vfs_shut ();
82 str_uninit_strings ();
83 }
84
85
86
87
88
89 static const struct test_vfs_prefix_to_class_ds
90 {
91 const char *input_string;
92 const struct vfs_class *expected_result;
93 } test_vfs_prefix_to_class_ds[] =
94 {
95 {
96 "test_1:",
97 &vfs_test_ops1
98 },
99 {
100 "test_2:",
101 &vfs_test_ops1
102 },
103 {
104 "test_3:",
105 &vfs_test_ops1
106 },
107 {
108 "test_4:",
109 &vfs_test_ops1
110 },
111 {
112 "test2:",
113 &vfs_test_ops2
114 },
115 {
116 "test3:",
117 &vfs_test_ops3
118 },
119 {
120 "test1:",
121 NULL
122 },
123 {
124 "test_5:",
125 NULL
126 },
127 {
128 "test4:",
129 NULL
130 },
131 };
132
133
134
135
136 START_PARAMETRIZED_TEST (test_vfs_prefix_to_class, test_vfs_prefix_to_class_ds)
137
138 {
139
140 struct vfs_class *actual_result;
141
142
143 actual_result = vfs_prefix_to_class ((char *) data->input_string);
144
145
146 mctest_assert_ptr_eq (actual_result, data->expected_result);
147 }
148
149 END_PARAMETRIZED_TEST
150
151
152
153
154 int
155 main (void)
156 {
157 TCase *tc_core;
158
159 tc_core = tcase_create ("Core");
160
161 tcase_add_checked_fixture (tc_core, setup, teardown);
162
163
164 mctest_add_parameterized_test (tc_core, test_vfs_prefix_to_class, test_vfs_prefix_to_class_ds);
165
166
167 return mctest_run_all (tc_core);
168 }
169
170