aboutsummaryrefslogtreecommitdiff
path: root/lib/tests
diff options
context:
space:
mode:
authorGravatar Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> 2008-03-15 04:51:45 +0000
committerGravatar Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> 2008-03-15 04:51:45 +0000
commit6004d95868fcd9badbc0f026980a4a3597eb22db (patch)
treebe1a47aeb9e08632f74bc7bd155504b0221367e2 /lib/tests
parent118e57b78972c4fbbcd4f45d84af546d7346141d (diff)
downloadmonitoring-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')
-rw-r--r--lib/tests/test_ini.c25
-rwxr-xr-xlib/tests/test_ini.t6
2 files changed, 27 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);
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";