|
3 |
#include <unistd.h> |
3 |
#include <unistd.h> |
4 |
#include <assert.h> |
4 |
#include <assert.h> |
5 |
#include <univention/config.h> |
5 |
#include <univention/config.h> |
|
|
6 |
#include <sys/types.h> |
7 |
#include <sys/wait.h> |
8 |
|
9 |
static char ucr_bin[] = "/usr/sbin/univention-config-registry"; |
10 |
static char ucr_name[] = "univention-config-registry"; |
11 |
static char key[] = "test/clib"; |
12 |
static char *LAYER[] = { |
13 |
"--ldap-policy", |
14 |
"--schedule", |
15 |
"--force", |
16 |
NULL, |
17 |
}; |
18 |
|
19 |
int fork_exec(char **argv) { |
20 |
pid_t pid; |
21 |
int status; |
22 |
|
23 |
pid = fork(); |
24 |
switch (pid) { |
25 |
case -1: // error |
26 |
abort(); |
27 |
|
28 |
case 0: // child |
29 |
return execv(ucr_bin, argv); |
30 |
|
31 |
default: // parent |
32 |
pid = wait(&status); |
33 |
assert(WIFEXITED(status) && WEXITSTATUS(status) == 0); |
34 |
return 0; |
35 |
} |
36 |
} |
37 |
|
38 |
int test_layer(void) { |
39 |
char assign[64]; |
40 |
int r, layer; |
41 |
pid_t pid; |
42 |
|
43 |
for (layer = 0; LAYER[layer]; layer++) { |
44 |
size_t size; |
45 |
|
46 |
size = snprintf(assign, sizeof assign, "%s=%s", key, LAYER[layer]); |
47 |
assert(0 < size && size < sizeof assign); |
48 |
char *argv[] = { |
49 |
ucr_name, |
50 |
"set", |
51 |
LAYER[layer], |
52 |
assign, |
53 |
NULL |
54 |
}; |
55 |
fprintf(stderr, "set %s %s\n", LAYER[layer], assign); |
56 |
fork_exec(argv); |
57 |
|
58 |
char *c = univention_config_get_string(key); |
59 |
fprintf(stderr, "should=%s is=%s\n", LAYER[layer], c); |
60 |
r = strcmp(c, LAYER[layer]); |
61 |
assert(r == 0); |
62 |
} |
63 |
|
64 |
for (layer = 0; LAYER[layer]; layer++) { |
65 |
char *argv[] = { |
66 |
ucr_name, |
67 |
"unset", |
68 |
LAYER[layer], |
69 |
key, |
70 |
NULL |
71 |
}; |
72 |
fprintf(stderr, "unset %s %s\n", LAYER[layer], key); |
73 |
fork_exec(argv); |
74 |
} |
75 |
} |
6 |
|
76 |
|
7 |
int main(void) { |
77 |
int main(void) { |
8 |
char key[] = "test/clib"; |
|
|
9 |
char value[] = "42"; |
78 |
char value[] = "42"; |
10 |
int r; |
79 |
int r; |
11 |
|
80 |
|
12 |
r = univention_config_set_string(key, value); |
81 |
r = univention_config_set_string(key, value); |
|
|
82 |
fprintf(stderr, "set %s=%s [%d]\n", key, value, r); |
13 |
assert(r == 0); |
83 |
assert(r == 0); |
14 |
|
84 |
|
15 |
char *c = univention_config_get_string(key); |
85 |
char *c = univention_config_get_string(key); |
|
|
86 |
fprintf(stderr, "get_str %s=%s\n", key, c); |
16 |
assert(c != NULL); |
87 |
assert(c != NULL); |
17 |
assert(strcmp(c, value) == 0); |
88 |
assert(strcmp(c, value) == 0); |
18 |
free(c); |
89 |
free(c); |
19 |
|
90 |
|
20 |
int i = univention_config_get_int(key); |
91 |
int i = univention_config_get_int(key); |
|
|
92 |
fprintf(stderr, "get_int %s=%d\n", key, i); |
21 |
assert(i == atoi(value)); |
93 |
assert(i == atoi(value)); |
22 |
|
94 |
|
23 |
long l = univention_config_get_long(key); |
95 |
long l = univention_config_get_long(key); |
|
|
96 |
fprintf(stderr, "get_long %s=%d\n", key, l); |
24 |
assert(l == atol(value)); |
97 |
assert(l == atol(value)); |
25 |
|
98 |
|
|
|
99 |
test_layer(); |
100 |
|
26 |
char *argv[] = { |
101 |
char *argv[] = { |
27 |
"univention-config-registry", |
102 |
ucr_name, |
28 |
"unset", |
103 |
"unset", |
29 |
key, |
104 |
key, |
30 |
NULL |
105 |
NULL |
31 |
}; |
106 |
}; |
32 |
return execv("/usr/sbin/univention-config-registry", argv); |
107 |
fprintf(stderr, "unset %s\n", key); |
|
|
108 |
return execv(ucr_bin, argv); |
33 |
} |
109 |
} |