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
/
testmod_version.c
115 lines (84 loc) · 3.29 KB
/
testmod_version.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
/**
* @file
*
* @brief Tests for version plugin
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*
*/
#include <stdlib.h>
#include <string.h>
#include <kdbconfig.h>
#include <kdbversion.h>
#include <tests_plugin.h>
static void test_basics (void)
{
printf ("test basics\n");
Key * parentKey = keyNew ("system:/elektra/version", KEY_END);
KeySet * conf = ksNew (0, KS_END);
PLUGIN_OPEN ("version");
KeySet * ks = ksNew (0, KS_END);
ElektraKdbPhase phase = ELEKTRA_KDB_GET_PHASE_STORAGE;
plugin->global = ksNew (
1, keyNew ("system:/elektra/kdb/backend/phase", KEY_BINARY, KEY_SIZE, sizeof (ElektraKdbPhase), KEY_VALUE, &phase, KEY_END),
KS_END);
succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
KeySet * expectedKs = elektraVersionKeySet ();
succeed_if (ksGetSize (ks) == ksGetSize (expectedKs), "wrong number of keys returned");
for (elektraCursor i = 0; i < ksGetSize (ks); i++)
{
Key * cur = ksAtCursor (ks, i);
Key * expected = ksAtCursor (expectedKs, i);
succeed_if (strcmp (keyName (expected), keyName (cur)) == 0, "key with wrong name returned");
succeed_if (strcmp (keyString (expected), keyString (cur)) == 0, "key with wrong value returned");
succeed_if (keyGetMeta (cur, "restrict/write") != NULL, "missing restrict/write metadata");
succeed_if (keyGetMeta (cur, "restrict/remove") != NULL, "missing restrict/remove metadata");
}
keyDel (parentKey);
ksDel (expectedKs);
ksDel (ks);
ksDel (plugin->global);
PLUGIN_CLOSE ();
}
static void test_rename (void)
{
printf ("test rename\n");
Key * parentKey = keyNew ("user:/somewhere/else", KEY_END);
size_t parentSize = keyGetNameSize (parentKey) - 1;
KeySet * conf = ksNew (0, KS_END);
PLUGIN_OPEN ("version");
KeySet * ks = ksNew (0, KS_END);
ElektraKdbPhase phase = ELEKTRA_KDB_GET_PHASE_STORAGE;
plugin->global = ksNew (
1, keyNew ("system:/elektra/kdb/backend/phase", KEY_BINARY, KEY_SIZE, sizeof (ElektraKdbPhase), KEY_VALUE, &phase, KEY_END),
KS_END);
succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
KeySet * expectedKs = elektraVersionKeySet ();
succeed_if (ksGetSize (ks) == ksGetSize (expectedKs), "wrong number of keys returned");
for (elektraCursor i = 0; i < ksGetSize (ks); i++)
{
Key * cur = ksAtCursor (ks, i);
Key * expected = ksAtCursor (expectedKs, i);
succeed_if (strncmp ("user:/somewhere/else", keyName (cur), parentSize) == 0, "key with wrong name returned");
succeed_if (strcmp (keyName (expected) + sizeof ("system:/elektra/version") - 1, keyName (cur) + parentSize) == 0,
"key with wrong name returned");
succeed_if (strcmp (keyString (expected), keyString (cur)) == 0, "key with wrong value returned");
succeed_if (keyGetMeta (cur, "restrict/write") != NULL, "missing restrict/write metadata");
succeed_if (keyGetMeta (cur, "restrict/remove") != NULL, "missing restrict/remove metadata");
}
keyDel (parentKey);
ksDel (expectedKs);
ksDel (ks);
ksDel (plugin->global);
PLUGIN_CLOSE ();
}
int main (int argc, char ** argv)
{
printf ("VERSION TESTS\n");
printf ("==================\n\n");
init (argc, argv);
test_basics ();
test_rename ();
print_result ("testmod_version");
return nbError;
}