2 libmc - check mcconfig submodule. read and write config files
5 The Free Software Foundation, Inc.
8 Slava Zanko <slavazanko@gmail.com>, 2011
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"
32 #include "lib/global.h"
33 #include "lib/mcconfig.h"
34 #include "lib/strutil.h"
35 #include "lib/strescape.h"
36 #include "lib/vfs/vfs.h"
37 #include "src/vfs/local/local.c"
44 str_init_strings("KOI8-R");
55 /* --------------------------------------------------------------------------------------------- */
56 #define fail_unless_strcmp( etalon ) \
58 strcmp(actual_value, etalon) == 0, \
59 "Actial value '%s' doesn't equal to etalon '%s'", actual_value, etalon \
62 START_TEST (create_ini_file
)
64 mc_config_t
*mc_config
;
67 char *ini_filename
= NULL
;
69 ini_filename
= g_build_filename(WORKDIR
, "test-create_ini_file.ini",NULL
);
72 mc_config
= mc_config_init (ini_filename
, FALSE
);
73 if (mc_config
== NULL
)
75 fail("unable to create mc_congif_t object!");
79 mc_config_set_string (mc_config
, "test-group1", "test-param1", " some value ");
80 mc_config_set_string (mc_config
, "test-group1", "test-param2", " \tkoi8-r: ôÅÓÔÏ×ÏÅ ÚÎÁÞÅÎÉÅ ");
81 mc_config_set_string (mc_config
, "test-group1", "test-param3", " \tsome value2\n\nf\b\005fff ");
83 mc_config_set_string_raw (mc_config
, "test-group2", "test-param1", " some value ");
84 mc_config_set_string_raw (mc_config
, "test-group2", "test-param2", " koi8-r: ôÅÓÔÏ×ÏÅ ÚÎÁÞÅÎÉÅ");
85 mc_config_set_string_raw (mc_config
, "test-group2", "test-param3", " \tsome value2\n\nf\b\005fff ");
87 if (!mc_config_save_file (mc_config
, &error
))
89 fail("Unable to save config file: %s",error
->message
);
93 mc_config_deinit (mc_config
);
94 mc_config
= mc_config_init (ini_filename
, FALSE
);
96 actual_value
= mc_config_get_string(mc_config
, "group-not-exists", "param-not_exists", NULL
);
97 fail_unless(actual_value
== NULL
, "return value for nonexistent ini-parameters isn't NULL (default value)!");
99 actual_value
= mc_config_get_string(mc_config
, "test-group1", "test-param1", "not-exists");
100 fail_unless_strcmp(" some value ");
101 g_free(actual_value
);
103 actual_value
= mc_config_get_string(mc_config
, "test-group1", "test-param2", "not-exists");
104 fail_unless_strcmp(" \tkoi8-r: ôÅÓÔÏ×ÏÅ ÚÎÁÞÅÎÉÅ ");
105 g_free(actual_value
);
107 actual_value
= mc_config_get_string(mc_config
, "test-group1", "test-param3", "not-exists");
108 fail_unless_strcmp(" \tsome value2\n\nf\b\005fff ");
109 g_free(actual_value
);
112 actual_value
= mc_config_get_string_raw( mc_config
, "test-group2", "test-param1", "not-exists");
113 fail_unless_strcmp(" some value ");
114 g_free(actual_value
);
116 actual_value
= mc_config_get_string_raw( mc_config
, "test-group2", "test-param2", "not-exists");
117 fail_unless_strcmp("not-exists");
118 g_free(actual_value
);
120 actual_value
= mc_config_get_string_raw( mc_config
, "test-group2", "test-param3", "not-exists");
121 fail_unless_strcmp(" \tsome value2\n\nf\b\005fff ");
122 g_free(actual_value
);
124 mc_config_deinit (mc_config
);
125 g_free(ini_filename
);
130 /* --------------------------------------------------------------------------------------------- */
132 START_TEST (emulate__learn_save
)
134 mc_config_t
*mc_config
;
135 char *actual_value
, *esc_str
;
136 char *ini_filename
= NULL
;
137 GError
*error
= NULL
;
139 ini_filename
= g_build_filename(WORKDIR
, "test-emulate__learn_save.ini",NULL
);
140 unlink(ini_filename
);
142 mc_config
= mc_config_init (ini_filename
, FALSE
);
143 if (mc_config
== NULL
)
145 fail("unable to create mc_congif_t object!");
149 esc_str
= strutils_escape ("T;E\\X;T-FOR-\\T;E;S\\TI;N'G", -1, ";", TRUE
);
150 mc_config_set_string_raw (mc_config
, "test-group1", "test-param1", esc_str
);
153 if (!mc_config_save_file (mc_config
, &error
))
155 fail("Unable to save config file: %s",error
->message
);
159 mc_config_deinit (mc_config
);
160 mc_config
= mc_config_init (ini_filename
, FALSE
);
162 actual_value
= mc_config_get_string_raw( mc_config
, "test-group1", "test-param1", "not-exists");
163 fail_unless_strcmp("T\\;E\\X\\;T-FOR-\\T\\;E\\;S\\TI\\;N'G");
164 g_free(actual_value
);
166 mc_config_deinit (mc_config
);
167 g_free(ini_filename
);
171 /* --------------------------------------------------------------------------------------------- */
178 Suite
*s
= suite_create (TEST_SUITE_NAME
);
179 TCase
*tc_core
= tcase_create ("Core");
182 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
184 /* Add new tests here: *************** */
185 tcase_add_test (tc_core
, create_ini_file
);
186 tcase_add_test (tc_core
, emulate__learn_save
);
187 /* *********************************** */
189 suite_add_tcase (s
, tc_core
);
190 sr
= srunner_create (s
);
191 // srunner_set_fork_status (sr, CK_NOFORK);
192 srunner_run_all (sr
, CK_NORMAL
);
193 number_failed
= srunner_ntests_failed (sr
);
195 return (number_failed
== 0) ? 0 : 1;
198 /* --------------------------------------------------------------------------------------------- */