aboutsummaryrefslogtreecommitdiff
path: root/lib/tests
diff options
context:
space:
mode:
authorGravatar Thomas Guyot-Sionnest <dermoth@aei.ca> 2009-01-23 02:39:45 -0500
committerGravatar Thomas Guyot-Sionnest <dermoth@aei.ca> 2009-01-23 02:43:59 -0500
commit8b103c0c778aa22dbe7688e7d11df20b7c80be70 (patch)
treede74e84102e6f693560b301971bb2b6ee1d05a98 /lib/tests
parent485f306868fa9c89b4f09e3b2b813d93ec64f0b4 (diff)
downloadmonitoring-plugins-8b103c0c778aa22dbe7688e7d11df20b7c80be70.tar.gz
Add die tests for parse_ini
Diffstat (limited to 'lib/tests')
-rw-r--r--lib/tests/Makefile.am6
-rw-r--r--lib/tests/test_ini1.c (renamed from lib/tests/test_ini.c)0
-rwxr-xr-xlib/tests/test_ini1.t (renamed from lib/tests/test_ini.t)0
-rw-r--r--lib/tests/test_ini3.c33
-rwxr-xr-xlib/tests/test_ini3.t34
-rwxr-xr-xlib/tests/test_opts3.t8
6 files changed, 76 insertions, 5 deletions
diff --git a/lib/tests/Makefile.am b/lib/tests/Makefile.am
index 4bab2f2a..694baf00 100644
--- a/lib/tests/Makefile.am
+++ b/lib/tests/Makefile.am
@@ -7,9 +7,9 @@ check_PROGRAMS = @EXTRA_TEST@
INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins
-EXTRA_PROGRAMS = test_utils test_disk test_tcp test_cmd test_base64 test_ini test_opts1 test_opts2 test_opts3
+EXTRA_PROGRAMS = test_utils test_disk test_tcp test_cmd test_base64 test_ini1 test_ini3 test_opts1 test_opts2 test_opts3
-np_test_scripts = test_base64.t test_cmd.t test_disk.t test_ini.t test_opts1.t test_opts2.t test_opts3.t test_tcp.t test_utils.t
+np_test_scripts = test_base64.t test_cmd.t test_disk.t test_ini1.t test_ini3.t test_opts1.t test_opts2.t test_opts3.t test_tcp.t test_utils.t
np_test_files = config-dos.ini config-opts.ini config-tiny.ini plugin.ini plugins.ini
EXTRA_DIST = $(np_test_scripts) $(np_test_files)
@@ -28,7 +28,7 @@ AM_CFLAGS = -g -I$(top_srcdir)/lib -I$(top_srcdir)/gl $(tap_cflags)
AM_LDFLAGS = $(tap_ldflags) -ltap
LDADD = $(top_srcdir)/lib/libnagiosplug.a $(top_srcdir)/gl/libgnu.a
-SOURCES = test_utils.c test_disk.c test_tcp.c test_cmd.c test_base64.c test_ini.c test_opts1.c test_opts2.c test_opts3.c
+SOURCES = test_utils.c test_disk.c test_tcp.c test_cmd.c test_base64.c test_ini1.c test_ini3.c test_opts1.c test_opts2.c test_opts3.c
test: ${noinst_PROGRAMS}
perl -MTest::Harness -e '$$Test::Harness::switches=""; runtests(map {$$_ .= ".t"} @ARGV)' $(EXTRA_PROGRAMS)
diff --git a/lib/tests/test_ini.c b/lib/tests/test_ini1.c
index c0853d7c..c0853d7c 100644
--- a/lib/tests/test_ini.c
+++ b/lib/tests/test_ini1.c
diff --git a/lib/tests/test_ini.t b/lib/tests/test_ini1.t
index 0487098c..0487098c 100755
--- a/lib/tests/test_ini.t
+++ b/lib/tests/test_ini1.t
diff --git a/lib/tests/test_ini3.c b/lib/tests/test_ini3.c
new file mode 100644
index 00000000..814b3ec0
--- /dev/null
+++ b/lib/tests/test_ini3.c
@@ -0,0 +1,33 @@
+/*****************************************************************************
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+*
+*****************************************************************************/
+
+#include "parse_ini.h"
+
+int
+main (int argc, char **argv)
+{
+
+ /*
+ * This is for testing arguments expected to die.
+ */
+
+ np_get_defaults(argv[1], argv[0]);
+
+ return 0;
+}
+
diff --git a/lib/tests/test_ini3.t b/lib/tests/test_ini3.t
new file mode 100755
index 00000000..57388dda
--- /dev/null
+++ b/lib/tests/test_ini3.t
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+use Test::More;
+use strict;
+use warnings;
+
+if (! -e "./test_ini") {
+ plan skip_all => "./test_ini not compiled - please install tap library and/or enable parse-ini to test";
+}
+
+# array of argument arrays
+# - First value is the expected return code
+# - 2nd value is the NAGIOS_CONFIG_PATH
+# TODO: looks like we look in default path after looking trough this variable - shall we?
+# - 3rd value is the plugin name
+# - 4th is the ini locator
+my @TESTS = (
+ [3, undef, "section", "section_unknown@./config-tiny.ini"],
+);
+
+plan tests => scalar(@TESTS);
+
+my $count=1;
+
+foreach my $args (@TESTS) {
+ my $rc = shift(@$args);
+ if (my $env = shift(@$args)) {
+ $ENV{"NAGIOS_CONFIG_PATH"} = $env;
+ } else {
+ delete($ENV{"NAGIOS_CONFIG_PATH"});
+ }
+ system {'./test_ini2'} @$args;
+ cmp_ok($?>>8, '==', $rc, "Parse-ini die " . $count++);
+}
+
diff --git a/lib/tests/test_opts3.t b/lib/tests/test_opts3.t
index 35b44687..fa7876d0 100755
--- a/lib/tests/test_opts3.t
+++ b/lib/tests/test_opts3.t
@@ -28,8 +28,12 @@ plan tests => scalar(@TESTS);
my $count=1;
foreach my $args (@TESTS) {
- my $rc = shift(@$args);
- $ENV{"NAGIOS_CONFIG_PATH"} = shift(@$args);
+ my $rc = shift(@$args);
+ if (my $env = shift(@$args)) {
+ $ENV{"NAGIOS_CONFIG_PATH"} = $env;
+ } else {
+ delete($ENV{"NAGIOS_CONFIG_PATH"});
+ }
system {'./test_opts3'} @$args;
cmp_ok($?>>8, '==', $rc, "Extra-opts die " . $count++);
}