Git init
[pkgs/e/elektra.git] / tests / test_trie.c
1 /*************************************************************************** 
2  *           test_trie.c  - Test suite for trie data structure
3  *                  -------------------
4  *  begin                : Thu Oct 24 2007
5  *  copyright            : (C) 2007 by Patrick Sabin
6  *  email                : patricksabin@gmx.at
7  ****************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the BSD License (revised).                      *
13  *                                                                         *
14  ***************************************************************************/
15
16 #ifdef HAVE_CONFIG_H
17 #include "config.h"
18 #endif
19
20 #include <stdio.h>
21 #ifdef HAVE_STDLIB_H
22 #include <stdlib.h>
23 #endif
24 #ifdef HAVE_STRING_H
25 #include <string.h>
26 #endif
27
28 #include <tests.h>
29
30 /*Needs private declarations*/
31 #include <kdbprivate.h>
32
33 void *mapper(void *s,char *backend)
34 {
35         return s;
36 }
37
38 void test_kdbTrie()
39 {
40         KDB *kdb = kdbOpen();
41
42         KeySet *ks=ksNew(0);
43
44         /*
45         k = keyNew ("user/template/key",0);
46         s=kdbGetBackend(kdb,k);
47         exit_if_fail(s, "Got null pointer from kdbGetBackend");
48         succeed_if(!strcmp("libelektra-template",kdbhGetBackendName(s)), "kdbGetBackend: didn't get the correct value");
49         keyDel (k);
50         */
51
52         /*
53         k = keyNew ("user/key",0);
54         s=kdbGetBackend(kdb,k);
55         exit_if_fail(s, "Got null pointer from kdbGetBackend");
56         succeed_if(!strcmp("libelektra-filesys",kdbhGetBackendName(s)), "kdbGetBackend: didn't get the correct value");
57         keyDel (k);
58         
59         k = keyNew ("system/key",0);
60         s=kdbGetBackend(kdb,k);
61         exit_if_fail(s, "Got null pointer from kdbGetBackend");
62         succeed_if(!strcmp("libelektra-filesys",kdbhGetBackendName(s)), "kdbGetBackend: didn't get the correct value");
63         keyDel (k);
64
65         k = keyNew ("system/filesystems/hda/",0);
66         s=kdbGetBackend(kdb,k);
67         exit_if_fail(s, "Got null pointer from kdbGetBackend");
68         succeed_if(!strcmp("libelektra-fstab",kdbhGetBackendName(s)), "kdbGetBackend: didn't get the correct value");
69         keyDel (k);
70         
71         printf ("Looking up dynamic mounting\n");
72         printf(BACKEND_DIR "fstab2/config/path\n");
73         ksAppendKey(ks,keyNew(BACKEND_DIR "fstab2/config/path",KEY_VALUE,"/tmp/fstab2",0));
74         kdbMount(kdb, mountpoint=keyNew("system/fstab/",0), "fstab",ks);
75
76         k = keyNew ("system/fstab/dev/hda",0);
77         s=kdbGetBackend(kdb,k);
78         exit_if_fail(s, "Got null pointer from kdbGetBackend");
79         succeed_if(!strcmp("libelektra-fstab",kdbhGetBackendName(s)), "kdbGetBackend: didn't get the correct value");
80         keyDel (k);
81
82         kdbUnmount(kdb,mountpoint);
83         keyDel(mountpoint);
84
85         k = keyNew ("system/fstab/dev/hda",0);
86         s=kdbGetBackend(kdb,k);
87         exit_if_fail(s, "Got null pointer from kdbGetBackend");
88         succeed_if(!strcmp("libelektra-filesys",kdbhGetBackendName(s)), "kdbGetBackend: didn't get the correct value");
89         keyDel (k);
90         */
91         /**/
92
93         ksDel (ks);
94         kdbClose (kdb);
95 }
96
97 int main()
98 {
99         printf("TRIE       TESTS\n");
100         printf("==================\n\n");
101
102         init ();
103
104         test_kdbTrie();
105
106         printf("\ntest_trie RESULTS: %d test(s) done. %d error(s).\n", nbTest, nbError);
107
108         return nbError;
109 }
110