summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@aei.ca>2009-01-20 23:55:34 -0500
committerThomas Guyot-Sionnest <dermoth@aei.ca>2009-01-20 23:58:02 -0500
commit3b69f134671e60eb5de0ca895177064294b6eb78 (patch)
treee4a006bf794efb29f539b3002f979f179a655b5e
parent26bf63a5bba0fae77033693030c75eace202f988 (diff)
downloadmonitoring-plugins-3b69f134671e60eb5de0ca895177064294b6eb78.tar.gz
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.
-rw-r--r--configure.in2
-rw-r--r--lib/tests/Makefile.am6
-rwxr-xr-xlib/tests/test_opts.t6
-rwxr-xr-xlib/tests/test_opts1bin0 -> 34139 bytes
-rw-r--r--lib/tests/test_opts1.c (renamed from lib/tests/test_opts.c)90
-rwxr-xr-xlib/tests/test_opts1.t6
-rwxr-xr-xlib/tests/test_opts2bin0 -> 35227 bytes
-rw-r--r--lib/tests/test_opts2.c151
-rwxr-xr-xlib/tests/test_opts2.t7
9 files changed, 169 insertions, 99 deletions
diff --git a/configure.in b/configure.in
index eb27d6a7..107cfd95 100644
--- a/configure.in
+++ b/configure.in
@@ -188,7 +188,7 @@ AM_CONDITIONAL([USE_PARSE_INI],[test "$enable_extra_opts" = "yes"])
188if test "$enable_extra_opts" = "yes" ; then 188if test "$enable_extra_opts" = "yes" ; then
189 AC_DEFINE(NP_EXTRA_OPTS,[1],[Enable INI file parsing.]) 189 AC_DEFINE(NP_EXTRA_OPTS,[1],[Enable INI file parsing.])
190 if test "$enable_libtap" = "yes"; then 190 if test "$enable_libtap" = "yes"; then
191 EXTRA_TEST="$EXTRA_TEST test_ini test_opts" 191 EXTRA_TEST="$EXTRA_TEST test_ini test_opts1 test_opts2"
192 AC_SUBST(EXTRA_TEST) 192 AC_SUBST(EXTRA_TEST)
193 fi 193 fi
194fi 194fi
diff --git a/lib/tests/Makefile.am b/lib/tests/Makefile.am
index a59a6536..f36c0be2 100644
--- a/lib/tests/Makefile.am
+++ b/lib/tests/Makefile.am
@@ -7,9 +7,9 @@ check_PROGRAMS = @EXTRA_TEST@
7 7
8INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins 8INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins
9 9
10EXTRA_PROGRAMS = test_utils test_disk test_tcp test_cmd test_base64 test_ini test_opts 10EXTRA_PROGRAMS = test_utils test_disk test_tcp test_cmd test_base64 test_ini test_opts1 test_opts2
11 11
12np_test_scripts = test_base64.t test_cmd.t test_disk.t test_ini.t test_opts.t test_tcp.t test_utils.t 12np_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
13np_test_files = config-dos.ini config-opts.ini config-tiny.ini plugin.ini plugins.ini 13np_test_files = config-dos.ini config-opts.ini config-tiny.ini plugin.ini plugins.ini
14EXTRA_DIST = $(np_test_scripts) $(np_test_files) 14EXTRA_DIST = $(np_test_scripts) $(np_test_files)
15 15
@@ -28,7 +28,7 @@ AM_CFLAGS = -g -I$(top_srcdir)/lib -I$(top_srcdir)/gl $(tap_cflags)
28AM_LDFLAGS = $(tap_ldflags) -ltap 28AM_LDFLAGS = $(tap_ldflags) -ltap
29LDADD = $(top_srcdir)/lib/libnagiosplug.a $(top_srcdir)/gl/libgnu.a 29LDADD = $(top_srcdir)/lib/libnagiosplug.a $(top_srcdir)/gl/libgnu.a
30 30
31SOURCES = test_utils.c test_disk.c test_tcp.c test_cmd.c test_base64.c test_ini.c test_opts.c 31SOURCES = test_utils.c test_disk.c test_tcp.c test_cmd.c test_base64.c test_ini.c test_opts1.c test_opts2.c
32 32
33test: ${noinst_PROGRAMS} 33test: ${noinst_PROGRAMS}
34 perl -MTest::Harness -e '$$Test::Harness::switches=""; runtests(map {$$_ .= ".t"} @ARGV)' $(EXTRA_PROGRAMS) 34 perl -MTest::Harness -e '$$Test::Harness::switches=""; runtests(map {$$_ .= ".t"} @ARGV)' $(EXTRA_PROGRAMS)
diff --git a/lib/tests/test_opts.t b/lib/tests/test_opts.t
deleted file mode 100755
index d69b8f1d..00000000
--- a/lib/tests/test_opts.t
+++ /dev/null
@@ -1,6 +0,0 @@
1#!/usr/bin/perl
2use Test::More;
3if (! -e "./test_opts") {
4 plan skip_all => "./test_opts not compiled - please install tap library and/or enable parse-ini to test";
5}
6exec "./test_opts";
diff --git a/lib/tests/test_opts1 b/lib/tests/test_opts1
new file mode 100755
index 00000000..cab0f2a0
--- /dev/null
+++ b/lib/tests/test_opts1
Binary files differ
diff --git a/lib/tests/test_opts.c b/lib/tests/test_opts1.c
index ad9a8548..ea984032 100644
--- a/lib/tests/test_opts.c
+++ b/lib/tests/test_opts1.c
@@ -57,7 +57,7 @@ main (int argc, char **argv)
57 char **argv_test=NULL, **argv_known=NULL; 57 char **argv_test=NULL, **argv_known=NULL;
58 int i, argc_test; 58 int i, argc_test;
59 59
60 plan_tests(10); 60 plan_tests(5);
61 61
62 argv_test=(char **)malloc(2*sizeof(char **)); 62 argv_test=(char **)malloc(2*sizeof(char **));
63 argv_test[0] = "prog_name"; 63 argv_test[0] = "prog_name";
@@ -201,94 +201,6 @@ main (int argc, char **argv)
201 ok(array_diff(argc_test, argv_test, 4, argv_known), "Missing section 3"); 201 ok(array_diff(argc_test, argv_test, 4, argv_known), "Missing section 3");
202 my_free(&argc_test,argv_test); */ 202 my_free(&argc_test,argv_test); */
203 203
204 setenv("NAGIOS_CONFIG_PATH", ".", 1);
205 argv_test=(char **)malloc(6*sizeof(char **));
206 argv_test[0] = "prog_name";
207 argv_test[1] = "arg1";
208 argv_test[2] = "--extra-opts";
209 argv_test[3] = "--arg3";
210 argv_test[4] = "val2";
211 argv_test[5] = NULL;
212 argc_test=5;
213 argv_known=(char **)realloc(argv_known, 6*sizeof(char **));
214 argv_known[0] = "prog_name";
215 argv_known[1] = "--foo=bar";
216 argv_known[2] = "arg1";
217 argv_known[3] = "--arg3";
218 argv_known[4] = "val2";
219 argv_known[5] = NULL;
220 argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
221 ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 1");
222
223 argv_test=(char **)malloc(3*sizeof(char **));
224 argv_test[0] = "prog_name";
225 argv_test[1] = "--extra-opts";
226 argv_test[2] = NULL;
227 argc_test=2;
228 argv_known=(char **)realloc(argv_known, 3*sizeof(char **));
229 argv_known[0] = "prog_name";
230 argv_known[1] = "--foo=bar";
231 argv_known[2] = NULL;
232 argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
233 ok(array_diff(argc_test, argv_test, 2, argv_known), "Default section 2");
234 my_free(&argc_test,argv_test);
235
236 argv_test=(char **)malloc(6*sizeof(char **));
237 argv_test[0] = "prog_name";
238 argv_test[1] = "arg1";
239 argv_test[2] = "--extra-opts=section1";
240 argv_test[3] = "--arg3";
241 argv_test[4] = "val2";
242 argv_test[5] = NULL;
243 argc_test=5;
244 argv_known=(char **)realloc(argv_known, 6*sizeof(char **));
245 argv_known[0] = "prog_name";
246 argv_known[1] = "--foobar=baz";
247 argv_known[2] = "arg1";
248 argv_known[3] = "--arg3";
249 argv_known[4] = "val2";
250 argv_known[5] = NULL;
251 argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
252 ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 3");
253 my_free(&argc_test,argv_test);
254
255 argv_test=(char **)malloc(6*sizeof(char **));
256 argv_test[0] = "prog_name";
257 argv_test[1] = "arg1";
258 argv_test[2] = "--extra-opts";
259 argv_test[3] = "-arg3";
260 argv_test[4] = "val2";
261 argv_test[5] = NULL;
262 argc_test=5;
263 argv_known=(char **)realloc(argv_known, 6*sizeof(char **));
264 argv_known[0] = "prog_name";
265 argv_known[1] = "--foo=bar";
266 argv_known[2] = "arg1";
267 argv_known[3] = "-arg3";
268 argv_known[4] = "val2";
269 argv_known[5] = NULL;
270 argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
271 ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 4");
272 my_free(&argc_test,argv_test);
273
274 argv_test=(char **)malloc(4*sizeof(char **));
275 argv_test[0] = "check_tcp";
276 argv_test[1] = "--extra-opts";
277 argv_test[2] = "--extra-opts=tcp_long_lines";
278 argv_test[3] = NULL;
279 argc_test=3;
280 argv_known=(char **)realloc(argv_known, 7*sizeof(char **));
281 argv_known[0] = "check_tcp";
282 argv_known[1] = "--timeout=10";
283 argv_known[2] = "--escape";
284 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";
285 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";
286 argv_known[5] = "--jail";
287 argv_known[6] = NULL;
288 argv_test=np_extra_opts(&argc_test, argv_test, "check_tcp");
289 ok(array_diff(argc_test, argv_test, 6, argv_known), "Long lines test");
290 my_free(&argc_test,argv_test);
291
292 return exit_status(); 204 return exit_status();
293} 205}
294 206
diff --git a/lib/tests/test_opts1.t b/lib/tests/test_opts1.t
new file mode 100755
index 00000000..52eed942
--- /dev/null
+++ b/lib/tests/test_opts1.t
@@ -0,0 +1,6 @@
1#!/usr/bin/perl
2use Test::More;
3if (! -e "./test_opts1") {
4 plan skip_all => "./test_opts1 not compiled - please install tap library and/or enable parse-ini to test";
5}
6exec "./test_opts1";
diff --git a/lib/tests/test_opts2 b/lib/tests/test_opts2
new file mode 100755
index 00000000..226fe919
--- /dev/null
+++ b/lib/tests/test_opts2
Binary files differ
diff --git a/lib/tests/test_opts2.c b/lib/tests/test_opts2.c
new file mode 100644
index 00000000..2646b2fc
--- /dev/null
+++ b/lib/tests/test_opts2.c
@@ -0,0 +1,151 @@
1/*****************************************************************************
2*
3* This program is free software: you can redistribute it and/or modify
4* it under the terms of the GNU General Public License as published by
5* the Free Software Foundation, either version 3 of the License, or
6* (at your option) any later version.
7*
8* This program is distributed in the hope that it will be useful,
9* but WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16*****************************************************************************/
17
18#include "common.h"
19#include "utils_base.h"
20#include "extra_opts.h"
21
22#include "tap.h"
23
24void my_free(int *argc, char **argv) {
25 int i;
26 printf (" Arg(%i): ", *argc);
27 for (i=1; i<*argc; i++) printf ("'%s' ", argv[i]);
28 printf ("\n");
29 free(argv);
30 *argc=0;
31}
32
33int array_diff(int i1, char **a1, int i2, char **a2) {
34 int i;
35
36 if (i1 != i2) {
37 printf(" Argument count doesn't match!\n");
38 return 0;
39 }
40 for (i=0; i<=i1; i++) {
41 if (a1[i]==NULL && a2[i]==NULL) continue;
42 if (a1[i]==NULL || a2[i]==NULL) {
43 printf(" Argument # %i null in one array!\n", i);
44 return 0;
45 }
46 if (strcmp(a1[i], a2[i])) {
47 printf(" Argument # %i doesn't match!\n", i);
48 return 0;
49 }
50 }
51 return 1;
52}
53
54int
55main (int argc, char **argv)
56{
57 char **argv_test=NULL, **argv_known=NULL;
58 int i, argc_test;
59
60 plan_tests(5);
61
62 argv_test=(char **)malloc(6*sizeof(char **));
63 argv_test[0] = "prog_name";
64 argv_test[1] = "arg1";
65 argv_test[2] = "--extra-opts";
66 argv_test[3] = "--arg3";
67 argv_test[4] = "val2";
68 argv_test[5] = NULL;
69 argc_test=5;
70 argv_known=(char **)realloc(argv_known, 6*sizeof(char **));
71 argv_known[0] = "prog_name";
72 argv_known[1] = "--foo=bar";
73 argv_known[2] = "arg1";
74 argv_known[3] = "--arg3";
75 argv_known[4] = "val2";
76 argv_known[5] = NULL;
77 argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
78 ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 1");
79
80 argv_test=(char **)malloc(3*sizeof(char **));
81 argv_test[0] = "prog_name";
82 argv_test[1] = "--extra-opts";
83 argv_test[2] = NULL;
84 argc_test=2;
85 argv_known=(char **)realloc(argv_known, 3*sizeof(char **));
86 argv_known[0] = "prog_name";
87 argv_known[1] = "--foo=bar";
88 argv_known[2] = NULL;
89 argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
90 ok(array_diff(argc_test, argv_test, 2, argv_known), "Default section 2");
91 my_free(&argc_test,argv_test);
92
93 argv_test=(char **)malloc(6*sizeof(char **));
94 argv_test[0] = "prog_name";
95 argv_test[1] = "arg1";
96 argv_test[2] = "--extra-opts=section1";
97 argv_test[3] = "--arg3";
98 argv_test[4] = "val2";
99 argv_test[5] = NULL;
100 argc_test=5;
101 argv_known=(char **)realloc(argv_known, 6*sizeof(char **));
102 argv_known[0] = "prog_name";
103 argv_known[1] = "--foobar=baz";
104 argv_known[2] = "arg1";
105 argv_known[3] = "--arg3";
106 argv_known[4] = "val2";
107 argv_known[5] = NULL;
108 argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
109 ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 3");
110 my_free(&argc_test,argv_test);
111
112 argv_test=(char **)malloc(6*sizeof(char **));
113 argv_test[0] = "prog_name";
114 argv_test[1] = "arg1";
115 argv_test[2] = "--extra-opts";
116 argv_test[3] = "-arg3";
117 argv_test[4] = "val2";
118 argv_test[5] = NULL;
119 argc_test=5;
120 argv_known=(char **)realloc(argv_known, 6*sizeof(char **));
121 argv_known[0] = "prog_name";
122 argv_known[1] = "--foo=bar";
123 argv_known[2] = "arg1";
124 argv_known[3] = "-arg3";
125 argv_known[4] = "val2";
126 argv_known[5] = NULL;
127 argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
128 ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 4");
129 my_free(&argc_test,argv_test);
130
131 argv_test=(char **)malloc(4*sizeof(char **));
132 argv_test[0] = "check_tcp";
133 argv_test[1] = "--extra-opts";
134 argv_test[2] = "--extra-opts=tcp_long_lines";
135 argv_test[3] = NULL;
136 argc_test=3;
137 argv_known=(char **)realloc(argv_known, 7*sizeof(char **));
138 argv_known[0] = "check_tcp";
139 argv_known[1] = "--timeout=10";
140 argv_known[2] = "--escape";
141 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";
142 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";
143 argv_known[5] = "--jail";
144 argv_known[6] = NULL;
145 argv_test=np_extra_opts(&argc_test, argv_test, "check_tcp");
146 ok(array_diff(argc_test, argv_test, 6, argv_known), "Long lines test");
147 my_free(&argc_test,argv_test);
148
149 return exit_status();
150}
151
diff --git a/lib/tests/test_opts2.t b/lib/tests/test_opts2.t
new file mode 100755
index 00000000..f7444f6f
--- /dev/null
+++ b/lib/tests/test_opts2.t
@@ -0,0 +1,7 @@
1#!/usr/bin/perl
2use Test::More;
3if (! -e "./test_opts2") {
4 plan skip_all => "./test_opts2 not compiled - please install tap library and/or enable parse-ini to test";
5}
6$ENV{"NAGIOS_CONFIG_PATH"} = ".";
7exec "./test_opts2";