diff options
Diffstat (limited to 'lib/tests')
-rw-r--r-- | lib/tests/test_ini.c | 25 | ||||
-rwxr-xr-x | lib/tests/test_ini.t | 6 |
2 files changed, 27 insertions, 4 deletions
diff --git a/lib/tests/test_ini.c b/lib/tests/test_ini.c index 302a2e5..b02d145 100644 --- a/lib/tests/test_ini.c +++ b/lib/tests/test_ini.c | |||
@@ -19,6 +19,7 @@ | |||
19 | 19 | ||
20 | #include "common.h" | 20 | #include "common.h" |
21 | #include "parse_ini.h" | 21 | #include "parse_ini.h" |
22 | #include "utils_base.h" | ||
22 | 23 | ||
23 | #include "tap.h" | 24 | #include "tap.h" |
24 | 25 | ||
@@ -29,6 +30,22 @@ void my_free(char *string) { | |||
29 | } | 30 | } |
30 | } | 31 | } |
31 | 32 | ||
33 | char* | ||
34 | list2str(np_arg_list *optlst) | ||
35 | { | ||
36 | char *optstr=NULL; | ||
37 | |||
38 | /* Put everything as a space-separated string */ | ||
39 | while (optlst) { | ||
40 | asprintf(&optstr, "%s%s ", optstr?optstr:"", optlst->arg); | ||
41 | optlst=optlst->next; | ||
42 | } | ||
43 | /* Strip last whitespace */ | ||
44 | optstr[strlen(optstr)-1]='\0'; | ||
45 | |||
46 | return optstr; | ||
47 | } | ||
48 | |||
32 | int | 49 | int |
33 | main (int argc, char **argv) | 50 | main (int argc, char **argv) |
34 | { | 51 | { |
@@ -36,11 +53,11 @@ main (int argc, char **argv) | |||
36 | 53 | ||
37 | plan_tests(4); | 54 | plan_tests(4); |
38 | 55 | ||
39 | optstr=np_get_defaults("section@./config-tiny.ini", "check_disk"); | 56 | optstr=list2str(np_get_defaults("section@./config-tiny.ini", "check_disk")); |
40 | ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank="), "config-tiny.ini's section as expected"); | 57 | ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank="), "config-tiny.ini's section as expected"); |
41 | my_free(optstr); | 58 | my_free(optstr); |
42 | 59 | ||
43 | optstr=np_get_defaults("@./config-tiny.ini", "section"); | 60 | optstr=list2str(np_get_defaults("@./config-tiny.ini", "section")); |
44 | ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank="), "Used default section name, without specific"); | 61 | ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank="), "Used default section name, without specific"); |
45 | my_free(optstr); | 62 | my_free(optstr); |
46 | 63 | ||
@@ -51,7 +68,7 @@ main (int argc, char **argv) | |||
51 | my_free(optstr); | 68 | my_free(optstr); |
52 | */ | 69 | */ |
53 | 70 | ||
54 | optstr=np_get_defaults("Section Two@./config-tiny.ini", "check_disk"); | 71 | optstr=list2str(np_get_defaults("Section Two@./config-tiny.ini", "check_disk")); |
55 | ok( !strcmp(optstr, "--something else=blah --remove=whitespace"), "config-tiny.ini's Section Two as expected"); | 72 | ok( !strcmp(optstr, "--something else=blah --remove=whitespace"), "config-tiny.ini's Section Two as expected"); |
56 | my_free(optstr); | 73 | my_free(optstr); |
57 | 74 | ||
@@ -70,7 +87,7 @@ main (int argc, char **argv) | |||
70 | my_free(optstr); | 87 | my_free(optstr); |
71 | */ | 88 | */ |
72 | 89 | ||
73 | optstr=np_get_defaults("check_mysql@./plugin.ini", "check_disk"); | 90 | optstr=list2str(np_get_defaults("check_mysql@./plugin.ini", "check_disk")); |
74 | ok( !strcmp(optstr, "--username=operator --password=secret"), "plugin.ini's check_mysql as expected"); | 91 | ok( !strcmp(optstr, "--username=operator --password=secret"), "plugin.ini's check_mysql as expected"); |
75 | my_free(optstr); | 92 | my_free(optstr); |
76 | 93 | ||
diff --git a/lib/tests/test_ini.t b/lib/tests/test_ini.t new file mode 100755 index 0000000..b130a01 --- /dev/null +++ b/lib/tests/test_ini.t | |||
@@ -0,0 +1,6 @@ | |||
1 | #!/usr/bin/perl | ||
2 | use Test::More; | ||
3 | if (! -e "./test_ini") { | ||
4 | plan skip_all => "./test_ini not compiled - please install tap library to test"; | ||
5 | } | ||
6 | exec "./test_ini"; | ||