diff options
author | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2009-01-20 23:55:34 -0500 |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2009-01-20 23:58:02 -0500 |
commit | 3b69f134671e60eb5de0ca895177064294b6eb78 (patch) | |
tree | e4a006bf794efb29f539b3002f979f179a655b5e /lib/tests/test_opts.c | |
parent | 26bf63a5bba0fae77033693030c75eace202f988 (diff) | |
download | monitoring-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.
Diffstat (limited to 'lib/tests/test_opts.c')
-rw-r--r-- | lib/tests/test_opts.c | 294 |
1 files changed, 0 insertions, 294 deletions
diff --git a/lib/tests/test_opts.c b/lib/tests/test_opts.c deleted file mode 100644 index ad9a8548..00000000 --- a/lib/tests/test_opts.c +++ /dev/null | |||
@@ -1,294 +0,0 @@ | |||
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 | |||
24 | void 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 | |||
33 | int 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 | |||
54 | int | ||
55 | main (int argc, char **argv) | ||
56 | { | ||
57 | char **argv_test=NULL, **argv_known=NULL; | ||
58 | int i, argc_test; | ||
59 | |||
60 | plan_tests(10); | ||
61 | |||
62 | argv_test=(char **)malloc(2*sizeof(char **)); | ||
63 | argv_test[0] = "prog_name"; | ||
64 | argv_test[1] = NULL; | ||
65 | argc_test=1; | ||
66 | argv_known=(char **)realloc(argv_known, 2*sizeof(char **)); | ||
67 | argv_known[0] = "prog_name"; | ||
68 | argv_known[1] = NULL; | ||
69 | argv_test=np_extra_opts(&argc_test, argv_test, "check_disk"); | ||
70 | ok(array_diff(argc_test, argv_test, 1, argv_known), "No opts, returns correct argv/argc"); | ||
71 | my_free(&argc_test, argv_test); | ||
72 | |||
73 | argv_test=(char **)malloc(6*sizeof(char **)); | ||
74 | argv_test[0] = "prog_name"; | ||
75 | argv_test[1] = "arg1"; | ||
76 | argv_test[2] = "--arg2=val1"; | ||
77 | argv_test[3] = "--arg3"; | ||
78 | argv_test[4] = "val2"; | ||
79 | argv_test[5] = NULL; | ||
80 | argc_test=5; | ||
81 | argv_known=(char **)realloc(argv_known, 6*sizeof(char **)); | ||
82 | argv_known[0] = "prog_name"; | ||
83 | argv_known[1] = "arg1"; | ||
84 | argv_known[2] = "--arg2=val1"; | ||
85 | argv_known[3] = "--arg3"; | ||
86 | argv_known[4] = "val2"; | ||
87 | argv_known[5] = NULL; | ||
88 | argv_test=np_extra_opts(&argc_test, argv_test, "check_disk"); | ||
89 | ok(array_diff(argc_test, argv_test, 5, argv_known), "No extra opts, verbatim copy of argv"); | ||
90 | my_free(&argc_test,argv_test); | ||
91 | |||
92 | argv_test=(char **)malloc(3*sizeof(char **)); | ||
93 | argv_test[0] = "prog_name"; | ||
94 | argv_test[1] = "--extra-opts=@./config-opts.ini"; | ||
95 | argv_test[2] = NULL; | ||
96 | argc_test=2; | ||
97 | argv_known=(char **)realloc(argv_known, 5*sizeof(char **)); | ||
98 | argv_known[0] = "prog_name"; | ||
99 | argv_known[1] = "--foo=Bar"; | ||
100 | argv_known[2] = "--this=Your Mother!"; | ||
101 | argv_known[3] = "--blank"; | ||
102 | argv_known[4] = NULL; | ||
103 | argv_test=np_extra_opts(&argc_test, argv_test, "check_disk"); | ||
104 | ok(array_diff(argc_test, argv_test, 4, argv_known), "Only extra opts using default section"); | ||
105 | my_free(&argc_test,argv_test); | ||
106 | |||
107 | argv_test=(char **)malloc(5*sizeof(char **)); | ||
108 | argv_test[0] = "prog_name"; | ||
109 | argv_test[1] = "--extra-opts=sect1@./config-opts.ini"; | ||
110 | argv_test[2] = "--extra-opts"; | ||
111 | argv_test[3] = "sect2@./config-opts.ini"; | ||
112 | argv_test[4] = NULL; | ||
113 | argc_test=4; | ||
114 | argv_known=(char **)realloc(argv_known, 5*sizeof(char **)); | ||
115 | argv_known[0] = "prog_name"; | ||
116 | argv_known[1] = "--one=two"; | ||
117 | argv_known[2] = "--something else=oops"; | ||
118 | argv_known[3] = "--this=that"; | ||
119 | argv_known[4] = NULL; | ||
120 | argv_test=np_extra_opts(&argc_test, argv_test, "check_disk"); | ||
121 | ok(array_diff(argc_test, argv_test, 4, argv_known), "Only extra opts specified twice"); | ||
122 | my_free(&argc_test,argv_test); | ||
123 | |||
124 | argv_test=(char **)malloc(7*sizeof(char **)); | ||
125 | argv_test[0] = "prog_name"; | ||
126 | argv_test[1] = "--arg1=val1"; | ||
127 | argv_test[2] = "--extra-opts=@./config-opts.ini"; | ||
128 | argv_test[3] = "--extra-opts"; | ||
129 | argv_test[4] = "sect1@./config-opts.ini"; | ||
130 | argv_test[5] = "--arg2"; | ||
131 | argv_test[6] = NULL; | ||
132 | argc_test=6; | ||
133 | argv_known=(char **)realloc(argv_known, 8*sizeof(char **)); | ||
134 | argv_known[0] = "prog_name"; | ||
135 | argv_known[1] = "--foo=Bar"; | ||
136 | argv_known[2] = "--this=Your Mother!"; | ||
137 | argv_known[3] = "--blank"; | ||
138 | argv_known[4] = "--one=two"; | ||
139 | argv_known[5] = "--arg1=val1"; | ||
140 | argv_known[6] = "--arg2"; | ||
141 | argv_known[7] = NULL; | ||
142 | argv_test=np_extra_opts(&argc_test, argv_test, "check_disk"); | ||
143 | ok(array_diff(argc_test, argv_test, 7, argv_known), "twice extra opts using two sections"); | ||
144 | my_free(&argc_test,argv_test); | ||
145 | |||
146 | /* Next three checks are expected to die. They are commented out as they | ||
147 | * could possibly go in a sepatare test checked for return value. | ||
148 | */ | ||
149 | /* argv_test=(char **)malloc(6*sizeof(char **)); | ||
150 | argv_test[0] = "prog_name"; | ||
151 | argv_test[1] = "arg1"; | ||
152 | argv_test[2] = "--extra-opts=missing@./config-opts.ini"; | ||
153 | argv_test[3] = "--arg3"; | ||
154 | argv_test[4] = "val2"; | ||
155 | argv_test[5] = NULL; | ||
156 | argc_test=5; | ||
157 | argv_known=(char **)realloc(argv_known, 5*sizeof(char **)); | ||
158 | argv_known[0] = "prog_name"; | ||
159 | argv_known[1] = "arg1"; | ||
160 | argv_known[2] = "--arg3"; | ||
161 | argv_known[3] = "val2"; | ||
162 | argv_known[4] = NULL; | ||
163 | argv_test=np_extra_opts(&argc_test, argv_test, "check_missing"); | ||
164 | ok(array_diff(argc_test, argv_test, 4, argv_known), "Missing section 1"); | ||
165 | my_free(&argc_test,argv_test); */ | ||
166 | |||
167 | /* argv_test=(char **)malloc(7*sizeof(char **)); | ||
168 | argv_test[0] = "prog_name"; | ||
169 | argv_test[1] = "arg1"; | ||
170 | argv_test[2] = "--extra-opts"; | ||
171 | argv_test[3] = "missing@./config-opts.ini"; | ||
172 | argv_test[4] = "--arg3"; | ||
173 | argv_test[5] = "val2"; | ||
174 | argv_test[6] = NULL; | ||
175 | argc_test=6; | ||
176 | argv_known=(char **)realloc(argv_known, 5*sizeof(char **)); | ||
177 | argv_known[0] = "prog_name"; | ||
178 | argv_known[1] = "arg1"; | ||
179 | argv_known[2] = "--arg3"; | ||
180 | argv_known[3] = "val2"; | ||
181 | argv_known[4] = NULL; | ||
182 | argv_test=np_extra_opts(&argc_test, argv_test, "check_missing"); | ||
183 | ok(array_diff(argc_test, argv_test, 4, argv_known), "Missing section 2"); | ||
184 | my_free(&argc_test,argv_test); */ | ||
185 | |||
186 | /* argv_test=(char **)malloc(6*sizeof(char **)); | ||
187 | argv_test[0] = "prog_name"; | ||
188 | argv_test[1] = "arg1"; | ||
189 | argv_test[2] = "--extra-opts"; | ||
190 | argv_test[3] = "--arg3"; | ||
191 | argv_test[4] = "val2"; | ||
192 | argv_test[5] = NULL; | ||
193 | argc_test=5; | ||
194 | argv_known=(char **)realloc(argv_known, 5*sizeof(char **)); | ||
195 | argv_known[0] = "prog_name"; | ||
196 | argv_known[1] = "arg1"; | ||
197 | argv_known[2] = "--arg3"; | ||
198 | argv_known[3] = "val2"; | ||
199 | argv_known[4] = NULL; | ||
200 | argv_test=np_extra_opts(&argc_test, argv_test, "check_missing"); | ||
201 | ok(array_diff(argc_test, argv_test, 4, argv_known), "Missing section 3"); | ||
202 | my_free(&argc_test,argv_test); */ | ||
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(); | ||
293 | } | ||
294 | |||