- tests/src/execute__execute_get_external_cmd_opts_from_config.c
This source file includes following definitions.
- mc_config_get_string_raw
- mc_config_get_string__init
- mc_config_get_string__deinit
- setup
- teardown
- START_PARAMETRIZED_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 "lib/mcconfig.h"
31 #include "lib/strutil.h"
32 #include "lib/vfs/vfs.h"
33 #include "src/vfs/local/local.c"
34
35 char *execute_get_external_cmd_opts_from_config (const char *command,
36 const vfs_path_t * filename_vpath,
37 long start_line);
38
39
40
41
42 static GPtrArray *mc_config_get_string__group__captured;
43
44 static GPtrArray *mc_config_get_string__param__captured;
45
46 static GPtrArray *mc_config_get_string__default_value__captured;
47
48 static GPtrArray *mc_config_get_string__return_value;
49
50
51 gchar *
52 mc_config_get_string_raw (mc_config_t *config_ignored, const gchar *group,
53 const gchar *param, const gchar *default_value)
54 {
55 char *return_value;
56 (void) config_ignored;
57
58 g_ptr_array_add (mc_config_get_string__group__captured, g_strdup (group));
59 g_ptr_array_add (mc_config_get_string__param__captured, g_strdup (param));
60 g_ptr_array_add (mc_config_get_string__default_value__captured, g_strdup (default_value));
61
62 return_value = g_ptr_array_index (mc_config_get_string__return_value, 0);
63 g_ptr_array_remove_index (mc_config_get_string__return_value, 0);
64 return return_value;
65 }
66
67 static void
68 mc_config_get_string__init (void)
69 {
70 mc_config_get_string__group__captured = g_ptr_array_new_with_free_func (g_free);
71 mc_config_get_string__param__captured = g_ptr_array_new_with_free_func (g_free);
72 mc_config_get_string__default_value__captured = g_ptr_array_new_with_free_func (g_free);
73
74 mc_config_get_string__return_value = g_ptr_array_new ();
75 }
76
77 static void
78 mc_config_get_string__deinit (void)
79 {
80 g_ptr_array_free (mc_config_get_string__group__captured, TRUE);
81 g_ptr_array_free (mc_config_get_string__param__captured, TRUE);
82 g_ptr_array_free (mc_config_get_string__default_value__captured, TRUE);
83
84 g_ptr_array_foreach (mc_config_get_string__return_value, (GFunc) g_free, NULL);
85 g_ptr_array_free (mc_config_get_string__return_value, TRUE);
86 }
87
88
89
90
91 static void
92 setup (void)
93 {
94 str_init_strings (NULL);
95 vfs_init ();
96 vfs_init_localfs ();
97 vfs_setup_work_dir ();
98
99 mc_config_get_string__init ();
100 }
101
102
103
104
105 static void
106 teardown (void)
107 {
108 mc_config_get_string__deinit ();
109
110 vfs_shut ();
111 str_uninit_strings ();
112 }
113
114
115
116
117
118 static const struct check_subtitute_ds
119 {
120 const char *config_opts_string;
121 const char *app_name;
122 const char *file_name;
123 int start_line;
124 const char *expected_result;
125 } check_subtitute_ds[] =
126 {
127 {
128 "-a -b -c %filename \\%filename %filename:%lineno \\%lineno +%lineno",
129 "some-editor",
130 "/path/to/file",
131 1234,
132 "-a -b -c '/path/to/file' %filename '/path/to/file':1234 %lineno +1234",
133 },
134 {
135 "%filename:\\\\\\\\\\\\%lineno",
136 "some-editor",
137 "/path/to/'f i\" l e \t\t\n",
138 1234,
139 "'/path/to/'\\''f i\" l e \t\t\n':\\\\\\\\\\\\1234",
140 },
141 };
142
143
144
145
146 START_PARAMETRIZED_TEST (check_if_filename_and_lineno_will_be_subtituted, check_subtitute_ds)
147
148 {
149
150 char *actual_result;
151 vfs_path_t *filename_vpath;
152
153 g_ptr_array_add (mc_config_get_string__return_value, g_strdup (data->config_opts_string));
154 filename_vpath = vfs_path_from_str (data->file_name);
155
156
157 actual_result =
158 execute_get_external_cmd_opts_from_config (data->app_name, filename_vpath,
159 data->start_line);
160
161
162
163
164 mctest_assert_str_eq (actual_result, data->expected_result);
165
166
167 mctest_assert_str_eq (g_ptr_array_index (mc_config_get_string__group__captured, 0),
168 CONFIG_EXT_EDITOR_VIEWER_SECTION);
169 mctest_assert_str_eq (g_ptr_array_index (mc_config_get_string__param__captured, 0),
170 data->app_name);
171 mctest_assert_str_eq (g_ptr_array_index (mc_config_get_string__default_value__captured, 0),
172 NULL);
173
174 vfs_path_free (filename_vpath, TRUE);
175
176 }
177
178 END_PARAMETRIZED_TEST
179
180
181
182
183 int
184 main (void)
185 {
186 TCase *tc_core;
187
188 tc_core = tcase_create ("Core");
189
190 tcase_add_checked_fixture (tc_core, setup, teardown);
191
192
193 mctest_add_parameterized_test (tc_core, check_if_filename_and_lineno_will_be_subtituted,
194 check_subtitute_ds);
195
196
197 return mctest_run_all (tc_core);
198 }
199
200