Update translations from Transifex
[midnight-commander.git] / tests / lib / mcconfig / config_string.c
blobd5dfcd7a71ae055edf97e35231ece6c28e91c427
1 /*
2 libmc - check mcconfig submodule. read and write config files
4 Copyright (C) 2011-2019
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/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 /* --------------------------------------------------------------------------------------------- */
41 static void
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 /* --------------------------------------------------------------------------------------------- */
52 static void
53 config_object__reopen (void)
55 GError *error = NULL;
57 if (!mc_config_save_file (mc_config, &error))
59 fail ("Unable to save config file: %s", error->message);
60 g_error_free (error);
63 mc_config_deinit (mc_config);
64 mc_config = mc_config_init (ini_filename, FALSE);
67 /* --------------------------------------------------------------------------------------------- */
69 static void
70 config_object__deinit (void)
72 mc_config_deinit (mc_config);
73 g_free (ini_filename);
76 /* --------------------------------------------------------------------------------------------- */
78 /* @Before */
79 static void
80 setup (void)
82 str_init_strings ("KOI8-R");
83 vfs_init ();
84 vfs_init_localfs ();
86 config_object__init ();
89 /* --------------------------------------------------------------------------------------------- */
91 /* @After */
92 static void
93 teardown (void)
95 config_object__deinit ();
97 vfs_shut ();
98 str_uninit_strings ();
101 /* --------------------------------------------------------------------------------------------- */
103 /* @DataSource("test_create_ini_file_ds") */
104 /* *INDENT-OFF* */
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[] =
114 { /* 0. */
115 "group-not-exists",
116 "param-not_exists",
117 NULL,
118 NULL,
119 NULL
121 { /* 1. */
122 "test-group1",
123 "test-param1",
124 "not-exists",
125 " some value ",
126 " some value "
128 { /* 2. */
129 "test-group1",
130 "test-param2",
131 "not-exists",
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 "
135 { /* 3. */
136 "test-group1",
137 "test-param3",
138 "not-exists",
139 " \tsome value2\n\nf\b\005fff ",
140 " \tsome value2\n\nf\b\005fff "
142 { /* 4. */
143 "test-group2",
144 "test-param1",
145 "not-exists",
146 " some value ",
147 " some value "
149 { /* 5. */
150 "test-group2",
151 "test-param2",
152 "not-exists",
153 "not-exists",
154 "not-exists"
156 { /* 6. */
157 "test-group2",
158 "test-param3",
159 "not-exists",
160 " \tsome value2\n\nf\b\005fff ",
161 " \tsome value2\n\nf\b\005fff "
165 /* *INDENT-ON* */
167 /* @Test(dataSource = "test_create_ini_file_ds") */
168 /* *INDENT-OFF* */
169 START_PARAMETRIZED_TEST (test_create_ini_file_paths, test_create_ini_file_ds)
170 /* *INDENT-ON* */
172 /* given */
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 ();
186 /* when */
187 actual_value =
188 mc_config_get_string (mc_config, data->input_group, data->input_param,
189 data->input_default_value);
190 actual_raw_value =
191 mc_config_get_string_raw (mc_config, data->input_group, data->input_param,
192 data->input_default_value);
194 /* then */
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);
201 /* *INDENT-OFF* */
202 END_PARAMETRIZED_TEST
203 /* *INDENT-ON* */
205 /* --------------------------------------------------------------------------------------------- */
207 /* @Test(group='Integration') */
208 /* *INDENT-OFF* */
209 START_TEST (emulate__learn_save)
210 /* *INDENT-ON* */
212 /* given */
213 char *actual_value;
216 char *esc_str;
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);
220 g_free (esc_str);
223 config_object__reopen ();
225 /* when */
226 actual_value = mc_config_get_string_raw (mc_config, "test-group1", "test-param1", "not-exists");
228 /* then */
229 mctest_assert_str_eq (actual_value, "T\\;E\\X\\;T-FOR-\\T\\;E\\;S\\TI\\;N'G");
230 g_free (actual_value);
232 /* *INDENT-OFF* */
233 END_TEST
234 /* *INDENT-ON* */
236 /* --------------------------------------------------------------------------------------------- */
239 main (void)
241 int number_failed;
243 Suite *s = suite_create (TEST_SUITE_NAME);
244 TCase *tc_core = tcase_create ("Core");
245 SRunner *sr;
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);
259 srunner_free (sr);
260 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
263 /* --------------------------------------------------------------------------------------------- */