user_configs_path.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. libmc - check mcconfig submodule. Get full paths to user's config files.
  3. Copyright (C) 2011-2019
  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. #if MC_HOMEDIR_XDG
  29. #define CONF_MAIN HOME_DIR PATH_SEP_STR ".config"
  30. #define CONF_DATA HOME_DIR PATH_SEP_STR ".local" PATH_SEP_STR "share"
  31. #define CONF_CACHE HOME_DIR PATH_SEP_STR ".cache"
  32. #else
  33. #define CONF_MAIN HOME_DIR
  34. #define CONF_DATA CONF_MAIN
  35. #define CONF_CACHE CONF_MAIN
  36. #endif
  37. /* --------------------------------------------------------------------------------------------- */
  38. /* @Before */
  39. static void
  40. setup (void)
  41. {
  42. g_setenv ("HOME", HOME_DIR, TRUE);
  43. #if MC_HOMEDIR_XDG
  44. g_setenv ("XDG_CONFIG_HOME", CONF_MAIN, TRUE);
  45. g_setenv ("XDG_DATA_HOME", CONF_DATA, TRUE);
  46. g_setenv ("XDG_CACHE_HOME", CONF_CACHE, TRUE);
  47. #endif
  48. str_init_strings ("UTF-8");
  49. vfs_init ();
  50. vfs_init_localfs ();
  51. }
  52. /* --------------------------------------------------------------------------------------------- */
  53. /* @After */
  54. static void
  55. teardown (void)
  56. {
  57. vfs_shut ();
  58. str_uninit_strings ();
  59. }
  60. /* --------------------------------------------------------------------------------------------- */
  61. /* @DataSource("test_user_config_paths_ds") */
  62. /* *INDENT-OFF* */
  63. static const struct test_user_config_paths_ds
  64. {
  65. const char *input_base_dir;
  66. const char *input_file_name;
  67. } test_user_config_paths_ds[] =
  68. {
  69. { /* 0. */
  70. CONF_MAIN,
  71. MC_CONFIG_FILE
  72. },
  73. { /* 1. */
  74. CONF_MAIN,
  75. MC_FHL_INI_FILE
  76. },
  77. { /* 2. */
  78. CONF_MAIN,
  79. MC_HOTLIST_FILE
  80. },
  81. { /* 3. */
  82. CONF_MAIN,
  83. GLOBAL_KEYMAP_FILE
  84. },
  85. { /* 4. */
  86. CONF_MAIN,
  87. MC_USERMENU_FILE
  88. },
  89. { /* 5. */
  90. CONF_MAIN,
  91. EDIT_SYNTAX_FILE
  92. },
  93. { /* 6. */
  94. CONF_MAIN,
  95. EDIT_HOME_MENU
  96. },
  97. { /* 7. */
  98. CONF_MAIN,
  99. EDIT_DIR PATH_SEP_STR "edit.indent.rc"
  100. },
  101. { /* 8. */
  102. CONF_MAIN,
  103. EDIT_DIR PATH_SEP_STR "edit.spell.rc"
  104. },
  105. { /* 9. */
  106. CONF_MAIN,
  107. MC_PANELS_FILE
  108. },
  109. { /* 10. */
  110. CONF_MAIN,
  111. MC_FILEBIND_FILE
  112. },
  113. { /* 11. */
  114. CONF_DATA,
  115. MC_SKINS_SUBDIR
  116. },
  117. { /* 12. */
  118. CONF_DATA,
  119. FISH_PREFIX
  120. },
  121. { /* 13. */
  122. CONF_DATA,
  123. "ashrc"
  124. },
  125. { /* 14. */
  126. CONF_DATA,
  127. "bashrc"
  128. },
  129. { /* 15. */
  130. CONF_DATA,
  131. "inputrc"
  132. },
  133. { /* 16. */
  134. CONF_DATA,
  135. MC_EXTFS_DIR
  136. },
  137. { /* 17. */
  138. CONF_DATA,
  139. MC_HISTORY_FILE
  140. },
  141. { /* 18. */
  142. CONF_DATA,
  143. MC_FILEPOS_FILE
  144. },
  145. { /* 19. */
  146. CONF_DATA,
  147. EDIT_CLIP_FILE
  148. },
  149. { /* 20. */
  150. CONF_DATA,
  151. MC_MACRO_FILE
  152. },
  153. { /* 21. */
  154. CONF_CACHE,
  155. "mc.log"
  156. },
  157. { /* 22. */
  158. CONF_CACHE,
  159. MC_TREESTORE_FILE
  160. },
  161. { /* 23. */
  162. CONF_CACHE,
  163. EDIT_TEMP_FILE
  164. },
  165. { /* 24. */
  166. CONF_CACHE,
  167. EDIT_BLOCK_FILE
  168. },
  169. };
  170. /* *INDENT-ON* */
  171. /* @Test(dataSource = "test_user_config_paths_ds") */
  172. /* *INDENT-OFF* */
  173. START_PARAMETRIZED_TEST (test_user_config_paths, test_user_config_paths_ds)
  174. /* *INDENT-ON* */
  175. {
  176. /* given */
  177. char *actual_result;
  178. /* when */
  179. actual_result = mc_config_get_full_path (data->input_file_name);
  180. /* then */
  181. {
  182. char *expected_file_path;
  183. expected_file_path =
  184. g_build_filename (data->input_base_dir, MC_USERCONF_DIR, data->input_file_name,
  185. (char *) NULL);
  186. mctest_assert_str_eq (actual_result, expected_file_path);
  187. g_free (expected_file_path);
  188. }
  189. g_free (actual_result);
  190. }
  191. /* *INDENT-OFF* */
  192. END_PARAMETRIZED_TEST
  193. /* *INDENT-ON* */
  194. /* --------------------------------------------------------------------------------------------- */
  195. int
  196. main (void)
  197. {
  198. int number_failed;
  199. Suite *s = suite_create (TEST_SUITE_NAME);
  200. TCase *tc_core = tcase_create ("Core");
  201. SRunner *sr;
  202. tcase_add_checked_fixture (tc_core, setup, teardown);
  203. /* Add new tests here: *************** */
  204. mctest_add_parameterized_test (tc_core, test_user_config_paths, test_user_config_paths_ds);
  205. /* *********************************** */
  206. suite_add_tcase (s, tc_core);
  207. sr = srunner_create (s);
  208. srunner_set_log (sr, "user_configs_path.log");
  209. srunner_run_all (sr, CK_ENV);
  210. number_failed = srunner_ntests_failed (sr);
  211. srunner_free (sr);
  212. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  213. }
  214. /* --------------------------------------------------------------------------------------------- */