root/tests/src/filemanager/cd_to.c

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

DEFINITIONS

This source file includes following definitions.
  1. get_current_type
  2. panel_cd
  3. mc_config_get_home_dir
  4. setup
  5. teardown
  6. START_PARAMETRIZED_TEST
  7. main

   1 /*
   2    src/filemanager - tests for cd_to() function
   3 
   4    Copyright (C) 2011-2025
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Slava Zanko <slavazanko@gmail.com>, 2011, 2013
   9    Andrew Borodin <aborodin@vmail.ru>, 2019, 2020
  10 
  11    This file is part of the Midnight Commander.
  12 
  13    The Midnight Commander is free software: you can redistribute it
  14    and/or modify it under the terms of the GNU General Public License as
  15    published by the Free Software Foundation, either version 3 of the License,
  16    or (at your option) any later version.
  17 
  18    The Midnight Commander is distributed in the hope that it will be useful,
  19    but WITHOUT ANY WARRANTY; without even the implied warranty of
  20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21    GNU General Public License for more details.
  22 
  23    You should have received a copy of the GNU General Public License
  24    along with this program.  If not, see <https://www.gnu.org/licenses/>.
  25  */
  26 
  27 #define TEST_SUITE_NAME "/src/filemanager"
  28 
  29 #include "tests/mctest.h"
  30 
  31 #include "src/vfs/local/local.c"
  32 
  33 #include "src/filemanager/cd.c"
  34 #include "src/filemanager/panel.h"
  35 
  36 /* --------------------------------------------------------------------------------------------- */
  37 
  38 /* @ThenReturnValue */
  39 static panel_view_mode_t get_current_type__return_value;
  40 
  41 /* @Mock */
  42 panel_view_mode_t
  43 get_current_type (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  44 {
  45     return get_current_type__return_value;
  46 }
  47 
  48 /* --------------------------------------------------------------------------------------------- */
  49 
  50 /* @CapturedValue */
  51 static vfs_path_t *do_cd__new_dir_vpath__captured;
  52 /* @CapturedValue */
  53 static enum cd_enum do_cd__cd_type__captured;
  54 /* @ThenReturnValue */
  55 static gboolean do_cd__return_value;
  56 
  57 /* @Mock */
  58 gboolean
  59 panel_cd (WPanel *panel, const vfs_path_t *new_dir_vpath, enum cd_enum cd_type)
     /* [previous][next][first][last][top][bottom][index][help]  */
  60 {
  61     (void) panel;
  62 
  63     do_cd__new_dir_vpath__captured = vfs_path_clone (new_dir_vpath);
  64     do_cd__cd_type__captured = cd_type;
  65     return do_cd__return_value;
  66 }
  67 
  68 /* --------------------------------------------------------------------------------------------- */
  69 
  70 /* @ThenReturnValue */
  71 static const char *mc_config_get_home_dir__return_value;
  72 
  73 /* @Mock */
  74 const char *
  75 mc_config_get_home_dir (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  76 {
  77     return mc_config_get_home_dir__return_value;
  78 }
  79 
  80 /* --------------------------------------------------------------------------------------------- */
  81 
  82 /* @Before */
  83 static void
  84 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  85 {
  86     str_init_strings (NULL);
  87 
  88     vfs_init ();
  89     vfs_init_localfs ();
  90     vfs_setup_work_dir ();
  91     do_cd__new_dir_vpath__captured = NULL;
  92 }
  93 
  94 /* --------------------------------------------------------------------------------------------- */
  95 
  96 /* @After */
  97 static void
  98 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  99 {
 100     vfs_path_free (do_cd__new_dir_vpath__captured, TRUE);
 101     vfs_shut ();
 102     str_uninit_strings ();
 103 }
 104 
 105 /* --------------------------------------------------------------------------------------------- */
 106 
 107 /* @DataSource("test_empty_mean_home_ds") */
 108 static const struct test_empty_mean_home_ds
 109 {
 110     const char *command;
 111 } test_empty_mean_home_ds[] = {
 112     { "" },
 113     { "                      " },
 114     { "\t\t\t\t\t\t\t\t\t\t\t" },
 115     { "  \t   \t  \t\t    \t    " },
 116 };
 117 
 118 /* @Test(dataSource = "test_empty_mean_home_ds") */
 119 START_PARAMETRIZED_TEST (test_empty_mean_home, test_empty_mean_home_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 120 {
 121     // given
 122     get_current_type__return_value = view_listing;
 123     do_cd__return_value = TRUE;
 124     mc_config_get_home_dir__return_value = "/home/test";
 125 
 126     // when
 127     {
 128         char *input_command;
 129 
 130         input_command = g_strdup (data->command);
 131         cd_to (input_command);
 132         g_free (input_command);
 133     }
 134     // then
 135     mctest_assert_str_eq (mc_config_get_home_dir__return_value,
 136                           vfs_path_as_str (do_cd__new_dir_vpath__captured));
 137     ck_assert_int_eq (do_cd__cd_type__captured, cd_parse_command);
 138 }
 139 END_PARAMETRIZED_TEST
 140 
 141 /* --------------------------------------------------------------------------------------------- */
 142 
 143 int
 144 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 145 {
 146     TCase *tc_core;
 147 
 148     tc_core = tcase_create ("Core");
 149 
 150     tcase_add_checked_fixture (tc_core, setup, teardown);
 151 
 152     // Add new tests here: ***************
 153     mctest_add_parameterized_test (tc_core, test_empty_mean_home, test_empty_mean_home_ds);
 154     // ***********************************
 155 
 156     return mctest_run_all (tc_core);
 157 }
 158 
 159 /* --------------------------------------------------------------------------------------------- */

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