root/tests/src/execute__execute_with_vfs_arg.c

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

DEFINITIONS

This source file includes following definitions.
  1. START_PARAMETRIZED_TEST
  2. START_TEST
  3. START_TEST
  4. START_TEST
  5. main

   1 /*
   2    src - tests for execute_with_vfs_arg() function
   3 
   4    Copyright (C) 2013-2022
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Slava Zanko <slavazanko@gmail.com>, 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"
  27 
  28 #include "tests/mctest.h"
  29 
  30 #include "execute__common.c"
  31 
  32 /* --------------------------------------------------------------------------------------------- */
  33 
  34 /* @DataSource("the_file_is_local_ds") */
  35 /* *INDENT-OFF* */
  36 static const struct the_file_is_local_ds
  37 {
  38     const char *input_path;
  39 } the_file_is_local_ds[] =
  40 {
  41     {
  42         NULL,
  43     },
  44     {
  45         "/blabla",
  46     },
  47 };
  48 /* *INDENT-ON* */
  49 
  50 /* @Test(dataSource = "the_file_is_local_ds") */
  51 /* *INDENT-OFF* */
  52 START_PARAMETRIZED_TEST (the_file_is_local, the_file_is_local_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
  53 /* *INDENT-ON* */
  54 {
  55     /* given */
  56     vfs_path_t *filename_vpath;
  57     filename_vpath = vfs_path_from_str (data->input_path);
  58 
  59     vfs_file_is_local__return_value = TRUE;
  60 
  61     /* when */
  62     execute_with_vfs_arg ("cmd_for_local_file", filename_vpath);
  63 
  64     /* then */
  65     mctest_assert_str_eq (do_execute__lc_shell__captured, "cmd_for_local_file");
  66     mctest_assert_str_eq (do_execute__command__captured, data->input_path);
  67 
  68     ck_assert_int_eq (vfs_file_is_local__vpath__captured->len, 1);
  69     {
  70         const vfs_path_t *tmp_vpath;
  71 
  72         tmp_vpath = (data->input_path == NULL) ? vfs_get_raw_current_dir () : filename_vpath;
  73         mctest_assert_true (vfs_path_equal
  74                             (g_ptr_array_index (vfs_file_is_local__vpath__captured, 0), tmp_vpath));
  75     }
  76     ck_assert_int_eq (do_execute__flags__captured, EXECUTE_INTERNAL);
  77     ck_assert_msg (mc_getlocalcopy__pathname_vpath__captured == NULL,
  78                    "\nFunction mc_getlocalcopy() shouldn't be called!");
  79 
  80     vfs_path_free (filename_vpath, TRUE);
  81 }
  82 /* *INDENT-OFF* */
  83 END_PARAMETRIZED_TEST
  84 /* *INDENT-ON* */
  85 
  86 /* --------------------------------------------------------------------------------------------- */
  87 
  88 /* @Test */
  89 /* *INDENT-OFF* */
  90 START_TEST (the_file_is_remote_but_empty)
     /* [previous][next][first][last][top][bottom][index][help]  */
  91 /* *INDENT-ON* */
  92 {
  93     /* given */
  94     vfs_path_t *filename_vpath;
  95     filename_vpath = NULL;
  96 
  97     vfs_file_is_local__return_value = FALSE;
  98 
  99     /* when */
 100     execute_with_vfs_arg ("cmd_for_remote_file", filename_vpath);
 101 
 102     /* then */
 103     mctest_assert_str_eq (do_execute__lc_shell__captured, NULL);
 104     mctest_assert_str_eq (do_execute__command__captured, NULL);
 105 
 106     ck_assert_int_eq (vfs_file_is_local__vpath__captured->len, 2);
 107 
 108     mctest_assert_true (vfs_path_equal
 109                         (g_ptr_array_index (vfs_file_is_local__vpath__captured, 0),
 110                          vfs_get_raw_current_dir ()));
 111     ck_assert_msg (g_ptr_array_index (vfs_file_is_local__vpath__captured, 1) == NULL,
 112                    "\nParameter for second call to vfs_file_is_local() should be NULL!");
 113     ck_assert_msg (mc_getlocalcopy__pathname_vpath__captured == NULL,
 114                    "\nFunction mc_getlocalcopy() shouldn't be called!");
 115 
 116     vfs_path_free (filename_vpath, TRUE);
 117 }
 118 /* *INDENT-OFF* */
 119 END_TEST
 120 /* *INDENT-ON* */
 121 
 122 /* --------------------------------------------------------------------------------------------- */
 123 
 124 /* @Test */
 125 /* *INDENT-OFF* */
 126 START_TEST (the_file_is_remote_fail_to_create_local_copy)
     /* [previous][next][first][last][top][bottom][index][help]  */
 127 /* *INDENT-ON* */
 128 {
 129     /* given */
 130     vfs_path_t *filename_vpath;
 131 
 132     filename_vpath = vfs_path_from_str ("/ftp://some.host/editme.txt");
 133 
 134     vfs_file_is_local__return_value = FALSE;
 135     mc_getlocalcopy__return_value = NULL;
 136 
 137     /* when */
 138     execute_with_vfs_arg ("cmd_for_remote_file", filename_vpath);
 139 
 140     /* then */
 141     mctest_assert_str_eq (do_execute__lc_shell__captured, NULL);
 142     mctest_assert_str_eq (do_execute__command__captured, NULL);
 143 
 144     ck_assert_int_eq (vfs_file_is_local__vpath__captured->len, 1);
 145 
 146     mctest_assert_true (vfs_path_equal
 147                         (g_ptr_array_index (vfs_file_is_local__vpath__captured, 0),
 148                          filename_vpath));
 149 
 150     mctest_assert_true (vfs_path_equal (mc_getlocalcopy__pathname_vpath__captured, filename_vpath));
 151 
 152     mctest_assert_str_eq (message_title__captured, _("Error"));
 153     mctest_assert_str_eq (message_text__captured,
 154                           _("Cannot fetch a local copy of /ftp://some.host/editme.txt"));
 155 
 156 
 157     vfs_path_free (filename_vpath, TRUE);
 158 }
 159 /* *INDENT-OFF* */
 160 END_TEST
 161 /* *INDENT-ON* */
 162 
 163 /* --------------------------------------------------------------------------------------------- */
 164 
 165 /* @Test */
 166 /* *INDENT-OFF* */
 167 START_TEST (the_file_is_remote)
     /* [previous][next][first][last][top][bottom][index][help]  */
 168 /* *INDENT-ON* */
 169 {
 170     /* given */
 171     vfs_path_t *filename_vpath, *local_vpath, *local_vpath_should_be_freeing;
 172 
 173     filename_vpath = vfs_path_from_str ("/ftp://some.host/editme.txt");
 174     local_vpath = vfs_path_from_str ("/tmp/blabla-editme.txt");
 175     local_vpath_should_be_freeing = vfs_path_clone (local_vpath);
 176 
 177     vfs_file_is_local__return_value = FALSE;
 178     mc_getlocalcopy__return_value = local_vpath_should_be_freeing;
 179 
 180     /* when */
 181     execute_with_vfs_arg ("cmd_for_remote_file", filename_vpath);
 182 
 183     /* then */
 184     mctest_assert_str_eq (do_execute__lc_shell__captured, "cmd_for_remote_file");
 185     mctest_assert_str_eq (do_execute__command__captured, "/tmp/blabla-editme.txt");
 186 
 187     ck_assert_int_eq (vfs_file_is_local__vpath__captured->len, 1);
 188 
 189     mctest_assert_true (vfs_path_equal
 190                         (g_ptr_array_index (vfs_file_is_local__vpath__captured, 0),
 191                          filename_vpath));
 192 
 193     mctest_assert_true (vfs_path_equal (mc_getlocalcopy__pathname_vpath__captured, filename_vpath));
 194 
 195     ck_assert_int_eq (mc_stat__vpath__captured->len, 2);
 196 
 197     mctest_assert_true (vfs_path_equal
 198                         (g_ptr_array_index (mc_stat__vpath__captured, 0), local_vpath));
 199     mctest_assert_true (vfs_path_equal
 200                         (g_ptr_array_index (mc_stat__vpath__captured, 0),
 201                          g_ptr_array_index (mc_stat__vpath__captured, 1)));
 202 
 203     mctest_assert_true (vfs_path_equal
 204                         (mc_ungetlocalcopy__pathname_vpath__captured, filename_vpath));
 205 
 206     mctest_assert_true (vfs_path_equal (mc_ungetlocalcopy__local_vpath__captured, local_vpath));
 207 
 208     vfs_path_free (filename_vpath, TRUE);
 209     vfs_path_free (local_vpath, TRUE);
 210 }
 211 /* *INDENT-OFF* */
 212 END_TEST
 213 /* *INDENT-ON* */
 214 
 215 /* --------------------------------------------------------------------------------------------- */
 216 
 217 int
 218 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 219 {
 220     TCase *tc_core;
 221 
 222     tc_core = tcase_create ("Core");
 223 
 224     tcase_add_checked_fixture (tc_core, setup, teardown);
 225 
 226     /* Add new tests here: *************** */
 227     mctest_add_parameterized_test (tc_core, the_file_is_local, the_file_is_local_ds);
 228     tcase_add_test (tc_core, the_file_is_remote_but_empty);
 229     tcase_add_test (tc_core, the_file_is_remote_fail_to_create_local_copy);
 230     tcase_add_test (tc_core, the_file_is_remote);
 231     /* *********************************** */
 232 
 233     return mctest_run_all (tc_core);
 234 }
 235 
 236 /* --------------------------------------------------------------------------------------------- */

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