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