2 libmc - check mcconfig submodule. read and write config files
4 Copyright (C) 2011-2024
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/vfs/vfs.h"
33 #include "src/vfs/local/local.c"
35 static mc_config_t
*mc_config
;
36 static char *ini_filename
;
38 /* --------------------------------------------------------------------------------------------- */
41 config_object__init (void)
43 ini_filename
= g_build_filename (WORKDIR
, "config_string.ini", (char *) NULL
);
44 unlink (ini_filename
);
46 mc_config
= mc_config_init (ini_filename
, FALSE
);
49 /* --------------------------------------------------------------------------------------------- */
52 config_object__reopen (void)
56 if (!mc_config_save_file (mc_config
, &error
))
58 ck_abort_msg ("Unable to save config file: %s", error
->message
);
62 mc_config_deinit (mc_config
);
63 mc_config
= mc_config_init (ini_filename
, FALSE
);
66 /* --------------------------------------------------------------------------------------------- */
69 config_object__deinit (void)
71 mc_config_deinit (mc_config
);
72 g_free (ini_filename
);
75 /* --------------------------------------------------------------------------------------------- */
81 str_init_strings ("KOI8-R");
85 config_object__init ();
88 /* --------------------------------------------------------------------------------------------- */
94 config_object__deinit ();
97 str_uninit_strings ();
100 /* --------------------------------------------------------------------------------------------- */
102 /* @DataSource("test_create_ini_file_ds") */
104 static const struct test_create_ini_file_ds
106 const char *input_group
;
107 const char *input_param
;
108 const char *input_default_value
;
109 const char *expected_value
;
110 const char *expected_raw_value
;
111 } test_create_ini_file_ds
[] =
131 " \tkoi8-r: ôÅÓÔÏ×ÏÅ ÚÎÁÞÅÎÉÅ ",
132 " \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 "
138 " \tsome value2\n\nf\b\005fff ",
139 " \tsome value2\n\nf\b\005fff "
159 " \tsome value2\n\nf\b\005fff ",
160 " \tsome value2\n\nf\b\005fff "
166 /* @Test(dataSource = "test_create_ini_file_ds") */
168 START_PARAMETRIZED_TEST (test_create_ini_file_paths
, test_create_ini_file_ds
)
172 char *actual_value
, *actual_raw_value
;
174 mc_config_set_string (mc_config
, "test-group1", "test-param1", " some value ");
175 mc_config_set_string (mc_config
, "test-group1", "test-param2", " \tkoi8-r: ôÅÓÔÏ×ÏÅ ÚÎÁÞÅÎÉÅ ");
176 mc_config_set_string (mc_config
, "test-group1", "test-param3", " \tsome value2\n\nf\b\005fff ");
177 mc_config_set_string_raw (mc_config
, "test-group2", "test-param1", " some value ");
178 mc_config_set_string_raw (mc_config
, "test-group2", "test-param2",
179 " koi8-r: ôÅÓÔÏ×ÏÅ ÚÎÁÞÅÎÉÅ");
180 mc_config_set_string_raw (mc_config
, "test-group2", "test-param3",
181 " \tsome value2\n\nf\b\005fff ");
183 config_object__reopen ();
187 mc_config_get_string (mc_config
, data
->input_group
, data
->input_param
,
188 data
->input_default_value
);
190 mc_config_get_string_raw (mc_config
, data
->input_group
, data
->input_param
,
191 data
->input_default_value
);
194 mctest_assert_str_eq (actual_value
, data
->expected_value
);
195 mctest_assert_str_eq (actual_raw_value
, data
->expected_raw_value
);
197 g_free (actual_value
);
198 g_free (actual_raw_value
);
201 END_PARAMETRIZED_TEST
204 /* --------------------------------------------------------------------------------------------- */
206 /* @Test(group='Integration') */
208 START_TEST (emulate__learn_save
)
217 esc_str
= str_escape ("T;E\\X;T-FOR-\\T;E;S\\TI;N'G", -1, ";", TRUE
);
218 mc_config_set_string_raw (mc_config
, "test-group1", "test-param1", esc_str
);
222 config_object__reopen ();
225 actual_value
= mc_config_get_string_raw (mc_config
, "test-group1", "test-param1", "not-exists");
228 mctest_assert_str_eq (actual_value
, "T\\;E\\X\\;T-FOR-\\T\\;E\\;S\\TI\\;N'G");
229 g_free (actual_value
);
235 /* --------------------------------------------------------------------------------------------- */
242 tc_core
= tcase_create ("Core");
244 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
246 /* Add new tests here: *************** */
247 mctest_add_parameterized_test (tc_core
, test_create_ini_file_paths
, test_create_ini_file_ds
);
248 tcase_add_test (tc_core
, emulate__learn_save
);
249 /* *********************************** */
251 return mctest_run_all (tc_core
);
254 /* --------------------------------------------------------------------------------------------- */