2 libmc - check mcconfig submodule. read and write config files
4 Copyright (C) 2011-2019
5 Free Software Foundation, Inc.
8 Slava Zanko <slavazanko@gmail.com>, 2011, 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 "lib/mcconfig"
28 #include "tests/mctest.h"
30 #include "lib/mcconfig.h"
31 #include "lib/strutil.h"
32 #include "lib/strescape.h"
33 #include "lib/vfs/vfs.h"
34 #include "src/vfs/local/local.c"
36 static mc_config_t
*mc_config
;
37 static char *ini_filename
;
39 /* --------------------------------------------------------------------------------------------- */
42 config_object__init (void)
44 ini_filename
= g_build_filename (WORKDIR
, "config_string.ini", (char *) NULL
);
45 unlink (ini_filename
);
47 mc_config
= mc_config_init (ini_filename
, FALSE
);
50 /* --------------------------------------------------------------------------------------------- */
53 config_object__reopen (void)
57 if (!mc_config_save_file (mc_config
, &error
))
59 fail ("Unable to save config file: %s", error
->message
);
63 mc_config_deinit (mc_config
);
64 mc_config
= mc_config_init (ini_filename
, FALSE
);
67 /* --------------------------------------------------------------------------------------------- */
70 config_object__deinit (void)
72 mc_config_deinit (mc_config
);
73 g_free (ini_filename
);
76 /* --------------------------------------------------------------------------------------------- */
82 str_init_strings ("KOI8-R");
86 config_object__init ();
89 /* --------------------------------------------------------------------------------------------- */
95 config_object__deinit ();
98 str_uninit_strings ();
101 /* --------------------------------------------------------------------------------------------- */
103 /* @DataSource("test_create_ini_file_ds") */
105 static const struct test_create_ini_file_ds
107 const char *input_group
;
108 const char *input_param
;
109 const char *input_default_value
;
110 const char *expected_value
;
111 const char *expected_raw_value
;
112 } test_create_ini_file_ds
[] =
132 " \tkoi8-r: ôÅÓÔÏ×ÏÅ ÚÎÁÞÅÎÉÅ ",
133 " \tkoi8-r: \320\242\320\265\321\201\321\202\320\276\320\262\320\276\320\265 \320\267\320\275\320\260\321\207\320\265\320\275\320\270\320\265 "
139 " \tsome value2\n\nf\b\005fff ",
140 " \tsome value2\n\nf\b\005fff "
160 " \tsome value2\n\nf\b\005fff ",
161 " \tsome value2\n\nf\b\005fff "
167 /* @Test(dataSource = "test_create_ini_file_ds") */
169 START_PARAMETRIZED_TEST (test_create_ini_file_paths
, test_create_ini_file_ds
)
173 char *actual_value
, *actual_raw_value
;
175 mc_config_set_string (mc_config
, "test-group1", "test-param1", " some value ");
176 mc_config_set_string (mc_config
, "test-group1", "test-param2", " \tkoi8-r: ôÅÓÔÏ×ÏÅ ÚÎÁÞÅÎÉÅ ");
177 mc_config_set_string (mc_config
, "test-group1", "test-param3", " \tsome value2\n\nf\b\005fff ");
178 mc_config_set_string_raw (mc_config
, "test-group2", "test-param1", " some value ");
179 mc_config_set_string_raw (mc_config
, "test-group2", "test-param2",
180 " koi8-r: ôÅÓÔÏ×ÏÅ ÚÎÁÞÅÎÉÅ");
181 mc_config_set_string_raw (mc_config
, "test-group2", "test-param3",
182 " \tsome value2\n\nf\b\005fff ");
184 config_object__reopen ();
188 mc_config_get_string (mc_config
, data
->input_group
, data
->input_param
,
189 data
->input_default_value
);
191 mc_config_get_string_raw (mc_config
, data
->input_group
, data
->input_param
,
192 data
->input_default_value
);
195 mctest_assert_str_eq (actual_value
, data
->expected_value
);
196 mctest_assert_str_eq (actual_raw_value
, data
->expected_raw_value
);
198 g_free (actual_value
);
199 g_free (actual_raw_value
);
202 END_PARAMETRIZED_TEST
205 /* --------------------------------------------------------------------------------------------- */
207 /* @Test(group='Integration') */
209 START_TEST (emulate__learn_save
)
218 esc_str
= strutils_escape ("T;E\\X;T-FOR-\\T;E;S\\TI;N'G", -1, ";", TRUE
);
219 mc_config_set_string_raw (mc_config
, "test-group1", "test-param1", esc_str
);
223 config_object__reopen ();
226 actual_value
= mc_config_get_string_raw (mc_config
, "test-group1", "test-param1", "not-exists");
229 mctest_assert_str_eq (actual_value
, "T\\;E\\X\\;T-FOR-\\T\\;E\\;S\\TI\\;N'G");
230 g_free (actual_value
);
236 /* --------------------------------------------------------------------------------------------- */
243 Suite
*s
= suite_create (TEST_SUITE_NAME
);
244 TCase
*tc_core
= tcase_create ("Core");
247 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
249 /* Add new tests here: *************** */
250 mctest_add_parameterized_test (tc_core
, test_create_ini_file_paths
, test_create_ini_file_ds
);
251 tcase_add_test (tc_core
, emulate__learn_save
);
252 /* *********************************** */
254 suite_add_tcase (s
, tc_core
);
255 sr
= srunner_create (s
);
256 srunner_set_log (sr
, "config_string.log");
257 srunner_run_all (sr
, CK_ENV
);
258 number_failed
= srunner_ntests_failed (sr
);
260 return (number_failed
== 0) ? EXIT_SUCCESS
: EXIT_FAILURE
;
263 /* --------------------------------------------------------------------------------------------- */