From 3b69f134671e60eb5de0ca895177064294b6eb78 Mon Sep 17 00:00:00 2001
From: Thomas Guyot-Sionnest <dermoth@aei.ca>
Date: Tue, 20 Jan 2009 23:55:34 -0500
Subject: Some platform are missing setenv

Instead of adding the gnulib module for solving tests only I split the test
in two, setting environment from Perl for the later.

diff --git a/configure.in b/configure.in
index eb27d6a..107cfd9 100644
--- a/configure.in
+++ b/configure.in
@@ -188,7 +188,7 @@ AM_CONDITIONAL([USE_PARSE_INI],[test "$enable_extra_opts" = "yes"])
 if test "$enable_extra_opts" = "yes" ; then
 	AC_DEFINE(NP_EXTRA_OPTS,[1],[Enable INI file parsing.])
 	if test "$enable_libtap" = "yes"; then
-		EXTRA_TEST="$EXTRA_TEST test_ini test_opts"
+		EXTRA_TEST="$EXTRA_TEST test_ini test_opts1 test_opts2"
 		AC_SUBST(EXTRA_TEST)
 	fi
 fi
diff --git a/lib/tests/Makefile.am b/lib/tests/Makefile.am
index a59a653..f36c0be 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_opts
+EXTRA_PROGRAMS = test_utils test_disk test_tcp test_cmd test_base64 test_ini test_opts1 test_opts2
 
-np_test_scripts = test_base64.t test_cmd.t test_disk.t test_ini.t test_opts.t test_tcp.t test_utils.t
+np_test_scripts = test_base64.t test_cmd.t test_disk.t test_ini.t test_opts1.t test_opts2.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_opts.c
+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: ${noinst_PROGRAMS}
 	perl -MTest::Harness -e '$$Test::Harness::switches=""; runtests(map {$$_ .= ".t"} @ARGV)' $(EXTRA_PROGRAMS)
diff --git a/lib/tests/test_opts.c b/lib/tests/test_opts.c
deleted file mode 100644
index ad9a854..0000000
--- a/lib/tests/test_opts.c
+++ /dev/null
@@ -1,294 +0,0 @@
-/*****************************************************************************
-* 
-* 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 "common.h"
-#include "utils_base.h"
-#include "extra_opts.h"
-
-#include "tap.h"
-
-void my_free(int *argc, char **argv) {
-	int i;
-	printf ("    Arg(%i): ", *argc);
-	for (i=1; i<*argc; i++) printf ("'%s' ", argv[i]);
-	printf ("\n");
-	free(argv);
-	*argc=0;
-}
-
-int array_diff(int i1, char **a1, int i2, char **a2) {
-	int i;
-
-	if (i1 != i2) {
-		printf("    Argument count doesn't match!\n");
-		return 0;
-	}
-	for (i=0; i<=i1; i++) {
-		if (a1[i]==NULL && a2[i]==NULL) continue;
-		if (a1[i]==NULL || a2[i]==NULL) {
-			printf("    Argument # %i null in one array!\n", i);
-			return 0;
-		}
-		if (strcmp(a1[i], a2[i])) {
-			printf("    Argument # %i doesn't match!\n", i);
-			return 0;
-		}
-	}
-	return 1;
-}
-
-int
-main (int argc, char **argv)
-{
-	char **argv_test=NULL, **argv_known=NULL;
-	int i, argc_test;
-
-	plan_tests(10);
-
-	argv_test=(char **)malloc(2*sizeof(char **));
-	argv_test[0] = "prog_name";
-	argv_test[1] = NULL;
-	argc_test=1;
-	argv_known=(char **)realloc(argv_known, 2*sizeof(char **));
-	argv_known[0] = "prog_name";
-	argv_known[1] = NULL;
-	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
-	ok(array_diff(argc_test, argv_test, 1, argv_known), "No opts, returns correct argv/argc");
-	my_free(&argc_test, argv_test);
-
-	argv_test=(char **)malloc(6*sizeof(char **));
-	argv_test[0] = "prog_name";
-	argv_test[1] = "arg1";
-	argv_test[2] = "--arg2=val1";
-	argv_test[3] = "--arg3";
-	argv_test[4] = "val2";
-	argv_test[5] = NULL;
-	argc_test=5;
-	argv_known=(char **)realloc(argv_known, 6*sizeof(char **));
-	argv_known[0] = "prog_name";
-	argv_known[1] = "arg1";
-	argv_known[2] = "--arg2=val1";
-	argv_known[3] = "--arg3";
-	argv_known[4] = "val2";
-	argv_known[5] = NULL;
-	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
-	ok(array_diff(argc_test, argv_test, 5, argv_known), "No extra opts, verbatim copy of argv");
-	my_free(&argc_test,argv_test);
-
-	argv_test=(char **)malloc(3*sizeof(char **));
-	argv_test[0] = "prog_name";
-	argv_test[1] = "--extra-opts=@./config-opts.ini";
-	argv_test[2] = NULL;
-	argc_test=2;
-	argv_known=(char **)realloc(argv_known, 5*sizeof(char **));
-	argv_known[0] = "prog_name";
-	argv_known[1] = "--foo=Bar";
-	argv_known[2] = "--this=Your Mother!";
-	argv_known[3] = "--blank";
-	argv_known[4] = NULL;
-	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
-	ok(array_diff(argc_test, argv_test, 4, argv_known), "Only extra opts using default section");
-	my_free(&argc_test,argv_test);
-
-	argv_test=(char **)malloc(5*sizeof(char **));
-	argv_test[0] = "prog_name";
-	argv_test[1] = "--extra-opts=sect1@./config-opts.ini";
-	argv_test[2] = "--extra-opts";
-	argv_test[3] = "sect2@./config-opts.ini";
-	argv_test[4] = NULL;
-	argc_test=4;
-	argv_known=(char **)realloc(argv_known, 5*sizeof(char **));
-	argv_known[0] = "prog_name";
-	argv_known[1] = "--one=two";
-	argv_known[2] = "--something else=oops";
-	argv_known[3] = "--this=that";
-	argv_known[4] = NULL;
-	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
-	ok(array_diff(argc_test, argv_test, 4, argv_known), "Only extra opts specified twice");
-	my_free(&argc_test,argv_test);
-
-	argv_test=(char **)malloc(7*sizeof(char **));
-	argv_test[0] = "prog_name";
-	argv_test[1] = "--arg1=val1";
-	argv_test[2] = "--extra-opts=@./config-opts.ini";
-	argv_test[3] = "--extra-opts";
-	argv_test[4] = "sect1@./config-opts.ini";
-	argv_test[5] = "--arg2";
-	argv_test[6] = NULL;
-	argc_test=6;
-	argv_known=(char **)realloc(argv_known, 8*sizeof(char **));
-	argv_known[0] = "prog_name";
-	argv_known[1] = "--foo=Bar";
-	argv_known[2] = "--this=Your Mother!";
-	argv_known[3] = "--blank";
-	argv_known[4] = "--one=two";
-	argv_known[5] = "--arg1=val1";
-	argv_known[6] = "--arg2";
-	argv_known[7] = NULL;
-	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
-	ok(array_diff(argc_test, argv_test, 7, argv_known), "twice extra opts using two sections");
-	my_free(&argc_test,argv_test);
-
-	/* Next three checks are expected to die. They are commented out as they
-	 * could possibly go in a sepatare test checked for return value.
-	 */
-	/* argv_test=(char **)malloc(6*sizeof(char **));
-	argv_test[0] = "prog_name";
-	argv_test[1] = "arg1";
-	argv_test[2] = "--extra-opts=missing@./config-opts.ini";
-	argv_test[3] = "--arg3";
-	argv_test[4] = "val2";
-	argv_test[5] = NULL;
-	argc_test=5;
-	argv_known=(char **)realloc(argv_known, 5*sizeof(char **));
-	argv_known[0] = "prog_name";
-	argv_known[1] = "arg1";
-	argv_known[2] = "--arg3";
-	argv_known[3] = "val2";
-	argv_known[4] = NULL;
-	argv_test=np_extra_opts(&argc_test, argv_test, "check_missing");
-	ok(array_diff(argc_test, argv_test, 4, argv_known), "Missing section 1");
-	my_free(&argc_test,argv_test); */
-
-	/* argv_test=(char **)malloc(7*sizeof(char **));
-	argv_test[0] = "prog_name";
-	argv_test[1] = "arg1";
-	argv_test[2] = "--extra-opts";
-	argv_test[3] = "missing@./config-opts.ini";
-	argv_test[4] = "--arg3";
-	argv_test[5] = "val2";
-	argv_test[6] = NULL;
-	argc_test=6;
-	argv_known=(char **)realloc(argv_known, 5*sizeof(char **));
-	argv_known[0] = "prog_name";
-	argv_known[1] = "arg1";
-	argv_known[2] = "--arg3";
-	argv_known[3] = "val2";
-	argv_known[4] = NULL;
-	argv_test=np_extra_opts(&argc_test, argv_test, "check_missing");
-	ok(array_diff(argc_test, argv_test, 4, argv_known), "Missing section 2");
-	my_free(&argc_test,argv_test); */
-
-	/* argv_test=(char **)malloc(6*sizeof(char **));
-	argv_test[0] = "prog_name";
-	argv_test[1] = "arg1";
-	argv_test[2] = "--extra-opts";
-	argv_test[3] = "--arg3";
-	argv_test[4] = "val2";
-	argv_test[5] = NULL;
-	argc_test=5;
-	argv_known=(char **)realloc(argv_known, 5*sizeof(char **));
-	argv_known[0] = "prog_name";
-	argv_known[1] = "arg1";
-	argv_known[2] = "--arg3";
-	argv_known[3] = "val2";
-	argv_known[4] = NULL;
-	argv_test=np_extra_opts(&argc_test, argv_test, "check_missing");
-	ok(array_diff(argc_test, argv_test, 4, argv_known), "Missing section 3");
-	my_free(&argc_test,argv_test); */
-
-	setenv("NAGIOS_CONFIG_PATH", ".", 1);
-	argv_test=(char **)malloc(6*sizeof(char **));
-	argv_test[0] = "prog_name";
-	argv_test[1] = "arg1";
-	argv_test[2] = "--extra-opts";
-	argv_test[3] = "--arg3";
-	argv_test[4] = "val2";
-	argv_test[5] = NULL;
-	argc_test=5;
-	argv_known=(char **)realloc(argv_known, 6*sizeof(char **));
-	argv_known[0] = "prog_name";
-	argv_known[1] = "--foo=bar";
-	argv_known[2] = "arg1";
-	argv_known[3] = "--arg3";
-	argv_known[4] = "val2";
-	argv_known[5] = NULL;
-	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
-	ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 1");
-
-	argv_test=(char **)malloc(3*sizeof(char **));
-	argv_test[0] = "prog_name";
-	argv_test[1] = "--extra-opts";
-	argv_test[2] = NULL;
-	argc_test=2;
-	argv_known=(char **)realloc(argv_known, 3*sizeof(char **));
-	argv_known[0] = "prog_name";
-	argv_known[1] = "--foo=bar";
-	argv_known[2] = NULL;
-	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
-	ok(array_diff(argc_test, argv_test, 2, argv_known), "Default section 2");
-	my_free(&argc_test,argv_test);
-
-	argv_test=(char **)malloc(6*sizeof(char **));
-	argv_test[0] = "prog_name";
-	argv_test[1] = "arg1";
-	argv_test[2] = "--extra-opts=section1";
-	argv_test[3] = "--arg3";
-	argv_test[4] = "val2";
-	argv_test[5] = NULL;
-	argc_test=5;
-	argv_known=(char **)realloc(argv_known, 6*sizeof(char **));
-	argv_known[0] = "prog_name";
-	argv_known[1] = "--foobar=baz";
-	argv_known[2] = "arg1";
-	argv_known[3] = "--arg3";
-	argv_known[4] = "val2";
-	argv_known[5] = NULL;
-	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
-	ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 3");
-	my_free(&argc_test,argv_test);
-
-	argv_test=(char **)malloc(6*sizeof(char **));
-	argv_test[0] = "prog_name";
-	argv_test[1] = "arg1";
-	argv_test[2] = "--extra-opts";
-	argv_test[3] = "-arg3";
-	argv_test[4] = "val2";
-	argv_test[5] = NULL;
-	argc_test=5;
-	argv_known=(char **)realloc(argv_known, 6*sizeof(char **));
-	argv_known[0] = "prog_name";
-	argv_known[1] = "--foo=bar";
-	argv_known[2] = "arg1";
-	argv_known[3] = "-arg3";
-	argv_known[4] = "val2";
-	argv_known[5] = NULL;
-	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
-	ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 4");
-	my_free(&argc_test,argv_test);
-
-	argv_test=(char **)malloc(4*sizeof(char **));
-	argv_test[0] = "check_tcp";
-	argv_test[1] = "--extra-opts";
-	argv_test[2] = "--extra-opts=tcp_long_lines";
-	argv_test[3] = NULL;
-	argc_test=3;
-	argv_known=(char **)realloc(argv_known, 7*sizeof(char **));
-	argv_known[0] = "check_tcp";
-	argv_known[1] = "--timeout=10";
-	argv_known[2] = "--escape";
-	argv_known[3] = "--send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda";
-	argv_known[4] = "--expect=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda";
-	argv_known[5] = "--jail";
-	argv_known[6] = NULL;
-	argv_test=np_extra_opts(&argc_test, argv_test, "check_tcp");
-	ok(array_diff(argc_test, argv_test, 6, argv_known), "Long lines test");
-	my_free(&argc_test,argv_test);
-
-	return exit_status();
-}
-
diff --git a/lib/tests/test_opts.t b/lib/tests/test_opts.t
deleted file mode 100755
index d69b8f1..0000000
--- a/lib/tests/test_opts.t
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/usr/bin/perl
-use Test::More;
-if (! -e "./test_opts") {
-	plan skip_all => "./test_opts not compiled - please install tap library and/or enable parse-ini to test";
-}
-exec "./test_opts";
diff --git a/lib/tests/test_opts1 b/lib/tests/test_opts1
new file mode 100755
index 0000000..cab0f2a
Binary files /dev/null and b/lib/tests/test_opts1 differ
diff --git a/lib/tests/test_opts1.c b/lib/tests/test_opts1.c
new file mode 100644
index 0000000..ea98403
--- /dev/null
+++ b/lib/tests/test_opts1.c
@@ -0,0 +1,206 @@
+/*****************************************************************************
+* 
+* 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 "common.h"
+#include "utils_base.h"
+#include "extra_opts.h"
+
+#include "tap.h"
+
+void my_free(int *argc, char **argv) {
+	int i;
+	printf ("    Arg(%i): ", *argc);
+	for (i=1; i<*argc; i++) printf ("'%s' ", argv[i]);
+	printf ("\n");
+	free(argv);
+	*argc=0;
+}
+
+int array_diff(int i1, char **a1, int i2, char **a2) {
+	int i;
+
+	if (i1 != i2) {
+		printf("    Argument count doesn't match!\n");
+		return 0;
+	}
+	for (i=0; i<=i1; i++) {
+		if (a1[i]==NULL && a2[i]==NULL) continue;
+		if (a1[i]==NULL || a2[i]==NULL) {
+			printf("    Argument # %i null in one array!\n", i);
+			return 0;
+		}
+		if (strcmp(a1[i], a2[i])) {
+			printf("    Argument # %i doesn't match!\n", i);
+			return 0;
+		}
+	}
+	return 1;
+}
+
+int
+main (int argc, char **argv)
+{
+	char **argv_test=NULL, **argv_known=NULL;
+	int i, argc_test;
+
+	plan_tests(5);
+
+	argv_test=(char **)malloc(2*sizeof(char **));
+	argv_test[0] = "prog_name";
+	argv_test[1] = NULL;
+	argc_test=1;
+	argv_known=(char **)realloc(argv_known, 2*sizeof(char **));
+	argv_known[0] = "prog_name";
+	argv_known[1] = NULL;
+	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
+	ok(array_diff(argc_test, argv_test, 1, argv_known), "No opts, returns correct argv/argc");
+	my_free(&argc_test, argv_test);
+
+	argv_test=(char **)malloc(6*sizeof(char **));
+	argv_test[0] = "prog_name";
+	argv_test[1] = "arg1";
+	argv_test[2] = "--arg2=val1";
+	argv_test[3] = "--arg3";
+	argv_test[4] = "val2";
+	argv_test[5] = NULL;
+	argc_test=5;
+	argv_known=(char **)realloc(argv_known, 6*sizeof(char **));
+	argv_known[0] = "prog_name";
+	argv_known[1] = "arg1";
+	argv_known[2] = "--arg2=val1";
+	argv_known[3] = "--arg3";
+	argv_known[4] = "val2";
+	argv_known[5] = NULL;
+	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
+	ok(array_diff(argc_test, argv_test, 5, argv_known), "No extra opts, verbatim copy of argv");
+	my_free(&argc_test,argv_test);
+
+	argv_test=(char **)malloc(3*sizeof(char **));
+	argv_test[0] = "prog_name";
+	argv_test[1] = "--extra-opts=@./config-opts.ini";
+	argv_test[2] = NULL;
+	argc_test=2;
+	argv_known=(char **)realloc(argv_known, 5*sizeof(char **));
+	argv_known[0] = "prog_name";
+	argv_known[1] = "--foo=Bar";
+	argv_known[2] = "--this=Your Mother!";
+	argv_known[3] = "--blank";
+	argv_known[4] = NULL;
+	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
+	ok(array_diff(argc_test, argv_test, 4, argv_known), "Only extra opts using default section");
+	my_free(&argc_test,argv_test);
+
+	argv_test=(char **)malloc(5*sizeof(char **));
+	argv_test[0] = "prog_name";
+	argv_test[1] = "--extra-opts=sect1@./config-opts.ini";
+	argv_test[2] = "--extra-opts";
+	argv_test[3] = "sect2@./config-opts.ini";
+	argv_test[4] = NULL;
+	argc_test=4;
+	argv_known=(char **)realloc(argv_known, 5*sizeof(char **));
+	argv_known[0] = "prog_name";
+	argv_known[1] = "--one=two";
+	argv_known[2] = "--something else=oops";
+	argv_known[3] = "--this=that";
+	argv_known[4] = NULL;
+	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
+	ok(array_diff(argc_test, argv_test, 4, argv_known), "Only extra opts specified twice");
+	my_free(&argc_test,argv_test);
+
+	argv_test=(char **)malloc(7*sizeof(char **));
+	argv_test[0] = "prog_name";
+	argv_test[1] = "--arg1=val1";
+	argv_test[2] = "--extra-opts=@./config-opts.ini";
+	argv_test[3] = "--extra-opts";
+	argv_test[4] = "sect1@./config-opts.ini";
+	argv_test[5] = "--arg2";
+	argv_test[6] = NULL;
+	argc_test=6;
+	argv_known=(char **)realloc(argv_known, 8*sizeof(char **));
+	argv_known[0] = "prog_name";
+	argv_known[1] = "--foo=Bar";
+	argv_known[2] = "--this=Your Mother!";
+	argv_known[3] = "--blank";
+	argv_known[4] = "--one=two";
+	argv_known[5] = "--arg1=val1";
+	argv_known[6] = "--arg2";
+	argv_known[7] = NULL;
+	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
+	ok(array_diff(argc_test, argv_test, 7, argv_known), "twice extra opts using two sections");
+	my_free(&argc_test,argv_test);
+
+	/* Next three checks are expected to die. They are commented out as they
+	 * could possibly go in a sepatare test checked for return value.
+	 */
+	/* argv_test=(char **)malloc(6*sizeof(char **));
+	argv_test[0] = "prog_name";
+	argv_test[1] = "arg1";
+	argv_test[2] = "--extra-opts=missing@./config-opts.ini";
+	argv_test[3] = "--arg3";
+	argv_test[4] = "val2";
+	argv_test[5] = NULL;
+	argc_test=5;
+	argv_known=(char **)realloc(argv_known, 5*sizeof(char **));
+	argv_known[0] = "prog_name";
+	argv_known[1] = "arg1";
+	argv_known[2] = "--arg3";
+	argv_known[3] = "val2";
+	argv_known[4] = NULL;
+	argv_test=np_extra_opts(&argc_test, argv_test, "check_missing");
+	ok(array_diff(argc_test, argv_test, 4, argv_known), "Missing section 1");
+	my_free(&argc_test,argv_test); */
+
+	/* argv_test=(char **)malloc(7*sizeof(char **));
+	argv_test[0] = "prog_name";
+	argv_test[1] = "arg1";
+	argv_test[2] = "--extra-opts";
+	argv_test[3] = "missing@./config-opts.ini";
+	argv_test[4] = "--arg3";
+	argv_test[5] = "val2";
+	argv_test[6] = NULL;
+	argc_test=6;
+	argv_known=(char **)realloc(argv_known, 5*sizeof(char **));
+	argv_known[0] = "prog_name";
+	argv_known[1] = "arg1";
+	argv_known[2] = "--arg3";
+	argv_known[3] = "val2";
+	argv_known[4] = NULL;
+	argv_test=np_extra_opts(&argc_test, argv_test, "check_missing");
+	ok(array_diff(argc_test, argv_test, 4, argv_known), "Missing section 2");
+	my_free(&argc_test,argv_test); */
+
+	/* argv_test=(char **)malloc(6*sizeof(char **));
+	argv_test[0] = "prog_name";
+	argv_test[1] = "arg1";
+	argv_test[2] = "--extra-opts";
+	argv_test[3] = "--arg3";
+	argv_test[4] = "val2";
+	argv_test[5] = NULL;
+	argc_test=5;
+	argv_known=(char **)realloc(argv_known, 5*sizeof(char **));
+	argv_known[0] = "prog_name";
+	argv_known[1] = "arg1";
+	argv_known[2] = "--arg3";
+	argv_known[3] = "val2";
+	argv_known[4] = NULL;
+	argv_test=np_extra_opts(&argc_test, argv_test, "check_missing");
+	ok(array_diff(argc_test, argv_test, 4, argv_known), "Missing section 3");
+	my_free(&argc_test,argv_test); */
+
+	return exit_status();
+}
+
diff --git a/lib/tests/test_opts1.t b/lib/tests/test_opts1.t
new file mode 100755
index 0000000..52eed94
--- /dev/null
+++ b/lib/tests/test_opts1.t
@@ -0,0 +1,6 @@
+#!/usr/bin/perl
+use Test::More;
+if (! -e "./test_opts1") {
+	plan skip_all => "./test_opts1 not compiled - please install tap library and/or enable parse-ini to test";
+}
+exec "./test_opts1";
diff --git a/lib/tests/test_opts2 b/lib/tests/test_opts2
new file mode 100755
index 0000000..226fe91
Binary files /dev/null and b/lib/tests/test_opts2 differ
diff --git a/lib/tests/test_opts2.c b/lib/tests/test_opts2.c
new file mode 100644
index 0000000..2646b2f
--- /dev/null
+++ b/lib/tests/test_opts2.c
@@ -0,0 +1,151 @@
+/*****************************************************************************
+* 
+* 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 "common.h"
+#include "utils_base.h"
+#include "extra_opts.h"
+
+#include "tap.h"
+
+void my_free(int *argc, char **argv) {
+	int i;
+	printf ("    Arg(%i): ", *argc);
+	for (i=1; i<*argc; i++) printf ("'%s' ", argv[i]);
+	printf ("\n");
+	free(argv);
+	*argc=0;
+}
+
+int array_diff(int i1, char **a1, int i2, char **a2) {
+	int i;
+
+	if (i1 != i2) {
+		printf("    Argument count doesn't match!\n");
+		return 0;
+	}
+	for (i=0; i<=i1; i++) {
+		if (a1[i]==NULL && a2[i]==NULL) continue;
+		if (a1[i]==NULL || a2[i]==NULL) {
+			printf("    Argument # %i null in one array!\n", i);
+			return 0;
+		}
+		if (strcmp(a1[i], a2[i])) {
+			printf("    Argument # %i doesn't match!\n", i);
+			return 0;
+		}
+	}
+	return 1;
+}
+
+int
+main (int argc, char **argv)
+{
+	char **argv_test=NULL, **argv_known=NULL;
+	int i, argc_test;
+
+	plan_tests(5);
+
+	argv_test=(char **)malloc(6*sizeof(char **));
+	argv_test[0] = "prog_name";
+	argv_test[1] = "arg1";
+	argv_test[2] = "--extra-opts";
+	argv_test[3] = "--arg3";
+	argv_test[4] = "val2";
+	argv_test[5] = NULL;
+	argc_test=5;
+	argv_known=(char **)realloc(argv_known, 6*sizeof(char **));
+	argv_known[0] = "prog_name";
+	argv_known[1] = "--foo=bar";
+	argv_known[2] = "arg1";
+	argv_known[3] = "--arg3";
+	argv_known[4] = "val2";
+	argv_known[5] = NULL;
+	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
+	ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 1");
+
+	argv_test=(char **)malloc(3*sizeof(char **));
+	argv_test[0] = "prog_name";
+	argv_test[1] = "--extra-opts";
+	argv_test[2] = NULL;
+	argc_test=2;
+	argv_known=(char **)realloc(argv_known, 3*sizeof(char **));
+	argv_known[0] = "prog_name";
+	argv_known[1] = "--foo=bar";
+	argv_known[2] = NULL;
+	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
+	ok(array_diff(argc_test, argv_test, 2, argv_known), "Default section 2");
+	my_free(&argc_test,argv_test);
+
+	argv_test=(char **)malloc(6*sizeof(char **));
+	argv_test[0] = "prog_name";
+	argv_test[1] = "arg1";
+	argv_test[2] = "--extra-opts=section1";
+	argv_test[3] = "--arg3";
+	argv_test[4] = "val2";
+	argv_test[5] = NULL;
+	argc_test=5;
+	argv_known=(char **)realloc(argv_known, 6*sizeof(char **));
+	argv_known[0] = "prog_name";
+	argv_known[1] = "--foobar=baz";
+	argv_known[2] = "arg1";
+	argv_known[3] = "--arg3";
+	argv_known[4] = "val2";
+	argv_known[5] = NULL;
+	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
+	ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 3");
+	my_free(&argc_test,argv_test);
+
+	argv_test=(char **)malloc(6*sizeof(char **));
+	argv_test[0] = "prog_name";
+	argv_test[1] = "arg1";
+	argv_test[2] = "--extra-opts";
+	argv_test[3] = "-arg3";
+	argv_test[4] = "val2";
+	argv_test[5] = NULL;
+	argc_test=5;
+	argv_known=(char **)realloc(argv_known, 6*sizeof(char **));
+	argv_known[0] = "prog_name";
+	argv_known[1] = "--foo=bar";
+	argv_known[2] = "arg1";
+	argv_known[3] = "-arg3";
+	argv_known[4] = "val2";
+	argv_known[5] = NULL;
+	argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
+	ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 4");
+	my_free(&argc_test,argv_test);
+
+	argv_test=(char **)malloc(4*sizeof(char **));
+	argv_test[0] = "check_tcp";
+	argv_test[1] = "--extra-opts";
+	argv_test[2] = "--extra-opts=tcp_long_lines";
+	argv_test[3] = NULL;
+	argc_test=3;
+	argv_known=(char **)realloc(argv_known, 7*sizeof(char **));
+	argv_known[0] = "check_tcp";
+	argv_known[1] = "--timeout=10";
+	argv_known[2] = "--escape";
+	argv_known[3] = "--send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda";
+	argv_known[4] = "--expect=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda";
+	argv_known[5] = "--jail";
+	argv_known[6] = NULL;
+	argv_test=np_extra_opts(&argc_test, argv_test, "check_tcp");
+	ok(array_diff(argc_test, argv_test, 6, argv_known), "Long lines test");
+	my_free(&argc_test,argv_test);
+
+	return exit_status();
+}
+
diff --git a/lib/tests/test_opts2.t b/lib/tests/test_opts2.t
new file mode 100755
index 0000000..f7444f6
--- /dev/null
+++ b/lib/tests/test_opts2.t
@@ -0,0 +1,7 @@
+#!/usr/bin/perl
+use Test::More;
+if (! -e "./test_opts2") {
+	plan skip_all => "./test_opts2 not compiled - please install tap library and/or enable parse-ini to test";
+}
+$ENV{"NAGIOS_CONFIG_PATH"} = ".";
+exec "./test_opts2";
-- 
cgit v0.10-9-g596f

