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_process.c
205 lines (167 loc) · 9.95 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/**
* @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_success (void)
{
printf ("test success\n");
Key * parentKey = keyNew ("user:/tests/process", KEY_END);
KeySet * conf = ksNew (1, keyNew ("user:/executable", KEY_VALUE, bindir_file ("process-testapp.sh"), KEY_END), KS_END);
PLUGIN_OPEN ("process");
// replace config, after PLUGIN_OPEN so that we can test kdbOpen
ksClear (plugin->config);
KeySet * newConf = ksNew (16, keyNew ("user:/executable", KEY_VALUE, bindir_file ("process-testapp.sh"), KEY_END), KS_END);
ksAppend (plugin->config, newConf);
ksDel (newConf);
// need to run close first, so we don't create memory leaks via double opn
succeed_if (plugin->kdbClose (plugin, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbClose was not successful");
succeed_if (strcmp (keyName (parentKey), "user:/tests/process") == 0, "parent has wrong name");
succeed_if (strcmp (keyString (parentKey), "close") == 0, "parent has wrong value");
KeySet * ks = ksNew (0, KS_END);
succeed_if (plugin->kdbOpen (plugin, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbOpen was not successful");
succeed_if (strcmp (keyName (parentKey), "user:/tests/process") == 0, "parent has wrong name");
succeed_if (strcmp (keyString (parentKey), "open") == 0, "parent has wrong value");
ksClear (ks);
succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
succeed_if (ksGetSize (ks) == 1, "ks has wrong size");
succeed_if (ksGetSize (ks) >= 1 && strcmp (keyName (ksAtCursor (ks, 0)), "user:/tests/process/operation") == 0,
"key has wrong name");
succeed_if (ksGetSize (ks) >= 1 && strcmp (keyString (ksAtCursor (ks, 0)), "get") == 0, "key has wrong value");
succeed_if (strcmp (keyName (parentKey), "user:/tests/process") == 0, "parent has wrong name");
succeed_if (strcmp (keyString (parentKey), "get") == 0, "parent has wrong value");
ksClear (ks);
succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
succeed_if (ksGetSize (ks) == 1, "ks has wrong size");
succeed_if (ksGetSize (ks) >= 1 && strcmp (keyName (ksAtCursor (ks, 0)), "user:/tests/process/operation") == 0,
"key has wrong name");
succeed_if (ksGetSize (ks) >= 1 && strcmp (keyString (ksAtCursor (ks, 0)), "set") == 0, "key has wrong value");
succeed_if (strcmp (keyName (parentKey), "user:/tests/process") == 0, "parent has wrong name");
succeed_if (strcmp (keyString (parentKey), "set") == 0, "parent has wrong value");
KeySet * expectedContract = ksNew (
16, keyNew ("system:/elektra/modules/testapp/exports/close", KEY_FUNC, plugin->kdbClose, KEY_END),
keyNew ("system:/elektra/modules/testapp/exports/get", KEY_FUNC, plugin->kdbGet, KEY_END),
keyNew ("system:/elektra/modules/testapp/exports/open", KEY_FUNC, plugin->kdbOpen, KEY_END),
keyNew ("system:/elektra/modules/testapp/exports/set", KEY_FUNC, plugin->kdbSet, KEY_END),
keyNew ("system:/elektra/modules/testapp/infos", KEY_VALUE, "Information about the process test plugin is in keys below",
KEY_END),
keyNew ("system:/elektra/modules/testapp/infos/author", KEY_VALUE, "Klemens Böswirth <[email protected]>", KEY_END),
keyNew ("system:/elektra/modules/testapp/infos/description", KEY_VALUE, "test plugin for process", KEY_END),
keyNew ("system:/elektra/modules/testapp/infos/licence", KEY_VALUE, "BSD", KEY_END),
keyNew ("system:/elektra/modules/testapp/infos/metadata", KEY_VALUE, "", KEY_END),
keyNew ("system:/elektra/modules/testapp/infos/needs", KEY_VALUE, "", KEY_END),
keyNew ("system:/elektra/modules/testapp/infos/placements", KEY_VALUE, "getstorage setstorage", KEY_END),
keyNew ("system:/elektra/modules/testapp/infos/provides", KEY_VALUE, "", KEY_END),
keyNew ("system:/elektra/modules/testapp/infos/recommends", KEY_VALUE, "", KEY_END),
keyNew ("system:/elektra/modules/testapp/infos/status", KEY_VALUE, "maintained unittest shelltest experimental", KEY_END),
KS_END);
ksClear (ks);
keySetName (parentKey, "system:/elektra/modules/testapp");
succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS,
"call to kdbGet (contract) was not successful");
compare_keyset (ks, expectedContract);
ksDel (expectedContract);
keyDel (parentKey);
ksDel (ks);
PLUGIN_CLOSE ();
}
static void test_error (void)
{
printf ("test error\n");
Key * parentKey = keyNew ("user:/tests/process", KEY_END);
KeySet * conf = ksNew (1, keyNew ("user:/executable", KEY_VALUE, bindir_file ("process-testapp.sh"), KEY_END), KS_END);
PLUGIN_OPEN ("process");
// replace config, after PLUGIN_OPEN so that we can test kdbOpen
ksClear (plugin->config);
KeySet * newConf =
ksNew (16, keyNew ("user:/executable", KEY_VALUE, bindir_file ("process-testapp.sh"), KEY_END),
keyNew ("user:/args", KEY_VALUE, "#0", KEY_END), keyNew ("user:/args/#0", KEY_VALUE, "error", KEY_END), KS_END);
ksAppend (plugin->config, newConf);
ksDel (newConf);
// need to run close first, so we don't create memory leaks via double open
succeed_if (plugin->kdbClose (plugin, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbClose was not error");
succeed_if (strcmp (keyName (parentKey), "user:/tests/process") == 0, "parent has wrong name");
succeed_if (strcmp (keyString (parentKey), "close") == 0, "parent has wrong value");
KeySet * ks = ksNew (0, KS_END);
succeed_if (plugin->kdbOpen (plugin, parentKey) == ELEKTRA_PLUGIN_STATUS_ERROR, "call to kdbOpen was not error");
succeed_if (strcmp (keyName (parentKey), "user:/tests/process") == 0, "parent has wrong name");
succeed_if (strcmp (keyString (parentKey), "open") == 0, "parent has wrong value");
ksClear (ks);
succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_ERROR, "call to kdbGet was not error");
succeed_if (ksGetSize (ks) == 1, "ks has wrong size");
succeed_if (ksGetSize (ks) >= 1 && strcmp (keyName (ksAtCursor (ks, 0)), "user:/tests/process/operation") == 0,
"key has wrong name");
succeed_if (ksGetSize (ks) >= 1 && strcmp (keyString (ksAtCursor (ks, 0)), "get") == 0, "key has wrong value");
succeed_if (strcmp (keyName (parentKey), "user:/tests/process") == 0, "parent has wrong name");
succeed_if (strcmp (keyString (parentKey), "get") == 0, "parent has wrong value");
ksClear (ks);
succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_ERROR, "call to kdbSet was not error");
succeed_if (ksGetSize (ks) == 1, "ks has wrong size");
succeed_if (ksGetSize (ks) >= 1 && strcmp (keyName (ksAtCursor (ks, 0)), "user:/tests/process/operation") == 0,
"key has wrong name");
succeed_if (ksGetSize (ks) >= 1 && strcmp (keyString (ksAtCursor (ks, 0)), "set") == 0, "key has wrong value");
succeed_if (strcmp (keyName (parentKey), "user:/tests/process") == 0, "parent has wrong name");
succeed_if (strcmp (keyString (parentKey), "set") == 0, "parent has wrong value");
keyDel (parentKey);
ksDel (ks);
PLUGIN_CLOSE ();
}
static void test_noupdate (void)
{
printf ("test noupdate\n");
Key * parentKey = keyNew ("user:/tests/process", KEY_END);
KeySet * conf = ksNew (1, keyNew ("user:/executable", KEY_VALUE, bindir_file ("process-testapp.sh"), KEY_END), KS_END);
PLUGIN_OPEN ("process");
// replace config, after PLUGIN_OPEN so that we can test kdbOpen
ksClear (plugin->config);
KeySet * newConf =
ksNew (16, keyNew ("user:/executable", KEY_VALUE, bindir_file ("process-testapp.sh"), KEY_END),
keyNew ("user:/args", KEY_VALUE, "#0", KEY_END), keyNew ("user:/args/#0", KEY_VALUE, "noupdate", KEY_END), KS_END);
ksAppend (plugin->config, newConf);
ksDel (newConf);
// need to run close first, so we don't create memory leaks via double open
succeed_if (plugin->kdbClose (plugin, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbClose was not no_update");
succeed_if (strcmp (keyName (parentKey), "user:/tests/process") == 0, "parent has wrong name");
succeed_if (strcmp (keyString (parentKey), "close") == 0, "parent has wrong value");
KeySet * ks = ksNew (0, KS_END);
succeed_if (plugin->kdbOpen (plugin, parentKey) == ELEKTRA_PLUGIN_STATUS_NO_UPDATE, "call to kdbOpen was not no_update");
succeed_if (strcmp (keyName (parentKey), "user:/tests/process") == 0, "parent has wrong name");
succeed_if (strcmp (keyString (parentKey), "open") == 0, "parent has wrong value");
ksClear (ks);
succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_NO_UPDATE, "call to kdbGet was not no_update");
succeed_if (ksGetSize (ks) == 1, "ks has wrong size");
succeed_if (ksGetSize (ks) >= 1 && strcmp (keyName (ksAtCursor (ks, 0)), "user:/tests/process/operation") == 0,
"key has wrong name");
succeed_if (ksGetSize (ks) >= 1 && strcmp (keyString (ksAtCursor (ks, 0)), "get") == 0, "key has wrong value");
succeed_if (strcmp (keyName (parentKey), "user:/tests/process") == 0, "parent has wrong name");
succeed_if (strcmp (keyString (parentKey), "get") == 0, "parent has wrong value");
ksClear (ks);
succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_NO_UPDATE, "call to kdbSet was not no_update");
succeed_if (ksGetSize (ks) == 1, "ks has wrong size");
succeed_if (ksGetSize (ks) >= 1 && strcmp (keyName (ksAtCursor (ks, 0)), "user:/tests/process/operation") == 0,
"key has wrong name");
succeed_if (ksGetSize (ks) >= 1 && strcmp (keyString (ksAtCursor (ks, 0)), "set") == 0, "key has wrong value");
succeed_if (strcmp (keyName (parentKey), "user:/tests/process") == 0, "parent has wrong name");
succeed_if (strcmp (keyString (parentKey), "set") == 0, "parent has wrong value");
keyDel (parentKey);
ksDel (ks);
PLUGIN_CLOSE ();
}
int main (int argc, char ** argv)
{
printf ("PROCESS TESTS\n");
printf ("==================\n\n");
init (argc, argv);
test_success ();
test_error ();
test_noupdate ();
print_result ("testmod_process");
return nbError;
}