user_configs_path.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. libmc - check mcconfig submodule. Get full paths to user's config files.
  3. Copyright (C) 2011-2025
  4. Free Software Foundation, Inc.
  5. Written by:
  6. Slava Zanko <slavazanko@gmail.com>, 2011, 2013
  7. This file is part of the Midnight Commander.
  8. The Midnight Commander is free software: you can redistribute it
  9. and/or modify it under the terms of the GNU General Public License as
  10. published by the Free Software Foundation, either version 3 of the License,
  11. or (at your option) any later version.
  12. The Midnight Commander is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. #define TEST_SUITE_NAME "lib/mcconfig"
  20. #include "tests/mctest.h"
  21. #include "lib/strutil.h"
  22. #include "lib/vfs/vfs.h"
  23. #include "lib/fileloc.h"
  24. #include "lib/mcconfig.h"
  25. #include "src/vfs/local/local.c"
  26. #define HOME_DIR "/home/testuser"
  27. #define CONF_MAIN HOME_DIR PATH_SEP_STR ".config"
  28. #define CONF_DATA HOME_DIR PATH_SEP_STR ".local" PATH_SEP_STR "share"
  29. #define CONF_CACHE HOME_DIR PATH_SEP_STR ".cache"
  30. /* --------------------------------------------------------------------------------------------- */
  31. /* @Before */
  32. static void
  33. setup (void)
  34. {
  35. g_setenv ("HOME", HOME_DIR, TRUE);
  36. g_setenv ("XDG_CONFIG_HOME", CONF_MAIN, TRUE);
  37. g_setenv ("XDG_DATA_HOME", CONF_DATA, TRUE);
  38. g_setenv ("XDG_CACHE_HOME", CONF_CACHE, TRUE);
  39. str_init_strings ("UTF-8");
  40. vfs_init ();
  41. vfs_init_localfs ();
  42. }
  43. /* --------------------------------------------------------------------------------------------- */
  44. /* @After */
  45. static void
  46. teardown (void)
  47. {
  48. vfs_shut ();
  49. str_uninit_strings ();
  50. }
  51. /* --------------------------------------------------------------------------------------------- */
  52. /* @DataSource("test_user_config_paths_ds") */
  53. static const struct test_user_config_paths_ds
  54. {
  55. const char *input_base_dir;
  56. const char *input_file_name;
  57. } test_user_config_paths_ds[] = {
  58. { CONF_MAIN, MC_CONFIG_FILE }, // 0.
  59. { CONF_MAIN, MC_FHL_INI_FILE }, // 1.
  60. { CONF_MAIN, MC_HOTLIST_FILE }, // 2.
  61. { CONF_MAIN, GLOBAL_KEYMAP_FILE }, // 3.
  62. { CONF_MAIN, MC_USERMENU_FILE }, // 4.
  63. { CONF_DATA, EDIT_SYNTAX_FILE }, // 5.
  64. { CONF_MAIN, EDIT_HOME_MENU }, // 6.
  65. { CONF_MAIN, MC_PANELS_FILE }, // 7.
  66. { CONF_MAIN, MC_EXT_FILE }, // 8.
  67. { CONF_DATA, MC_SKINS_DIR }, // 9.
  68. { CONF_DATA, VFS_SHELL_PREFIX }, // 10.
  69. { CONF_DATA, MC_ASHRC_FILE }, // 11.
  70. { CONF_DATA, MC_BASHRC_FILE }, // 12.
  71. { CONF_DATA, MC_INPUTRC_FILE }, // 13.
  72. { CONF_DATA, MC_ZSHRC_FILE }, // 14.
  73. { CONF_DATA, MC_EXTFS_DIR }, // 15.
  74. { CONF_DATA, MC_HISTORY_FILE }, // 16.
  75. { CONF_DATA, MC_FILEPOS_FILE }, // 17.
  76. { CONF_DATA, EDIT_HOME_CLIP_FILE }, // 18.
  77. { CONF_DATA, MC_MACRO_FILE }, // 19.
  78. { CONF_CACHE, "mc.log" }, // 20.
  79. { CONF_CACHE, MC_TREESTORE_FILE }, // 21.
  80. { CONF_CACHE, EDIT_HOME_TEMP_FILE }, // 22.
  81. { CONF_CACHE, EDIT_HOME_BLOCK_FILE }, // 23.
  82. };
  83. /* @Test(dataSource = "test_user_config_paths_ds") */
  84. START_PARAMETRIZED_TEST (test_user_config_paths, test_user_config_paths_ds)
  85. {
  86. // given
  87. char *actual_result;
  88. // when
  89. actual_result = mc_config_get_full_path (data->input_file_name);
  90. // then
  91. {
  92. char *expected_file_path;
  93. expected_file_path = g_build_filename (data->input_base_dir, MC_USERCONF_DIR,
  94. data->input_file_name, (char *) NULL);
  95. mctest_assert_str_eq (actual_result, expected_file_path);
  96. g_free (expected_file_path);
  97. }
  98. g_free (actual_result);
  99. }
  100. END_PARAMETRIZED_TEST
  101. /* --------------------------------------------------------------------------------------------- */
  102. int
  103. main (void)
  104. {
  105. TCase *tc_core;
  106. tc_core = tcase_create ("Core");
  107. tcase_add_checked_fixture (tc_core, setup, teardown);
  108. // Add new tests here: ***************
  109. mctest_add_parameterized_test (tc_core, test_user_config_paths, test_user_config_paths_ds);
  110. // ***********************************
  111. return mctest_run_all (tc_core);
  112. }
  113. /* --------------------------------------------------------------------------------------------- */