-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestmod_validation.c
95 lines (68 loc) · 2.17 KB
/
testmod_validation.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
#ifdef HAVE_KDBCONFIG_H
#include "kdbconfig.h"
#endif
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <langinfo.h>
#include <tests.h>
#include "validation.h"
#define NR_KEYS 4
void test_lookupre()
{
KeySet *ks = ksNew (5,
keyNew ("user/a", KEY_VALUE, "a", KEY_COMMENT, "does not match", KEY_END),
keyNew ("user/b", KEY_VALUE, " a ", KEY_COMMENT, "does not match", KEY_END),
keyNew ("user/c", KEY_VALUE, "\t\t", KEY_COMMENT, "match", KEY_END),
keyNew ("user/d", KEY_VALUE, " \t \t ", KEY_COMMENT, "match", KEY_END),
KS_END);
Key *match = 0;
regex_t regex;
regcomp(®ex,"^[ \t]*$",REG_NOSUB);
// we start from the first key
ksRewind(ks);
// show the key that match this string
match=ksLookupRE(ks,®ex);
succeed_if (!strcmp(keyName(match), "user/c"), "Key did not match");
match=ksLookupRE(ks,®ex);
succeed_if (!strcmp(keyName(match), "user/d"), "Key did not match");
regfree(®ex); // free regex resources
ksDel (ks);
}
void test_extended()
{
KeySet *ks = ksNew (5,
keyNew ("user/a", KEY_VALUE, "la", KEY_COMMENT, "match", KEY_END),
keyNew ("user/b", KEY_VALUE, "lalala", KEY_COMMENT, "match", KEY_END),
keyNew ("user/c", KEY_VALUE, "jump", KEY_COMMENT, "does not match", KEY_END),
keyNew ("user/d", KEY_VALUE, "lalalala", KEY_COMMENT, "match", KEY_END),
KS_END);
Key *match = 0;
regex_t regex;
regcomp(®ex,"^(la)+$", REG_NOSUB|REG_EXTENDED);
// we start from the first key
ksRewind(ks);
// show the key that match this string
match=ksLookupRE(ks,®ex);
succeed_if (!strcmp(keyName(match), "user/a"), "Key did not match");
match=ksLookupRE(ks,®ex);
succeed_if (!strcmp(keyName(match), "user/b"), "Key did not match");
match=ksLookupRE(ks,®ex);
succeed_if (!strcmp(keyName(match), "user/d"), "Key did not match");
regfree(®ex); // free regex resources
ksDel (ks);
}
int main(int argc, char** argv)
{
printf(" ICONV TESTS\n");
printf("====================\n\n");
init (argc, argv);
test_lookupre();
test_extended();
printf("\ntest_backendhelpers RESULTS: %d test(s) done. %d error(s).\n", nbTest, nbError);
return nbError;
}