2 src - tests for execute_with_vfs_arg() function
5 The Free Software Foundation, Inc.
8 Slava Zanko <slavazanko@gmail.com>, 2013
10 This file is part of the Midnight Commander.
12 The Midnight Commander is free software: you can redistribute it
13 and/or modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation, either version 3 of the License,
15 or (at your option) any later version.
17 The Midnight Commander is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #define TEST_SUITE_NAME "/src"
28 #include "tests/mctest.h"
30 #include "execute__common.c"
32 /* --------------------------------------------------------------------------------------------- */
34 /* @DataSource("the_file_is_local_ds") */
36 static const struct the_file_is_local_ds
38 const char *input_path
;
39 } the_file_is_local_ds
[] =
50 /* @Test(dataSource = "the_file_is_local_ds") */
52 START_PARAMETRIZED_TEST (the_file_is_local
, the_file_is_local_ds
)
56 vfs_path_t
*filename_vpath
;
57 filename_vpath
= vfs_path_from_str (data
->input_path
);
59 vfs_file_is_local__return_value
= TRUE
;
62 execute_with_vfs_arg ("cmd_for_local_file", filename_vpath
);
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
);
68 mctest_assert_int_eq (vfs_file_is_local__vpath__captured
->len
, 1);
70 const vfs_path_t
*tmp_vpath
;
72 tmp_vpath
= (data
->input_path
== NULL
) ? vfs_get_raw_current_dir () : filename_vpath
;
73 mctest_assert_int_eq (vfs_path_equal
74 (g_ptr_array_index (vfs_file_is_local__vpath__captured
, 0),
77 mctest_assert_int_eq (do_execute__flags__captured
, EXECUTE_INTERNAL
);
78 fail_unless (mc_getlocalcopy__pathname_vpath__captured
== NULL
,
79 "\nFunction mc_getlocalcopy() shouldn't be called!");
81 vfs_path_free (filename_vpath
);
87 /* --------------------------------------------------------------------------------------------- */
91 START_TEST (the_file_is_remote_but_empty
)
95 vfs_path_t
*filename_vpath
;
96 filename_vpath
= NULL
;
98 vfs_file_is_local__return_value
= FALSE
;
101 execute_with_vfs_arg ("cmd_for_remote_file", filename_vpath
);
104 mctest_assert_str_eq (do_execute__lc_shell__captured
, NULL
);
105 mctest_assert_str_eq (do_execute__command__captured
, NULL
);
107 mctest_assert_int_eq (vfs_file_is_local__vpath__captured
->len
, 2);
109 mctest_assert_int_eq (vfs_path_equal
110 (g_ptr_array_index (vfs_file_is_local__vpath__captured
, 0),
111 vfs_get_raw_current_dir ()), TRUE
);
112 fail_unless (g_ptr_array_index (vfs_file_is_local__vpath__captured
, 1) == NULL
,
113 "\nParameter for second call to vfs_file_is_local() should be NULL!");
114 fail_unless (mc_getlocalcopy__pathname_vpath__captured
== NULL
,
115 "\nFunction mc_getlocalcopy() shouldn't be called!");
117 vfs_path_free (filename_vpath
);
123 /* --------------------------------------------------------------------------------------------- */
127 START_TEST (the_file_is_remote_fail_to_create_local_copy
)
131 vfs_path_t
*filename_vpath
;
133 filename_vpath
= vfs_path_from_str ("/ftp://some.host/editme.txt");
135 vfs_file_is_local__return_value
= FALSE
;
136 mc_getlocalcopy__return_value
= NULL
;
139 execute_with_vfs_arg ("cmd_for_remote_file", filename_vpath
);
142 mctest_assert_str_eq (do_execute__lc_shell__captured
, NULL
);
143 mctest_assert_str_eq (do_execute__command__captured
, NULL
);
145 mctest_assert_int_eq (vfs_file_is_local__vpath__captured
->len
, 1);
147 mctest_assert_int_eq (vfs_path_equal
148 (g_ptr_array_index (vfs_file_is_local__vpath__captured
, 0),
149 filename_vpath
), TRUE
);
151 mctest_assert_int_eq (vfs_path_equal
152 (mc_getlocalcopy__pathname_vpath__captured
, filename_vpath
), TRUE
);
154 mctest_assert_str_eq (message_title__captured
, _("Error"));
155 mctest_assert_str_eq (message_text__captured
,
156 _("Cannot fetch a local copy of /ftp://some.host/editme.txt"));
159 vfs_path_free (filename_vpath
);
165 /* --------------------------------------------------------------------------------------------- */
169 START_TEST (the_file_is_remote
)
173 vfs_path_t
*filename_vpath
, *local_vpath
, *local_vpath_should_be_freeing
;
175 filename_vpath
= vfs_path_from_str ("/ftp://some.host/editme.txt");
176 local_vpath
= vfs_path_from_str ("/tmp/blabla-editme.txt");
177 local_vpath_should_be_freeing
= vfs_path_clone (local_vpath
);
179 vfs_file_is_local__return_value
= FALSE
;
180 mc_getlocalcopy__return_value
= local_vpath_should_be_freeing
;
183 execute_with_vfs_arg ("cmd_for_remote_file", filename_vpath
);
186 mctest_assert_str_eq (do_execute__lc_shell__captured
, "cmd_for_remote_file");
187 mctest_assert_str_eq (do_execute__command__captured
, "/tmp/blabla-editme.txt");
189 mctest_assert_int_eq (vfs_file_is_local__vpath__captured
->len
, 1);
191 mctest_assert_int_eq (vfs_path_equal
192 (g_ptr_array_index (vfs_file_is_local__vpath__captured
, 0),
193 filename_vpath
), TRUE
);
195 mctest_assert_int_eq (vfs_path_equal
196 (mc_getlocalcopy__pathname_vpath__captured
, filename_vpath
), TRUE
);
198 mctest_assert_int_eq (mc_stat__vpath__captured
->len
, 2);
200 mctest_assert_int_eq (vfs_path_equal
201 (g_ptr_array_index (mc_stat__vpath__captured
, 0), local_vpath
), TRUE
);
202 mctest_assert_int_eq (vfs_path_equal
203 (g_ptr_array_index (mc_stat__vpath__captured
, 0),
204 g_ptr_array_index (mc_stat__vpath__captured
, 1)), TRUE
);
206 mctest_assert_int_eq (vfs_path_equal
207 (mc_ungetlocalcopy__pathname_vpath__captured
, filename_vpath
), TRUE
);
209 mctest_assert_int_eq (vfs_path_equal (mc_ungetlocalcopy__local_vpath__captured
, local_vpath
),
212 vfs_path_free (filename_vpath
);
213 vfs_path_free (local_vpath
);
219 /* --------------------------------------------------------------------------------------------- */
226 Suite
*s
= suite_create (TEST_SUITE_NAME
);
227 TCase
*tc_core
= tcase_create ("Core");
230 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
232 /* Add new tests here: *************** */
233 mctest_add_parameterized_test (tc_core
, the_file_is_local
, the_file_is_local_ds
);
234 tcase_add_test (tc_core
, the_file_is_remote_but_empty
);
235 tcase_add_test (tc_core
, the_file_is_remote_fail_to_create_local_copy
);
236 tcase_add_test (tc_core
, the_file_is_remote
);
237 /* *********************************** */
239 suite_add_tcase (s
, tc_core
);
240 sr
= srunner_create (s
);
241 srunner_set_log (sr
, "execute__execute_with_vfs_arg.log");
242 srunner_run_all (sr
, CK_NORMAL
);
243 number_failed
= srunner_ntests_failed (sr
);
245 return (number_failed
== 0) ? 0 : 1;
248 /* --------------------------------------------------------------------------------------------- */