Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief Test suite for mounting related issues.
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : */
8 :
9 : #include <../../src/libs/elektra/backend.c>
10 : #include <../../src/libs/elektra/mount.c>
11 : #include <../../src/libs/elektra/split.c>
12 : #include <../../src/libs/elektra/trie.c>
13 : #include <tests_internal.h>
14 :
15 0 : KDB * kdb_new (void)
16 : {
17 28 : KDB * kdb = elektraCalloc (sizeof (KDB));
18 28 : kdb->split = splitNew ();
19 0 : return kdb;
20 : }
21 :
22 4 : Backend * b_new (const char * name, const char * value)
23 : {
24 4 : Backend * backend = elektraCalloc (sizeof (Backend));
25 4 : backend->refcounter = 1;
26 :
27 4 : backend->mountpoint = keyNew (name, KEY_VALUE, value, KEY_END);
28 4 : keyIncRef (backend->mountpoint);
29 :
30 4 : return backend;
31 : }
32 :
33 28 : static void kdb_del (KDB * kdb)
34 : {
35 28 : backendClose (kdb->defaultBackend, 0);
36 28 : if (kdb->initBackend)
37 : {
38 4 : backendClose (kdb->initBackend, 0);
39 : }
40 28 : trieClose (kdb->trie, 0);
41 28 : splitDel (kdb->split);
42 :
43 28 : elektraFree (kdb);
44 28 : }
45 :
46 2 : static void test_mount (void)
47 : {
48 2 : printf ("test mount backend\n");
49 :
50 2 : KDB * kdb = kdb_new ();
51 2 : mountBackend (kdb, b_new ("user", "user"), 0);
52 2 : succeed_if (kdb->trie, "there should be a trie");
53 :
54 2 : Key * mp = keyNew ("user", KEY_VALUE, "user", KEY_END);
55 2 : Key * sk = keyNew ("user", KEY_VALUE, "user", KEY_END);
56 :
57 2 : compare_key (mountGetBackend (kdb, sk)->mountpoint, mp);
58 4 : compare_key (mountGetMountpoint (kdb, sk), mp);
59 :
60 2 : keySetName (sk, "user/below");
61 2 : compare_key (mountGetBackend (kdb, sk)->mountpoint, mp);
62 4 : compare_key (mountGetMountpoint (kdb, sk), mp);
63 :
64 2 : keySetName (sk, "system");
65 2 : kdb->defaultBackend = b_new ("", "default");
66 2 : succeed_if (mountGetBackend (kdb, sk) == kdb->defaultBackend, "did not return default backend");
67 :
68 2 : keySetName (mp, "");
69 2 : keySetString (mp, "default");
70 2 : compare_key (mountGetBackend (kdb, sk)->mountpoint, mp);
71 4 : compare_key (mountGetMountpoint (kdb, sk), mp);
72 :
73 2 : keyDel (sk);
74 2 : keyDel (mp);
75 :
76 2 : kdb_del (kdb);
77 2 : }
78 :
79 20 : KeySet * modules_config (void)
80 : {
81 20 : return ksNew (5, keyNew ("system/elektra/modules", KEY_END), KS_END);
82 : }
83 :
84 2 : KeySet * minimal_config (void)
85 : {
86 2 : return ksNew (5, keyNew ("system/elektra/mountpoints", KEY_END), KS_END);
87 : }
88 :
89 :
90 2 : static void test_minimaltrie (void)
91 : {
92 2 : printf ("Test minimal mount\n");
93 :
94 2 : KDB * kdb = kdb_new ();
95 2 : Key * errorKey = keyNew (0);
96 2 : KeySet * modules = modules_config ();
97 2 : succeed_if (mountOpen (kdb, minimal_config (), modules, errorKey) == 0, "could not open minimal config")
98 :
99 2 : succeed_if (output_warnings (errorKey), "warnings found");
100 2 : succeed_if (output_error (errorKey), "error found");
101 :
102 2 : succeed_if (!kdb->trie, "minimal trie is null");
103 :
104 2 : keyDel (errorKey);
105 2 : ksDel (modules);
106 2 : kdb_del (kdb);
107 2 : }
108 :
109 2 : KeySet * simple_config (void)
110 : {
111 2 : return ksNew (5, keyNew ("system/elektra/mountpoints", KEY_END), keyNew ("system/elektra/mountpoints/simple", KEY_END),
112 : keyNew ("system/elektra/mountpoints/simple/mountpoint", KEY_VALUE, "user/tests/simple", KEY_END), KS_END);
113 : }
114 :
115 2 : static void test_simple (void)
116 : {
117 2 : printf ("Test simple mount\n");
118 :
119 2 : KDB * kdb = kdb_new ();
120 2 : Key * errorKey = keyNew (0);
121 2 : KeySet * modules = modules_config ();
122 2 : succeed_if (mountOpen (kdb, simple_config (), modules, errorKey) == 0, "could not open trie");
123 :
124 2 : succeed_if (output_warnings (errorKey), "warnings found");
125 2 : succeed_if (output_error (errorKey), "error found");
126 :
127 2 : exit_if_fail (kdb->trie, "kdb->trie was not build up successfully");
128 :
129 2 : Key * searchKey = keyNew ("user", KEY_END);
130 2 : Backend * backend = trieLookup (kdb->trie, searchKey);
131 2 : succeed_if (!backend, "there should be no backend");
132 :
133 :
134 2 : Key * mp = keyNew ("user/tests/simple", KEY_VALUE, "simple", KEY_END);
135 2 : keySetName (searchKey, "user/tests/simple");
136 2 : backend = trieLookup (kdb->trie, searchKey);
137 2 : succeed_if (backend, "there should be a backend");
138 2 : if (backend) compare_key (backend->mountpoint, mp);
139 :
140 :
141 2 : keySetName (searchKey, "user/tests/simple/below");
142 2 : Backend * b2 = trieLookup (kdb->trie, searchKey);
143 2 : succeed_if (b2, "there should be a backend");
144 2 : succeed_if (backend == b2, "should be same backend");
145 2 : if (b2) compare_key (b2->mountpoint, mp);
146 :
147 :
148 2 : keySetName (searchKey, "user/tests/simple/deep/below");
149 2 : b2 = trieLookup (kdb->trie, searchKey);
150 2 : succeed_if (b2, "there should be a backend");
151 2 : succeed_if (backend == b2, "should be same backend");
152 2 : if (b2) compare_key (b2->mountpoint, mp);
153 :
154 2 : keyDel (errorKey);
155 2 : ksDel (modules);
156 2 : keyDel (mp);
157 2 : keyDel (searchKey);
158 2 : kdb_del (kdb);
159 2 : }
160 :
161 2 : KeySet * set_simple (void)
162 : {
163 2 : return ksNew (50, keyNew ("system/elektra/mountpoints/simple", KEY_END),
164 :
165 : keyNew ("system/elektra/mountpoints/simple/config", KEY_END),
166 : keyNew ("system/elektra/mountpoints/simple/config/anything", KEY_VALUE, "backend", KEY_END),
167 : keyNew ("system/elektra/mountpoints/simple/config/more", KEY_END),
168 : keyNew ("system/elektra/mountpoints/simple/config/more/config", KEY_END),
169 : keyNew ("system/elektra/mountpoints/simple/config/more/config/below", KEY_END),
170 : keyNew ("system/elektra/mountpoints/simple/config/path", KEY_END),
171 :
172 : keyNew ("system/elektra/mountpoints/simple/errorplugins", KEY_END),
173 : keyNew ("system/elektra/mountpoints/simple/errorplugins/#1" KDB_DEFAULT_STORAGE, KEY_END),
174 :
175 : keyNew ("system/elektra/mountpoints/simple/getplugins", KEY_END),
176 : keyNew ("system/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE, KEY_END),
177 : keyNew ("system/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config", KEY_END),
178 : keyNew ("system/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/anything", KEY_VALUE, "plugin",
179 : KEY_END),
180 : keyNew ("system/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/more", KEY_END),
181 : keyNew ("system/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/more/config", KEY_END),
182 : keyNew ("system/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/more/config/below", KEY_END),
183 : keyNew ("system/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/path", KEY_END),
184 :
185 : keyNew ("system/elektra/mountpoints/simple/mountpoint", KEY_VALUE, "user/tests/backend/simple", KEY_END),
186 :
187 : keyNew ("system/elektra/mountpoints/simple/setplugins", KEY_END),
188 : keyNew ("system/elektra/mountpoints/simple/setplugins/#1" KDB_DEFAULT_STORAGE, KEY_END),
189 :
190 : keyNew ("system/elektra/mountpoints/simple/errorplugins", KEY_END),
191 : keyNew ("system/elektra/mountpoints/simple/errorplugins/#1" KDB_DEFAULT_STORAGE, KEY_END), KS_END);
192 : }
193 :
194 :
195 4 : KeySet * set_pluginconf (void)
196 : {
197 4 : return ksNew (10, keyNew ("system/anything", KEY_VALUE, "backend", KEY_END), keyNew ("system/more", KEY_END),
198 : keyNew ("system/more/config", KEY_END), keyNew ("system/more/config/below", KEY_END), keyNew ("system/path", KEY_END),
199 : keyNew ("user/anything", KEY_VALUE, "plugin", KEY_END), keyNew ("user/more", KEY_END),
200 : keyNew ("user/more/config", KEY_END), keyNew ("user/more/config/below", KEY_END), keyNew ("user/path", KEY_END),
201 : KS_END);
202 : }
203 :
204 2 : static void test_simpletrie (void)
205 : {
206 2 : printf ("Test simple mount with plugins\n");
207 :
208 2 : KDB * kdb = kdb_new ();
209 2 : KeySet * modules = ksNew (0, KS_END);
210 2 : elektraModulesInit (modules, 0);
211 :
212 2 : KeySet * config = set_simple ();
213 2 : ksAppendKey (config, keyNew ("system/elektra/mountpoints", KEY_END));
214 2 : succeed_if (mountOpen (kdb, config, modules, 0) == 0, "could not open mount");
215 :
216 2 : Key * key = keyNew ("user/tests/backend/simple", KEY_END);
217 2 : Backend * backend = trieLookup (kdb->trie, key);
218 :
219 2 : keyAddBaseName (key, "somewhere");
220 2 : keyAddBaseName (key, "deep");
221 2 : keyAddBaseName (key, "below");
222 2 : Backend * backend2 = trieLookup (kdb->trie, key);
223 2 : succeed_if (backend == backend2, "should be same backend");
224 :
225 2 : succeed_if (backend->getplugins[0] == 0, "there should be no plugin");
226 2 : exit_if_fail (backend->getplugins[1] != 0, "there should be a plugin");
227 2 : succeed_if (backend->getplugins[2] == 0, "there should be no plugin");
228 :
229 2 : succeed_if (backend->setplugins[0] == 0, "there should be no plugin");
230 2 : exit_if_fail (backend->setplugins[1] != 0, "there should be a plugin");
231 2 : succeed_if (backend->setplugins[2] == 0, "there should be no plugin");
232 :
233 2 : Key * mp = backend->mountpoint;
234 2 : succeed_if (mp, "no mountpoint found");
235 2 : if (mp)
236 : {
237 2 : succeed_if_same_string (keyName (mp), "user/tests/backend/simple");
238 2 : succeed_if_same_string (keyString (mp), "simple");
239 : }
240 :
241 2 : Plugin * plugin = backend->getplugins[1];
242 :
243 2 : KeySet * test_config = set_pluginconf ();
244 2 : KeySet * cconfig = elektraPluginGetConfig (plugin);
245 2 : succeed_if (cconfig != 0, "there should be a config");
246 2 : compare_keyset (cconfig, test_config);
247 2 : ksDel (test_config);
248 :
249 2 : succeed_if (plugin->kdbGet != 0, "no get pointer");
250 2 : succeed_if (plugin->kdbSet != 0, "no set pointer");
251 :
252 2 : keyDel (key);
253 2 : kdb_del (kdb);
254 2 : ksDel (modules);
255 2 : }
256 :
257 :
258 2 : KeySet * set_two (void)
259 : {
260 2 : return ksNew (50, keyNew ("system/elektra/mountpoints", KEY_END), keyNew ("system/elektra/mountpoints/simple", KEY_END),
261 :
262 : keyNew ("system/elektra/mountpoints/simple/config", KEY_END),
263 : keyNew ("system/elektra/mountpoints/simple/config/anything", KEY_VALUE, "backend", KEY_END),
264 : keyNew ("system/elektra/mountpoints/simple/config/more", KEY_END),
265 : keyNew ("system/elektra/mountpoints/simple/config/more/config", KEY_END),
266 : keyNew ("system/elektra/mountpoints/simple/config/more/config/below", KEY_END),
267 : keyNew ("system/elektra/mountpoints/simple/config/path", KEY_END),
268 :
269 : keyNew ("system/elektra/mountpoints/simple/getplugins", KEY_END),
270 : keyNew ("system/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE, KEY_END),
271 : keyNew ("system/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config", KEY_END),
272 : keyNew ("system/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/anything", KEY_VALUE, "plugin",
273 : KEY_END),
274 : keyNew ("system/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/more", KEY_END),
275 : keyNew ("system/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/more/config", KEY_END),
276 : keyNew ("system/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/more/config/below", KEY_END),
277 : keyNew ("system/elektra/mountpoints/simple/getplugins/#1" KDB_DEFAULT_STORAGE "/config/path", KEY_END),
278 :
279 : keyNew ("system/elektra/mountpoints/simple/mountpoint", KEY_VALUE, "user/tests/backend/simple", KEY_END),
280 :
281 : keyNew ("system/elektra/mountpoints/simple/setplugins", KEY_END),
282 : keyNew ("system/elektra/mountpoints/simple/setplugins/#1" KDB_DEFAULT_STORAGE, KEY_END),
283 :
284 :
285 : keyNew ("system/elektra/mountpoints/two", KEY_END),
286 :
287 : keyNew ("system/elektra/mountpoints/two/config", KEY_END),
288 : keyNew ("system/elektra/mountpoints/two/config/anything", KEY_VALUE, "backend", KEY_END),
289 : keyNew ("system/elektra/mountpoints/two/config/more", KEY_END),
290 : keyNew ("system/elektra/mountpoints/two/config/more/config", KEY_END),
291 : keyNew ("system/elektra/mountpoints/two/config/more/config/below", KEY_END),
292 : keyNew ("system/elektra/mountpoints/two/config/path", KEY_END),
293 :
294 : keyNew ("system/elektra/mountpoints/two/getplugins", KEY_END),
295 : keyNew ("system/elektra/mountpoints/two/getplugins/#1" KDB_DEFAULT_STORAGE, KEY_END),
296 : keyNew ("system/elektra/mountpoints/two/getplugins/#1" KDB_DEFAULT_STORAGE "/config", KEY_END),
297 : keyNew ("system/elektra/mountpoints/two/getplugins/#1" KDB_DEFAULT_STORAGE "/config/anything", KEY_VALUE, "plugin",
298 : KEY_END),
299 : keyNew ("system/elektra/mountpoints/two/getplugins/#1" KDB_DEFAULT_STORAGE "/config/more", KEY_END),
300 : keyNew ("system/elektra/mountpoints/two/getplugins/#1" KDB_DEFAULT_STORAGE "/config/more/config", KEY_END),
301 : keyNew ("system/elektra/mountpoints/two/getplugins/#1" KDB_DEFAULT_STORAGE "/config/more/config/below", KEY_END),
302 : keyNew ("system/elektra/mountpoints/two/getplugins/#1" KDB_DEFAULT_STORAGE "/config/path", KEY_END),
303 :
304 : keyNew ("system/elektra/mountpoints/two/mountpoint", KEY_VALUE, "user/tests/backend/two", KEY_END),
305 :
306 : keyNew ("system/elektra/mountpoints/two/setplugins", KEY_END),
307 : keyNew ("system/elektra/mountpoints/two/setplugins/#1" KDB_DEFAULT_STORAGE, KEY_END),
308 : keyNew ("system/elektra/mountpoints/two/setplugins/#2" KDB_DEFAULT_STORAGE, KEY_END), KS_END);
309 : }
310 :
311 2 : static void test_two (void)
312 : {
313 2 : printf ("Test two mounts\n");
314 :
315 2 : KDB * kdb = kdb_new ();
316 2 : KeySet * modules = ksNew (0, KS_END);
317 2 : elektraModulesInit (modules, 0);
318 :
319 2 : KeySet * config = set_two ();
320 2 : ksAppendKey (config, keyNew ("system/elektra/mountpoints", KEY_END));
321 2 : succeed_if (mountOpen (kdb, config, modules, 0) == 0, "could not open mount");
322 :
323 2 : Key * key = keyNew ("user/tests/backend/simple", KEY_END);
324 2 : Backend * backend = trieLookup (kdb->trie, key);
325 :
326 2 : keyAddBaseName (key, "somewhere");
327 2 : keyAddBaseName (key, "deep");
328 2 : keyAddBaseName (key, "below");
329 2 : Backend * backend2 = trieLookup (kdb->trie, key);
330 2 : succeed_if (backend == backend2, "should be same backend");
331 :
332 2 : succeed_if (backend->getplugins[0] == 0, "there should be no plugin");
333 2 : exit_if_fail (backend->getplugins[1] != 0, "there should be a plugin");
334 2 : succeed_if (backend->getplugins[2] == 0, "there should be no plugin");
335 :
336 2 : succeed_if (backend->setplugins[0] == 0, "there should be no plugin");
337 2 : exit_if_fail (backend->setplugins[1] != 0, "there should be a plugin");
338 2 : succeed_if (backend->setplugins[2] == 0, "there should be no plugin");
339 :
340 : Key * mp;
341 2 : succeed_if ((mp = backend->mountpoint) != 0, "no mountpoint found");
342 2 : succeed_if_same_string (keyName (mp), "user/tests/backend/simple");
343 2 : succeed_if_same_string (keyString (mp), "simple");
344 :
345 2 : Plugin * plugin = backend->getplugins[1];
346 :
347 2 : KeySet * test_config = set_pluginconf ();
348 2 : KeySet * cconfig = elektraPluginGetConfig (plugin);
349 2 : succeed_if (cconfig != 0, "there should be a config");
350 2 : compare_keyset (cconfig, test_config);
351 2 : ksDel (test_config);
352 :
353 2 : succeed_if (plugin->kdbGet != 0, "no get pointer");
354 2 : succeed_if (plugin->kdbSet != 0, "no set pointer");
355 :
356 2 : keySetName (key, "user/tests/backend/two");
357 2 : Backend * two = trieLookup (kdb->trie, key);
358 2 : succeed_if (two != backend, "should be differnt backend");
359 :
360 2 : succeed_if ((mp = two->mountpoint) != 0, "no mountpoint found");
361 2 : succeed_if_same_string (keyName (mp), "user/tests/backend/two");
362 2 : succeed_if_same_string (keyString (mp), "two");
363 :
364 2 : keyDel (key);
365 2 : elektraModulesClose (modules, 0);
366 2 : ksDel (modules);
367 2 : kdb_del (kdb);
368 2 : }
369 :
370 :
371 2 : KeySet * set_us (void)
372 : {
373 2 : return ksNew (50, keyNew ("system/elektra/mountpoints", KEY_END), keyNew ("system/elektra/mountpoints/user", KEY_END),
374 : keyNew ("system/elektra/mountpoints/user/mountpoint", KEY_VALUE, "user", KEY_END),
375 : keyNew ("system/elektra/mountpoints/system", KEY_END),
376 : keyNew ("system/elektra/mountpoints/system/mountpoint", KEY_VALUE, "system", KEY_END), KS_END);
377 : }
378 :
379 2 : static void test_us (void)
380 : {
381 2 : printf ("Test mounting of user and system backends\n");
382 :
383 2 : KDB * kdb = kdb_new ();
384 2 : KeySet * modules = ksNew (0, KS_END);
385 2 : elektraModulesInit (modules, 0);
386 :
387 2 : KeySet * config = set_us ();
388 2 : ksAppendKey (config, keyNew ("system/elektra/mountpoints", KEY_END));
389 2 : succeed_if (mountOpen (kdb, config, modules, 0) == 0, "could not open mount");
390 :
391 2 : Key * key = keyNew ("user/anywhere/backend/simple", KEY_END);
392 2 : Backend * backend = trieLookup (kdb->trie, key);
393 :
394 2 : keyAddBaseName (key, "somewhere");
395 2 : keyAddBaseName (key, "deep");
396 2 : keyAddBaseName (key, "below");
397 2 : Backend * backend2 = trieLookup (kdb->trie, key);
398 2 : succeed_if (backend == backend2, "should be same backend");
399 :
400 2 : succeed_if (backend->getplugins[0] == 0, "there should be no plugin");
401 2 : exit_if_fail (backend->getplugins[1] == 0, "there should be no plugin");
402 2 : succeed_if (backend->getplugins[2] == 0, "there should be no plugin");
403 :
404 2 : succeed_if (backend->setplugins[0] == 0, "there should be no plugin");
405 2 : exit_if_fail (backend->setplugins[1] == 0, "there should be no plugin");
406 2 : succeed_if (backend->setplugins[2] == 0, "there should be no plugin");
407 :
408 2 : Key * mp = backend->mountpoint;
409 2 : succeed_if (mp, "no mountpoint found");
410 2 : if (mp)
411 : {
412 2 : succeed_if_same_string (keyName (mp), "user");
413 2 : succeed_if_same_string (keyString (mp), "user");
414 : }
415 :
416 2 : keySetName (key, "system/anywhere/tests/backend/two");
417 2 : Backend * two = trieLookup (kdb->trie, key);
418 2 : succeed_if (two != backend, "should be differnt backend");
419 :
420 2 : succeed_if ((mp = two->mountpoint) != 0, "no mountpoint found");
421 2 : succeed_if_same_string (keyName (mp), "system");
422 2 : succeed_if_same_string (keyString (mp), "system");
423 :
424 2 : keyDel (key);
425 2 : elektraModulesClose (modules, 0);
426 2 : ksDel (modules);
427 2 : kdb_del (kdb);
428 2 : }
429 :
430 2 : KeySet * endings_config (void)
431 : {
432 2 : return ksNew (5, keyNew ("system/elektra/mountpoints", KEY_END), keyNew ("system/elektra/mountpoints/slash", KEY_END),
433 : keyNew ("system/elektra/mountpoints/slash/mountpoint", KEY_VALUE, "user/endings", KEY_END),
434 : keyNew ("system/elektra/mountpoints/hash", KEY_END),
435 : keyNew ("system/elektra/mountpoints/hash/mountpoint", KEY_VALUE, "user/endings#", KEY_END),
436 : keyNew ("system/elektra/mountpoints/space", KEY_END),
437 : keyNew ("system/elektra/mountpoints/space/mountpoint", KEY_VALUE, "user/endings ", KEY_END),
438 : keyNew ("system/elektra/mountpoints/endings", KEY_END),
439 : keyNew ("system/elektra/mountpoints/endings/mountpoint", KEY_VALUE, "user/endings\200", KEY_END), KS_END);
440 : }
441 :
442 2 : static void test_endings (void)
443 : {
444 2 : printf ("Test mounting with different endings\n");
445 :
446 2 : KDB * kdb = kdb_new ();
447 2 : Key * errorKey = keyNew (0);
448 2 : KeySet * modules = modules_config ();
449 2 : succeed_if (mountOpen (kdb, endings_config (), modules, errorKey) == 0, "could not open mount");
450 :
451 2 : succeed_if (output_warnings (errorKey), "warnings found");
452 2 : succeed_if (output_error (errorKey), "error found");
453 :
454 2 : exit_if_fail (kdb->trie, "kdb->trie was not build up successfully");
455 :
456 2 : Key * searchKey = keyNew ("user", KEY_END);
457 2 : Backend * backend = trieLookup (kdb->trie, searchKey);
458 2 : succeed_if (!backend, "there should be no backend");
459 :
460 :
461 2 : Key * mp = keyNew ("user/endings", KEY_VALUE, "slash", KEY_END);
462 2 : keySetName (searchKey, "user/endings");
463 2 : backend = trieLookup (kdb->trie, searchKey);
464 2 : succeed_if (backend, "there should be a backend");
465 2 : if (backend) compare_key (backend->mountpoint, mp);
466 :
467 :
468 2 : keySetName (searchKey, "user/endings#");
469 2 : keySetName (mp, "user/endings#");
470 2 : keySetString (mp, "hash");
471 2 : Backend * b2 = trieLookup (kdb->trie, searchKey);
472 2 : succeed_if (b2, "there should be a backend");
473 2 : succeed_if (backend != b2, "should be other backend");
474 2 : if (b2) compare_key (b2->mountpoint, mp);
475 :
476 :
477 2 : keySetName (searchKey, "user/endings/_");
478 2 : keySetName (mp, "user/endings");
479 2 : keySetString (mp, "slash");
480 2 : b2 = trieLookup (kdb->trie, searchKey);
481 2 : succeed_if (b2, "there should be a backend");
482 2 : succeed_if (backend == b2, "should be the same backend");
483 2 : if (b2) compare_key (b2->mountpoint, mp);
484 :
485 :
486 2 : keySetName (searchKey, "user/endings/X");
487 2 : keySetName (mp, "user/endings");
488 2 : keySetString (mp, "slash");
489 2 : b2 = trieLookup (kdb->trie, searchKey);
490 2 : succeed_if (b2, "there should be a backend");
491 2 : succeed_if (backend == b2, "should be the same backend");
492 2 : if (b2) compare_key (b2->mountpoint, mp);
493 :
494 :
495 2 : keySetName (searchKey, "user/endings_");
496 2 : b2 = trieLookup (kdb->trie, searchKey);
497 2 : succeed_if (!b2, "there should be no backend");
498 :
499 :
500 2 : keySetName (searchKey, "user/endingsX");
501 2 : b2 = trieLookup (kdb->trie, searchKey);
502 2 : succeed_if (!b2, "there should be no backend");
503 :
504 :
505 2 : keySetName (searchKey, "user/endings!");
506 2 : b2 = trieLookup (kdb->trie, searchKey);
507 2 : succeed_if (!b2, "there should be no backend");
508 :
509 :
510 2 : keySetName (searchKey, "user/endings ");
511 2 : keySetName (mp, "user/endings ");
512 2 : keySetString (mp, "space");
513 2 : b2 = trieLookup (kdb->trie, searchKey);
514 2 : succeed_if (b2, "there should be a backend");
515 2 : succeed_if (backend != b2, "should be other backend");
516 2 : if (b2) compare_key (b2->mountpoint, mp);
517 :
518 2 : keySetName (searchKey, "user/endings\200");
519 2 : keySetName (mp, "user/endings\200");
520 2 : keySetString (mp, "endings");
521 2 : b2 = trieLookup (kdb->trie, searchKey);
522 2 : succeed_if (b2, "there should be a backend");
523 2 : succeed_if (backend != b2, "should be other backend");
524 2 : if (b2) compare_key (b2->mountpoint, mp);
525 :
526 : // output_trie(trie);
527 :
528 2 : keyDel (errorKey);
529 2 : ksDel (modules);
530 2 : keyDel (mp);
531 2 : keyDel (searchKey);
532 2 : kdb_del (kdb);
533 2 : }
534 :
535 2 : KeySet * oldroot_config (void)
536 : {
537 2 : return ksNew (5, keyNew ("system/elektra/mountpoints", KEY_END), keyNew ("system/elektra/mountpoints/root", KEY_END),
538 : keyNew ("system/elektra/mountpoints/root/mountpoint", KEY_VALUE, "", KEY_END),
539 : keyNew ("system/elektra/mountpoints/simple", KEY_END),
540 : keyNew ("system/elektra/mountpoints/simple/mountpoint", KEY_VALUE, "user/tests/simple", KEY_END), KS_END);
541 : }
542 :
543 2 : static void test_oldroot (void)
544 : {
545 2 : printf ("Test mounting with old root\n");
546 :
547 2 : KDB * kdb = kdb_new ();
548 2 : Key * errorKey = keyNew (0);
549 2 : KeySet * modules = modules_config ();
550 2 : succeed_if (mountOpen (kdb, oldroot_config (), modules, errorKey) == 0, "root should be mounted as default");
551 :
552 2 : succeed_if (output_warnings (errorKey), "warnings found");
553 2 : succeed_if (output_error (errorKey), "error found");
554 :
555 2 : exit_if_fail (kdb->trie, "trie was not build up successfully");
556 :
557 2 : Key * searchKey = keyNew ("user", KEY_END);
558 2 : Key * rmp = keyNew ("", KEY_VALUE, "root", KEY_END);
559 2 : Backend * backend = trieLookup (kdb->trie, searchKey);
560 2 : succeed_if (!backend, "there should be no root backend");
561 :
562 :
563 2 : Key * mp = keyNew ("user/tests/simple", KEY_VALUE, "simple", KEY_END);
564 2 : keySetName (searchKey, "user/tests/simple");
565 2 : backend = trieLookup (kdb->trie, searchKey);
566 2 : succeed_if (backend, "there should be a backend");
567 2 : if (backend) compare_key (backend->mountpoint, mp);
568 :
569 :
570 2 : keySetName (searchKey, "user/tests/simple/below");
571 2 : Backend * b2 = trieLookup (kdb->trie, searchKey);
572 2 : succeed_if (b2, "there should be a backend");
573 2 : succeed_if (backend == b2, "should be same backend");
574 2 : if (b2) compare_key (b2->mountpoint, mp);
575 :
576 :
577 2 : keySetName (searchKey, "user/tests/simple/deep/below");
578 2 : b2 = trieLookup (kdb->trie, searchKey);
579 2 : succeed_if (b2, "there should be a backend");
580 2 : succeed_if (backend == b2, "should be same backend");
581 2 : if (b2) compare_key (b2->mountpoint, mp);
582 :
583 2 : keyDel (mp);
584 2 : keyDel (rmp);
585 :
586 2 : keyDel (searchKey);
587 :
588 2 : kdb_del (kdb);
589 2 : keyDel (errorKey);
590 2 : ksDel (modules);
591 2 : }
592 :
593 2 : KeySet * cascading_config (void)
594 : {
595 2 : return ksNew (5, keyNew ("system/elektra/mountpoints", KEY_END), keyNew ("system/elektra/mountpoints/simple", KEY_END),
596 : keyNew ("system/elektra/mountpoints/simple/mountpoint", KEY_VALUE, "/tests/simple", KEY_END), KS_END);
597 : }
598 :
599 2 : static void test_cascading (void)
600 : {
601 2 : printf ("Test simple mount with cascading\n");
602 :
603 2 : KDB * kdb = kdb_new ();
604 2 : Key * errorKey = keyNew (0);
605 2 : KeySet * modules = modules_config ();
606 2 : succeed_if (mountOpen (kdb, cascading_config (), modules, errorKey) == 0, "could not open trie");
607 :
608 2 : succeed_if (output_warnings (errorKey), "warnings found");
609 2 : succeed_if (output_error (errorKey), "error found");
610 :
611 2 : exit_if_fail (kdb->trie, "kdb->trie was not build up successfully");
612 :
613 : // output_trie (kdb->trie);
614 :
615 2 : Key * searchKey = keyNew ("user", KEY_END);
616 2 : Backend * backend = trieLookup (kdb->trie, searchKey);
617 2 : succeed_if (!backend, "there should be no backend");
618 :
619 2 : keySetName (searchKey, "system");
620 2 : backend = trieLookup (kdb->trie, searchKey);
621 2 : succeed_if (!backend, "there should be no backend");
622 :
623 :
624 2 : Key * mp = keyNew ("/tests/simple", KEY_VALUE, "simple", KEY_END);
625 :
626 2 : keySetName (searchKey, "user/tests/simple");
627 2 : backend = trieLookup (kdb->trie, searchKey);
628 2 : succeed_if (backend, "there should be a backend");
629 2 : if (backend) compare_key (backend->mountpoint, mp);
630 :
631 :
632 2 : keySetName (searchKey, "user/tests/simple/below");
633 2 : Backend * b2 = trieLookup (kdb->trie, searchKey);
634 2 : succeed_if (b2, "there should be a backend");
635 2 : succeed_if (backend == b2, "should be same backend");
636 2 : if (b2) compare_key (b2->mountpoint, mp);
637 :
638 :
639 2 : keySetName (searchKey, "user/tests/simple/deep/below");
640 2 : b2 = trieLookup (kdb->trie, searchKey);
641 2 : succeed_if (b2, "there should be a backend");
642 2 : succeed_if (backend == b2, "should be same backend");
643 2 : if (b2) compare_key (b2->mountpoint, mp);
644 :
645 :
646 2 : keySetName (searchKey, "system/tests/simple");
647 2 : backend = trieLookup (kdb->trie, searchKey);
648 2 : succeed_if (backend, "there should be a backend");
649 2 : if (backend) compare_key (backend->mountpoint, mp);
650 :
651 2 : keySetName (searchKey, "system/tests/simple/below");
652 2 : b2 = trieLookup (kdb->trie, searchKey);
653 2 : succeed_if (b2, "there should be a backend");
654 2 : succeed_if (backend == b2, "should be same backend");
655 2 : if (b2) compare_key (b2->mountpoint, mp);
656 :
657 :
658 2 : keySetName (searchKey, "system/tests/simple/deep/below");
659 2 : b2 = trieLookup (kdb->trie, searchKey);
660 2 : succeed_if (b2, "there should be a backend");
661 2 : succeed_if (backend == b2, "should be same backend");
662 2 : if (b2) compare_key (b2->mountpoint, mp);
663 :
664 :
665 2 : keyDel (errorKey);
666 2 : ksDel (modules);
667 2 : keyDel (mp);
668 2 : keyDel (searchKey);
669 2 : kdb_del (kdb);
670 2 : }
671 :
672 :
673 8 : KeySet * root_config (void)
674 : {
675 8 : return ksNew (5, keyNew ("system/elektra/mountpoints", KEY_END), keyNew ("system/elektra/mountpoints/root", KEY_END),
676 : keyNew ("system/elektra/mountpoints/root/mountpoint", KEY_VALUE, "/", KEY_END),
677 : keyNew ("system/elektra/mountpoints/simple", KEY_END),
678 : keyNew ("system/elektra/mountpoints/simple/mountpoint", KEY_VALUE, "user/tests/simple", KEY_END), KS_END);
679 : }
680 :
681 2 : static void test_root (void)
682 : {
683 2 : printf ("Test mounting with root\n");
684 :
685 2 : KDB * kdb = kdb_new ();
686 2 : Key * errorKey = keyNew (0);
687 2 : KeySet * modules = modules_config ();
688 2 : succeed_if (mountOpen (kdb, root_config (), modules, errorKey) == 0, "could not buildup mount");
689 :
690 2 : succeed_if (output_warnings (errorKey), "warnings found");
691 2 : succeed_if (output_error (errorKey), "error found");
692 :
693 2 : exit_if_fail (kdb->trie, "trie was not build up successfully");
694 :
695 2 : Key * searchKey = keyNew ("", KEY_END);
696 2 : Key * rmp = keyNew ("/", KEY_VALUE, "root", KEY_END);
697 2 : Backend * b2 = 0;
698 :
699 2 : keySetName (searchKey, "user");
700 2 : b2 = trieLookup (kdb->trie, searchKey);
701 2 : succeed_if (b2, "there should be a backend");
702 2 : if (b2) compare_key (b2->mountpoint, rmp);
703 :
704 :
705 2 : Backend * backend = 0;
706 2 : Key * mp = keyNew ("user/tests/simple", KEY_VALUE, "simple", KEY_END);
707 2 : keySetName (searchKey, "user/tests/simple");
708 2 : backend = trieLookup (kdb->trie, searchKey);
709 2 : succeed_if (backend, "there should be a backend");
710 2 : if (backend) compare_key (backend->mountpoint, mp);
711 :
712 :
713 2 : keySetName (searchKey, "user/tests/simple/below");
714 2 : b2 = trieLookup (kdb->trie, searchKey);
715 2 : succeed_if (b2, "there should be a backend");
716 2 : succeed_if (backend == b2, "should be same backend");
717 2 : if (b2) compare_key (b2->mountpoint, mp);
718 :
719 :
720 2 : keySetName (searchKey, "user/tests/simple/deep/below");
721 2 : b2 = trieLookup (kdb->trie, searchKey);
722 2 : succeed_if (b2, "there should be a backend");
723 2 : succeed_if (backend == b2, "should be same backend");
724 2 : if (b2) compare_key (b2->mountpoint, mp);
725 :
726 2 : keyDel (mp);
727 2 : keyDel (rmp);
728 :
729 2 : keyDel (searchKey);
730 :
731 2 : kdb_del (kdb);
732 2 : keyDel (errorKey);
733 2 : ksDel (modules);
734 2 : }
735 :
736 2 : static void test_default (void)
737 : {
738 2 : printf ("Test mounting with default\n");
739 :
740 2 : KDB * kdb = kdb_new ();
741 2 : Key * errorKey = keyNew (0);
742 2 : KeySet * modules = modules_config ();
743 2 : succeed_if (mountOpen (kdb, root_config (), modules, errorKey) == 0, "could not buildup mount");
744 2 : succeed_if (mountDefault (kdb, modules, 1, errorKey) == 0, "could not mount default backend");
745 :
746 2 : succeed_if (output_warnings (errorKey), "warnings found");
747 2 : succeed_if (output_error (errorKey), "error found");
748 :
749 2 : exit_if_fail (kdb->trie, "trie was not build up successfully");
750 :
751 : // output_trie (kdb->trie);
752 :
753 2 : Key * searchKey = keyNew ("", KEY_END);
754 2 : Key * rmp = keyNew ("/", KEY_VALUE, "root", KEY_END);
755 2 : Backend * b2 = 0;
756 :
757 2 : keySetName (searchKey, "user");
758 2 : b2 = trieLookup (kdb->trie, searchKey);
759 2 : succeed_if (b2, "there should be a backend");
760 2 : if (b2) compare_key (b2->mountpoint, rmp);
761 :
762 :
763 2 : Backend * backend = 0;
764 2 : Key * mp = keyNew ("user/tests/simple", KEY_VALUE, "simple", KEY_END);
765 2 : keySetName (searchKey, "user/tests/simple");
766 2 : backend = trieLookup (kdb->trie, searchKey);
767 2 : succeed_if (backend, "there should be a backend");
768 2 : if (backend) compare_key (backend->mountpoint, mp);
769 :
770 :
771 2 : keySetName (searchKey, "user/tests/simple/below");
772 2 : b2 = trieLookup (kdb->trie, searchKey);
773 2 : succeed_if (b2, "there should be a backend");
774 2 : succeed_if (backend == b2, "should be same backend");
775 2 : if (b2) compare_key (b2->mountpoint, mp);
776 :
777 :
778 2 : keySetName (searchKey, "user/tests/simple/deep/below");
779 2 : b2 = trieLookup (kdb->trie, searchKey);
780 2 : succeed_if (b2, "there should be a backend");
781 2 : succeed_if (backend == b2, "should be same backend");
782 2 : if (b2) compare_key (b2->mountpoint, mp);
783 :
784 2 : Key * dmp = keyNew ("", KEY_VALUE, "default", KEY_END);
785 2 : keySetName (searchKey, "system/elektra");
786 2 : b2 = trieLookup (kdb->trie, searchKey);
787 2 : succeed_if (b2, "there should be a backend");
788 2 : succeed_if (b2 == kdb->defaultBackend, "should be the default backend");
789 2 : if (b2) compare_key (b2->mountpoint, dmp);
790 :
791 2 : keySetName (searchKey, "system/elektra/below");
792 2 : b2 = trieLookup (kdb->trie, searchKey);
793 2 : succeed_if (b2, "there should be a backend");
794 2 : succeed_if (b2 == kdb->defaultBackend, "should be the default backend");
795 2 : if (b2) compare_key (b2->mountpoint, dmp);
796 :
797 2 : keyDel (dmp);
798 2 : keyDel (mp);
799 2 : keyDel (rmp);
800 :
801 2 : keyDel (searchKey);
802 :
803 2 : kdb_del (kdb);
804 2 : keyDel (errorKey);
805 2 : ksDel (modules);
806 2 : }
807 :
808 2 : static void test_init (void)
809 : {
810 2 : printf ("Test mounting with init (no config)\n");
811 :
812 2 : KDB * kdb = kdb_new ();
813 2 : Key * errorKey = keyNew (0);
814 2 : KeySet * modules = modules_config ();
815 2 : succeed_if (mountOpen (kdb, ksNew (5, KS_END), modules, errorKey) == 0, "could not buildup mount");
816 2 : succeed_if (mountDefault (kdb, modules, 0, errorKey) == 0, "could not mount default backend");
817 :
818 2 : succeed_if (output_warnings (errorKey), "warnings found");
819 2 : succeed_if (output_error (errorKey), "error found");
820 :
821 2 : exit_if_fail (kdb->trie, "trie was not build up successfully");
822 :
823 : // output_trie (kdb->trie);
824 : // output_split (kdb->split);
825 :
826 2 : Key * searchKey = keyNew ("", KEY_END);
827 2 : Key * dmp = keyNew ("", KEY_VALUE, "default", KEY_END);
828 2 : Backend * b2 = 0;
829 :
830 2 : keySetName (searchKey, "user");
831 2 : b2 = trieLookup (kdb->trie, searchKey);
832 2 : succeed_if (!b2, "there should be no backend");
833 :
834 2 : keySetName (searchKey, "user/tests/simple");
835 2 : b2 = trieLookup (kdb->trie, searchKey);
836 2 : succeed_if (!b2, "there should be no backend");
837 :
838 2 : keySetName (searchKey, "user/tests/simple/below");
839 2 : b2 = trieLookup (kdb->trie, searchKey);
840 2 : succeed_if (!b2, "there should be no backend");
841 :
842 :
843 2 : keySetName (searchKey, "user/tests/simple/deep/below");
844 2 : b2 = trieLookup (kdb->trie, searchKey);
845 2 : succeed_if (!b2, "there should be no backend");
846 :
847 2 : keySetName (searchKey, "system/elektra");
848 2 : b2 = trieLookup (kdb->trie, searchKey);
849 2 : succeed_if (b2, "there should be a backend");
850 2 : succeed_if (b2 == kdb->initBackend, "should be the init backend");
851 2 : if (b2) compare_key (b2->mountpoint, dmp);
852 :
853 2 : keySetName (searchKey, "system/elektra/below");
854 2 : b2 = trieLookup (kdb->trie, searchKey);
855 2 : succeed_if (b2, "there should be a backend");
856 2 : succeed_if (b2 == kdb->initBackend, "should be the init backend");
857 2 : if (b2) compare_key (b2->mountpoint, dmp);
858 :
859 2 : keySetName (searchKey, "system");
860 2 : b2 = trieLookup (kdb->trie, searchKey);
861 2 : succeed_if (!b2, "there should be no backend");
862 :
863 2 : keySetName (searchKey, "system/something");
864 2 : b2 = trieLookup (kdb->trie, searchKey);
865 2 : succeed_if (!b2, "there should be no backend");
866 :
867 2 : keyDel (dmp);
868 :
869 2 : keyDel (searchKey);
870 :
871 2 : kdb_del (kdb);
872 2 : keyDel (errorKey);
873 2 : ksDel (modules);
874 2 : }
875 :
876 2 : static void test_rootInit (void)
877 : {
878 2 : printf ("Test mounting with root and init\n");
879 :
880 2 : KDB * kdb = kdb_new ();
881 2 : Key * errorKey = keyNew (0);
882 2 : KeySet * modules = modules_config ();
883 2 : succeed_if (mountOpen (kdb, root_config (), modules, errorKey) == 0, "could not buildup mount");
884 2 : succeed_if (mountDefault (kdb, modules, 0, errorKey) == 0, "could not mount default backend");
885 :
886 2 : succeed_if (output_warnings (errorKey), "warnings found");
887 2 : succeed_if (output_error (errorKey), "error found");
888 :
889 2 : exit_if_fail (kdb->trie, "trie was not build up successfully");
890 :
891 : // output_trie (kdb->trie);
892 :
893 2 : Key * searchKey = keyNew ("", KEY_END);
894 2 : Key * rmp = keyNew ("/", KEY_VALUE, "root", KEY_END);
895 2 : Backend * b2 = 0;
896 :
897 2 : keySetName (searchKey, "user");
898 2 : b2 = trieLookup (kdb->trie, searchKey);
899 2 : succeed_if (b2, "there should be a backend");
900 2 : if (b2) compare_key (b2->mountpoint, rmp);
901 :
902 :
903 2 : Backend * backend = 0;
904 2 : Key * mp = keyNew ("user/tests/simple", KEY_VALUE, "simple", KEY_END);
905 2 : keySetName (searchKey, "user/tests/simple");
906 2 : backend = trieLookup (kdb->trie, searchKey);
907 2 : succeed_if (backend, "there should be a backend");
908 2 : if (backend) compare_key (backend->mountpoint, mp);
909 :
910 :
911 2 : keySetName (searchKey, "user/tests/simple/below");
912 2 : b2 = trieLookup (kdb->trie, searchKey);
913 2 : succeed_if (b2, "there should be a backend");
914 2 : succeed_if (backend == b2, "should be same backend");
915 2 : if (b2) compare_key (b2->mountpoint, mp);
916 :
917 :
918 2 : keySetName (searchKey, "user/tests/simple/deep/below");
919 2 : b2 = trieLookup (kdb->trie, searchKey);
920 2 : succeed_if (b2, "there should be a backend");
921 2 : succeed_if (backend == b2, "should be same backend");
922 2 : if (b2) compare_key (b2->mountpoint, mp);
923 :
924 2 : Key * dmp = keyNew ("", KEY_VALUE, "default", KEY_END);
925 2 : keySetName (searchKey, "system/elektra");
926 2 : b2 = trieLookup (kdb->trie, searchKey);
927 2 : succeed_if (b2, "there should be a backend");
928 2 : succeed_if (b2 == kdb->initBackend, "should be the init backend");
929 2 : if (b2) compare_key (b2->mountpoint, dmp);
930 :
931 2 : keySetName (searchKey, "system/elektra/below");
932 2 : b2 = trieLookup (kdb->trie, searchKey);
933 2 : succeed_if (b2, "there should be a backend");
934 2 : succeed_if (b2 == kdb->initBackend, "should be the init backend");
935 2 : if (b2) compare_key (b2->mountpoint, dmp);
936 :
937 2 : keySetName (searchKey, "system");
938 2 : b2 = trieLookup (kdb->trie, searchKey);
939 2 : succeed_if (b2, "there should be a backend");
940 2 : succeed_if (b2 != kdb->initBackend, "should not be the init backend");
941 2 : if (b2) compare_key (b2->mountpoint, rmp);
942 :
943 2 : keySetName (searchKey, "system/something");
944 2 : b2 = trieLookup (kdb->trie, searchKey);
945 2 : succeed_if (b2, "there should be a backend");
946 2 : succeed_if (b2 != kdb->initBackend, "should not be the init backend");
947 2 : if (b2) compare_key (b2->mountpoint, rmp);
948 :
949 2 : keyDel (dmp);
950 2 : keyDel (mp);
951 2 : keyDel (rmp);
952 :
953 2 : keyDel (searchKey);
954 :
955 2 : kdb_del (kdb);
956 2 : keyDel (errorKey);
957 2 : ksDel (modules);
958 2 : }
959 :
960 2 : static void test_modules (void)
961 : {
962 2 : printf ("Test mounting with modules\n");
963 :
964 2 : KDB * kdb = kdb_new ();
965 2 : Key * errorKey = keyNew (0);
966 2 : KeySet * modules = modules_config ();
967 2 : succeed_if (mountOpen (kdb, root_config (), modules, errorKey) == 0, "could not buildup mount");
968 2 : succeed_if (mountDefault (kdb, modules, 1, errorKey) == 0, "could not mount default backend");
969 2 : succeed_if (mountModules (kdb, modules, errorKey) == 0, "could not mount modules");
970 :
971 2 : succeed_if (output_warnings (errorKey), "warnings found");
972 2 : succeed_if (output_error (errorKey), "error found");
973 :
974 2 : exit_if_fail (kdb->trie, "trie was not build up successfully");
975 :
976 : // output_trie (kdb->trie);
977 :
978 2 : Key * searchKey = keyNew ("", KEY_END);
979 2 : Key * rmp = keyNew ("/", KEY_VALUE, "root", KEY_END);
980 2 : Backend * b2 = 0;
981 :
982 2 : keySetName (searchKey, "user");
983 2 : b2 = trieLookup (kdb->trie, searchKey);
984 2 : succeed_if (b2, "there should be a backend");
985 2 : if (b2) compare_key (b2->mountpoint, rmp);
986 :
987 :
988 2 : Backend * backend = 0;
989 2 : Key * mp = keyNew ("user/tests/simple", KEY_VALUE, "simple", KEY_END);
990 2 : keySetName (searchKey, "user/tests/simple");
991 2 : backend = trieLookup (kdb->trie, searchKey);
992 2 : succeed_if (backend, "there should be a backend");
993 2 : if (backend) compare_key (backend->mountpoint, mp);
994 :
995 :
996 2 : keySetName (searchKey, "user/tests/simple/below");
997 2 : b2 = trieLookup (kdb->trie, searchKey);
998 2 : succeed_if (b2, "there should be a backend");
999 2 : succeed_if (backend == b2, "should be same backend");
1000 2 : if (b2) compare_key (b2->mountpoint, mp);
1001 :
1002 :
1003 2 : keySetName (searchKey, "user/tests/simple/deep/below");
1004 2 : b2 = trieLookup (kdb->trie, searchKey);
1005 2 : succeed_if (b2, "there should be a backend");
1006 2 : succeed_if (backend == b2, "should be same backend");
1007 2 : if (b2) compare_key (b2->mountpoint, mp);
1008 :
1009 2 : Key * dmp = keyNew ("", KEY_VALUE, "default", KEY_END);
1010 2 : keySetName (searchKey, "system/elektra");
1011 2 : b2 = trieLookup (kdb->trie, searchKey);
1012 2 : succeed_if (b2, "there should be a backend");
1013 2 : succeed_if (b2 == kdb->defaultBackend, "should be the default backend");
1014 2 : if (b2) compare_key (b2->mountpoint, dmp);
1015 :
1016 2 : keySetName (searchKey, "system/elektra/below");
1017 2 : b2 = trieLookup (kdb->trie, searchKey);
1018 2 : succeed_if (b2, "there should be a backend");
1019 2 : succeed_if (b2 == kdb->defaultBackend, "should be the default backend");
1020 2 : if (b2) compare_key (b2->mountpoint, dmp);
1021 :
1022 2 : Key * mmp = keyNew ("system/elektra/modules", KEY_VALUE, "modules", KEY_END);
1023 2 : keyAddBaseName (mmp, "default");
1024 :
1025 : /*
1026 : keySetName(searchKey, "system/elektra/modules/default");
1027 : b2 = trieLookup(kdb->trie, searchKey);
1028 : succeed_if (b2, "there should be a backend");
1029 : succeed_if (b2 != kdb->defaultBackend, "should not be the default backend");
1030 : compare_key(b2->mountpoint, mmp);
1031 : */
1032 :
1033 2 : keyDel (mmp);
1034 2 : keyDel (dmp);
1035 2 : keyDel (mp);
1036 2 : keyDel (rmp);
1037 :
1038 2 : keyDel (searchKey);
1039 :
1040 2 : kdb_del (kdb);
1041 2 : keyDel (errorKey);
1042 2 : ksDel (modules);
1043 2 : }
1044 :
1045 2 : int main (int argc, char ** argv)
1046 : {
1047 2 : printf ("MOUNT TESTS\n");
1048 2 : printf ("==================\n\n");
1049 :
1050 2 : init (argc, argv);
1051 :
1052 2 : test_mount ();
1053 2 : test_minimaltrie ();
1054 2 : test_simple ();
1055 2 : test_simpletrie ();
1056 2 : test_two ();
1057 2 : test_us ();
1058 2 : test_endings ();
1059 2 : test_oldroot ();
1060 2 : test_cascading ();
1061 2 : test_root ();
1062 2 : test_default ();
1063 2 : test_init ();
1064 2 : test_rootInit ();
1065 2 : test_modules ();
1066 :
1067 2 : printf ("\ntest_trie RESULTS: %d test(s) done. %d error(s).\n", nbTest, nbError);
1068 :
1069 2 : return nbError;
1070 : }
|