user_configs_path.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. libmc - check mcconfig submodule. Get full paths to user's config files.
  3. Copyright (C) 2011-2021
  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/strescape.h"
  23. #include "lib/vfs/vfs.h"
  24. #include "lib/fileloc.h"
  25. #include "lib/mcconfig.h"
  26. #include "src/vfs/local/local.c"
  27. #define HOME_DIR "/home/testuser"
  28. #define CONF_MAIN HOME_DIR PATH_SEP_STR ".config"
  29. #define CONF_DATA HOME_DIR PATH_SEP_STR ".local" PATH_SEP_STR "share"
  30. #define CONF_CACHE HOME_DIR PATH_SEP_STR ".cache"
  31. /* --------------------------------------------------------------------------------------------- */
  32. /* @Before */
  33. static void
  34. setup (void)
  35. {
  36. g_setenv ("HOME", HOME_DIR, TRUE);
  37. g_setenv ("XDG_CONFIG_HOME", CONF_MAIN, TRUE);
  38. g_setenv ("XDG_DATA_HOME", CONF_DATA, TRUE);
  39. g_setenv ("XDG_CACHE_HOME", CONF_CACHE, TRUE);
  40. str_init_strings ("UTF-8");
  41. vfs_init ();
  42. vfs_init_localfs ();
  43. }
  44. /* --------------------------------------------------------------------------------------------- */
  45. /* @After */
  46. static void
  47. teardown (void)
  48. {
  49. vfs_shut ();
  50. str_uninit_strings ();
  51. }
  52. /* --------------------------------------------------------------------------------------------- */
  53. /* @DataSource("test_user_config_paths_ds") */
  54. /* *INDENT-OFF* */
  55. static const struct test_user_config_paths_ds
  56. {
  57. const char *input_base_dir;
  58. const char *input_file_name;
  59. } test_user_config_paths_ds[] =
  60. {
  61. { /* 0. */
  62. CONF_MAIN,
  63. MC_CONFIG_FILE
  64. },
  65. { /* 1. */
  66. CONF_MAIN,
  67. MC_FHL_INI_FILE
  68. },
  69. { /* 2. */
  70. CONF_MAIN,
  71. MC_HOTLIST_FILE
  72. },
  73. { /* 3. */
  74. CONF_MAIN,
  75. GLOBAL_KEYMAP_FILE
  76. },
  77. { /* 4. */
  78. CONF_MAIN,
  79. MC_USERMENU_FILE
  80. },
  81. { /* 5. */
  82. CONF_MAIN,
  83. EDIT_HOME_SYNTAX_FILE
  84. },
  85. { /* 6. */
  86. CONF_MAIN,
  87. EDIT_HOME_MENU
  88. },
  89. { /* 7. */
  90. CONF_MAIN,
  91. MC_PANELS_FILE
  92. },
  93. { /* 8. */
  94. CONF_MAIN,
  95. MC_FILEBIND_FILE
  96. },
  97. { /* 9. */
  98. CONF_DATA,
  99. MC_SKINS_DIR
  100. },
  101. { /* 10. */
  102. CONF_DATA,
  103. FISH_PREFIX
  104. },
  105. { /* 11. */
  106. CONF_DATA,
  107. MC_ASHRC_FILE
  108. },
  109. { /* 12. */
  110. CONF_DATA,
  111. MC_BASHRC_FILE
  112. },
  113. { /* 13. */
  114. CONF_DATA,
  115. MC_INPUTRC_FILE
  116. },
  117. { /* 14. */
  118. CONF_DATA,
  119. MC_ZSHRC_FILE
  120. },
  121. { /* 15. */
  122. CONF_DATA,
  123. MC_EXTFS_DIR
  124. },
  125. { /* 16. */
  126. CONF_DATA,
  127. MC_HISTORY_FILE
  128. },
  129. { /* 17. */
  130. CONF_DATA,
  131. MC_FILEPOS_FILE
  132. },
  133. { /* 18. */
  134. CONF_DATA,
  135. EDIT_HOME_CLIP_FILE
  136. },
  137. { /* 19. */
  138. CONF_DATA,
  139. MC_MACRO_FILE
  140. },
  141. { /* 20. */
  142. CONF_CACHE,
  143. "mc.log"
  144. },
  145. { /* 21. */
  146. CONF_CACHE,
  147. MC_TREESTORE_FILE
  148. },
  149. { /* 22. */
  150. CONF_CACHE,
  151. EDIT_HOME_TEMP_FILE
  152. },
  153. { /* 23. */
  154. CONF_CACHE,
  155. EDIT_HOME_BLOCK_FILE
  156. },
  157. };
  158. /* *INDENT-ON* */
  159. /* @Test(dataSource = "test_user_config_paths_ds") */
  160. /* *INDENT-OFF* */
  161. START_PARAMETRIZED_TEST (test_user_config_paths, test_user_config_paths_ds)
  162. /* *INDENT-ON* */
  163. {
  164. /* given */
  165. char *actual_result;
  166. /* when */
  167. actual_result = mc_config_get_full_path (data->input_file_name);
  168. /* then */
  169. {
  170. char *expected_file_path;
  171. expected_file_path =
  172. g_build_filename (data->input_base_dir, MC_USERCONF_DIR, data->input_file_name,
  173. (char *) NULL);
  174. mctest_assert_str_eq (actual_result, expected_file_path);
  175. g_free (expected_file_path);
  176. }
  177. g_free (actual_result);
  178. }
  179. /* *INDENT-OFF* */
  180. END_PARAMETRIZED_TEST
  181. /* *INDENT-ON* */
  182. /* --------------------------------------------------------------------------------------------- */
  183. int
  184. main (void)
  185. {
  186. TCase *tc_core;
  187. tc_core = tcase_create ("Core");
  188. tcase_add_checked_fixture (tc_core, setup, teardown);
  189. /* Add new tests here: *************** */
  190. mctest_add_parameterized_test (tc_core, test_user_config_paths, test_user_config_paths_ds);
  191. /* *********************************** */
  192. return mctest_run_all (tc_core);
  193. }
  194. /* --------------------------------------------------------------------------------------------- */