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/vfs/vfs.h"
33 #include "src/vfs/local/local.c"
34
35 static mc_config_t *mc_config;
36 static char *ini_filename;
37
38
39
40 static void
41 config_object__init (void)
42 {
43 ini_filename = g_build_filename (WORKDIR, "config_string.ini", (char *) NULL);
44 unlink (ini_filename);
45
46 mc_config = mc_config_init (ini_filename, FALSE);
47 }
48
49
50
51 static void
52 config_object__reopen (void)
53 {
54 GError *error = NULL;
55
56 if (!mc_config_save_file (mc_config, &error))
57 {
58 ck_abort_msg ("Unable to save config file: %s", error->message);
59 }
60
61 mc_config_deinit (mc_config);
62 mc_config = mc_config_init (ini_filename, FALSE);
63 }
64
65
66
67 static void
68 config_object__deinit (void)
69 {
70 mc_config_deinit (mc_config);
71 g_free (ini_filename);
72 }
73
74
75
76
77 static void
78 setup (void)
79 {
80 str_init_strings ("KOI8-R");
81 vfs_init ();
82 vfs_init_localfs ();
83
84 config_object__init ();
85 }
86
87
88
89
90 static void
91 teardown (void)
92 {
93 config_object__deinit ();
94
95 vfs_shut ();
96 str_uninit_strings ();
97 }
98
99
100
101
102
103 static const struct test_create_ini_file_ds
104 {
105 const char *input_group;
106 const char *input_param;
107 const char *input_default_value;
108 const char *expected_value;
109 const char *expected_raw_value;
110 } test_create_ini_file_ds[] =
111 {
112 {
113 "group-not-exists",
114 "param-not_exists",
115 NULL,
116 NULL,
117 NULL
118 },
119 {
120 "test-group1",
121 "test-param1",
122 "not-exists",
123 " some value ",
124 " some value "
125 },
126 {
127 "test-group1",
128 "test-param2",
129 "not-exists",
130
131 " \t \xF4\xC5\xD3\xD4\xCF\xD7\xCF\xC5 \xDA\xCE\xC1\xDE\xC5\xCE\xC9\xC5 ",
132
133 " \t Тестовое значение "
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",
177 " \t \xF4\xC5\xD3\xD4\xCF\xD7\xCF\xC5 \xDA\xCE\xC1\xDE\xC5\xCE\xC9\xC5 ");
178 mc_config_set_string (mc_config, "test-group1", "test-param3", " \tsome value2\n\nf\b\005fff ");
179 mc_config_set_string_raw (mc_config, "test-group2", "test-param1", " some value ");
180 mc_config_set_string_raw (mc_config, "test-group2", "test-param2",
181 " \xF4\xC5\xD3\xD4\xCF\xD7\xCF\xC5 \xDA\xCE\xC1\xDE\xC5\xCE\xC9\xC5");
182 mc_config_set_string_raw (mc_config, "test-group2", "test-param3",
183 " \tsome value2\n\nf\b\005fff ");
184
185 config_object__reopen ();
186
187
188 actual_value =
189 mc_config_get_string (mc_config, data->input_group, data->input_param,
190 data->input_default_value);
191 actual_raw_value =
192 mc_config_get_string_raw (mc_config, data->input_group, data->input_param,
193 data->input_default_value);
194
195
196 mctest_assert_str_eq (actual_value, data->expected_value);
197 mctest_assert_str_eq (actual_raw_value, data->expected_raw_value);
198
199 g_free (actual_value);
200 g_free (actual_raw_value);
201 }
202
203 END_PARAMETRIZED_TEST
204
205
206
207
208
209
210 START_TEST (emulate__learn_save)
211
212 {
213
214 char *actual_value;
215
216 {
217 char *esc_str;
218
219 esc_str = str_escape ("T;E\\X;T-FOR-\\T;E;S\\TI;N'G", -1, ";", TRUE);
220 mc_config_set_string_raw (mc_config, "test-group1", "test-param1", esc_str);
221 g_free (esc_str);
222 }
223
224 config_object__reopen ();
225
226
227 actual_value = mc_config_get_string_raw (mc_config, "test-group1", "test-param1", "not-exists");
228
229
230 mctest_assert_str_eq (actual_value, "T\\;E\\X\\;T-FOR-\\T\\;E\\;S\\TI\\;N'G");
231 g_free (actual_value);
232 }
233
234 END_TEST
235
236
237
238
239 int
240 main (void)
241 {
242 TCase *tc_core;
243
244 tc_core = tcase_create ("Core");
245
246 tcase_add_checked_fixture (tc_core, setup, teardown);
247
248
249 mctest_add_parameterized_test (tc_core, test_create_ini_file_paths, test_create_ini_file_ds);
250 tcase_add_test (tc_core, emulate__learn_save);
251
252
253 return mctest_run_all (tc_core);
254 }
255
256