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-2025
   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 <https://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/vfs/vfs.h"
  32 #include "lib/fileloc.h"
  33 
  34 #include "lib/mcconfig.h"
  35 #include "src/vfs/local/local.c"
  36 
  37 #define HOME_DIR   "/home/testuser"
  38 
  39 #define CONF_MAIN  HOME_DIR PATH_SEP_STR ".config"
  40 #define CONF_DATA  HOME_DIR PATH_SEP_STR ".local" PATH_SEP_STR "share"
  41 #define CONF_CACHE HOME_DIR PATH_SEP_STR ".cache"
  42 
  43 /* --------------------------------------------------------------------------------------------- */
  44 
  45 /* @Before */
  46 static void
  47 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  48 {
  49     g_setenv ("HOME", HOME_DIR, TRUE);
  50     g_setenv ("XDG_CONFIG_HOME", CONF_MAIN, TRUE);
  51     g_setenv ("XDG_DATA_HOME", CONF_DATA, TRUE);
  52     g_setenv ("XDG_CACHE_HOME", CONF_CACHE, TRUE);
  53     str_init_strings ("UTF-8");
  54     vfs_init ();
  55     vfs_init_localfs ();
  56 }
  57 
  58 /* --------------------------------------------------------------------------------------------- */
  59 
  60 /* @After */
  61 static void
  62 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  63 {
  64     vfs_shut ();
  65     str_uninit_strings ();
  66 }
  67 
  68 /* --------------------------------------------------------------------------------------------- */
  69 
  70 /* @DataSource("test_user_config_paths_ds") */
  71 static const struct test_user_config_paths_ds
  72 {
  73     const char *input_base_dir;
  74     const char *input_file_name;
  75 } test_user_config_paths_ds[] = {
  76     { CONF_MAIN, MC_CONFIG_FILE },         // 0.
  77     { CONF_MAIN, MC_FHL_INI_FILE },        // 1.
  78     { CONF_MAIN, MC_HOTLIST_FILE },        // 2.
  79     { CONF_MAIN, GLOBAL_KEYMAP_FILE },     // 3.
  80     { CONF_MAIN, MC_USERMENU_FILE },       // 4.
  81     { CONF_DATA, EDIT_SYNTAX_FILE },       // 5.
  82     { CONF_MAIN, EDIT_HOME_MENU },         // 6.
  83     { CONF_MAIN, MC_PANELS_FILE },         // 7.
  84     { CONF_MAIN, MC_EXT_FILE },            // 8.
  85     { CONF_DATA, MC_SKINS_DIR },           // 9.
  86     { CONF_DATA, VFS_SHELL_PREFIX },       // 10.
  87     { CONF_DATA, MC_ASHRC_FILE },          // 11.
  88     { CONF_DATA, MC_BASHRC_FILE },         // 12.
  89     { CONF_DATA, MC_INPUTRC_FILE },        // 13.
  90     { CONF_DATA, MC_ZSHRC_FILE },          // 14.
  91     { CONF_DATA, MC_EXTFS_DIR },           // 15.
  92     { CONF_DATA, MC_HISTORY_FILE },        // 16.
  93     { CONF_DATA, MC_FILEPOS_FILE },        // 17.
  94     { CONF_DATA, EDIT_HOME_CLIP_FILE },    // 18.
  95     { CONF_DATA, MC_MACRO_FILE },          // 19.
  96     { CONF_CACHE, "mc.log" },              // 20.
  97     { CONF_CACHE, MC_TREESTORE_FILE },     // 21.
  98     { CONF_CACHE, EDIT_HOME_TEMP_FILE },   // 22.
  99     { CONF_CACHE, EDIT_HOME_BLOCK_FILE },  // 23.
 100 };
 101 
 102 /* @Test(dataSource = "test_user_config_paths_ds") */
 103 START_PARAMETRIZED_TEST (test_user_config_paths, test_user_config_paths_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 104 {
 105     // given
 106     char *actual_result;
 107 
 108     // when
 109     actual_result = mc_config_get_full_path (data->input_file_name);
 110 
 111     // then
 112     {
 113         char *expected_file_path;
 114 
 115         expected_file_path = g_build_filename (data->input_base_dir, MC_USERCONF_DIR,
 116                                                data->input_file_name, (char *) NULL);
 117         mctest_assert_str_eq (actual_result, expected_file_path);
 118         g_free (expected_file_path);
 119     }
 120     g_free (actual_result);
 121 }
 122 END_PARAMETRIZED_TEST
 123 
 124 /* --------------------------------------------------------------------------------------------- */
 125 
 126 int
 127 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 128 {
 129     TCase *tc_core;
 130 
 131     tc_core = tcase_create ("Core");
 132 
 133     tcase_add_checked_fixture (tc_core, setup, teardown);
 134 
 135     // Add new tests here: ***************
 136     mctest_add_parameterized_test (tc_core, test_user_config_paths, test_user_config_paths_ds);
 137     // ***********************************
 138 
 139     return mctest_run_all (tc_core);
 140 }
 141 
 142 /* --------------------------------------------------------------------------------------------- */

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