diff options
author | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2009-01-21 04:55:34 (GMT) |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2009-01-21 04:58:02 (GMT) |
commit | 3b69f134671e60eb5de0ca895177064294b6eb78 (patch) | |
tree | e4a006bf794efb29f539b3002f979f179a655b5e /lib/tests/test_opts2.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_opts2.c')
-rw-r--r-- | lib/tests/test_opts2.c | 151 |
1 files changed, 151 insertions, 0 deletions
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 @@ | |||
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(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 | |||