Fixed exec_get_export_variables_ext test
[midnight-commander.git] / tests / src / filemanager / do_cd_command.c
blobdefbc92c4a2435cc5d8a1697936a61ebb771ebe4
1 /*
2 src/filemanager - tests for do_cd_command() function
4 Copyright (C) 2011
5 The Free Software Foundation, Inc.
7 Written by:
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"
28 #include <config.h>
30 #include <check.h>
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;
43 /* @Mock */
44 panel_view_mode_t
45 get_current_type (void)
47 return get_current_type__return_value;
50 /* --------------------------------------------------------------------------------------------- */
52 /* @CapturedValue */
53 static vfs_path_t *do_cd__new_dir_vpath__captured;
54 /* @CapturedValue */
55 static enum cd_enum do_cd__cd_type__captured;
56 /* @ThenReturnValue */
57 static gboolean do_cd__return_value;
59 /* @Mock */
60 gboolean
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;
73 /* @Mock */
74 const char *
75 mc_config_get_home_dir (void)
77 return mc_config_get_home_dir__return_value;
80 /* --------------------------------------------------------------------------------------------- */
82 /* @Before */
83 static void
84 setup (void)
86 str_init_strings (NULL);
88 vfs_init ();
89 init_localfs ();
90 vfs_setup_work_dir ();
91 do_cd__new_dir_vpath__captured = NULL;
94 /* --------------------------------------------------------------------------------------------- */
96 /* @After */
97 static void
98 teardown (void)
100 vfs_path_free (do_cd__new_dir_vpath__captured);
101 vfs_shut ();
102 str_uninit_strings ();
105 /* --------------------------------------------------------------------------------------------- */
107 /* @DataSource("test_empty_mean_home_ds") */
108 /* *INDENT-OFF* */
109 static const struct test_empty_mean_home_ds
111 const char *command;
112 } test_empty_mean_home_ds[] =
115 "cd"
118 "cd "
121 "cd\t\t\t\t\t\t\t\t\t\t\t"
124 "cd \t \t \t\t \t "
127 /* *INDENT-ON* */
129 /* @Test(dataSource = "test_empty_mean_home_ds") */
130 /* *INDENT-OFF* */
131 START_TEST (test_empty_mean_home)
132 /* *INDENT-ON* */
134 /* given */
136 get_current_type__return_value = view_listing;
137 do_cd__return_value = TRUE;
138 mc_config_get_home_dir__return_value = "/home/test";
140 /* when */
142 char *input_command;
144 input_command = g_strdup (test_empty_mean_home_ds[_i].command);
145 do_cd_command (input_command);
146 g_free (input_command);
148 /* then */
150 char *actual_path;
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);
158 /* *INDENT-OFF* */
159 END_TEST
160 /* *INDENT-ON* */
162 /* --------------------------------------------------------------------------------------------- */
165 main (void)
167 int number_failed;
169 Suite *s = suite_create (TEST_SUITE_NAME);
170 TCase *tc_core = tcase_create ("Core");
171 SRunner *sr;
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);
185 srunner_free (sr);
186 return (number_failed == 0) ? 0 : 1;
189 /* --------------------------------------------------------------------------------------------- */