root/tests/src/execute__common.c

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

DEFINITIONS

This source file includes following definitions.
  1. vfs_file_is_local
  2. vfs_file_is_local__init
  3. vpath_captured_free
  4. vfs_file_is_local__deinit
  5. do_execute
  6. do_execute__init
  7. do_execute__deinit
  8. mc_getlocalcopy
  9. mc_getlocalcopy__init
  10. mc_getlocalcopy__deinit
  11. message
  12. message__init
  13. message__deinit
  14. mc_stat
  15. mc_stat__init
  16. mc_stat__deinit
  17. mc_ungetlocalcopy
  18. mc_ungetlocalcopy__init
  19. mc_ungetlocalcopy__deinit
  20. setup
  21. teardown

   1 /*
   2    Common code for testing functions in src/execute.c file.
   3 
   4    Copyright (C) 2013-2021
   5 
   6    Free Software Foundation, Inc.
   7 
   8    Written by:
   9    Slava Zanko <slavazanko@gmail.com>, 2013
  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 #include "lib/widget.h"
  28 #include "lib/strutil.h"
  29 #include "lib/vfs/vfs.h"
  30 #include "src/vfs/local/local.c"
  31 
  32 #include "src/execute.h"
  33 
  34 /* --------------------------------------------------------------------------------------------- */
  35 
  36 /* @CapturedValue */
  37 static GPtrArray *vfs_file_is_local__vpath__captured;
  38 
  39 /* @ThenReturnValue */
  40 static gboolean vfs_file_is_local__return_value;
  41 
  42 /* @Mock */
  43 gboolean
  44 vfs_file_is_local (const vfs_path_t * vpath)
     /* [previous][next][first][last][top][bottom][index][help]  */
  45 {
  46     g_ptr_array_add (vfs_file_is_local__vpath__captured, vfs_path_clone (vpath));
  47     return vfs_file_is_local__return_value;
  48 }
  49 
  50 static void
  51 vfs_file_is_local__init (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  52 {
  53     vfs_file_is_local__vpath__captured = g_ptr_array_new ();
  54 }
  55 
  56 static void
  57 vpath_captured_free (gpointer data, gpointer user_data)
     /* [previous][next][first][last][top][bottom][index][help]  */
  58 {
  59     (void) user_data;
  60     vfs_path_free ((vfs_path_t *) data, TRUE);
  61 }
  62 
  63 static void
  64 vfs_file_is_local__deinit (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  65 {
  66     g_ptr_array_foreach (vfs_file_is_local__vpath__captured, vpath_captured_free, NULL);
  67     g_ptr_array_free (vfs_file_is_local__vpath__captured, TRUE);
  68 }
  69 
  70 /* --------------------------------------------------------------------------------------------- */
  71 
  72 void do_execute (const char *lc_shell, const char *command, int flags);
  73 
  74 /* @CapturedValue */
  75 static char *do_execute__lc_shell__captured;
  76 /* @CapturedValue */
  77 static char *do_execute__command__captured;
  78 /* @CapturedValue */
  79 static int do_execute__flags__captured;
  80 
  81 /* @Mock */
  82 void
  83 do_execute (const char *lc_shell, const char *command, int flags)
     /* [previous][next][first][last][top][bottom][index][help]  */
  84 {
  85     do_execute__lc_shell__captured = g_strdup (lc_shell);
  86     do_execute__command__captured = g_strdup (command);
  87     do_execute__flags__captured = flags;
  88 }
  89 
  90 static void
  91 do_execute__init (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  92 {
  93     do_execute__command__captured = NULL;
  94     do_execute__lc_shell__captured = NULL;
  95 }
  96 
  97 static void
  98 do_execute__deinit (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  99 {
 100     g_free (do_execute__lc_shell__captured);
 101     g_free (do_execute__command__captured);
 102 }
 103 
 104 /* --------------------------------------------------------------------------------------------- */
 105 
 106 /* @CapturedValue */
 107 static vfs_path_t *mc_getlocalcopy__pathname_vpath__captured;
 108 /* @ThenReturnValue */
 109 static vfs_path_t *mc_getlocalcopy__return_value;
 110 
 111 /* @Mock */
 112 vfs_path_t *
 113 mc_getlocalcopy (const vfs_path_t * pathname_vpath)
     /* [previous][next][first][last][top][bottom][index][help]  */
 114 {
 115     mc_getlocalcopy__pathname_vpath__captured = vfs_path_clone (pathname_vpath);
 116     return mc_getlocalcopy__return_value;
 117 }
 118 
 119 static void
 120 mc_getlocalcopy__init (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 121 {
 122     mc_getlocalcopy__pathname_vpath__captured = NULL;
 123     mc_getlocalcopy__return_value = NULL;
 124 }
 125 
 126 static void
 127 mc_getlocalcopy__deinit (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 128 {
 129     vfs_path_free (mc_getlocalcopy__pathname_vpath__captured, TRUE);
 130 }
 131 
 132 /* --------------------------------------------------------------------------------------------- */
 133 
 134 
 135 /* @CapturedValue */
 136 static int message_flags__captured;
 137 
 138 /* @CapturedValue */
 139 static char *message_title__captured;
 140 
 141 /* @CapturedValue */
 142 static char *message_text__captured;
 143 
 144 /* @Mock */
 145 void
 146 message (int flags, const char *title, const char *text, ...)
     /* [previous][next][first][last][top][bottom][index][help]  */
 147 {
 148     va_list ap;
 149 
 150     message_flags__captured = flags;
 151 
 152     message_title__captured = (title == MSG_ERROR) ? g_strdup (_("Error")) : g_strdup (title);
 153 
 154     va_start (ap, text);
 155     message_text__captured = g_strdup_vprintf (text, ap);
 156     va_end (ap);
 157 
 158 }
 159 
 160 static void
 161 message__init (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 162 {
 163     message_flags__captured = 0;
 164     message_title__captured = NULL;
 165     message_text__captured = NULL;
 166 }
 167 
 168 static void
 169 message__deinit (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 170 {
 171     g_free (message_title__captured);
 172     g_free (message_text__captured);
 173 }
 174 
 175 /* --------------------------------------------------------------------------------------------- */
 176 
 177 /* @CapturedValue */
 178 static GPtrArray *mc_stat__vpath__captured = NULL;
 179 /* @ThenReturnValue */
 180 static int mc_stat__return_value = 0;
 181 
 182 /* @Mock */
 183 int
 184 mc_stat (const vfs_path_t * vpath, struct stat *stat_ignored)
     /* [previous][next][first][last][top][bottom][index][help]  */
 185 {
 186     (void) stat_ignored;
 187     if (mc_stat__vpath__captured != NULL)
 188         g_ptr_array_add (mc_stat__vpath__captured, vfs_path_clone (vpath));
 189     return mc_stat__return_value;
 190 }
 191 
 192 
 193 static void
 194 mc_stat__init (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 195 {
 196     mc_stat__vpath__captured = g_ptr_array_new ();
 197 }
 198 
 199 static void
 200 mc_stat__deinit (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 201 {
 202     g_ptr_array_foreach (mc_stat__vpath__captured, vpath_captured_free, NULL);
 203     g_ptr_array_free (mc_stat__vpath__captured, TRUE);
 204     mc_stat__vpath__captured = NULL;
 205 }
 206 
 207 /* --------------------------------------------------------------------------------------------- */
 208 
 209 /* @CapturedValue */
 210 static vfs_path_t *mc_ungetlocalcopy__pathname_vpath__captured;
 211 /* @CapturedValue */
 212 static vfs_path_t *mc_ungetlocalcopy__local_vpath__captured;
 213 /* @ThenReturnValue */
 214 static int mc_ungetlocalcopy__return_value = 0;
 215 
 216 /* @Mock */
 217 int
 218 mc_ungetlocalcopy (const vfs_path_t * pathname_vpath, const vfs_path_t * local_vpath,
     /* [previous][next][first][last][top][bottom][index][help]  */
 219                    gboolean has_changed_ignored)
 220 {
 221     (void) has_changed_ignored;
 222 
 223     mc_ungetlocalcopy__pathname_vpath__captured = vfs_path_clone (pathname_vpath);
 224     mc_ungetlocalcopy__local_vpath__captured = vfs_path_clone (local_vpath);
 225     return mc_ungetlocalcopy__return_value;
 226 }
 227 
 228 static void
 229 mc_ungetlocalcopy__init (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 230 {
 231     mc_ungetlocalcopy__pathname_vpath__captured = NULL;
 232     mc_ungetlocalcopy__local_vpath__captured = NULL;
 233 }
 234 
 235 static void
 236 mc_ungetlocalcopy__deinit (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 237 {
 238     vfs_path_free (mc_ungetlocalcopy__pathname_vpath__captured, TRUE);
 239     vfs_path_free (mc_ungetlocalcopy__local_vpath__captured, TRUE);
 240 }
 241 
 242 /* --------------------------------------------------------------------------------------------- */
 243 
 244 /* @Before */
 245 static void
 246 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 247 {
 248     str_init_strings (NULL);
 249     vfs_init ();
 250     vfs_init_localfs ();
 251     vfs_setup_work_dir ();
 252 
 253     vfs_file_is_local__init ();
 254     do_execute__init ();
 255     mc_getlocalcopy__init ();
 256     message__init ();
 257     mc_stat__init ();
 258     mc_ungetlocalcopy__init ();
 259 }
 260 
 261 /* --------------------------------------------------------------------------------------------- */
 262 
 263 /* @After */
 264 static void
 265 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 266 {
 267     mc_ungetlocalcopy__deinit ();
 268     mc_stat__deinit ();
 269     message__deinit ();
 270     mc_getlocalcopy__deinit ();
 271     do_execute__deinit ();
 272     vfs_file_is_local__deinit ();
 273 
 274     vfs_shut ();
 275     str_uninit_strings ();
 276 }
 277 
 278 /* --------------------------------------------------------------------------------------------- */

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