forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestmod_list.c
More file actions
84 lines (71 loc) · 2.91 KB
/
testmod_list.c
File metadata and controls
84 lines (71 loc) · 2.91 KB
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
/**
* @file
*
* @brief Tests for list plugin
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*
*/
#include <stdlib.h>
#include <string.h>
#include <kdbconfig.h>
#include <tests_plugin.h>
static void doTest (void)
{
KeySet * ks = ksNew (5, keyNew ("user:/tests/list/to/be/cut/key1", KEY_END), keyNew ("user:/tests/list/to/be/cut/key2", KEY_END),
keyNew ("user:/tests/list/to/be/cut/meta1", KEY_END),
keyNew ("user:/tests/list/to/be/cut/meta2", KEY_VALUE, "meta?", KEY_META, "convert/metaname", "amimetanow?",
KEY_META, "convert/append", "previous", KEY_END),
KS_END);
KeySet * conf = ksNew (
20, keyNew ("user:/placements", KEY_END), keyNew ("user:/placements/get", KEY_VALUE, "pregetstorage", KEY_END),
keyNew ("user:/placements/set", KEY_VALUE, "presetstorage", KEY_END), keyNew ("user:/plugins", KEY_END),
keyNew ("user:/plugins/#0", KEY_VALUE, "rename", KEY_END), keyNew ("user:/plugins/#0/config", KEY_END),
// Configure "rename" plugin directly to cut a part of the key name
keyNew ("user:/plugins/#0/config/cut", KEY_VALUE, "to/be/cut", KEY_END), keyNew ("user:/plugins/#0/placements", KEY_END),
keyNew ("user:/plugins/#0/placements/set", KEY_VALUE, "presetstorage", KEY_END),
keyNew ("user:/plugins/#0/placements/get", KEY_VALUE, "pregetstorage", KEY_END),
keyNew ("user:/plugins/#1", KEY_VALUE, "keytometa", KEY_END), keyNew ("user:/plugins/#1/placements", KEY_END),
keyNew ("user:/plugins/#1/placements/set", KEY_VALUE, "presetstorage", KEY_END),
keyNew ("user:/plugins/#1/placements/get", KEY_VALUE, "pregetstorage", KEY_END),
// For all plugins, but only used by "rename" plugin
keyNew ("user:/config", KEY_END), keyNew ("user:/config/toupper", KEY_END), KS_END);
Key * parentKey = keyNew ("user:/tests/list", KEY_END);
ksAppendKey (ks, parentKey);
PLUGIN_OPEN ("list");
Plugin * check = elektraPluginOpen ("keytometa", modules, ksNew (5, KS_END), parentKey);
if (!check)
{
printf ("Abort test case, keytometa is missing");
goto end;
}
elektraPluginClose (check, 0);
check = elektraPluginOpen ("rename", modules, ksNew (5, KS_END), parentKey);
if (!check)
{
printf ("Abort test case, rename is missing");
goto end;
}
elektraPluginClose (check, 0);
succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbget failed");
const Key * key = ksLookupByName (ks, "user:/tests/list/META1", 0);
succeed_if (key, "key not found");
const Key * meta = keyGetMeta (key, "amimetanow?");
succeed_if (meta, "metakey not found");
succeed_if (plugin->kdbSet (plugin, ks, parentKey) >= 0, "kdbset failed");
key = ksLookupByName (ks, "user:/tests/list/to/be/cut/meta1", 0);
succeed_if (key, "key not found");
end:
PLUGIN_CLOSE ();
keyDel (parentKey);
ksDel (ks);
}
int main (int argc, char ** argv)
{
printf ("LIST TESTS\n");
printf ("==================\n\n");
init (argc, argv);
doTest ();
print_result ("testmod_list");
return nbError;
}