forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testmod_process.c
111 lines (87 loc) · 3.47 KB
/
testmod_process.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
/**
* @file
*
* @brief Tests for process 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 test_basics (void)
{
printf ("test basics\n");
const char * tmpFile = elektraFilename ();
Key * parentKey = keyNew ("user/tests/process", KEY_VALUE, tmpFile, KEY_END);
KeySet * conf = ksNew (0, KS_END);
// We can safely assume dump exists as without it the processplugin wouldn't work
// We don't test any other plugin here since we can't make any guarantees about their existence
Key * pluginKey = keyNew ("/plugin", KEY_VALUE, "dump", KEY_END);
ksAppendKey (conf, pluginKey);
PLUGIN_OPEN ("process");
KeySet * ks = ksNew (0, KS_END);
succeed_if (plugin->kdbOpen (plugin, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbOpen was not successful");
Key * contractKey = keyNew ("system/elektra/modules/process", KEY_END);
KeySet * contractSet = ksNew (0, KS_END);
succeed_if (plugin->kdbGet (plugin, contractSet, contractKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS,
"call to kdbGet for the contract was not successful");
succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
succeed_if (plugin->kdbError (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbError was not successful");
succeed_if (plugin->kdbClose (plugin, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbClose was not successful");
keyDel (contractKey);
ksDel (contractSet);
keyDel (parentKey);
ksDel (ks);
PLUGIN_CLOSE ();
elektraUnlink (tmpFile);
}
static void test_no_plugin_key (void)
{
printf ("test no plugin key \n");
Key * parentKey = keyNew ("user/tests/process", KEY_END);
KeySet * conf = ksNew (0, KS_END);
// No plugin key, should fail
KeySet * modules = ksNew (0, KS_END);
elektraModulesInit (modules, 0);
Key * errorKey = keyNew ("", KEY_END);
Plugin * plugin = elektraPluginOpen ("process", modules, conf, errorKey);
succeed_if (!output_warnings (errorKey), "no warnings in kdbOpen for plugin process");
succeed_if (output_error (errorKey), "error in kdbOpen for plugin process");
keyDel (errorKey);
keyDel (parentKey);
succeed_if (plugin != 0, "could not open process plugin");
PLUGIN_CLOSE ();
}
static void test_invalid_plugin_key (void)
{
printf ("test invalid plugin key\n");
Key * parentKey = keyNew ("user/tests/process", KEY_END);
KeySet * conf = ksNew (0, KS_END);
Key * pluginKey = keyNew ("/plugin", KEY_VALUE, "non_existent_plugin", KEY_END);
ksAppendKey (conf, pluginKey);
// Non-existent plugin, should fail
KeySet * modules = ksNew (0, KS_END);
elektraModulesInit (modules, 0);
Key * errorKey = keyNew ("", KEY_END);
Plugin * plugin = elektraPluginOpen ("process", modules, conf, errorKey);
succeed_if (!output_warnings (errorKey), "no warnings in kdbOpen for plugin process");
succeed_if (!output_error (errorKey), "no error in kdbOpen for plugin process");
keyDel (errorKey);
keyDel (parentKey);
succeed_if (plugin == 0, "could open process plugin");
PLUGIN_CLOSE ();
}
int main (int argc, char ** argv)
{
printf ("PROCESS TESTS\n");
printf ("==================\n\n");
init (argc, argv);
test_basics ();
test_no_plugin_key ();
test_invalid_plugin_key ();
print_result ("testmod_process");
return nbError;
}