forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestmod_filecheck.c
More file actions
149 lines (136 loc) · 3.7 KB
/
Copy pathtestmod_filecheck.c
File metadata and controls
149 lines (136 loc) · 3.7 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
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
/**
* @file
*
* @brief Tests for filecheck 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 testBom (const char * filename, int reject, int expected)
{
Key * parentKey = keyNew ("user:/tests/filecheck", KEY_VALUE, srcdir_file (filename), KEY_END);
KeySet * conf;
if (!reject)
{
conf = NULL;
}
else
{
conf = ksNew (10, keyNew ("system:/reject/bom", KEY_END), KS_END);
}
KeySet * ks = ksNew (0, KS_END);
PLUGIN_OPEN ("filecheck");
int ret = plugin->kdbGet (plugin, ks, parentKey);
succeed_if (ret == expected, "kdbGet failed");
PLUGIN_CLOSE ();
ksDel (ks);
keyDel (parentKey);
}
static void testNull (const char * filename, int reject, int expected)
{
Key * parentKey = keyNew ("user:/tests/filecheck", KEY_VALUE, srcdir_file (filename), KEY_END);
KeySet * conf;
if (!reject)
{
conf = NULL;
}
else
{
conf = ksNew (10, keyNew ("system:/reject/null", KEY_END), KS_END);
}
KeySet * ks = ksNew (0, KS_END);
PLUGIN_OPEN ("filecheck");
int ret = plugin->kdbGet (plugin, ks, parentKey);
succeed_if (ret == expected, "kdbGet failed");
PLUGIN_CLOSE ();
ksDel (ks);
keyDel (parentKey);
}
static void testLEConsistency (const char * filename, int reject, int expected)
{
Key * parentKey = keyNew ("user:/tests/filecheck", KEY_VALUE, srcdir_file (filename), KEY_END);
KeySet * conf;
if (!reject)
{
conf = NULL;
}
else
{
conf = ksNew (10, keyNew ("system:/check/lineending", KEY_END), KS_END);
}
KeySet * ks = ksNew (0, KS_END);
PLUGIN_OPEN ("filecheck");
int ret = plugin->kdbGet (plugin, ks, parentKey);
succeed_if (ret == expected, "kdbGet failed");
PLUGIN_CLOSE ();
ksDel (ks);
keyDel (parentKey);
}
static void testLEcrlf (const char * filename, int reject, int expected)
{
Key * parentKey = keyNew ("user:/tests/filecheck", KEY_VALUE, srcdir_file (filename), KEY_END);
KeySet * conf;
if (!reject)
{
conf = NULL;
}
else
{
conf = ksNew (10, keyNew ("system:/check/lineending", KEY_END),
keyNew ("system:/valid/lineending", KEY_VALUE, "CRLF", KEY_END), KS_END);
}
KeySet * ks = ksNew (0, KS_END);
PLUGIN_OPEN ("filecheck");
int ret = plugin->kdbGet (plugin, ks, parentKey);
succeed_if (ret == expected, "kdbGet failed");
PLUGIN_CLOSE ();
ksDel (ks);
keyDel (parentKey);
}
static void testEncoding (const char * filename, int reject, int expected)
{
Key * parentKey = keyNew ("user:/tests/filecheck", KEY_VALUE, srcdir_file (filename), KEY_END);
KeySet * conf;
if (!reject)
{
conf = NULL;
}
else
{
conf = ksNew (10, keyNew ("system:/check/encoding", KEY_END),
keyNew ("system:/valid/encoding", KEY_VALUE, "UTF-8", KEY_END), KS_END);
}
KeySet * ks = ksNew (0, KS_END);
PLUGIN_OPEN ("filecheck");
int ret = plugin->kdbGet (plugin, ks, parentKey);
succeed_if (ret == expected, "kdbGet failed");
PLUGIN_CLOSE ();
ksDel (ks);
keyDel (parentKey);
}
int main (int argc, char ** argv)
{
printf ("FILECHECK TESTS\n");
printf ("==================\n\n");
init (argc, argv);
testBom ("filecheck/BOMFILE", 0, 1);
testBom ("filecheck/BOMFILE", 1, (-1));
testBom ("filecheck/NOBOMFILE", 0, 1);
testBom ("filecheck/NOBOMFILE", 1, 1);
testNull ("filecheck/NULLBYTE", 0, 1);
testNull ("filecheck/NULLBYTE", 1, (-1));
testNull ("filecheck/NONULLBYTE", 0, 1);
testNull ("filecheck/NONULLBYTE", 1, 1);
testLEConsistency ("filecheck/inconsistent", 0, 1);
testLEConsistency ("filecheck/inconsistent", 1, (-1));
testLEcrlf ("filecheck/valid1", 1, 1);
testLEcrlf ("filecheck/invalid", 1, (-1));
testEncoding ("filecheck/utf.txt", 1, 1);
testEncoding ("filecheck/iso.txt", 1, (-1));
print_result ("testmod_filecheck");
return nbError;
}