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. vfs_file_is_local__deinit
  4. do_execute
  5. do_execute__init
  6. do_execute__deinit
  7. mc_getlocalcopy
  8. mc_getlocalcopy__init
  9. mc_getlocalcopy__deinit
  10. message
  11. message__init
  12. message__deinit
  13. mc_stat
  14. mc_stat__init
  15. mc_stat__deinit
  16. mc_ungetlocalcopy
  17. mc_ungetlocalcopy__init
  18. mc_ungetlocalcopy__deinit
  19. setup
  20. teardown

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

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