diff options
author | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | 2008-03-15 04:51:45 +0000 |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | 2008-03-15 04:51:45 +0000 |
commit | 6004d95868fcd9badbc0f026980a4a3597eb22db (patch) | |
tree | be1a47aeb9e08632f74bc7bd155504b0221367e2 /lib/tests/test_ini.c | |
parent | 118e57b78972c4fbbcd4f45d84af546d7346141d (diff) | |
download | monitoring-plugins-6004d95868fcd9badbc0f026980a4a3597eb22db.tar.gz |
This commit consist of two changes:
1. Make np_get_defaults return a linked list instead of a string. It will then be easy to convert the linked list back to an argument array.
2. Fix tests 3-4 of test_ini.c.
A test_ini.t was added too. parse_ini and test_ini aren't included yet in the build makefiles.
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1945 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'lib/tests/test_ini.c')
-rw-r--r-- | lib/tests/test_ini.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/lib/tests/test_ini.c b/lib/tests/test_ini.c index 302a2e56..b02d1452 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 | ||