forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testmod_dump.c
123 lines (99 loc) · 2.69 KB
/
testmod_dump.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* @file
*
* @brief
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*/
#ifdef HAVE_KDBCONFIG_H
#include "kdbconfig.h"
#endif
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <tests.h>
KeySet * get_dump (void)
{
Key *k1, *k2;
// clang-format off
KeySet *ks = ksNew(10,
k1 = keyNew("user/tests/dump",
KEY_VALUE, "root key",
KEY_META, "a", "b",
KEY_END),
k2 = keyNew("user/tests/dump/a",
KEY_VALUE, "a value",
KEY_META, "ab", "cd",
KEY_END),
keyNew("user/tests/dump/b",
KEY_VALUE, "b value",
KEY_META, "longer val", "here some even more with ugly €@\\1¹²³¼ chars",
KEY_END),
KS_END
);
// clang-format on
keyCopyMeta (k1, k2, "ab");
return ks;
}
#if 0
void test_writedump(const char *file)
{
KDB *kdb = kdbOpen();
Key *mnt;
KeySet *conf;
KeySet *ks = get_dump();
printf("Test write dump\n");
succeed_if (kdbMount(kdb,mnt=keyNew("user/tests/dump",KEY_VALUE,"dump", KEY_END),
conf=ksNew (2,keyNew("system/path", KEY_VALUE, file, KEY_END), KS_END)) == 0,
"could not mount dump");
succeed_if (kdbSet(kdb,ks,keyNew("user/tests/dump",KEY_END),KDB_O_DEL) >= 0, "could not set keys");
ksDel (conf);
keyDel(mnt);
ksDel (ks);
kdbClose (kdb);
}
void test_readdump(const char *file)
{
KDB *kdb = kdbOpen();
Key *mnt;
KeySet *conf;
KeySet *ks = get_dump();
KeySet *read = ksNew(0, KS_END);
Key *k1, *k2;
printf("Test read dump\n");
succeed_if (kdbMount(kdb,mnt=keyNew("user/tests/dump",KEY_VALUE,"dump", KEY_END),
conf=ksNew (2,keyNew("system/path", KEY_VALUE, file, KEY_END), KS_END)) == 0,
"could not mount dump");
succeed_if (kdbGet(kdb,read,keyNew("user/tests/dump",KEY_END),KDB_O_DEL) >= 0, "could not get keys");
ksDel (conf);
keyDel(mnt);
compare_keyset (read, ks, 0, 0);
k1 = ksLookupByName(ks, "user/tests/dump", 0);
succeed_if (k1 != 0, "did not find key");
k2 = ksLookupByName(ks, "user/tests/dump/a", 0);
succeed_if (k2 != 0, "did not find key");
succeed_if (!strcmp(keyValue(keyGetMeta(k1, "ab")), "cd"), "metavalue not correct");
succeed_if (!strcmp(keyValue(keyGetMeta(k2, "ab")), "cd"), "metavalue not correct");
succeed_if (keyGetMeta(k1, "ab") == keyGetMeta(k2, "ab"), "does not point to the same storage");
// ksOutput (read, stdout, KEY_VALUE);
ksDel (ks);
ksDel (read);
kdbClose (kdb);
}
#endif
int main (int argc, char ** argv)
{
printf ("MOUNT TESTS\n");
printf ("==================\n\n");
init (argc, argv);
/*
test_writedump("dump_mount_test.edf");
test_readdump("dump_mount_test.edf");
*/
print_result ("test_mount");
return nbError;
}