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 @@ #include "common.h" #include "parse_ini.h" +#include "utils_base.h" #include "tap.h" @@ -29,6 +30,22 @@ void my_free(char *string) { } } +char* +list2str(np_arg_list *optlst) +{ + char *optstr=NULL; + + /* Put everything as a space-separated string */ + while (optlst) { + asprintf(&optstr, "%s%s ", optstr?optstr:"", optlst->arg); + optlst=optlst->next; + } + /* Strip last whitespace */ + optstr[strlen(optstr)-1]='\0'; + + return optstr; +} + int main (int argc, char **argv) { @@ -36,11 +53,11 @@ main (int argc, char **argv) plan_tests(4); - optstr=np_get_defaults("section@./config-tiny.ini", "check_disk"); + optstr=list2str(np_get_defaults("section@./config-tiny.ini", "check_disk")); ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank="), "config-tiny.ini's section as expected"); my_free(optstr); - optstr=np_get_defaults("@./config-tiny.ini", "section"); + optstr=list2str(np_get_defaults("@./config-tiny.ini", "section")); ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank="), "Used default section name, without specific"); my_free(optstr); @@ -51,7 +68,7 @@ main (int argc, char **argv) my_free(optstr); */ - optstr=np_get_defaults("Section Two@./config-tiny.ini", "check_disk"); + optstr=list2str(np_get_defaults("Section Two@./config-tiny.ini", "check_disk")); ok( !strcmp(optstr, "--something else=blah --remove=whitespace"), "config-tiny.ini's Section Two as expected"); my_free(optstr); @@ -70,7 +87,7 @@ main (int argc, char **argv) my_free(optstr); */ - optstr=np_get_defaults("check_mysql@./plugin.ini", "check_disk"); + optstr=list2str(np_get_defaults("check_mysql@./plugin.ini", "check_disk")); ok( !strcmp(optstr, "--username=operator --password=secret"), "plugin.ini's check_mysql as expected"); my_free(optstr); |