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 : #include <tests_internal.h>
10 :
11 2 : static void test_ksNew (void)
12 : {
13 2 : KeySet * ks = 0;
14 2 : KeySet * keys = ksNew (15, KS_END);
15 : KeySet * config;
16 :
17 2 : printf ("Test ks creation\n");
18 2 : exit_if_fail ((ks = ksNew (0, KS_END)) != 0, "could not create new keyset");
19 :
20 2 : succeed_if (ksAppendKey (ks, keyNew (0)) == -1, "could append a key with no name");
21 2 : succeed_if (ksAppendKey (ks, keyNew (0)) == -1, "could append a key with no name");
22 2 : succeed_if (ksAppendKey (ks, keyNew (0)) == -1, "could append a key with no name");
23 2 : succeed_if (ksGetSize (ks) == 0, "size not correct after 3 keys");
24 :
25 2 : KeySet * ks2 = ksNew (0, KS_END);
26 2 : ksCopy (ks2, ks);
27 2 : succeed_if (ksGetSize (ks2) == 0, "size not correct after 3 keys");
28 :
29 2 : succeed_if (ksAppendKey (ks, keyNew (0)) == -1, "could append a key with no name");
30 2 : succeed_if (ksAppendKey (ks, keyNew (0)) == -1, "could append a key with no name");
31 2 : succeed_if (ksAppendKey (ks, keyNew (0)) == -1, "could append a key with no name");
32 2 : succeed_if (ksGetSize (ks) == 0, "could not append 3 more keys");
33 :
34 2 : ksCopy (ks2, ks);
35 2 : succeed_if (ksGetSize (ks2) == 0, "could not append 3 more keys");
36 :
37 2 : ksClear (ks2); // useless, just test for double free
38 2 : ksCopy (ks2, ks);
39 2 : succeed_if (ksGetSize (ks2) == 0, "could not append 3 more keys");
40 :
41 2 : succeed_if (ksDel (ks) == 0, "could not delete keyset");
42 :
43 :
44 2 : succeed_if (ksGetSize (keys) == 0, "could not append 3 more keys");
45 2 : succeed_if (ksGetAlloc (keys) == 15, "allocation size wrong");
46 2 : succeed_if (ksDel (keys) == 0, "could not delete keyset");
47 :
48 2 : config = ksNew (100, keyNew ("user/sw/app/fixedConfiguration/key1", KEY_VALUE, "value1", 0),
49 : keyNew ("user/sw/app/fixedConfiguration/key2", KEY_VALUE, "value2", 0),
50 : keyNew ("user/sw/app/fixedConfiguration/key3", KEY_VALUE, "value3", 0), KS_END);
51 2 : succeed_if (ksGetSize (config) == 3, "could not append 3 keys in keyNew");
52 2 : succeed_if (ksGetAlloc (config) == 100, "allocation size wrong");
53 2 : keyDel (ksPop (config));
54 2 : succeed_if (ksGetAlloc (config) == 49, "allocation size wrong");
55 2 : keyDel (ksPop (config));
56 2 : succeed_if (ksGetAlloc (config) == 24, "allocation size wrong");
57 2 : keyDel (ksPop (config));
58 2 : succeed_if (ksGetAlloc (config) == 15, "allocation size wrong");
59 2 : succeed_if (ksDel (config) == 0, "could not delete keyset");
60 :
61 2 : config = ksNew (17, keyNew ("user/sw/app/fixedConfiguration/key1", KEY_VALUE, "value1", 0),
62 : keyNew ("user/sw/app/fixedConfiguration/key2", KEY_VALUE, "value2", 0),
63 : keyNew ("user/sw/app/fixedConfiguration/key3", KEY_VALUE, "value1", 0),
64 : keyNew ("user/sw/app/fixedConfiguration/key4", KEY_VALUE, "value3", 0), KS_END);
65 :
66 2 : succeed_if (ksGetSize (config) == 4, "could not append 5 keys in keyNew");
67 2 : succeed_if (ksGetAlloc (config) == 17, "allocation size wrong");
68 2 : ksAppendKey (config, keyNew ("user/sw/app/fixedConfiguration/key6", KEY_VALUE, "value4", 0));
69 :
70 2 : ksClear (ks2);
71 2 : ksCopy (ks2, config);
72 2 : compare_keyset (config, ks2);
73 :
74 2 : succeed_if (ksDel (config) == 0, "could not delete keyset");
75 2 : succeed_if (ksDel (ks2) == 0, "could not delete keyset");
76 2 : }
77 :
78 2 : static void test_ksDuplicate (void)
79 : {
80 2 : printf ("Test bug duplicate\n");
81 2 : KeySet * ks = ksNew (0, KS_END);
82 :
83 2 : succeed_if (ksAppendKey (ks, keyNew ("system/duplicate", KEY_VALUE, "abc", KEY_END)) == 1, "could not append key");
84 2 : succeed_if (!strcmp (keyValue (ksLookupByName (ks, "system/duplicate", 0)), "abc"), "wrong value for inserted key");
85 :
86 2 : succeed_if (ksAppendKey (ks, keyNew ("system/duplicate", KEY_VALUE, "xyz", KEY_END)) == 1, "could not append duplicate key");
87 2 : succeed_if (!strcmp (keyValue (ksLookupByName (ks, "system/duplicate", 0)), "xyz"), "wrong value for inserted key");
88 :
89 2 : ksDel (ks);
90 2 : }
91 :
92 2 : static void test_ksHole (void)
93 : {
94 2 : printf ("Test holes in keysets\n");
95 2 : KeySet * ks = ksNew (0, KS_END);
96 :
97 2 : succeed_if (ksAppendKey (ks, keyNew ("system/sw/new", KEY_VALUE, "abc", KEY_END)) == 1, "could not append key");
98 2 : succeed_if (ksAppendKey (ks, keyNew ("system/sw/new/sub", KEY_VALUE, "xyz", KEY_END)) == 2, "could not append key");
99 2 : succeed_if (ksAppendKey (ks, keyNew ("system/sw/new/mis/sub", KEY_VALUE, "xyz", KEY_END)) == 3,
100 : "could not append key which makes a hole");
101 :
102 2 : ksDel (ks);
103 2 : }
104 :
105 : #define size 5
106 :
107 0 : int fac (int i)
108 : {
109 250 : if (i == 0)
110 : return 1;
111 : else
112 200 : return i * fac (i - 1);
113 : }
114 :
115 : /* Buggy, does not really yield all permutations */
116 48 : static void per (int k, Key ** pool, Key ** result)
117 : {
118 : int i;
119 48 : int cursize = size - 1;
120 :
121 240 : for (i = 0; i < size - 1; ++i)
122 : {
123 : // printf ("%d -- ", k);
124 192 : int selected = k % (cursize);
125 192 : k /= cursize + 1;
126 192 : cursize--;
127 :
128 : // copy the selected to the result
129 192 : result[i] = pool[selected];
130 :
131 : // remove the selected from the pool
132 384 : memmove (pool + selected, // destination
133 192 : pool + (selected + 1), // source
134 192 : (size - selected - 1) * sizeof (struct Key *));
135 : }
136 48 : result[size - 1] = 0;
137 48 : }
138 :
139 2 : static void test_append (void)
140 : {
141 2 : printf ("Test if keyset is sorted after appending\n");
142 :
143 : Key * key;
144 : Key * n;
145 : Key *s1, *s2, *s3;
146 : KeySet * ks;
147 :
148 2 : ks = ksNew (0, KS_END);
149 :
150 2 : succeed_if (ksAppendKey (ks, key = keyNew ("system/sw/new", KEY_VALUE, "abc", KEY_END)) == 1, "could not append key");
151 2 : succeed_if (ksGetSize (ks) == 1, "wrong size");
152 2 : succeed_if (ks->array[0] == key, "key not on position 0");
153 2 : succeed_if (ks->array[1] == 0, "array not null terminated");
154 :
155 2 : succeed_if (ksAppendKey (ks, n = keyNew ("system/sw/new", KEY_VALUE, "xyz1", KEY_END)) == 1, "could not append key");
156 2 : succeed_if (ksGetSize (ks) == 1, "wrong size");
157 2 : succeed_if (ks->array[0] == n, "n not on position 0");
158 2 : succeed_if (ks->array[0] != key, "key is on position 0");
159 2 : succeed_if (ks->array[1] == 0, "array not null terminated");
160 :
161 2 : ksDel (ks);
162 :
163 :
164 2 : ks = ksNew (0, KS_END);
165 :
166 2 : succeed_if (ksAppendKey (ks, key = keyNew ("system/sw/new", KEY_VALUE, "abc", KEY_END)) == 1, "could not append key");
167 2 : succeed_if (ksGetSize (ks) == 1, "wrong size");
168 2 : succeed_if (ks->array[0] == key, "key not on position 0");
169 2 : succeed_if (ks->array[1] == 0, "array not null terminated");
170 :
171 2 : succeed_if (ksAppendKey (ks, n = keyNew ("system/sw/new/sub1", KEY_VALUE, "xyz1", KEY_END)) == 2, "could not append key");
172 2 : succeed_if (ksGetSize (ks) == 2, "wrong size");
173 2 : succeed_if (ks->array[0] == key, "key not on position 0");
174 2 : succeed_if (ks->array[1] == n, "new key not on position 1");
175 2 : succeed_if (ks->array[2] == 0, "array not null terminated");
176 :
177 2 : ksDel (ks);
178 :
179 :
180 2 : ks = ksNew (0, KS_END);
181 :
182 2 : succeed_if (ksAppendKey (ks, n = keyNew ("system/sw/new/sub1", KEY_VALUE, "xyz1", KEY_END)) == 1, "could not append key");
183 2 : succeed_if (ksGetSize (ks) == 1, "wrong size");
184 2 : succeed_if (ks->array[0] == n, "key not on position 0");
185 2 : succeed_if (ks->array[1] == 0, "array not null terminated");
186 :
187 2 : succeed_if (ksAppendKey (ks, key = keyNew ("system/sw/new", KEY_VALUE, "abc", KEY_END)) == 2, "could not append key");
188 2 : succeed_if (ksGetSize (ks) == 2, "wrong size");
189 2 : succeed_if (ks->array[0] == key, "key not on position 0");
190 2 : succeed_if (ks->array[1] == n, "key not on position 1");
191 2 : succeed_if (ks->array[2] == 0, "array not null terminated");
192 :
193 2 : ksDel (ks);
194 :
195 :
196 2 : key = keyNew ("system/sw/new", KEY_VALUE, "abc", KEY_END);
197 2 : s1 = keyNew ("system/sw/new/sub1", KEY_VALUE, "xyz1", KEY_END);
198 2 : s2 = keyNew ("system/sw/new/sub2", KEY_VALUE, "xyz2", KEY_END);
199 2 : s3 = keyNew ("system/sw/new/sub3", KEY_VALUE, "xyz3", KEY_END);
200 2 : keyIncRef (key);
201 2 : keyIncRef (s1);
202 2 : keyIncRef (s2);
203 2 : keyIncRef (s3);
204 :
205 2 : Key * solution[size] = { key, s1, s2, s3, 0 };
206 : Key * solutioncopy[size];
207 : Key * next[size];
208 : int i, j;
209 :
210 100 : for (i = 0; i < fac (size - 1); ++i)
211 : {
212 48 : memcpy (solutioncopy, solution, size * sizeof (struct Key *));
213 48 : per (i, solutioncopy, next);
214 :
215 48 : ks = ksNew (0, KS_END);
216 :
217 288 : for (j = 0; j < size - 1; ++j)
218 : {
219 : // printf ("%p ", (void*)next[j]);
220 : // printf ("%s ", keyName(next[j]));
221 192 : succeed_if (ksAppendKey (ks, next[j]) == j + 1, "could not append key");
222 : }
223 : // printf ("\nsolution is:\n");
224 :
225 48 : succeed_if (!memcmp (ks->array, solution, size), "solution is not correct");
226 :
227 48 : ksDel (ks);
228 : }
229 :
230 :
231 2 : ks = ksNew (0, KS_END);
232 :
233 2 : succeed_if (ksAppendKey (ks, key) == 1, "could not append key");
234 2 : succeed_if (ksGetSize (ks) == 1, "wrong size");
235 2 : succeed_if (ks->array[0] == key, "key not on position 0");
236 2 : succeed_if (ks->array[1] == 0, "array not null terminated");
237 :
238 2 : succeed_if (ksAppendKey (ks, s1) == 2, "could not append key");
239 2 : succeed_if (ksGetSize (ks) == 2, "wrong size");
240 2 : succeed_if (ks->array[0] == key, "key not on position 0");
241 2 : succeed_if (ks->array[1] == s1, "key not on position 1");
242 2 : succeed_if (ks->array[2] == 0, "array not null terminated");
243 :
244 2 : succeed_if (ksAppendKey (ks, s2) == 3, "could not append key");
245 2 : succeed_if (ksGetSize (ks) == 3, "wrong size");
246 2 : succeed_if (ks->array[0] == key, "key not on position 0");
247 2 : succeed_if (ks->array[1] == s1, "key not on position 1");
248 2 : succeed_if (ks->array[2] == s2, "key not on position 2");
249 2 : succeed_if (ks->array[3] == 0, "array not null terminated");
250 :
251 2 : succeed_if (ksAppendKey (ks, s3) == 4, "could not append key");
252 2 : succeed_if (ksGetSize (ks) == 4, "wrong size");
253 2 : succeed_if (ks->array[0] == key, "key not on position 0");
254 2 : succeed_if (ks->array[1] == s1, "key not on position 1");
255 2 : succeed_if (ks->array[2] == s2, "key not on position 2");
256 2 : succeed_if (ks->array[3] == s3, "key not on position 3");
257 2 : succeed_if (ks->array[4] == 0, "array not null terminated");
258 :
259 2 : succeed_if (!memcmp (ks->array, solution, size), "solution is not correct");
260 :
261 2 : ksDel (ks);
262 :
263 :
264 2 : ks = ksNew (0, KS_END);
265 :
266 2 : succeed_if (ksAppendKey (ks, s3) == 1, "could not append key");
267 2 : succeed_if (ksGetSize (ks) == 1, "wrong size");
268 2 : succeed_if (ks->array[0] == s3, "key not on position 0");
269 2 : succeed_if (ks->array[1] == 0, "array not null terminated");
270 :
271 2 : succeed_if (ksAppendKey (ks, key) == 2, "could not append key");
272 2 : succeed_if (ksGetSize (ks) == 2, "wrong size");
273 2 : succeed_if (ks->array[0] == key, "key not on position 0");
274 2 : succeed_if (ks->array[1] == s3, "key not on position 1");
275 2 : succeed_if (ks->array[2] == 0, "array not null terminated");
276 :
277 2 : succeed_if (ksAppendKey (ks, s1) == 3, "could not append key");
278 2 : succeed_if (ksGetSize (ks) == 3, "wrong size");
279 2 : succeed_if (ks->array[0] == key, "key not on position 0");
280 2 : succeed_if (ks->array[1] == s1, "key not on position 1");
281 2 : succeed_if (ks->array[2] == s3, "key not on position 2");
282 2 : succeed_if (ks->array[3] == 0, "array not null terminated");
283 :
284 2 : succeed_if (ksAppendKey (ks, s2) == 4, "could not append key");
285 2 : succeed_if (ksGetSize (ks) == 4, "wrong size");
286 2 : succeed_if (ks->array[0] == key, "key not on position 0");
287 2 : succeed_if (ks->array[1] == s1, "key not on position 1");
288 2 : succeed_if (ks->array[2] == s2, "key not on position 2");
289 2 : succeed_if (ks->array[3] == s3, "key not on position 3");
290 2 : succeed_if (ks->array[4] == 0, "array not null terminated");
291 :
292 2 : succeed_if (!memcmp (ks->array, solution, size), "solution is not correct");
293 :
294 : /*
295 : Key *it;
296 : ksRewind(ks);
297 : while ((it = ksNext(ks)) != 0)
298 : {
299 : printf ("%s\n", keyName(it));
300 : }
301 : */
302 :
303 :
304 2 : ksDel (ks);
305 :
306 :
307 2 : keyDecRef (key);
308 2 : keyDel (key);
309 2 : keyDecRef (s1);
310 2 : keyDel (s1);
311 2 : keyDecRef (s2);
312 2 : keyDel (s2);
313 2 : keyDecRef (s3);
314 2 : keyDel (s3);
315 2 : }
316 :
317 2 : static void test_equal (void)
318 : {
319 2 : Key * k1 = keyNew (0);
320 2 : Key * k2 = keyNew (0);
321 :
322 2 : succeed_if (keyCmp (0, 0) == 0, "null pointers should be same");
323 2 : succeed_if (keyCmp (k1, k2) == 0, "should be same");
324 :
325 2 : keySetName (k1, "");
326 2 : keySetName (k2, "");
327 2 : succeed_if (keyCmp (k1, k2) == 0, "should be same");
328 :
329 2 : keySetName (k1, "user");
330 2 : keySetName (k2, "user");
331 2 : succeed_if (keyCmp (k1, k2) == 0, "should be same");
332 :
333 2 : keySetName (k1, "system");
334 2 : keySetName (k2, "system");
335 2 : succeed_if (keyCmp (k1, k2) == 0, "should be same");
336 :
337 2 : keySetName (k1, "user/a");
338 2 : keySetName (k2, "user/a");
339 2 : succeed_if (keyCmp (k1, k2) == 0, "should be same");
340 :
341 2 : keyDel (k1);
342 2 : keyDel (k2);
343 2 : }
344 :
345 2 : static void test_cmp (void)
346 : {
347 2 : printf ("Compare two keys\n");
348 :
349 2 : Key * k1 = keyNew (0);
350 2 : Key * k2 = keyNew (0);
351 :
352 2 : succeed_if (keyCmp (0, 0) == 0, "null keys comparision");
353 2 : succeed_if (keyCmp (k1, 0) == 1, "compare null key with key with no name");
354 2 : succeed_if (keyCmp (0, k2) == -1, "compare null key with key with no name");
355 :
356 2 : keySetName (k1, "user/a");
357 2 : succeed_if (keyCmp (k2, k2) == 0, "null keys comparision");
358 2 : succeed_if (keyCmp (k1, k2) == 1, "compare key with no name with user/a");
359 2 : succeed_if (keyCmp (k2, k1) == -1, "compare key with no name with user/a");
360 :
361 2 : keySetName (k2, "user/a");
362 2 : succeed_if (keyCmp (k1, k1) == 0, "compare the same key");
363 2 : succeed_if (keyCmp (k1, k2) == 0, "compare the same key");
364 2 : succeed_if (keyCmp (k2, k1) == 0, "compare the same key");
365 :
366 2 : keySetOwner (k1, "non_existing_user");
367 2 : succeed_if (keyCmp (k2, k2) == 0, "null owner comparision");
368 2 : succeed_if (keyCmp (k1, k2) > 0, "compare key with no owner with non_existing_user");
369 2 : succeed_if (keyCmp (k2, k1) < 0, "compare key with no owner with non_existing_user");
370 :
371 2 : keySetOwner (k2, "other_non_existing_user");
372 2 : succeed_if (keyCmp (k1, k2) < 0, "compare key with owner non_existing_user with other_non_existing_user");
373 2 : succeed_if (keyCmp (k2, k1) > 0, "compare key with owner non_existing_user with other_non_existing_user");
374 :
375 2 : keySetName (k2, "user/b");
376 2 : succeed_if (keyCmp (k1, k2) < 0, "compare key with different names");
377 2 : succeed_if (keyCmp (k2, k1) > 0, "compare key with different names");
378 :
379 2 : keyDel (k1);
380 2 : keyDel (k2);
381 2 : }
382 :
383 2 : static void test_appendowner (void)
384 : {
385 : Key *key, *s1, *s2, *s3;
386 : KeySet * ks;
387 :
388 2 : printf ("Append Keys with owner");
389 :
390 2 : key = keyNew ("system/sw/new", KEY_VALUE, "abc", KEY_END);
391 2 : s1 = keyNew ("system/sw/new", KEY_VALUE, "xyz1", KEY_OWNER, "s1", KEY_END);
392 2 : s2 = keyNew ("system/sw/new", KEY_VALUE, "xyz2", KEY_OWNER, "s2", KEY_END);
393 2 : s3 = keyNew ("system/sw/new", KEY_VALUE, "xyz3", KEY_OWNER, "s3", KEY_END);
394 2 : ks = ksNew (0, KS_END);
395 :
396 2 : succeed_if (ksAppendKey (ks, key) == 1, "could not append key");
397 2 : succeed_if (ksGetSize (ks) == 1, "wrong size");
398 2 : succeed_if (ks->array[0] == key, "key not on position 0");
399 2 : succeed_if (ks->array[1] == 0, "array not null terminated");
400 :
401 2 : succeed_if (ksAppendKey (ks, s1) == 2, "could not append key");
402 2 : succeed_if (ksGetSize (ks) == 2, "wrong size");
403 2 : succeed_if (ks->array[0] == key, "key not on position 0");
404 2 : succeed_if (ks->array[1] == s1, "key not on position 1");
405 2 : succeed_if (ks->array[2] == 0, "array not null terminated");
406 :
407 2 : succeed_if (ksAppendKey (ks, s2) == 3, "could not append key");
408 2 : succeed_if (ksGetSize (ks) == 3, "wrong size");
409 2 : succeed_if (ks->array[0] == key, "key not on position 0");
410 2 : succeed_if (ks->array[1] == s1, "key not on position 1");
411 2 : succeed_if (ks->array[2] == s2, "key not on position 2");
412 2 : succeed_if (ks->array[3] == 0, "array not null terminated");
413 :
414 2 : succeed_if (ksAppendKey (ks, s3) == 4, "could not append key");
415 2 : succeed_if (ksGetSize (ks) == 4, "wrong size");
416 2 : succeed_if (ks->array[0] == key, "key not on position 0");
417 2 : succeed_if (ks->array[1] == s1, "key not on position 1");
418 2 : succeed_if (ks->array[2] == s2, "key not on position 2");
419 2 : succeed_if (ks->array[3] == s3, "key not on position 3");
420 2 : succeed_if (ks->array[4] == 0, "array not null terminated");
421 :
422 2 : ksDel (ks);
423 2 : }
424 :
425 2 : static void test_ksLookupCase (void)
426 : {
427 2 : printf ("Test bug lookup with case\n");
428 2 : KeySet * ks = ksNew (32, keyNew ("system/ay/key", KEY_VALUE, "aykey", KEY_END),
429 : keyNew ("system/mY/kex", KEY_VALUE, "mykex", KEY_END), keyNew ("system/xy/key", KEY_VALUE, "xykey", KEY_END),
430 : keyNew ("system/My/key", KEY_VALUE, "Mykey", KEY_END), KS_END);
431 : // Does not work without KDB_O_NOALL
432 2 : Key * found = ksLookupByName (ks, "system/my/key", KDB_O_NOCASE | KDB_O_NOALL);
433 2 : succeed_if (found != 0, "could not find key (binary search fails when ignoring case)");
434 2 : ksDel (ks);
435 2 : }
436 :
437 2 : static void test_ksLookupOwner (void)
438 : {
439 2 : printf ("Test bug lookup with owner\n");
440 2 : Key * found = 0;
441 2 : KeySet * ks = ksNew (32, keyNew ("user:fritz/my/key", KEY_VALUE, "fritz", KEY_END),
442 : keyNew ("user:frotz/my/key", KEY_VALUE, "frotz", KEY_END),
443 : keyNew ("user/my/key", KEY_VALUE, "current", KEY_END), KS_END);
444 :
445 2 : found = ksLookupByName (ks, "user/my/key", KDB_O_WITHOWNER);
446 2 : succeed_if (found != 0, "could not find key");
447 2 : succeed_if (!strcmp (keyValue (found), "current"), "got wrong key");
448 :
449 2 : found = ksLookupByName (ks, "user:fritz/my/key", KDB_O_WITHOWNER);
450 2 : succeed_if (found != 0, "could not find key");
451 2 : succeed_if (!strcmp (keyValue (found), "fritz"), "got wrong key");
452 :
453 2 : found = ksLookupByName (ks, "user:frotz/my/key", KDB_O_WITHOWNER);
454 2 : succeed_if (found != 0, "could not find key");
455 2 : succeed_if (!strcmp (keyValue (found), "frotz"), "got wrong key");
456 :
457 2 : found = ksLookupByName (ks, "user:fretz/my/key", KDB_O_WITHOWNER);
458 2 : succeed_if (found == 0, "found non existing key");
459 :
460 2 : found = ksLookupByName (ks, "user/my/key", 0);
461 2 : succeed_if (found != 0, "could not find key");
462 2 : succeed_if (!strcmp (keyValue (found), "fritz"), "binary search seems to be non-deterministic");
463 :
464 2 : found = ksLookupByName (ks, "user:fritz/my/key", 0);
465 2 : succeed_if (found != 0, "could not find key");
466 2 : succeed_if (!strcmp (keyValue (found), "fritz"), "binary search seems to be non-deterministic");
467 :
468 2 : found = ksLookupByName (ks, "user:frotz/my/key", 0);
469 2 : succeed_if (found != 0, "could not find key");
470 2 : succeed_if (!strcmp (keyValue (found), "fritz"), "binary search seems to be non-deterministic");
471 :
472 2 : found = ksLookupByName (ks, "user:fretz/my/key", 0);
473 2 : succeed_if (found != 0, "could not find key");
474 2 : succeed_if (!strcmp (keyValue (found), "fritz"), "binary search seems to be non-deterministic");
475 :
476 2 : ksDel (ks);
477 2 : }
478 :
479 2 : int main (int argc, char ** argv)
480 : {
481 2 : printf ("KEYSET ORDERING TESTS\n");
482 2 : printf ("==========================\n\n");
483 :
484 2 : init (argc, argv);
485 :
486 2 : test_ksNew ();
487 2 : test_ksDuplicate ();
488 :
489 2 : test_ksHole ();
490 2 : test_append ();
491 2 : test_equal ();
492 2 : test_cmp ();
493 2 : test_appendowner ();
494 2 : test_ksLookupCase ();
495 2 : test_ksLookupOwner ();
496 :
497 2 : printf ("\n%s RESULTS: %d test(s) done. %d error(s).\n", argv[0], nbTest, nbError);
498 :
499 2 : return nbError;
500 : }
|