This source file includes following definitions.
- my_get_current_dir
- mc_stat
- 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/vfs"
27
28 #include "tests/mctest.h"
29
30 #include <stdlib.h>
31
32 #include "lib/strutil.h"
33 #include "lib/util.h"
34 #include "lib/vfs/xdirentry.h"
35 #include "src/vfs/local/local.c"
36
37
38
39
40 char *
41 my_get_current_dir (void)
42 {
43 return g_strdup ("/some/path");
44 }
45
46
47
48 static gboolean mc_stat__is_2nd_call_different = FALSE;
49 static gboolean mc_stat__call_count = 0;
50
51
52 int
53 mc_stat (const vfs_path_t *vpath, struct stat *my_stat)
54 {
55 (void) vpath;
56
57 if (mc_stat__call_count++ > 1 && mc_stat__is_2nd_call_different)
58 {
59 my_stat->st_ino = 2;
60 my_stat->st_dev = 22;
61 }
62 else
63 {
64 my_stat->st_ino = 1;
65 my_stat->st_dev = 11;
66 }
67 if (mc_stat__call_count > 2)
68 {
69 mc_stat__call_count = 0;
70 }
71 return 0;
72 }
73
74
75
76
77 static void
78 setup (void)
79 {
80 str_init_strings (NULL);
81
82 vfs_init ();
83 vfs_init_localfs ();
84 vfs_setup_work_dir ();
85 }
86
87
88
89
90 static void
91 teardown (void)
92 {
93 vfs_shut ();
94 str_uninit_strings ();
95 }
96
97
98
99
100
101 static const struct test_vfs_setup_cwd_symlink_ds
102 {
103 gboolean is_2nd_call_different;
104 const char *expected_result;
105 } test_vfs_setup_cwd_symlink_ds[] =
106 {
107 {
108 TRUE,
109 "/some/path"
110 },
111 {
112 FALSE,
113 "/some/path2"
114 },
115 };
116
117
118
119
120 START_PARAMETRIZED_TEST (test_vfs_setup_cwd_symlink, test_vfs_setup_cwd_symlink_ds)
121
122 {
123
124 vfs_set_raw_current_dir (NULL);
125 mc_stat__is_2nd_call_different = data->is_2nd_call_different;
126 mc_stat__call_count = 0;
127 setenv ("PWD", "/some/path2", 1);
128
129
130 vfs_setup_cwd ();
131
132
133 mctest_assert_str_eq (vfs_get_current_dir (), data->expected_result);
134 }
135
136 END_PARAMETRIZED_TEST
137
138
139
140
141 int
142 main (void)
143 {
144 TCase *tc_core;
145
146 tc_core = tcase_create ("Core");
147
148 tcase_add_checked_fixture (tc_core, setup, teardown);
149
150
151 mctest_add_parameterized_test (tc_core, test_vfs_setup_cwd_symlink,
152 test_vfs_setup_cwd_symlink_ds);
153
154
155 return mctest_run_all (tc_core);
156 }
157
158