subshell: ensure compatibility with fish 3.8
[midnight-commander.git] / tests / lib / mcconfig / config_string.c
blob15213ebf6600ca6e3e6e2c3023552331c0f2e043
1 /*
2 libmc - check mcconfig submodule. read and write config files
4 Copyright (C) 2011-2024
5 Free Software Foundation, Inc.
7 Written by:
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 /* --------------------------------------------------------------------------------------------- */
40 static void
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 /* --------------------------------------------------------------------------------------------- */
51 static void
52 config_object__reopen (void)
54 GError *error = NULL;
56 if (!mc_config_save_file (mc_config, &error))
58 ck_abort_msg ("Unable to save config file: %s", error->message);
59 g_error_free (error);
62 mc_config_deinit (mc_config);
63 mc_config = mc_config_init (ini_filename, FALSE);
66 /* --------------------------------------------------------------------------------------------- */
68 static void
69 config_object__deinit (void)
71 mc_config_deinit (mc_config);
72 g_free (ini_filename);
75 /* --------------------------------------------------------------------------------------------- */
77 /* @Before */
78 static void
79 setup (void)
81 str_init_strings ("KOI8-R");
82 vfs_init ();
83 vfs_init_localfs ();
85 config_object__init ();
88 /* --------------------------------------------------------------------------------------------- */
90 /* @After */
91 static void
92 teardown (void)
94 config_object__deinit ();
96 vfs_shut ();
97 str_uninit_strings ();
100 /* --------------------------------------------------------------------------------------------- */
102 /* @DataSource("test_create_ini_file_ds") */
103 /* *INDENT-OFF* */
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[] =
113 { /* 0. */
114 "group-not-exists",
115 "param-not_exists",
116 NULL,
117 NULL,
118 NULL
120 { /* 1. */
121 "test-group1",
122 "test-param1",
123 "not-exists",
124 " some value ",
125 " some value "
127 { /* 2. */
128 "test-group1",
129 "test-param2",
130 "not-exists",
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 "
134 { /* 3. */
135 "test-group1",
136 "test-param3",
137 "not-exists",
138 " \tsome value2\n\nf\b\005fff ",
139 " \tsome value2\n\nf\b\005fff "
141 { /* 4. */
142 "test-group2",
143 "test-param1",
144 "not-exists",
145 " some value ",
146 " some value "
148 { /* 5. */
149 "test-group2",
150 "test-param2",
151 "not-exists",
152 "not-exists",
153 "not-exists"
155 { /* 6. */
156 "test-group2",
157 "test-param3",
158 "not-exists",
159 " \tsome value2\n\nf\b\005fff ",
160 " \tsome value2\n\nf\b\005fff "
164 /* *INDENT-ON* */
166 /* @Test(dataSource = "test_create_ini_file_ds") */
167 /* *INDENT-OFF* */
168 START_PARAMETRIZED_TEST (test_create_ini_file_paths, test_create_ini_file_ds)
169 /* *INDENT-ON* */
171 /* given */
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 ();
185 /* when */
186 actual_value =
187 mc_config_get_string (mc_config, data->input_group, data->input_param,
188 data->input_default_value);
189 actual_raw_value =
190 mc_config_get_string_raw (mc_config, data->input_group, data->input_param,
191 data->input_default_value);
193 /* then */
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);
200 /* *INDENT-OFF* */
201 END_PARAMETRIZED_TEST
202 /* *INDENT-ON* */
204 /* --------------------------------------------------------------------------------------------- */
206 /* @Test(group='Integration') */
207 /* *INDENT-OFF* */
208 START_TEST (emulate__learn_save)
209 /* *INDENT-ON* */
211 /* given */
212 char *actual_value;
215 char *esc_str;
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);
219 g_free (esc_str);
222 config_object__reopen ();
224 /* when */
225 actual_value = mc_config_get_string_raw (mc_config, "test-group1", "test-param1", "not-exists");
227 /* then */
228 mctest_assert_str_eq (actual_value, "T\\;E\\X\\;T-FOR-\\T\\;E\\;S\\TI\\;N'G");
229 g_free (actual_value);
231 /* *INDENT-OFF* */
232 END_TEST
233 /* *INDENT-ON* */
235 /* --------------------------------------------------------------------------------------------- */
238 main (void)
240 TCase *tc_core;
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 /* --------------------------------------------------------------------------------------------- */