root/tests/lib/mcconfig/user_configs_path.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. setup
  2. teardown
  3. START_PARAMETRIZED_TEST
  4. main

   1 /*
   2    libmc - check mcconfig submodule. Get full paths to user's config files.
   3 
   4    Copyright (C) 2011-2019
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Slava Zanko <slavazanko@gmail.com>, 2011, 2013
   9 
  10    This file is part of the Midnight Commander.
  11 
  12    The Midnight Commander is free software: you can redistribute it
  13    and/or modify it under the terms of the GNU General Public License as
  14    published by the Free Software Foundation, either version 3 of the License,
  15    or (at your option) any later version.
  16 
  17    The Midnight Commander is distributed in the hope that it will be useful,
  18    but WITHOUT ANY WARRANTY; without even the implied warranty of
  19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20    GNU General Public License for more details.
  21 
  22    You should have received a copy of the GNU General Public License
  23    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  24  */
  25 
  26 #define TEST_SUITE_NAME "lib/mcconfig"
  27 
  28 #include "tests/mctest.h"
  29 
  30 #include "lib/strutil.h"
  31 #include "lib/strescape.h"
  32 #include "lib/vfs/vfs.h"
  33 #include "lib/fileloc.h"
  34 
  35 #include "lib/mcconfig.h"
  36 #include "src/vfs/local/local.c"
  37 
  38 #define HOME_DIR "/home/testuser"
  39 
  40 #if MC_HOMEDIR_XDG
  41 #define CONF_MAIN HOME_DIR PATH_SEP_STR ".config"
  42 #define CONF_DATA HOME_DIR PATH_SEP_STR ".local" PATH_SEP_STR "share"
  43 #define CONF_CACHE HOME_DIR PATH_SEP_STR ".cache"
  44 #else
  45 #define CONF_MAIN HOME_DIR
  46 #define CONF_DATA CONF_MAIN
  47 #define CONF_CACHE CONF_MAIN
  48 #endif
  49 
  50 /* --------------------------------------------------------------------------------------------- */
  51 
  52 /* @Before */
  53 static void
  54 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  55 {
  56     g_setenv ("HOME", HOME_DIR, TRUE);
  57 #if MC_HOMEDIR_XDG
  58     g_setenv ("XDG_CONFIG_HOME", CONF_MAIN, TRUE);
  59     g_setenv ("XDG_DATA_HOME", CONF_DATA, TRUE);
  60     g_setenv ("XDG_CACHE_HOME", CONF_CACHE, TRUE);
  61 #endif
  62     str_init_strings ("UTF-8");
  63     vfs_init ();
  64     init_localfs ();
  65 }
  66 
  67 /* --------------------------------------------------------------------------------------------- */
  68 
  69 /* @After */
  70 static void
  71 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  72 {
  73     vfs_shut ();
  74     str_uninit_strings ();
  75 }
  76 
  77 /* --------------------------------------------------------------------------------------------- */
  78 
  79 /* @DataSource("test_user_config_paths_ds") */
  80 /* *INDENT-OFF* */
  81 static const struct test_user_config_paths_ds
  82 {
  83     const char *input_base_dir;
  84     const char *input_file_name;
  85 } test_user_config_paths_ds[] =
  86 {
  87     { /* 0. */
  88         CONF_MAIN,
  89         MC_CONFIG_FILE
  90     },
  91     { /* 1. */
  92         CONF_MAIN,
  93         MC_FHL_INI_FILE
  94     },
  95     { /* 2. */
  96         CONF_MAIN,
  97         MC_HOTLIST_FILE
  98     },
  99     { /* 3. */
 100         CONF_MAIN,
 101         GLOBAL_KEYMAP_FILE
 102     },
 103     { /* 4. */
 104         CONF_MAIN,
 105         MC_USERMENU_FILE
 106     },
 107     { /* 5. */
 108         CONF_MAIN,
 109         EDIT_SYNTAX_FILE
 110     },
 111     { /* 6. */
 112         CONF_MAIN,
 113         EDIT_HOME_MENU
 114     },
 115     { /* 7. */
 116         CONF_MAIN,
 117         EDIT_DIR PATH_SEP_STR "edit.indent.rc"
 118     },
 119     { /* 8. */
 120         CONF_MAIN,
 121         EDIT_DIR PATH_SEP_STR "edit.spell.rc"
 122     },
 123     { /* 9. */
 124         CONF_MAIN,
 125         MC_PANELS_FILE
 126     },
 127     { /* 10. */
 128         CONF_MAIN,
 129         MC_FILEBIND_FILE
 130     },
 131     { /* 11. */
 132         CONF_DATA,
 133         MC_SKINS_SUBDIR
 134     },
 135     { /* 12. */
 136         CONF_DATA,
 137         FISH_PREFIX
 138     },
 139     { /* 13. */
 140         CONF_DATA,
 141         "ashrc"
 142     },
 143     { /* 14. */
 144         CONF_DATA,
 145         "bashrc"
 146     },
 147     { /* 15. */
 148         CONF_DATA,
 149         "inputrc"
 150     },
 151     { /* 16. */
 152         CONF_DATA,
 153         MC_EXTFS_DIR
 154     },
 155     { /* 17. */
 156         CONF_DATA,
 157         MC_HISTORY_FILE
 158     },
 159     { /* 18. */
 160         CONF_DATA,
 161         MC_FILEPOS_FILE
 162     },
 163     { /* 19. */
 164         CONF_DATA,
 165         EDIT_CLIP_FILE
 166     },
 167     { /* 20. */
 168         CONF_DATA,
 169         MC_MACRO_FILE
 170     },
 171     { /* 21. */
 172         CONF_CACHE,
 173         "mc.log"
 174     },
 175     { /* 22. */
 176         CONF_CACHE,
 177         MC_TREESTORE_FILE
 178     },
 179     { /* 23. */
 180         CONF_CACHE,
 181         EDIT_TEMP_FILE
 182     },
 183     { /* 24. */
 184         CONF_CACHE,
 185         EDIT_BLOCK_FILE
 186     },
 187 };
 188 /* *INDENT-ON* */
 189 
 190 /* @Test(dataSource = "test_user_config_paths_ds") */
 191 /* *INDENT-OFF* */
 192 START_PARAMETRIZED_TEST (test_user_config_paths, test_user_config_paths_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 193 /* *INDENT-ON* */
 194 {
 195     /* given */
 196     char *actual_result;
 197 
 198     /* when */
 199     actual_result = mc_config_get_full_path (data->input_file_name);
 200 
 201     /* then */
 202     {
 203         char *expected_file_path;
 204 
 205         expected_file_path =
 206             g_build_filename (data->input_base_dir, MC_USERCONF_DIR, data->input_file_name,
 207                               (char *) NULL);
 208         mctest_assert_str_eq (actual_result, expected_file_path);
 209         g_free (expected_file_path);
 210     }
 211     g_free (actual_result);
 212 }
 213 /* *INDENT-OFF* */
 214 END_PARAMETRIZED_TEST
 215 /* *INDENT-ON* */
 216 
 217 /* --------------------------------------------------------------------------------------------- */
 218 
 219 int
 220 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 221 {
 222     int number_failed;
 223 
 224     Suite *s = suite_create (TEST_SUITE_NAME);
 225     TCase *tc_core = tcase_create ("Core");
 226     SRunner *sr;
 227 
 228     tcase_add_checked_fixture (tc_core, setup, teardown);
 229 
 230     /* Add new tests here: *************** */
 231     mctest_add_parameterized_test (tc_core, test_user_config_paths, test_user_config_paths_ds);
 232     /* *********************************** */
 233 
 234     suite_add_tcase (s, tc_core);
 235     sr = srunner_create (s);
 236     srunner_set_log (sr, "user_configs_path.log");
 237     srunner_run_all (sr, CK_ENV);
 238     number_failed = srunner_ntests_failed (sr);
 239     srunner_free (sr);
 240     return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 241 }
 242 
 243 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */