user_configs_path.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /*
  2. libmc - check mcconfig submodule. Get full paths to user's config files.
  3. Copyright (C) 2011, 2013
  4. The 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. #ifdef 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. #ifdef 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. 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. { /* 0. */
  74. CONF_MAIN,
  75. MC_FHL_INI_FILE
  76. },
  77. { /* 0. */
  78. CONF_MAIN,
  79. MC_HOTLIST_FILE
  80. },
  81. { /* 0. */
  82. CONF_MAIN,
  83. GLOBAL_KEYMAP_FILE
  84. },
  85. { /* 0. */
  86. CONF_MAIN,
  87. MC_USERMENU_FILE
  88. },
  89. { /* 0. */
  90. CONF_MAIN,
  91. EDIT_SYNTAX_FILE
  92. },
  93. { /* 0. */
  94. CONF_MAIN,
  95. EDIT_HOME_MENU
  96. },
  97. { /* 0. */
  98. CONF_MAIN,
  99. EDIT_DIR PATH_SEP_STR "edit.indent.rc"
  100. },
  101. { /* 0. */
  102. CONF_MAIN,
  103. EDIT_DIR PATH_SEP_STR "edit.spell.rc"
  104. },
  105. { /* 0. */
  106. CONF_MAIN,
  107. MC_PANELS_FILE
  108. },
  109. { /* 0. */
  110. CONF_MAIN,
  111. MC_FILEBIND_FILE
  112. },
  113. { /* 0. */
  114. CONF_DATA,
  115. MC_SKINS_SUBDIR
  116. },
  117. { /* 0. */
  118. CONF_DATA,
  119. FISH_PREFIX
  120. },
  121. { /* 0. */
  122. CONF_DATA,
  123. "bashrc"
  124. },
  125. { /* 0. */
  126. CONF_DATA,
  127. "inputrc"
  128. },
  129. { /* 0. */
  130. CONF_DATA,
  131. MC_EXTFS_DIR
  132. },
  133. { /* 0. */
  134. CONF_DATA,
  135. MC_HISTORY_FILE
  136. },
  137. { /* 0. */
  138. CONF_DATA,
  139. MC_FILEPOS_FILE
  140. },
  141. { /* 0. */
  142. CONF_DATA,
  143. EDIT_CLIP_FILE
  144. },
  145. { /* 0. */
  146. CONF_DATA,
  147. MC_MACRO_FILE
  148. },
  149. { /* 0. */
  150. CONF_CACHE,
  151. "mc.log"
  152. },
  153. { /* 0. */
  154. CONF_CACHE,
  155. MC_TREESTORE_FILE
  156. },
  157. { /* 0. */
  158. CONF_CACHE,
  159. EDIT_TEMP_FILE
  160. },
  161. { /* 0. */
  162. CONF_CACHE,
  163. EDIT_BLOCK_FILE
  164. },
  165. };
  166. /* *INDENT-ON* */
  167. /* @Test(dataSource = "test_user_config_paths_ds") */
  168. /* *INDENT-OFF* */
  169. START_PARAMETRIZED_TEST (test_user_config_paths, test_user_config_paths_ds)
  170. /* *INDENT-ON* */
  171. {
  172. /* given */
  173. char *actual_result;
  174. /* when */
  175. actual_result = mc_config_get_full_path (data->input_file_name);
  176. /* then */
  177. {
  178. char *expected_file_path;
  179. expected_file_path =
  180. g_build_filename (data->input_base_dir, MC_USERCONF_DIR, data->input_file_name, NULL);
  181. mctest_assert_str_eq (actual_result, expected_file_path);
  182. g_free (expected_file_path);
  183. }
  184. g_free (actual_result);
  185. }
  186. /* *INDENT-OFF* */
  187. END_PARAMETRIZED_TEST
  188. /* *INDENT-ON* */
  189. /* --------------------------------------------------------------------------------------------- */
  190. int
  191. main (void)
  192. {
  193. int number_failed;
  194. Suite *s = suite_create (TEST_SUITE_NAME);
  195. TCase *tc_core = tcase_create ("Core");
  196. SRunner *sr;
  197. tcase_add_checked_fixture (tc_core, setup, teardown);
  198. /* Add new tests here: *************** */
  199. mctest_add_parameterized_test (tc_core, test_user_config_paths, test_user_config_paths_ds);
  200. /* *********************************** */
  201. suite_add_tcase (s, tc_core);
  202. sr = srunner_create (s);
  203. srunner_set_log (sr, "user_configs_path.log");
  204. /* srunner_set_fork_status (sr, CK_NOFORK); */
  205. srunner_run_all (sr, CK_NORMAL);
  206. number_failed = srunner_ntests_failed (sr);
  207. srunner_free (sr);
  208. return (number_failed == 0) ? 0 : 1;
  209. }
  210. /* --------------------------------------------------------------------------------------------- */