- tests/src/execute__execute_with_vfs_arg.c
This source file includes following definitions.
- START_PARAMETRIZED_TEST
- START_TEST
- START_TEST
- 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 "/src"
27
28 #include "tests/mctest.h"
29
30 #include "execute__common.c"
31
32
33
34
35
36 static const struct the_file_is_local_ds
37 {
38 const char *input_path;
39 } the_file_is_local_ds[] =
40 {
41 {
42 NULL,
43 },
44 {
45 "/blabla",
46 },
47 };
48
49
50
51
52 START_PARAMETRIZED_TEST (the_file_is_local, the_file_is_local_ds)
53
54 {
55
56 vfs_path_t *filename_vpath;
57 filename_vpath = vfs_path_from_str (data->input_path);
58
59 vfs_file_is_local__return_value = TRUE;
60
61
62 execute_with_vfs_arg ("cmd_for_local_file", filename_vpath);
63
64
65 mctest_assert_str_eq (do_execute__lc_shell__captured, "cmd_for_local_file");
66 mctest_assert_str_eq (do_execute__command__captured, data->input_path);
67
68 ck_assert_int_eq (vfs_file_is_local__vpath__captured->len, 1);
69 {
70 const vfs_path_t *tmp_vpath;
71
72 tmp_vpath = (data->input_path == NULL) ? vfs_get_raw_current_dir () : filename_vpath;
73 mctest_assert_true (vfs_path_equal
74 (g_ptr_array_index (vfs_file_is_local__vpath__captured, 0), tmp_vpath));
75 }
76 ck_assert_int_eq (do_execute__flags__captured, EXECUTE_INTERNAL);
77 ck_assert_msg (mc_getlocalcopy__pathname_vpath__captured == NULL,
78 "\nFunction mc_getlocalcopy() shouldn't be called!");
79
80 vfs_path_free (filename_vpath, TRUE);
81 }
82
83 END_PARAMETRIZED_TEST
84
85
86
87
88
89
90 START_TEST (the_file_is_remote_but_empty)
91
92 {
93
94 vfs_path_t *filename_vpath;
95 filename_vpath = NULL;
96
97 vfs_file_is_local__return_value = FALSE;
98
99
100 execute_with_vfs_arg ("cmd_for_remote_file", filename_vpath);
101
102
103 mctest_assert_str_eq (do_execute__lc_shell__captured, NULL);
104 mctest_assert_str_eq (do_execute__command__captured, NULL);
105
106 ck_assert_int_eq (vfs_file_is_local__vpath__captured->len, 2);
107
108 mctest_assert_true (vfs_path_equal
109 (g_ptr_array_index (vfs_file_is_local__vpath__captured, 0),
110 vfs_get_raw_current_dir ()));
111 ck_assert_msg (g_ptr_array_index (vfs_file_is_local__vpath__captured, 1) == NULL,
112 "\nParameter for second call to vfs_file_is_local() should be NULL!");
113 ck_assert_msg (mc_getlocalcopy__pathname_vpath__captured == NULL,
114 "\nFunction mc_getlocalcopy() shouldn't be called!");
115
116 vfs_path_free (filename_vpath, TRUE);
117 }
118
119 END_TEST
120
121
122
123
124
125
126 START_TEST (the_file_is_remote_fail_to_create_local_copy)
127
128 {
129
130 vfs_path_t *filename_vpath;
131
132 filename_vpath = vfs_path_from_str ("/ftp://some.host/editme.txt");
133
134 vfs_file_is_local__return_value = FALSE;
135 mc_getlocalcopy__return_value = NULL;
136
137
138 execute_with_vfs_arg ("cmd_for_remote_file", filename_vpath);
139
140
141 mctest_assert_str_eq (do_execute__lc_shell__captured, NULL);
142 mctest_assert_str_eq (do_execute__command__captured, NULL);
143
144 ck_assert_int_eq (vfs_file_is_local__vpath__captured->len, 1);
145
146 mctest_assert_true (vfs_path_equal
147 (g_ptr_array_index (vfs_file_is_local__vpath__captured, 0),
148 filename_vpath));
149
150 mctest_assert_true (vfs_path_equal (mc_getlocalcopy__pathname_vpath__captured, filename_vpath));
151
152 mctest_assert_str_eq (message_title__captured, _("Error"));
153 mctest_assert_str_eq (message_text__captured,
154 _("Cannot fetch a local copy of /ftp://some.host/editme.txt"));
155
156
157 vfs_path_free (filename_vpath, TRUE);
158 }
159
160 END_TEST
161
162
163
164
165
166
167 START_TEST (the_file_is_remote)
168
169 {
170
171 vfs_path_t *filename_vpath, *local_vpath, *local_vpath_should_be_freeing;
172
173 filename_vpath = vfs_path_from_str ("/ftp://some.host/editme.txt");
174 local_vpath = vfs_path_from_str ("/tmp/blabla-editme.txt");
175 local_vpath_should_be_freeing = vfs_path_clone (local_vpath);
176
177 vfs_file_is_local__return_value = FALSE;
178 mc_getlocalcopy__return_value = local_vpath_should_be_freeing;
179
180
181 execute_with_vfs_arg ("cmd_for_remote_file", filename_vpath);
182
183
184 mctest_assert_str_eq (do_execute__lc_shell__captured, "cmd_for_remote_file");
185 mctest_assert_str_eq (do_execute__command__captured, "/tmp/blabla-editme.txt");
186
187 ck_assert_int_eq (vfs_file_is_local__vpath__captured->len, 1);
188
189 mctest_assert_true (vfs_path_equal
190 (g_ptr_array_index (vfs_file_is_local__vpath__captured, 0),
191 filename_vpath));
192
193 mctest_assert_true (vfs_path_equal (mc_getlocalcopy__pathname_vpath__captured, filename_vpath));
194
195 ck_assert_int_eq (mc_stat__vpath__captured->len, 2);
196
197 mctest_assert_true (vfs_path_equal
198 (g_ptr_array_index (mc_stat__vpath__captured, 0), local_vpath));
199 mctest_assert_true (vfs_path_equal
200 (g_ptr_array_index (mc_stat__vpath__captured, 0),
201 g_ptr_array_index (mc_stat__vpath__captured, 1)));
202
203 mctest_assert_true (vfs_path_equal
204 (mc_ungetlocalcopy__pathname_vpath__captured, filename_vpath));
205
206 mctest_assert_true (vfs_path_equal (mc_ungetlocalcopy__local_vpath__captured, local_vpath));
207
208 vfs_path_free (filename_vpath, TRUE);
209 vfs_path_free (local_vpath, TRUE);
210 }
211
212 END_TEST
213
214
215
216
217 int
218 main (void)
219 {
220 TCase *tc_core;
221
222 tc_core = tcase_create ("Core");
223
224 tcase_add_checked_fixture (tc_core, setup, teardown);
225
226
227 mctest_add_parameterized_test (tc_core, the_file_is_local, the_file_is_local_ds);
228 tcase_add_test (tc_core, the_file_is_remote_but_empty);
229 tcase_add_test (tc_core, the_file_is_remote_fail_to_create_local_copy);
230 tcase_add_test (tc_core, the_file_is_remote);
231
232
233 return mctest_run_all (tc_core);
234 }
235
236