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

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