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 static const struct data_source
64 {
65 const char *input_string;
66 const char *expected_string;
67 } data_source[] = {
68
69 { "/", "/" },
70 { "/usr/bin", "/usr/bin" },
71 #ifdef HAVE_CHARSET
72 { "/" VFS_ENCODING_PREFIX "UTF-8/", "/" },
73 { "/" VFS_ENCODING_PREFIX "UTF-8/usr/bin", "/usr/bin" },
74 #else
75 { "/" VFS_ENCODING_PREFIX "UTF-8/", "/" VFS_ENCODING_PREFIX "UTF-8/" },
76 { "/" VFS_ENCODING_PREFIX "UTF-8/usr/bin", "/" VFS_ENCODING_PREFIX "UTF-8/usr/bin" },
77 #endif
78
79
80 { "usr/bin", "/usr/bin" },
81 #ifdef HAVE_CHARSET
82 { VFS_ENCODING_PREFIX "UTF-8/", "/" },
83 { VFS_ENCODING_PREFIX "UTF-8/usr/bin", "/usr/bin" },
84 #else
85 { VFS_ENCODING_PREFIX "UTF-8/", VFS_ENCODING_PREFIX "UTF-8/" },
86 { VFS_ENCODING_PREFIX "UTF-8/usr/bin", VFS_ENCODING_PREFIX "UTF-8/usr/bin" },
87 #endif
88 };
89
90
91 START_PARAMETRIZED_TEST (realpath_test, data_source)
92 {
93 int ret;
94
95
96
97 ret = chdir ("/");
98
99
100 if (mc_realpath (data->input_string, resolved_path) == NULL)
101 resolved_path[0] = '\0';
102
103
104 mctest_assert_str_eq (resolved_path, data->expected_string);
105
106 (void) ret;
107 }
108 END_PARAMETRIZED_TEST
109
110
111
112 int
113 main (void)
114 {
115 TCase *tc_core;
116 char *cwd;
117
118 tc_core = tcase_create ("Core");
119
120
121 cwd = my_get_current_dir ();
122 g_setenv ("TEMP", cwd, TRUE);
123 g_free (cwd);
124
125 tcase_add_checked_fixture (tc_core, setup, teardown);
126
127
128 mctest_add_parameterized_test (tc_core, realpath_test, data_source);
129
130
131 return mctest_run_all (tc_core);
132 }
133
134