2011-12-02 00:04:05 +04:00
|
|
|
/*
|
|
|
|
libmc - check mcconfig submodule. Get full paths to user's config files.
|
|
|
|
|
2022-01-02 11:02:55 +03:00
|
|
|
Copyright (C) 2011-2022
|
2014-02-12 10:33:10 +04:00
|
|
|
Free Software Foundation, Inc.
|
2011-12-02 00:04:05 +04:00
|
|
|
|
|
|
|
Written by:
|
2013-01-19 17:42:26 +04:00
|
|
|
Slava Zanko <slavazanko@gmail.com>, 2011, 2013
|
2011-12-02 00:04:05 +04:00
|
|
|
|
|
|
|
This file is part of the Midnight Commander.
|
|
|
|
|
|
|
|
The Midnight Commander is free software: you can redistribute it
|
|
|
|
and/or modify it under the terms of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation, either version 3 of the License,
|
|
|
|
or (at your option) any later version.
|
|
|
|
|
|
|
|
The Midnight Commander is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-01-19 16:05:19 +04:00
|
|
|
*/
|
2011-12-02 00:04:05 +04:00
|
|
|
|
|
|
|
#define TEST_SUITE_NAME "lib/mcconfig"
|
|
|
|
|
2013-01-19 17:42:26 +04:00
|
|
|
#include "tests/mctest.h"
|
2011-12-02 00:04:05 +04:00
|
|
|
|
|
|
|
#include "lib/strutil.h"
|
|
|
|
#include "lib/strescape.h"
|
|
|
|
#include "lib/vfs/vfs.h"
|
|
|
|
#include "lib/fileloc.h"
|
|
|
|
|
|
|
|
#include "lib/mcconfig.h"
|
|
|
|
#include "src/vfs/local/local.c"
|
|
|
|
|
|
|
|
#define HOME_DIR "/home/testuser"
|
|
|
|
|
2013-01-19 16:05:19 +04:00
|
|
|
#define CONF_MAIN HOME_DIR PATH_SEP_STR ".config"
|
|
|
|
#define CONF_DATA HOME_DIR PATH_SEP_STR ".local" PATH_SEP_STR "share"
|
|
|
|
#define CONF_CACHE HOME_DIR PATH_SEP_STR ".cache"
|
2011-12-02 00:04:05 +04:00
|
|
|
|
2013-01-28 19:18:15 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2011-12-02 00:04:05 +04:00
|
|
|
|
2013-01-28 19:18:15 +04:00
|
|
|
/* @Before */
|
2011-12-02 00:04:05 +04:00
|
|
|
static void
|
|
|
|
setup (void)
|
|
|
|
{
|
|
|
|
g_setenv ("HOME", HOME_DIR, TRUE);
|
|
|
|
g_setenv ("XDG_CONFIG_HOME", CONF_MAIN, TRUE);
|
|
|
|
g_setenv ("XDG_DATA_HOME", CONF_DATA, TRUE);
|
|
|
|
g_setenv ("XDG_CACHE_HOME", CONF_CACHE, TRUE);
|
2013-01-19 16:05:19 +04:00
|
|
|
str_init_strings ("UTF-8");
|
2011-12-02 00:04:05 +04:00
|
|
|
vfs_init ();
|
2019-05-12 19:35:20 +03:00
|
|
|
vfs_init_localfs ();
|
2011-12-02 00:04:05 +04:00
|
|
|
}
|
|
|
|
|
2013-01-28 19:18:15 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* @After */
|
2011-12-02 00:04:05 +04:00
|
|
|
static void
|
|
|
|
teardown (void)
|
|
|
|
{
|
|
|
|
vfs_shut ();
|
2013-01-19 16:05:19 +04:00
|
|
|
str_uninit_strings ();
|
2011-12-02 00:04:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2013-01-28 19:18:15 +04:00
|
|
|
|
|
|
|
/* @DataSource("test_user_config_paths_ds") */
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-OFF* */
|
2013-01-28 19:18:15 +04:00
|
|
|
static const struct test_user_config_paths_ds
|
2011-12-02 00:04:05 +04:00
|
|
|
{
|
2013-01-28 19:18:15 +04:00
|
|
|
const char *input_base_dir;
|
|
|
|
const char *input_file_name;
|
|
|
|
} test_user_config_paths_ds[] =
|
|
|
|
{
|
|
|
|
{ /* 0. */
|
|
|
|
CONF_MAIN,
|
|
|
|
MC_CONFIG_FILE
|
|
|
|
},
|
2013-09-02 20:38:29 +04:00
|
|
|
{ /* 1. */
|
2013-01-28 19:18:15 +04:00
|
|
|
CONF_MAIN,
|
|
|
|
MC_FHL_INI_FILE
|
|
|
|
},
|
2013-09-02 20:38:29 +04:00
|
|
|
{ /* 2. */
|
2017-02-24 23:32:01 +03:00
|
|
|
CONF_MAIN,
|
2013-01-28 19:18:15 +04:00
|
|
|
MC_HOTLIST_FILE
|
|
|
|
},
|
2013-09-02 20:38:29 +04:00
|
|
|
{ /* 3. */
|
2013-01-28 19:18:15 +04:00
|
|
|
CONF_MAIN,
|
|
|
|
GLOBAL_KEYMAP_FILE
|
|
|
|
},
|
2013-09-02 20:38:29 +04:00
|
|
|
{ /* 4. */
|
2013-01-28 19:18:15 +04:00
|
|
|
CONF_MAIN,
|
|
|
|
MC_USERMENU_FILE
|
|
|
|
},
|
2013-09-02 20:38:29 +04:00
|
|
|
{ /* 5. */
|
2013-01-28 19:18:15 +04:00
|
|
|
CONF_MAIN,
|
2020-05-03 11:07:01 +03:00
|
|
|
EDIT_HOME_SYNTAX_FILE
|
2013-01-28 19:18:15 +04:00
|
|
|
},
|
2013-09-02 20:38:29 +04:00
|
|
|
{ /* 6. */
|
2013-01-28 19:18:15 +04:00
|
|
|
CONF_MAIN,
|
|
|
|
EDIT_HOME_MENU
|
|
|
|
},
|
2013-09-02 20:38:29 +04:00
|
|
|
{ /* 7. */
|
2013-01-28 19:18:15 +04:00
|
|
|
CONF_MAIN,
|
|
|
|
MC_PANELS_FILE
|
|
|
|
},
|
2020-05-03 11:23:20 +03:00
|
|
|
{ /* 8. */
|
2013-01-28 19:18:15 +04:00
|
|
|
CONF_MAIN,
|
2022-07-22 20:12:59 +03:00
|
|
|
MC_EXT_FILE
|
2013-01-28 19:18:15 +04:00
|
|
|
},
|
2020-05-03 11:23:20 +03:00
|
|
|
{ /* 9. */
|
2013-01-28 19:18:15 +04:00
|
|
|
CONF_DATA,
|
2020-05-03 12:17:49 +03:00
|
|
|
MC_SKINS_DIR
|
2013-01-28 19:18:15 +04:00
|
|
|
},
|
2020-05-03 11:23:20 +03:00
|
|
|
{ /* 10. */
|
2013-01-28 19:18:15 +04:00
|
|
|
CONF_DATA,
|
|
|
|
FISH_PREFIX
|
|
|
|
},
|
2020-05-03 11:23:20 +03:00
|
|
|
{ /* 11. */
|
2013-09-02 20:00:53 +04:00
|
|
|
CONF_DATA,
|
2021-02-18 10:28:34 +03:00
|
|
|
MC_ASHRC_FILE
|
2013-09-02 20:00:53 +04:00
|
|
|
},
|
2020-05-03 11:23:20 +03:00
|
|
|
{ /* 12. */
|
2013-01-28 19:18:15 +04:00
|
|
|
CONF_DATA,
|
2021-02-18 10:28:34 +03:00
|
|
|
MC_BASHRC_FILE
|
2013-01-28 19:18:15 +04:00
|
|
|
},
|
2020-05-03 11:23:20 +03:00
|
|
|
{ /* 13. */
|
2013-01-28 19:18:15 +04:00
|
|
|
CONF_DATA,
|
2021-02-18 10:28:34 +03:00
|
|
|
MC_INPUTRC_FILE
|
2013-01-28 19:18:15 +04:00
|
|
|
},
|
2020-05-03 11:23:20 +03:00
|
|
|
{ /* 14. */
|
2013-01-28 19:18:15 +04:00
|
|
|
CONF_DATA,
|
2021-02-28 17:56:46 +03:00
|
|
|
MC_ZSHRC_FILE
|
2013-01-28 19:18:15 +04:00
|
|
|
},
|
2020-05-03 11:23:20 +03:00
|
|
|
{ /* 15. */
|
2013-01-28 19:18:15 +04:00
|
|
|
CONF_DATA,
|
2021-02-28 17:56:46 +03:00
|
|
|
MC_EXTFS_DIR
|
2013-01-28 19:18:15 +04:00
|
|
|
},
|
2020-05-03 11:23:20 +03:00
|
|
|
{ /* 16. */
|
2013-01-28 19:18:15 +04:00
|
|
|
CONF_DATA,
|
2021-02-28 17:56:46 +03:00
|
|
|
MC_HISTORY_FILE
|
2013-01-28 19:18:15 +04:00
|
|
|
},
|
2020-05-03 11:23:20 +03:00
|
|
|
{ /* 17. */
|
2013-01-28 19:18:15 +04:00
|
|
|
CONF_DATA,
|
2021-02-28 17:56:46 +03:00
|
|
|
MC_FILEPOS_FILE
|
2013-01-28 19:18:15 +04:00
|
|
|
},
|
2020-05-03 11:23:20 +03:00
|
|
|
{ /* 18. */
|
2013-01-28 19:18:15 +04:00
|
|
|
CONF_DATA,
|
2021-02-28 17:56:46 +03:00
|
|
|
EDIT_HOME_CLIP_FILE
|
2013-01-28 19:18:15 +04:00
|
|
|
},
|
2020-05-03 11:23:20 +03:00
|
|
|
{ /* 19. */
|
2021-02-28 17:56:46 +03:00
|
|
|
CONF_DATA,
|
|
|
|
MC_MACRO_FILE
|
|
|
|
},
|
|
|
|
{ /* 20. */
|
2013-01-28 19:18:15 +04:00
|
|
|
CONF_CACHE,
|
|
|
|
"mc.log"
|
|
|
|
},
|
2021-02-28 17:56:46 +03:00
|
|
|
{ /* 21. */
|
2013-01-28 19:18:15 +04:00
|
|
|
CONF_CACHE,
|
|
|
|
MC_TREESTORE_FILE
|
|
|
|
},
|
2021-02-28 17:56:46 +03:00
|
|
|
{ /* 22. */
|
2013-01-28 19:18:15 +04:00
|
|
|
CONF_CACHE,
|
2020-05-03 11:07:01 +03:00
|
|
|
EDIT_HOME_TEMP_FILE
|
2013-01-28 19:18:15 +04:00
|
|
|
},
|
2021-02-28 17:56:46 +03:00
|
|
|
{ /* 23. */
|
2013-01-28 19:18:15 +04:00
|
|
|
CONF_CACHE,
|
2020-05-03 11:07:01 +03:00
|
|
|
EDIT_HOME_BLOCK_FILE
|
2013-01-28 19:18:15 +04:00
|
|
|
},
|
|
|
|
};
|
|
|
|
/* *INDENT-ON* */
|
2011-12-02 00:04:05 +04:00
|
|
|
|
2013-01-28 19:18:15 +04:00
|
|
|
/* @Test(dataSource = "test_user_config_paths_ds") */
|
|
|
|
/* *INDENT-OFF* */
|
|
|
|
START_PARAMETRIZED_TEST (test_user_config_paths, test_user_config_paths_ds)
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
{
|
|
|
|
/* given */
|
|
|
|
char *actual_result;
|
|
|
|
|
|
|
|
/* when */
|
|
|
|
actual_result = mc_config_get_full_path (data->input_file_name);
|
|
|
|
|
|
|
|
/* then */
|
|
|
|
{
|
|
|
|
char *expected_file_path;
|
|
|
|
|
|
|
|
expected_file_path =
|
2016-03-25 21:33:44 +03:00
|
|
|
g_build_filename (data->input_base_dir, MC_USERCONF_DIR, data->input_file_name,
|
|
|
|
(char *) NULL);
|
2013-01-28 19:18:15 +04:00
|
|
|
mctest_assert_str_eq (actual_result, expected_file_path);
|
|
|
|
g_free (expected_file_path);
|
|
|
|
}
|
|
|
|
g_free (actual_result);
|
2011-12-02 00:04:05 +04:00
|
|
|
}
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-OFF* */
|
2013-01-28 19:18:15 +04:00
|
|
|
END_PARAMETRIZED_TEST
|
2013-01-19 16:05:19 +04:00
|
|
|
/* *INDENT-ON* */
|
2011-12-02 00:04:05 +04:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
2020-12-30 18:23:26 +03:00
|
|
|
TCase *tc_core;
|
2011-12-02 00:04:05 +04:00
|
|
|
|
2020-12-30 18:23:26 +03:00
|
|
|
tc_core = tcase_create ("Core");
|
2011-12-02 00:04:05 +04:00
|
|
|
|
|
|
|
tcase_add_checked_fixture (tc_core, setup, teardown);
|
|
|
|
|
|
|
|
/* Add new tests here: *************** */
|
2013-01-28 19:18:15 +04:00
|
|
|
mctest_add_parameterized_test (tc_core, test_user_config_paths, test_user_config_paths_ds);
|
2011-12-02 00:04:05 +04:00
|
|
|
/* *********************************** */
|
|
|
|
|
2020-12-30 18:23:26 +03:00
|
|
|
return mctest_run_all (tc_core);
|
2011-12-02 00:04:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|