aboutsummaryrefslogtreecommitdiff
path: root/lib/tests
diff options
context:
space:
mode:
authorGravatar Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> 2008-03-16 18:10:47 +0000
committerGravatar Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> 2008-03-16 18:10:47 +0000
commit4a7ff5e95203af8379c8ffe3fdf133714ecbadef (patch)
treed6d7609aaac3031e23289800f60933e79ec583a5 /lib/tests
parent92b969e2391936cbb66a8f547a77f94f05430419 (diff)
downloadmonitoring-plugins-4a7ff5e95203af8379c8ffe3fdf133714ecbadef.tar.gz
Add tests:
- DOS-newline ini file - section defined twice git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1951 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'lib/tests')
-rw-r--r--lib/tests/config-dos.ini24
-rw-r--r--lib/tests/plugin.ini6
-rw-r--r--lib/tests/test_ini.c13
3 files changed, 42 insertions, 1 deletions
diff --git a/lib/tests/config-dos.ini b/lib/tests/config-dos.ini
new file mode 100644
index 00000000..0cea3f3a
--- /dev/null
+++ b/lib/tests/config-dos.ini
@@ -0,0 +1,24 @@
+# This config file is amended from perl's Config::Tiny's testcases
+
+# Line below is allowed in perl's Config::Tiny, but not in our parse_ini.c
+#root=something
+
+[section]
+one=two
+Foo=Bar
+this=Your Mother!
+blank=
+
+[Section Two]
+something else=blah
+ remove = whitespace
+
+[ /path/to/file.txt ]
+this=that
+
+[ section2]
+this=that
+
+[section3 ]
+this=that
+
diff --git a/lib/tests/plugin.ini b/lib/tests/plugin.ini
index d07fc4f3..e22f8bdb 100644
--- a/lib/tests/plugin.ini
+++ b/lib/tests/plugin.ini
@@ -3,10 +3,16 @@
username=operator
password=secret # Remember to change later
+[section_twice]
+foo=bar
+
[check_mysql2]
u=admin
p=secret
+[section_twice]
+bar=foo
+
[check space_and_flags]
foo=bar
a=
diff --git a/lib/tests/test_ini.c b/lib/tests/test_ini.c
index 9031f7f8..84749279 100644
--- a/lib/tests/test_ini.c
+++ b/lib/tests/test_ini.c
@@ -34,12 +34,15 @@ char*
list2str(np_arg_list *optlst)
{
char *optstr=NULL;
+ np_arg_list *optltmp;
/* Put everything as a space-separated string */
asprintf(&optstr, "");
while (optlst) {
asprintf(&optstr, "%s%s ", optstr, optlst->arg);
+ optltmp=optlst;
optlst=optlst->next;
+ free(optltmp);
}
/* Strip last whitespace */
if (strlen(optstr)>1) optstr[strlen(optstr)-1]='\0';
@@ -52,7 +55,7 @@ main (int argc, char **argv)
{
char *optstr=NULL;
- plan_tests(10);
+ plan_tests(12);
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");
@@ -94,6 +97,14 @@ main (int argc, char **argv)
ok( !strcmp(optstr, "--foo=bar -a -b --bar"), "plugin.ini space in stanza and flag arguments");
my_free(optstr);
+ optstr=list2str(np_get_defaults("Section Two@./config-dos.ini", "check_disk"));
+ ok( !strcmp(optstr, "--something else=blah --remove=whitespace"), "config-dos.ini's Section Two as expected");
+ my_free(optstr);
+
+ optstr=list2str(np_get_defaults("section_twice@./plugin.ini", "check_disk"));
+ ok( !strcmp(optstr, "--foo=bar --bar=foo"), "plugin.ini's section_twice defined twice in the file");
+ my_free(optstr);
+
return exit_status();
}