user_configs_path.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. libmc - check mcconfig submodule. Get full paths to user's config files.
  3. Copyright (C) 2011-2024
  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 <http://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. /* *INDENT-OFF* */
  54. static const struct test_user_config_paths_ds
  55. {
  56. const char *input_base_dir;
  57. const char *input_file_name;
  58. } test_user_config_paths_ds[] =
  59. {
  60. { /* 0. */
  61. CONF_MAIN,
  62. MC_CONFIG_FILE
  63. },
  64. { /* 1. */
  65. CONF_MAIN,
  66. MC_FHL_INI_FILE
  67. },
  68. { /* 2. */
  69. CONF_MAIN,
  70. MC_HOTLIST_FILE
  71. },
  72. { /* 3. */
  73. CONF_MAIN,
  74. GLOBAL_KEYMAP_FILE
  75. },
  76. { /* 4. */
  77. CONF_MAIN,
  78. MC_USERMENU_FILE
  79. },
  80. { /* 5. */
  81. CONF_DATA,
  82. EDIT_SYNTAX_FILE
  83. },
  84. { /* 6. */
  85. CONF_MAIN,
  86. EDIT_HOME_MENU
  87. },
  88. { /* 7. */
  89. CONF_MAIN,
  90. MC_PANELS_FILE
  91. },
  92. { /* 8. */
  93. CONF_MAIN,
  94. MC_EXT_FILE
  95. },
  96. { /* 9. */
  97. CONF_DATA,
  98. MC_SKINS_DIR
  99. },
  100. { /* 10. */
  101. CONF_DATA,
  102. VFS_SHELL_PREFIX
  103. },
  104. { /* 11. */
  105. CONF_DATA,
  106. MC_ASHRC_FILE
  107. },
  108. { /* 12. */
  109. CONF_DATA,
  110. MC_BASHRC_FILE
  111. },
  112. { /* 13. */
  113. CONF_DATA,
  114. MC_INPUTRC_FILE
  115. },
  116. { /* 14. */
  117. CONF_DATA,
  118. MC_ZSHRC_FILE
  119. },
  120. { /* 15. */
  121. CONF_DATA,
  122. MC_EXTFS_DIR
  123. },
  124. { /* 16. */
  125. CONF_DATA,
  126. MC_HISTORY_FILE
  127. },
  128. { /* 17. */
  129. CONF_DATA,
  130. MC_FILEPOS_FILE
  131. },
  132. { /* 18. */
  133. CONF_DATA,
  134. EDIT_HOME_CLIP_FILE
  135. },
  136. { /* 19. */
  137. CONF_DATA,
  138. MC_MACRO_FILE
  139. },
  140. { /* 20. */
  141. CONF_CACHE,
  142. "mc.log"
  143. },
  144. { /* 21. */
  145. CONF_CACHE,
  146. MC_TREESTORE_FILE
  147. },
  148. { /* 22. */
  149. CONF_CACHE,
  150. EDIT_HOME_TEMP_FILE
  151. },
  152. { /* 23. */
  153. CONF_CACHE,
  154. EDIT_HOME_BLOCK_FILE
  155. },
  156. };
  157. /* *INDENT-ON* */
  158. /* @Test(dataSource = "test_user_config_paths_ds") */
  159. /* *INDENT-OFF* */
  160. START_PARAMETRIZED_TEST (test_user_config_paths, test_user_config_paths_ds)
  161. /* *INDENT-ON* */
  162. {
  163. /* given */
  164. char *actual_result;
  165. /* when */
  166. actual_result = mc_config_get_full_path (data->input_file_name);
  167. /* then */
  168. {
  169. char *expected_file_path;
  170. expected_file_path =
  171. g_build_filename (data->input_base_dir, MC_USERCONF_DIR, data->input_file_name,
  172. (char *) NULL);
  173. mctest_assert_str_eq (actual_result, expected_file_path);
  174. g_free (expected_file_path);
  175. }
  176. g_free (actual_result);
  177. }
  178. /* *INDENT-OFF* */
  179. END_PARAMETRIZED_TEST
  180. /* *INDENT-ON* */
  181. /* --------------------------------------------------------------------------------------------- */
  182. int
  183. main (void)
  184. {
  185. TCase *tc_core;
  186. tc_core = tcase_create ("Core");
  187. tcase_add_checked_fixture (tc_core, setup, teardown);
  188. /* Add new tests here: *************** */
  189. mctest_add_parameterized_test (tc_core, test_user_config_paths, test_user_config_paths_ds);
  190. /* *********************************** */
  191. return mctest_run_all (tc_core);
  192. }
  193. /* --------------------------------------------------------------------------------------------- */