This source file includes following definitions.
- 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/util"
27
28 #include "tests/mctest.h"
29
30 #include "lib/strutil.h"
31 #include "lib/vfs/vfs.h"
32 #include "src/vfs/local/local.c"
33
34 #include "lib/util.h"
35
36
37
38 static char resolved_path[PATH_MAX];
39
40
41
42
43 static void
44 setup (void)
45 {
46 str_init_strings (NULL);
47 vfs_init ();
48 vfs_init_localfs ();
49 vfs_setup_work_dir ();
50 }
51
52
53 static void
54 teardown (void)
55 {
56 vfs_shut ();
57 str_uninit_strings ();
58 }
59
60
61
62
63
64 static const struct data_source
65 {
66 const char *input_string;
67 const char *expected_string;
68 } data_source[] =
69 {
70
71 { "/", "/"},
72 { "/usr/bin", "/usr/bin" },
73 #ifdef HAVE_CHARSET
74 { "/" VFS_ENCODING_PREFIX "UTF-8/", "/" },
75 { "/" VFS_ENCODING_PREFIX "UTF-8/usr/bin", "/usr/bin" },
76 #else
77 { "/" VFS_ENCODING_PREFIX "UTF-8/", "/" VFS_ENCODING_PREFIX "UTF-8/" },
78 { "/" VFS_ENCODING_PREFIX "UTF-8/usr/bin", "/" VFS_ENCODING_PREFIX "UTF-8/usr/bin" },
79 #endif
80
81
82 { "usr/bin", "/usr/bin" },
83 #ifdef HAVE_CHARSET
84 { VFS_ENCODING_PREFIX "UTF-8/", "/" },
85 { VFS_ENCODING_PREFIX "UTF-8/usr/bin", "/usr/bin" }
86 #else
87 { VFS_ENCODING_PREFIX "UTF-8/", VFS_ENCODING_PREFIX "UTF-8/" },
88 { VFS_ENCODING_PREFIX "UTF-8/usr/bin", VFS_ENCODING_PREFIX "UTF-8/usr/bin" }
89 #endif
90 };
91
92
93
94
95 START_PARAMETRIZED_TEST (realpath_test, data_source)
96
97 {
98 int ret;
99
100
101
102 ret = chdir ("/");
103
104
105 if (mc_realpath (data->input_string, resolved_path) == NULL)
106 resolved_path[0] = '\0';
107
108
109 mctest_assert_str_eq (resolved_path, data->expected_string);
110
111 (void) ret;
112 }
113
114 END_PARAMETRIZED_TEST
115
116
117
118
119 int
120 main (void)
121 {
122 TCase *tc_core;
123 char *cwd;
124
125 tc_core = tcase_create ("Core");
126
127
128 cwd = my_get_current_dir ();
129 g_setenv ("TEMP", cwd, TRUE);
130 g_free (cwd);
131
132 tcase_add_checked_fixture (tc_core, setup, teardown);
133
134
135 mctest_add_parameterized_test (tc_core, realpath_test, data_source);
136
137
138 return mctest_run_all (tc_core);
139 }
140
141