src/strutil/xstrtol.c: sync with gnulib.
[midnight-commander.git] / tests / lib / mcconfig / user_configs_path.c
blobcbddfa5191bf68bedb5c0008e2f17f26b72bd2ad
1 /*
2 libmc - check mcconfig submodule. Get full paths to user's config files.
4 Copyright (C) 2011-2024
5 Free Software Foundation, Inc.
7 Written by:
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/vfs/vfs.h"
32 #include "lib/fileloc.h"
34 #include "lib/mcconfig.h"
35 #include "src/vfs/local/local.c"
37 #define HOME_DIR "/home/testuser"
39 #define CONF_MAIN HOME_DIR PATH_SEP_STR ".config"
40 #define CONF_DATA HOME_DIR PATH_SEP_STR ".local" PATH_SEP_STR "share"
41 #define CONF_CACHE HOME_DIR PATH_SEP_STR ".cache"
43 /* --------------------------------------------------------------------------------------------- */
45 /* @Before */
46 static void
47 setup (void)
49 g_setenv ("HOME", HOME_DIR, TRUE);
50 g_setenv ("XDG_CONFIG_HOME", CONF_MAIN, TRUE);
51 g_setenv ("XDG_DATA_HOME", CONF_DATA, TRUE);
52 g_setenv ("XDG_CACHE_HOME", CONF_CACHE, TRUE);
53 str_init_strings ("UTF-8");
54 vfs_init ();
55 vfs_init_localfs ();
58 /* --------------------------------------------------------------------------------------------- */
60 /* @After */
61 static void
62 teardown (void)
64 vfs_shut ();
65 str_uninit_strings ();
68 /* --------------------------------------------------------------------------------------------- */
70 /* @DataSource("test_user_config_paths_ds") */
71 /* *INDENT-OFF* */
72 static const struct test_user_config_paths_ds
74 const char *input_base_dir;
75 const char *input_file_name;
76 } test_user_config_paths_ds[] =
78 { /* 0. */
79 CONF_MAIN,
80 MC_CONFIG_FILE
82 { /* 1. */
83 CONF_MAIN,
84 MC_FHL_INI_FILE
86 { /* 2. */
87 CONF_MAIN,
88 MC_HOTLIST_FILE
90 { /* 3. */
91 CONF_MAIN,
92 GLOBAL_KEYMAP_FILE
94 { /* 4. */
95 CONF_MAIN,
96 MC_USERMENU_FILE
98 { /* 5. */
99 CONF_DATA,
100 EDIT_SYNTAX_FILE
102 { /* 6. */
103 CONF_MAIN,
104 EDIT_HOME_MENU
106 { /* 7. */
107 CONF_MAIN,
108 MC_PANELS_FILE
110 { /* 8. */
111 CONF_MAIN,
112 MC_EXT_FILE
114 { /* 9. */
115 CONF_DATA,
116 MC_SKINS_DIR
118 { /* 10. */
119 CONF_DATA,
120 VFS_SHELL_PREFIX
122 { /* 11. */
123 CONF_DATA,
124 MC_ASHRC_FILE
126 { /* 12. */
127 CONF_DATA,
128 MC_BASHRC_FILE
130 { /* 13. */
131 CONF_DATA,
132 MC_INPUTRC_FILE
134 { /* 14. */
135 CONF_DATA,
136 MC_ZSHRC_FILE
138 { /* 15. */
139 CONF_DATA,
140 MC_EXTFS_DIR
142 { /* 16. */
143 CONF_DATA,
144 MC_HISTORY_FILE
146 { /* 17. */
147 CONF_DATA,
148 MC_FILEPOS_FILE
150 { /* 18. */
151 CONF_DATA,
152 EDIT_HOME_CLIP_FILE
154 { /* 19. */
155 CONF_DATA,
156 MC_MACRO_FILE
158 { /* 20. */
159 CONF_CACHE,
160 "mc.log"
162 { /* 21. */
163 CONF_CACHE,
164 MC_TREESTORE_FILE
166 { /* 22. */
167 CONF_CACHE,
168 EDIT_HOME_TEMP_FILE
170 { /* 23. */
171 CONF_CACHE,
172 EDIT_HOME_BLOCK_FILE
175 /* *INDENT-ON* */
177 /* @Test(dataSource = "test_user_config_paths_ds") */
178 /* *INDENT-OFF* */
179 START_PARAMETRIZED_TEST (test_user_config_paths, test_user_config_paths_ds)
180 /* *INDENT-ON* */
182 /* given */
183 char *actual_result;
185 /* when */
186 actual_result = mc_config_get_full_path (data->input_file_name);
188 /* then */
190 char *expected_file_path;
192 expected_file_path =
193 g_build_filename (data->input_base_dir, MC_USERCONF_DIR, data->input_file_name,
194 (char *) NULL);
195 mctest_assert_str_eq (actual_result, expected_file_path);
196 g_free (expected_file_path);
198 g_free (actual_result);
200 /* *INDENT-OFF* */
201 END_PARAMETRIZED_TEST
202 /* *INDENT-ON* */
204 /* --------------------------------------------------------------------------------------------- */
207 main (void)
209 TCase *tc_core;
211 tc_core = tcase_create ("Core");
213 tcase_add_checked_fixture (tc_core, setup, teardown);
215 /* Add new tests here: *************** */
216 mctest_add_parameterized_test (tc_core, test_user_config_paths, test_user_config_paths_ds);
217 /* *********************************** */
219 return mctest_run_all (tc_core);
222 /* --------------------------------------------------------------------------------------------- */