This source file includes following definitions.
- test1_mock_open_archive
- test1_mock_archive_same
- setup
- teardown
- vfs_die
- START_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/direntry.c"
32
33 #include "src/vfs/local/local.c"
34
35 #define ARCH_NAME "/path/to/some/file.ext"
36 #define ETALON_PATH "path/to/test1_file.ext"
37 #define ETALON_VFS_NAME "#test2:user:pass@host.net"
38 #define ETALON_VFS_URL_NAME "test2://user:pass@host.net"
39
40 static struct vfs_s_subclass test_subclass1, test_subclass2, test_subclass3;
41 static struct vfs_class *vfs_test_ops1 = VFS_CLASS (&test_subclass1);
42 static struct vfs_class *vfs_test_ops2 = VFS_CLASS (&test_subclass2);
43 static struct vfs_class *vfs_test_ops3 = VFS_CLASS (&test_subclass3);
44
45
46
47 static int
48 test1_mock_open_archive (struct vfs_s_super *super, const vfs_path_t *vpath,
49 const vfs_path_element_t *vpath_element)
50 {
51 struct vfs_s_inode *root;
52
53 mctest_assert_str_eq (vfs_path_as_str (vpath), "/" ETALON_VFS_URL_NAME ARCH_NAME);
54
55 super->name = g_strdup (vfs_path_as_str (vpath));
56 root = vfs_s_new_inode (vpath_element->class, super, NULL);
57 super->root = root;
58 return 0;
59 }
60
61
62
63 static int
64 test1_mock_archive_same (const vfs_path_element_t *vpath_element, struct vfs_s_super *super,
65 const vfs_path_t *vpath, void *cookie)
66 {
67 const char *path;
68
69 (void) vpath_element;
70 (void) super;
71 (void) cookie;
72
73 path = vfs_path_get_last_path_str (vpath);
74 return (strcmp (ARCH_NAME, path) != 0 ? 0 : 1);
75 }
76
77
78
79
80 static void
81 setup (void)
82 {
83 str_init_strings (NULL);
84
85 vfs_init ();
86 vfs_init_localfs ();
87 vfs_setup_work_dir ();
88
89 vfs_init_subclass (&test_subclass1, "testfs1", VFSF_NOLINKS | VFSF_REMOTE, "test1");
90 test_subclass1.open_archive = test1_mock_open_archive;
91 test_subclass1.archive_same = test1_mock_archive_same;
92 test_subclass1.archive_check = NULL;
93 vfs_register_class (vfs_test_ops1);
94
95 vfs_init_subclass (&test_subclass2, "testfs2", VFSF_UNKNOWN, "test2");
96 vfs_register_class (vfs_test_ops2);
97
98 vfs_init_subclass (&test_subclass3, "testfs3", VFSF_UNKNOWN, "test3");
99 vfs_register_class (vfs_test_ops3);
100 }
101
102
103
104
105 static void
106 teardown (void)
107 {
108 vfs_shut ();
109 str_uninit_strings ();
110 }
111
112
113 void
114 vfs_die (const char *m)
115 {
116 printf ("VFS_DIE: '%s'\n", m);
117 }
118
119
120
121
122
123 START_TEST (test_vfs_s_get_path)
124
125 {
126
127 struct vfs_s_super *archive;
128 const char *result;
129
130
131 vfs_path_t *vpath =
132 vfs_path_from_str_flags ("/" ETALON_VFS_NAME ARCH_NAME "#test1:/" ETALON_PATH,
133 VPF_USE_DEPRECATED_PARSER);
134
135 result = vfs_s_get_path (vpath, &archive, 0);
136
137
138 mctest_assert_str_eq (result, ETALON_PATH);
139 mctest_assert_str_eq (archive->name, "/" ETALON_VFS_URL_NAME ARCH_NAME);
140
141 g_free (vpath);
142
143 }
144
145 END_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 tcase_add_test (tc_core, test_vfs_s_get_path);
161
162
163 return mctest_run_all (tc_core);
164 }
165
166