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-2021
   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 <http://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 /* *INDENT-OFF* */
 109 static const struct test_empty_mean_home_ds
 110 {
 111     const char *command;
 112 } test_empty_mean_home_ds[] =
 113 {
 114     {
 115         ""
 116     },
 117     {
 118         "                      "
 119     },
 120     {
 121         "\t\t\t\t\t\t\t\t\t\t\t"
 122     },
 123     {
 124         "  \t   \t  \t\t    \t    "
 125     },
 126 };
 127 /* *INDENT-ON* */
 128 
 129 /* @Test(dataSource = "test_empty_mean_home_ds") */
 130 /* *INDENT-OFF* */
 131 START_PARAMETRIZED_TEST (test_empty_mean_home, test_empty_mean_home_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 132 /* *INDENT-ON* */
 133 {
 134     /* given */
 135     get_current_type__return_value = view_listing;
 136     do_cd__return_value = TRUE;
 137     mc_config_get_home_dir__return_value = "/home/test";
 138 
 139     /* when */
 140     {
 141         char *input_command;
 142 
 143         input_command = g_strdup (data->command);
 144         cd_to (input_command);
 145         g_free (input_command);
 146     }
 147     /* then */
 148     mctest_assert_str_eq (mc_config_get_home_dir__return_value,
 149                           vfs_path_as_str (do_cd__new_dir_vpath__captured));
 150     mctest_assert_int_eq (do_cd__cd_type__captured, cd_parse_command);
 151 }
 152 /* *INDENT-OFF* */
 153 END_PARAMETRIZED_TEST
 154 /* *INDENT-ON* */
 155 
 156 /* --------------------------------------------------------------------------------------------- */
 157 
 158 int
 159 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 160 {
 161     TCase *tc_core;
 162 
 163     tc_core = tcase_create ("Core");
 164 
 165     tcase_add_checked_fixture (tc_core, setup, teardown);
 166 
 167     /* Add new tests here: *************** */
 168     mctest_add_parameterized_test (tc_core, test_empty_mean_home, test_empty_mean_home_ds);
 169     /* *********************************** */
 170 
 171     return mctest_run_all (tc_core);
 172 }
 173 
 174 /* --------------------------------------------------------------------------------------------- */

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