user_configs_path.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. libmc - check mcconfig submodule. Get full paths to user's config files.
  3. Copyright (C) 2011
  4. The Free Software Foundation, Inc.
  5. Written by:
  6. Slava Zanko <slavazanko@gmail.com>, 2011
  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 <config.h>
  21. #include <check.h>
  22. #include "lib/global.h"
  23. #include "lib/strutil.h"
  24. #include "lib/strescape.h"
  25. #include "lib/vfs/vfs.h"
  26. #include "lib/fileloc.h"
  27. #include "lib/mcconfig.h"
  28. #include "src/vfs/local/local.c"
  29. #define HOME_DIR "/home/testuser"
  30. #ifdef MC_HOMEDIR_XDG
  31. # define CONF_MAIN HOME_DIR PATH_SEP_STR ".config"
  32. # define CONF_DATA HOME_DIR PATH_SEP_STR ".local" PATH_SEP_STR "share"
  33. # define CONF_CACHE HOME_DIR PATH_SEP_STR ".cache"
  34. #else
  35. # define CONF_MAIN HOME_DIR
  36. # define CONF_DATA CONF_MAIN
  37. # define CONF_CACHE CONF_MAIN
  38. #endif
  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. static void
  53. teardown (void)
  54. {
  55. vfs_shut ();
  56. str_uninit_strings();
  57. }
  58. #define path_fail_unless(conf_dir, conf_name) {\
  59. result = mc_config_get_full_path (conf_name); \
  60. fail_unless (strcmp( conf_dir PATH_SEP_STR MC_USERCONF_DIR PATH_SEP_STR conf_name, result) == 0); \
  61. g_free (result); \
  62. }
  63. /* --------------------------------------------------------------------------------------------- */
  64. START_TEST (user_configs_path_test)
  65. {
  66. char *result;
  67. path_fail_unless (CONF_MAIN, MC_CONFIG_FILE);
  68. path_fail_unless (CONF_MAIN, MC_FHL_INI_FILE);
  69. path_fail_unless (CONF_MAIN, MC_HOTLIST_FILE);
  70. path_fail_unless (CONF_MAIN, GLOBAL_KEYMAP_FILE);
  71. path_fail_unless (CONF_MAIN, MC_USERMENU_FILE);
  72. path_fail_unless (CONF_MAIN, EDIT_SYNTAX_FILE);
  73. path_fail_unless (CONF_MAIN, EDIT_HOME_MENU);
  74. path_fail_unless (CONF_MAIN, EDIT_DIR PATH_SEP_STR "edit.indent.rc");
  75. path_fail_unless (CONF_MAIN, EDIT_DIR PATH_SEP_STR "edit.spell.rc");
  76. path_fail_unless (CONF_MAIN, MC_PANELS_FILE);
  77. path_fail_unless (CONF_MAIN, MC_FILEBIND_FILE);
  78. path_fail_unless (CONF_DATA, MC_SKINS_SUBDIR);
  79. path_fail_unless (CONF_DATA, FISH_PREFIX);
  80. path_fail_unless (CONF_DATA, "bashrc");
  81. path_fail_unless (CONF_DATA, "inputrc");
  82. path_fail_unless (CONF_DATA, MC_EXTFS_DIR);
  83. path_fail_unless (CONF_DATA, MC_HISTORY_FILE);
  84. path_fail_unless (CONF_DATA, MC_FILEPOS_FILE);
  85. path_fail_unless (CONF_DATA, EDIT_CLIP_FILE);
  86. path_fail_unless (CONF_DATA, MC_MACRO_FILE);
  87. path_fail_unless (CONF_CACHE, "mc.log");
  88. path_fail_unless (CONF_CACHE, MC_TREESTORE_FILE);
  89. path_fail_unless (CONF_CACHE, EDIT_TEMP_FILE);
  90. path_fail_unless (CONF_CACHE, EDIT_BLOCK_FILE);
  91. }
  92. END_TEST
  93. /* --------------------------------------------------------------------------------------------- */
  94. int
  95. main (void)
  96. {
  97. int number_failed;
  98. Suite *s = suite_create (TEST_SUITE_NAME);
  99. TCase *tc_core = tcase_create ("Core");
  100. SRunner *sr;
  101. tcase_add_checked_fixture (tc_core, setup, teardown);
  102. /* Add new tests here: *************** */
  103. tcase_add_test (tc_core, user_configs_path_test);
  104. /* *********************************** */
  105. suite_add_tcase (s, tc_core);
  106. sr = srunner_create (s);
  107. srunner_set_log (sr, "user_configs_path.log");
  108. // srunner_set_fork_status (sr, CK_NOFORK);
  109. srunner_run_all (sr, CK_NORMAL);
  110. number_failed = srunner_ntests_failed (sr);
  111. srunner_free (sr);
  112. return (number_failed == 0) ? 0 : 1;
  113. }
  114. /* --------------------------------------------------------------------------------------------- */