Add tests for src/execute.c:execute_with_vfs_arg() function.
[midnight-commander.git] / tests / src / execute__common.c
blob97d12f09bc4fc9ae42649e7d58f3fda6a7b12afb
1 /*
2 Common code for testing functions in src/execute.c file.
4 Copyright (C) 2013
6 The Free Software Foundation, Inc.
8 Written by:
9 Slava Zanko <slavazanko@gmail.com>, 2013
11 This file is part of the Midnight Commander.
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.
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.
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/>.
27 #include "lib/widget.h"
28 #include "lib/strutil.h"
29 #include "lib/vfs/path.h"
30 #include "src/vfs/local/local.c"
32 #include "src/execute.h"
34 /* --------------------------------------------------------------------------------------------- */
36 /* @CapturedValue */
37 static GPtrArray *vfs_file_is_local__vpath__captured;
39 /* @ThenReturnValue */
40 static gboolean vfs_file_is_local__return_value;
42 /* @Mock */
43 gboolean
44 vfs_file_is_local (const vfs_path_t * vpath)
46 g_ptr_array_add (vfs_file_is_local__vpath__captured, vfs_path_clone (vpath));
47 return vfs_file_is_local__return_value;
50 static void
51 vfs_file_is_local__init ()
53 vfs_file_is_local__vpath__captured = g_ptr_array_new ();
56 static void
57 vfs_file_is_local__deinit ()
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);
63 /* --------------------------------------------------------------------------------------------- */
65 void do_execute (const char *lc_shell, const char *command, int flags);
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;
74 /* @Mock */
75 void
76 do_execute (const char *lc_shell, const char *command, int flags)
78 do_execute__lc_shell__captured = g_strdup (lc_shell);
79 do_execute__command__captured = g_strdup (command);
80 do_execute__flags__captured = flags;
83 static void
84 do_execute__init ()
86 do_execute__command__captured = NULL;
87 do_execute__lc_shell__captured = NULL;
90 static void
91 do_execute__deinit ()
93 g_free (do_execute__lc_shell__captured);
94 g_free (do_execute__command__captured);
97 /* --------------------------------------------------------------------------------------------- */
99 /* @CapturedValue */
100 static vfs_path_t *mc_getlocalcopy__pathname_vpath__captured;
101 /* @ThenReturnValue */
102 static vfs_path_t *mc_getlocalcopy__return_value;
104 /* @Mock */
105 vfs_path_t *
106 mc_getlocalcopy (const vfs_path_t * pathname_vpath)
108 mc_getlocalcopy__pathname_vpath__captured = vfs_path_clone (pathname_vpath);
109 return mc_getlocalcopy__return_value;
112 static void
113 mc_getlocalcopy__init ()
115 mc_getlocalcopy__pathname_vpath__captured = NULL;
116 mc_getlocalcopy__return_value = NULL;
119 static void
120 mc_getlocalcopy__deinit ()
122 vfs_path_free (mc_getlocalcopy__pathname_vpath__captured);
125 /* --------------------------------------------------------------------------------------------- */
128 /* @CapturedValue */
129 static int message_flags__captured;
131 /* @CapturedValue */
132 static char *message_title__captured;
134 /* @CapturedValue */
135 static char *message_text__captured;
137 /* @Mock */
138 void
139 message (int flags, const char *title, const char *text, ...)
141 va_list ap;
143 message_flags__captured = flags;
145 message_title__captured = (title == MSG_ERROR) ? g_strdup (_("Error")) : g_strdup (title);
147 va_start (ap, text);
148 message_text__captured = g_strdup_vprintf (text, ap);
149 va_end (ap);
153 static void
154 message__init ()
156 message_flags__captured = 0;
157 message_title__captured = NULL;
158 message_text__captured = NULL;
161 static void
162 message__deinit ()
164 g_free (message_title__captured);
165 g_free (message_text__captured);
168 /* --------------------------------------------------------------------------------------------- */
170 /* @CapturedValue */
171 static GPtrArray *mc_stat__vpath__captured = NULL;
172 /* @ThenReturnValue */
173 static int mc_stat__return_value = 0;
175 /* @Mock */
177 mc_stat (const vfs_path_t * vpath, struct stat *stat_ignored)
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;
186 static void
187 mc_stat__init ()
189 mc_stat__vpath__captured = g_ptr_array_new ();
192 static void
193 mc_stat__deinit ()
195 g_ptr_array_foreach (mc_stat__vpath__captured, (GFunc) vfs_path_free, NULL);
196 g_ptr_array_free (mc_stat__vpath__captured, TRUE);
199 /* --------------------------------------------------------------------------------------------- */
201 /* @CapturedValue */
202 static vfs_path_t *mc_ungetlocalcopy__pathname_vpath__captured;
203 /* @CapturedValue */
204 static vfs_path_t *mc_ungetlocalcopy__local_vpath__captured;
205 /* @ThenReturnValue */
206 static int mc_ungetlocalcopy__return_value = 0;
208 /* @Mock */
210 mc_ungetlocalcopy (const vfs_path_t * pathname_vpath, const vfs_path_t * local_vpath,
211 gboolean has_changed_ignored)
213 (void) has_changed_ignored;
215 mc_ungetlocalcopy__pathname_vpath__captured = vfs_path_clone (pathname_vpath);
216 mc_ungetlocalcopy__local_vpath__captured = vfs_path_clone (local_vpath);
217 return mc_ungetlocalcopy__return_value;
220 static void
221 mc_ungetlocalcopy__init ()
223 mc_ungetlocalcopy__pathname_vpath__captured = NULL;
224 mc_ungetlocalcopy__local_vpath__captured = NULL;
227 static void
228 mc_ungetlocalcopy__deinit ()
230 vfs_path_free (mc_ungetlocalcopy__pathname_vpath__captured);
231 vfs_path_free (mc_ungetlocalcopy__local_vpath__captured);
234 /* --------------------------------------------------------------------------------------------- */
236 /* @Before */
237 static void
238 setup (void)
240 str_init_strings (NULL);
241 vfs_init ();
242 init_localfs ();
243 vfs_setup_work_dir ();
245 vfs_file_is_local__init ();
246 do_execute__init ();
247 mc_getlocalcopy__init ();
248 message__init ();
249 mc_stat__init ();
250 mc_ungetlocalcopy__init ();
253 /* --------------------------------------------------------------------------------------------- */
255 /* @After */
256 static void
257 teardown (void)
259 mc_ungetlocalcopy__deinit ();
260 mc_stat__deinit ();
261 message__deinit ();
262 mc_getlocalcopy__deinit ();
263 do_execute__deinit ();
264 vfs_file_is_local__deinit ();
266 vfs_shut ();
267 str_uninit_strings ();
270 /* --------------------------------------------------------------------------------------------- */