forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testmod_lineendings.c
70 lines (59 loc) · 1.87 KB
/
testmod_lineendings.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
/**
* @file
*
* @brief Tests for lineendings 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>
void testvalid (const char * file)
{
Key * parentKey = keyNew ("user/tests/lineendings", KEY_VALUE, srcdir_file (file), KEY_END);
KeySet * conf = 0;
PLUGIN_OPEN ("lineendings");
KeySet * ks = ksNew (0, KS_END);
succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbget failed");
succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbset failed");
ksDel (ks);
keyDel (parentKey);
PLUGIN_CLOSE ();
}
void testinconsistent (const char * file)
{
Key * parentKey = keyNew ("user/tests/lineendings", KEY_VALUE, srcdir_file (file), KEY_END);
KeySet * conf = 0;
PLUGIN_OPEN ("lineendings");
KeySet * ks = ksNew (0, KS_END);
succeed_if (plugin->kdbGet (plugin, ks, parentKey) == (-1), "should have failed");
succeed_if (plugin->kdbSet (plugin, ks, parentKey) == (-1), "should have failed");
ksDel (ks);
keyDel (parentKey);
PLUGIN_CLOSE ();
}
void testinvalid (const char * file)
{
Key * parentKey = keyNew ("user/tests/lineendings", KEY_VALUE, srcdir_file (file), KEY_END);
KeySet * conf = ksNew (20, keyNew ("system/valid", KEY_VALUE, "CRLF", KEY_END), KS_END);
PLUGIN_OPEN ("lineendings");
KeySet * ks = ksNew (0, KS_END);
succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbget failed");
succeed_if (plugin->kdbSet (plugin, ks, parentKey) == (-1), "should have failed");
ksDel (ks);
keyDel (parentKey);
PLUGIN_CLOSE ();
}
int main (int argc, char ** argv)
{
printf ("LINEENDINGS TESTS\n");
printf ("==================\n\n");
init (argc, argv);
testvalid ("lineendings/valid1");
testinconsistent ("lineendings/inconsistent");
testinvalid ("lineendings/invalid");
print_result ("testmod_lineendings");
return nbError;
}