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 static const struct test_ftpfs_parse_long_list_ds
88 {
89 const char *name;
90 } test_ftpfs_parse_long_list_ds[] = {
91 { "aix" },
92 { "ms" },
93 };
94
95
96 START_PARAMETRIZED_TEST (test_ftpfs_parse_long_list, test_ftpfs_parse_long_list_ds)
97 {
98
99 char *name;
100 GSList *input, *parsed, *output;
101 GSList *parsed_iter, *output_iter;
102 int err_count;
103
104
105 name = g_strdup_printf ("%s/%s_list.input", TEST_DATA_DIR, data->name);
106 input = read_list (name);
107 g_free (name);
108 mctest_assert_not_null (input);
109
110 name = g_strdup_printf ("%s/%s_list.output", TEST_DATA_DIR, data->name);
111 output = read_list (name);
112 g_free (name);
113 mctest_assert_not_null (output);
114
115 parsed = ftpfs_parse_long_list (me, super->root, input, &err_count);
116
117
118 for (parsed_iter = parsed, output_iter = output; parsed_iter != NULL && output_iter != NULL;
119 parsed_iter = g_slist_next (parsed_iter), output_iter = g_slist_next (output_iter))
120 mctest_assert_str_eq (VFS_ENTRY (parsed_iter->data)->name, (char *) output_iter->data);
121
122 mctest_assert_null (parsed_iter);
123 mctest_assert_null (output_iter);
124
125 for (parsed_iter = parsed, output_iter = output; parsed_iter != NULL;
126 parsed_iter = g_slist_next (parsed_iter))
127 vfs_s_free_entry (me, VFS_ENTRY (parsed_iter->data));
128
129 g_slist_free (parsed);
130
131 g_slist_free_full (input, g_free);
132 g_slist_free_full (output, g_free);
133 }
134 END_PARAMETRIZED_TEST
135
136
137
138 int
139 main (void)
140 {
141 TCase *tc_core;
142
143 tc_core = tcase_create ("Core");
144
145 tcase_add_checked_fixture (tc_core, setup, teardown);
146
147
148 mctest_add_parameterized_test (tc_core, test_ftpfs_parse_long_list,
149 test_ftpfs_parse_long_list_ds);
150
151
152 return mctest_run_all (tc_core);
153 }
154
155