2 src/filemanager - tests for do_cd_command() function
5 The Free Software Foundation, Inc.
8 Slava Zanko <slavazanko@gmail.com>, 2011
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/filemanager"
32 #include "lib/global.h"
33 #include "src/vfs/local/local.c"
35 #include "src/filemanager/command.c"
38 /* --------------------------------------------------------------------------------------------- */
40 /* @ThenReturnValue */
41 static panel_view_mode_t get_current_type__return_value
;
45 get_current_type (void)
47 return get_current_type__return_value
;
50 /* --------------------------------------------------------------------------------------------- */
53 static vfs_path_t
*do_cd__new_dir_vpath__captured
;
55 static enum cd_enum do_cd__cd_type__captured
;
56 /* @ThenReturnValue */
57 static gboolean do_cd__return_value
;
61 do_cd (const vfs_path_t
* new_dir_vpath
, enum cd_enum cd_type
)
63 do_cd__new_dir_vpath__captured
= vfs_path_clone (new_dir_vpath
);
64 do_cd__cd_type__captured
= cd_type
;
65 return do_cd__return_value
;
68 /* --------------------------------------------------------------------------------------------- */
70 /* @ThenReturnValue */
71 static const char *mc_config_get_home_dir__return_value
;
75 mc_config_get_home_dir (void)
77 return mc_config_get_home_dir__return_value
;
80 /* --------------------------------------------------------------------------------------------- */
86 str_init_strings (NULL
);
90 vfs_setup_work_dir ();
91 do_cd__new_dir_vpath__captured
= NULL
;
94 /* --------------------------------------------------------------------------------------------- */
100 vfs_path_free (do_cd__new_dir_vpath__captured
);
102 str_uninit_strings ();
105 /* --------------------------------------------------------------------------------------------- */
107 /* @DataSource("test_empty_mean_home_ds") */
109 static const struct test_empty_mean_home_ds
112 } test_empty_mean_home_ds
[] =
121 "cd\t\t\t\t\t\t\t\t\t\t\t"
129 /* @Test(dataSource = "test_empty_mean_home_ds") */
131 START_TEST (test_empty_mean_home
)
136 get_current_type__return_value
= view_listing
;
137 do_cd__return_value
= TRUE
;
138 mc_config_get_home_dir__return_value
= "/home/test";
144 input_command
= g_strdup (test_empty_mean_home_ds
[_i
].command
);
145 do_cd_command (input_command
);
146 g_free (input_command
);
152 actual_path
= vfs_path_to_str (do_cd__new_dir_vpath__captured
);
153 g_assert_cmpstr (mc_config_get_home_dir__return_value
, ==, actual_path
);
154 g_free (actual_path
);
156 ck_assert_int_eq (do_cd__cd_type__captured
, cd_parse_command
);
162 /* --------------------------------------------------------------------------------------------- */
169 Suite
*s
= suite_create (TEST_SUITE_NAME
);
170 TCase
*tc_core
= tcase_create ("Core");
173 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
175 /* Add new tests here: *************** */
176 tcase_add_loop_test (tc_core
, test_empty_mean_home
, 0,
177 sizeof (test_empty_mean_home_ds
) / sizeof (test_empty_mean_home_ds
[0]));
178 /* *********************************** */
180 suite_add_tcase (s
, tc_core
);
181 sr
= srunner_create (s
);
182 srunner_set_log (sr
, "do_cd_command.log");
183 srunner_run_all (sr
, CK_NORMAL
);
184 number_failed
= srunner_ntests_failed (sr
);
186 return (number_failed
== 0) ? 0 : 1;
189 /* --------------------------------------------------------------------------------------------- */