2 src - tests for execute_external_editor_or_viewer() function
5 The Free Software Foundation, Inc.
8 Slava Zanko <slavazanko@gmail.com>, 2013
10 This file is part of the Midnight Commander.
12 The Midnight Commander is free software: you can redistribute it
13 and/or modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation, either version 3 of the License,
15 or (at your option) any later version.
17 The Midnight Commander is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #define TEST_SUITE_NAME "/src"
32 #include "lib/global.h"
33 #include "lib/mcconfig.h"
34 #include "lib/strutil.h"
35 #include "lib/vfs/path.h"
36 #include "src/vfs/local/local.c"
38 char *execute_get_external_cmd_opts_from_config (const char *command
,
39 const vfs_path_t
* filename_vpath
, int start_line
);
41 /* --------------------------------------------------------------------------------------------- */
44 static GPtrArray
*mc_config_get_string__group__captured
;
46 static GPtrArray
*mc_config_get_string__param__captured
;
48 static GPtrArray
*mc_config_get_string__default_value__captured
;
49 /* @ThenReturnValue */
50 static GPtrArray
*mc_config_get_string__return_value
;
54 mc_config_get_string_raw (const mc_config_t
* config_ignored
, const gchar
* group
,
55 const gchar
* param
, const gchar
* default_value
)
58 (void) config_ignored
;
60 g_ptr_array_add (mc_config_get_string__group__captured
, g_strdup (group
));
61 g_ptr_array_add (mc_config_get_string__param__captured
, g_strdup (param
));
62 g_ptr_array_add (mc_config_get_string__default_value__captured
, g_strdup (default_value
));
64 return_value
= g_ptr_array_index (mc_config_get_string__return_value
, 0);
65 g_ptr_array_remove_index (mc_config_get_string__return_value
, 0);
70 mc_config_get_string__init (void)
72 mc_config_get_string__group__captured
= g_ptr_array_new ();
73 mc_config_get_string__param__captured
= g_ptr_array_new ();
74 mc_config_get_string__default_value__captured
= g_ptr_array_new ();
76 mc_config_get_string__return_value
= g_ptr_array_new ();
80 mc_config_get_string__deinit (void)
82 g_ptr_array_foreach (mc_config_get_string__group__captured
, (GFunc
) g_free
, NULL
);
83 g_ptr_array_free (mc_config_get_string__group__captured
, TRUE
);
85 g_ptr_array_foreach (mc_config_get_string__param__captured
, (GFunc
) g_free
, NULL
);
86 g_ptr_array_free (mc_config_get_string__param__captured
, TRUE
);
88 g_ptr_array_foreach (mc_config_get_string__default_value__captured
, (GFunc
) g_free
, NULL
);
89 g_ptr_array_free (mc_config_get_string__default_value__captured
, TRUE
);
91 g_ptr_array_foreach (mc_config_get_string__return_value
, (GFunc
) g_free
, NULL
);
92 g_ptr_array_free (mc_config_get_string__return_value
, TRUE
);
95 /* --------------------------------------------------------------------------------------------- */
101 str_init_strings (NULL
);
104 vfs_setup_work_dir ();
106 mc_config_get_string__init ();
109 /* --------------------------------------------------------------------------------------------- */
115 mc_config_get_string__deinit ();
118 str_uninit_strings ();
121 /* --------------------------------------------------------------------------------------------- */
123 /* @DataSource("check_subtitute_ds") */
125 static const struct check_subtitute_ds
127 const char *config_opts_string
;
128 const char *app_name
;
129 const char *file_name
;
131 const char *expected_result
;
132 } check_subtitute_ds
[] =
135 "-a -b -c %filename \\%filename %filename:%lineno \\%lineno +%lineno",
139 "-a -b -c '/path/to/file' %filename '/path/to/file':1234 %lineno +1234",
142 "%filename:\\\\\\\\\\\\%lineno",
144 "/path/to/'f i\" l e \t\t\n",
146 "'/path/to/'\\''f i\" l e \t\t\n':\\\\\\\\\\\\1234",
151 /* @Test(dataSource = "check_subtitute_ds") */
153 START_TEST (check_if_filename_and_lineno_will_be_subtituted
)
157 const struct check_subtitute_ds
*data
= &check_subtitute_ds
[_i
];
159 vfs_path_t
*filename_vpath
;
161 g_ptr_array_add (mc_config_get_string__return_value
, g_strdup (data
->config_opts_string
));
162 filename_vpath
= vfs_path_from_str (data
->file_name
);
166 execute_get_external_cmd_opts_from_config (data
->app_name
, filename_vpath
,
171 /* check returned value */
172 g_assert_cmpstr (actual_result
, ==, data
->expected_result
);
174 /* check calls to mc_config_get_string() function */
175 g_assert_cmpstr (g_ptr_array_index (mc_config_get_string__group__captured
, 0), ==,
176 CONFIG_EXT_EDITOR_VIEWER_SECTION
);
177 g_assert_cmpstr (g_ptr_array_index (mc_config_get_string__param__captured
, 0), ==,
179 g_assert_cmpstr (g_ptr_array_index (mc_config_get_string__default_value__captured
, 0), ==,
182 vfs_path_free (filename_vpath
);
189 /* --------------------------------------------------------------------------------------------- */
196 Suite
*s
= suite_create (TEST_SUITE_NAME
);
197 TCase
*tc_core
= tcase_create ("Core");
200 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
202 /* Add new tests here: *************** */
203 tcase_add_loop_test (tc_core
, check_if_filename_and_lineno_will_be_subtituted
, 0,
204 sizeof (check_subtitute_ds
) / sizeof (check_subtitute_ds
[0]));
205 /* *********************************** */
207 suite_add_tcase (s
, tc_core
);
208 sr
= srunner_create (s
);
209 srunner_set_log (sr
, "execute__execute_get_external_cmd_opts_from_config.log");
210 srunner_run_all (sr
, CK_NORMAL
);
211 number_failed
= srunner_ntests_failed (sr
);
213 return (number_failed
== 0) ? 0 : 1;
216 /* --------------------------------------------------------------------------------------------- */