root/tests/src/filemanager/do_cd_command.c

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

DEFINITIONS

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

   1 /*
   2    src/filemanager - tests for do_cd_command() function
   3 
   4    Copyright (C) 2011-2018
   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 "/src/filemanager"
  27 
  28 #include "tests/mctest.h"
  29 
  30 #include "src/vfs/local/local.c"
  31 
  32 #include "src/filemanager/command.c"
  33 
  34 
  35 /* --------------------------------------------------------------------------------------------- */
  36 
  37 /* @ThenReturnValue */
  38 static panel_view_mode_t get_current_type__return_value;
  39 
  40 /* @Mock */
  41 panel_view_mode_t
  42 get_current_type (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  43 {
  44     return get_current_type__return_value;
  45 }
  46 
  47 /* --------------------------------------------------------------------------------------------- */
  48 
  49 /* @CapturedValue */
  50 static vfs_path_t *do_cd__new_dir_vpath__captured;
  51 /* @CapturedValue */
  52 static enum cd_enum do_cd__cd_type__captured;
  53 /* @ThenReturnValue */
  54 static gboolean do_cd__return_value;
  55 
  56 /* @Mock */
  57 gboolean
  58 do_cd (const vfs_path_t * new_dir_vpath, enum cd_enum cd_type)
     /* [previous][next][first][last][top][bottom][index][help]  */
  59 {
  60     do_cd__new_dir_vpath__captured = vfs_path_clone (new_dir_vpath);
  61     do_cd__cd_type__captured = cd_type;
  62     return do_cd__return_value;
  63 }
  64 
  65 /* --------------------------------------------------------------------------------------------- */
  66 
  67 /* @ThenReturnValue */
  68 static const char *mc_config_get_home_dir__return_value;
  69 
  70 /* @Mock */
  71 const char *
  72 mc_config_get_home_dir (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  73 {
  74     return mc_config_get_home_dir__return_value;
  75 }
  76 
  77 /* --------------------------------------------------------------------------------------------- */
  78 
  79 /* @Before */
  80 static void
  81 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  82 {
  83     str_init_strings (NULL);
  84 
  85     vfs_init ();
  86     init_localfs ();
  87     vfs_setup_work_dir ();
  88     do_cd__new_dir_vpath__captured = NULL;
  89 }
  90 
  91 /* --------------------------------------------------------------------------------------------- */
  92 
  93 /* @After */
  94 static void
  95 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  96 {
  97     vfs_path_free (do_cd__new_dir_vpath__captured);
  98     vfs_shut ();
  99     str_uninit_strings ();
 100 }
 101 
 102 /* --------------------------------------------------------------------------------------------- */
 103 
 104 /* @DataSource("test_empty_mean_home_ds") */
 105 /* *INDENT-OFF* */
 106 static const struct test_empty_mean_home_ds
 107 {
 108     const char *command;
 109 } test_empty_mean_home_ds[] =
 110 {
 111     {
 112         "cd"
 113     },
 114     {
 115         "cd                      "
 116     },
 117     {
 118         "cd\t\t\t\t\t\t\t\t\t\t\t"
 119     },
 120     {
 121         "cd  \t   \t  \t\t    \t    "
 122     },
 123 };
 124 /* *INDENT-ON* */
 125 
 126 /* @Test(dataSource = "test_empty_mean_home_ds") */
 127 /* *INDENT-OFF* */
 128 START_PARAMETRIZED_TEST (test_empty_mean_home, test_empty_mean_home_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 129 /* *INDENT-ON* */
 130 {
 131     /* given */
 132     get_current_type__return_value = view_listing;
 133     do_cd__return_value = TRUE;
 134     mc_config_get_home_dir__return_value = "/home/test";
 135 
 136     /* when */
 137     {
 138         char *input_command;
 139 
 140         input_command = g_strdup (data->command);
 141         do_cd_command (input_command);
 142         g_free (input_command);
 143     }
 144     /* then */
 145     mctest_assert_str_eq (mc_config_get_home_dir__return_value,
 146                           vfs_path_as_str (do_cd__new_dir_vpath__captured));
 147     mctest_assert_int_eq (do_cd__cd_type__captured, cd_parse_command);
 148 }
 149 /* *INDENT-OFF* */
 150 END_PARAMETRIZED_TEST
 151 /* *INDENT-ON* */
 152 
 153 /* --------------------------------------------------------------------------------------------- */
 154 
 155 int
 156 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 157 {
 158     int number_failed;
 159 
 160     Suite *s = suite_create (TEST_SUITE_NAME);
 161     TCase *tc_core = tcase_create ("Core");
 162     SRunner *sr;
 163 
 164     tcase_add_checked_fixture (tc_core, setup, teardown);
 165 
 166     /* Add new tests here: *************** */
 167     mctest_add_parameterized_test (tc_core, test_empty_mean_home, test_empty_mean_home_ds);
 168     /* *********************************** */
 169 
 170     suite_add_tcase (s, tc_core);
 171     sr = srunner_create (s);
 172     srunner_set_log (sr, "do_cd_command.log");
 173     srunner_run_all (sr, CK_ENV);
 174     number_failed = srunner_ntests_failed (sr);
 175     srunner_free (sr);
 176     return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 177 }
 178 
 179 /* --------------------------------------------------------------------------------------------- */

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