2 libmc - check mcconfig submodule. Get full paths to user's config files.
4 Copyright (C) 2011-2016
5 Free Software Foundation, Inc.
8 Slava Zanko <slavazanko@gmail.com>, 2011, 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/mcconfig"
28 #include "tests/mctest.h"
30 #include "lib/strutil.h"
31 #include "lib/strescape.h"
32 #include "lib/vfs/vfs.h"
33 #include "lib/fileloc.h"
35 #include "lib/mcconfig.h"
36 #include "src/vfs/local/local.c"
38 #define HOME_DIR "/home/testuser"
41 #define CONF_MAIN HOME_DIR PATH_SEP_STR ".config"
42 #define CONF_DATA HOME_DIR PATH_SEP_STR ".local" PATH_SEP_STR "share"
43 #define CONF_CACHE HOME_DIR PATH_SEP_STR ".cache"
45 #define CONF_MAIN HOME_DIR
46 #define CONF_DATA CONF_MAIN
47 #define CONF_CACHE CONF_MAIN
50 /* --------------------------------------------------------------------------------------------- */
56 g_setenv ("HOME", HOME_DIR
, TRUE
);
58 g_setenv ("XDG_CONFIG_HOME", CONF_MAIN
, TRUE
);
59 g_setenv ("XDG_DATA_HOME", CONF_DATA
, TRUE
);
60 g_setenv ("XDG_CACHE_HOME", CONF_CACHE
, TRUE
);
62 str_init_strings ("UTF-8");
67 /* --------------------------------------------------------------------------------------------- */
74 str_uninit_strings ();
77 /* --------------------------------------------------------------------------------------------- */
79 /* @DataSource("test_user_config_paths_ds") */
81 static const struct test_user_config_paths_ds
83 const char *input_base_dir
;
84 const char *input_file_name
;
85 } test_user_config_paths_ds
[] =
117 EDIT_DIR PATH_SEP_STR
"edit.indent.rc"
121 EDIT_DIR PATH_SEP_STR
"edit.spell.rc"
190 /* @Test(dataSource = "test_user_config_paths_ds") */
192 START_PARAMETRIZED_TEST (test_user_config_paths
, test_user_config_paths_ds
)
199 actual_result
= mc_config_get_full_path (data
->input_file_name
);
203 char *expected_file_path
;
206 g_build_filename (data
->input_base_dir
, MC_USERCONF_DIR
, data
->input_file_name
,
208 mctest_assert_str_eq (actual_result
, expected_file_path
);
209 g_free (expected_file_path
);
211 g_free (actual_result
);
214 END_PARAMETRIZED_TEST
217 /* --------------------------------------------------------------------------------------------- */
224 Suite
*s
= suite_create (TEST_SUITE_NAME
);
225 TCase
*tc_core
= tcase_create ("Core");
228 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
230 /* Add new tests here: *************** */
231 mctest_add_parameterized_test (tc_core
, test_user_config_paths
, test_user_config_paths_ds
);
232 /* *********************************** */
234 suite_add_tcase (s
, tc_core
);
235 sr
= srunner_create (s
);
236 srunner_set_log (sr
, "user_configs_path.log");
237 srunner_run_all (sr
, CK_ENV
);
238 number_failed
= srunner_ntests_failed (sr
);
240 return (number_failed
== 0) ? EXIT_SUCCESS
: EXIT_FAILURE
;
243 /* --------------------------------------------------------------------------------------------- */