This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathtest_backends.c
126 lines (108 loc) · 4.37 KB
/
test_backends.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
124
125
126
/**
* @file
*
* @brief
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*/
#include <kdb.h>
#include <kdbprivate.h>
#include <stdlib.h>
#include <tests.h>
static void addBackendForDivide (KeySet * backends, const char * mountpoint)
{
BackendData data = {
.backend = NULL,
.keys = ksNew (0, KS_END),
.definition = NULL,
.plugins = NULL,
.initialized = false,
};
ksAppendKey (backends, keyNew (mountpoint, KEY_BINARY, KEY_SIZE, sizeof (data), KEY_VALUE, &data, KEY_END));
}
static void deleteBackends (KeySet * backends)
{
for (elektraCursor i = 0; i < ksGetSize (backends); i++)
{
BackendData * data = (BackendData *) keyValue (ksAtCursor (backends, i));
ksDel (data->keys);
}
ksDel (backends);
}
// TODO [new_backend]: more thorough tests
void test_backendsDivide (void)
{
printf ("Test backendsDivide");
KeySet * backends = ksNew (0, KS_END);
addBackendForDivide (backends, "dir:/");
addBackendForDivide (backends, "user:/");
addBackendForDivide (backends, "user:/bar");
addBackendForDivide (backends, "user:/bar/bar");
addBackendForDivide (backends, "user:/bar/baz");
addBackendForDivide (backends, "user:/bar/foo");
addBackendForDivide (backends, "user:/baz");
addBackendForDivide (backends, "user:/foo");
addBackendForDivide (backends, "system:/");
addBackendForDivide (backends, "default:/");
// clang-format off
KeySet * ks = ksNew (20,
keyNew ("spec:/xyz", KEY_END),
keyNew ("user:/abc", KEY_END),
keyNew ("user:/bak/abc", KEY_END),
keyNew ("user:/bar/abc", KEY_END),
keyNew ("user:/bar/bar/abc", KEY_END),
keyNew ("user:/bar/bar/def", KEY_END),
keyNew ("user:/bar/bar/xyz", KEY_END),
keyNew ("user:/bar/foo/abc", KEY_END),
keyNew ("user:/bar/foo/xyz", KEY_END),
keyNew ("user:/bar/xyz", KEY_END),
keyNew ("user:/foo/abc", KEY_END),
keyNew ("user:/foo/xyz", KEY_END),
keyNew ("user:/xyz", KEY_END),
keyNew ("default:/xyz", KEY_END),
KS_END);
// clang-format on
succeed_if (backendsDivide (backends, ks) == 1, "couldn't split ks");
KeySet * ks0 = ksNew (10, KS_END);
KeySet * ks1 = ksNew (10, keyNew ("user:/abc", KEY_END), keyNew ("user:/bak/abc", KEY_END), keyNew ("user:/xyz", KEY_END), KS_END);
KeySet * ks2 = ksNew (10, keyNew ("user:/bar/abc", KEY_END), keyNew ("user:/bar/xyz", KEY_END), KS_END);
KeySet * ks3 = ksNew (10, keyNew ("user:/bar/bar/abc", KEY_END), keyNew ("user:/bar/bar/def", KEY_END),
keyNew ("user:/bar/bar/xyz", KEY_END), KS_END);
KeySet * ks4 = ksNew (10, KS_END);
KeySet * ks5 = ksNew (10, keyNew ("user:/bar/foo/abc", KEY_END), keyNew ("user:/bar/foo/xyz", KEY_END), KS_END);
KeySet * ks6 = ksNew (10, KS_END);
KeySet * ks7 = ksNew (10, keyNew ("user:/foo/abc", KEY_END), keyNew ("user:/foo/xyz", KEY_END), KS_END);
KeySet * ks8 = ksNew (10, KS_END);
KeySet * ks9 = ksNew (10, keyNew ("default:/xyz", KEY_END), keyNew ("spec:/xyz", KEY_END), KS_END);
compare_keyset (ks0, ((const BackendData *) keyValue (ksLookupByName (backends, "dir:/", 0)))->keys);
compare_keyset (ks1, ((const BackendData *) keyValue (ksLookupByName (backends, "user:/", 0)))->keys);
compare_keyset (ks2, ((const BackendData *) keyValue (ksLookupByName (backends, "user:/bar", 0)))->keys);
compare_keyset (ks3, ((const BackendData *) keyValue (ksLookupByName (backends, "user:/bar/bar", 0)))->keys);
compare_keyset (ks4, ((const BackendData *) keyValue (ksLookupByName (backends, "user:/bar/baz", 0)))->keys);
compare_keyset (ks5, ((const BackendData *) keyValue (ksLookupByName (backends, "user:/bar/foo", 0)))->keys);
compare_keyset (ks6, ((const BackendData *) keyValue (ksLookupByName (backends, "user:/baz", 0)))->keys);
compare_keyset (ks7, ((const BackendData *) keyValue (ksLookupByName (backends, "user:/foo", 0)))->keys);
compare_keyset (ks8, ((const BackendData *) keyValue (ksLookupByName (backends, "system:/", 0)))->keys);
compare_keyset (ks9, ((const BackendData *) keyValue (ksLookupByName (backends, "default:/", 0)))->keys);
deleteBackends (backends);
ksDel (ks);
ksDel (ks0);
ksDel (ks1);
ksDel (ks2);
ksDel (ks3);
ksDel (ks4);
ksDel (ks5);
ksDel (ks6);
ksDel (ks7);
ksDel (ks8);
ksDel (ks9);
}
int main (int argc, char ** argv)
{
printf ("BACKENDS TESTS\n");
printf ("==================\n\n");
init (argc, argv);
test_backendsDivide ();
printf ("\ntest_backends RESULTS: %d test(s) done. %d error(s).\n", nbTest, nbError);
return nbError;
}