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-2019
   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     mctest_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_int_eq (vfs_path_equal
  74                               (g_ptr_array_index (vfs_file_is_local__vpath__captured, 0),
  75                                tmp_vpath), TRUE);
  76     }
  77     mctest_assert_int_eq (do_execute__flags__captured, EXECUTE_INTERNAL);
  78     fail_unless (mc_getlocalcopy__pathname_vpath__captured == NULL,
  79                  "\nFunction mc_getlocalcopy() shouldn't be called!");
  80 
  81     vfs_path_free (filename_vpath);
  82 }
  83 /* *INDENT-OFF* */
  84 END_PARAMETRIZED_TEST
  85 /* *INDENT-ON* */
  86 
  87 /* --------------------------------------------------------------------------------------------- */
  88 
  89 /* @Test */
  90 /* *INDENT-OFF* */
  91 START_TEST (the_file_is_remote_but_empty)
     /* [previous][next][first][last][top][bottom][index][help]  */
  92 /* *INDENT-ON* */
  93 {
  94     /* given */
  95     vfs_path_t *filename_vpath;
  96     filename_vpath = NULL;
  97 
  98     vfs_file_is_local__return_value = FALSE;
  99 
 100     /* when */
 101     execute_with_vfs_arg ("cmd_for_remote_file", filename_vpath);
 102 
 103     /* then */
 104     mctest_assert_str_eq (do_execute__lc_shell__captured, NULL);
 105     mctest_assert_str_eq (do_execute__command__captured, NULL);
 106 
 107     mctest_assert_int_eq (vfs_file_is_local__vpath__captured->len, 2);
 108 
 109     mctest_assert_int_eq (vfs_path_equal
 110                           (g_ptr_array_index (vfs_file_is_local__vpath__captured, 0),
 111                            vfs_get_raw_current_dir ()), TRUE);
 112     fail_unless (g_ptr_array_index (vfs_file_is_local__vpath__captured, 1) == NULL,
 113                  "\nParameter for second call to vfs_file_is_local() should be NULL!");
 114     fail_unless (mc_getlocalcopy__pathname_vpath__captured == NULL,
 115                  "\nFunction mc_getlocalcopy() shouldn't be called!");
 116 
 117     vfs_path_free (filename_vpath);
 118 }
 119 /* *INDENT-OFF* */
 120 END_TEST
 121 /* *INDENT-ON* */
 122 
 123 /* --------------------------------------------------------------------------------------------- */
 124 
 125 /* @Test */
 126 /* *INDENT-OFF* */
 127 START_TEST (the_file_is_remote_fail_to_create_local_copy)
     /* [previous][next][first][last][top][bottom][index][help]  */
 128 /* *INDENT-ON* */
 129 {
 130     /* given */
 131     vfs_path_t *filename_vpath;
 132 
 133     filename_vpath = vfs_path_from_str ("/ftp://some.host/editme.txt");
 134 
 135     vfs_file_is_local__return_value = FALSE;
 136     mc_getlocalcopy__return_value = NULL;
 137 
 138     /* when */
 139     execute_with_vfs_arg ("cmd_for_remote_file", filename_vpath);
 140 
 141     /* then */
 142     mctest_assert_str_eq (do_execute__lc_shell__captured, NULL);
 143     mctest_assert_str_eq (do_execute__command__captured, NULL);
 144 
 145     mctest_assert_int_eq (vfs_file_is_local__vpath__captured->len, 1);
 146 
 147     mctest_assert_int_eq (vfs_path_equal
 148                           (g_ptr_array_index (vfs_file_is_local__vpath__captured, 0),
 149                            filename_vpath), TRUE);
 150 
 151     mctest_assert_int_eq (vfs_path_equal
 152                           (mc_getlocalcopy__pathname_vpath__captured, filename_vpath), TRUE);
 153 
 154     mctest_assert_str_eq (message_title__captured, _("Error"));
 155     mctest_assert_str_eq (message_text__captured,
 156                           _("Cannot fetch a local copy of /ftp://some.host/editme.txt"));
 157 
 158 
 159     vfs_path_free (filename_vpath);
 160 }
 161 /* *INDENT-OFF* */
 162 END_TEST
 163 /* *INDENT-ON* */
 164 
 165 /* --------------------------------------------------------------------------------------------- */
 166 
 167 /* @Test */
 168 /* *INDENT-OFF* */
 169 START_TEST (the_file_is_remote)
     /* [previous][next][first][last][top][bottom][index][help]  */
 170 /* *INDENT-ON* */
 171 {
 172     /* given */
 173     vfs_path_t *filename_vpath, *local_vpath, *local_vpath_should_be_freeing;
 174 
 175     filename_vpath = vfs_path_from_str ("/ftp://some.host/editme.txt");
 176     local_vpath = vfs_path_from_str ("/tmp/blabla-editme.txt");
 177     local_vpath_should_be_freeing = vfs_path_clone (local_vpath);
 178 
 179     vfs_file_is_local__return_value = FALSE;
 180     mc_getlocalcopy__return_value = local_vpath_should_be_freeing;
 181 
 182     /* when */
 183     execute_with_vfs_arg ("cmd_for_remote_file", filename_vpath);
 184 
 185     /* then */
 186     mctest_assert_str_eq (do_execute__lc_shell__captured, "cmd_for_remote_file");
 187     mctest_assert_str_eq (do_execute__command__captured, "/tmp/blabla-editme.txt");
 188 
 189     mctest_assert_int_eq (vfs_file_is_local__vpath__captured->len, 1);
 190 
 191     mctest_assert_int_eq (vfs_path_equal
 192                           (g_ptr_array_index (vfs_file_is_local__vpath__captured, 0),
 193                            filename_vpath), TRUE);
 194 
 195     mctest_assert_int_eq (vfs_path_equal
 196                           (mc_getlocalcopy__pathname_vpath__captured, filename_vpath), TRUE);
 197 
 198     mctest_assert_int_eq (mc_stat__vpath__captured->len, 2);
 199 
 200     mctest_assert_int_eq (vfs_path_equal
 201                           (g_ptr_array_index (mc_stat__vpath__captured, 0), local_vpath), TRUE);
 202     mctest_assert_int_eq (vfs_path_equal
 203                           (g_ptr_array_index (mc_stat__vpath__captured, 0),
 204                            g_ptr_array_index (mc_stat__vpath__captured, 1)), TRUE);
 205 
 206     mctest_assert_int_eq (vfs_path_equal
 207                           (mc_ungetlocalcopy__pathname_vpath__captured, filename_vpath), TRUE);
 208 
 209     mctest_assert_int_eq (vfs_path_equal (mc_ungetlocalcopy__local_vpath__captured, local_vpath),
 210                           TRUE);
 211 
 212     vfs_path_free (filename_vpath);
 213     vfs_path_free (local_vpath);
 214 }
 215 /* *INDENT-OFF* */
 216 END_TEST
 217 /* *INDENT-ON* */
 218 
 219 /* --------------------------------------------------------------------------------------------- */
 220 
 221 int
 222 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 223 {
 224     int number_failed;
 225 
 226     Suite *s = suite_create (TEST_SUITE_NAME);
 227     TCase *tc_core = tcase_create ("Core");
 228     SRunner *sr;
 229 
 230     tcase_add_checked_fixture (tc_core, setup, teardown);
 231 
 232     /* Add new tests here: *************** */
 233     mctest_add_parameterized_test (tc_core, the_file_is_local, the_file_is_local_ds);
 234     tcase_add_test (tc_core, the_file_is_remote_but_empty);
 235     tcase_add_test (tc_core, the_file_is_remote_fail_to_create_local_copy);
 236     tcase_add_test (tc_core, the_file_is_remote);
 237     /* *********************************** */
 238 
 239     suite_add_tcase (s, tc_core);
 240     sr = srunner_create (s);
 241     srunner_set_log (sr, "execute__execute_with_vfs_arg.log");
 242     srunner_run_all (sr, CK_ENV);
 243     number_failed = srunner_ntests_failed (sr);
 244     srunner_free (sr);
 245     return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 246 }
 247 
 248 /* --------------------------------------------------------------------------------------------- */

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