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"
32 #include "lib/global.h"
34 #include "execute__common.c"
36 /* --------------------------------------------------------------------------------------------- */
38 /* @DataSource("the_file_is_local_ds") */
40 static const struct the_file_is_local_ds
42 const char *input_path
;
43 } the_file_is_local_ds
[] =
54 /* @Test(dataSource = "the_file_is_local_ds") */
56 START_TEST (the_file_is_local
)
60 vfs_path_t
*filename_vpath
;
61 const char *input_path
= the_file_is_local_ds
[_i
].input_path
;
62 filename_vpath
= vfs_path_from_str (input_path
);
64 vfs_file_is_local__return_value
= TRUE
;
67 execute_with_vfs_arg ("cmd_for_local_file", filename_vpath
);
70 g_assert_cmpstr (do_execute__lc_shell__captured
, ==, "cmd_for_local_file");
71 g_assert_cmpstr (do_execute__command__captured
, ==, input_path
);
73 ck_assert_int_eq (vfs_file_is_local__vpath__captured
->len
, 1);
75 const vfs_path_t
*tmp_vpath
;
77 tmp_vpath
= (input_path
== NULL
) ? vfs_get_raw_current_dir () : filename_vpath
;
78 ck_assert_int_eq (vfs_path_cmp
79 (g_ptr_array_index (vfs_file_is_local__vpath__captured
, 0), tmp_vpath
),
82 ck_assert_int_eq (do_execute__flags__captured
, EXECUTE_INTERNAL
);
83 fail_unless (mc_getlocalcopy__pathname_vpath__captured
== NULL
,
84 "\nFunction mc_getlocalcopy() shouldn't be called!");
86 vfs_path_free (filename_vpath
);
92 /* --------------------------------------------------------------------------------------------- */
96 START_TEST (the_file_is_remote_but_empty
)
100 vfs_path_t
*filename_vpath
;
101 filename_vpath
= NULL
;
103 vfs_file_is_local__return_value
= FALSE
;
106 execute_with_vfs_arg ("cmd_for_remote_file", filename_vpath
);
109 g_assert_cmpstr (do_execute__lc_shell__captured
, ==, NULL
);
110 g_assert_cmpstr (do_execute__command__captured
, ==, NULL
);
112 ck_assert_int_eq (vfs_file_is_local__vpath__captured
->len
, 2);
114 ck_assert_int_eq (vfs_path_cmp
115 (g_ptr_array_index (vfs_file_is_local__vpath__captured
, 0),
116 vfs_get_raw_current_dir ()), 0);
117 fail_unless (g_ptr_array_index (vfs_file_is_local__vpath__captured
, 1) == NULL
,
118 "\nParameter for second call to vfs_file_is_local() should be NULL!");
119 fail_unless (mc_getlocalcopy__pathname_vpath__captured
== NULL
,
120 "\nFunction mc_getlocalcopy() shouldn't be called!");
122 vfs_path_free (filename_vpath
);
128 /* --------------------------------------------------------------------------------------------- */
132 START_TEST (the_file_is_remote_fail_to_create_local_copy
)
136 vfs_path_t
*filename_vpath
;
138 filename_vpath
= vfs_path_from_str ("/ftp://some.host/editme.txt");
140 vfs_file_is_local__return_value
= FALSE
;
141 mc_getlocalcopy__return_value
= NULL
;
144 execute_with_vfs_arg ("cmd_for_remote_file", filename_vpath
);
147 g_assert_cmpstr (do_execute__lc_shell__captured
, ==, NULL
);
148 g_assert_cmpstr (do_execute__command__captured
, ==, NULL
);
150 ck_assert_int_eq (vfs_file_is_local__vpath__captured
->len
, 1);
152 ck_assert_int_eq (vfs_path_cmp
153 (g_ptr_array_index (vfs_file_is_local__vpath__captured
, 0), filename_vpath
),
156 ck_assert_int_eq (vfs_path_cmp (mc_getlocalcopy__pathname_vpath__captured
, filename_vpath
), 0);
158 g_assert_cmpstr (message_title__captured
, ==, _("Error"));
159 g_assert_cmpstr (message_text__captured
, ==,
160 _("Cannot fetch a local copy of /ftp://some.host/editme.txt"));
163 vfs_path_free (filename_vpath
);
169 /* --------------------------------------------------------------------------------------------- */
173 START_TEST (the_file_is_remote
)
177 vfs_path_t
*filename_vpath
, *local_vpath
, *local_vpath_should_be_freeing
;
179 filename_vpath
= vfs_path_from_str ("/ftp://some.host/editme.txt");
180 local_vpath
= vfs_path_from_str ("/tmp/blabla-editme.txt");
181 local_vpath_should_be_freeing
= vfs_path_clone (local_vpath
);
183 vfs_file_is_local__return_value
= FALSE
;
184 mc_getlocalcopy__return_value
= local_vpath_should_be_freeing
;
187 execute_with_vfs_arg ("cmd_for_remote_file", filename_vpath
);
190 g_assert_cmpstr (do_execute__lc_shell__captured
, ==, "cmd_for_remote_file");
191 g_assert_cmpstr (do_execute__command__captured
, ==, "/tmp/blabla-editme.txt");
193 ck_assert_int_eq (vfs_file_is_local__vpath__captured
->len
, 1);
195 ck_assert_int_eq (vfs_path_cmp
196 (g_ptr_array_index (vfs_file_is_local__vpath__captured
, 0), filename_vpath
),
199 ck_assert_int_eq (vfs_path_cmp (mc_getlocalcopy__pathname_vpath__captured
, filename_vpath
), 0);
201 ck_assert_int_eq (mc_stat__vpath__captured
->len
, 2);
203 ck_assert_int_eq (vfs_path_cmp
204 (g_ptr_array_index (mc_stat__vpath__captured
, 0), local_vpath
), 0);
205 ck_assert_int_eq (vfs_path_cmp
206 (g_ptr_array_index (mc_stat__vpath__captured
, 0),
207 g_ptr_array_index (mc_stat__vpath__captured
, 1)), 0);
209 ck_assert_int_eq (vfs_path_cmp (mc_ungetlocalcopy__pathname_vpath__captured
, filename_vpath
),
212 ck_assert_int_eq (vfs_path_cmp (mc_ungetlocalcopy__local_vpath__captured
, local_vpath
), 0);
214 vfs_path_free (filename_vpath
);
215 vfs_path_free (local_vpath
);
221 /* --------------------------------------------------------------------------------------------- */
228 Suite
*s
= suite_create (TEST_SUITE_NAME
);
229 TCase
*tc_core
= tcase_create ("Core");
232 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
234 /* Add new tests here: *************** */
235 tcase_add_loop_test (tc_core
, the_file_is_local
, 0,
236 sizeof (the_file_is_local_ds
) / sizeof (the_file_is_local_ds
[0]));
237 tcase_add_test (tc_core
, the_file_is_remote_but_empty
);
238 tcase_add_test (tc_core
, the_file_is_remote_fail_to_create_local_copy
);
239 tcase_add_test (tc_core
, the_file_is_remote
);
240 /* *********************************** */
242 suite_add_tcase (s
, tc_core
);
243 sr
= srunner_create (s
);
244 srunner_set_log (sr
, "execute__execute_with_vfs_arg.log");
245 srunner_run_all (sr
, CK_NORMAL
);
246 number_failed
= srunner_ntests_failed (sr
);
248 return (number_failed
== 0) ? 0 : 1;
251 /* --------------------------------------------------------------------------------------------- */