-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibconfc_test.c
75 lines (59 loc) · 2.45 KB
/
libconfc_test.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
#include <stdio.h>
#include "libconfc.h"
int main(int argc, char **argv)
{
if(argc < 2) {
printf("Error: config file not specified\nUsage: %s initial.conf\n", argv[0]);
return 1;
}
conf_t *conf_test = conf_init();
if(!conf_load(conf_test, argv[1])) {
printf("Error loading config file\n");
return 1;
}
printf("\nTest 1: print initial config\n");
conf_print(conf_test);
printf("\nTest 2: print only 'ip' and 'mac' key-value:\n");
const char *val = conf_get_val(conf_test, "ip");
if(val) printf("%s = %s\n", "ip", val);
val = conf_get_val(conf_test, "mac");
if(val) printf("%s = %s\n", "mac", val);
printf("\nTest 3: remove key 'gateway' and print full config\n");
conf_remove(&conf_test, "gateway");
conf_print(conf_test);
printf("\nTest 4: remove last key and print full config\n");
conf_remove(&conf_test, "hostname");
conf_print(conf_test);
printf("\nTest 5: remove first key and print full config\n");
conf_remove(&conf_test, "interface");
conf_print(conf_test);
printf("\nTest 6: check if key 'interface' exists\n");
val = conf_get_val(conf_test, "interface");
!val ? printf("'interface' does not exist\n") : printf("'interface' does exist. val = %s\n", val);
printf("\nTest 7: check if key 'mac' exists\n");
val = conf_get_val(conf_test, "mac");
!val ? printf("'mac' does not exist\n") : printf("'mac' does exist. val = %s\n", val);
printf("\nTest 8: check if key 'mac' = 'f0:19:54:27:7d:ab'\n");
int chk = conf_check_val(conf_test, "mac", "f0:79:59:67:7d:ad");
printf("%s\n", chk ? "true" : "false");
printf("\nTest 9: check if key 'mac' = 'a3:b1:cd:d7:e9:f5'\n");
chk = conf_check_val(conf_test, "mac", "a3:b1:cd:d7:e9:f5");
printf("%s\n", chk ? "true" : "false");
printf("\nTest 10: add new key 'domain1' to the bottom of config\n");
conf_set_val(conf_test, "domain1", "last.org");
conf_print(conf_test);
printf("\nTest 11: add new key 'domain0' to the top of config\n");
conf_add_1st(&conf_test, "domain0", "first.org");
conf_print(conf_test);
printf("\nTest 12: update 'IP' value\n");
conf_set_val(conf_test, "IP", "1.1.1.1");
conf_print(conf_test);
printf("\nTest 13: save modified config to 'modded.conf'\n");
if(!conf_save(conf_test, "modded.conf")) {
printf("Error writing config file\n");
return 1;
} else {
printf("Done!\n");
}
conf_free(conf_test);
}