Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : *
8 : */
9 :
10 :
11 : #include "type.h"
12 :
13 : #include <kdbmodule.h>
14 : #include <kdbplugin.h>
15 : #include <tests_plugin.h>
16 :
17 : static bool checkType (const Key * key)
18 : {
19 132208 : return elektraTypeCheckType (key);
20 : }
21 :
22 2 : void test_validate (void)
23 : {
24 2 : Key * parentKey = keyNew ("system/elektra/modules/type", KEY_END);
25 2 : KeySet * conf = ksNew (0, KS_END);
26 :
27 2 : PLUGIN_OPEN ("type");
28 :
29 2 : KeySet * ks = ksNew (0, KS_END);
30 2 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
31 : Key * key;
32 2 : key = ksLookupByName (ks, "system/elektra/modules/type/exports/validateKey", 0);
33 2 : exit_if_fail (key, "key not found");
34 :
35 : union
36 : {
37 : int (*f) (Plugin *, Key *, Key *);
38 : void * v;
39 : } conversation;
40 :
41 2 : exit_if_fail (keyGetBinary (key, &conversation.v, sizeof (conversation)) == sizeof (conversation),
42 : "failed to load validateKey function");
43 :
44 2 : Key * k = keyNew ("user/anything", KEY_VALUE, "0", KEY_META, "check/type", "short", KEY_END);
45 2 : succeed_if (conversation.f (plugin, k, parentKey), "should validate as short");
46 2 : succeed_if (keyGetMeta (parentKey, "error/number") == NULL, "shouldn't find error number");
47 :
48 2 : keySetString (k, "a");
49 2 : succeed_if (!conversation.f (plugin, k, parentKey), "shouldn't validate as short");
50 2 : succeed_if (keyGetMeta (parentKey, "error/number") != NULL, "should find error number");
51 :
52 2 : keyDel (k);
53 :
54 2 : ksDel (ks);
55 2 : keyDel (parentKey);
56 :
57 2 : PLUGIN_CLOSE ();
58 2 : }
59 :
60 2 : void test_short (void)
61 : {
62 2 : Key * k = keyNew ("user/anything", KEY_VALUE, "0", KEY_META, "check/type", "short", KEY_END);
63 4 : succeed_if (checkType (k), "should check successfully");
64 2 : keySetString (k, "-32768");
65 4 : succeed_if (checkType (k), "should check successfully");
66 2 : keySetString (k, "-32769");
67 4 : succeed_if (!checkType (k), "should fail (number too low)");
68 2 : keySetString (k, "32768");
69 4 : succeed_if (!checkType (k), "should fail (number too high)");
70 2 : keySetString (k, "32767");
71 4 : succeed_if (checkType (k), "should check successfully");
72 2 : keySetString (k, "x");
73 4 : succeed_if (!checkType (k), "should fail");
74 2 : keySetString (k, "");
75 4 : succeed_if (!checkType (k), "should fail");
76 2 : keySetString (k, "32767x");
77 4 : succeed_if (!checkType (k), "should fail because of garbage afterwards");
78 2 : keySetString (k, "32767 x");
79 4 : succeed_if (!checkType (k), "should fail because of garbage afterwards");
80 :
81 2 : keyDel (k);
82 2 : }
83 :
84 2 : void test_unsignedShort (void)
85 : {
86 2 : Key * k = keyNew ("user/anything", KEY_VALUE, "0", KEY_META, "check/type", "unsigned_short", KEY_END);
87 4 : succeed_if (checkType (k), "should check successfully");
88 2 : keySetString (k, "0");
89 4 : succeed_if (checkType (k), "should check successfully");
90 2 : keySetString (k, "-1");
91 4 : succeed_if (!checkType (k), "should fail (number too low)");
92 2 : keySetString (k, "65536");
93 4 : succeed_if (!checkType (k), "should fail (number too high)");
94 2 : keySetString (k, "65535");
95 4 : succeed_if (checkType (k), "should check successfully");
96 2 : keySetString (k, "x");
97 4 : succeed_if (!checkType (k), "should fail");
98 2 : keySetString (k, "");
99 4 : succeed_if (!checkType (k), "should fail");
100 2 : keySetString (k, "32767x");
101 4 : succeed_if (!checkType (k), "should fail because of garbage afterwards");
102 2 : keySetString (k, "32767 x");
103 4 : succeed_if (!checkType (k), "should fail because of garbage afterwards");
104 :
105 2 : keyDel (k);
106 2 : }
107 :
108 2 : void test_float (void)
109 : {
110 2 : Key * k = keyNew ("user/anything", KEY_VALUE, "0", KEY_META, "check/type", "float", KEY_END);
111 4 : succeed_if (checkType (k), "should check successfully");
112 2 : keySetString (k, "0");
113 4 : succeed_if (checkType (k), "should check successfully");
114 2 : keySetString (k, "1.5");
115 4 : succeed_if (checkType (k), "should check successfully");
116 2 : keySetString (k, "1,5");
117 4 : succeed_if (!checkType (k), "should fail");
118 2 : keySetString (k, "1233322.5");
119 4 : succeed_if (checkType (k), "should check successfully");
120 2 : keySetString (k, "123233223322333322.5");
121 4 : succeed_if (checkType (k), "should check successfully");
122 2 : keySetString (k, "123233223322333322.0001");
123 4 : succeed_if (checkType (k), "should check successfully");
124 2 : keySetString (k, "x");
125 4 : succeed_if (!checkType (k), "should fail");
126 2 : keySetString (k, "");
127 4 : succeed_if (!checkType (k), "should fail");
128 2 : keySetString (k, ".");
129 4 : succeed_if (!checkType (k), "should fail");
130 2 : keySetString (k, "1.");
131 4 : succeed_if (checkType (k), "should check successfully");
132 2 : keySetString (k, ".5");
133 4 : succeed_if (checkType (k), "should check successfully");
134 :
135 2 : keyDel (k);
136 2 : }
137 :
138 2 : void test_bool (void)
139 : {
140 2 : Key * k = keyNew ("user/anything", KEY_VALUE, "0", KEY_META, "check/type", "boolean", KEY_END);
141 4 : succeed_if (checkType (k), "should check successfully");
142 2 : keySetString (k, "1");
143 4 : succeed_if (checkType (k), "should check successfully");
144 2 : keySetString (k, ".");
145 4 : succeed_if (!checkType (k), "should fail");
146 2 : keySetString (k, "true");
147 4 : succeed_if (!checkType (k), "should fail");
148 2 : keySetString (k, "false");
149 4 : succeed_if (!checkType (k), "should fail");
150 :
151 2 : keyDel (k);
152 2 : }
153 :
154 2 : void test_none (void)
155 : {
156 2 : Key * k = keyNew ("user/anything", KEY_VALUE, "anything", KEY_END);
157 4 : succeed_if (checkType (k), "should check successfully");
158 2 : keySetString (k, "1");
159 4 : succeed_if (checkType (k), "should check successfully");
160 2 : keySetString (k, "any other");
161 4 : succeed_if (checkType (k), "should check successfully");
162 2 : keySetString (k, "do not care");
163 4 : succeed_if (checkType (k), "should check successfully");
164 2 : keySetString (k, "");
165 4 : succeed_if (checkType (k), "should check successfully");
166 :
167 2 : keyDel (k);
168 2 : }
169 :
170 2 : void test_char (void)
171 : {
172 2 : Key * k = keyNew ("user/anything", KEY_VALUE, "a", KEY_META, "check/type", "char", KEY_END);
173 4 : succeed_if (checkType (k), "a should check successfully as char");
174 2 : keySetString (k, "b");
175 4 : succeed_if (checkType (k), "b should check successfully as char");
176 2 : keySetString (k, " ");
177 4 : succeed_if (checkType (k), "space should check successfully as char");
178 2 : keySetString (k, "");
179 4 : succeed_if (!checkType (k), "empty string should not check successfully as char");
180 2 : keySetString (k, "ab");
181 4 : succeed_if (!checkType (k), "two chars should not check successfully as char");
182 :
183 2 : char x[2] = { 0, 0 };
184 2 : char msg[] = "\\xXX should check successfully as char";
185 2 : const char hex[] = "0123456789abcdef";
186 510 : for (int i = 1; i < 255; ++i)
187 : {
188 508 : x[0] = (char) i;
189 508 : keySetString (k, x);
190 508 : msg[2] = hex[i / 16];
191 508 : msg[3] = hex[i % 16];
192 1016 : succeed_if (checkType (k), msg);
193 : }
194 :
195 :
196 2 : keyDel (k);
197 2 : }
198 :
199 2 : void test_wchar (void)
200 : {
201 2 : Key * k = keyNew ("user/anything", KEY_VALUE, "a", KEY_META, "check/type", "wchar", KEY_END);
202 2 : keySetString (k, "");
203 4 : succeed_if (!checkType (k), "empty string should not check successfully as wchar");
204 :
205 2 : char * s = elektraCalloc (3 * MB_CUR_MAX + 1);
206 2 : wcstombs (s, L"ab", 3 * MB_CUR_MAX);
207 2 : keySetString (k, s);
208 4 : succeed_if (!checkType (k), "two wchars should not check successfully as wchar");
209 :
210 : size_t max = WCHAR_MAX;
211 : if (max > 0xFFFF)
212 : {
213 : max = 0xFFFF;
214 : }
215 :
216 : size_t c = 0;
217 131068 : for (size_t i = 1; i < max; ++i)
218 : {
219 131068 : size_t ret = wcstombs (s, (wchar_t[]){ (wchar_t) i, 0 }, 3 * MB_CUR_MAX);
220 131068 : if (ret > 0)
221 : {
222 131068 : c++;
223 131068 : keySetString (k, s);
224 131068 : nbTest++;
225 131068 : if (!checkType (k))
226 : {
227 0 : yield_error ("the following should check successfully as wchar:");
228 0 : printf ("0x%zx\n", i);
229 : }
230 : }
231 131068 : int x ELEKTRA_UNUSED = wctomb (NULL, 0);
232 : }
233 :
234 2 : elektraFree (s);
235 :
236 2 : keyDel (k);
237 2 : }
238 :
239 :
240 2 : void test_octet (void)
241 : {
242 2 : Key * k = keyNew ("user/anything", KEY_VALUE, "a", KEY_META, "check/type", "octet", KEY_END);
243 4 : succeed_if (checkType (k), "a should check successfully as octet");
244 2 : keySetString (k, "b");
245 4 : succeed_if (checkType (k), "b should check successfully as octet");
246 2 : keySetString (k, " ");
247 4 : succeed_if (checkType (k), "space should check successfully as octet");
248 2 : keySetString (k, "");
249 4 : succeed_if (!checkType (k), "empty string should not check successfully as octet");
250 2 : keySetString (k, "ab");
251 4 : succeed_if (!checkType (k), "two chars should not check successfully as octet");
252 :
253 2 : char x[2] = { 0, 0 };
254 2 : char msg[] = "\\xXX should check successfully as octet";
255 2 : const char hex[] = "0123456789abcdef";
256 510 : for (int i = 1; i < 255; ++i)
257 : {
258 508 : x[0] = (char) i;
259 508 : keySetString (k, x);
260 508 : msg[2] = hex[i / 16];
261 508 : msg[3] = hex[i % 16];
262 1016 : succeed_if (checkType (k), msg);
263 : }
264 :
265 2 : keyDel (k);
266 2 : }
267 :
268 2 : void test_string (void)
269 : {
270 2 : Key * k = keyNew ("user/anything", KEY_VALUE, "a", KEY_META, "check/type", "string", KEY_END);
271 2 : keySetString (k, "");
272 4 : succeed_if (!checkType (k), "empty string should not check successfully as string");
273 :
274 2 : keySetString (k, "ab");
275 4 : succeed_if (checkType (k), "\"ab\" should check successfully as string");
276 :
277 2 : keySetString (k, "monkey circus");
278 4 : succeed_if (checkType (k), "\"monkey circus\" should check successfully as string");
279 :
280 2 : keySetString (k, "日本");
281 4 : succeed_if (checkType (k), "\"日本\" should check successfully as string");
282 :
283 2 : keySetString (k, "😂 😄 😃 😀 😊 😉 😍 😘 😚 😗 😙 😜 😝 😛 😳");
284 4 : succeed_if (checkType (k), "emoji sequence should check successfully as string");
285 :
286 2 : keyDel (k);
287 2 : }
288 :
289 2 : void test_wstring (void)
290 2 : {
291 2 : Key * k = keyNew ("user/anything", KEY_VALUE, "a", KEY_META, "check/type", "wstring", KEY_END);
292 2 : keySetString (k, "");
293 4 : succeed_if (!checkType (k), "empty string should not check successfully as wstring");
294 :
295 2 : char s[255 * MB_CUR_MAX];
296 2 : wcstombs (s, L"ab", sizeof (s));
297 2 : keySetString (k, s);
298 4 : succeed_if (checkType (k), "two wchars should check successfully as wstring");
299 :
300 2 : wcstombs (s, L"monkey circus", sizeof (s));
301 2 : keySetString (k, s);
302 4 : succeed_if (checkType (k), "L\"monkey circus\" should check successfully as wstring");
303 :
304 2 : wcstombs (s, L"日本", sizeof (s));
305 2 : keySetString (k, s);
306 4 : succeed_if (checkType (k), "\"日本\" should check successfully as wstring");
307 :
308 2 : wcstombs (s, L"😂 😄 😃 😀 😊 😉 😍 😘 😚 😗 😙 😜 😝 😛 😳", sizeof (s));
309 2 : keySetString (k, s);
310 4 : succeed_if (checkType (k), "emoji sequence should check successfully as wstring");
311 :
312 2 : keyDel (k);
313 2 : }
314 :
315 :
316 2 : static void test_enum (void)
317 : {
318 2 : Key * parentKey = keyNew ("user/tests/type/enum", KEY_VALUE, "", KEY_END);
319 2 : Key * k1 = keyNew ("user/tests/type/enum/valid1", KEY_VALUE, "LOW", KEY_META, "check/type", "enum", KEY_META, "check/enum", "#1",
320 : KEY_META, "check/enum/#0", "LOW", KEY_META, "check/enum/#1", "MIDDLE", KEY_END);
321 2 : Key * k2 =
322 : keyNew ("user/tests/type/enum/valid2", KEY_VALUE, "MIDDLE", KEY_META, "check/type", "enum", KEY_META, "check/enum", "#2",
323 : KEY_META, "check/enum/#0", "LOW", KEY_META, "check/enum/#1", "MIDDLE", KEY_META, "check/enum/#2", "HIGH", KEY_END);
324 2 : Key * k3 = keyNew ("user/tests/type/enum/valid3", KEY_VALUE, "HIGH", KEY_META, "check/type", "enum", KEY_META, "check/enum", "#2",
325 : KEY_META, "check/enum/#0", "LOW", KEY_META, "check/enum/#2", "HIGH", KEY_END);
326 :
327 2 : KeySet * conf = ksNew (0, KS_END);
328 2 : KeySet * ks = ksNew (3, k1, k2, k3, KS_END);
329 2 : PLUGIN_OPEN ("type");
330 :
331 2 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "kdbGet failed");
332 2 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "kdbSet failed");
333 :
334 2 : ksDel (ks);
335 2 : keyDel (parentKey);
336 2 : PLUGIN_CLOSE ();
337 2 : }
338 :
339 2 : static void test_enumMulti (void)
340 : {
341 2 : Key * parentKey = keyNew ("user/tests/type/enum", KEY_VALUE, "", KEY_END);
342 2 : Key * k1 = keyNew ("user/tests/type/enum/valid1", KEY_VALUE, "LOW", KEY_META, "check/enum/delimiter", "_", KEY_META, "check/type",
343 : "enum", KEY_META, "check/enum", "#1", KEY_META, "check/enum/#0", "LOW", KEY_META, "check/enum/#1", "MIDDLE",
344 : KEY_END);
345 2 : Key * k2 = keyNew ("user/tests/type/enum/valid2", KEY_VALUE, "LOW_MIDDLE", KEY_META, "check/enum/delimiter", "_", KEY_META,
346 : "check/type", "enum", KEY_META, "check/enum", "#1", KEY_META, "check/enum/#0", "LOW", KEY_META, "check/enum/#1",
347 : "MIDDLE", KEY_END);
348 2 : Key * k3 = keyNew ("user/tests/type/enum/invalid1", KEY_VALUE, "HIGH", KEY_META, "check/enum/delimiter", "_", KEY_META,
349 : "check/type", "enum", KEY_META, "check/enum", "#1", KEY_META, "check/enum/#0", "LOW", KEY_META, "check/enum/#1",
350 : "MIDDLE", KEY_END);
351 2 : Key * k4 = keyNew ("user/tests/type/enum/invalid2", KEY_VALUE, "MIDDLE_FAIL", KEY_META, "check/enum/delimiter", "_", KEY_META,
352 : "check/type", "enum", KEY_META, "check/enum", "#1", KEY_META, "check/enum/#0", "LOW", KEY_META, "check/enum/#1",
353 : "MIDDLE", KEY_END);
354 2 : KeySet * conf = ksNew (0, KS_END);
355 2 : KeySet * ks = ksNew (3, k1, k2, KS_END);
356 2 : PLUGIN_OPEN ("type");
357 :
358 2 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "kdbGet failed");
359 2 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "kdbSet failed");
360 2 : ksDel (ks);
361 :
362 2 : ks = ksNew (20, KS_END);
363 2 : ksAppendKey (ks, k3);
364 2 : ksRewind (ks);
365 2 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_ERROR, "kdbGet should have failed");
366 2 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_ERROR, "kdbSet should have failed");
367 2 : ksDel (ks);
368 :
369 2 : ks = ksNew (20, KS_END);
370 2 : ksAppendKey (ks, k4);
371 2 : ksRewind (ks);
372 2 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_ERROR, "kdbGet should have failed");
373 2 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_ERROR, "kdbSet should have failed");
374 2 : ksDel (ks);
375 :
376 2 : keyDel (parentKey);
377 2 : PLUGIN_CLOSE ();
378 2 : }
379 :
380 2 : static void test_enumNormalize (void)
381 : {
382 2 : Key * parentKey = keyNew ("user/tests/type/enum", KEY_VALUE, "", KEY_END);
383 2 : Key * k1 = keyNew ("user/tests/type/enum/valid1", KEY_VALUE, "LOW", KEY_META, "check/type", "enum", KEY_META, "check/enum", "#1",
384 : KEY_META, "check/enum/#0", "LOW", KEY_META, "check/enum/#1", "MIDDLE", KEY_META, "check/enum/normalize", "1",
385 : KEY_END);
386 2 : Key * k2 = keyNew ("user/tests/type/enum/valid2", KEY_VALUE, "MIDDLE", KEY_META, "check/type", "enum", KEY_META, "check/enum", "#2",
387 : KEY_META, "check/enum/#0", "LOW", KEY_META, "check/enum/#1", "MIDDLE", KEY_META, "check/enum/#2", "HIGH",
388 : KEY_META, "check/enum/normalize", "1", KEY_END);
389 2 : Key * k3 = keyNew ("user/tests/type/enum/valid3", KEY_VALUE, "HIGH", KEY_META, "check/type", "enum", KEY_META, "check/enum", "#2",
390 : KEY_META, "check/enum/#0", "LOW", KEY_META, "check/enum/#2", "HIGH", KEY_META, "check/enum/normalize", "1",
391 : KEY_END);
392 :
393 2 : KeySet * conf = ksNew (0, KS_END);
394 2 : KeySet * ks = ksNew (3, k1, k2, k3, KS_END);
395 2 : PLUGIN_OPEN ("type");
396 :
397 2 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "kdbGet failed");
398 2 : succeed_if_same_string (keyString (k1), "0");
399 2 : succeed_if_same_string (keyString (k2), "1");
400 2 : succeed_if_same_string (keyString (k3), "2");
401 :
402 2 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "kdbSet failed");
403 2 : succeed_if_same_string (keyString (k1), "LOW");
404 2 : succeed_if_same_string (keyString (k2), "MIDDLE");
405 2 : succeed_if_same_string (keyString (k3), "HIGH");
406 :
407 2 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "kdbGet failed");
408 2 : succeed_if_same_string (keyString (k1), "0");
409 2 : succeed_if_same_string (keyString (k2), "1");
410 2 : succeed_if_same_string (keyString (k3), "2");
411 :
412 2 : keySetString (k1, "0");
413 2 : keySetString (k2, "LOW");
414 2 : keySetString (k3, "0");
415 :
416 2 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "kdbSet failed");
417 2 : succeed_if_same_string (keyString (k1), "LOW");
418 2 : succeed_if_same_string (keyString (k2), "LOW");
419 2 : succeed_if_same_string (keyString (k3), "LOW");
420 :
421 2 : ksDel (ks);
422 2 : keyDel (parentKey);
423 2 : PLUGIN_CLOSE ();
424 2 : }
425 :
426 2 : static void test_enumMultiNormalize (void)
427 : {
428 2 : Key * parentKey = keyNew ("user/tests/type/enum", KEY_VALUE, "", KEY_END);
429 2 : Key * k1 = keyNew ("user/tests/type/enum/valid1", KEY_VALUE, "none", KEY_META, "check/enum/delimiter", "_", KEY_META, "check/type",
430 : "enum", KEY_META, "check/enum", "#2", KEY_META, "check/enum/#0", "none", KEY_META, "check/enum/#1", "low",
431 : KEY_META, "check/enum/#2", "high", KEY_META, "check/enum/normalize", "1", KEY_END);
432 2 : Key * k2 = keyNew ("user/tests/type/enum/valid2", KEY_VALUE, "low", KEY_META, "check/enum/delimiter", "_", KEY_META, "check/type",
433 : "enum", KEY_META, "check/enum", "#2", KEY_META, "check/enum/#0", "none", KEY_META, "check/enum/#1", "low",
434 : KEY_META, "check/enum/#2", "high", KEY_META, "check/enum/normalize", "1", KEY_END);
435 2 : Key * k3 = keyNew ("user/tests/type/enum/valid3", KEY_VALUE, "high", KEY_META, "check/enum/delimiter", "_", KEY_META, "check/type",
436 : "enum", KEY_META, "check/enum", "#2", KEY_META, "check/enum/#0", "none", KEY_META, "check/enum/#1", "low",
437 : KEY_META, "check/enum/#2", "high", KEY_META, "check/enum/normalize", "1", KEY_END);
438 2 : Key * k4 = keyNew ("user/tests/type/enum/valid4", KEY_VALUE, "high_low", KEY_META, "check/enum/delimiter", "_", KEY_META,
439 : "check/type", "enum", KEY_META, "check/enum", "#2", KEY_META, "check/enum/#0", "none", KEY_META, "check/enum/#1",
440 : "low", KEY_META, "check/enum/#2", "high", KEY_META, "check/enum/normalize", "1", KEY_END);
441 2 : Key * k5 = keyNew ("user/tests/type/enum/valid5", KEY_VALUE, "none_low", KEY_META, "check/enum/delimiter", "_", KEY_META,
442 : "check/type", "enum", KEY_META, "check/enum", "#2", KEY_META, "check/enum/#0", "none", KEY_META, "check/enum/#1",
443 : "low", KEY_META, "check/enum/#2", "high", KEY_META, "check/enum/normalize", "1", KEY_END);
444 2 : Key * k6 = keyNew ("user/tests/type/enum/valid6", KEY_VALUE, "low_low_high", KEY_META, "check/enum/delimiter", "_", KEY_META,
445 : "check/type", "enum", KEY_META, "check/enum", "#2", KEY_META, "check/enum/#0", "none", KEY_META, "check/enum/#1",
446 : "low", KEY_META, "check/enum/#2", "high", KEY_META, "check/enum/normalize", "1", KEY_END);
447 2 : Key * k7 = keyNew ("user/tests/type/enum/valid7", KEY_VALUE, "low_high", KEY_META, "check/enum/delimiter", "_", KEY_META,
448 : "check/type", "enum", KEY_META, "check/enum", "#2", KEY_META, "check/enum/#0", "none", KEY_META, "check/enum/#1",
449 : "low", KEY_META, "check/enum/#2", "high", KEY_META, "check/enum/normalize", "1", KEY_END);
450 2 : KeySet * conf = ksNew (0, KS_END);
451 2 : KeySet * ks = ksNew (7, k1, k2, k3, k4, k5, k6, k7, KS_END);
452 2 : PLUGIN_OPEN ("type");
453 :
454 2 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "kdbGet failed");
455 2 : succeed_if_same_string (keyString (k1), "0");
456 2 : succeed_if_same_string (keyString (k2), "1");
457 2 : succeed_if_same_string (keyString (k3), "2");
458 2 : succeed_if_same_string (keyString (k4), "3");
459 2 : succeed_if_same_string (keyString (k5), "1");
460 2 : succeed_if_same_string (keyString (k6), "3");
461 2 : succeed_if_same_string (keyString (k7), "3");
462 :
463 2 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "kdbSet failed");
464 2 : succeed_if_same_string (keyString (k1), "none");
465 2 : succeed_if_same_string (keyString (k2), "low");
466 2 : succeed_if_same_string (keyString (k3), "high");
467 2 : succeed_if_same_string (keyString (k4), "high_low");
468 2 : succeed_if_same_string (keyString (k5), "none_low");
469 2 : succeed_if_same_string (keyString (k6), "low_low_high");
470 2 : succeed_if_same_string (keyString (k7), "low_high");
471 :
472 2 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "kdbGet failed");
473 2 : succeed_if_same_string (keyString (k1), "0");
474 2 : succeed_if_same_string (keyString (k2), "1");
475 2 : succeed_if_same_string (keyString (k3), "2");
476 2 : succeed_if_same_string (keyString (k4), "3");
477 2 : succeed_if_same_string (keyString (k5), "1");
478 2 : succeed_if_same_string (keyString (k6), "3");
479 2 : succeed_if_same_string (keyString (k7), "3");
480 :
481 2 : keySetString (k1, "3");
482 2 : keySetString (k2, "0");
483 2 : keySetString (k3, "1");
484 :
485 2 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "kdbSet failed");
486 2 : succeed_if_same_string (keyString (k1), "high_low");
487 2 : succeed_if_same_string (keyString (k2), "none");
488 2 : succeed_if_same_string (keyString (k3), "low");
489 2 : succeed_if_same_string (keyString (k4), "high_low");
490 2 : succeed_if_same_string (keyString (k5), "none_low");
491 2 : succeed_if_same_string (keyString (k6), "low_low_high");
492 2 : succeed_if_same_string (keyString (k7), "low_high");
493 :
494 :
495 2 : ksDel (ks);
496 2 : keyDel (parentKey);
497 2 : PLUGIN_CLOSE ();
498 2 : }
499 :
500 4 : static void test_booleanDefault (const char * type)
501 : {
502 4 : Key * parentKey = keyNew ("user/tests/type", KEY_END);
503 4 : KeySet * conf = ksNew (0, KS_END);
504 4 : PLUGIN_OPEN ("type");
505 4 : KeySet * ks = ksNew (30, keyNew ("user/tests/type/t1", KEY_VALUE, "true", KEY_META, type, "boolean", KEY_END),
506 : keyNew ("user/tests/type/t2", KEY_VALUE, "tRUe", KEY_META, type, "boolean", KEY_END),
507 : keyNew ("user/tests/type/f1", KEY_VALUE, "false", KEY_META, type, "boolean", KEY_END),
508 : keyNew ("user/tests/type/f2", KEY_VALUE, "falsE", KEY_META, type, "boolean", KEY_END),
509 : keyNew ("user/tests/type/off", KEY_VALUE, "off", KEY_META, type, "boolean", KEY_END),
510 : keyNew ("user/tests/type/on", KEY_VALUE, "on", KEY_META, type, "boolean", KEY_END), KS_END);
511 4 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
512 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "1");
513 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t2", 0)), "1");
514 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/f1", 0)), "0");
515 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/f2", 0)), "0");
516 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/on", 0)), "1");
517 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/off", 0)), "0");
518 :
519 4 : ksDel (ks);
520 4 : keyDel (parentKey);
521 :
522 4 : PLUGIN_CLOSE ();
523 4 : }
524 :
525 4 : static void test_booleanDefaultRestore (const char * type)
526 : {
527 4 : Key * parentKey = keyNew ("user/tests/type", KEY_END);
528 4 : KeySet * conf = ksNew (0, KS_END);
529 4 : PLUGIN_OPEN ("type");
530 4 : KeySet * ks = ksNew (30, keyNew ("user/tests/type/a0", KEY_VALUE, "x", KEY_END),
531 : keyNew ("user/tests/type/t1", KEY_VALUE, "true", KEY_META, type, "boolean", KEY_END),
532 : keyNew ("user/tests/type/t2", KEY_VALUE, "tRUe", KEY_META, type, "boolean", KEY_END),
533 : keyNew ("user/tests/type/f1", KEY_VALUE, "false", KEY_META, type, "boolean", KEY_END),
534 : keyNew ("user/tests/type/f2", KEY_VALUE, "falsE", KEY_META, type, "boolean", KEY_END),
535 : keyNew ("user/tests/type/off", KEY_VALUE, "off", KEY_META, type, "boolean", KEY_END),
536 : keyNew ("user/tests/type/on", KEY_VALUE, "on", KEY_META, type, "boolean", KEY_END), KS_END);
537 4 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
538 4 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
539 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t2", 0)), "tRUe");
540 4 : ksDel (ks);
541 4 : keyDel (parentKey);
542 :
543 4 : PLUGIN_CLOSE ();
544 4 : }
545 :
546 4 : static void test_booleanDefaultError (const char * type)
547 : {
548 4 : Key * parentKey = keyNew ("user/tests/type", KEY_END);
549 4 : KeySet * conf = ksNew (0, KS_END);
550 4 : PLUGIN_OPEN ("type");
551 4 : KeySet * ks = ksNew (30, keyNew ("user/tests/type/t1", KEY_VALUE, "true", KEY_META, type, "boolean", KEY_END),
552 : keyNew ("user/tests/type/t2", KEY_VALUE, "tRUe", KEY_META, type, "boolean", KEY_END),
553 : keyNew ("user/tests/type/nt", KEY_VALUE, "i'm not true", KEY_META, type, "boolean", KEY_END),
554 : keyNew ("user/tests/type/f1", KEY_VALUE, "false", KEY_META, type, "boolean", KEY_END),
555 : keyNew ("user/tests/type/f2", KEY_VALUE, "falsE", KEY_META, type, "boolean", KEY_END),
556 : keyNew ("user/tests/type/nf", KEY_VALUE, "i'm not false", KEY_META, type, "boolean", KEY_END),
557 : keyNew ("user/tests/type/off", KEY_VALUE, "off", KEY_META, type, "boolean", KEY_END),
558 : keyNew ("user/tests/type/on", KEY_VALUE, "on", KEY_META, type, "boolean", KEY_END), KS_END);
559 4 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_ERROR, "call to kdbGet was not successful");
560 4 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_ERROR, "call to kdbSet was not successful");
561 4 : ksDel (ks);
562 4 : keyDel (parentKey);
563 :
564 4 : PLUGIN_CLOSE ();
565 4 : }
566 :
567 4 : static void test_booleanUserValue (const char * type)
568 : {
569 4 : Key * parentKey = keyNew ("user/tests/type", KEY_END);
570 4 : KeySet * conf = ksNew (10, keyNew ("user/booleans", KEY_VALUE, "#1", KEY_END),
571 : keyNew ("user/booleans/#0/true", KEY_VALUE, "strangeTrueValue", KEY_END),
572 : keyNew ("user/booleans/#0/false", KEY_VALUE, "0", KEY_END),
573 : keyNew ("user/booleans/#1/true", KEY_VALUE, "1", KEY_END),
574 : keyNew ("user/booleans/#1/false", KEY_VALUE, "strangeFalseValue", KEY_END), KS_END);
575 4 : PLUGIN_OPEN ("type");
576 4 : KeySet * ks = ksNew (30, keyNew ("user/tests/type/t1", KEY_VALUE, "strangeTrueValue", KEY_META, type, "boolean", KEY_END),
577 : keyNew ("user/tests/type/f1", KEY_VALUE, "strangeFalseValue", KEY_META, type, "boolean", KEY_END), KS_END);
578 4 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
579 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "1");
580 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/f1", 0)), "0");
581 4 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
582 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "strangeTrueValue");
583 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/f1", 0)), "strangeFalseValue");
584 :
585 4 : ksDel (ks);
586 4 : keyDel (parentKey);
587 :
588 4 : PLUGIN_CLOSE ();
589 4 : }
590 :
591 4 : static void test_booleanUserValueWeird (const char * type)
592 : {
593 4 : Key * parentKey = keyNew ("user/tests/type", KEY_END);
594 4 : KeySet * conf = ksNew (10, keyNew ("user/booleans", KEY_VALUE, "#3", KEY_END),
595 : keyNew ("user/booleans/#0/true", KEY_VALUE, "strangeTrueValue", KEY_END),
596 : keyNew ("user/booleans/#0/false", KEY_VALUE, "0", KEY_END),
597 : keyNew ("user/booleans/#1/true", KEY_VALUE, "1", KEY_END),
598 : keyNew ("user/booleans/#1/false", KEY_VALUE, "strangeFalseValue", KEY_END), KS_END);
599 4 : PLUGIN_OPEN ("type");
600 4 : KeySet * ks = ksNew (30, keyNew ("user/tests/type/t1", KEY_VALUE, "strangeTrueValue", KEY_META, type, "boolean", KEY_END),
601 : keyNew ("user/tests/type/f1", KEY_VALUE, "strangeFalseValue", KEY_META, type, "boolean", KEY_END), KS_END);
602 4 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
603 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "1");
604 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/f1", 0)), "0");
605 4 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
606 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "strangeTrueValue");
607 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/f1", 0)), "strangeFalseValue");
608 :
609 4 : ksDel (ks);
610 4 : keyDel (parentKey);
611 :
612 4 : PLUGIN_CLOSE ();
613 4 : }
614 :
615 2 : static void test_booleanUserValueError (void)
616 : {
617 2 : Key * parentKey = keyNew ("user/tests/type", KEY_END);
618 2 : KeySet * conf = ksNew (10, keyNew ("user/booleans", KEY_VALUE, "#1", KEY_END),
619 : keyNew ("user/booleans/#0/true", KEY_VALUE, "strangeTrueValue", KEY_END),
620 : keyNew ("user/booleans/#1/true", KEY_VALUE, "1", KEY_END),
621 : keyNew ("user/booleans/#1/false", KEY_VALUE, "strangeFalseValue", KEY_END), KS_END);
622 2 : KeySet * modules = ksNew (0, KS_END);
623 2 : elektraModulesInit (modules, 0);
624 2 : Key * errorKey = keyNew ("", KEY_END);
625 2 : Plugin * plugin = elektraPluginOpen ("type", modules, conf, errorKey);
626 2 : succeed_if (plugin == NULL, "plugin open should have failed");
627 2 : succeed_if (keyGetMeta (errorKey, "error") != NULL, "no error found after failed open");
628 2 : succeed_if_same_string (keyString (keyGetMeta (errorKey, "error/reason")),
629 : "You must set both true and false for a boolean pair (config key: '/booleans/#0')");
630 2 : keyDel (errorKey);
631 2 : keyDel (parentKey);
632 :
633 2 : PLUGIN_CLOSE ();
634 2 : }
635 :
636 4 : static void test_booleanChangeValue (const char * type)
637 : {
638 4 : Key * parentKey = keyNew ("user/tests/type", KEY_END);
639 4 : KeySet * conf = ksNew (0, KS_END);
640 4 : PLUGIN_OPEN ("type");
641 4 : KeySet * ks = ksNew (30, keyNew ("user/tests/type/t1", KEY_VALUE, "0", KEY_META, type, "boolean", KEY_END), KS_END);
642 4 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
643 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "0");
644 :
645 4 : keySetString (ksLookupByName (ks, "user/tests/type/t1", 0), "yes");
646 :
647 4 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
648 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "yes");
649 :
650 4 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
651 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "1");
652 :
653 4 : keySetString (ksLookupByName (ks, "user/tests/type/t1", 0), "1");
654 :
655 4 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
656 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "1");
657 :
658 4 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
659 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "1");
660 :
661 4 : ksDel (ks);
662 4 : keyDel (parentKey);
663 :
664 4 : PLUGIN_CLOSE ();
665 4 : }
666 :
667 4 : static void test_booleanOverride (const char * type)
668 : {
669 4 : Key * parentKey = keyNew ("user/tests/type", KEY_END);
670 4 : KeySet * conf = ksNew (1, keyNew ("user/boolean/restoreas", KEY_VALUE, "#0", KEY_END), KS_END);
671 4 : PLUGIN_OPEN ("type");
672 4 : Key * k1 = keyNew ("user/tests/type/t1", KEY_VALUE, "t", KEY_META, type, "boolean", KEY_META, "check/boolean/true", "t", KEY_META,
673 : "check/boolean/false", "f", KEY_END);
674 4 : KeySet * ks = ksNew (30, k1, KS_END);
675 4 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
676 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "1");
677 4 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
678 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "t");
679 :
680 4 : keySetString (k1, "1");
681 4 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
682 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "1");
683 4 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
684 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "t");
685 :
686 4 : keySetString (k1, "t");
687 4 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
688 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "1");
689 4 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
690 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "t");
691 :
692 4 : ksDel (ks);
693 4 : keyDel (parentKey);
694 :
695 4 : PLUGIN_CLOSE ();
696 4 : }
697 :
698 20 : static void test_booleanRestoreAsDefault (const char * type, const char * restore, const char * restoreTrue, const char * restoreFalse)
699 : {
700 20 : Key * parentKey = keyNew ("user/tests/type", KEY_END);
701 20 : KeySet * conf = ksNew (1, keyNew ("user/boolean/restoreas", KEY_VALUE, restore, KEY_END), KS_END);
702 20 : PLUGIN_OPEN ("type");
703 20 : Key * k1 = keyNew ("user/tests/type/t1", KEY_VALUE, "enabled", KEY_META, type, "boolean", KEY_END);
704 20 : KeySet * ks = ksNew (30, k1, KS_END);
705 20 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
706 20 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "1");
707 20 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
708 20 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), restoreTrue);
709 :
710 20 : keySetString (k1, "1");
711 20 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
712 20 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "1");
713 20 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
714 20 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), restoreTrue);
715 :
716 20 : keySetString (k1, "false");
717 20 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
718 20 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "0");
719 20 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
720 20 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), restoreFalse);
721 :
722 20 : keySetString (k1, "0");
723 20 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
724 20 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "0");
725 20 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
726 20 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), restoreFalse);
727 :
728 20 : ksDel (ks);
729 20 : keyDel (parentKey);
730 :
731 20 : PLUGIN_CLOSE ();
732 20 : }
733 :
734 4 : static void test_booleanRestoreAs (const char * type)
735 : {
736 4 : Key * parentKey = keyNew ("user/tests/type", KEY_END);
737 4 : KeySet * conf =
738 4 : ksNew (4, keyNew ("user/boolean/restoreas", KEY_VALUE, "#0", KEY_END), keyNew ("user/booleans", KEY_VALUE, "#0", KEY_END),
739 : keyNew ("user/booleans/#0/true", KEY_VALUE, "t", KEY_END),
740 : keyNew ("user/booleans/#0/false", KEY_VALUE, "f", KEY_END), KS_END);
741 4 : PLUGIN_OPEN ("type");
742 4 : Key * k1 = keyNew ("user/tests/type/t1", KEY_VALUE, "t", KEY_META, type, "boolean", KEY_END);
743 4 : KeySet * ks = ksNew (30, k1, KS_END);
744 4 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
745 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "1");
746 4 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
747 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "t");
748 :
749 4 : keySetString (k1, "1");
750 4 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
751 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "1");
752 4 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
753 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "t");
754 :
755 4 : keySetString (k1, "f");
756 4 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
757 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "0");
758 4 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
759 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "f");
760 :
761 4 : keySetString (k1, "0");
762 4 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
763 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "0");
764 4 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
765 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "f");
766 :
767 4 : ksDel (ks);
768 4 : keyDel (parentKey);
769 :
770 4 : PLUGIN_CLOSE ();
771 4 : }
772 :
773 4 : static void test_booleanRestoreDisabled (const char * type)
774 : {
775 4 : Key * parentKey = keyNew ("user/tests/type", KEY_END);
776 4 : KeySet * conf = ksNew (1, keyNew ("user/boolean/restoreas", KEY_VALUE, "none", KEY_END), KS_END);
777 4 : PLUGIN_OPEN ("type");
778 4 : Key * k1 = keyNew ("user/tests/type/t1", KEY_VALUE, "true", KEY_META, type, "boolean", KEY_END);
779 4 : KeySet * ks = ksNew (30, k1, KS_END);
780 4 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
781 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "1");
782 4 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
783 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "1");
784 :
785 4 : keySetString (k1, "1");
786 4 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
787 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "1");
788 4 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
789 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "1");
790 :
791 4 : keySetString (k1, "false");
792 4 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
793 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "0");
794 4 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
795 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "0");
796 :
797 4 : keySetString (k1, "0");
798 4 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
799 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "0");
800 4 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
801 4 : succeed_if_same_string (keyString (ksLookupByName (ks, "user/tests/type/t1", 0)), "0");
802 :
803 4 : ksDel (ks);
804 4 : keyDel (parentKey);
805 :
806 4 : PLUGIN_CLOSE ();
807 4 : }
808 :
809 2 : int main (int argc, char ** argv)
810 : {
811 2 : printf ("TYPE TESTS\n");
812 2 : printf ("==================\n\n");
813 :
814 2 : init (argc, argv);
815 :
816 2 : test_validate ();
817 2 : test_short ();
818 2 : test_unsignedShort ();
819 2 : test_float ();
820 2 : test_bool ();
821 2 : test_none ();
822 2 : test_char ();
823 2 : test_wchar ();
824 2 : test_octet ();
825 2 : test_string ();
826 2 : test_wstring ();
827 :
828 2 : test_enum ();
829 2 : test_enumMulti ();
830 :
831 2 : test_enumNormalize ();
832 2 : test_enumMultiNormalize ();
833 :
834 2 : test_booleanDefault ("type");
835 2 : test_booleanDefaultError ("type");
836 2 : test_booleanDefaultRestore ("type");
837 2 : test_booleanUserValue ("type");
838 2 : test_booleanUserValueWeird ("type");
839 2 : test_booleanChangeValue ("type");
840 2 : test_booleanOverride ("type");
841 :
842 2 : test_booleanDefault ("check/type");
843 2 : test_booleanDefaultError ("check/type");
844 2 : test_booleanDefaultRestore ("check/type");
845 2 : test_booleanUserValue ("check/type");
846 2 : test_booleanUserValueWeird ("check/type");
847 2 : test_booleanChangeValue ("check/type");
848 2 : test_booleanOverride ("check/type");
849 :
850 2 : test_booleanRestoreDisabled ("type");
851 2 : test_booleanRestoreDisabled ("check/type");
852 :
853 2 : test_booleanRestoreAs ("type");
854 2 : test_booleanRestoreAs ("check/type");
855 :
856 2 : test_booleanRestoreAsDefault ("type", "#0", "yes", "no");
857 2 : test_booleanRestoreAsDefault ("type", "#1", "true", "false");
858 2 : test_booleanRestoreAsDefault ("type", "#2", "on", "off");
859 2 : test_booleanRestoreAsDefault ("type", "#3", "enabled", "disabled");
860 2 : test_booleanRestoreAsDefault ("type", "#4", "enable", "disable");
861 :
862 2 : test_booleanRestoreAsDefault ("check/type", "#0", "yes", "no");
863 2 : test_booleanRestoreAsDefault ("check/type", "#1", "true", "false");
864 2 : test_booleanRestoreAsDefault ("check/type", "#2", "on", "off");
865 2 : test_booleanRestoreAsDefault ("check/type", "#3", "enabled", "disabled");
866 2 : test_booleanRestoreAsDefault ("check/type", "#4", "enable", "disable");
867 :
868 2 : test_booleanUserValueError ();
869 :
870 2 : print_result ("testmod_type");
871 :
872 2 : return nbError;
873 : }
|