This source file includes following definitions.
- setup
- teardown
- read_list
- 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 #define TEST_SUITE_NAME "/src/vfs/ftpfs"
26
27 #include "tests/mctest.h"
28
29 #include <stdio.h>
30
31 #include "direntry.c"
32 #include "src/vfs/ftpfs/ftpfs_parse_ls.c"
33
34
35
36 static struct vfs_s_subclass ftpfs_subclass;
37 static struct vfs_class *me = VFS_CLASS (&ftpfs_subclass);
38
39 static struct vfs_s_super *super;
40
41
42
43
44 static void
45 setup (void)
46 {
47 vfs_init_subclass (&ftpfs_subclass, "ftpfs", VFSF_NOLINKS | VFSF_REMOTE | VFSF_USETMP, "ftp");
48
49 super = vfs_s_new_super (me);
50 super->name = g_strdup (PATH_SEP_STR);
51 super->root = vfs_s_new_inode (me, super, vfs_s_default_stat (me, S_IFDIR | 0755));
52 }
53
54
55
56
57 static void
58 teardown (void)
59 {
60 vfs_s_free_super (me, super);
61 }
62
63
64
65 static GSList *
66 read_list (const char *fname)
67 {
68 FILE *f;
69 char buf[BUF_MEDIUM];
70 GSList *ret = NULL;
71
72 f = fopen (fname, "r");
73 if (f == NULL)
74 return NULL;
75
76 while (fgets (buf, sizeof (buf), f) != NULL)
77 ret = g_slist_prepend (ret, g_strdup (buf));
78
79 fclose (f);
80
81 return ret;
82 }
83
84
85
86
87
88 static const struct test_ftpfs_parse_long_list_ds
89 {
90 const char *name;
91 } test_ftpfs_parse_long_list_ds[] =
92 {
93 {
94 "aix"
95 },
96 {
97 "ms"
98 }
99 };
100
101
102
103
104 START_PARAMETRIZED_TEST (test_ftpfs_parse_long_list, test_ftpfs_parse_long_list_ds)
105
106 {
107
108 char *name;
109 GSList *input, *parsed, *output;
110 GSList *parsed_iter, *output_iter;
111 int err_count;
112
113
114 name = g_strdup_printf ("%s/%s_list.input", TEST_DATA_DIR, data->name);
115 input = read_list (name);
116 g_free (name);
117 mctest_assert_not_null (input);
118
119 name = g_strdup_printf ("%s/%s_list.output", TEST_DATA_DIR, data->name);
120 output = read_list (name);
121 g_free (name);
122 mctest_assert_not_null (output);
123
124 parsed = ftpfs_parse_long_list (me, super->root, input, &err_count);
125
126
127 for (parsed_iter = parsed, output_iter = output;
128 parsed_iter != NULL && output_iter != NULL;
129 parsed_iter = g_slist_next (parsed_iter), output_iter = g_slist_next (output_iter))
130 mctest_assert_str_eq (VFS_ENTRY (parsed_iter->data)->name, (char *) output_iter->data);
131
132 mctest_assert_null (parsed_iter);
133 mctest_assert_null (output_iter);
134
135 for (parsed_iter = parsed, output_iter = output; parsed_iter != NULL;
136 parsed_iter = g_slist_next (parsed_iter))
137 vfs_s_free_entry (me, VFS_ENTRY (parsed_iter->data));
138
139 g_slist_free (parsed);
140
141 g_slist_free_full (input, g_free);
142 g_slist_free_full (output, g_free);
143 }
144
145 END_PARAMETRIZED_TEST
146
147
148
149
150 int
151 main (void)
152 {
153 TCase *tc_core;
154
155 tc_core = tcase_create ("Core");
156
157 tcase_add_checked_fixture (tc_core, setup, teardown);
158
159
160 mctest_add_parameterized_test (tc_core, test_ftpfs_parse_long_list,
161 test_ftpfs_parse_long_list_ds);
162
163
164 return mctest_run_all (tc_core);
165 }
166
167