From 6004d95868fcd9badbc0f026980a4a3597eb22db Mon Sep 17 00:00:00 2001 From: Thomas Guyot-Sionnest Date: Sat, 15 Mar 2008 04:51:45 +0000 Subject: 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 --- lib/tests/test_ini.c | 25 +++++++++++++++++++++---- lib/tests/test_ini.t | 6 ++++++ 2 files changed, 27 insertions(+), 4 deletions(-) create mode 100755 lib/tests/test_ini.t (limited to 'lib/tests') 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); diff --git a/lib/tests/test_ini.t b/lib/tests/test_ini.t new file mode 100755 index 00000000..b130a01b --- /dev/null +++ b/lib/tests/test_ini.t @@ -0,0 +1,6 @@ +#!/usr/bin/perl +use Test::More; +if (! -e "./test_ini") { + plan skip_all => "./test_ini not compiled - please install tap library to test"; +} +exec "./test_ini"; -- cgit v1.2.3-74-g34f1