|
0 |
- |
1 |
#include <stdlib.h> |
1 |
-- |
2 |
#include <stdio.h> |
|
|
3 |
#include <stdbool.h> |
4 |
#include "filter.h" |
5 |
|
6 |
static struct filter filter = { |
7 |
.base = "dc=bar,dc=baz", |
8 |
.scope = 2, // LDAP.SCOPE_SUBTREE |
9 |
.filter = "objectclass=*", |
10 |
}; |
11 |
static struct filter *filters[2] = { |
12 |
&filter, |
13 |
NULL, |
14 |
}; |
15 |
static CacheEntry entry = { |
16 |
.attributes = NULL, |
17 |
.attribute_count = 0, |
18 |
.modules = NULL, |
19 |
.module_count = 0, |
20 |
}; |
21 |
|
22 |
static bool test_match_exact(void) { |
23 |
char dn[] = "dc=bar,dc=baz"; |
24 |
int r = cache_entry_ldap_filter_match(filters, dn, &entry); |
25 |
return r == 1; |
26 |
} |
27 |
|
28 |
static bool test_match_one(void) { |
29 |
char dn[] = "dc=foo,dc=bar,dc=baz"; |
30 |
int r = cache_entry_ldap_filter_match(filters, dn, &entry); |
31 |
return r == 1; |
32 |
} |
33 |
|
34 |
static bool test_match_other(void) { |
35 |
char dn[] = "dc=foo"; |
36 |
int r = cache_entry_ldap_filter_match(filters, dn, &entry); |
37 |
return r == 0; |
38 |
} |
39 |
|
40 |
static bool test_match_sub(void) { |
41 |
char dn[] = "dc=bam,dc=foo,dc=bar,dc=baz"; |
42 |
int r = cache_entry_ldap_filter_match(filters, dn, &entry); |
43 |
return r == 1; |
44 |
} |
45 |
|
46 |
static bool test_match_case(void) { |
47 |
char dn[] = "dc=foo,dc=bar,dc=BAZ"; |
48 |
int r = cache_entry_ldap_filter_match(filters, dn, &entry); |
49 |
return r == 0; |
50 |
} |
51 |
|
52 |
static bool test_match_short(void) { |
53 |
char dn[] = "dc=baz"; |
54 |
int r = cache_entry_ldap_filter_match(filters, dn, &entry); |
55 |
return r == 0; |
56 |
} |
57 |
|
58 |
static bool test_match_infix(void) { |
59 |
char dn[] = "dc=foo,dc=bar,dc=baz,dc=bam"; |
60 |
int r = cache_entry_ldap_filter_match(filters, dn, &entry); |
61 |
return r == 0; |
62 |
} |
63 |
|
64 |
#define TEST(n) { .name = "test_" # n, .func = test_##n } |
65 |
struct tests { |
66 |
const char *name; |
67 |
bool (*func)(void); |
68 |
} tests[] = { |
69 |
TEST(match_exact), |
70 |
TEST(match_one), |
71 |
TEST(match_other), |
72 |
TEST(match_sub), |
73 |
TEST(match_case), |
74 |
TEST(match_short), |
75 |
TEST(match_infix), |
76 |
}; |
77 |
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x))) |
78 |
|
79 |
int main(int argc, char *argv[]) { |
80 |
int i, failed = 0; |
81 |
for (i = 0; i < ARRAY_SIZE(tests); i++) |
82 |
if (tests[i].func()) { |
83 |
fprintf(stdout, "+%s\n", tests[i].name); |
84 |
} else { |
85 |
fprintf(stdout, "-%s\n", tests[i].name); |
86 |
failed++; |
87 |
} |
88 |
return failed; |
89 |
} |
2 |
.../univention-directory-listener/src/filter.c | 36 +++++++++++--------- |
90 |
.../univention-directory-listener/src/filter.c | 36 +++++++++++--------- |
3 |
1 files changed, 20 insertions(+), 16 deletions(-) |
91 |
1 files changed, 20 insertions(+), 16 deletions(-) |