1 /***************************************************************************
2 * test_ks.c - KeySet struct test suite
4 * begin : Thu Dez 12 2006
5 * copyright : (C) 2006 by Markus Raab
6 * email : sizon5@gmail.com
7 ****************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the BSD License (revised). *
14 ***************************************************************************/
33 KeySet * keys = ksNew (15,0);
36 printf("Test ks creation\n");
37 exit_if_fail((ks=ksNew(0)) != 0, "could not create new keyset");
39 succeed_if (ksAppendKey(ks,keyNew(0)) == 1, "could not append a key");
40 succeed_if (ksAppendKey(ks,keyNew(0)) == 2, "could not append a key");
41 succeed_if (ksAppendKey(ks,keyNew(0)) == 3, "could not append a key");
42 succeed_if(ksGetSize(ks) == 3, "size not correct after 3 keys");
44 KeySet *ks2=ksNew (0);
46 compare_keyset (ks, ks2, 0, 0);
48 succeed_if (ksAppendKey(ks,keyNew(0)) == 4, "could not append a key");
49 succeed_if (ksAppendKey(ks,keyNew(0)) == 5, "could not append a key");
50 succeed_if (ksAppendKey(ks,keyNew(0)) == 6, "could not append a key");
51 succeed_if(ksGetSize(ks) == 6, "could not append 3 more keys");
54 compare_keyset (ks, ks2, 0, 0);
56 ksClear (ks2); // useless, just test for double free
58 compare_keyset (ks, ks2, 0, 0);
60 succeed_if(ksDel(ks) == 0, "could not delete keyset");
63 succeed_if(ksGetSize(keys) == 0, "could not append 3 more keys");
64 succeed_if(ksGetAlloc(keys) == 16, "allocation size wrong");
65 succeed_if(ksDel(keys) == 0, "could not delete keyset");
68 keyNew ("user/sw/app/fixedConfiguration/key1", KEY_VALUE, "value1", 0),
69 keyNew ("user/sw/app/fixedConfiguration/key2", KEY_VALUE, "value2", 0),
70 keyNew ("user/sw/app/fixedConfiguration/key3", KEY_VALUE, "value3", 0),0);
71 succeed_if(ksGetSize(config) == 3, "could not append 3 keys in keyNew");
72 succeed_if(ksGetAlloc(config) == 100, "allocation size wrong");
73 keyDel (ksPop (config));
74 succeed_if(ksGetAlloc(config) == 50, "allocation size wrong");
75 keyDel (ksPop (config));
76 succeed_if(ksGetAlloc(config) == 25, "allocation size wrong");
77 keyDel (ksPop (config));
78 succeed_if(ksGetAlloc(config) == 16, "allocation size wrong");
79 succeed_if(ksDel(config) == 0, "could not delete keyset");
82 keyNew ("user/sw/app/fixedConfiguration/key1", KEY_VALUE, "value1", 0),
83 keyNew ("user/sw/app/fixedConfiguration/key2", KEY_VALUE, "value2", 0),
84 keyNew ("user/sw/app/fixedConfiguration/key3", KEY_VALUE, "value1", 0),
85 keyNew ("user/sw/app/fixedConfiguration/key4", KEY_VALUE, "value3", 0),0);
87 succeed_if(ksGetSize(config) == 4, "could not append 5 keys in keyNew");
88 succeed_if(ksGetAlloc(config) == 16, "allocation size wrong");
89 ksAppendKey(config, keyNew ("user/sw/app/fixedConfiguration/key6", KEY_VALUE, "value4", 0));
93 compare_keyset (config, ks2, 0, 0);
95 succeed_if(ksDel(config) == 0, "could not delete keyset");
96 succeed_if(ksDel(ks2) == 0, "could not delete keyset");
101 printf ("Test empty keysets\n");
107 succeed_if (ksGetSize (ks) == 0, "size not correct");
108 succeed_if (ksPop (ks) == 0, "pop empty keyset");
109 succeed_if (ksGetSize (ks) == 0, "size not correct");
112 ks = ksNew (1, current=keyNew("user/test", KEY_END), KS_END);
113 succeed_if (ksGetSize (ks) == 1, "size not correct");
114 succeed_if (ksPop (ks) == current, "pop empty keyset");
115 succeed_if (ksGetSize (ks) == 0, "size not correct");
116 succeed_if (ksPop (ks) == 0, "pop empty keyset");
117 succeed_if (ksGetSize (ks) == 0, "size not correct");
123 succeed_if (ksAppend (ks, ks2) == 0, "could not append empty keyset");
124 succeed_if (ksGetSize (ks) == 0, "empty keyset does not have correct size");
125 succeed_if (ksGetSize (ks2) == 0, "empty keyset does not have correct size");
126 succeed_if (ksPop(ks) == 0, "could not pop empty keyset");
127 succeed_if (ksPop(ks2) == 0, "could not pop empty keyset2");
131 ks = ksNew (1, current=keyNew("user/test", KEY_END), KS_END);
133 succeed_if (ksGetSize (ks) == 1, "empty keyset does not have correct size");
134 succeed_if (ksGetSize (ks2) == 0, "empty keyset does not have correct size");
135 succeed_if (ksAppend (ks, ks2) == 1, "could not append empty keyset");
136 succeed_if (ksGetSize (ks) == 1, "empty keyset does not have correct size");
137 succeed_if (ksGetSize (ks2) == 0, "empty keyset does not have correct size");
138 succeed_if (ksPop(ks) == current, "could not pop keyset");
139 succeed_if (ksPop(ks2) == 0, "could not pop empty keyset2");
140 succeed_if (ksGetSize (ks) == 0, "empty keyset does not have correct size");
141 succeed_if (ksGetSize (ks2) == 0, "empty keyset does not have correct size");
142 succeed_if (ksAppend (ks, ks2) == 0, "could not append empty keyset");
143 succeed_if (ksGetSize (ks) == 0, "empty keyset does not have correct size");
144 succeed_if (ksGetSize (ks2) == 0, "empty keyset does not have correct size");
151 ks2 = ksNew (1, current=keyNew("user/test", KEY_END), KS_END);
152 succeed_if (ksGetSize (ks) == 0, "empty keyset does not have correct size");
153 succeed_if (ksGetSize (ks2) == 1, "empty keyset does not have correct size");
154 succeed_if (ksAppend (ks, ks2) == 1, "could not append empty keyset");
155 succeed_if (ksGetSize (ks) == 1, "empty keyset does not have correct size");
156 succeed_if (ksGetSize (ks2) == 1, "empty keyset does not have correct size");
157 succeed_if (ksPop(ks) == current, "could not pop keyset");
158 succeed_if (ksPop(ks2) == current, "could not pop empty keyset2");
159 succeed_if (ksGetSize (ks) == 0, "empty keyset does not have correct size");
160 succeed_if (ksGetSize (ks2) == 0, "empty keyset does not have correct size");
161 succeed_if (ksAppend (ks, ks2) == 0, "could not append empty keyset");
162 succeed_if (ksGetSize (ks) == 0, "empty keyset does not have correct size");
163 succeed_if (ksGetSize (ks2) == 0, "empty keyset does not have correct size");
164 keyDel (current); // only one keyDel, because ksPop decrements counter
169 #define NR_KEYSETS 10
171 void test_ksReference()
176 KeySet *kss[NR_KEYSETS];
179 printf("Test reference of key\n");
182 k1 = keyNew("user/aname", KEY_END);
183 succeed_if (keyGetRef(k1) == 0, "reference counter of new key");
185 succeed_if (keyGetRef(k1) == 1, "reference counter of inserted key");
189 succeed_if (keyGetRef(k2) == 0, "reference counter not resetted");
191 succeed_if (keyGetRef(k2) == 1, "reference counter not incremented");
197 keyNew ("user/key", KEY_END),
198 keyNew ("system/key", KEY_END),
201 k1=ksLookupByName(ks, "user/key", 0);
202 k2=ksLookupByName(ks, "system/key", 0);
203 succeed_if (keyGetRef(k1) == 1, "reference counter of new inserted key");
204 succeed_if (keyGetRef(k2) == 1, "reference counter of new inserted key");
209 keyNew ("user/key", KEY_END),
210 keyNew ("system/key", KEY_END),
213 k1=ksLookupByName(ks, "user/key", 0);
214 k2=ksLookupByName(ks, "system/key", 0);
215 succeed_if (keyGetRef(k1) == 1, "reference counter of new inserted key");
216 succeed_if (keyGetRef(k2) == 1, "reference counter of new inserted key");
219 succeed_if (keyGetRef(k1) == 2, "reference counter after duplication of keyset");
220 succeed_if (keyGetRef(k2) == 2, "reference counter after ksdup");
222 succeed_if (keyGetRef(k1) == 1, "reference counter after pop");
224 succeed_if (keyGetRef(k1) == 1, "reference counter");
225 succeed_if (keyGetRef(k2) == 2, "reference counter should not be influenced");
228 succeed_if (keyGetRef(k1) == 1, "reference counter, delete from first keyset");
229 succeed_if (keyGetRef(k2) == 1, "reference counter, delete from first keyset");
230 ksDel (ks1); // k1 and k2 deleted
235 succeed_if (keyGetRef(k1) == 0, "reference counter of new inserted key");
236 ksAppendKey(ks1, k1);
237 succeed_if (keyGetRef(k1) == 1, "reference counter of new inserted key");
238 ksAppendKey(ks2, k1);
239 succeed_if (keyGetRef(k1) == 2, "reference counter of new inserted key");
242 succeed_if (keyGetRef(k1) == 1, "reference counter of new inserted key");
243 succeed_if (keyDel (k1) == 1, "keyDel did not work");
244 succeed_if (keyGetRef(k1) == 1, "reference counter of new inserted key");
246 succeed_if (ksDel (ks1) == 0, "could not delete key");
247 succeed_if (ksDel (ks2) == 0, "could not delete key");
251 k1=keyNew ("user/key", KEY_END),
252 k2=keyNew ("system/key", KEY_END),
254 for (i=1; i< NR_KEYSETS; i++)
256 succeed_if (keyGetRef(k1) == i, "reference counter");
257 succeed_if (keyGetRef(k2) == 1, "reference counter");
258 kss[i] = ksDup (kss[i-1]);
259 succeed_if (keyGetRef(k2) == 2, "reference counter");
261 succeed_if (keyGetRef(k2) == 1, "reference counter");
262 succeed_if (keyDel(k2) == 1, "delete key");
263 succeed_if (keyGetRef(k2) == 1, "reference counter");
266 succeed_if (keyGetRef(k1) == NR_KEYSETS, "reference counter");
267 succeed_if (keyGetRef(k2) == 1, "reference counter");
269 for (i=0; i< NR_KEYSETS; i++)
271 succeed_if (keyGetRef(k1) == NR_KEYSETS-i, "reference counter");
280 KeySet *copy = ksNew (0);
282 printf("Test resize of keyset\n");
283 exit_if_fail((ks=ksNew(0)) != 0, "could not create new keyset");
284 for (i=0; i< 100; i++)
286 ksAppendKey(ks, keyNew (KEY_END));
287 if (i >= 63) { succeed_if(ksGetAlloc(ks) == 128, "allocation size wrong"); }
288 else if (i >= 31) { succeed_if(ksGetAlloc(ks) == 64, "allocation size wrong"); }
289 else if (i >= 15) { succeed_if(ksGetAlloc(ks) == 32, "allocation size wrong"); }
290 else if (i >= 0) { succeed_if(ksGetAlloc(ks) == 16, "allocation size wrong"); }
292 succeed_if(ksGetSize(ks) == 100, "could not append 100 keys");
293 succeed_if(ksGetAlloc(ks) == 128, "allocation size wrong");
294 for (i=100; i >= 0; i--)
297 if (i >= 64) { succeed_if(ksGetAlloc(ks) == 128, "allocation size wrong"); }
298 else if (i >= 32) { succeed_if(ksGetAlloc(ks) == 64, "allocation size wrong"); }
299 else if (i >= 16) { succeed_if(ksGetAlloc(ks) == 32, "allocation size wrong"); }
300 else if (i >= 0) { succeed_if(ksGetAlloc(ks) == 16, "allocation size wrong"); }
302 succeed_if(ksGetSize(ks) == 0, "could not pop 100 keys");
303 succeed_if(ksGetAlloc(ks) == 16, "allocation size wrong");
306 exit_if_fail((ks=ksNew(0)) != 0, "could not create new keyset");
308 succeed_if(ksGetAlloc(ks) == 101, "allocation size wrong");
309 for (i=0; i< 100; i++)
311 ksAppendKey(ks, keyNew (KEY_END));
313 succeed_if(ksGetSize(ks) == 100, "could not append 100 keys");
314 succeed_if(ksGetAlloc(ks) == 101, "allocation size wrong");
320 succeed_if(ksGetSize(ks) == 102, "Problem loading keyset with 102 keys");
321 succeed_if(ksGetAlloc(ks) == 128, "alloc size wrong");
324 compare_keyset(copy, ks, 0, 0);
326 ksClear (copy); // useless, just test for double free
328 compare_keyset(copy, ks, 0, 0);
339 printf("Test ks duplication\n");
341 exit_if_fail((ks=ksNew(0)) != 0, "could not create new keyset");
343 succeed_if(other, "other creation failed");
344 succeed_if(ksGetSize(ks) == 0, "ks has keys");
345 succeed_if(ksGetSize(other) == 0, "other has keys");
349 exit_if_fail((ks=ksNew(1, keyNew(0), 0)) != 0, "could not create new keyset");
351 succeed_if(other, "other creation failed");
352 succeed_if(ksGetSize(ks) == 1, "ks has no keys");
353 succeed_if(ksGetSize(other) == 1, "other has no keys");
357 exit_if_fail((ks=ksNew(1, keyNew(0), 0)) != 0, "could not create new keyset");
358 succeed_if (ksAppendKey(ks,keyNew("user/test", KEY_END)) == 2, "could not append a key");
359 succeed_if (ksAppendKey(ks,keyNew(0)) == 3, "could not append a key");
360 succeed_if (ksAppendKey(ks,keyNew(0)) == 4, "could not append a key");
362 succeed_if(other, "other creation failed");
363 succeed_if(ksGetSize(ks) == 4, "ks has no keys");
364 succeed_if(ksGetSize(other) == 4, "other has no keys");
368 exit_if_fail((ks=ksNew(1, keyNew(0), 0)) != 0, "could not create new keyset");
369 succeed_if (ksAppendKey(ks,keyNew("user/test", KEY_END)) == 2, "could not append a key");
370 succeed_if (ksAppendKey(ks,keyNew(0)) == 3, "could not append a key");
371 succeed_if (ksAppendKey(ks,keyNew(0)) == 4, "could not append a key");
373 succeed_if(other, "other creation failed");
374 keyDel (ksPop (other));
375 succeed_if(ksGetSize(ks) == 4, "ks has no keys");
376 succeed_if(ksGetSize(other) == 3, "other has no keys");
380 exit_if_fail((ks=ksNew(1, keyNew(0), 0)) != 0, "could not create new keyset");
381 succeed_if (ksAppendKey(ks,keyNew("user/test", KEY_END)) == 2, "could not append a key");
382 succeed_if (ksAppendKey(ks,keyNew(0)) == 3, "could not append a key");
383 succeed_if (ksAppendKey(ks,keyNew(0)) == 4, "could not append a key");
385 succeed_if(other, "other creation failed");
386 keyDel(ksPop (other));
387 succeed_if (ksAppendKey(ks,keyNew(0)) == 5, "could not append a key");
388 succeed_if(ksGetSize(ks) == 5, "ks has no keys");
389 succeed_if(ksGetSize(other) == 3, "other has no keys");
399 printf("Test ks copy\n");
402 exit_if_fail((ks=ksNew(0)) != 0, "could not create new keyset");
403 succeed_if(ksCopy(other,ks)==1, "Copy failed");
404 succeed_if(other, "other creation failed");
405 succeed_if(ksGetSize(ks) == 0, "ks has keys");
406 succeed_if(ksGetSize(other) == 0, "other has keys");
411 exit_if_fail((ks=ksNew(1, keyNew(0), 0)) != 0, "could not create new keyset");
412 succeed_if(ksCopy(other,ks)==1, "Copy failed");
413 succeed_if(other, "other creation failed");
414 succeed_if(ksGetSize(ks) == 1, "ks has no keys");
415 succeed_if(ksGetSize(other) == 1, "other has no keys");
420 exit_if_fail((ks=ksNew(1, keyNew(0), 0)) != 0, "could not create new keyset");
421 succeed_if (ksAppendKey(ks,keyNew("user/test", KEY_END)) == 2, "could not append a key");
422 succeed_if (ksAppendKey(ks,keyNew(0)) == 3, "could not append a key");
423 succeed_if (ksAppendKey(ks,keyNew(0)) == 4, "could not append a key");
424 succeed_if(ksCopy(other,ks)==1, "Copy failed");
425 succeed_if(other, "other creation failed");
426 succeed_if(ksGetSize(ks) == 4, "ks has no keys");
427 succeed_if(ksGetSize(other) == 4, "other has no keys");
432 exit_if_fail((ks=ksNew(1, keyNew(0), 0)) != 0, "could not create new keyset");
433 succeed_if (ksAppendKey(ks,keyNew("user/test", KEY_END)) == 2, "could not append a key");
434 succeed_if (ksAppendKey(ks,keyNew(0)) == 3, "could not append a key");
435 succeed_if (ksAppendKey(ks,keyNew(0)) == 4, "could not append a key");
436 succeed_if(ksCopy(other,ks)==1, "Copy failed");
437 succeed_if(other, "other creation failed");
438 keyDel (ksPop (other));
439 succeed_if(ksGetSize(ks) == 4, "ks has no keys");
440 succeed_if(ksGetSize(other) == 3, "other has no keys");
445 exit_if_fail((ks=ksNew(1, keyNew(0), 0)) != 0, "could not create new keyset");
446 succeed_if (ksAppendKey(ks,keyNew("user/test", KEY_END)) == 2, "could not append a key");
447 succeed_if (ksAppendKey(ks,keyNew(0)) == 3, "could not append a key");
448 succeed_if (ksAppendKey(ks,keyNew(0)) == 4, "could not append a key");
449 succeed_if(ksCopy(other,ks)==1, "Copy failed");
450 succeed_if(other, "other creation failed");
451 keyDel(ksPop (other));
452 succeed_if (ksAppendKey(ks,keyNew(0)) == 5, "could not append a key");
453 succeed_if(ksGetSize(ks) == 5, "ks has no keys");
454 succeed_if(ksGetSize(other) == 3, "other has no keys");
459 exit_if_fail((ks=ksNew(1, keyNew(0), 0)) != 0, "could not create new keyset");
460 succeed_if (ksAppendKey(ks,keyNew("user/test", KEY_END)) == 2, "could not append a key");
461 succeed_if (ksAppendKey(ks,keyNew(0)) == 3, "could not append a key");
462 succeed_if (ksAppendKey(ks,keyNew(0)) == 4, "could not append a key");
463 succeed_if(ksCopy(other,ks)==1, "Copy failed");
464 succeed_if(other, "other creation failed");
465 keyDel(ksPop (other));
466 succeed_if (ksAppendKey(ks,keyNew(0)) == 5, "could not append a key");
467 succeed_if(ksGetSize(ks) == 5, "ks has no keys");
468 succeed_if(ksGetSize(other) == 3, "other has no keys");
470 succeed_if(ksCopy(ks,0)==0, "Clear failed");
471 succeed_if(ksGetSize(ks) == 0, "ks has keys");
473 succeed_if(ksCopy(other,0)==0, "Clear failed");
474 succeed_if(ksGetSize(other) == 0, "other has keys");
479 void test_ksIterate()
482 KeySet *other=ksNew(0);
485 char name [] = "user/n";
486 char output [] = "2 key not on its place";
488 printf("Test keyset iterate\n");
489 ksAppendKey(ks,keyNew("user/1", KEY_END));
490 ksAppendKey(ks,keyNew("user/2", KEY_END));
491 ksAppendKey(ks,keyNew("user/3", KEY_END));
492 ksAppendKey(ks,keyNew("user/4", KEY_END));
493 ksAppendKey(ks,keyNew("user/5", KEY_END));
494 succeed_if(ksGetSize(ks) == 5, "could not append 5 keys");
497 succeed_if(strcmp(keyName(key), "user/5") == 0, "1 key not on first place");
498 succeed_if (keyDel (key) == 0, "could not del popped key");
500 succeed_if(ksAppend(other,ks) == 4, "could not append keys");
505 succeed_if (key != 0, "got null pointer key");
508 succeed_if(strcmp(keyName(key), name) == 0, output);
512 succeed_if (ksAppendKey(other, keyNew ("user/3", KEY_END)) == 1, "could not append one key");
514 succeed_if (key != 0, "got null pointer key");
515 succeed_if(strcmp(keyName(key), "user/3") == 0, "only key to pop not found");
516 succeed_if (keyDel (key) == 0, "could not del popped key");
521 keyNew("user/0", KEY_END),
522 keyNew("user/1", KEY_END),
523 keyNew("user/2", KEY_END),
524 keyNew("user/3", KEY_END),
528 keyNew("user/4", KEY_END),
529 keyNew("user/5", KEY_END),
530 keyNew("user/6", KEY_END),
531 keyNew("user/7", KEY_END),
534 succeed_if(ksAppend(ks,other) == 8, "could not append keys");
536 for (i=7; i >= 0; i--)
539 succeed_if (key != 0, "got null pointer key");
542 succeed_if(strcmp(keyName(key), name) == 0, output);
555 char name [] = "user/n";
556 char output [] = "n key not on its place";
558 printf("Test keyset cursor\n");
560 ksAppendKey(ks,keyNew("user/1", KEY_END));
561 ksAppendKey(ks,keyNew("user/2", KEY_END));
562 ksAppendKey(ks,keyNew("user/3", KEY_END));
563 cursor = ksGetCursor (ks);
564 ksAppendKey(ks,keyNew("user/4", KEY_END));
565 ksAppendKey(ks,keyNew("user/5", KEY_END));
566 succeed_if(ksGetSize(ks) == 5, "could not append 5 keys");
568 succeed_if (cursor == ksGetCursor(ks), "cursor after appending");
569 ksSetCursor (ks, cursor);
570 succeed_if (cursor == ksGetCursor(ks), "cursor set to 3");
572 cursor = ksGetCursor (ks);
574 succeed_if (cursor == ksGetCursor(ks), "cursor should stay the same");
575 succeed_if(strcmp(keyName(key), "user/5") == 0, "1 key not on first place");
576 succeed_if (keyDel (key) == 0, "could not del popped key");
584 cursor = ksGetCursor (ks);
589 ksSetCursor(ks, cursor);
590 key = ksCurrent (ks);
595 keyNew("user/0", KEY_END),
596 keyNew("user/1", KEY_END),
597 keyNew("user/2", KEY_END),
598 keyNew("user/3", KEY_END),
602 for (i=0; i < 4; i++)
607 cursor = ksGetCursor (ks);
613 ksSetCursor(ks, cursor);
614 key = ksCurrent (ks);
615 succeed_if(!strcmp (keyName(key), name), output);
626 printf("Test ks sort\n");
628 printf ("Sort with no keyNeedRemove set\n");
630 ksAppendKey(ks, keyNew("user/bname", KEY_END));
631 ksAppendKey(ks, keyNew("user/aname", KEY_END));
632 ksAppendKey(ks, keyNew("user/cname", KEY_END));
637 succeed_if (strcmp (keyName (key), "user/aname") == 0, "a should be 1.");
640 succeed_if (strcmp (keyName (key), "user/bname") == 0, "b should be 2.");
643 succeed_if (strcmp (keyName (key), "user/cname") == 0, "c should be 3.");
647 ksAppendKey(ks, keyNew("user/a", KEY_END));
648 ksAppendKey(ks, keyNew("user/e", KEY_END));
649 ksAppendKey(ks, keyNew("user/b", KEY_END));
650 ksAppendKey(ks, keyNew("user/b", KEY_END));
651 ksAppendKey(ks, keyNew("user/d", KEY_END));
652 ksAppendKey(ks, keyNew("user/c", KEY_END));
653 ksAppendKey(ks, keyNew("user/c", KEY_END));
654 ksAppendKey(ks, keyNew("user/g", KEY_END));
655 ksAppendKey(ks, keyNew("user/h", KEY_END));
656 ksAppendKey(ks, keyNew("user/h", KEY_END));
657 ksAppendKey(ks, keyNew("user/f", KEY_END));
661 for (i=0; (key=ksNext(ks)) != 0; i++)
665 case 0: succeed_if (strcmp (keyName (key), "user/a") == 0, "wrong name found.");
666 succeed_if (keyNeedRemove (key) == 0, "wrong removed key information");
668 case 1: succeed_if (strcmp (keyName (key), "user/b") == 0, "wrong name found.");
669 succeed_if (keyNeedRemove (key) == 0, "wrong removed key information");
671 case 2: succeed_if (strcmp (keyName (key), "user/b") == 0, "wrong name found.");
672 succeed_if (keyNeedRemove (key) == 0, "wrong removed key information");
674 case 3: succeed_if (strcmp (keyName (key), "user/c") == 0, "wrong name found.");
675 succeed_if (keyNeedRemove (key) == 0, "wrong removed key information");
677 case 4: succeed_if (strcmp (keyName (key), "user/c") == 0, "wrong name found.");
678 succeed_if (keyNeedRemove (key) == 0, "wrong removed key information");
680 case 5: succeed_if (strcmp (keyName (key), "user/d") == 0, "wrong name found.");
681 succeed_if (keyNeedRemove (key) == 0, "wrong removed key information");
683 case 6: succeed_if (strcmp (keyName (key), "user/e") == 0, "wrong name found.");
684 succeed_if (keyNeedRemove (key) == 0, "wrong removed key information");
686 case 7: succeed_if (strcmp (keyName (key), "user/f") == 0, "wrong name found.");
687 succeed_if (keyNeedRemove (key) == 0, "wrong removed key information");
689 case 8: succeed_if (strcmp (keyName (key), "user/g") == 0, "wrong name found.");
690 succeed_if (keyNeedRemove (key) == 0, "wrong removed key information");
692 case 9: succeed_if (strcmp (keyName (key), "user/h") == 0, "wrong name found.");
693 succeed_if (keyNeedRemove (key) == 0, "wrong removed key information");
695 case 10:succeed_if (strcmp (keyName (key), "user/h") == 0, "wrong name found.");
696 succeed_if (keyNeedRemove (key) == 0, "wrong removed key information");
698 default:succeed_if (0, "should not reach");
704 printf ("Sort with some keyNeedRemove set\n");
706 k1 = keyNew("user/aname", KEY_END);
712 succeed_if (keyGetRef(k2) == 0, "reference counter not resetted");
714 succeed_if (keyGetRef(k2) == 1, "reference counter not incremented");
719 // printf ("%d\n", keyNeedRemove (key));
720 succeed_if (keyNeedRemove (key) == 1, "Removed key should be on first position");
724 k1 = keyNew("user/aname", KEY_END);
733 succeed_if (keyNeedRemove (key) == 1, "Removed key should be on first position");
737 ksAppendKey(ks, keyNew("user/a", KEY_REMOVE, KEY_END));
738 ksAppendKey(ks, keyNew("user/e", KEY_END));
739 ksAppendKey(ks, keyNew("user/b", KEY_REMOVE, KEY_END));
740 ksAppendKey(ks, keyNew("user/b", KEY_END));
741 ksAppendKey(ks, keyNew("user/d", KEY_REMOVE, KEY_END));
742 ksAppendKey(ks, keyNew("user/c", KEY_END));
743 ksAppendKey(ks, keyNew("user/c", KEY_REMOVE, KEY_END));
744 ksAppendKey(ks, keyNew("user/g", KEY_REMOVE, KEY_END));
745 ksAppendKey(ks, keyNew("user/h", KEY_REMOVE, KEY_END));
746 ksAppendKey(ks, keyNew("user/h", KEY_END));
747 ksAppendKey(ks, keyNew("user/f", KEY_REMOVE, KEY_END));
751 // output_keyset(ks,0);
752 for (i=0; (key=ksNext(ks)) != 0; i++)
756 case 0: succeed_if (strcmp (keyName (key), "user/h") == 0, "wrong name found.");
757 succeed_if (keyNeedRemove (key) == 1, "wrong removed key information");
759 case 1: succeed_if (strcmp (keyName (key), "user/g") == 0, "wrong name found.");
760 succeed_if (keyNeedRemove (key) == 1, "wrong removed key information");
762 case 2: succeed_if (strcmp (keyName (key), "user/f") == 0, "wrong name found.");
763 succeed_if (keyNeedRemove (key) == 1, "wrong removed key information");
765 case 3: succeed_if (strcmp (keyName (key), "user/d") == 0, "wrong name found.");
766 succeed_if (keyNeedRemove (key) == 1, "wrong removed key information");
768 case 4: succeed_if (strcmp (keyName (key), "user/c") == 0, "wrong name found.");
769 succeed_if (keyNeedRemove (key) == 1, "wrong removed key information");
771 case 5: succeed_if (strcmp (keyName (key), "user/b") == 0, "wrong name found.");
772 succeed_if (keyNeedRemove (key) == 1, "wrong removed key information");
774 case 6: succeed_if (strcmp (keyName (key), "user/a") == 0, "wrong name found.");
775 succeed_if (keyNeedRemove (key) == 1, "wrong removed key information");
777 case 7: succeed_if (strcmp (keyName (key), "user/b") == 0, "wrong name found.");
778 succeed_if (keyNeedRemove (key) == 0, "wrong removed key information");
780 case 8: succeed_if (strcmp (keyName (key), "user/c") == 0, "wrong name found.");
781 succeed_if (keyNeedRemove (key) == 0, "wrong removed key information");
783 case 9: succeed_if (strcmp (keyName (key), "user/e") == 0, "wrong name found.");
784 succeed_if (keyNeedRemove (key) == 0, "wrong removed key information");
786 case 10:succeed_if (strcmp (keyName (key), "user/h") == 0, "wrong name found.");
787 succeed_if (keyNeedRemove (key) == 0, "wrong removed key information");
789 default:succeed_if (0, "should not reach");
796 printf ("Sort with all keyNeedRemove set\n");
798 ksAppendKey(ks, keyNew("user/a", KEY_REMOVE, KEY_END));
799 ksAppendKey(ks, keyNew("user/e", KEY_REMOVE, KEY_END));
800 ksAppendKey(ks, keyNew("user/b/a", KEY_REMOVE, KEY_END));
801 ksAppendKey(ks, keyNew("user/b", KEY_REMOVE, KEY_END));
802 ksAppendKey(ks, keyNew("user/d", KEY_REMOVE, KEY_END));
803 ksAppendKey(ks, keyNew("user/c", KEY_REMOVE, KEY_END));
804 ksAppendKey(ks, keyNew("user/c/a", KEY_REMOVE, KEY_END));
805 ksAppendKey(ks, keyNew("user/g", KEY_REMOVE, KEY_END));
806 ksAppendKey(ks, keyNew("user/h/a", KEY_REMOVE, KEY_END));
807 ksAppendKey(ks, keyNew("user/h", KEY_REMOVE, KEY_END));
808 ksAppendKey(ks, keyNew("user/f", KEY_REMOVE, KEY_END));
812 // output_keyset(ks,0);
813 for (i=0; (key=ksNext(ks)) != 0; i++)
817 case 0: succeed_if (strcmp (keyName (key), "user/h/a") == 0, "wrong name found.");
818 succeed_if (keyNeedRemove (key) == 1, "wrong removed key information");
820 case 1: succeed_if (strcmp (keyName (key), "user/h") == 0, "wrong name found.");
821 succeed_if (keyNeedRemove (key) == 1, "wrong removed key information");
823 case 2: succeed_if (strcmp (keyName (key), "user/g") == 0, "wrong name found.");
824 succeed_if (keyNeedRemove (key) == 1, "wrong removed key information");
826 case 3: succeed_if (strcmp (keyName (key), "user/f") == 0, "wrong name found.");
827 succeed_if (keyNeedRemove (key) == 1, "wrong removed key information");
829 case 4: succeed_if (strcmp (keyName (key), "user/e") == 0, "wrong name found.");
830 succeed_if (keyNeedRemove (key) == 1, "wrong removed key information");
832 case 5: succeed_if (strcmp (keyName (key), "user/d") == 0, "wrong name found.");
833 succeed_if (keyNeedRemove (key) == 1, "wrong removed key information");
835 case 6: succeed_if (strcmp (keyName (key), "user/c/a") == 0, "wrong name found.");
836 succeed_if (keyNeedRemove (key) == 1, "wrong removed key information");
838 case 7: succeed_if (strcmp (keyName (key), "user/c") == 0, "wrong name found.");
839 succeed_if (keyNeedRemove (key) == 1, "wrong removed key information");
841 case 8: succeed_if (strcmp (keyName (key), "user/b/a") == 0, "wrong name found.");
842 succeed_if (keyNeedRemove (key) == 1, "wrong removed key information");
844 case 9: succeed_if (strcmp (keyName (key), "user/b") == 0, "wrong name found.");
845 succeed_if (keyNeedRemove (key) == 1, "wrong removed key information");
847 case 10:succeed_if (strcmp (keyName (key), "user/a") == 0, "wrong name found.");
848 succeed_if (keyNeedRemove (key) == 1, "wrong removed key information");
850 default:succeed_if (0, "should not reach");
856 printf ("Sort with mixed keyNeedRemove set and subdirs\n");
858 ksAppendKey(ks, keyNew("user/dir1/key1", KEY_REMOVE, KEY_END));
859 ksAppendKey(ks, keyNew("user/dir1/key2", KEY_END));
860 ksAppendKey(ks, keyNew("user/dir1/key3", KEY_REMOVE, KEY_END));
861 ksAppendKey(ks, keyNew("user/dir2", KEY_REMOVE, KEY_END));
862 ksAppendKey(ks, keyNew("user/dir2/key1", KEY_REMOVE, KEY_END));
863 ksAppendKey(ks, keyNew("user/dir3/key1", KEY_END));
864 ksAppendKey(ks, keyNew("user/dir3", KEY_END));
865 ksAppendKey(ks, keyNew("user/dir3/key2", KEY_END));
866 ksAppendKey(ks, keyNew("user/dir4", KEY_END));
867 ksAppendKey(ks, keyNew("user/dir5/key1", KEY_REMOVE, KEY_END));
868 ksAppendKey(ks, keyNew("user/dir6/key1", KEY_END));
872 // output_keyset(ks,0);
873 for (i=0; (key=ksNext(ks)) != 0; i++)
877 case 0: succeed_if (strcmp (keyName (key), "user/dir5/key1") == 0, "wrong name found.");
878 succeed_if (keyNeedRemove (key) == 1, "wrong removed key information");
880 case 1: succeed_if (strcmp (keyName (key), "user/dir2/key1") == 0, "wrong name found.");
881 succeed_if (keyNeedRemove (key) == 1, "wrong removed key information");
883 case 2: succeed_if (strcmp (keyName (key), "user/dir2") == 0, "wrong name found.");
884 succeed_if (keyNeedRemove (key) == 1, "wrong removed key information");
886 case 3: succeed_if (strcmp (keyName (key), "user/dir1/key3") == 0, "wrong name found.");
887 succeed_if (keyNeedRemove (key) == 1, "wrong removed key information");
889 case 4: succeed_if (strcmp (keyName (key), "user/dir1/key1") == 0, "wrong name found.");
890 succeed_if (keyNeedRemove (key) == 1, "wrong removed key information");
892 case 5: succeed_if (strcmp (keyName (key), "user/dir1/key2") == 0, "wrong name found.");
893 succeed_if (keyNeedRemove (key) == 0, "wrong removed key information");
895 case 6: succeed_if (strcmp (keyName (key), "user/dir3") == 0, "wrong name found.");
896 succeed_if (keyNeedRemove (key) == 0, "wrong removed key information");
898 case 7: succeed_if (strcmp (keyName (key), "user/dir3/key1") == 0, "wrong name found.");
899 succeed_if (keyNeedRemove (key) == 0, "wrong removed key information");
901 case 8: succeed_if (strcmp (keyName (key), "user/dir3/key2") == 0, "wrong name found.");
902 succeed_if (keyNeedRemove (key) == 0, "wrong removed key information");
904 case 9: succeed_if (strcmp (keyName (key), "user/dir4") == 0, "wrong name found.");
905 succeed_if (keyNeedRemove (key) == 0, "wrong removed key information");
907 case 10:succeed_if (strcmp (keyName (key), "user/dir6/key1") == 0, "wrong name found.");
908 succeed_if (keyNeedRemove (key) == 0, "wrong removed key information");
910 default:succeed_if (0, "should not reach");
917 void ksUnsort (KeySet *ks)
921 KeySet *randks=ksNew(0); /*This is the final randomized keyset*/
922 KeySet *tempks=ksNew(0); /*Temporary storage for keys not chosen to be inserted*/
924 while (ksGetSize(ks) > 0)
927 size = ksGetSize(ks);
928 /* printf ("iterating %d\n", size); */
929 while ((cur=ksPop(ks)) != 0)
931 /* printf ("\titerating %s\n", keyName(cur)); */
932 if (!(rand()%size)) ksAppendKey(randks, cur);
933 else ksAppendKey(tempks,cur);
935 ksAppend(ks, tempks);
947 printf ("Test lookup\n");
953 KeySet *ks = ksNew (30,
954 k[0]=keyNew ("user/rem3", KEY_REMOVE, KEY_DIR, KEY_END),
955 k[1]=keyNew ("user/rem2", KEY_REMOVE, KEY_DIR, KEY_END),
956 k[2]=keyNew ("user/rem1/key2", KEY_REMOVE, KEY_END),
957 k[3]=keyNew ("user/rem1/key1", KEY_REMOVE, KEY_END),
958 k[4]=keyNew ("user/rem1", KEY_REMOVE, KEY_DIR, KEY_END),
959 k[5]=keyNew ("user/dir1", KEY_DIR, KEY_END),
960 k[6]=keyNew ("user/dir1/key1", KEY_VALUE, "value1", KEY_END),
961 k[7]=keyNew ("user/dir1/key2", KEY_VALUE, "value2", KEY_END),
962 k[8]=keyNew ("user/dir1/key3", KEY_VALUE, "value3", KEY_END),
963 k[9]=keyNew ("user/dir1/key4", KEY_VALUE, "value4", KEY_END),
964 k[10]=keyNew ("user/dir1/.inactive1", KEY_COMMENT, "key is inactive", KEY_END),
965 k[11]=keyNew ("user/dir1/.inactive2", KEY_COMMENT, "additional information", KEY_END),
966 k[12]=keyNew ("user:max/dir2", KEY_DIR, KEY_END),
967 k[13]=keyNew ("user:max/dir2/key1", KEY_VALUE, "value1", KEY_END),
968 k[14]=keyNew ("user/dir2/key2", KEY_VALUE, "value2", KEY_END),
969 k[15]=keyNew ("user/dir2/key3", KEY_VALUE, "value3", KEY_END),
970 k[16]=keyNew ("user:hugo/dir2/key4", KEY_VALUE, "value4", KEY_END),
971 k[17]=keyNew ("user/dir3", KEY_DIR, KEY_END),
972 k[18]=keyNew ("user/dir3/key1", KEY_VALUE, "value1", KEY_END),
973 k[19]=keyNew ("user:sb/dir3/.inactive1", KEY_COMMENT, "key is inactive", KEY_END),
974 k[20]=keyNew ("user/dir3/.inactive2", KEY_COMMENT, "a users comment", KEY_END),
975 k[21]=keyNew ("user/dir4", KEY_DIR, KEY_END),
976 k[22]=keyNew ("user/dir5", KEY_DIR, KEY_END),
980 k[23] = keyNew ("user/DiR1", KEY_END);
982 k[24] = keyNew ("user/DiR1/KEY1", KEY_END);
983 k[25] = keyNew ("user:wrongowner/DiR1/KEY1", KEY_END);
984 k[26] = keyNew ("user:nop/DiR1/KEY1", KEY_END);
985 k[27] = keyNew ("user:wrongowner/dir1/key1", KEY_END);
986 k[28] = keyNew ("user:nop/dir1/key1", KEY_END);
988 k[29] = keyNew ("user:wrongowner/dir2/key1", KEY_END);
989 k[30] = keyNew ("user/dir2/key1", KEY_END);
990 k[31] = keyNew ("user:max/dir2/key1", KEY_END);
994 succeed_if (ksLookup(0, k[23], 0) == 0, "null pointer");
995 succeed_if (ksLookup(ks, 0, 0) == 0, "null pointer");
997 for (i=0; i<100; i++)
1001 succeed_if (ksLookup(ks, k[j], 0)==0, "found removed key");
1003 succeed_if (ksLookup(ks, k[j], 0)==k[j], "did not found key");
1004 succeed_if (ksLookup(ks, k[23], KDB_O_NOCASE) == k[5], "did not found key");
1005 succeed_if (ksLookup(ks, k[23], 0) == 0, "found wrong key");
1006 succeed_if (ksLookup(ks, k[24], KDB_O_NOCASE) == k[6], "did not found key");
1007 succeed_if (ksLookup(ks, k[24], 0) == 0, "found wrong key");
1008 succeed_if (ksLookup(ks, k[25], KDB_O_NOCASE) == k[6], "did not found key");
1009 succeed_if (ksLookup(ks, k[25], KDB_O_WITHOWNER|KDB_O_NOCASE) == 0, "found wrong key");
1010 succeed_if (ksLookup(ks, k[28], 0) == k[6], "did not found key");
1011 succeed_if (ksLookup(ks, k[28], KDB_O_WITHOWNER) == 0, "found wrong key");
1012 succeed_if (ksLookup(ks, k[31], KDB_O_WITHOWNER) == k[13], "did not found key");
1013 /* Empty lines to add more tests:
1014 succeed_if (ksLookup(ks, k[], ) == k[], "did not found key");
1015 succeed_if (ksLookup(ks, k[], ) == 0, "found wrong key");
1020 for (i=23; i<32;i++) keyDel (k[i]);
1023 void test_ksLookupByName()
1025 printf ("Test lookup by name\n");
1032 KeySet *ks = ksNew (30,
1033 k[0]=keyNew (name[0] = "user/rem3", KEY_REMOVE, KEY_DIR, KEY_END),
1034 k[1]=keyNew (name[1] = "user/rem2", KEY_REMOVE, KEY_DIR, KEY_END),
1035 k[2]=keyNew (name[2] = "user/rem1/key2", KEY_REMOVE, KEY_END),
1036 k[3]=keyNew (name[3] = "user/rem1/key1", KEY_REMOVE, KEY_END),
1037 k[4]=keyNew (name[4] = "user/rem1", KEY_REMOVE, KEY_DIR, KEY_END),
1038 k[5]=keyNew (name[5] = "user/dir1", KEY_DIR, KEY_END),
1039 k[6]=keyNew (name[6] = "user/dir1/key1", KEY_VALUE, "value1", KEY_END),
1040 k[7]=keyNew (name[7] = "user/dir1/key2", KEY_VALUE, "value2", KEY_END),
1041 k[8]=keyNew (name[8] = "user/dir1/key3", KEY_VALUE, "value3", KEY_END),
1042 k[9]=keyNew (name[9] = "user/dir1/key4", KEY_VALUE, "value4", KEY_END),
1043 k[10]=keyNew (name[10] ="user/dir1/.inactive1", KEY_COMMENT, "key is inactive", KEY_END),
1044 k[11]=keyNew (name[11] ="user/dir1/.inactive2", KEY_COMMENT, "additional information", KEY_END),
1045 k[12]=keyNew (name[12] ="user:max/dir2", KEY_DIR, KEY_END),
1046 k[13]=keyNew (name[13] ="user:max/dir2/key1", KEY_VALUE, "value1", KEY_END),
1047 k[14]=keyNew (name[14] ="user/dir2/key2", KEY_VALUE, "value2", KEY_END),
1048 k[15]=keyNew (name[15] ="user/dir2/key3", KEY_VALUE, "value3", KEY_END),
1049 k[16]=keyNew (name[16] ="user:hugo/dir2/key4", KEY_VALUE, "value4", KEY_END),
1050 k[17]=keyNew (name[17] ="user/dir3", KEY_DIR, KEY_END),
1051 k[18]=keyNew (name[18] ="user/dir3/key1", KEY_VALUE, "value1", KEY_END),
1052 k[19]=keyNew (name[19] ="user:sb/dir3/.inactive1", KEY_COMMENT, "key is inactive", KEY_END),
1053 k[20]=keyNew (name[20] ="user/dir3/.inactive2", KEY_COMMENT, "a users comment", KEY_END),
1054 k[21]=keyNew (name[21] ="user/dir4", KEY_DIR, KEY_END),
1055 k[22]=keyNew (name[22] ="user/dir5", KEY_DIR, KEY_END),
1058 name[23] = "user/DiR1";
1059 name[24] = "user/DiR1/KEY1";
1060 name[25] = "user:wrongowner/DiR1/KEY1";
1061 name[26] = "user:nop/DiR1/KEY1";
1062 name[27] = "user:wrongowner/dir1/key1";
1063 name[28] = "user:nop/dir1/key1";
1064 name[29] = "user:wrongowner/dir2/key1";
1065 name[30] = "user/dir2/key1";
1066 name[31] = "user:max/dir2/key1";
1070 succeed_if (ksLookupByName(0, name[23], 0) == 0, "null pointer");
1071 succeed_if (ksLookup(ks, 0, 0) == 0, "null pointer");
1073 for (i=0; i<100; i++)
1077 succeed_if (ksLookupByName(ks, name[j], 0)==0, "found removed key");
1079 succeed_if (ksLookupByName(ks, name[j], 0)==k[j], "did not found key");
1080 succeed_if (ksLookupByName(ks, name[23], KDB_O_NOCASE) == k[5], "did not found key");
1081 succeed_if (ksLookupByName(ks, name[23], 0) == 0, "found wrong key");
1082 succeed_if (ksLookupByName(ks, name[24], KDB_O_NOCASE) == k[6], "did not found key");
1083 succeed_if (ksLookupByName(ks, name[24], 0) == 0, "found wrong key");
1084 succeed_if (ksLookupByName(ks, name[25], KDB_O_NOCASE) == k[6], "did not found key");
1085 succeed_if (ksLookupByName(ks, name[25], KDB_O_WITHOWNER|KDB_O_NOCASE) == 0, "found wrong key");
1086 succeed_if (ksLookupByName(ks, name[28], 0) == k[6], "did not found key");
1087 succeed_if (ksLookupByName(ks, name[28], KDB_O_WITHOWNER) == 0, "found wrong key");
1088 succeed_if (ksLookupByName(ks, name[31], KDB_O_WITHOWNER) == k[13], "did not found key");
1089 /* Empty lines to add more tests:
1090 succeed_if (ksLookupByName(ks, name[], ) == name[], "did not found key");
1091 succeed_if (ksLookupByName(ks, name[], ) == 0, "found wrong key");
1099 void test_ksLookupName()
1102 KeySet *ks= ksNew(0);
1104 printf ("Test lookup functions\n");
1105 succeed_if (ksNeedSort (ks) == 1, "sort state not correct");
1107 ksAppendKey(ks, keyNew("user/domain/key", KEY_VALUE, "domainvalue",
1108 KEY_OWNER, "markus", KEY_END));
1109 ksAppendKey(ks, keyNew("user/single/key", KEY_VALUE, "singlevalue", KEY_END));
1110 ksAppendKey(ks, keyNew("user/named/key", KEY_VALUE, "myvalue", KEY_END));
1111 ksAppendKey(ks, keyNew("system/named/key", KEY_VALUE, "syskey", KEY_END));
1112 ksAppendKey(ks, keyNew("system/sysonly/key", KEY_VALUE, "sysonlykey", KEY_END));
1113 ksAppendKey(ks, keyNew("user/named/bin", KEY_TYPE, KEY_TYPE_BINARY, KEY_SIZE, 10,
1114 KEY_VALUE, "binary\1\2data", KEY_END));
1115 ksAppendKey(ks, keyNew("system/named/bin", KEY_TYPE, KEY_TYPE_BINARY, KEY_SIZE, 10,
1116 KEY_VALUE, "sys\1bin\2", KEY_END));
1117 ksAppendKey(ks, keyNew("system/named/key", KEY_TYPE, KEY_TYPE_BINARY, KEY_SIZE, 10,
1118 KEY_VALUE, "syskey", KEY_END));
1119 succeed_if (ksGetSize(ks) == 8, "could not append all keys");
1121 succeed_if (ksNeedSort (ks) == 1, "sort state not correct");
1123 // a positive testcase
1124 found = ksLookupByName (ks, "user/named/key", 0);
1125 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1126 succeed_if (ksNeedSort (ks) == 0, "sort state not correct");
1127 ksAppendKey(ks, keyNew("user/single/key", KEY_VALUE, "singlevalue", KEY_END));
1128 succeed_if (ksNeedSort (ks) == 1, "sort state not correct");
1130 succeed_if (found != 0, "did not found correct name");
1131 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1132 succeed_if (strcmp (keyName(found), "user/named/key") == 0, "name not correct in found key");
1133 succeed_if (strcmp (keyValue(found), "myvalue") == 0, "not correct value in found key");
1135 // here you can't find the keys
1136 succeed_if (ksLookupByName (ks, "named/key", 0) == 0, "not valid keyname");
1137 succeed_if (ksNeedSort (ks) == 0, "sort state not correct");
1138 succeed_if (ksLookupByName (ks, "u/named/key", 0) == 0, "not valid keyname");
1139 succeed_if (ksLookupByName (ks, "usea/named/key", 0) == 0, "not valid keyname");
1140 succeed_if (ksLookupByName (ks, " user/named/key", 0) == 0, "found key with bad prefix");
1142 succeed_if (ksLookupByName (ks, "user/named/Key", 0) == 0, "found wrong case key");
1143 succeed_if (ksLookupByName (ks, "User/Named/key", 0) == 0, "found wrong case key");
1144 succeed_if (ksLookupByName (ks, "User/named/key", 0) == 0, "found wrong case key");
1145 succeed_if (ksLookupByName (ks, "user/NAMED/key", 0) == 0, "found wrong case key");
1146 succeed_if (ksLookupByName (ks, "USER/NAMED/KEY", 0) == 0, "found wrong case key");
1148 succeed_if (ksLookupByName (ks, "user/named/keys", 0) == 0, "wrong postfix");
1149 succeed_if (ksLookupByName (ks, "user/named/key_", 0) == 0, "wrong postfix");
1151 succeed_if (ksLookupByName (ks, "user/named/k/ey", 0) == 0, "seperation that should be");
1152 succeed_if (ksLookupByName (ks, "user/na/med/key", 0) == 0, "seperation that should be");
1154 succeed_if (ksLookupByName (ks, "system/domain/key", 0) == 0, "found key in wrong domain");
1156 //now try to find them, and compare value
1157 found = ksLookupByName (ks, "user/domain/key", 0);
1158 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1159 succeed_if (found != 0, "did not found correct name");
1160 succeed_if (strcmp (keyName(found), "user/domain/key") == 0, "name not correct in found key");
1161 succeed_if (strcmp (keyValue(found), "domainvalue") == 0, "not correct value in found key");
1163 found = ksLookupByName (ks, "user/single/key", 0);
1164 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1165 succeed_if (found != 0, "did not found correct name");
1166 succeed_if (strcmp (keyName(found), "user/single/key") == 0, "name not correct in found key");
1167 succeed_if (strcmp (keyValue(found), "singlevalue") == 0, "not correct value in found key");
1169 found = ksLookupByName (ks, "system/named/key", 0);
1170 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1171 succeed_if (found != 0, "did not found correct name");
1172 succeed_if (strcmp (keyName(found), "system/named/key") == 0, "name not correct in found key");
1173 succeed_if (strcmp (keyValue(found), "syskey") == 0, "not correct value in found key");
1175 found = ksLookupByName (ks, "user/named/bin", 0);
1176 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1177 succeed_if (found != 0, "did not found correct name");
1178 succeed_if (strcmp (keyName(found), "user/named/bin") == 0, "name not correct in found key");
1179 succeed_if (strncmp (keyValue(found), "binary\1\2data",10) == 0, "not correct value in found key");
1181 found = ksLookupByName (ks, "user/named/key", 0);
1182 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1183 succeed_if (found != 0, "could not find same key again");
1184 succeed_if (strcmp (keyName(found), "user/named/key") == 0, "name not correct in found key");
1185 succeed_if (strcmp (keyValue(found), "myvalue") == 0, "not correct value in found key");
1187 printf ("Test nocase lookup functions\n");
1188 found = ksLookupByName (ks, "user/named/key", KDB_O_NOCASE);
1189 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1190 succeed_if (found != 0, "could not find same key again, nocase");
1191 succeed_if (strcmp (keyName(found), "user/named/key") == 0, "name not correct in found key");
1192 succeed_if (strcmp (keyValue(found), "myvalue") == 0, "not correct value in found key");
1194 found = ksLookupByName (ks, "user/NameD/KeY", KDB_O_NOCASE);
1195 succeed_if (found != 0, "could not find same key again, nocase used");
1196 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1197 succeed_if (strcmp (keyName(found), "user/named/key") == 0, "name not correct in found key");
1198 succeed_if (strcmp (keyValue(found), "myvalue") == 0, "not correct value in found key");
1200 found = ksLookupByName (ks, "user/NameD/KEY", KDB_O_NOCASE);
1201 succeed_if (found != 0, "could not find same key again, nocase used");
1202 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1203 succeed_if (strcmp (keyName(found), "user/named/key") == 0, "name not correct in found key");
1204 succeed_if (strcmp (keyValue(found), "myvalue") == 0, "not correct value in found key");
1206 printf ("Test cascading lookup functions\n");
1207 found = ksLookupByName (ks, "/named/key", 0);
1208 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1209 succeed_if (found != 0, "cascading search failed");
1210 succeed_if (strcmp (keyName(found), "user/named/key") == 0, "name not correct in found key");
1211 succeed_if (strcmp (keyValue(found), "myvalue") == 0, "not correct value in found key");
1213 found = ksLookupByName (ks, "/single/Key", KDB_O_NOCASE);
1214 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1215 succeed_if (found != 0, "could not find same key again, nocase used");
1216 succeed_if (strcmp (keyName(found), "user/single/key") == 0, "name not correct in found key");
1217 succeed_if (strcmp (keyValue(found), "singlevalue") == 0, "not correct value in found key");
1219 found = ksLookupByName (ks, "/sysonly/key", 0);
1220 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1221 succeed_if (found != 0, "could not find same key again, nocase used");
1222 succeed_if (strcmp (keyName(found), "system/sysonly/key") == 0, "name not correct in found key");
1223 succeed_if (strcmp (keyValue(found), "sysonlykey") == 0, "not correct value in found key");
1225 succeed_if (ksLookupByName (ks, "/named/", 0) == 0, "found part of key with cascading");
1226 succeed_if (ksLookupByName (ks, "/named/keyd", 0) == 0, "found part of key with cascading, bad postfix");
1228 printf ("Test domain lookup functions\n");
1229 found = ksLookupByName (ks, "user:markus/domain/key", KDB_O_WITHOWNER);
1230 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1231 succeed_if (found != 0, "could not find domain key");
1232 succeed_if (strcmp (keyValue(found), "domainvalue") == 0, "not correct value in domain key");
1233 succeed_if (ksLookupByName (ks, "user:hugo/domain/key", KDB_O_WITHOWNER) == 0, "found key in wrong domain");
1234 succeed_if (ksLookupByName (ks, "user:y/domain/key", KDB_O_WITHOWNER) == 0, "found key in wrong domain");
1235 succeed_if (ksLookupByName (ks, "user:markuss/domain/key", KDB_O_WITHOWNER) == 0, "found key in wrong domain");
1236 succeed_if (ksLookupByName (ks, "user:marku/domain/key", KDB_O_WITHOWNER) == 0, "found key in wrong domain");
1242 void test_ksLookupNameRemove()
1245 KeySet *ks=ksNew(0);
1246 printf ("Test lookup functions with removed keys\n");
1247 ksAppendKey(ks, keyNew("user/a", KEY_REMOVE, KEY_END));
1248 ksAppendKey(ks, keyNew("user/e", KEY_END));
1249 ksAppendKey(ks, keyNew("user/b", KEY_REMOVE, KEY_END));
1250 ksAppendKey(ks, keyNew("user/b", KEY_END));
1251 ksAppendKey(ks, keyNew("user/d", KEY_REMOVE, KEY_END));
1252 ksAppendKey(ks, keyNew("user/c", KEY_END));
1253 ksAppendKey(ks, keyNew("user/c", KEY_REMOVE, KEY_END));
1254 ksAppendKey(ks, keyNew("user/g", KEY_REMOVE, KEY_END));
1255 ksAppendKey(ks, keyNew("user/h", KEY_REMOVE, KEY_END));
1256 ksAppendKey(ks, keyNew("user/h", KEY_END));
1257 ksAppendKey(ks, keyNew("user/f", KEY_REMOVE, KEY_END));
1259 found = ksLookupByName (ks, "user/e", 0);
1260 succeed_if (found != 0, "could not find same key again, nocase used");
1261 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1262 succeed_if (strcmp (keyName(found), "user/e") == 0, "name not correct in found key");
1264 found = ksLookupByName (ks, "user/b", 0);
1265 succeed_if (found != 0, "could not find same key again, nocase used");
1266 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1267 succeed_if (strcmp (keyName(found), "user/b") == 0, "name not correct in found key");
1269 found = ksLookupByName (ks, "user/c", 0);
1270 succeed_if (found != 0, "could not find same key again, nocase used");
1271 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1272 succeed_if (strcmp (keyName(found), "user/c") == 0, "name not correct in found key");
1274 found = ksLookupByName (ks, "user/h", 0);
1275 succeed_if (found != 0, "could not find same key again, nocase used");
1276 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1277 succeed_if (strcmp (keyName(found), "user/h") == 0, "name not correct in found key");
1279 succeed_if (ksLookupByName (ks, "user/nonexists", 0) == 0, "found nonexists key");
1280 succeed_if (ksLookupByName (ks, "user/g", 0) == 0, "found removed key");
1281 succeed_if (ksLookupByName (ks, "user/f", 0) == 0, "found removed key");
1286 void test_ksLookupNameAll()
1290 KeySet *ks= ksNew(0);
1291 printf ("Test lookup functions with KDB_O_NOALL\n");
1292 ksAppendKey(ks, keyNew("user/a", KEY_END));
1293 ksAppendKey(ks, keyNew("user/b", KEY_END));
1294 ksAppendKey(ks, keyNew("user/c", KEY_END));
1295 ksAppendKey(ks, keyNew("user/d", KEY_END));
1296 ksAppendKey(ks, keyNew("user/e", KEY_END));
1297 ksAppendKey(ks, keyNew("user/00", KEY_DIR, KEY_END));
1298 ksAppendKey(ks, keyNew("user/00/a", KEY_END));
1299 ksAppendKey(ks, keyNew("user/00/b", KEY_END));
1300 ksAppendKey(ks, keyNew("user/00/c", KEY_END));
1301 ksAppendKey(ks, keyNew("user/01", KEY_DIR, KEY_END));
1302 ksAppendKey(ks, keyNew("user/01/a", KEY_END));
1303 ksAppendKey(ks, keyNew("user/01/b", KEY_END));
1304 ksAppendKey(ks, keyNew("user/01/c", KEY_END));
1305 ksAppendKey(ks, keyNew("user/01/d", KEY_END));
1306 ksAppendKey(ks, keyNew("user/02", KEY_DIR, KEY_END));
1307 ksAppendKey(ks, keyNew("user/02/a", KEY_END));
1308 ksAppendKey(ks, keyNew("user/02/b", KEY_END));
1309 ksAppendKey(ks, keyNew("user/02/c", KEY_END));
1310 ksAppendKey(ks, keyNew("user/02/d", KEY_END));
1311 ksAppendKey(ks, keyNew("user/02/e", KEY_END));
1312 ksAppendKey(ks, keyNew("user/02/f", KEY_END));
1314 found = ksLookupByName (ks, "user/e", KDB_O_NOALL);
1315 succeed_if (found != 0, "could not find key");
1316 succeed_if (strcmp (keyName(found), "user/e") == 0, "name not correct in found key");
1318 found = ksLookupByName (ks, "user/e", KDB_O_NOALL);
1319 succeed_if (found == 0, "should not find");
1322 found = ksLookupByName (ks, "user/a", KDB_O_NOALL);
1323 succeed_if (found != 0, "could not find key");
1324 succeed_if (strcmp (keyName(found), "user/a") == 0, "name not correct in found key");
1326 found = ksLookupByName (ks, "user/e", KDB_O_NOALL);
1327 succeed_if (found != 0, "could not find key");
1328 succeed_if (strcmp (keyName(found), "user/e") == 0, "name not correct in found key");
1330 found = ksLookupByName (ks, "user/00", KDB_O_NOALL);
1331 succeed_if (found != 0, "could not find key");
1332 succeed_if (keyIsDir (found) == 1, "should be dir");
1333 succeed_if (strcmp (keyName(found), "user/00") == 0, "name not correct in found key");
1335 found = ksLookupByName (ks, "user/01", KDB_O_NOALL);
1336 succeed_if (found != 0, "could not find key");
1337 succeed_if (keyIsDir (found) == 1, "should be dir");
1338 succeed_if (strcmp (keyName(found), "user/01") == 0, "name not correct in found key");
1340 found = ksNext (ks);
1341 succeed_if (found != 0, "could not get next key");
1342 succeed_if (strcmp (keyName(found), "user/01/a") == 0, "name not correct in next key");
1344 found = ksLookupByName (ks, "user/02", KDB_O_NOALL);
1345 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1346 succeed_if (found != 0, "could not find key");
1347 succeed_if (keyIsDir (found) == 1, "should be dir");
1348 succeed_if (strcmp (keyName(found), "user/02") == 0, "name not correct in found key");
1350 cursor = ksGetCursor (ks);
1351 found = ksLookupByName (ks, "user/01", KDB_O_NOALL);
1352 succeed_if (ksGetCursor(ks) == cursor, "cursor should not change");
1353 succeed_if (found == 0, "should not find");
1356 found = ksLookupByName (ks, "user/a", KDB_O_NOALL | KDB_O_NOCASE);
1357 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1358 succeed_if (found != 0, "could not find key");
1359 succeed_if (strcmp (keyName(found), "user/a") == 0, "name not correct in found key");
1361 found = ksLookupByName (ks, "user/E", KDB_O_NOALL | KDB_O_NOCASE);
1362 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1363 succeed_if (found != 0, "could not find key");
1364 succeed_if (strcmp (keyName(found), "user/e") == 0, "name not correct in found key");
1366 found = ksLookupByName (ks, "user/00", KDB_O_NOALL | KDB_O_NOCASE);
1367 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1368 succeed_if (found != 0, "could not find key");
1369 succeed_if (keyIsDir (found) == 1, "should be dir");
1370 succeed_if (strcmp (keyName(found), "user/00") == 0, "name not correct in found key");
1372 found = ksLookupByName (ks, "user/01", KDB_O_NOALL | KDB_O_NOCASE);
1373 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1374 succeed_if (found != 0, "could not find key");
1375 succeed_if (keyIsDir (found) == 1, "should be dir");
1376 succeed_if (strcmp (keyName(found), "user/01") == 0, "name not correct in found key");
1378 found = ksNext (ks);
1379 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1380 succeed_if (found != 0, "could not get next key");
1381 succeed_if (strcmp (keyName(found), "user/01/a") == 0, "name not correct in next key");
1383 found = ksLookupByName (ks, "user/02", KDB_O_NOALL | KDB_O_NOCASE);
1384 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1385 succeed_if (found != 0, "could not find key");
1386 succeed_if (keyIsDir (found) == 1, "should be dir");
1387 succeed_if (strcmp (keyName(found), "user/02") == 0, "name not correct in found key");
1389 found = ksLookupByName (ks, "user/02/F", KDB_O_NOALL | KDB_O_NOCASE);
1390 succeed_if (ksCurrent(ks) == found, "current not set correctly");
1391 succeed_if (found != 0, "could not find key");
1392 succeed_if (strcmp (keyName(found), "user/02/f") == 0, "name not correct in found key");
1394 cursor = ksGetCursor (ks);
1395 found = ksLookupByName (ks, "user/a", KDB_O_NOALL | KDB_O_NOCASE);
1396 succeed_if (ksGetCursor(ks) == cursor, "cursor should stay as is if not found");
1397 succeed_if (found == 0, "should not find");
1400 found = ksLookupByName (ks, "user/a", KDB_O_NOALL | KDB_O_WITHOWNER | KDB_O_NOCASE);
1401 succeed_if (found != 0, "could not find key");
1402 succeed_if (strcmp (keyName(found), "user/a") == 0, "name not correct in found key");
1404 found = ksLookupByName (ks, "user/E", KDB_O_NOALL | KDB_O_WITHOWNER | KDB_O_NOCASE);
1405 succeed_if (found != 0, "could not find key");
1406 succeed_if (strcmp (keyName(found), "user/e") == 0, "name not correct in found key");
1408 found = ksLookupByName (ks, "user/00", KDB_O_NOALL | KDB_O_WITHOWNER | KDB_O_NOCASE);
1409 succeed_if (found != 0, "could not find key");
1410 succeed_if (keyIsDir (found) == 1, "should be dir");
1411 succeed_if (strcmp (keyName(found), "user/00") == 0, "name not correct in found key");
1413 found = ksLookupByName (ks, "user/01", KDB_O_NOALL | KDB_O_WITHOWNER | KDB_O_NOCASE);
1414 succeed_if (found != 0, "could not find key");
1415 succeed_if (keyIsDir (found) == 1, "should be dir");
1416 succeed_if (strcmp (keyName(found), "user/01") == 0, "name not correct in found key");
1418 found = ksNext (ks);
1419 succeed_if (found != 0, "could not get next key");
1420 succeed_if (strcmp (keyName(found), "user/01/a") == 0, "name not correct in next key");
1422 found = ksLookupByName (ks, "user/02", KDB_O_NOALL | KDB_O_WITHOWNER | KDB_O_NOCASE);
1423 succeed_if (found != 0, "could not find key");
1424 succeed_if (keyIsDir (found) == 1, "should be dir");
1425 succeed_if (strcmp (keyName(found), "user/02") == 0, "name not correct in found key");
1427 found = ksLookupByName (ks, "user:notvalid/02/F", KDB_O_NOALL | KDB_O_WITHOWNER | KDB_O_NOCASE);
1428 succeed_if (found == 0, "should not find key");
1434 void test_ksLookupValue()
1436 KeySet *ks = ksNew(0);
1438 printf ("test lookups for values\n");
1440 ksAppendKey(ks, keyNew("user/1", KEY_VALUE, "singlevalue", KEY_END));
1441 ksAppendKey(ks, keyNew("user/2", KEY_VALUE, "myvalue", KEY_END));
1442 ksAppendKey(ks, keyNew("user/3", KEY_VALUE, "syskey", KEY_END));
1444 ksAppendKey(ks, keyNew("user/b1", KEY_TYPE, KEY_TYPE_BINARY, KEY_SIZE, 10,
1445 KEY_VALUE, "binary\1\2data", KEY_END));
1446 ksAppendKey(ks, keyNew("user/b2", KEY_TYPE, KEY_TYPE_BINARY, KEY_SIZE, 10,
1447 KEY_VALUE, "sys\1bin\2", KEY_END));
1448 ksAppendKey(ks, keyNew("user/b3", KEY_TYPE, KEY_TYPE_BINARY, KEY_SIZE, 10,
1449 KEY_VALUE, "sy\1\33\12\32skey", KEY_END));
1450 succeed_if(ksGetSize(ks) == 6, "could not append keys");
1452 succeed_if (ksLookupByString (ks, "value", 0) == 0, "found part of value");
1453 succeed_if (ksLookupByString (ks, " singlevalue", 0) == 0, "prefix of value");
1454 succeed_if (ksLookupByString (ks, "/singlevalue", 0) == 0, "prefix of value");
1455 succeed_if (ksLookupByString (ks, "singlevalue ", 0) == 0, "postfix of value");
1457 found = ksLookupByString(ks, "singlevalue", 0);
1458 succeed_if (found != 0, "could not find value");
1459 succeed_if (strcmp (keyName(found), "user/1") == 0, "not correct key found");
1461 found = ksLookupByString(ks, "singlevalue", 0);
1462 succeed_if (found != 0, "could not find value again");
1463 succeed_if (strcmp (keyName(found), "user/1") == 0, "not correct key found");
1465 found = ksLookupByString(ks, "myvalue", 0);
1466 succeed_if (found != 0, "could not find value");
1467 succeed_if (strcmp (keyName(found), "user/2") == 0, "not correct key found");
1469 found = ksLookupByString(ks, "syskey", 0);
1470 succeed_if (found != 0, "could not find value");
1471 succeed_if (strcmp (keyName(found), "user/3") == 0, "not correct key found");
1474 found = ksLookupByString(ks, "singlevalue", KDB_O_NOALL);
1475 succeed_if (found != 0, "could not find value");
1476 succeed_if (strcmp (keyName(found), "user/1") == 0, "not correct key found");
1478 found = ksLookupByString(ks, "singlevalue", 0);
1479 succeed_if (found != 0, "could not find value again");
1480 succeed_if (strcmp (keyName(found), "user/1") == 0, "not correct key found");
1483 found = ksLookupByString(ks, "myvalue", KDB_O_NOALL);
1484 succeed_if (found != 0, "could not find value");
1485 succeed_if (strcmp (keyName(found), "user/2") == 0, "not correct key found");
1487 found = ksLookupByString(ks, "syskey", 0);
1488 succeed_if (found != 0, "could not find value");
1489 succeed_if (strcmp (keyName(found), "user/3") == 0, "not correct key found");
1491 // TODO: BUG found = ksLookupByString(ks, "singlevalue", KDB_O_NOALL);
1492 // succeed_if (found == 0, "could find value");
1494 // found = ksLookupByString(ks, "singlevalue", KDB_O_NOALL);
1495 // succeed_if (found == 0, "found value again");
1498 found = ksLookupByString(ks, "myvalue", KDB_O_NOALL);
1499 succeed_if (found != 0, "could not find value");
1500 succeed_if (strcmp (keyName(found), "user/2") == 0, "not correct key found");
1502 found = ksLookupByString(ks, "syskey", 0);
1503 succeed_if (found != 0, "could not find value");
1504 succeed_if (strcmp (keyName(found), "user/3") == 0, "not correct key found");
1506 found = ksLookupByString(ks, "syskey", KDB_O_NOALL);
1507 succeed_if (found != 0, "could not find value");
1508 succeed_if (strcmp (keyName(found), "user/3") == 0, "not correct key found");
1510 found = ksLookupByString(ks, "syskey", KDB_O_NOALL);
1511 succeed_if (found == 0, "found value");
1517 //copied out from example
1518 void test_ksExample()
1520 KeySet *ks=ksNew(0);
1523 ksAppendKey(ks,keyNew(0)); // an empty key
1525 ksAppendKey(ks,keyNew("user/sw", // the name of the key
1526 KEY_END)); // no more args
1528 ksAppendKey(ks,keyNew("user/tmp/ex1",
1529 KEY_VALUE,"some data", // set a string value
1530 KEY_END)); // end of args
1532 ksAppendKey(ks,keyNew("user/tmp/ex2",
1533 KEY_VALUE,"some data", // with a simple value
1534 KEY_MODE,0777, // permissions
1535 KEY_END)); // end of args
1537 ksAppendKey(ks,keyNew("user/tmp/ex4",
1538 KEY_TYPE,KEY_TYPE_BINARY, // key type
1539 KEY_SIZE,7, // assume binary length 7
1540 KEY_VALUE,"some data", // value that will be truncated in 7 bytes
1541 KEY_COMMENT,"value is truncated",
1542 KEY_OWNER,"root", // owner (not uid) is root
1543 KEY_UID,0, // root uid
1544 KEY_END)); // end of args
1546 ksAppendKey(ks,keyNew("user/tmp/ex5",
1547 KEY_TYPE, KEY_TYPE_BINARY, // binary value
1549 KEY_VALUE,"some data", // value that will be truncated in 7 bytes
1550 KEY_COMMENT,"value is truncated",
1551 KEY_OWNER,"root", // owner (not uid) is root
1552 KEY_UID,0, // root uid
1553 KEY_END)); // end of args
1559 succeed_if(key != NULL, "keyNew: Unable to create a new empty key");
1562 succeed_if(key != NULL, "keyNew: Unable to create a key with name");
1563 succeed_if(strcmp(keyName(key), "user/sw") == 0, "keyNew: Key's name setted incorrectly");
1568 #define MAX_SIZE 200
1569 void test_ksCommonParentName()
1571 char ret [MAX_SIZE+1];
1572 KeySet *ks = ksNew (10,
1573 keyNew("system/sw/xorg/Monitors/Monitor1/vrefresh",0),
1574 keyNew("system/sw/xorg/Monitors/Monitor1/hrefresh",0),
1575 keyNew("system/sw/xorg/Monitors/Monitor2/vrefresh",0),
1576 keyNew("system/sw/xorg/Monitors/Monitor2/hrefresh",0),
1577 keyNew("system/sw/xorg/Devices/Device1/driver",0),
1578 keyNew("system/sw/xorg/Devices/Device1/mode",0),KS_END);
1580 printf ("Test common parentname\n");
1583 succeed_if (ksGetCommonParentName(ks, ret, MAX_SIZE) > 0, "could not find correct parentname");
1584 succeed_if (strcmp (ret, "system/sw/xorg") == 0, "parentname not correct");
1589 keyNew("user",0),KS_END);
1590 succeed_if (ksGetCommonParentName(ks, ret, MAX_SIZE) == 0, "could find correct parentname");
1591 succeed_if (strcmp (ret, "") == 0, "parentname not empty");
1595 keyNew("system/some/thing",0),
1596 keyNew("system/other/thing",0), KS_END);
1597 succeed_if (ksGetCommonParentName(ks, ret, MAX_SIZE) == 7, "could find correct parentname");
1598 succeed_if (strcmp (ret, "system") == 0, "parentname not empty");
1602 keyNew("system/here/in/deep/goes/ok/thing",0),
1603 keyNew("system/here/in/deep/goes/ok/other/thing",0),
1605 succeed_if (ksGetCommonParentName(ks, ret, MAX_SIZE) > 0, "could find correct parentname");
1606 succeed_if (strcmp (ret, "system/here/in/deep/goes/ok") == 0, "parentname not empty");
1610 keyNew("system/here/in/deep/goes/ok/thing",0),
1611 keyNew("system/here/in/deep/goes/ok/other/thing",0),
1612 keyNew("user/unique/thing",0),KS_END);
1613 succeed_if (ksGetCommonParentName(ks, ret, MAX_SIZE) == 0, "could find correct parentname");
1614 succeed_if (strcmp (ret, "") == 0, "parentname not empty");
1618 keyNew("user/unique/thing",0),KS_END);
1619 succeed_if (ksGetCommonParentName(ks, ret, MAX_SIZE) > 0, "could find correct parentname");
1620 succeed_if (strcmp (ret, "user/unique/thing") == 0, "parentname not empty");
1624 void test_ksAppend()
1628 printf ("Test appending keys\n");
1632 KeySet *testDirectBelow =
1634 KeySet *testReturned =
1637 parentKey[0] = keyNew ("user/test/keyset", KEY_END);
1638 parentKey[1] = keyNew ("user/test/keyset/dir1", KEY_END);
1641 /* A real world example out in kdb.c */
1644 KeySet *tmp = ksNew(ksGetSize(returned), KS_END);
1645 KeySet *keys = ksNew (0);
1647 /* add all keys direct below parentKey */
1648 ksRewind (returned);
1649 while ((current = ksPop(returned)) != 0)
1651 if (keyIsDirectBelow(parentKey[i], current))
1653 ksAppendKey(keys, current);
1655 ksAppendKey(tmp, current);
1658 ksAppend (returned, tmp);
1661 ksOutput (tmp, stdout, KDB_O_HEADER);
1662 ksOutput (returned, stdout, KDB_O_HEADER);
1663 printf (" ----- keys -------\n");
1664 ksOutput (keys, stdout, KDB_O_HEADER);
1669 compare_keyset (returned, testReturned, 0, 0);
1670 compare_keyset (keys, testDirectBelow, 0, 0);
1672 succeed_if (ksGetSize (tmp) == 84, "size not correct");
1673 succeed_if (ksGetSize (returned) == 84, "size not correct");
1674 succeed_if (ksGetSize (keys) == 18, "size not correct");
1676 succeed_if (ksGetAlloc (tmp) == 102, "alloc not correct");
1677 succeed_if (ksGetAlloc (returned) == 128, "alloc not correct");
1678 succeed_if (ksGetAlloc (keys) == 32, "alloc not correct");
1681 ksAppend (returned, keys); /* add the keys back */
1688 keyDel (parentKey[0]);
1689 keyDel (parentKey[1]);
1691 ksDel (testReturned);
1692 ksDel (testDirectBelow);
1698 /**A functional mode to keys.
1700 * Instead of writing your own loop you can write
1701 * a function working with a key and pass it to
1704 * The function will be executed for all keys in
1707 * @param ks the keyset to work with
1708 * @param func the function to execute on every key of the keyset
1709 * @return the sum of all return values
1710 * @return -1 if any function returned -1, the execution will stop there, but
1711 * ksCurrent() will tell you where it stopped.
1714 int ksForEach (KeySet *ks, int (*func) (Key *k))
1720 cursor_t cursor = ksGetCursor (ks);
1722 while ((current = ksNext (ks)) != 0)
1724 rc = func (current);
1725 if (rc == -1) return -1;
1728 ksSetCursor(ks, cursor);
1735 * filter is executed for every key in the keyset result. When it returns 0,
1736 * the key will be dropped, when it returns 1 it will be ksAppendKey()ed to result,
1737 * when it returns -1 the processing will be stopped. You can use ksCurrent()
1738 * on input to see where the problem was. Because of this input is not const,
1739 * apart from ksCurrent() the input will not be changed. The keys that have
1740 * been in result before will stay untouched.
1742 * @param result is the keyset where keys are added.
1743 * @param input is the keyset the filter works on.
1744 * @param filter is the function to execute on every key of the keyset to decide if
1745 * it should be ksAppendKey()ed to the result.
1746 * @return the number of keys added on success
1747 * @return 0 when nothing was done
1748 * @return -1 when filter returned an error (-1), ksCurrent() of input will
1749 * be the problematic key.
1752 int ksFilter (KeySet *result, KeySet *input, int (*filter) (Key *k))
1758 cursor_t cursor = ksGetCursor (input);
1760 while ((current = ksNext (input)) != 0)
1762 rc = filter (current);
1763 if (rc == -1) return -1;
1767 ksAppendKey(result, keyDup (current));
1770 ksSetCursor(input, cursor);
1777 int add_string (Key *check) { return keySetString (check, "string"); }
1778 int add_comment (Key *check) { return keySetComment (check, "comment"); }
1779 int has_a (Key *check) { return keyName(check)[5]=='a'; }
1780 int below_a (Key *check) { return keyIsBelow(global_a, check); }
1781 int direct_below_a (Key *check) { return keyIsDirectBelow(global_a, check); }
1783 int sum_helper (Key *check) { return atoi(keyValue(check)); }
1784 int below_30 (Key *check) { return atoi(keyValue(check))<30; }
1785 int find_80 (Key *check) { int n=atoi(keyValue(check)); return n>70?-1:1; }
1787 void test_ksFunctional()
1792 KeySet *ks = ksNew (64,
1793 keyNew ("user/a/1", KEY_END),
1794 keyNew ("user/a/2", KEY_END),
1795 keyNew ("user/a/b/1", KEY_END),
1796 keyNew ("user/a/b/2", KEY_END),
1797 keyNew ("user/ab/2", KEY_END),
1798 keyNew ("user/b/1", KEY_END),
1799 keyNew ("user/b/2", KEY_END),
1801 global_a = keyNew ("user/a", KEY_END);
1803 printf ("Test functional style\n");
1805 ksForEach (ks, add_string);
1806 ksForEach (ks, add_comment);
1809 while ((current = ksNext(ks)) != 0)
1811 succeed_if (strcmp (keyValue (current), "string") == 0, "for each did not add string");
1812 succeed_if (strcmp (keyComment (current), "comment") == 0, "for each did not add comment");
1816 succeed_if (ksGetSize(ks) == 7, "initial size wrong");
1817 succeed_if (ksGetSize(out) == 0, "initial size wrong");
1818 ksFilter (out, ks, has_a);
1819 succeed_if (ksGetSize(out) == 5, "has_a cutted more then the user/b");
1823 ksFilter (out, ks, below_a);
1824 succeed_if (ksGetSize(out) == 4, "below_a cutted more then the user/ab/2");
1828 ksFilter (out, ks, direct_below_a);
1829 succeed_if (ksGetSize(out) == 2, "direct_below_a cutted more then the user/a/b/*");
1833 keyDel (global_a); global_a = 0;
1835 KeySet *values = ksNew (64,
1836 keyNew ("user/a", KEY_VALUE, "40", KEY_END),
1837 keyNew ("user/b", KEY_VALUE, "20", KEY_END),
1838 keyNew ("user/c", KEY_VALUE, "80", KEY_END),
1839 keyNew ("user/d", KEY_VALUE, "24", KEY_END),
1840 keyNew ("user/e", KEY_VALUE, "32", KEY_END),
1841 keyNew ("user/f", KEY_VALUE, "12", KEY_END),
1842 keyNew ("user/g", KEY_VALUE, "43", KEY_END),
1845 succeed_if (ksForEach (values, sum_helper) == 251, "could not sum up");
1847 KeySet *values_below_30 = ksNew (0);
1848 ksFilter (values_below_30, values, below_30);
1849 succeed_if (ksGetSize (values_below_30) == 3, "could not filter out everything above 30");
1850 succeed_if (ksForEach (values_below_30, sum_helper) == 56, "could not sum up");
1852 succeed_if (ksForEach (values, find_80) == -1, "did not find 80");
1853 found = ksCurrent (values);
1854 succeed_if (ksLookupByName (values, "user/c", 0) == found, "did not find 80");
1855 /*succeed_if (ksLookupByString (values, "80", 0) == found, "lookup by value did not find 80");*/
1857 ksDel (values_below_30);
1860 void test_ksLookupPop()
1862 printf ("Test ksLookup with KDB_O_POP\n");
1866 KeySet *small =ksNew (5,
1867 a=keyNew ("user/a", KEY_END),
1868 b=keyNew ("user/b", KEY_END),
1869 c=keyNew ("user/c", KEY_END), KS_END);
1873 succeed_if (ksCurrent(small) == a, "current not set correctly");
1875 succeed_if (ksGetSize(small) == 3, "could not append all keys");
1876 found = ksLookupByName (small, "user/a", KDB_O_POP);
1877 succeed_if (found == a, "not correct key");
1878 succeed_if (strcmp (keyName(found), "user/a") == 0, "name not correct in found key");
1879 succeed_if (ksCurrent(small) == 0, "current not set correctly");
1880 succeed_if (keyDel (found) == 0, "could not del popped key");
1884 succeed_if (ksCurrent(small) == c, "current not set correctly");
1886 succeed_if (ksGetSize(small) == 2, "could not append all keys");
1887 found = ksLookupByName (small, "user/b", KDB_O_POP);
1888 succeed_if (found == b, "not correct key");
1889 succeed_if (strcmp (keyName(found), "user/b") == 0, "name not correct in found key");
1890 succeed_if (ksCurrent(small) == c, "current not set correctly");
1891 succeed_if (keyDel (found) == 0, "could not del popped key");
1893 succeed_if (ksGetSize(small) == 1, "could not append all keys");
1894 found = ksLookupByName (small, "user/b", KDB_O_POP);
1895 succeed_if (found == 0, "found something, but shouldnt");
1896 succeed_if (ksCurrent(small) == c, "current not set correctly");
1898 succeed_if (ksGetSize(small) == 1, "could not append all keys");
1899 found = ksLookupByName (small, "user/c", KDB_O_POP);
1900 succeed_if (found == c, "not correct key");
1901 succeed_if (strcmp (keyName(found), "user/c") == 0, "name not correct in found key");
1902 succeed_if (ksCurrent(small) == 0, "current not set correctly");
1903 succeed_if (keyDel (found) == 0, "could not del popped key");
1905 succeed_if (ksGetSize(small) == 0, "could not append all keys");
1906 found = ksLookupByName (small, "user/d", KDB_O_POP);
1907 succeed_if (found == 0, "found something, but shouldnt");
1908 succeed_if (ksCurrent(small) == 0, "current not set correctly");
1912 KeySet *ks= ksNew(0);
1914 succeed_if (ksNeedSort (ks) == 1, "sort state not correct");
1916 ksAppendKey(ks, keyNew("user/domain/key", KEY_VALUE, "domainvalue",
1917 KEY_OWNER, "markus", KEY_END));
1918 ksAppendKey(ks, keyNew("user/single/key", KEY_VALUE, "singlevalue", KEY_END));
1919 ksAppendKey(ks, keyNew("user/named/key", KEY_VALUE, "myvalue", KEY_END));
1920 ksAppendKey(ks, keyNew("system/named/key", KEY_VALUE, "syskey", KEY_END));
1921 ksAppendKey(ks, keyNew("system/sysonly/key", KEY_VALUE, "sysonlykey", KEY_END));
1922 ksAppendKey(ks, keyNew("user/named/bin", KEY_TYPE, KEY_TYPE_BINARY, KEY_SIZE, 10,
1923 KEY_VALUE, "binary\1\2data", KEY_END));
1924 ksAppendKey(ks, keyNew("system/named/bin", KEY_TYPE, KEY_TYPE_BINARY, KEY_SIZE, 10,
1925 KEY_VALUE, "sys\1bin\2", KEY_END));
1926 ksAppendKey(ks, keyNew("system/named/key", KEY_TYPE, KEY_TYPE_BINARY, KEY_SIZE, 10,
1927 KEY_VALUE, "syskey", KEY_END));
1928 succeed_if (ksGetSize(ks) == 8, "could not append all keys");
1930 succeed_if (ksNeedSort (ks) == 1, "sort state not correct");
1932 // a positive testcase
1933 found = ksLookupByName (ks, "user/named/key", KDB_O_POP);
1934 succeed_if (ksGetSize(ks) == 7, "did not pop key");
1935 succeed_if (ksCurrent(ks) == 0, "current not set correctly");
1936 succeed_if (ksNeedSort (ks) == 0, "sort state not correct");
1937 ksAppendKey(ks, keyNew("user/single/key", KEY_VALUE, "singlevalue", KEY_END));
1938 succeed_if (ksGetSize(ks) == 8, "did not pop key");
1939 succeed_if (ksNeedSort (ks) == 1, "sort state not correct");
1940 succeed_if (found != 0, "did not found correct name");
1941 succeed_if (ksCurrent(ks) == 0, "current not set correctly");
1942 succeed_if (strcmp (keyName(found), "user/named/key") == 0, "name not correct in found key");
1943 succeed_if (strcmp (keyValue(found), "myvalue") == 0, "not correct value in found key");
1944 succeed_if (keyDel (found) == 0, "could not del popped key");
1946 // here you can't find the keys
1947 succeed_if (ksLookupByName (ks, "named/key", KDB_O_POP) == 0, "not valid keyname");
1948 succeed_if (ksNeedSort (ks) == 0, "sort state not correct");
1949 succeed_if (ksLookupByName (ks, "u/named/key", KDB_O_POP) == 0, "not valid keyname");
1950 succeed_if (ksLookupByName (ks, "usea/named/key", KDB_O_POP) == 0, "not valid keyname");
1951 succeed_if (ksLookupByName (ks, " user/named/key", KDB_O_POP) == 0, "found key with bad prefix");
1953 succeed_if (ksLookupByName (ks, "user/named/Key", KDB_O_POP) == 0, "found wrong case key");
1954 succeed_if (ksLookupByName (ks, "User/Named/key", KDB_O_POP) == 0, "found wrong case key");
1955 succeed_if (ksLookupByName (ks, "User/named/key", KDB_O_POP) == 0, "found wrong case key");
1956 succeed_if (ksLookupByName (ks, "user/NAMED/key", KDB_O_POP) == 0, "found wrong case key");
1957 succeed_if (ksLookupByName (ks, "USER/NAMED/KEY", KDB_O_POP) == 0, "found wrong case key");
1959 succeed_if (ksLookupByName (ks, "user/named/keys", KDB_O_POP) == 0, "wrong postfix");
1960 succeed_if (ksLookupByName (ks, "user/named/key_", KDB_O_POP) == 0, "wrong postfix");
1962 succeed_if (ksLookupByName (ks, "user/named/k/ey", KDB_O_POP) == 0, "seperation that should be");
1963 succeed_if (ksLookupByName (ks, "user/na/med/key", KDB_O_POP) == 0, "seperation that should be");
1965 succeed_if (ksLookupByName (ks, "system/domain/key", KDB_O_POP) == 0, "found key in wrong domain");
1967 //now try to find them, and compare value
1968 found = ksLookupByName (ks, "user/domain/key", KDB_O_POP);
1969 succeed_if (ksGetSize(ks) == 7, "did not pop key");
1970 succeed_if (ksCurrent(ks) == 0, "current not set correctly");
1971 succeed_if (found != 0, "did not found correct name");
1972 succeed_if (strcmp (keyName(found), "user/domain/key") == 0, "name not correct in found key");
1973 succeed_if (strcmp (keyValue(found), "domainvalue") == 0, "not correct value in found key");
1974 succeed_if (keyDel (found) == 0, "could not del popped key");
1976 found = ksLookupByName (ks, "user/single/key", KDB_O_POP);
1977 succeed_if (ksGetSize(ks) == 6, "did not pop key");
1978 succeed_if (ksCurrent(ks) == 0, "current not set correctly");
1979 succeed_if (found != 0, "did not found correct name");
1980 succeed_if (strcmp (keyName(found), "user/single/key") == 0, "name not correct in found key");
1981 succeed_if (strcmp (keyValue(found), "singlevalue") == 0, "not correct value in found key");
1982 succeed_if (keyDel (found) == 0, "could not del popped key");
1984 found = ksLookupByName (ks, "system/named/key", KDB_O_POP);
1985 succeed_if (ksGetSize(ks) == 5, "did not pop key");
1986 succeed_if (ksCurrent(ks) == 0, "current not set correctly");
1987 succeed_if (found != 0, "did not found correct name");
1988 succeed_if (strcmp (keyName(found), "system/named/key") == 0, "name not correct in found key");
1989 succeed_if (strcmp (keyValue(found), "syskey") == 0, "not correct value in found key");
1990 succeed_if (keyDel (found) == 0, "could not del popped key");
1992 found = ksLookupByName (ks, "user/named/bin", KDB_O_POP);
1993 succeed_if (ksGetSize(ks) == 4, "pop key");
1994 succeed_if (ksCurrent(ks) == 0, "current not set correctly");
1995 succeed_if (found != 0, "did not found correct name");
1996 succeed_if (strcmp (keyName(found), "user/named/bin") == 0, "name not correct in found key");
1997 succeed_if (strncmp (keyValue(found), "binary\1\2data",10) == 0, "not correct value in found key");
1998 succeed_if (keyDel (found) == 0, "could not del popped key");
2000 found = ksLookupByName (ks, "user/named/key", KDB_O_POP);
2001 succeed_if (ksGetSize(ks) == 4, "did not pop key");
2002 succeed_if (ksCurrent(ks) == 0, "current not set correctly");
2003 succeed_if (found == 0, "could find same key again");
2005 printf ("Test nocase lookup functions\n");
2006 found = ksLookupByName (ks, "user/named/key", KDB_O_NOCASE | KDB_O_POP);
2007 succeed_if (ksGetSize(ks) == 4, "key");
2008 succeed_if (ksCurrent(ks) == 0, "current not set correctly");
2009 succeed_if (found == 0, "could find same key again, nocase");
2011 ksAppendKey(ks, keyNew("user/named/key", KEY_VALUE, "myvalue", KEY_END));
2012 found = ksLookupByName (ks, "user/NameD/KeY", KDB_O_NOCASE | KDB_O_POP);
2013 succeed_if (ksGetSize(ks) == 4, "did not pop key");
2014 succeed_if (found != 0, "could not find same key again, nocase used");
2015 succeed_if (ksCurrent(ks) == 0, "current not set correctly");
2016 succeed_if (strcmp (keyName(found), "user/named/key") == 0, "name not correct in found key");
2017 succeed_if (strcmp (keyValue(found), "myvalue") == 0, "not correct value in found key");
2018 succeed_if (keyDel (found) == 0, "could not del popped key");
2020 ksAppendKey(ks, keyNew("user/named/key", KEY_VALUE, "myvalue", KEY_END));
2021 found = ksLookupByName (ks, "user/NameD/KEY", KDB_O_NOCASE | KDB_O_POP);
2022 succeed_if (ksGetSize(ks) == 4, "did not pop key");
2023 succeed_if (found != 0, "could not find same key again, nocase used");
2024 succeed_if (ksCurrent(ks) == 0, "current not set correctly");
2025 succeed_if (strcmp (keyName(found), "user/named/key") == 0, "name not correct in found key");
2026 succeed_if (strcmp (keyValue(found), "myvalue") == 0, "not correct value in found key");
2027 succeed_if (keyDel (found) == 0, "could not del popped key");
2029 ksAppendKey(ks, keyNew("user/named/key", KEY_VALUE, "myvalue", KEY_END));
2030 printf ("Test cascading lookup functions\n");
2031 found = ksLookupByName (ks, "/named/key", KDB_O_POP);
2032 succeed_if (ksGetSize(ks) == 4, "did not pop key");
2033 succeed_if (ksCurrent(ks) == 0, "current not set correctly");
2034 succeed_if (found != 0, "cascading search failed");
2035 succeed_if (strcmp (keyName(found), "user/named/key") == 0, "name not correct in found key");
2036 succeed_if (strcmp (keyValue(found), "myvalue") == 0, "not correct value in found key");
2037 succeed_if (keyDel (found) == 0, "could not del popped key");
2039 found = ksLookupByName (ks, "/single/Key", KDB_O_NOCASE | KDB_O_POP);
2040 succeed_if (ksGetSize(ks) == 3, "did not pop key");
2041 succeed_if (ksCurrent(ks) == 0, "current not set correctly");
2042 succeed_if (found != 0, "could not find same key again, nocase used");
2043 succeed_if (strcmp (keyName(found), "user/single/key") == 0, "name not correct in found key");
2044 succeed_if (strcmp (keyValue(found), "singlevalue") == 0, "not correct value in found key");
2045 succeed_if (keyDel (found) == 0, "could not del popped key");
2047 found = ksLookupByName (ks, "/sysonly/key", KDB_O_POP);
2048 succeed_if (ksCurrent(ks) == 0, "current not set correctly");
2049 succeed_if (ksGetSize(ks) == 2, "did not pop key");
2050 succeed_if (found != 0, "could not find same key again, nocase used");
2051 succeed_if (strcmp (keyName(found), "system/sysonly/key") == 0, "name not correct in found key");
2052 succeed_if (strcmp (keyValue(found), "sysonlykey") == 0, "not correct value in found key");
2053 succeed_if (keyDel (found) == 0, "could not del popped key");
2055 succeed_if (ksLookupByName (ks, "/named/", KDB_O_POP) == 0, "found part of key with cascading");
2056 succeed_if (ksLookupByName (ks, "/named/keyd", KDB_O_POP) == 0, "found part of key with cascading, bad postfix");
2058 ksAppendKey(ks, keyNew("user:markus/domain/key", KEY_VALUE, "domainvalue", KEY_END));
2059 printf ("Test domain lookup functions\n");
2060 found = ksLookupByName (ks, "user:markus/domain/key", KDB_O_WITHOWNER | KDB_O_POP);
2061 succeed_if (ksCurrent(ks) == 0, "current not set correctly");
2062 succeed_if (ksGetSize(ks) == 2, "did not pop key");
2063 succeed_if (found != 0, "could not find domain key");
2064 succeed_if (strcmp (keyValue(found), "domainvalue") == 0, "not correct value in domain key");
2065 succeed_if (ksLookupByName (ks, "user:hugo/domain/key", KDB_O_WITHOWNER | KDB_O_POP) == 0, "found key in wrong domain");
2066 succeed_if (ksLookupByName (ks, "user:y/domain/key", KDB_O_WITHOWNER | KDB_O_POP) == 0, "found key in wrong domain");
2067 succeed_if (ksLookupByName (ks, "user:markuss/domain/key", KDB_O_WITHOWNER | KDB_O_POP) == 0, "found key in wrong domain");
2068 succeed_if (ksLookupByName (ks, "user:marku/domain/key", KDB_O_WITHOWNER | KDB_O_POP) == 0, "found key in wrong domain");
2069 succeed_if (ksGetSize(ks) == 2, "did not pop key");
2070 succeed_if (keyDel (found) == 0, "could not del popped key");
2078 printf("KEYSET TESTS\n");
2079 printf("==================\n\n");
2093 test_ksLookupByName();
2094 test_ksLookupName();
2095 test_ksLookupNameRemove();
2096 test_ksLookupNameAll();
2097 /*test_ksLookupValue();*/
2099 test_ksCommonParentName();
2101 test_ksFunctional();
2104 printf("\ntest_ks RESULTS: %d test(s) done. %d error(s).\n", nbTest, nbError);