forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestmod_lineendings.c
126 lines (98 loc) · 4.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
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
/**
* @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, const char * lineending)
{
Key * parentKey = keyNew ("user:/tests/lineendings", KEY_VALUE, srcdir_file (file), KEY_END);
KeySet * conf = ksNew (20, keyNew ("system:/valid", KEY_VALUE, lineending, KEY_END), KS_END);
PLUGIN_OPEN ("lineendings");
KeySet * ks = ksNew (0, KS_END);
/* get value should (always) be successful */
succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS,
"kdbGet returned an unexpected value (ELEKTRA_PLUGIN_STATUS_SUCCESS was expected)");
/* get value should be successful */
succeed_if (plugin->kdbCommit (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS,
"kdbCommit returned an unexpected value (ELEKTRA_PLUGIN_STATUS_SUCCESS was expected)");
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);
/* check if no warnings are initial present in the parent key */
succeed_if (keyGetMeta (parentKey, "warnings") == NULL, "A warning on the parentKey was present before calling kdbGet.");
/* get value should always be successful since only warnings are produced */
succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS,
"kdbGet returned an unexpected value (ELEKTRA_PLUGIN_STATUS_SUCCESS was expected)");
/* check if a warning was added to the parent key because of the previous get value */
succeed_if (keyGetMeta (parentKey, "warnings") != NULL,
"A warning on the parentKey was not present after an invalid call to kdbGet.");
/* check if no errors are initial present in the parent key */
succeed_if (keyGetMeta (parentKey, "error") == NULL, "An error on the parentKey was present before the call the kdbCommit");
/* set value should produce an error */
succeed_if (plugin->kdbCommit (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_ERROR,
"kdbGet returned an unexpected value (ELEKTRA_PLUGIN_STATUS_ERROR was expected)");
/* check if an error was added to the parent key because of the previous set value */
succeed_if (keyGetMeta (parentKey, "error") != NULL,
"An error on the parentKey was not present after an invalid call to kdbCommit.");
ksDel (ks);
keyDel (parentKey);
PLUGIN_CLOSE ();
}
void testinvalid (const char * file, const char * lineending)
{
Key * parentKey = keyNew ("user:/tests/lineendings", KEY_VALUE, srcdir_file (file), KEY_END);
KeySet * conf = ksNew (20, keyNew ("system:/valid", KEY_VALUE, lineending, KEY_END), KS_END);
PLUGIN_OPEN ("lineendings");
KeySet * ks = ksNew (0, KS_END);
/* check if no warnings are initial present in the parent key */
succeed_if (keyGetMeta (parentKey, "warnings") == NULL, "A warning on the parentKey was present before calling kdbGet.");
/* get value should always be successful since only warnings are produced */
succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS,
"kdbGet returned an unexpected value (ELEKTRA_PLUGIN_STATUS_SUCCESS was expected).");
/* check if a warning was added to the parent key because of the previous get value */
succeed_if (keyGetMeta (parentKey, "warnings") != NULL,
"A warning on the parentKey was not present after an invalid call to kdbGet.");
/* check if no errors are initial present in the parent key */
succeed_if (keyGetMeta (parentKey, "error") == NULL, "An error on the parentKey was present before the call the kdbCommit");
/* set value should produce an error */
succeed_if (plugin->kdbCommit (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_ERROR,
"kdbCommit returned an unexpected value (ELEKTRA_PLUGIN_STATUS_ERROR was expected).");
/* check if an error was added to the parent key because of the previous set value */
succeed_if (keyGetMeta (parentKey, "error") != NULL,
"An error on the parentKey was not present after an invalid call to kdbCommit.");
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", "CRLF");
testvalid ("lineendings/valid2", "LF");
testvalid ("lineendings/valid3", "LFCR");
testvalid ("lineendings/valid4", "CR");
testinconsistent ("lineendings/inconsistent1");
testinconsistent ("lineendings/inconsistent2");
testinvalid ("lineendings/invalid1", "CRLF");
testinvalid ("lineendings/invalid1", "LFCR");
testinvalid ("lineendings/invalid1", "CR");
testinvalid ("lineendings/invalid2", "LF");
print_result ("testmod_lineendings");
return nbError;
}