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-2024
   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 #define CONF_MAIN HOME_DIR PATH_SEP_STR ".config"
  41 #define CONF_DATA HOME_DIR PATH_SEP_STR ".local" PATH_SEP_STR "share"
  42 #define CONF_CACHE HOME_DIR PATH_SEP_STR ".cache"
  43 
  44 /* --------------------------------------------------------------------------------------------- */
  45 
  46 /* @Before */
  47 static void
  48 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  49 {
  50     g_setenv ("HOME", HOME_DIR, TRUE);
  51     g_setenv ("XDG_CONFIG_HOME", CONF_MAIN, TRUE);
  52     g_setenv ("XDG_DATA_HOME", CONF_DATA, TRUE);
  53     g_setenv ("XDG_CACHE_HOME", CONF_CACHE, TRUE);
  54     str_init_strings ("UTF-8");
  55     vfs_init ();
  56     vfs_init_localfs ();
  57 }
  58 
  59 /* --------------------------------------------------------------------------------------------- */
  60 
  61 /* @After */
  62 static void
  63 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  64 {
  65     vfs_shut ();
  66     str_uninit_strings ();
  67 }
  68 
  69 /* --------------------------------------------------------------------------------------------- */
  70 
  71 /* @DataSource("test_user_config_paths_ds") */
  72 /* *INDENT-OFF* */
  73 static const struct test_user_config_paths_ds
  74 {
  75     const char *input_base_dir;
  76     const char *input_file_name;
  77 } test_user_config_paths_ds[] =
  78 {
  79     { /* 0. */
  80         CONF_MAIN,
  81         MC_CONFIG_FILE
  82     },
  83     { /* 1. */
  84         CONF_MAIN,
  85         MC_FHL_INI_FILE
  86     },
  87     { /* 2. */
  88         CONF_MAIN,
  89         MC_HOTLIST_FILE
  90     },
  91     { /* 3. */
  92         CONF_MAIN,
  93         GLOBAL_KEYMAP_FILE
  94     },
  95     { /* 4. */
  96         CONF_MAIN,
  97         MC_USERMENU_FILE
  98     },
  99     { /* 5. */
 100         CONF_DATA,
 101         EDIT_SYNTAX_FILE
 102     },
 103     { /* 6. */
 104         CONF_MAIN,
 105         EDIT_HOME_MENU
 106     },
 107     { /* 7. */
 108         CONF_MAIN,
 109         MC_PANELS_FILE
 110     },
 111     { /* 8. */
 112         CONF_MAIN,
 113         MC_EXT_FILE
 114     },
 115     { /* 9. */
 116         CONF_DATA,
 117         MC_SKINS_DIR
 118     },
 119     { /* 10. */
 120         CONF_DATA,
 121         VFS_SHELL_PREFIX
 122     },
 123     { /* 11. */
 124         CONF_DATA,
 125         MC_ASHRC_FILE
 126     },
 127     { /* 12. */
 128         CONF_DATA,
 129         MC_BASHRC_FILE
 130     },
 131     { /* 13. */
 132         CONF_DATA,
 133         MC_INPUTRC_FILE
 134     },
 135     { /* 14. */
 136         CONF_DATA,
 137         MC_ZSHRC_FILE
 138     },
 139     { /* 15. */
 140         CONF_DATA,
 141         MC_EXTFS_DIR
 142     },
 143     { /* 16. */
 144         CONF_DATA,
 145         MC_HISTORY_FILE
 146     },
 147     { /* 17. */
 148         CONF_DATA,
 149         MC_FILEPOS_FILE
 150     },
 151     { /* 18. */
 152         CONF_DATA,
 153         EDIT_HOME_CLIP_FILE
 154     },
 155     { /* 19. */
 156         CONF_DATA,
 157         MC_MACRO_FILE
 158     },
 159     { /* 20. */
 160         CONF_CACHE,
 161         "mc.log"
 162     },
 163     { /* 21. */
 164         CONF_CACHE,
 165         MC_TREESTORE_FILE
 166     },
 167     { /* 22. */
 168         CONF_CACHE,
 169         EDIT_HOME_TEMP_FILE
 170     },
 171     { /* 23. */
 172         CONF_CACHE,
 173         EDIT_HOME_BLOCK_FILE
 174     },
 175 };
 176 /* *INDENT-ON* */
 177 
 178 /* @Test(dataSource = "test_user_config_paths_ds") */
 179 /* *INDENT-OFF* */
 180 START_PARAMETRIZED_TEST (test_user_config_paths, test_user_config_paths_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 181 /* *INDENT-ON* */
 182 {
 183     /* given */
 184     char *actual_result;
 185 
 186     /* when */
 187     actual_result = mc_config_get_full_path (data->input_file_name);
 188 
 189     /* then */
 190     {
 191         char *expected_file_path;
 192 
 193         expected_file_path =
 194             g_build_filename (data->input_base_dir, MC_USERCONF_DIR, data->input_file_name,
 195                               (char *) NULL);
 196         mctest_assert_str_eq (actual_result, expected_file_path);
 197         g_free (expected_file_path);
 198     }
 199     g_free (actual_result);
 200 }
 201 /* *INDENT-OFF* */
 202 END_PARAMETRIZED_TEST
 203 /* *INDENT-ON* */
 204 
 205 /* --------------------------------------------------------------------------------------------- */
 206 
 207 int
 208 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 209 {
 210     TCase *tc_core;
 211 
 212     tc_core = tcase_create ("Core");
 213 
 214     tcase_add_checked_fixture (tc_core, setup, teardown);
 215 
 216     /* Add new tests here: *************** */
 217     mctest_add_parameterized_test (tc_core, test_user_config_paths, test_user_config_paths_ds);
 218     /* *********************************** */
 219 
 220     return mctest_run_all (tc_core);
 221 }
 222 
 223 /* --------------------------------------------------------------------------------------------- */

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