2 Common code for testing functions in src/execute.c file.
4 Copyright (C) 2013-2024
6 Free Software Foundation, Inc.
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/vfs.h"
30 #include "src/vfs/local/local.c"
32 #include "src/execute.h"
34 /* --------------------------------------------------------------------------------------------- */
37 static GPtrArray
*vfs_file_is_local__vpath__captured
;
39 /* @ThenReturnValue */
40 static gboolean vfs_file_is_local__return_value
;
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
;
51 vpath_captured_free (gpointer data
)
53 vfs_path_free ((vfs_path_t
*) data
, TRUE
);
57 vfs_file_is_local__init (void)
59 vfs_file_is_local__vpath__captured
= g_ptr_array_new_with_free_func (vpath_captured_free
);
63 vfs_file_is_local__deinit (void)
65 g_ptr_array_free (vfs_file_is_local__vpath__captured
, TRUE
);
68 /* --------------------------------------------------------------------------------------------- */
70 void do_execute (const char *lc_shell
, const char *command
, int flags
);
73 static char *do_execute__lc_shell__captured
;
75 static char *do_execute__command__captured
;
77 static int do_execute__flags__captured
;
81 do_execute (const char *lc_shell
, const char *command
, int flags
)
83 do_execute__lc_shell__captured
= g_strdup (lc_shell
);
84 do_execute__command__captured
= g_strdup (command
);
85 do_execute__flags__captured
= flags
;
89 do_execute__init (void)
91 do_execute__command__captured
= NULL
;
92 do_execute__lc_shell__captured
= NULL
;
96 do_execute__deinit (void)
98 g_free (do_execute__lc_shell__captured
);
99 g_free (do_execute__command__captured
);
102 /* --------------------------------------------------------------------------------------------- */
105 static vfs_path_t
*mc_getlocalcopy__pathname_vpath__captured
;
106 /* @ThenReturnValue */
107 static vfs_path_t
*mc_getlocalcopy__return_value
;
111 mc_getlocalcopy (const vfs_path_t
*pathname_vpath
)
113 mc_getlocalcopy__pathname_vpath__captured
= vfs_path_clone (pathname_vpath
);
114 return mc_getlocalcopy__return_value
;
118 mc_getlocalcopy__init (void)
120 mc_getlocalcopy__pathname_vpath__captured
= NULL
;
121 mc_getlocalcopy__return_value
= NULL
;
125 mc_getlocalcopy__deinit (void)
127 vfs_path_free (mc_getlocalcopy__pathname_vpath__captured
, TRUE
);
130 /* --------------------------------------------------------------------------------------------- */
134 static int message_flags__captured
;
137 static char *message_title__captured
;
140 static char *message_text__captured
;
144 message (int flags
, const char *title
, const char *text
, ...)
148 message_flags__captured
= flags
;
150 message_title__captured
= (title
== MSG_ERROR
) ? g_strdup (_("Error")) : g_strdup (title
);
153 message_text__captured
= g_strdup_vprintf (text
, ap
);
161 message_flags__captured
= 0;
162 message_title__captured
= NULL
;
163 message_text__captured
= NULL
;
167 message__deinit (void)
169 g_free (message_title__captured
);
170 g_free (message_text__captured
);
173 /* --------------------------------------------------------------------------------------------- */
176 static GPtrArray
*mc_stat__vpath__captured
= NULL
;
177 /* @ThenReturnValue */
178 static int mc_stat__return_value
= 0;
182 mc_stat (const vfs_path_t
*vpath
, struct stat
*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
;
194 mc_stat__vpath__captured
= g_ptr_array_new_with_free_func (vpath_captured_free
);
198 mc_stat__deinit (void)
200 g_ptr_array_free (mc_stat__vpath__captured
, TRUE
);
201 mc_stat__vpath__captured
= NULL
;
204 /* --------------------------------------------------------------------------------------------- */
207 static vfs_path_t
*mc_ungetlocalcopy__pathname_vpath__captured
;
209 static vfs_path_t
*mc_ungetlocalcopy__local_vpath__captured
;
210 /* @ThenReturnValue */
211 static int mc_ungetlocalcopy__return_value
= 0;
215 mc_ungetlocalcopy (const vfs_path_t
*pathname_vpath
, const vfs_path_t
*local_vpath
,
216 gboolean has_changed_ignored
)
218 (void) has_changed_ignored
;
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
;
226 mc_ungetlocalcopy__init (void)
228 mc_ungetlocalcopy__pathname_vpath__captured
= NULL
;
229 mc_ungetlocalcopy__local_vpath__captured
= NULL
;
233 mc_ungetlocalcopy__deinit (void)
235 vfs_path_free (mc_ungetlocalcopy__pathname_vpath__captured
, TRUE
);
236 vfs_path_free (mc_ungetlocalcopy__local_vpath__captured
, TRUE
);
239 /* --------------------------------------------------------------------------------------------- */
245 str_init_strings (NULL
);
248 vfs_setup_work_dir ();
250 vfs_file_is_local__init ();
252 mc_getlocalcopy__init ();
255 mc_ungetlocalcopy__init ();
258 /* --------------------------------------------------------------------------------------------- */
264 mc_ungetlocalcopy__deinit ();
267 mc_getlocalcopy__deinit ();
268 do_execute__deinit ();
269 vfs_file_is_local__deinit ();
272 str_uninit_strings ();
275 /* --------------------------------------------------------------------------------------------- */