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-2020
   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     mc_global.timer = mc_timer_new ();
  63     str_init_strings ("UTF-8");
  64     vfs_init ();
  65     vfs_init_localfs ();
  66 }
  67 
  68 /* --------------------------------------------------------------------------------------------- */
  69 
  70 /* @After */
  71 static void
  72 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  73 {
  74     vfs_shut ();
  75     str_uninit_strings ();
  76     mc_timer_destroy (mc_global.timer);
  77 }
  78 
  79 /* --------------------------------------------------------------------------------------------- */
  80 
  81 /* @DataSource("test_user_config_paths_ds") */
  82 /* *INDENT-OFF* */
  83 static const struct test_user_config_paths_ds
  84 {
  85     const char *input_base_dir;
  86     const char *input_file_name;
  87 } test_user_config_paths_ds[] =
  88 {
  89     { /* 0. */
  90         CONF_MAIN,
  91         MC_CONFIG_FILE
  92     },
  93     { /* 1. */
  94         CONF_MAIN,
  95         MC_FHL_INI_FILE
  96     },
  97     { /* 2. */
  98         CONF_MAIN,
  99         MC_HOTLIST_FILE
 100     },
 101     { /* 3. */
 102         CONF_MAIN,
 103         GLOBAL_KEYMAP_FILE
 104     },
 105     { /* 4. */
 106         CONF_MAIN,
 107         MC_USERMENU_FILE
 108     },
 109     { /* 5. */
 110         CONF_MAIN,
 111         EDIT_HOME_SYNTAX_FILE
 112     },
 113     { /* 6. */
 114         CONF_MAIN,
 115         EDIT_HOME_MENU
 116     },
 117     { /* 7. */
 118         CONF_MAIN,
 119         MC_PANELS_FILE
 120     },
 121     { /* 8. */
 122         CONF_MAIN,
 123         MC_FILEBIND_FILE
 124     },
 125     { /* 9. */
 126         CONF_DATA,
 127         MC_SKINS_DIR
 128     },
 129     { /* 10. */
 130         CONF_DATA,
 131         FISH_PREFIX
 132     },
 133     { /* 11. */
 134         CONF_DATA,
 135         "ashrc"
 136     },
 137     { /* 12. */
 138         CONF_DATA,
 139         "bashrc"
 140     },
 141     { /* 13. */
 142         CONF_DATA,
 143         "inputrc"
 144     },
 145     { /* 14. */
 146         CONF_DATA,
 147         MC_EXTFS_DIR
 148     },
 149     { /* 15. */
 150         CONF_DATA,
 151         MC_HISTORY_FILE
 152     },
 153     { /* 16. */
 154         CONF_DATA,
 155         MC_FILEPOS_FILE
 156     },
 157     { /* 17. */
 158         CONF_DATA,
 159         EDIT_HOME_CLIP_FILE
 160     },
 161     { /* 18. */
 162         CONF_DATA,
 163         MC_MACRO_FILE
 164     },
 165     { /* 19. */
 166         CONF_CACHE,
 167         "mc.log"
 168     },
 169     { /* 20. */
 170         CONF_CACHE,
 171         MC_TREESTORE_FILE
 172     },
 173     { /* 21. */
 174         CONF_CACHE,
 175         EDIT_HOME_TEMP_FILE
 176     },
 177     { /* 22. */
 178         CONF_CACHE,
 179         EDIT_HOME_BLOCK_FILE
 180     },
 181 };
 182 /* *INDENT-ON* */
 183 
 184 /* @Test(dataSource = "test_user_config_paths_ds") */
 185 /* *INDENT-OFF* */
 186 START_PARAMETRIZED_TEST (test_user_config_paths, test_user_config_paths_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 187 /* *INDENT-ON* */
 188 {
 189     /* given */
 190     char *actual_result;
 191 
 192     /* when */
 193     actual_result = mc_config_get_full_path (data->input_file_name);
 194 
 195     /* then */
 196     {
 197         char *expected_file_path;
 198 
 199         expected_file_path =
 200             g_build_filename (data->input_base_dir, MC_USERCONF_DIR, data->input_file_name,
 201                               (char *) NULL);
 202         mctest_assert_str_eq (actual_result, expected_file_path);
 203         g_free (expected_file_path);
 204     }
 205     g_free (actual_result);
 206 }
 207 /* *INDENT-OFF* */
 208 END_PARAMETRIZED_TEST
 209 /* *INDENT-ON* */
 210 
 211 /* --------------------------------------------------------------------------------------------- */
 212 
 213 int
 214 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 215 {
 216     int number_failed;
 217 
 218     Suite *s = suite_create (TEST_SUITE_NAME);
 219     TCase *tc_core = tcase_create ("Core");
 220     SRunner *sr;
 221 
 222     tcase_add_checked_fixture (tc_core, setup, teardown);
 223 
 224     /* Add new tests here: *************** */
 225     mctest_add_parameterized_test (tc_core, test_user_config_paths, test_user_config_paths_ds);
 226     /* *********************************** */
 227 
 228     suite_add_tcase (s, tc_core);
 229     sr = srunner_create (s);
 230     srunner_set_log (sr, "user_configs_path.log");
 231     srunner_run_all (sr, CK_ENV);
 232     number_failed = srunner_ntests_failed (sr);
 233     srunner_free (sr);
 234     return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 235 }
 236 
 237 /* --------------------------------------------------------------------------------------------- */

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