This source file includes following definitions.
- config_object__init
- config_object__reopen
- config_object__deinit
- setup
- teardown
- START_PARAMETRIZED_TEST
- START_TEST
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 #define TEST_SUITE_NAME "lib/mcconfig"
27
28 #include "tests/mctest.h"
29
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"
35
36 static mc_config_t *mc_config;
37 static char *ini_filename;
38
39
40
41 static void
42 config_object__init (void)
43 {
44 ini_filename = g_build_filename (WORKDIR, "config_string.ini", (char *) NULL);
45 unlink (ini_filename);
46
47 mc_config = mc_config_init (ini_filename, FALSE);
48 }
49
50
51
52 static void
53 config_object__reopen (void)
54 {
55 GError *error = NULL;
56
57 if (!mc_config_save_file (mc_config, &error))
58 {
59 ck_abort_msg ("Unable to save config file: %s", error->message);
60 g_error_free (error);
61 }
62
63 mc_config_deinit (mc_config);
64 mc_config = mc_config_init (ini_filename, FALSE);
65 }
66
67
68
69 static void
70 config_object__deinit (void)
71 {
72 mc_config_deinit (mc_config);
73 g_free (ini_filename);
74 }
75
76
77
78
79 static void
80 setup (void)
81 {
82 str_init_strings ("KOI8-R");
83 vfs_init ();
84 vfs_init_localfs ();
85
86 config_object__init ();
87 }
88
89
90
91
92 static void
93 teardown (void)
94 {
95 config_object__deinit ();
96
97 vfs_shut ();
98 str_uninit_strings ();
99 }
100
101
102
103
104
105 static const struct test_create_ini_file_ds
106 {
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[] =
113 {
114 {
115 "group-not-exists",
116 "param-not_exists",
117 NULL,
118 NULL,
119 NULL
120 },
121 {
122 "test-group1",
123 "test-param1",
124 "not-exists",
125 " some value ",
126 " some value "
127 },
128 {
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 "
134 },
135 {
136 "test-group1",
137 "test-param3",
138 "not-exists",
139 " \tsome value2\n\nf\b\005fff ",
140 " \tsome value2\n\nf\b\005fff "
141 },
142 {
143 "test-group2",
144 "test-param1",
145 "not-exists",
146 " some value ",
147 " some value "
148 },
149 {
150 "test-group2",
151 "test-param2",
152 "not-exists",
153 "not-exists",
154 "not-exists"
155 },
156 {
157 "test-group2",
158 "test-param3",
159 "not-exists",
160 " \tsome value2\n\nf\b\005fff ",
161 " \tsome value2\n\nf\b\005fff "
162 },
163
164 };
165
166
167
168
169 START_PARAMETRIZED_TEST (test_create_ini_file_paths, test_create_ini_file_ds)
170
171 {
172
173 char *actual_value, *actual_raw_value;
174
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 ");
183
184 config_object__reopen ();
185
186
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);
193
194
195 mctest_assert_str_eq (actual_value, data->expected_value);
196 mctest_assert_str_eq (actual_raw_value, data->expected_raw_value);
197
198 g_free (actual_value);
199 g_free (actual_raw_value);
200 }
201
202 END_PARAMETRIZED_TEST
203
204
205
206
207
208
209 START_TEST (emulate__learn_save)
210
211 {
212
213 char *actual_value;
214
215 {
216 char *esc_str;
217
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);
221 }
222
223 config_object__reopen ();
224
225
226 actual_value = mc_config_get_string_raw (mc_config, "test-group1", "test-param1", "not-exists");
227
228
229 mctest_assert_str_eq (actual_value, "T\\;E\\X\\;T-FOR-\\T\\;E\\;S\\TI\\;N'G");
230 g_free (actual_value);
231 }
232
233 END_TEST
234
235
236
237
238 int
239 main (void)
240 {
241 TCase *tc_core;
242
243 tc_core = tcase_create ("Core");
244
245 tcase_add_checked_fixture (tc_core, setup, teardown);
246
247
248 mctest_add_parameterized_test (tc_core, test_create_ini_file_paths, test_create_ini_file_ds);
249 tcase_add_test (tc_core, emulate__learn_save);
250
251
252 return mctest_run_all (tc_core);
253 }
254
255