- tests/src/execute__execute_external_editor_or_viewer.c
This source file includes following definitions.
- execute_get_external_cmd_opts_from_config
- execute_get_external_cmd_opts_from_config__init
- execute_get_external_cmd_opts_from_config__deinit
- do_executev
- do_executev__init
- do_executev__deinit
- my_setup
- my_teardown
- START_TEST
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 #define TEST_SUITE_NAME "/src"
27
28 #include "tests/mctest.h"
29
30 #include "execute__common.c"
31
32
33
34 char *execute_get_external_cmd_opts_from_config (const char *command,
35 const vfs_path_t * filename_vpath,
36 long start_line);
37
38
39 static char *execute_external_cmd_opts__command__captured;
40
41 static vfs_path_t *execute_external_cmd_opts__filename_vpath__captured;
42
43 static int execute_external_cmd_opts__start_line__captured;
44
45
46 static char *execute_external_cmd_opts__return_value;
47
48
49 char *
50 execute_get_external_cmd_opts_from_config (const char *command, const vfs_path_t *filename_vpath,
51 long start_line)
52 {
53 execute_external_cmd_opts__command__captured = g_strdup (command);
54 execute_external_cmd_opts__filename_vpath__captured = vfs_path_clone (filename_vpath);
55 execute_external_cmd_opts__start_line__captured = start_line;
56
57 return execute_external_cmd_opts__return_value;
58 }
59
60 static void
61 execute_get_external_cmd_opts_from_config__init (void)
62 {
63 execute_external_cmd_opts__command__captured = NULL;
64 execute_external_cmd_opts__filename_vpath__captured = NULL;
65 execute_external_cmd_opts__start_line__captured = 0;
66 }
67
68 static void
69 execute_get_external_cmd_opts_from_config__deinit (void)
70 {
71 g_free (execute_external_cmd_opts__command__captured);
72 vfs_path_free (execute_external_cmd_opts__filename_vpath__captured, TRUE);
73 }
74
75
76 void do_executev (const char *lc_shell, int flags, char *const argv[]);
77
78
79 static char *do_executev__lc_shell__captured;
80
81 static int do_executev__flags__captured;
82
83 static GPtrArray *do_executev__argv__captured;
84
85
86 void
87 do_executev (const char *lc_shell, int flags, char *const argv[])
88 {
89 do_executev__lc_shell__captured = g_strdup (lc_shell);
90 do_executev__flags__captured = flags;
91
92 for (; argv != NULL && *argv != NULL; argv++)
93 g_ptr_array_add (do_executev__argv__captured, g_strdup (*argv));
94 }
95
96 static void
97 do_executev__init (void)
98 {
99 do_executev__lc_shell__captured = NULL;
100 do_executev__argv__captured = g_ptr_array_new_with_free_func (g_free);
101 do_executev__flags__captured = 0;
102 }
103
104 static void
105 do_executev__deinit (void)
106 {
107 g_free (do_executev__lc_shell__captured);
108 g_ptr_array_free (do_executev__argv__captured, TRUE);
109 }
110
111
112
113
114 static void
115 my_setup (void)
116 {
117 setup ();
118
119 execute_get_external_cmd_opts_from_config__init ();
120 do_executev__init ();
121 }
122
123
124
125
126 static void
127 my_teardown (void)
128 {
129 do_executev__deinit ();
130 execute_get_external_cmd_opts_from_config__deinit ();
131
132 teardown ();
133 }
134
135
136
137
138
139 START_TEST (do_open_external_editor_or_viewer)
140
141 {
142
143 vfs_path_t *filename_vpath;
144 filename_vpath = vfs_path_from_str ("/path/to/file.txt");
145
146 vfs_file_is_local__return_value = TRUE;
147 execute_external_cmd_opts__return_value =
148 g_strdup
149 (" 'param 1 with spaces' \"param 2\" -a -b -cdef /path/to/file.txt +123");
150
151
152 execute_external_editor_or_viewer ("editor_or_viewer", filename_vpath, 123);
153
154
155
156
157 mctest_assert_str_eq (execute_external_cmd_opts__command__captured, "editor_or_viewer");
158 mctest_assert_true (vfs_path_equal
159 (execute_external_cmd_opts__filename_vpath__captured, filename_vpath));
160 ck_assert_int_eq (execute_external_cmd_opts__start_line__captured, 123);
161
162
163 mctest_assert_str_eq (do_executev__lc_shell__captured, "editor_or_viewer");
164 ck_assert_int_eq (do_executev__flags__captured, EXECUTE_INTERNAL);
165 ck_assert_int_eq (do_executev__argv__captured->len, 7);
166
167 mctest_assert_str_eq (g_ptr_array_index (do_executev__argv__captured, 0),
168 "param 1 with spaces");
169 mctest_assert_str_eq (g_ptr_array_index (do_executev__argv__captured, 1), "param 2");
170 mctest_assert_str_eq (g_ptr_array_index (do_executev__argv__captured, 2), "-a");
171 mctest_assert_str_eq (g_ptr_array_index (do_executev__argv__captured, 3), "-b");
172 mctest_assert_str_eq (g_ptr_array_index (do_executev__argv__captured, 4), "-cdef");
173 mctest_assert_str_eq (g_ptr_array_index (do_executev__argv__captured, 5), "/path/to/file.txt");
174 mctest_assert_str_eq (g_ptr_array_index (do_executev__argv__captured, 6), "+123");
175
176 vfs_path_free (filename_vpath, TRUE);
177 }
178
179 END_TEST
180
181
182
183
184 int
185 main (void)
186 {
187 TCase *tc_core;
188
189 tc_core = tcase_create ("Core");
190
191 tcase_add_checked_fixture (tc_core, my_setup, my_teardown);
192
193
194 tcase_add_test (tc_core, do_open_external_editor_or_viewer);
195
196
197 return mctest_run_all (tc_core);
198 }
199
200