2 lib/vfs - test vfs_setup_cwd() functionality
4 Copyright (C) 2013-2017
5 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 "/lib/vfs"
28 #include "tests/mctest.h"
32 #include "lib/strutil.h"
33 #include "lib/vfs/xdirentry.h"
34 #include "src/vfs/local/local.c"
36 /* --------------------------------------------------------------------------------------------- */
40 g_get_current_dir (void)
42 return g_strdup ("/some/path");
45 /* --------------------------------------------------------------------------------------------- */
47 static gboolean mc_stat__is_2nd_call_different
= FALSE
;
48 static gboolean mc_stat__call_count
= 0;
52 mc_stat (const vfs_path_t
* vpath
, struct stat
*my_stat
)
56 if (mc_stat__call_count
++ > 1 && mc_stat__is_2nd_call_different
)
66 if (mc_stat__call_count
> 2)
68 mc_stat__call_count
= 0;
73 /* --------------------------------------------------------------------------------------------- */
79 str_init_strings (NULL
);
83 vfs_setup_work_dir ();
86 /* --------------------------------------------------------------------------------------------- */
93 str_uninit_strings ();
96 /* --------------------------------------------------------------------------------------------- */
98 /* @DataSource("test_vfs_setup_cwd_symlink_ds") */
100 static const struct test_vfs_setup_cwd_symlink_ds
102 gboolean is_2nd_call_different
;
103 const char *expected_result
;
104 } test_vfs_setup_cwd_symlink_ds
[] =
119 START_PARAMETRIZED_TEST (test_vfs_setup_cwd_symlink
, test_vfs_setup_cwd_symlink_ds
)
123 vfs_set_raw_current_dir (NULL
);
124 mc_stat__is_2nd_call_different
= data
->is_2nd_call_different
;
125 mc_stat__call_count
= 0;
126 setenv ("PWD", "/some/path2", 1);
132 mctest_assert_str_eq (vfs_path_as_str (vfs_get_raw_current_dir ()), data
->expected_result
);
135 END_PARAMETRIZED_TEST
138 /* --------------------------------------------------------------------------------------------- */
145 Suite
*s
= suite_create (TEST_SUITE_NAME
);
146 TCase
*tc_core
= tcase_create ("Core");
149 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
151 /* Add new tests here: *************** */
152 mctest_add_parameterized_test (tc_core
, test_vfs_setup_cwd_symlink
,
153 test_vfs_setup_cwd_symlink_ds
);
154 /* *********************************** */
156 suite_add_tcase (s
, tc_core
);
157 sr
= srunner_create (s
);
158 srunner_set_log (sr
, "vfs_setup_cwd.log");
159 srunner_run_all (sr
, CK_ENV
);
160 number_failed
= srunner_ntests_failed (sr
);
162 return (number_failed
== 0) ? EXIT_SUCCESS
: EXIT_FAILURE
;
165 /* --------------------------------------------------------------------------------------------- */