diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2024-10-31 13:58:50 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-31 13:58:50 (GMT) |
commit | 87eb2bef1ee2a6a42793437b2f5d63f41b1e1806 (patch) | |
tree | 9513fdfe66af00b7332fd1578f50af8403e64371 /lib/tests | |
parent | b1d260a821b7d4916d6bf1a026fbc9b4f2b268ae (diff) | |
parent | 7d90b8200f709d125df19fa6aedf633c64b88ad4 (diff) | |
download | monitoring-plugins-87eb2bef1ee2a6a42793437b2f5d63f41b1e1806.tar.gz |
Merge pull request #2034 from RincewindsHat/cleanup/lib
Cleanup/lib
Diffstat (limited to 'lib/tests')
-rw-r--r-- | lib/tests/test_base64.c | 308 | ||||
-rw-r--r-- | lib/tests/test_cmd.c | 261 | ||||
-rw-r--r-- | lib/tests/test_disk.c | 180 | ||||
-rwxr-xr-x | lib/tests/test_generic_output | bin | 0 -> 143808 bytes | |||
-rw-r--r-- | lib/tests/test_ini1.c | 116 | ||||
-rw-r--r-- | lib/tests/test_ini3.c | 37 | ||||
-rw-r--r-- | lib/tests/test_opts1.c | 105 | ||||
-rw-r--r-- | lib/tests/test_opts2.c | 124 | ||||
-rw-r--r-- | lib/tests/test_opts3.c | 37 | ||||
-rw-r--r-- | lib/tests/test_tcp.c | 48 | ||||
-rw-r--r-- | lib/tests/test_utils.c | 491 |
11 files changed, 796 insertions, 911 deletions
diff --git a/lib/tests/test_base64.c b/lib/tests/test_base64.c index 05dd794..94cb5aa 100644 --- a/lib/tests/test_base64.c +++ b/lib/tests/test_base64.c | |||
@@ -1,29 +1,27 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * This program is free software: you can redistribute it and/or modify | 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 | 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 | 5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. | 6 | * (at your option) any later version. |
7 | * | 7 | * |
8 | * This program is distributed in the hope that it will be useful, | 8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. | 11 | * GNU General Public License for more details. |
12 | * | 12 | * |
13 | * You should have received a copy of the GNU General Public License | 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/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | * | 15 | * |
16 | * | 16 | * |
17 | *****************************************************************************/ | 17 | *****************************************************************************/ |
18 | 18 | ||
19 | #include "common.h" | 19 | #include "common.h" |
20 | #include "gl/base64.h" | 20 | #include "gl/base64.h" |
21 | #include "tap.h" | 21 | #include "tap.h" |
22 | 22 | ||
23 | int | 23 | int main(int argc, char **argv) { |
24 | main (int argc, char **argv) | 24 | #if 0 /* The current base64 function doesn't work on 8bit data */ |
25 | { | ||
26 | #if 0 /* The current base64 function doesn't work on 8bit data */ | ||
27 | char random[1024] = { | 25 | char random[1024] = { |
28 | 0x8b,0xb0,0xc4,0xe2,0xfc,0x22,0x9f,0x0d,0x85,0xe7,0x2c,0xaa,0x39,0xa1,0x46,0x88, | 26 | 0x8b,0xb0,0xc4,0xe2,0xfc,0x22,0x9f,0x0d,0x85,0xe7,0x2c,0xaa,0x39,0xa1,0x46,0x88, |
29 | 0x50,0xe6,0x34,0x37,0x0b,0x45,0x4b,0xb8,0xb2,0x86,0x7a,0x3e,0x7f,0x0c,0x40,0x18, | 27 | 0x50,0xe6,0x34,0x37,0x0b,0x45,0x4b,0xb8,0xb2,0x86,0x7a,0x3e,0x7f,0x0c,0x40,0x18, |
@@ -182,168 +180,124 @@ main (int argc, char **argv) | |||
182 | #endif | 180 | #endif |
183 | 181 | ||
184 | char random[1024] = { | 182 | char random[1024] = { |
185 | 0x0b,0x30,0x44,0x62,0x7c,0x22,0x1f,0x0d,0x05,0x67,0x2c,0x2a,0x39,0x21,0x46,0x08, | 183 | 0x0b, 0x30, 0x44, 0x62, 0x7c, 0x22, 0x1f, 0x0d, 0x05, 0x67, 0x2c, 0x2a, 0x39, 0x21, 0x46, 0x08, 0x50, 0x66, 0x34, 0x37, 0x0b, 0x45, |
186 | 0x50,0x66,0x34,0x37,0x0b,0x45,0x4b,0x38,0x32,0x06,0x7a,0x3e,0x7f,0x0c,0x40,0x18, | 184 | 0x4b, 0x38, 0x32, 0x06, 0x7a, 0x3e, 0x7f, 0x0c, 0x40, 0x18, 0x6b, 0x2d, 0x60, 0x4c, 0x60, 0x0c, 0x23, 0x43, 0x3b, 0x3e, 0x1b, 0x16, |
187 | 0x6b,0x2d,0x60,0x4c,0x60,0x0c,0x23,0x43,0x3b,0x3e,0x1b,0x16,0x04,0x46,0x58,0x3f, | 185 | 0x04, 0x46, 0x58, 0x3f, 0x40, 0x6a, 0x11, 0x05, 0x63, 0x71, 0x14, 0x35, 0x47, 0x79, 0x13, 0x6f, 0x6b, 0x27, 0x18, 0x5b, 0x48, 0x27, |
188 | 0x40,0x6a,0x11,0x05,0x63,0x71,0x14,0x35,0x47,0x79,0x13,0x6f,0x6b,0x27,0x18,0x5b, | 186 | 0x3e, 0x6f, 0x15, 0x33, 0x4f, 0x3e, 0x5e, 0x51, 0x73, 0x68, 0x25, 0x0f, 0x06, 0x5b, 0x7c, 0x72, 0x75, 0x3e, 0x3f, 0x1b, 0x5c, 0x6d, |
189 | 0x48,0x27,0x3e,0x6f,0x15,0x33,0x4f,0x3e,0x5e,0x51,0x73,0x68,0x25,0x0f,0x06,0x5b, | 187 | 0x6a, 0x39, 0x7c, 0x63, 0x63, 0x60, 0x6c, 0x7a, 0x33, 0x76, 0x52, 0x13, 0x25, 0x33, 0x7d, 0x65, 0x23, 0x27, 0x11, 0x06, 0x06, 0x47, |
190 | 0x7c,0x72,0x75,0x3e,0x3f,0x1b,0x5c,0x6d,0x6a,0x39,0x7c,0x63,0x63,0x60,0x6c,0x7a, | 188 | 0x71, 0x1e, 0x14, 0x74, 0x63, 0x70, 0x2d, 0x15, 0x27, 0x18, 0x51, 0x06, 0x05, 0x33, 0x11, 0x2c, 0x6b, 0x00, 0x2d, 0x77, 0x20, 0x48, |
191 | 0x33,0x76,0x52,0x13,0x25,0x33,0x7d,0x65,0x23,0x27,0x11,0x06,0x06,0x47,0x71,0x1e, | 189 | 0x0d, 0x73, 0x51, 0x45, 0x25, 0x7f, 0x7f, 0x35, 0x26, 0x2e, 0x26, 0x53, 0x24, 0x68, 0x1e, 0x0e, 0x58, 0x3a, 0x59, 0x50, 0x56, 0x37, |
192 | 0x14,0x74,0x63,0x70,0x2d,0x15,0x27,0x18,0x51,0x06,0x05,0x33,0x11,0x2c,0x6b,0x00, | 190 | 0x5f, 0x66, 0x01, 0x4c, 0x5a, 0x64, 0x32, 0x50, 0x7b, 0x6a, 0x20, 0x72, 0x2b, 0x1d, 0x7e, 0x43, 0x7b, 0x61, 0x42, 0x0b, 0x61, 0x73, |
193 | 0x2d,0x77,0x20,0x48,0x0d,0x73,0x51,0x45,0x25,0x7f,0x7f,0x35,0x26,0x2e,0x26,0x53, | 191 | 0x24, 0x79, 0x3a, 0x6b, 0x4a, 0x79, 0x6e, 0x09, 0x0f, 0x27, 0x2d, 0x0c, 0x5e, 0x32, 0x4b, 0x0d, 0x79, 0x46, 0x39, 0x21, 0x0a, 0x26, |
194 | 0x24,0x68,0x1e,0x0e,0x58,0x3a,0x59,0x50,0x56,0x37,0x5f,0x66,0x01,0x4c,0x5a,0x64, | 192 | 0x5f, 0x3a, 0x00, 0x26, 0x3f, 0x13, 0x2e, 0x7e, 0x50, 0x2b, 0x67, 0x46, 0x72, 0x3f, 0x3b, 0x01, 0x46, 0x1b, 0x0b, 0x35, 0x49, 0x39, |
195 | 0x32,0x50,0x7b,0x6a,0x20,0x72,0x2b,0x1d,0x7e,0x43,0x7b,0x61,0x42,0x0b,0x61,0x73, | 193 | 0x19, 0x70, 0x3d, 0x02, 0x41, 0x0e, 0x38, 0x05, 0x76, 0x65, 0x4f, 0x31, 0x6c, 0x5e, 0x17, 0x04, 0x15, 0x36, 0x26, 0x64, 0x34, 0x14, |
196 | 0x24,0x79,0x3a,0x6b,0x4a,0x79,0x6e,0x09,0x0f,0x27,0x2d,0x0c,0x5e,0x32,0x4b,0x0d, | 194 | 0x17, 0x7c, 0x0e, 0x0b, 0x5b, 0x55, 0x53, 0x6b, 0x00, 0x42, 0x41, 0x4f, 0x02, 0x5c, 0x13, 0x0a, 0x2c, 0x2c, 0x3e, 0x10, 0x14, 0x33, |
197 | 0x79,0x46,0x39,0x21,0x0a,0x26,0x5f,0x3a,0x00,0x26,0x3f,0x13,0x2e,0x7e,0x50,0x2b, | 195 | 0x45, 0x7c, 0x7a, 0x5a, 0x31, 0x61, 0x39, 0x08, 0x22, 0x6a, 0x1e, 0x0f, 0x6f, 0x1b, 0x6c, 0x13, 0x5e, 0x79, 0x20, 0x79, 0x50, 0x62, |
198 | 0x67,0x46,0x72,0x3f,0x3b,0x01,0x46,0x1b,0x0b,0x35,0x49,0x39,0x19,0x70,0x3d,0x02, | 196 | 0x06, 0x2c, 0x76, 0x17, 0x04, 0x2b, 0x2a, 0x75, 0x1f, 0x0c, 0x37, 0x4e, 0x0f, 0x7b, 0x2d, 0x34, 0x75, 0x60, 0x31, 0x74, 0x2e, 0x0a, |
199 | 0x41,0x0e,0x38,0x05,0x76,0x65,0x4f,0x31,0x6c,0x5e,0x17,0x04,0x15,0x36,0x26,0x64, | 197 | 0x4a, 0x11, 0x6c, 0x49, 0x25, 0x01, 0x3a, 0x3d, 0x22, 0x1e, 0x6d, 0x18, 0x51, 0x78, 0x2d, 0x62, 0x31, 0x4c, 0x50, 0x40, 0x17, 0x4b, |
200 | 0x34,0x14,0x17,0x7c,0x0e,0x0b,0x5b,0x55,0x53,0x6b,0x00,0x42,0x41,0x4f,0x02,0x5c, | 198 | 0x6f, 0x22, 0x00, 0x7f, 0x61, 0x2a, 0x34, 0x3e, 0x00, 0x5f, 0x2f, 0x5f, 0x2f, 0x14, 0x2a, 0x55, 0x27, 0x1f, 0x46, 0x1f, 0x12, 0x46, |
201 | 0x13,0x0a,0x2c,0x2c,0x3e,0x10,0x14,0x33,0x45,0x7c,0x7a,0x5a,0x31,0x61,0x39,0x08, | 199 | 0x5e, 0x1e, 0x0c, 0x7c, 0x38, 0x01, 0x61, 0x64, 0x76, 0x22, 0x6e, 0x08, 0x20, 0x38, 0x4f, 0x73, 0x72, 0x55, 0x12, 0x42, 0x19, 0x50, |
202 | 0x22,0x6a,0x1e,0x0f,0x6f,0x1b,0x6c,0x13,0x5e,0x79,0x20,0x79,0x50,0x62,0x06,0x2c, | 200 | 0x61, 0x43, 0x77, 0x7d, 0x41, 0x2e, 0x35, 0x4f, 0x3d, 0x31, 0x28, 0x58, 0x67, 0x1b, 0x03, 0x51, 0x20, 0x32, 0x1c, 0x08, 0x6e, 0x37, |
203 | 0x76,0x17,0x04,0x2b,0x2a,0x75,0x1f,0x0c,0x37,0x4e,0x0f,0x7b,0x2d,0x34,0x75,0x60, | 201 | 0x75, 0x37, 0x44, 0x4f, 0x68, 0x19, 0x07, 0x64, 0x14, 0x28, 0x25, 0x2b, 0x69, 0x35, 0x18, 0x27, 0x26, 0x14, 0x13, 0x70, 0x42, 0x19, |
204 | 0x31,0x74,0x2e,0x0a,0x4a,0x11,0x6c,0x49,0x25,0x01,0x3a,0x3d,0x22,0x1e,0x6d,0x18, | 202 | 0x12, 0x75, 0x3e, 0x02, 0x5d, 0x7c, 0x13, 0x1f, 0x16, 0x53, 0x3b, 0x74, 0x48, 0x3c, 0x5e, 0x39, 0x6c, 0x1c, 0x1c, 0x74, 0x39, 0x1f, |
205 | 0x51,0x78,0x2d,0x62,0x31,0x4c,0x50,0x40,0x17,0x4b,0x6f,0x22,0x00,0x7f,0x61,0x2a, | 203 | 0x00, 0x1b, 0x06, 0x0a, 0x68, 0x3b, 0x52, 0x4f, 0x1e, 0x6e, 0x3c, 0x35, 0x0c, 0x38, 0x0e, 0x0b, 0x3b, 0x1a, 0x76, 0x23, 0x29, 0x53, |
206 | 0x34,0x3e,0x00,0x5f,0x2f,0x5f,0x2f,0x14,0x2a,0x55,0x27,0x1f,0x46,0x1f,0x12,0x46, | 204 | 0x1e, 0x5f, 0x41, 0x0c, 0x4b, 0x0a, 0x65, 0x28, 0x78, 0x67, 0x48, 0x59, 0x26, 0x6d, 0x31, 0x76, 0x23, 0x70, 0x61, 0x64, 0x3b, 0x38, |
207 | 0x5e,0x1e,0x0c,0x7c,0x38,0x01,0x61,0x64,0x76,0x22,0x6e,0x08,0x20,0x38,0x4f,0x73, | 205 | 0x79, 0x66, 0x74, 0x53, 0x2c, 0x64, 0x64, 0x54, 0x03, 0x54, 0x65, 0x44, 0x4c, 0x18, 0x4f, 0x48, 0x20, 0x4f, 0x72, 0x10, 0x3f, 0x0c, |
208 | 0x72,0x55,0x12,0x42,0x19,0x50,0x61,0x43,0x77,0x7d,0x41,0x2e,0x35,0x4f,0x3d,0x31, | 206 | 0x52, 0x2d, 0x03, 0x14, 0x03, 0x51, 0x42, 0x10, 0x77, 0x6a, 0x34, 0x06, 0x32, 0x03, 0x72, 0x14, 0x7c, 0x08, 0x5d, 0x52, 0x1a, 0x62, |
209 | 0x28,0x58,0x67,0x1b,0x03,0x51,0x20,0x32,0x1c,0x08,0x6e,0x37,0x75,0x37,0x44,0x4f, | 207 | 0x7c, 0x3e, 0x30, 0x7e, 0x5f, 0x7f, 0x54, 0x0f, 0x44, 0x49, 0x5d, 0x5e, 0x10, 0x6a, 0x06, 0x2b, 0x06, 0x53, 0x10, 0x39, 0x37, 0x32, |
210 | 0x68,0x19,0x07,0x64,0x14,0x28,0x25,0x2b,0x69,0x35,0x18,0x27,0x26,0x14,0x13,0x70, | 208 | 0x4a, 0x4e, 0x3d, 0x2b, 0x65, 0x38, 0x39, 0x07, 0x72, 0x54, 0x64, 0x4d, 0x56, 0x6a, 0x03, 0x22, 0x70, 0x7b, 0x5f, 0x60, 0x0b, 0x2a, |
211 | 0x42,0x19,0x12,0x75,0x3e,0x02,0x5d,0x7c,0x13,0x1f,0x16,0x53,0x3b,0x74,0x48,0x3c, | 209 | 0x0b, 0x6b, 0x10, 0x64, 0x14, 0x05, 0x22, 0x00, 0x73, 0x40, 0x23, 0x5b, 0x51, 0x1f, 0x2b, 0x1a, 0x5d, 0x69, 0x7a, 0x46, 0x0c, 0x5f, |
212 | 0x5e,0x39,0x6c,0x1c,0x1c,0x74,0x39,0x1f,0x00,0x1b,0x06,0x0a,0x68,0x3b,0x52,0x4f, | 210 | 0x32, 0x4b, 0x4a, 0x28, 0x52, 0x79, 0x5b, 0x12, 0x42, 0x18, 0x00, 0x5d, 0x27, 0x31, 0x53, 0x3c, 0x4c, 0x36, 0x4e, 0x38, 0x3f, 0x72, |
213 | 0x1e,0x6e,0x3c,0x35,0x0c,0x38,0x0e,0x0b,0x3b,0x1a,0x76,0x23,0x29,0x53,0x1e,0x5f, | 211 | 0x03, 0x71, 0x02, 0x5b, 0x36, 0x59, 0x7f, 0x75, 0x6e, 0x08, 0x54, 0x0d, 0x34, 0x1c, 0x34, 0x57, 0x5d, 0x69, 0x48, 0x00, 0x3b, 0x05, |
214 | 0x41,0x0c,0x4b,0x0a,0x65,0x28,0x78,0x67,0x48,0x59,0x26,0x6d,0x31,0x76,0x23,0x70, | 212 | 0x07, 0x6e, 0x27, 0x65, 0x6e, 0x40, 0x3d, 0x3a, 0x4f, 0x72, 0x5d, 0x39, 0x16, 0x0f, 0x63, 0x12, 0x12, 0x15, 0x3a, 0x70, 0x0d, 0x57, |
215 | 0x61,0x64,0x3b,0x38,0x79,0x66,0x74,0x53,0x2c,0x64,0x64,0x54,0x03,0x54,0x65,0x44, | 213 | 0x18, 0x0d, 0x5e, 0x3d, 0x22, 0x68, 0x68, 0x7c, 0x6d, 0x4f, 0x0c, 0x7b, 0x09, 0x2d, 0x4a, 0x73, 0x20, 0x47, 0x07, 0x57, 0x75, 0x5d, |
216 | 0x4c,0x18,0x4f,0x48,0x20,0x4f,0x72,0x10,0x3f,0x0c,0x52,0x2d,0x03,0x14,0x03,0x51, | 214 | 0x53, 0x70, 0x34, 0x21, 0x40, 0x57, 0x51, 0x5e, 0x49, 0x44, 0x00, 0x54, 0x27, 0x04, 0x68, 0x7e, 0x59, 0x56, 0x58, 0x74, 0x14, 0x3c, |
217 | 0x42,0x10,0x77,0x6a,0x34,0x06,0x32,0x03,0x72,0x14,0x7c,0x08,0x5d,0x52,0x1a,0x62, | 215 | 0x16, 0x33, 0x41, 0x16, 0x4b, 0x2f, 0x49, 0x37, 0x0a, 0x54, 0x08, 0x08, 0x1f, 0x39, 0x67, 0x76, 0x28, 0x28, 0x07, 0x1d, 0x61, 0x47, |
218 | 0x7c,0x3e,0x30,0x7e,0x5f,0x7f,0x54,0x0f,0x44,0x49,0x5d,0x5e,0x10,0x6a,0x06,0x2b, | 216 | 0x51, 0x4d, 0x75, 0x26, 0x52, 0x47, 0x47, 0x0c, 0x57, 0x58, 0x74, 0x3e, 0x62, 0x6c, 0x58, 0x3a, 0x44, 0x1e, 0x16, 0x2e, 0x21, 0x1c, |
219 | 0x06,0x53,0x10,0x39,0x37,0x32,0x4a,0x4e,0x3d,0x2b,0x65,0x38,0x39,0x07,0x72,0x54, | 217 | 0x73, 0x45, 0x67, 0x74, 0x4f, 0x33, 0x66, 0x0e, 0x74, 0x66, 0x26, 0x1f, 0x2e, 0x38, 0x44, 0x40, 0x7e, 0x2a, 0x50, 0x52, 0x5e, 0x43, |
220 | 0x64,0x4d,0x56,0x6a,0x03,0x22,0x70,0x7b,0x5f,0x60,0x0b,0x2a,0x0b,0x6b,0x10,0x64, | 218 | 0x01, 0x7a, 0x38, 0x49, 0x3c, 0x55, 0x4d, 0x5a, 0x44, 0x08, 0x26, 0x59, 0x4d, 0x45, 0x0b, 0x48, 0x0a, 0x33, 0x5e, 0x4a, 0x4d, 0x75, |
221 | 0x14,0x05,0x22,0x00,0x73,0x40,0x23,0x5b,0x51,0x1f,0x2b,0x1a,0x5d,0x69,0x7a,0x46, | 219 | 0x16, 0x17, 0x63, 0x46, 0x01, 0x2a, 0x55, 0x7b, 0x0f, 0x02, 0x73, 0x6a, 0x4b, 0x7f, 0x75, 0x65, 0x3c, 0x4c, 0x33, 0x39, 0x6c, 0x74, |
222 | 0x0c,0x5f,0x32,0x4b,0x4a,0x28,0x52,0x79,0x5b,0x12,0x42,0x18,0x00,0x5d,0x27,0x31, | 220 | 0x05, 0x60, 0x0f, 0x7f, 0x2d, 0x41, 0x4d, 0x4d, 0x46, 0x71, 0x09, 0x6f, 0x4f, 0x60, 0x15, 0x0f, 0x46, 0x73, 0x63, 0x4c, 0x5e, 0x74, |
223 | 0x53,0x3c,0x4c,0x36,0x4e,0x38,0x3f,0x72,0x03,0x71,0x02,0x5b,0x36,0x59,0x7f,0x75, | 221 | 0x30, 0x0d, 0x28, 0x43, 0x08, 0x72, 0x32, 0x04, 0x2e, 0x31, 0x29, 0x27, 0x44, 0x6d, 0x13, 0x17, 0x48, 0x0f, 0x49, 0x52, 0x10, 0x13, |
224 | 0x6e,0x08,0x54,0x0d,0x34,0x1c,0x34,0x57,0x5d,0x69,0x48,0x00,0x3b,0x05,0x07,0x6e, | 222 | 0x7f, 0x17, 0x16, 0x62, 0x79, 0x35, 0x78, 0x3e, 0x01, 0x7c, 0x2e, 0x0f, 0x76, 0x3e, 0x5e, 0x53, 0x6c, 0x5b, 0x5f, 0x7c, 0x19, 0x41, |
225 | 0x27,0x65,0x6e,0x40,0x3d,0x3a,0x4f,0x72,0x5d,0x39,0x16,0x0f,0x63,0x12,0x12,0x15, | 223 | 0x02, 0x2f, 0x17, 0x64, 0x41, 0x75, 0x10, 0x04, 0x47, 0x7c, 0x3d, 0x4b, 0x52, 0x00, 0x10, 0x5d, 0x51, 0x4e, 0x7a, 0x27, 0x25, 0x55, |
226 | 0x3a,0x70,0x0d,0x57,0x18,0x0d,0x5e,0x3d,0x22,0x68,0x68,0x7c,0x6d,0x4f,0x0c,0x7b, | 224 | 0x40, 0x12, 0x35, 0x60, 0x05, 0x1b, 0x34, 0x2d, 0x04, 0x7a, 0x6a, 0x69, 0x02, 0x79, 0x03, 0x3a, 0x2f, 0x06, 0x0a, 0x79, 0x7b, 0x12, |
227 | 0x09,0x2d,0x4a,0x73,0x20,0x47,0x07,0x57,0x75,0x5d,0x53,0x70,0x34,0x21,0x40,0x57, | 225 | 0x5d, 0x7c, 0x52, 0x29, 0x47, 0x58, 0x12, 0x73, 0x3f, 0x27, 0x56, 0x05, 0x0c, 0x48, 0x32, 0x58, 0x6b, 0x57, 0x5c, 0x03, 0x64, 0x56, |
228 | 0x51,0x5e,0x49,0x44,0x00,0x54,0x27,0x04,0x68,0x7e,0x59,0x56,0x58,0x74,0x14,0x3c, | 226 | 0x11, 0x52, 0x7a, 0x30, 0x36, 0x29, 0x17, 0x3b, 0x68, 0x7a, 0x7c, 0x05, 0x6b, 0x6b, 0x13, 0x6a, 0x24, 0x5c, 0x68, 0x42, 0x18, 0x32, |
229 | 0x16,0x33,0x41,0x16,0x4b,0x2f,0x49,0x37,0x0a,0x54,0x08,0x08,0x1f,0x39,0x67,0x76, | 227 | 0x03, 0x73, 0x6e, 0x04, 0x21, 0x2e, 0x01, 0x04, 0x63, 0x7d, 0x44, 0x41, 0x12, 0x31, 0x0b, 0x15, 0x1f, 0x70, 0x00, 0x2e, 0x66, 0x14, |
230 | 0x28,0x28,0x07,0x1d,0x61,0x47,0x51,0x4d,0x75,0x26,0x52,0x47,0x47,0x0c,0x57,0x58, | 228 | 0x3c, 0x7f, 0x2b, 0x00, 0x1f, 0x0c, 0x28, 0x59, 0x0a, 0x16, 0x49, 0x5a, 0x5c, 0x64, 0x65, 0x4b, 0x11, 0x29, 0x15, 0x36, 0x5a, 0x65, |
231 | 0x74,0x3e,0x62,0x6c,0x58,0x3a,0x44,0x1e,0x16,0x2e,0x21,0x1c,0x73,0x45,0x67,0x74, | 229 | 0x19, 0x4f, 0x60, 0x23, 0x3a, 0x3a, 0x13, 0x25, 0x02, 0x78, 0x4c, 0x54}; |
232 | 0x4f,0x33,0x66,0x0e,0x74,0x66,0x26,0x1f,0x2e,0x38,0x44,0x40,0x7e,0x2a,0x50,0x52, | 230 | char b64_known[1369] = { |
233 | 0x5e,0x43,0x01,0x7a,0x38,0x49,0x3c,0x55,0x4d,0x5a,0x44,0x08,0x26,0x59,0x4d,0x45, | 231 | 0x43, 0x7a, 0x42, 0x45, 0x59, 0x6e, 0x77, 0x69, 0x48, 0x77, 0x30, 0x46, 0x5a, 0x79, 0x77, 0x71, 0x4f, 0x53, 0x46, 0x47, 0x43, 0x46, |
234 | 0x0b,0x48,0x0a,0x33,0x5e,0x4a,0x4d,0x75,0x16,0x17,0x63,0x46,0x01,0x2a,0x55,0x7b, | 232 | 0x42, 0x6d, 0x4e, 0x44, 0x63, 0x4c, 0x52, 0x55, 0x73, 0x34, 0x4d, 0x67, 0x5a, 0x36, 0x50, 0x6e, 0x38, 0x4d, 0x51, 0x42, 0x68, 0x72, |
235 | 0x0f,0x02,0x73,0x6a,0x4b,0x7f,0x75,0x65,0x3c,0x4c,0x33,0x39,0x6c,0x74,0x05,0x60, | 233 | 0x4c, 0x57, 0x42, 0x4d, 0x59, 0x41, 0x77, 0x6a, 0x51, 0x7a, 0x73, 0x2b, 0x47, 0x78, 0x59, 0x45, 0x52, 0x6c, 0x67, 0x2f, 0x51, 0x47, |
236 | 0x0f,0x7f,0x2d,0x41,0x4d,0x4d,0x46,0x71,0x09,0x6f,0x4f,0x60,0x15,0x0f,0x46,0x73, | 234 | 0x6f, 0x52, 0x42, 0x57, 0x4e, 0x78, 0x46, 0x44, 0x56, 0x48, 0x65, 0x52, 0x4e, 0x76, 0x61, 0x79, 0x63, 0x59, 0x57, 0x30, 0x67, 0x6e, |
237 | 0x63,0x4c,0x5e,0x74,0x30,0x0d,0x28,0x43,0x08,0x72,0x32,0x04,0x2e,0x31,0x29,0x27, | 235 | 0x50, 0x6d, 0x38, 0x56, 0x4d, 0x30, 0x38, 0x2b, 0x58, 0x6c, 0x46, 0x7a, 0x61, 0x43, 0x55, 0x50, 0x42, 0x6c, 0x74, 0x38, 0x63, 0x6e, |
238 | 0x44,0x6d,0x13,0x17,0x48,0x0f,0x49,0x52,0x10,0x13,0x7f,0x17,0x16,0x62,0x79,0x35, | 236 | 0x55, 0x2b, 0x50, 0x78, 0x74, 0x63, 0x62, 0x57, 0x6f, 0x35, 0x66, 0x47, 0x4e, 0x6a, 0x59, 0x47, 0x78, 0x36, 0x4d, 0x33, 0x5a, 0x53, |
239 | 0x78,0x3e,0x01,0x7c,0x2e,0x0f,0x76,0x3e,0x5e,0x53,0x6c,0x5b,0x5f,0x7c,0x19,0x41, | 237 | 0x45, 0x79, 0x55, 0x7a, 0x66, 0x57, 0x55, 0x6a, 0x4a, 0x78, 0x45, 0x47, 0x42, 0x6b, 0x64, 0x78, 0x48, 0x68, 0x52, 0x30, 0x59, 0x33, |
240 | 0x02,0x2f,0x17,0x64,0x41,0x75,0x10,0x04,0x47,0x7c,0x3d,0x4b,0x52,0x00,0x10,0x5d, | 238 | 0x41, 0x74, 0x46, 0x53, 0x63, 0x59, 0x55, 0x51, 0x59, 0x46, 0x4d, 0x78, 0x45, 0x73, 0x61, 0x77, 0x41, 0x74, 0x64, 0x79, 0x42, 0x49, |
241 | 0x51,0x4e,0x7a,0x27,0x25,0x55,0x40,0x12,0x35,0x60,0x05,0x1b,0x34,0x2d,0x04,0x7a, | 239 | 0x44, 0x58, 0x4e, 0x52, 0x52, 0x53, 0x56, 0x2f, 0x66, 0x7a, 0x55, 0x6d, 0x4c, 0x69, 0x5a, 0x54, 0x4a, 0x47, 0x67, 0x65, 0x44, 0x6c, |
242 | 0x6a,0x69,0x02,0x79,0x03,0x3a,0x2f,0x06,0x0a,0x79,0x7b,0x12,0x5d,0x7c,0x52,0x29, | 240 | 0x67, 0x36, 0x57, 0x56, 0x42, 0x57, 0x4e, 0x31, 0x39, 0x6d, 0x41, 0x55, 0x78, 0x61, 0x5a, 0x44, 0x4a, 0x51, 0x65, 0x32, 0x6f, 0x67, |
243 | 0x47,0x58,0x12,0x73,0x3f,0x27,0x56,0x05,0x0c,0x48,0x32,0x58,0x6b,0x57,0x5c,0x03, | 241 | 0x63, 0x69, 0x73, 0x64, 0x66, 0x6b, 0x4e, 0x37, 0x59, 0x55, 0x49, 0x4c, 0x59, 0x58, 0x4d, 0x6b, 0x65, 0x54, 0x70, 0x72, 0x53, 0x6e, |
244 | 0x64,0x56,0x11,0x52,0x7a,0x30,0x36,0x29,0x17,0x3b,0x68,0x7a,0x7c,0x05,0x6b,0x6b, | 242 | 0x6c, 0x75, 0x43, 0x51, 0x38, 0x6e, 0x4c, 0x51, 0x78, 0x65, 0x4d, 0x6b, 0x73, 0x4e, 0x65, 0x55, 0x59, 0x35, 0x49, 0x51, 0x6f, 0x6d, |
245 | 0x13,0x6a,0x24,0x5c,0x68,0x42,0x18,0x32,0x03,0x73,0x6e,0x04,0x21,0x2e,0x01,0x04, | 243 | 0x58, 0x7a, 0x6f, 0x41, 0x4a, 0x6a, 0x38, 0x54, 0x4c, 0x6e, 0x35, 0x51, 0x4b, 0x32, 0x64, 0x47, 0x63, 0x6a, 0x38, 0x37, 0x41, 0x55, |
246 | 0x63,0x7d,0x44,0x41,0x12,0x31,0x0b,0x15,0x1f,0x70,0x00,0x2e,0x66,0x14,0x3c,0x7f, | 244 | 0x59, 0x62, 0x43, 0x7a, 0x56, 0x4a, 0x4f, 0x52, 0x6c, 0x77, 0x50, 0x51, 0x4a, 0x42, 0x44, 0x6a, 0x67, 0x46, 0x64, 0x6d, 0x56, 0x50, |
247 | 0x2b,0x00,0x1f,0x0c,0x28,0x59,0x0a,0x16,0x49,0x5a,0x5c,0x64,0x65,0x4b,0x11,0x29, | 245 | 0x4d, 0x57, 0x78, 0x65, 0x46, 0x77, 0x51, 0x56, 0x4e, 0x69, 0x5a, 0x6b, 0x4e, 0x42, 0x51, 0x58, 0x66, 0x41, 0x34, 0x4c, 0x57, 0x31, |
248 | 0x15,0x36,0x5a,0x65,0x19,0x4f,0x60,0x23,0x3a,0x3a,0x13,0x25,0x02,0x78,0x4c,0x54 | 246 | 0x56, 0x54, 0x61, 0x77, 0x42, 0x43, 0x51, 0x55, 0x38, 0x43, 0x58, 0x42, 0x4d, 0x4b, 0x4c, 0x43, 0x77, 0x2b, 0x45, 0x42, 0x51, 0x7a, |
249 | }; | 247 | 0x52, 0x58, 0x78, 0x36, 0x57, 0x6a, 0x46, 0x68, 0x4f, 0x51, 0x67, 0x69, 0x61, 0x68, 0x34, 0x50, 0x62, 0x78, 0x74, 0x73, 0x45, 0x31, |
250 | char b64_known[1369] = { | 248 | 0x35, 0x35, 0x49, 0x48, 0x6c, 0x51, 0x59, 0x67, 0x59, 0x73, 0x64, 0x68, 0x63, 0x45, 0x4b, 0x79, 0x70, 0x31, 0x48, 0x77, 0x77, 0x33, |
251 | 0x43,0x7a,0x42,0x45,0x59,0x6e,0x77,0x69,0x48,0x77,0x30,0x46,0x5a,0x79,0x77,0x71, | 249 | 0x54, 0x67, 0x39, 0x37, 0x4c, 0x54, 0x52, 0x31, 0x59, 0x44, 0x46, 0x30, 0x4c, 0x67, 0x70, 0x4b, 0x45, 0x57, 0x78, 0x4a, 0x4a, 0x51, |
252 | 0x4f,0x53,0x46,0x47,0x43,0x46,0x42,0x6d,0x4e,0x44,0x63,0x4c,0x52,0x55,0x73,0x34, | 250 | 0x45, 0x36, 0x50, 0x53, 0x49, 0x65, 0x62, 0x52, 0x68, 0x52, 0x65, 0x43, 0x31, 0x69, 0x4d, 0x55, 0x78, 0x51, 0x51, 0x42, 0x64, 0x4c, |
253 | 0x4d,0x67,0x5a,0x36,0x50,0x6e,0x38,0x4d,0x51,0x42,0x68,0x72,0x4c,0x57,0x42,0x4d, | 251 | 0x62, 0x79, 0x49, 0x41, 0x66, 0x32, 0x45, 0x71, 0x4e, 0x44, 0x34, 0x41, 0x58, 0x79, 0x39, 0x66, 0x4c, 0x78, 0x51, 0x71, 0x56, 0x53, |
254 | 0x59,0x41,0x77,0x6a,0x51,0x7a,0x73,0x2b,0x47,0x78,0x59,0x45,0x52,0x6c,0x67,0x2f, | 252 | 0x63, 0x66, 0x52, 0x68, 0x38, 0x53, 0x52, 0x6c, 0x34, 0x65, 0x44, 0x48, 0x77, 0x34, 0x41, 0x57, 0x46, 0x6b, 0x64, 0x69, 0x4a, 0x75, |
255 | 0x51,0x47,0x6f,0x52,0x42,0x57,0x4e,0x78,0x46,0x44,0x56,0x48,0x65,0x52,0x4e,0x76, | 253 | 0x43, 0x43, 0x41, 0x34, 0x54, 0x33, 0x4e, 0x79, 0x56, 0x52, 0x4a, 0x43, 0x47, 0x56, 0x42, 0x68, 0x51, 0x33, 0x64, 0x39, 0x51, 0x53, |
256 | 0x61,0x79,0x63,0x59,0x57,0x30,0x67,0x6e,0x50,0x6d,0x38,0x56,0x4d,0x30,0x38,0x2b, | 254 | 0x34, 0x31, 0x54, 0x7a, 0x30, 0x78, 0x4b, 0x46, 0x68, 0x6e, 0x47, 0x77, 0x4e, 0x52, 0x49, 0x44, 0x49, 0x63, 0x43, 0x47, 0x34, 0x33, |
257 | 0x58,0x6c,0x46,0x7a,0x61,0x43,0x55,0x50,0x42,0x6c,0x74,0x38,0x63,0x6e,0x55,0x2b, | 255 | 0x64, 0x54, 0x64, 0x45, 0x54, 0x32, 0x67, 0x5a, 0x42, 0x32, 0x51, 0x55, 0x4b, 0x43, 0x55, 0x72, 0x61, 0x54, 0x55, 0x59, 0x4a, 0x79, |
258 | 0x50,0x78,0x74,0x63,0x62,0x57,0x6f,0x35,0x66,0x47,0x4e,0x6a,0x59,0x47,0x78,0x36, | 256 | 0x59, 0x55, 0x45, 0x33, 0x42, 0x43, 0x47, 0x52, 0x4a, 0x31, 0x50, 0x67, 0x4a, 0x64, 0x66, 0x42, 0x4d, 0x66, 0x46, 0x6c, 0x4d, 0x37, |
259 | 0x4d,0x33,0x5a,0x53,0x45,0x79,0x55,0x7a,0x66,0x57,0x55,0x6a,0x4a,0x78,0x45,0x47, | 257 | 0x64, 0x45, 0x67, 0x38, 0x58, 0x6a, 0x6c, 0x73, 0x48, 0x42, 0x78, 0x30, 0x4f, 0x52, 0x38, 0x41, 0x47, 0x77, 0x59, 0x4b, 0x61, 0x44, |
260 | 0x42,0x6b,0x64,0x78,0x48,0x68,0x52,0x30,0x59,0x33,0x41,0x74,0x46,0x53,0x63,0x59, | 258 | 0x74, 0x53, 0x54, 0x78, 0x35, 0x75, 0x50, 0x44, 0x55, 0x4d, 0x4f, 0x41, 0x34, 0x4c, 0x4f, 0x78, 0x70, 0x32, 0x49, 0x79, 0x6c, 0x54, |
261 | 0x55,0x51,0x59,0x46,0x4d,0x78,0x45,0x73,0x61,0x77,0x41,0x74,0x64,0x79,0x42,0x49, | 259 | 0x48, 0x6c, 0x39, 0x42, 0x44, 0x45, 0x73, 0x4b, 0x5a, 0x53, 0x68, 0x34, 0x5a, 0x30, 0x68, 0x5a, 0x4a, 0x6d, 0x30, 0x78, 0x64, 0x69, |
262 | 0x44,0x58,0x4e,0x52,0x52,0x53,0x56,0x2f,0x66,0x7a,0x55,0x6d,0x4c,0x69,0x5a,0x54, | 260 | 0x4e, 0x77, 0x59, 0x57, 0x51, 0x37, 0x4f, 0x48, 0x6c, 0x6d, 0x64, 0x46, 0x4d, 0x73, 0x5a, 0x47, 0x52, 0x55, 0x41, 0x31, 0x52, 0x6c, |
263 | 0x4a,0x47,0x67,0x65,0x44,0x6c,0x67,0x36,0x57,0x56,0x42,0x57,0x4e,0x31,0x39,0x6d, | 261 | 0x52, 0x45, 0x77, 0x59, 0x54, 0x30, 0x67, 0x67, 0x54, 0x33, 0x49, 0x51, 0x50, 0x77, 0x78, 0x53, 0x4c, 0x51, 0x4d, 0x55, 0x41, 0x31, |
264 | 0x41,0x55,0x78,0x61,0x5a,0x44,0x4a,0x51,0x65,0x32,0x6f,0x67,0x63,0x69,0x73,0x64, | 262 | 0x46, 0x43, 0x45, 0x48, 0x64, 0x71, 0x4e, 0x41, 0x59, 0x79, 0x41, 0x33, 0x49, 0x55, 0x66, 0x41, 0x68, 0x64, 0x55, 0x68, 0x70, 0x69, |
265 | 0x66,0x6b,0x4e,0x37,0x59,0x55,0x49,0x4c,0x59,0x58,0x4d,0x6b,0x65,0x54,0x70,0x72, | 263 | 0x66, 0x44, 0x34, 0x77, 0x66, 0x6c, 0x39, 0x2f, 0x56, 0x41, 0x39, 0x45, 0x53, 0x56, 0x31, 0x65, 0x45, 0x47, 0x6f, 0x47, 0x4b, 0x77, |
266 | 0x53,0x6e,0x6c,0x75,0x43,0x51,0x38,0x6e,0x4c,0x51,0x78,0x65,0x4d,0x6b,0x73,0x4e, | 264 | 0x5a, 0x54, 0x45, 0x44, 0x6b, 0x33, 0x4d, 0x6b, 0x70, 0x4f, 0x50, 0x53, 0x74, 0x6c, 0x4f, 0x44, 0x6b, 0x48, 0x63, 0x6c, 0x52, 0x6b, |
267 | 0x65,0x55,0x59,0x35,0x49,0x51,0x6f,0x6d,0x58,0x7a,0x6f,0x41,0x4a,0x6a,0x38,0x54, | 265 | 0x54, 0x56, 0x5a, 0x71, 0x41, 0x79, 0x4a, 0x77, 0x65, 0x31, 0x39, 0x67, 0x43, 0x79, 0x6f, 0x4c, 0x61, 0x78, 0x42, 0x6b, 0x46, 0x41, |
268 | 0x4c,0x6e,0x35,0x51,0x4b,0x32,0x64,0x47,0x63,0x6a,0x38,0x37,0x41,0x55,0x59,0x62, | 266 | 0x55, 0x69, 0x41, 0x48, 0x4e, 0x41, 0x49, 0x31, 0x74, 0x52, 0x48, 0x79, 0x73, 0x61, 0x58, 0x57, 0x6c, 0x36, 0x52, 0x67, 0x78, 0x66, |
269 | 0x43,0x7a,0x56,0x4a,0x4f,0x52,0x6c,0x77,0x50,0x51,0x4a,0x42,0x44,0x6a,0x67,0x46, | 267 | 0x4d, 0x6b, 0x74, 0x4b, 0x4b, 0x46, 0x4a, 0x35, 0x57, 0x78, 0x4a, 0x43, 0x47, 0x41, 0x42, 0x64, 0x4a, 0x7a, 0x46, 0x54, 0x50, 0x45, |
270 | 0x64,0x6d,0x56,0x50,0x4d,0x57,0x78,0x65,0x46,0x77,0x51,0x56,0x4e,0x69,0x5a,0x6b, | 268 | 0x77, 0x32, 0x54, 0x6a, 0x67, 0x2f, 0x63, 0x67, 0x4e, 0x78, 0x41, 0x6c, 0x73, 0x32, 0x57, 0x58, 0x39, 0x31, 0x62, 0x67, 0x68, 0x55, |
271 | 0x4e,0x42,0x51,0x58,0x66,0x41,0x34,0x4c,0x57,0x31,0x56,0x54,0x61,0x77,0x42,0x43, | 269 | 0x44, 0x54, 0x51, 0x63, 0x4e, 0x46, 0x64, 0x64, 0x61, 0x55, 0x67, 0x41, 0x4f, 0x77, 0x55, 0x48, 0x62, 0x69, 0x64, 0x6c, 0x62, 0x6b, |
272 | 0x51,0x55,0x38,0x43,0x58,0x42,0x4d,0x4b,0x4c,0x43,0x77,0x2b,0x45,0x42,0x51,0x7a, | 270 | 0x41, 0x39, 0x4f, 0x6b, 0x39, 0x79, 0x58, 0x54, 0x6b, 0x57, 0x44, 0x32, 0x4d, 0x53, 0x45, 0x68, 0x55, 0x36, 0x63, 0x41, 0x31, 0x58, |
273 | 0x52,0x58,0x78,0x36,0x57,0x6a,0x46,0x68,0x4f,0x51,0x67,0x69,0x61,0x68,0x34,0x50, | 271 | 0x47, 0x41, 0x31, 0x65, 0x50, 0x53, 0x4a, 0x6f, 0x61, 0x48, 0x78, 0x74, 0x54, 0x77, 0x78, 0x37, 0x43, 0x53, 0x31, 0x4b, 0x63, 0x79, |
274 | 0x62,0x78,0x74,0x73,0x45,0x31,0x35,0x35,0x49,0x48,0x6c,0x51,0x59,0x67,0x59,0x73, | 272 | 0x42, 0x48, 0x42, 0x31, 0x64, 0x31, 0x58, 0x56, 0x4e, 0x77, 0x4e, 0x43, 0x46, 0x41, 0x56, 0x31, 0x46, 0x65, 0x53, 0x55, 0x51, 0x41, |
275 | 0x64,0x68,0x63,0x45,0x4b,0x79,0x70,0x31,0x48,0x77,0x77,0x33,0x54,0x67,0x39,0x37, | 273 | 0x56, 0x43, 0x63, 0x45, 0x61, 0x48, 0x35, 0x5a, 0x56, 0x6c, 0x68, 0x30, 0x46, 0x44, 0x77, 0x57, 0x4d, 0x30, 0x45, 0x57, 0x53, 0x79, |
276 | 0x4c,0x54,0x52,0x31,0x59,0x44,0x46,0x30,0x4c,0x67,0x70,0x4b,0x45,0x57,0x78,0x4a, | 274 | 0x39, 0x4a, 0x4e, 0x77, 0x70, 0x55, 0x43, 0x41, 0x67, 0x66, 0x4f, 0x57, 0x64, 0x32, 0x4b, 0x43, 0x67, 0x48, 0x48, 0x57, 0x46, 0x48, |
277 | 0x4a,0x51,0x45,0x36,0x50,0x53,0x49,0x65,0x62,0x52,0x68,0x52,0x65,0x43,0x31,0x69, | 275 | 0x55, 0x55, 0x31, 0x31, 0x4a, 0x6c, 0x4a, 0x48, 0x52, 0x77, 0x78, 0x58, 0x57, 0x48, 0x51, 0x2b, 0x59, 0x6d, 0x78, 0x59, 0x4f, 0x6b, |
278 | 0x4d,0x55,0x78,0x51,0x51,0x42,0x64,0x4c,0x62,0x79,0x49,0x41,0x66,0x32,0x45,0x71, | 276 | 0x51, 0x65, 0x46, 0x69, 0x34, 0x68, 0x48, 0x48, 0x4e, 0x46, 0x5a, 0x33, 0x52, 0x50, 0x4d, 0x32, 0x59, 0x4f, 0x64, 0x47, 0x59, 0x6d, |
279 | 0x4e,0x44,0x34,0x41,0x58,0x79,0x39,0x66,0x4c,0x78,0x51,0x71,0x56,0x53,0x63,0x66, | 277 | 0x48, 0x79, 0x34, 0x34, 0x52, 0x45, 0x42, 0x2b, 0x4b, 0x6c, 0x42, 0x53, 0x58, 0x6b, 0x4d, 0x42, 0x65, 0x6a, 0x68, 0x4a, 0x50, 0x46, |
280 | 0x52,0x68,0x38,0x53,0x52,0x6c,0x34,0x65,0x44,0x48,0x77,0x34,0x41,0x57,0x46,0x6b, | 278 | 0x56, 0x4e, 0x57, 0x6b, 0x51, 0x49, 0x4a, 0x6c, 0x6c, 0x4e, 0x52, 0x51, 0x74, 0x49, 0x43, 0x6a, 0x4e, 0x65, 0x53, 0x6b, 0x31, 0x31, |
281 | 0x64,0x69,0x4a,0x75,0x43,0x43,0x41,0x34,0x54,0x33,0x4e,0x79,0x56,0x52,0x4a,0x43, | 279 | 0x46, 0x68, 0x64, 0x6a, 0x52, 0x67, 0x45, 0x71, 0x56, 0x58, 0x73, 0x50, 0x41, 0x6e, 0x4e, 0x71, 0x53, 0x33, 0x39, 0x31, 0x5a, 0x54, |
282 | 0x47,0x56,0x42,0x68,0x51,0x33,0x64,0x39,0x51,0x53,0x34,0x31,0x54,0x7a,0x30,0x78, | 280 | 0x78, 0x4d, 0x4d, 0x7a, 0x6c, 0x73, 0x64, 0x41, 0x56, 0x67, 0x44, 0x33, 0x38, 0x74, 0x51, 0x55, 0x31, 0x4e, 0x52, 0x6e, 0x45, 0x4a, |
283 | 0x4b,0x46,0x68,0x6e,0x47,0x77,0x4e,0x52,0x49,0x44,0x49,0x63,0x43,0x47,0x34,0x33, | 281 | 0x62, 0x30, 0x39, 0x67, 0x46, 0x51, 0x39, 0x47, 0x63, 0x32, 0x4e, 0x4d, 0x58, 0x6e, 0x51, 0x77, 0x44, 0x53, 0x68, 0x44, 0x43, 0x48, |
284 | 0x64,0x54,0x64,0x45,0x54,0x32,0x67,0x5a,0x42,0x32,0x51,0x55,0x4b,0x43,0x55,0x72, | 282 | 0x49, 0x79, 0x42, 0x43, 0x34, 0x78, 0x4b, 0x53, 0x64, 0x45, 0x62, 0x52, 0x4d, 0x58, 0x53, 0x41, 0x39, 0x4a, 0x55, 0x68, 0x41, 0x54, |
285 | 0x61,0x54,0x55,0x59,0x4a,0x79,0x59,0x55,0x45,0x33,0x42,0x43,0x47,0x52,0x4a,0x31, | 283 | 0x66, 0x78, 0x63, 0x57, 0x59, 0x6e, 0x6b, 0x31, 0x65, 0x44, 0x34, 0x42, 0x66, 0x43, 0x34, 0x50, 0x64, 0x6a, 0x35, 0x65, 0x55, 0x32, |
286 | 0x50,0x67,0x4a,0x64,0x66,0x42,0x4d,0x66,0x46,0x6c,0x4d,0x37,0x64,0x45,0x67,0x38, | 284 | 0x78, 0x62, 0x58, 0x33, 0x77, 0x5a, 0x51, 0x51, 0x49, 0x76, 0x46, 0x32, 0x52, 0x42, 0x64, 0x52, 0x41, 0x45, 0x52, 0x33, 0x77, 0x39, |
287 | 0x58,0x6a,0x6c,0x73,0x48,0x42,0x78,0x30,0x4f,0x52,0x38,0x41,0x47,0x77,0x59,0x4b, | 285 | 0x53, 0x31, 0x49, 0x41, 0x45, 0x46, 0x31, 0x52, 0x54, 0x6e, 0x6f, 0x6e, 0x4a, 0x56, 0x56, 0x41, 0x45, 0x6a, 0x56, 0x67, 0x42, 0x52, |
288 | 0x61,0x44,0x74,0x53,0x54,0x78,0x35,0x75,0x50,0x44,0x55,0x4d,0x4f,0x41,0x34,0x4c, | 286 | 0x73, 0x30, 0x4c, 0x51, 0x52, 0x36, 0x61, 0x6d, 0x6b, 0x43, 0x65, 0x51, 0x4d, 0x36, 0x4c, 0x77, 0x59, 0x4b, 0x65, 0x58, 0x73, 0x53, |
289 | 0x4f,0x78,0x70,0x32,0x49,0x79,0x6c,0x54,0x48,0x6c,0x39,0x42,0x44,0x45,0x73,0x4b, | 287 | 0x58, 0x58, 0x78, 0x53, 0x4b, 0x55, 0x64, 0x59, 0x45, 0x6e, 0x4d, 0x2f, 0x4a, 0x31, 0x59, 0x46, 0x44, 0x45, 0x67, 0x79, 0x57, 0x47, |
290 | 0x5a,0x53,0x68,0x34,0x5a,0x30,0x68,0x5a,0x4a,0x6d,0x30,0x78,0x64,0x69,0x4e,0x77, | 288 | 0x74, 0x58, 0x58, 0x41, 0x4e, 0x6b, 0x56, 0x68, 0x46, 0x53, 0x65, 0x6a, 0x41, 0x32, 0x4b, 0x52, 0x63, 0x37, 0x61, 0x48, 0x70, 0x38, |
291 | 0x59,0x57,0x51,0x37,0x4f,0x48,0x6c,0x6d,0x64,0x46,0x4d,0x73,0x5a,0x47,0x52,0x55, | 289 | 0x42, 0x57, 0x74, 0x72, 0x45, 0x32, 0x6f, 0x6b, 0x58, 0x47, 0x68, 0x43, 0x47, 0x44, 0x49, 0x44, 0x63, 0x32, 0x34, 0x45, 0x49, 0x53, |
292 | 0x41,0x31,0x52,0x6c,0x52,0x45,0x77,0x59,0x54,0x30,0x67,0x67,0x54,0x33,0x49,0x51, | 290 | 0x34, 0x42, 0x42, 0x47, 0x4e, 0x39, 0x52, 0x45, 0x45, 0x53, 0x4d, 0x51, 0x73, 0x56, 0x48, 0x33, 0x41, 0x41, 0x4c, 0x6d, 0x59, 0x55, |
293 | 0x50,0x77,0x78,0x53,0x4c,0x51,0x4d,0x55,0x41,0x31,0x46,0x43,0x45,0x48,0x64,0x71, | 291 | 0x50, 0x48, 0x38, 0x72, 0x41, 0x42, 0x38, 0x4d, 0x4b, 0x46, 0x6b, 0x4b, 0x46, 0x6b, 0x6c, 0x61, 0x58, 0x47, 0x52, 0x6c, 0x53, 0x78, |
294 | 0x4e,0x41,0x59,0x79,0x41,0x33,0x49,0x55,0x66,0x41,0x68,0x64,0x55,0x68,0x70,0x69, | 292 | 0x45, 0x70, 0x46, 0x54, 0x5a, 0x61, 0x5a, 0x52, 0x6c, 0x50, 0x59, 0x43, 0x4d, 0x36, 0x4f, 0x68, 0x4d, 0x6c, 0x41, 0x6e, 0x68, 0x4d, |
295 | 0x66,0x44,0x34,0x77,0x66,0x6c,0x39,0x2f,0x56,0x41,0x39,0x45,0x53,0x56,0x31,0x65, | 293 | 0x56, 0x41, 0x3d, 0x3d, 0x00}; |
296 | 0x45,0x47,0x6f,0x47,0x4b,0x77,0x5a,0x54,0x45,0x44,0x6b,0x33,0x4d,0x6b,0x70,0x4f, | ||
297 | 0x50,0x53,0x74,0x6c,0x4f,0x44,0x6b,0x48,0x63,0x6c,0x52,0x6b,0x54,0x56,0x5a,0x71, | ||
298 | 0x41,0x79,0x4a,0x77,0x65,0x31,0x39,0x67,0x43,0x79,0x6f,0x4c,0x61,0x78,0x42,0x6b, | ||
299 | 0x46,0x41,0x55,0x69,0x41,0x48,0x4e,0x41,0x49,0x31,0x74,0x52,0x48,0x79,0x73,0x61, | ||
300 | 0x58,0x57,0x6c,0x36,0x52,0x67,0x78,0x66,0x4d,0x6b,0x74,0x4b,0x4b,0x46,0x4a,0x35, | ||
301 | 0x57,0x78,0x4a,0x43,0x47,0x41,0x42,0x64,0x4a,0x7a,0x46,0x54,0x50,0x45,0x77,0x32, | ||
302 | 0x54,0x6a,0x67,0x2f,0x63,0x67,0x4e,0x78,0x41,0x6c,0x73,0x32,0x57,0x58,0x39,0x31, | ||
303 | 0x62,0x67,0x68,0x55,0x44,0x54,0x51,0x63,0x4e,0x46,0x64,0x64,0x61,0x55,0x67,0x41, | ||
304 | 0x4f,0x77,0x55,0x48,0x62,0x69,0x64,0x6c,0x62,0x6b,0x41,0x39,0x4f,0x6b,0x39,0x79, | ||
305 | 0x58,0x54,0x6b,0x57,0x44,0x32,0x4d,0x53,0x45,0x68,0x55,0x36,0x63,0x41,0x31,0x58, | ||
306 | 0x47,0x41,0x31,0x65,0x50,0x53,0x4a,0x6f,0x61,0x48,0x78,0x74,0x54,0x77,0x78,0x37, | ||
307 | 0x43,0x53,0x31,0x4b,0x63,0x79,0x42,0x48,0x42,0x31,0x64,0x31,0x58,0x56,0x4e,0x77, | ||
308 | 0x4e,0x43,0x46,0x41,0x56,0x31,0x46,0x65,0x53,0x55,0x51,0x41,0x56,0x43,0x63,0x45, | ||
309 | 0x61,0x48,0x35,0x5a,0x56,0x6c,0x68,0x30,0x46,0x44,0x77,0x57,0x4d,0x30,0x45,0x57, | ||
310 | 0x53,0x79,0x39,0x4a,0x4e,0x77,0x70,0x55,0x43,0x41,0x67,0x66,0x4f,0x57,0x64,0x32, | ||
311 | 0x4b,0x43,0x67,0x48,0x48,0x57,0x46,0x48,0x55,0x55,0x31,0x31,0x4a,0x6c,0x4a,0x48, | ||
312 | 0x52,0x77,0x78,0x58,0x57,0x48,0x51,0x2b,0x59,0x6d,0x78,0x59,0x4f,0x6b,0x51,0x65, | ||
313 | 0x46,0x69,0x34,0x68,0x48,0x48,0x4e,0x46,0x5a,0x33,0x52,0x50,0x4d,0x32,0x59,0x4f, | ||
314 | 0x64,0x47,0x59,0x6d,0x48,0x79,0x34,0x34,0x52,0x45,0x42,0x2b,0x4b,0x6c,0x42,0x53, | ||
315 | 0x58,0x6b,0x4d,0x42,0x65,0x6a,0x68,0x4a,0x50,0x46,0x56,0x4e,0x57,0x6b,0x51,0x49, | ||
316 | 0x4a,0x6c,0x6c,0x4e,0x52,0x51,0x74,0x49,0x43,0x6a,0x4e,0x65,0x53,0x6b,0x31,0x31, | ||
317 | 0x46,0x68,0x64,0x6a,0x52,0x67,0x45,0x71,0x56,0x58,0x73,0x50,0x41,0x6e,0x4e,0x71, | ||
318 | 0x53,0x33,0x39,0x31,0x5a,0x54,0x78,0x4d,0x4d,0x7a,0x6c,0x73,0x64,0x41,0x56,0x67, | ||
319 | 0x44,0x33,0x38,0x74,0x51,0x55,0x31,0x4e,0x52,0x6e,0x45,0x4a,0x62,0x30,0x39,0x67, | ||
320 | 0x46,0x51,0x39,0x47,0x63,0x32,0x4e,0x4d,0x58,0x6e,0x51,0x77,0x44,0x53,0x68,0x44, | ||
321 | 0x43,0x48,0x49,0x79,0x42,0x43,0x34,0x78,0x4b,0x53,0x64,0x45,0x62,0x52,0x4d,0x58, | ||
322 | 0x53,0x41,0x39,0x4a,0x55,0x68,0x41,0x54,0x66,0x78,0x63,0x57,0x59,0x6e,0x6b,0x31, | ||
323 | 0x65,0x44,0x34,0x42,0x66,0x43,0x34,0x50,0x64,0x6a,0x35,0x65,0x55,0x32,0x78,0x62, | ||
324 | 0x58,0x33,0x77,0x5a,0x51,0x51,0x49,0x76,0x46,0x32,0x52,0x42,0x64,0x52,0x41,0x45, | ||
325 | 0x52,0x33,0x77,0x39,0x53,0x31,0x49,0x41,0x45,0x46,0x31,0x52,0x54,0x6e,0x6f,0x6e, | ||
326 | 0x4a,0x56,0x56,0x41,0x45,0x6a,0x56,0x67,0x42,0x52,0x73,0x30,0x4c,0x51,0x52,0x36, | ||
327 | 0x61,0x6d,0x6b,0x43,0x65,0x51,0x4d,0x36,0x4c,0x77,0x59,0x4b,0x65,0x58,0x73,0x53, | ||
328 | 0x58,0x58,0x78,0x53,0x4b,0x55,0x64,0x59,0x45,0x6e,0x4d,0x2f,0x4a,0x31,0x59,0x46, | ||
329 | 0x44,0x45,0x67,0x79,0x57,0x47,0x74,0x58,0x58,0x41,0x4e,0x6b,0x56,0x68,0x46,0x53, | ||
330 | 0x65,0x6a,0x41,0x32,0x4b,0x52,0x63,0x37,0x61,0x48,0x70,0x38,0x42,0x57,0x74,0x72, | ||
331 | 0x45,0x32,0x6f,0x6b,0x58,0x47,0x68,0x43,0x47,0x44,0x49,0x44,0x63,0x32,0x34,0x45, | ||
332 | 0x49,0x53,0x34,0x42,0x42,0x47,0x4e,0x39,0x52,0x45,0x45,0x53,0x4d,0x51,0x73,0x56, | ||
333 | 0x48,0x33,0x41,0x41,0x4c,0x6d,0x59,0x55,0x50,0x48,0x38,0x72,0x41,0x42,0x38,0x4d, | ||
334 | 0x4b,0x46,0x6b,0x4b,0x46,0x6b,0x6c,0x61,0x58,0x47,0x52,0x6c,0x53,0x78,0x45,0x70, | ||
335 | 0x46,0x54,0x5a,0x61,0x5a,0x52,0x6c,0x50,0x59,0x43,0x4d,0x36,0x4f,0x68,0x4d,0x6c, | ||
336 | 0x41,0x6e,0x68,0x4d,0x56,0x41,0x3d,0x3d,0x00 | ||
337 | }; | ||
338 | char *b64_test; | 294 | char *b64_test; |
339 | 295 | ||
340 | plan_tests(1); | 296 | plan_tests(1); |
341 | 297 | ||
342 | base64_encode_alloc (random, 1024, &b64_test); | 298 | base64_encode_alloc(random, 1024, &b64_test); |
343 | 299 | ||
344 | ok(strcmp(b64_known, b64_test) == 0, | 300 | ok(strcmp(b64_known, b64_test) == 0, "Test matching a base64 encoded 1024 bytes random string"); |
345 | "Test matching a base64 encoded 1024 bytes random string"); | ||
346 | 301 | ||
347 | return exit_status(); | 302 | return exit_status(); |
348 | } | 303 | } |
349 | |||
diff --git a/lib/tests/test_cmd.c b/lib/tests/test_cmd.c index 02ae11f..c8867df 100644 --- a/lib/tests/test_cmd.c +++ b/lib/tests/test_cmd.c | |||
@@ -1,20 +1,20 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * This program is free software: you can redistribute it and/or modify | 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 | 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 | 5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. | 6 | * (at your option) any later version. |
7 | * | 7 | * |
8 | * This program is distributed in the hope that it will be useful, | 8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. | 11 | * GNU General Public License for more details. |
12 | * | 12 | * |
13 | * You should have received a copy of the GNU General Public License | 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/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | * | 15 | * |
16 | * | 16 | * |
17 | *****************************************************************************/ | 17 | *****************************************************************************/ |
18 | 18 | ||
19 | #include "common.h" | 19 | #include "common.h" |
20 | #include "utils_cmd.h" | 20 | #include "utils_cmd.h" |
@@ -22,27 +22,23 @@ | |||
22 | #include "tap.h" | 22 | #include "tap.h" |
23 | 23 | ||
24 | #define COMMAND_LINE 1024 | 24 | #define COMMAND_LINE 1024 |
25 | #define UNSET 65530 | 25 | #define UNSET 65530 |
26 | 26 | ||
27 | char * | 27 | char *get_command(char *const *line) { |
28 | get_command (char *const *line) | ||
29 | { | ||
30 | char *cmd; | 28 | char *cmd; |
31 | int i = 0; | 29 | int i = 0; |
32 | 30 | ||
33 | asprintf (&cmd, " %s", line[i++]); | 31 | asprintf(&cmd, " %s", line[i++]); |
34 | while (line[i] != NULL) { | 32 | while (line[i] != NULL) { |
35 | asprintf (&cmd, "%s %s", cmd, line[i]); | 33 | asprintf(&cmd, "%s %s", cmd, line[i]); |
36 | i++; | 34 | i++; |
37 | } | 35 | } |
38 | 36 | ||
39 | return cmd; | 37 | return cmd; |
40 | } | 38 | } |
41 | 39 | ||
42 | int | 40 | int main(int argc, char **argv) { |
43 | main (int argc, char **argv) | 41 | char **command_line = malloc(sizeof(char *) * COMMAND_LINE); |
44 | { | ||
45 | char **command_line = malloc (sizeof (char *) * COMMAND_LINE); | ||
46 | char *command = NULL; | 42 | char *command = NULL; |
47 | char *perl; | 43 | char *perl; |
48 | output chld_out, chld_err; | 44 | output chld_out, chld_err; |
@@ -51,183 +47,154 @@ main (int argc, char **argv) | |||
51 | 47 | ||
52 | plan_tests(51); | 48 | plan_tests(51); |
53 | 49 | ||
54 | diag ("Running plain echo command, set one"); | 50 | diag("Running plain echo command, set one"); |
55 | 51 | ||
56 | /* ensure everything is empty before we begin */ | 52 | /* ensure everything is empty before we begin */ |
57 | memset (&chld_out, 0, sizeof (output)); | 53 | memset(&chld_out, 0, sizeof(output)); |
58 | memset (&chld_err, 0, sizeof (output)); | 54 | memset(&chld_err, 0, sizeof(output)); |
59 | ok (chld_out.lines == 0, "(initialised) Checking stdout is reset"); | 55 | ok(chld_out.lines == 0, "(initialised) Checking stdout is reset"); |
60 | ok (chld_err.lines == 0, "(initialised) Checking stderr is reset"); | 56 | ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); |
61 | ok (result == UNSET, "(initialised) Checking exit code is reset"); | 57 | ok(result == UNSET, "(initialised) Checking exit code is reset"); |
62 | 58 | ||
63 | command_line[0] = strdup ("/bin/echo"); | 59 | command_line[0] = strdup("/bin/echo"); |
64 | command_line[1] = strdup ("this"); | 60 | command_line[1] = strdup("this"); |
65 | command_line[2] = strdup ("is"); | 61 | command_line[2] = strdup("is"); |
66 | command_line[3] = strdup ("test"); | 62 | command_line[3] = strdup("test"); |
67 | command_line[4] = strdup ("one"); | 63 | command_line[4] = strdup("one"); |
68 | 64 | ||
69 | command = get_command (command_line); | 65 | command = get_command(command_line); |
70 | 66 | ||
71 | result = cmd_run_array (command_line, &chld_out, &chld_err, 0); | 67 | result = cmd_run_array(command_line, &chld_out, &chld_err, 0); |
72 | ok (chld_out.lines == 1, | 68 | ok(chld_out.lines == 1, "(array) Check for expected number of stdout lines"); |
73 | "(array) Check for expected number of stdout lines"); | 69 | ok(chld_err.lines == 0, "(array) Check for expected number of stderr lines"); |
74 | ok (chld_err.lines == 0, | 70 | ok(strcmp(chld_out.line[0], "this is test one") == 0, "(array) Check for expected stdout output"); |
75 | "(array) Check for expected number of stderr lines"); | 71 | ok(result == 0, "(array) Checking exit code"); |
76 | ok (strcmp (chld_out.line[0], "this is test one") == 0, | ||
77 | "(array) Check for expected stdout output"); | ||
78 | ok (result == 0, "(array) Checking exit code"); | ||
79 | 72 | ||
80 | /* ensure everything is empty again */ | 73 | /* ensure everything is empty again */ |
81 | memset (&chld_out, 0, sizeof (output)); | 74 | memset(&chld_out, 0, sizeof(output)); |
82 | memset (&chld_err, 0, sizeof (output)); | 75 | memset(&chld_err, 0, sizeof(output)); |
83 | result = UNSET; | 76 | result = UNSET; |
84 | ok (chld_out.lines == 0, "(initialised) Checking stdout is reset"); | 77 | ok(chld_out.lines == 0, "(initialised) Checking stdout is reset"); |
85 | ok (chld_err.lines == 0, "(initialised) Checking stderr is reset"); | 78 | ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); |
86 | ok (result == UNSET, "(initialised) Checking exit code is reset"); | 79 | ok(result == UNSET, "(initialised) Checking exit code is reset"); |
87 | 80 | ||
88 | result = cmd_run (command, &chld_out, &chld_err, 0); | 81 | result = cmd_run(command, &chld_out, &chld_err, 0); |
89 | 82 | ||
90 | ok (chld_out.lines == 1, | 83 | ok(chld_out.lines == 1, "(string) Check for expected number of stdout lines"); |
91 | "(string) Check for expected number of stdout lines"); | 84 | ok(chld_err.lines == 0, "(string) Check for expected number of stderr lines"); |
92 | ok (chld_err.lines == 0, | 85 | ok(strcmp(chld_out.line[0], "this is test one") == 0, "(string) Check for expected stdout output"); |
93 | "(string) Check for expected number of stderr lines"); | 86 | ok(result == 0, "(string) Checking exit code"); |
94 | ok (strcmp (chld_out.line[0], "this is test one") == 0, | ||
95 | "(string) Check for expected stdout output"); | ||
96 | ok (result == 0, "(string) Checking exit code"); | ||
97 | 87 | ||
98 | diag ("Running plain echo command, set two"); | 88 | diag("Running plain echo command, set two"); |
99 | 89 | ||
100 | /* ensure everything is empty again */ | 90 | /* ensure everything is empty again */ |
101 | memset (&chld_out, 0, sizeof (output)); | 91 | memset(&chld_out, 0, sizeof(output)); |
102 | memset (&chld_err, 0, sizeof (output)); | 92 | memset(&chld_err, 0, sizeof(output)); |
103 | result = UNSET; | 93 | result = UNSET; |
104 | ok (chld_out.lines == 0, "(initialised) Checking stdout is reset"); | 94 | ok(chld_out.lines == 0, "(initialised) Checking stdout is reset"); |
105 | ok (chld_err.lines == 0, "(initialised) Checking stderr is reset"); | 95 | ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); |
106 | ok (result == UNSET, "(initialised) Checking exit code is reset"); | 96 | ok(result == UNSET, "(initialised) Checking exit code is reset"); |
107 | 97 | ||
108 | command_line[0] = strdup ("/bin/echo"); | 98 | command_line[0] = strdup("/bin/echo"); |
109 | command_line[1] = strdup ("this is test two"); | 99 | command_line[1] = strdup("this is test two"); |
110 | command_line[2] = NULL; | 100 | command_line[2] = NULL; |
111 | command_line[3] = NULL; | 101 | command_line[3] = NULL; |
112 | command_line[4] = NULL; | 102 | command_line[4] = NULL; |
113 | 103 | ||
114 | result = cmd_run_array (command_line, &chld_out, &chld_err, 0); | 104 | result = cmd_run_array(command_line, &chld_out, &chld_err, 0); |
115 | ok (chld_out.lines == 1, | 105 | ok(chld_out.lines == 1, "(array) Check for expected number of stdout lines"); |
116 | "(array) Check for expected number of stdout lines"); | 106 | ok(chld_err.lines == 0, "(array) Check for expected number of stderr lines"); |
117 | ok (chld_err.lines == 0, | 107 | ok(strcmp(chld_out.line[0], "this is test two") == 0, "(array) Check for expected stdout output"); |
118 | "(array) Check for expected number of stderr lines"); | 108 | ok(result == 0, "(array) Checking exit code"); |
119 | ok (strcmp (chld_out.line[0], "this is test two") == 0, | ||
120 | "(array) Check for expected stdout output"); | ||
121 | ok (result == 0, "(array) Checking exit code"); | ||
122 | 109 | ||
123 | /* ensure everything is empty again */ | 110 | /* ensure everything is empty again */ |
124 | memset (&chld_out, 0, sizeof (output)); | 111 | memset(&chld_out, 0, sizeof(output)); |
125 | memset (&chld_err, 0, sizeof (output)); | 112 | memset(&chld_err, 0, sizeof(output)); |
126 | result = UNSET; | 113 | result = UNSET; |
127 | ok (chld_out.lines == 0, "(initialised) Checking stdout is reset"); | 114 | ok(chld_out.lines == 0, "(initialised) Checking stdout is reset"); |
128 | ok (chld_err.lines == 0, "(initialised) Checking stderr is reset"); | 115 | ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); |
129 | ok (result == UNSET, "(initialised) Checking exit code is reset"); | 116 | ok(result == UNSET, "(initialised) Checking exit code is reset"); |
130 | |||
131 | result = cmd_run (command, &chld_out, &chld_err, 0); | ||
132 | 117 | ||
133 | ok (chld_out.lines == 1, | 118 | result = cmd_run(command, &chld_out, &chld_err, 0); |
134 | "(string) Check for expected number of stdout lines"); | ||
135 | ok (chld_err.lines == 0, | ||
136 | "(string) Check for expected number of stderr lines"); | ||
137 | ok (strcmp (chld_out.line[0], "this is test one") == 0, | ||
138 | "(string) Check for expected stdout output"); | ||
139 | ok (result == 0, "(string) Checking exit code"); | ||
140 | 119 | ||
120 | ok(chld_out.lines == 1, "(string) Check for expected number of stdout lines"); | ||
121 | ok(chld_err.lines == 0, "(string) Check for expected number of stderr lines"); | ||
122 | ok(strcmp(chld_out.line[0], "this is test one") == 0, "(string) Check for expected stdout output"); | ||
123 | ok(result == 0, "(string) Checking exit code"); | ||
141 | 124 | ||
142 | /* ensure everything is empty again */ | 125 | /* ensure everything is empty again */ |
143 | memset (&chld_out, 0, sizeof (output)); | 126 | memset(&chld_out, 0, sizeof(output)); |
144 | memset (&chld_err, 0, sizeof (output)); | 127 | memset(&chld_err, 0, sizeof(output)); |
145 | result = UNSET; | 128 | result = UNSET; |
146 | ok (chld_out.lines == 0, "(initialised) Checking stdout is reset"); | 129 | ok(chld_out.lines == 0, "(initialised) Checking stdout is reset"); |
147 | ok (chld_err.lines == 0, "(initialised) Checking stderr is reset"); | 130 | ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); |
148 | ok (result == UNSET, "(initialised) Checking exit code is reset"); | 131 | ok(result == UNSET, "(initialised) Checking exit code is reset"); |
149 | 132 | ||
150 | /* Pass linefeeds via parameters through - those should be evaluated by echo to give multi line output */ | 133 | /* Pass linefeeds via parameters through - those should be evaluated by echo to give multi line output */ |
151 | command_line[0] = strdup("/bin/echo"); | 134 | command_line[0] = strdup("/bin/echo"); |
152 | command_line[1] = strdup("this is a test via echo\nline two\nit's line 3"); | 135 | command_line[1] = strdup("this is a test via echo\nline two\nit's line 3"); |
153 | command_line[2] = strdup("and (note space between '3' and 'and') $$ will not get evaluated"); | 136 | command_line[2] = strdup("and (note space between '3' and 'and') $$ will not get evaluated"); |
154 | 137 | ||
155 | result = cmd_run_array (command_line, &chld_out, &chld_err, 0); | 138 | result = cmd_run_array(command_line, &chld_out, &chld_err, 0); |
156 | ok (chld_out.lines == 3, | 139 | ok(chld_out.lines == 3, "(array) Check for expected number of stdout lines"); |
157 | "(array) Check for expected number of stdout lines"); | 140 | ok(chld_err.lines == 0, "(array) Check for expected number of stderr lines"); |
158 | ok (chld_err.lines == 0, | 141 | ok(strcmp(chld_out.line[0], "this is a test via echo") == 0, "(array) Check line 1 for expected stdout output"); |
159 | "(array) Check for expected number of stderr lines"); | 142 | ok(strcmp(chld_out.line[1], "line two") == 0, "(array) Check line 2 for expected stdout output"); |
160 | ok (strcmp (chld_out.line[0], "this is a test via echo") == 0, | 143 | ok(strcmp(chld_out.line[2], "it's line 3 and (note space between '3' and 'and') $$ will not get evaluated") == 0, |
161 | "(array) Check line 1 for expected stdout output"); | 144 | "(array) Check line 3 for expected stdout output"); |
162 | ok (strcmp (chld_out.line[1], "line two") == 0, | 145 | ok(result == 0, "(array) Checking exit code"); |
163 | "(array) Check line 2 for expected stdout output"); | ||
164 | ok (strcmp (chld_out.line[2], "it's line 3 and (note space between '3' and 'and') $$ will not get evaluated") == 0, | ||
165 | "(array) Check line 3 for expected stdout output"); | ||
166 | ok (result == 0, "(array) Checking exit code"); | ||
167 | |||
168 | |||
169 | 146 | ||
170 | /* ensure everything is empty again */ | 147 | /* ensure everything is empty again */ |
171 | memset (&chld_out, 0, sizeof (output)); | 148 | memset(&chld_out, 0, sizeof(output)); |
172 | memset (&chld_err, 0, sizeof (output)); | 149 | memset(&chld_err, 0, sizeof(output)); |
173 | result = UNSET; | 150 | result = UNSET; |
174 | ok (chld_out.lines == 0, "(initialised) Checking stdout is reset"); | 151 | ok(chld_out.lines == 0, "(initialised) Checking stdout is reset"); |
175 | ok (chld_err.lines == 0, "(initialised) Checking stderr is reset"); | 152 | ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); |
176 | ok (result == UNSET, "(initialised) Checking exit code is reset"); | 153 | ok(result == UNSET, "(initialised) Checking exit code is reset"); |
177 | 154 | ||
178 | command = (char *)malloc(COMMAND_LINE); | 155 | command = (char *)malloc(COMMAND_LINE); |
179 | strcpy(command, "/bin/echo3456 non-existent command"); | 156 | strcpy(command, "/bin/echo3456 non-existent command"); |
180 | result = cmd_run (command, &chld_out, &chld_err, 0); | 157 | result = cmd_run(command, &chld_out, &chld_err, 0); |
181 | |||
182 | ok (chld_out.lines == 0, | ||
183 | "Non existent command, so no output"); | ||
184 | ok (chld_err.lines == 0, | ||
185 | "No stderr either"); | ||
186 | ok (result == 3, "Get return code 3 (?) for non-existent command"); | ||
187 | 158 | ||
159 | ok(chld_out.lines == 0, "Non existent command, so no output"); | ||
160 | ok(chld_err.lines == 0, "No stderr either"); | ||
161 | ok(result == 3, "Get return code 3 (?) for non-existent command"); | ||
188 | 162 | ||
189 | /* ensure everything is empty again */ | 163 | /* ensure everything is empty again */ |
190 | memset (&chld_out, 0, sizeof (output)); | 164 | memset(&chld_out, 0, sizeof(output)); |
191 | memset (&chld_err, 0, sizeof (output)); | 165 | memset(&chld_err, 0, sizeof(output)); |
192 | result = UNSET; | 166 | result = UNSET; |
193 | 167 | ||
194 | command = (char *)malloc(COMMAND_LINE); | 168 | command = (char *)malloc(COMMAND_LINE); |
195 | strcpy(command, "/bin/sh non-existent-file"); | 169 | strcpy(command, "/bin/sh non-existent-file"); |
196 | result = cmd_run (command, &chld_out, &chld_err, 0); | 170 | result = cmd_run(command, &chld_out, &chld_err, 0); |
197 | |||
198 | ok (chld_out.lines == 0, | ||
199 | "/bin/sh returns no stdout when file is missing..."); | ||
200 | ok (chld_err.lines == 1, | ||
201 | "...but does give an error line"); | ||
202 | ok (strstr(chld_err.line[0],"non-existent-file") != NULL, "And missing filename is in error message"); | ||
203 | ok (result != 0, "Get non-zero return code from /bin/sh"); | ||
204 | 171 | ||
172 | ok(chld_out.lines == 0, "/bin/sh returns no stdout when file is missing..."); | ||
173 | ok(chld_err.lines == 1, "...but does give an error line"); | ||
174 | ok(strstr(chld_err.line[0], "non-existent-file") != NULL, "And missing filename is in error message"); | ||
175 | ok(result != 0, "Get non-zero return code from /bin/sh"); | ||
205 | 176 | ||
206 | /* ensure everything is empty again */ | 177 | /* ensure everything is empty again */ |
207 | result = UNSET; | 178 | result = UNSET; |
208 | 179 | ||
209 | command = (char *)malloc(COMMAND_LINE); | 180 | command = (char *)malloc(COMMAND_LINE); |
210 | strcpy(command, "/bin/sh -c 'exit 7'"); | 181 | strcpy(command, "/bin/sh -c 'exit 7'"); |
211 | result = cmd_run (command, NULL, NULL, 0); | 182 | result = cmd_run(command, NULL, NULL, 0); |
212 | |||
213 | ok (result == 7, "Get return code 7 from /bin/sh"); | ||
214 | 183 | ||
184 | ok(result == 7, "Get return code 7 from /bin/sh"); | ||
215 | 185 | ||
216 | /* ensure everything is empty again */ | 186 | /* ensure everything is empty again */ |
217 | memset (&chld_out, 0, sizeof (output)); | 187 | memset(&chld_out, 0, sizeof(output)); |
218 | memset (&chld_err, 0, sizeof (output)); | 188 | memset(&chld_err, 0, sizeof(output)); |
219 | result = UNSET; | 189 | result = UNSET; |
220 | 190 | ||
221 | command = (char *)malloc(COMMAND_LINE); | 191 | command = (char *)malloc(COMMAND_LINE); |
222 | strcpy(command, "/bin/non-existent-command"); | 192 | strcpy(command, "/bin/non-existent-command"); |
223 | result = cmd_run (command, &chld_out, &chld_err, 0); | 193 | result = cmd_run(command, &chld_out, &chld_err, 0); |
224 | |||
225 | ok (chld_out.lines == 0, | ||
226 | "/bin/non-existent-command returns no stdout..."); | ||
227 | ok (chld_err.lines == 0, | ||
228 | "...and no stderr output either"); | ||
229 | ok (result == 3, "Get return code 3 = UNKNOWN when command does not exist"); | ||
230 | 194 | ||
195 | ok(chld_out.lines == 0, "/bin/non-existent-command returns no stdout..."); | ||
196 | ok(chld_err.lines == 0, "...and no stderr output either"); | ||
197 | ok(result == 3, "Get return code 3 = UNKNOWN when command does not exist"); | ||
231 | 198 | ||
232 | return exit_status (); | 199 | return exit_status(); |
233 | } | 200 | } |
diff --git a/lib/tests/test_disk.c b/lib/tests/test_disk.c index e283fe2..c18db7a 100644 --- a/lib/tests/test_disk.c +++ b/lib/tests/test_disk.c | |||
@@ -1,36 +1,31 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * This program is free software: you can redistribute it and/or modify | 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 | 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 | 5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. | 6 | * (at your option) any later version. |
7 | * | 7 | * |
8 | * This program is distributed in the hope that it will be useful, | 8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. | 11 | * GNU General Public License for more details. |
12 | * | 12 | * |
13 | * You should have received a copy of the GNU General Public License | 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/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | * | 15 | * |
16 | * | 16 | * |
17 | *****************************************************************************/ | 17 | *****************************************************************************/ |
18 | 18 | ||
19 | #include "common.h" | 19 | #include "common.h" |
20 | #include "utils_disk.h" | 20 | #include "utils_disk.h" |
21 | #include "tap.h" | 21 | #include "tap.h" |
22 | #include "regex.h" | 22 | #include "regex.h" |
23 | 23 | ||
24 | void np_test_mount_entry_regex (struct mount_entry *dummy_mount_list, | 24 | void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc); |
25 | char *regstr, int cflags, int expect, | ||
26 | char *desc); | ||
27 | 25 | ||
28 | 26 | int main(int argc, char **argv) { | |
29 | int | 27 | struct name_list *exclude_filesystem = NULL; |
30 | main (int argc, char **argv) | 28 | struct name_list *exclude_fstype = NULL; |
31 | { | ||
32 | struct name_list *exclude_filesystem=NULL; | ||
33 | struct name_list *exclude_fstype=NULL; | ||
34 | struct name_list *dummy_mountlist = NULL; | 29 | struct name_list *dummy_mountlist = NULL; |
35 | struct name_list *temp_name; | 30 | struct name_list *temp_name; |
36 | struct parameter_list *paths = NULL; | 31 | struct parameter_list *paths = NULL; |
@@ -44,19 +39,19 @@ main (int argc, char **argv) | |||
44 | 39 | ||
45 | plan_tests(33); | 40 | plan_tests(33); |
46 | 41 | ||
47 | ok( np_find_name(exclude_filesystem, "/var/log") == false, "/var/log not in list"); | 42 | ok(np_find_name(exclude_filesystem, "/var/log") == false, "/var/log not in list"); |
48 | np_add_name(&exclude_filesystem, "/var/log"); | 43 | np_add_name(&exclude_filesystem, "/var/log"); |
49 | ok( np_find_name(exclude_filesystem, "/var/log") == true, "is in list now"); | 44 | ok(np_find_name(exclude_filesystem, "/var/log") == true, "is in list now"); |
50 | ok( np_find_name(exclude_filesystem, "/home") == false, "/home not in list"); | 45 | ok(np_find_name(exclude_filesystem, "/home") == false, "/home not in list"); |
51 | np_add_name(&exclude_filesystem, "/home"); | 46 | np_add_name(&exclude_filesystem, "/home"); |
52 | ok( np_find_name(exclude_filesystem, "/home") == true, "is in list now"); | 47 | ok(np_find_name(exclude_filesystem, "/home") == true, "is in list now"); |
53 | ok( np_find_name(exclude_filesystem, "/var/log") == true, "/var/log still in list"); | 48 | ok(np_find_name(exclude_filesystem, "/var/log") == true, "/var/log still in list"); |
54 | 49 | ||
55 | ok( np_find_name(exclude_fstype, "iso9660") == false, "iso9660 not in list"); | 50 | ok(np_find_name(exclude_fstype, "iso9660") == false, "iso9660 not in list"); |
56 | np_add_name(&exclude_fstype, "iso9660"); | 51 | np_add_name(&exclude_fstype, "iso9660"); |
57 | ok( np_find_name(exclude_fstype, "iso9660") == true, "is in list now"); | 52 | ok(np_find_name(exclude_fstype, "iso9660") == true, "is in list now"); |
58 | 53 | ||
59 | ok( np_find_name(exclude_filesystem, "iso9660") == false, "Make sure no clashing in variables"); | 54 | ok(np_find_name(exclude_filesystem, "iso9660") == false, "Make sure no clashing in variables"); |
60 | 55 | ||
61 | /* | 56 | /* |
62 | for (temp_name = exclude_filesystem; temp_name; temp_name = temp_name->next) { | 57 | for (temp_name = exclude_filesystem; temp_name; temp_name = temp_name->next) { |
@@ -64,55 +59,35 @@ main (int argc, char **argv) | |||
64 | } | 59 | } |
65 | */ | 60 | */ |
66 | 61 | ||
67 | me = (struct mount_entry *) malloc(sizeof *me); | 62 | me = (struct mount_entry *)malloc(sizeof *me); |
68 | me->me_devname = strdup("/dev/c0t0d0s0"); | 63 | me->me_devname = strdup("/dev/c0t0d0s0"); |
69 | me->me_mountdir = strdup("/"); | 64 | me->me_mountdir = strdup("/"); |
70 | *mtail = me; | 65 | *mtail = me; |
71 | mtail = &me->me_next; | 66 | mtail = &me->me_next; |
72 | 67 | ||
73 | me = (struct mount_entry *) malloc(sizeof *me); | 68 | me = (struct mount_entry *)malloc(sizeof *me); |
74 | me->me_devname = strdup("/dev/c1t0d1s0"); | 69 | me->me_devname = strdup("/dev/c1t0d1s0"); |
75 | me->me_mountdir = strdup("/var"); | 70 | me->me_mountdir = strdup("/var"); |
76 | *mtail = me; | 71 | *mtail = me; |
77 | mtail = &me->me_next; | 72 | mtail = &me->me_next; |
78 | 73 | ||
79 | me = (struct mount_entry *) malloc(sizeof *me); | 74 | me = (struct mount_entry *)malloc(sizeof *me); |
80 | me->me_devname = strdup("/dev/c2t0d0s0"); | 75 | me->me_devname = strdup("/dev/c2t0d0s0"); |
81 | me->me_mountdir = strdup("/home"); | 76 | me->me_mountdir = strdup("/home"); |
82 | *mtail = me; | 77 | *mtail = me; |
83 | mtail = &me->me_next; | 78 | mtail = &me->me_next; |
84 | 79 | ||
85 | np_test_mount_entry_regex(dummy_mount_list, strdup("/"), | 80 | np_test_mount_entry_regex(dummy_mount_list, strdup("/"), cflags, 3, strdup("a")); |
86 | cflags, 3, strdup("a")); | 81 | np_test_mount_entry_regex(dummy_mount_list, strdup("/dev"), cflags, 3, strdup("regex on dev names:")); |
87 | np_test_mount_entry_regex(dummy_mount_list, strdup("/dev"), | 82 | np_test_mount_entry_regex(dummy_mount_list, strdup("/foo"), cflags, 0, strdup("regex on non existent dev/path:")); |
88 | cflags, 3,strdup("regex on dev names:")); | 83 | np_test_mount_entry_regex(dummy_mount_list, strdup("/Foo"), cflags | REG_ICASE, 0, strdup("regi on non existent dev/path:")); |
89 | np_test_mount_entry_regex(dummy_mount_list, strdup("/foo"), | 84 | np_test_mount_entry_regex(dummy_mount_list, strdup("/c.t0"), cflags, 3, strdup("partial devname regex match:")); |
90 | cflags, 0, | 85 | np_test_mount_entry_regex(dummy_mount_list, strdup("c0t0"), cflags, 1, strdup("partial devname regex match:")); |
91 | strdup("regex on non existent dev/path:")); | 86 | np_test_mount_entry_regex(dummy_mount_list, strdup("C0t0"), cflags | REG_ICASE, 1, strdup("partial devname regi match:")); |
92 | np_test_mount_entry_regex(dummy_mount_list, strdup("/Foo"), | 87 | np_test_mount_entry_regex(dummy_mount_list, strdup("home"), cflags, 1, strdup("partial pathname regex match:")); |
93 | cflags | REG_ICASE,0, | 88 | np_test_mount_entry_regex(dummy_mount_list, strdup("hOme"), cflags | REG_ICASE, 1, strdup("partial pathname regi match:")); |
94 | strdup("regi on non existent dev/path:")); | 89 | np_test_mount_entry_regex(dummy_mount_list, strdup("(/home)|(/var)"), cflags, 2, strdup("grouped regex pathname match:")); |
95 | np_test_mount_entry_regex(dummy_mount_list, strdup("/c.t0"), | 90 | np_test_mount_entry_regex(dummy_mount_list, strdup("(/homE)|(/Var)"), cflags | REG_ICASE, 2, strdup("grouped regi pathname match:")); |
96 | cflags, 3, | ||
97 | strdup("partial devname regex match:")); | ||
98 | np_test_mount_entry_regex(dummy_mount_list, strdup("c0t0"), | ||
99 | cflags, 1, | ||
100 | strdup("partial devname regex match:")); | ||
101 | np_test_mount_entry_regex(dummy_mount_list, strdup("C0t0"), | ||
102 | cflags | REG_ICASE, 1, | ||
103 | strdup("partial devname regi match:")); | ||
104 | np_test_mount_entry_regex(dummy_mount_list, strdup("home"), | ||
105 | cflags, 1, | ||
106 | strdup("partial pathname regex match:")); | ||
107 | np_test_mount_entry_regex(dummy_mount_list, strdup("hOme"), | ||
108 | cflags | REG_ICASE, 1, | ||
109 | strdup("partial pathname regi match:")); | ||
110 | np_test_mount_entry_regex(dummy_mount_list, strdup("(/home)|(/var)"), | ||
111 | cflags, 2, | ||
112 | strdup("grouped regex pathname match:")); | ||
113 | np_test_mount_entry_regex(dummy_mount_list, strdup("(/homE)|(/Var)"), | ||
114 | cflags | REG_ICASE, 2, | ||
115 | strdup("grouped regi pathname match:")); | ||
116 | 91 | ||
117 | np_add_parameter(&paths, "/home/groups"); | 92 | np_add_parameter(&paths, "/home/groups"); |
118 | np_add_parameter(&paths, "/var"); | 93 | np_add_parameter(&paths, "/var"); |
@@ -124,20 +99,20 @@ main (int argc, char **argv) | |||
124 | for (p = paths; p; p = p->name_next) { | 99 | for (p = paths; p; p = p->name_next) { |
125 | struct mount_entry *temp_me; | 100 | struct mount_entry *temp_me; |
126 | temp_me = p->best_match; | 101 | temp_me = p->best_match; |
127 | if (! strcmp(p->name, "/home/groups")) { | 102 | if (!strcmp(p->name, "/home/groups")) { |
128 | ok( temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/groups got right best match: /home"); | 103 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/groups got right best match: /home"); |
129 | } else if (! strcmp(p->name, "/var")) { | 104 | } else if (!strcmp(p->name, "/var")) { |
130 | ok( temp_me && !strcmp(temp_me->me_mountdir, "/var"), "/var got right best match: /var"); | 105 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/var"), "/var got right best match: /var"); |
131 | } else if (! strcmp(p->name, "/tmp")) { | 106 | } else if (!strcmp(p->name, "/tmp")) { |
132 | ok( temp_me && !strcmp(temp_me->me_mountdir, "/"), "/tmp got right best match: /"); | 107 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/"), "/tmp got right best match: /"); |
133 | } else if (! strcmp(p->name, "/home/tonvoon")) { | 108 | } else if (!strcmp(p->name, "/home/tonvoon")) { |
134 | ok( temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/tonvoon got right best match: /home"); | 109 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/tonvoon got right best match: /home"); |
135 | } else if (! strcmp(p->name, "/dev/c2t0d0s0")) { | 110 | } else if (!strcmp(p->name, "/dev/c2t0d0s0")) { |
136 | ok( temp_me && !strcmp(temp_me->me_devname, "/dev/c2t0d0s0"), "/dev/c2t0d0s0 got right best match: /dev/c2t0d0s0"); | 111 | ok(temp_me && !strcmp(temp_me->me_devname, "/dev/c2t0d0s0"), "/dev/c2t0d0s0 got right best match: /dev/c2t0d0s0"); |
137 | } | 112 | } |
138 | } | 113 | } |
139 | 114 | ||
140 | paths = NULL; /* Bad boy - should free, but this is a test suite */ | 115 | paths = NULL; /* Bad boy - should free, but this is a test suite */ |
141 | np_add_parameter(&paths, "/home/groups"); | 116 | np_add_parameter(&paths, "/home/groups"); |
142 | np_add_parameter(&paths, "/var"); | 117 | np_add_parameter(&paths, "/var"); |
143 | np_add_parameter(&paths, "/tmp"); | 118 | np_add_parameter(&paths, "/tmp"); |
@@ -146,31 +121,31 @@ main (int argc, char **argv) | |||
146 | 121 | ||
147 | np_set_best_match(paths, dummy_mount_list, true); | 122 | np_set_best_match(paths, dummy_mount_list, true); |
148 | for (p = paths; p; p = p->name_next) { | 123 | for (p = paths; p; p = p->name_next) { |
149 | if (! strcmp(p->name, "/home/groups")) { | 124 | if (!strcmp(p->name, "/home/groups")) { |
150 | ok( ! p->best_match , "/home/groups correctly not found"); | 125 | ok(!p->best_match, "/home/groups correctly not found"); |
151 | } else if (! strcmp(p->name, "/var")) { | 126 | } else if (!strcmp(p->name, "/var")) { |
152 | ok( p->best_match, "/var found"); | 127 | ok(p->best_match, "/var found"); |
153 | } else if (! strcmp(p->name, "/tmp")) { | 128 | } else if (!strcmp(p->name, "/tmp")) { |
154 | ok(! p->best_match, "/tmp correctly not found"); | 129 | ok(!p->best_match, "/tmp correctly not found"); |
155 | } else if (! strcmp(p->name, "/home/tonvoon")) { | 130 | } else if (!strcmp(p->name, "/home/tonvoon")) { |
156 | ok(! p->best_match, "/home/tonvoon not found"); | 131 | ok(!p->best_match, "/home/tonvoon not found"); |
157 | } else if (! strcmp(p->name, "/home")) { | 132 | } else if (!strcmp(p->name, "/home")) { |
158 | ok( p->best_match, "/home found"); | 133 | ok(p->best_match, "/home found"); |
159 | } | 134 | } |
160 | } | 135 | } |
161 | 136 | ||
162 | /* test deleting first element in paths */ | 137 | /* test deleting first element in paths */ |
163 | paths = np_del_parameter(paths, NULL); | 138 | paths = np_del_parameter(paths, NULL); |
164 | for (p = paths; p; p = p->name_next) { | 139 | for (p = paths; p; p = p->name_next) { |
165 | if (! strcmp(p->name, "/home/groups")) | 140 | if (!strcmp(p->name, "/home/groups")) |
166 | found = 1; | 141 | found = 1; |
167 | } | 142 | } |
168 | ok(found == 0, "first element successfully deleted"); | 143 | ok(found == 0, "first element successfully deleted"); |
169 | found = 0; | 144 | found = 0; |
170 | 145 | ||
171 | p=paths; | 146 | p = paths; |
172 | while (p) { | 147 | while (p) { |
173 | if (! strcmp(p->name, "/tmp")) | 148 | if (!strcmp(p->name, "/tmp")) |
174 | p = np_del_parameter(p, prev); | 149 | p = np_del_parameter(p, prev); |
175 | else { | 150 | else { |
176 | prev = p; | 151 | prev = p; |
@@ -179,7 +154,7 @@ main (int argc, char **argv) | |||
179 | } | 154 | } |
180 | 155 | ||
181 | for (p = paths; p; p = p->name_next) { | 156 | for (p = paths; p; p = p->name_next) { |
182 | if (! strcmp(p->name, "/tmp")) | 157 | if (!strcmp(p->name, "/tmp")) |
183 | found = 1; | 158 | found = 1; |
184 | if (p->name_next) | 159 | if (p->name_next) |
185 | prev = p; | 160 | prev = p; |
@@ -190,7 +165,7 @@ main (int argc, char **argv) | |||
190 | 165 | ||
191 | p = np_del_parameter(last, prev); | 166 | p = np_del_parameter(last, prev); |
192 | for (p = paths; p; p = p->name_next) { | 167 | for (p = paths; p; p = p->name_next) { |
193 | if (! strcmp(p->name, "/home")) | 168 | if (!strcmp(p->name, "/home")) |
194 | found = 1; | 169 | found = 1; |
195 | last = p; | 170 | last = p; |
196 | count++; | 171 | count++; |
@@ -198,27 +173,20 @@ main (int argc, char **argv) | |||
198 | ok(found == 0, "last (/home) element successfully deleted"); | 173 | ok(found == 0, "last (/home) element successfully deleted"); |
199 | ok(count == 2, "two elements remaining"); | 174 | ok(count == 2, "two elements remaining"); |
200 | 175 | ||
201 | |||
202 | return exit_status(); | 176 | return exit_status(); |
203 | } | 177 | } |
204 | 178 | ||
205 | 179 | void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc) { | |
206 | void | ||
207 | np_test_mount_entry_regex (struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc) | ||
208 | { | ||
209 | int matches = 0; | 180 | int matches = 0; |
210 | regex_t re; | 181 | regex_t re; |
211 | struct mount_entry *me; | 182 | struct mount_entry *me; |
212 | if (regcomp(&re,regstr, cflags) == 0) { | 183 | if (regcomp(&re, regstr, cflags) == 0) { |
213 | for (me = dummy_mount_list; me; me= me->me_next) { | 184 | for (me = dummy_mount_list; me; me = me->me_next) { |
214 | if(np_regex_match_mount_entry(me,&re)) | 185 | if (np_regex_match_mount_entry(me, &re)) |
215 | matches++; | 186 | matches++; |
216 | } | 187 | } |
217 | ok( matches == expect, | 188 | ok(matches == expect, "%s '%s' matched %i/3 entries. ok: %i/3", desc, regstr, expect, matches); |
218 | "%s '%s' matched %i/3 entries. ok: %i/3", | ||
219 | desc, regstr, expect, matches); | ||
220 | 189 | ||
221 | } else | 190 | } else |
222 | ok ( false, "regex '%s' not compilable", regstr); | 191 | ok(false, "regex '%s' not compilable", regstr); |
223 | } | 192 | } |
224 | |||
diff --git a/lib/tests/test_generic_output b/lib/tests/test_generic_output new file mode 100755 index 0000000..51e299a --- /dev/null +++ b/lib/tests/test_generic_output | |||
Binary files differ | |||
diff --git a/lib/tests/test_ini1.c b/lib/tests/test_ini1.c index 6843bac..246c125 100644 --- a/lib/tests/test_ini1.c +++ b/lib/tests/test_ini1.c | |||
@@ -1,20 +1,20 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * This program is free software: you can redistribute it and/or modify | 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 | 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 | 5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. | 6 | * (at your option) any later version. |
7 | * | 7 | * |
8 | * This program is distributed in the hope that it will be useful, | 8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. | 11 | * GNU General Public License for more details. |
12 | * | 12 | * |
13 | * You should have received a copy of the GNU General Public License | 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/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | * | 15 | * |
16 | * | 16 | * |
17 | *****************************************************************************/ | 17 | *****************************************************************************/ |
18 | 18 | ||
19 | #include "common.h" | 19 | #include "common.h" |
20 | #include "utils_base.h" | 20 | #include "utils_base.h" |
@@ -29,81 +29,93 @@ void my_free(char *string) { | |||
29 | } | 29 | } |
30 | } | 30 | } |
31 | 31 | ||
32 | char* | 32 | char *list2str(np_arg_list *optlst) { |
33 | list2str(np_arg_list *optlst) | 33 | char *optstr = NULL; |
34 | { | ||
35 | char *optstr=NULL; | ||
36 | np_arg_list *optltmp; | 34 | np_arg_list *optltmp; |
37 | 35 | ||
38 | /* Put everything as a space-separated string */ | 36 | /* Put everything as a space-separated string */ |
39 | asprintf(&optstr, ""); | 37 | asprintf(&optstr, ""); |
40 | while (optlst) { | 38 | while (optlst) { |
41 | asprintf(&optstr, "%s%s ", optstr, optlst->arg); | 39 | asprintf(&optstr, "%s%s ", optstr, optlst->arg); |
42 | optltmp=optlst; | 40 | optltmp = optlst; |
43 | optlst=optlst->next; | 41 | optlst = optlst->next; |
44 | free(optltmp); | 42 | free(optltmp); |
45 | } | 43 | } |
46 | /* Strip last whitespace */ | 44 | /* Strip last whitespace */ |
47 | if (strlen(optstr)>1) optstr[strlen(optstr)-1]='\0'; | 45 | if (strlen(optstr) > 1) |
46 | optstr[strlen(optstr) - 1] = '\0'; | ||
48 | 47 | ||
49 | return optstr; | 48 | return optstr; |
50 | } | 49 | } |
51 | 50 | ||
52 | int | 51 | int main(int argc, char **argv) { |
53 | main (int argc, char **argv) | 52 | char *optstr = NULL; |
54 | { | ||
55 | char *optstr=NULL; | ||
56 | 53 | ||
57 | plan_tests(12); | 54 | plan_tests(12); |
58 | 55 | ||
59 | optstr=list2str(np_get_defaults("section@./config-tiny.ini", "check_disk")); | 56 | optstr = list2str(np_get_defaults("section@./config-tiny.ini", "check_disk")); |
60 | ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "config-tiny.ini's section as expected"); | 57 | ok(!strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "config-tiny.ini's section as expected"); |
61 | my_free(optstr); | 58 | my_free(optstr); |
62 | 59 | ||
63 | optstr=list2str(np_get_defaults("@./config-tiny.ini", "section")); | 60 | optstr = list2str(np_get_defaults("@./config-tiny.ini", "section")); |
64 | ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "Used default section name, without specific"); | 61 | ok(!strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "Used default section name, without specific"); |
65 | my_free(optstr); | 62 | my_free(optstr); |
66 | 63 | ||
67 | optstr=list2str(np_get_defaults("Section Two@./config-tiny.ini", "check_disk")); | 64 | optstr = list2str(np_get_defaults("Section Two@./config-tiny.ini", "check_disk")); |
68 | ok( !strcmp(optstr, "--something else=blah --remove=whitespace"), "config-tiny.ini's Section Two as expected"); | 65 | ok(!strcmp(optstr, "--something else=blah --remove=whitespace"), "config-tiny.ini's Section Two as expected"); |
69 | my_free(optstr); | 66 | my_free(optstr); |
70 | 67 | ||
71 | optstr=list2str(np_get_defaults("/path/to/file.txt@./config-tiny.ini", "check_disk")); | 68 | optstr = list2str(np_get_defaults("/path/to/file.txt@./config-tiny.ini", "check_disk")); |
72 | ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's filename as section name"); | 69 | ok(!strcmp(optstr, "--this=that"), "config-tiny.ini's filename as section name"); |
73 | my_free(optstr); | 70 | my_free(optstr); |
74 | 71 | ||
75 | optstr=list2str(np_get_defaults("section2@./config-tiny.ini", "check_disk")); | 72 | optstr = list2str(np_get_defaults("section2@./config-tiny.ini", "check_disk")); |
76 | ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's section2 with whitespace before section name"); | 73 | ok(!strcmp(optstr, "--this=that"), "config-tiny.ini's section2 with whitespace before section name"); |
77 | my_free(optstr); | 74 | my_free(optstr); |
78 | 75 | ||
79 | optstr=list2str(np_get_defaults("section3@./config-tiny.ini", "check_disk")); | 76 | optstr = list2str(np_get_defaults("section3@./config-tiny.ini", "check_disk")); |
80 | ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's section3 with whitespace after section name"); | 77 | ok(!strcmp(optstr, "--this=that"), "config-tiny.ini's section3 with whitespace after section name"); |
81 | my_free(optstr); | 78 | my_free(optstr); |
82 | 79 | ||
83 | optstr=list2str(np_get_defaults("check_mysql@./plugin.ini", "check_disk")); | 80 | optstr = list2str(np_get_defaults("check_mysql@./plugin.ini", "check_disk")); |
84 | ok( !strcmp(optstr, "--username=operator --password=secret"), "plugin.ini's check_mysql as expected"); | 81 | ok(!strcmp(optstr, "--username=operator --password=secret"), "plugin.ini's check_mysql as expected"); |
85 | my_free(optstr); | 82 | my_free(optstr); |
86 | 83 | ||
87 | optstr=list2str(np_get_defaults("check_mysql2@./plugin.ini", "check_disk")); | 84 | optstr = list2str(np_get_defaults("check_mysql2@./plugin.ini", "check_disk")); |
88 | ok( !strcmp(optstr, "-u=admin -p=secret"), "plugin.ini's check_mysql2 as expected"); | 85 | ok(!strcmp(optstr, "-u=admin -p=secret"), "plugin.ini's check_mysql2 as expected"); |
89 | my_free(optstr); | 86 | my_free(optstr); |
90 | 87 | ||
91 | optstr=list2str(np_get_defaults("check space_and_flags@./plugin.ini", "check_disk")); | 88 | optstr = list2str(np_get_defaults("check space_and_flags@./plugin.ini", "check_disk")); |
92 | ok( !strcmp(optstr, "--foo=bar -a -b --bar"), "plugin.ini space in stanza and flag arguments"); | 89 | ok(!strcmp(optstr, "--foo=bar -a -b --bar"), "plugin.ini space in stanza and flag arguments"); |
93 | my_free(optstr); | 90 | my_free(optstr); |
94 | 91 | ||
95 | optstr=list2str(np_get_defaults("Section Two@./config-dos.ini", "check_disk")); | 92 | optstr = list2str(np_get_defaults("Section Two@./config-dos.ini", "check_disk")); |
96 | ok( !strcmp(optstr, "--something else=blah --remove=whitespace"), "config-dos.ini's Section Two as expected"); | 93 | ok(!strcmp(optstr, "--something else=blah --remove=whitespace"), "config-dos.ini's Section Two as expected"); |
97 | my_free(optstr); | 94 | my_free(optstr); |
98 | 95 | ||
99 | optstr=list2str(np_get_defaults("section_twice@./plugin.ini", "check_disk")); | 96 | optstr = list2str(np_get_defaults("section_twice@./plugin.ini", "check_disk")); |
100 | ok( !strcmp(optstr, "--foo=bar --bar=foo"), "plugin.ini's section_twice defined twice in the file"); | 97 | ok(!strcmp(optstr, "--foo=bar --bar=foo"), "plugin.ini's section_twice defined twice in the file"); |
101 | my_free(optstr); | 98 | my_free(optstr); |
102 | 99 | ||
103 | optstr=list2str(np_get_defaults("tcp_long_lines@plugins.ini", "check_tcp")); | 100 | optstr = list2str(np_get_defaults("tcp_long_lines@plugins.ini", "check_tcp")); |
104 | ok( !strcmp(optstr, "--escape --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 --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 --jail"), "Long options"); | 101 | ok(!strcmp(optstr, "--escape --send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar " |
102 | "BAZ yadda yadda yadda Foo bar BAZ yadda yadda " | ||
103 | "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda " | ||
104 | "yadda yadda Foo bar BAZ yadda yadda yadda Foo " | ||
105 | "bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda " | ||
106 | "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ " | ||
107 | "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda --expect=Foo bar BAZ yadda yadda " | ||
108 | "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ " | ||
109 | "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo " | ||
110 | "bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda " | ||
111 | "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda " | ||
112 | "yadda yadda Foo bar BAZ yadda yadda yadda Foo " | ||
113 | "bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda " | ||
114 | "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ " | ||
115 | "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo " | ||
116 | "bar BAZ yadda yadda yadda --jail"), | ||
117 | "Long options"); | ||
105 | my_free(optstr); | 118 | my_free(optstr); |
106 | 119 | ||
107 | return exit_status(); | 120 | return exit_status(); |
108 | } | 121 | } |
109 | |||
diff --git a/lib/tests/test_ini3.c b/lib/tests/test_ini3.c index 8a2a041..2186e4b 100644 --- a/lib/tests/test_ini3.c +++ b/lib/tests/test_ini3.c | |||
@@ -1,26 +1,24 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * This program is free software: you can redistribute it and/or modify | 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 | 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 | 5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. | 6 | * (at your option) any later version. |
7 | * | 7 | * |
8 | * This program is distributed in the hope that it will be useful, | 8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. | 11 | * GNU General Public License for more details. |
12 | * | 12 | * |
13 | * You should have received a copy of the GNU General Public License | 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/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | * | 15 | * |
16 | * | 16 | * |
17 | *****************************************************************************/ | 17 | *****************************************************************************/ |
18 | 18 | ||
19 | #include "parse_ini.h" | 19 | #include "parse_ini.h" |
20 | 20 | ||
21 | int | 21 | int main(int argc, char **argv) { |
22 | main (int argc, char **argv) | ||
23 | { | ||
24 | 22 | ||
25 | /* | 23 | /* |
26 | * This is for testing arguments expected to die. | 24 | * This is for testing arguments expected to die. |
@@ -30,4 +28,3 @@ main (int argc, char **argv) | |||
30 | 28 | ||
31 | return 0; | 29 | return 0; |
32 | } | 30 | } |
33 | |||
diff --git a/lib/tests/test_opts1.c b/lib/tests/test_opts1.c index 077c5b6..984183d 100644 --- a/lib/tests/test_opts1.c +++ b/lib/tests/test_opts1.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * This program is free software: you can redistribute it and/or modify | 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 | 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 | 5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. | 6 | * (at your option) any later version. |
7 | * | 7 | * |
8 | * This program is distributed in the hope that it will be useful, | 8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. | 11 | * GNU General Public License for more details. |
12 | * | 12 | * |
13 | * You should have received a copy of the GNU General Public License | 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/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | * | 15 | * |
16 | *****************************************************************************/ | 16 | *****************************************************************************/ |
17 | 17 | ||
18 | #include "common.h" | 18 | #include "common.h" |
19 | #include "utils_base.h" | 19 | #include "utils_base.h" |
@@ -40,23 +40,24 @@ void my_free(int *argc, char **newargv, char **argv) { | |||
40 | #else | 40 | #else |
41 | void my_free(int *argc, char **newargv, char **argv) { | 41 | void my_free(int *argc, char **newargv, char **argv) { |
42 | /* Free stuff (and print while we're at it) */ | 42 | /* Free stuff (and print while we're at it) */ |
43 | int i, freeflag=1; | 43 | int i, freeflag = 1; |
44 | printf (" Arg(%i): ", *argc+1); | 44 | printf(" Arg(%i): ", *argc + 1); |
45 | printf ("'%s' ", newargv[0]); | 45 | printf("'%s' ", newargv[0]); |
46 | for (i=1; i<*argc; i++) { | 46 | for (i = 1; i < *argc; i++) { |
47 | printf ("'%s' ", newargv[i]); | 47 | printf("'%s' ", newargv[i]); |
48 | /* Stop freeing when we get to the start of the original array */ | 48 | /* Stop freeing when we get to the start of the original array */ |
49 | if (freeflag) { | 49 | if (freeflag) { |
50 | if (newargv[i] == argv[1]) | 50 | if (newargv[i] == argv[1]) |
51 | freeflag=0; | 51 | freeflag = 0; |
52 | else | 52 | else |
53 | free(newargv[i]); | 53 | free(newargv[i]); |
54 | } | 54 | } |
55 | } | 55 | } |
56 | printf ("\n"); | 56 | printf("\n"); |
57 | /* Free only if it's a different array */ | 57 | /* Free only if it's a different array */ |
58 | if (newargv != argv) free(newargv); | 58 | if (newargv != argv) |
59 | *argc=0; | 59 | free(newargv); |
60 | *argc = 0; | ||
60 | } | 61 | } |
61 | #endif | 62 | #endif |
62 | 63 | ||
@@ -67,9 +68,10 @@ int array_diff(int i1, char **a1, int i2, char **a2) { | |||
67 | printf(" Argument count doesn't match!\n"); | 68 | printf(" Argument count doesn't match!\n"); |
68 | return 0; | 69 | return 0; |
69 | } | 70 | } |
70 | for (i=0; i<=i1; i++) { | 71 | for (i = 0; i <= i1; i++) { |
71 | if (a1[i]==NULL && a2[i]==NULL) continue; | 72 | if (a1[i] == NULL && a2[i] == NULL) |
72 | if (a1[i]==NULL || a2[i]==NULL) { | 73 | continue; |
74 | if (a1[i] == NULL || a2[i] == NULL) { | ||
73 | printf(" Argument # %i null in one array!\n", i); | 75 | printf(" Argument # %i null in one array!\n", i); |
74 | return 0; | 76 | return 0; |
75 | } | 77 | } |
@@ -81,59 +83,58 @@ int array_diff(int i1, char **a1, int i2, char **a2) { | |||
81 | return 1; | 83 | return 1; |
82 | } | 84 | } |
83 | 85 | ||
84 | int | 86 | int main(int argc, char **argv) { |
85 | main (int argc, char **argv) | 87 | char **argv_new = NULL; |
86 | { | ||
87 | char **argv_new=NULL; | ||
88 | int i, argc_test; | 88 | int i, argc_test; |
89 | 89 | ||
90 | plan_tests(5); | 90 | plan_tests(5); |
91 | 91 | ||
92 | { | 92 | { |
93 | char *argv_test[] = {"prog_name", (char *) NULL}; | 93 | char *argv_test[] = {"prog_name", (char *)NULL}; |
94 | argc_test=1; | 94 | argc_test = 1; |
95 | char *argv_known[] = {"prog_name", (char *) NULL}; | 95 | char *argv_known[] = {"prog_name", (char *)NULL}; |
96 | argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); | 96 | argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); |
97 | ok(array_diff(argc_test, argv_new, 1, argv_known), "No opts, returns correct argv/argc"); | 97 | ok(array_diff(argc_test, argv_new, 1, argv_known), "No opts, returns correct argv/argc"); |
98 | my_free(&argc_test, argv_new, argv_test); | 98 | my_free(&argc_test, argv_new, argv_test); |
99 | } | 99 | } |
100 | 100 | ||
101 | { | 101 | { |
102 | char *argv_test[] = {"prog_name", "arg1", "--arg2=val1", "--arg3", "val2", (char *) NULL}; | 102 | char *argv_test[] = {"prog_name", "arg1", "--arg2=val1", "--arg3", "val2", (char *)NULL}; |
103 | argc_test=5; | 103 | argc_test = 5; |
104 | char *argv_known[] = {"prog_name", "arg1", "--arg2=val1", "--arg3", "val2", (char *) NULL}; | 104 | char *argv_known[] = {"prog_name", "arg1", "--arg2=val1", "--arg3", "val2", (char *)NULL}; |
105 | argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); | 105 | argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); |
106 | ok(array_diff(argc_test, argv_new, 5, argv_known), "No extra opts, verbatim copy of argv"); | 106 | ok(array_diff(argc_test, argv_new, 5, argv_known), "No extra opts, verbatim copy of argv"); |
107 | my_free(&argc_test, argv_new, argv_test); | 107 | my_free(&argc_test, argv_new, argv_test); |
108 | } | 108 | } |
109 | 109 | ||
110 | { | 110 | { |
111 | char *argv_test[] = {"prog_name", "--extra-opts=@./config-opts.ini", (char *) NULL}; | 111 | char *argv_test[] = {"prog_name", "--extra-opts=@./config-opts.ini", (char *)NULL}; |
112 | argc_test=2; | 112 | argc_test = 2; |
113 | char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank", (char *) NULL}; | 113 | char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank", (char *)NULL}; |
114 | argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); | 114 | argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); |
115 | ok(array_diff(argc_test, argv_new, 4, argv_known), "Only extra opts using default section"); | 115 | ok(array_diff(argc_test, argv_new, 4, argv_known), "Only extra opts using default section"); |
116 | my_free(&argc_test, argv_new, argv_test); | 116 | my_free(&argc_test, argv_new, argv_test); |
117 | } | 117 | } |
118 | 118 | ||
119 | { | 119 | { |
120 | char *argv_test[] = {"prog_name", "--extra-opts=sect1@./config-opts.ini", "--extra-opts", "sect2@./config-opts.ini", (char *) NULL}; | 120 | char *argv_test[] = {"prog_name", "--extra-opts=sect1@./config-opts.ini", "--extra-opts", "sect2@./config-opts.ini", (char *)NULL}; |
121 | argc_test=4; | 121 | argc_test = 4; |
122 | char *argv_known[] = {"prog_name", "--one=two", "--something else=oops", "--this=that", (char *) NULL}; | 122 | char *argv_known[] = {"prog_name", "--one=two", "--something else=oops", "--this=that", (char *)NULL}; |
123 | argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); | 123 | argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); |
124 | ok(array_diff(argc_test, argv_new, 4, argv_known), "Only extra opts specified twice"); | 124 | ok(array_diff(argc_test, argv_new, 4, argv_known), "Only extra opts specified twice"); |
125 | my_free(&argc_test, argv_new, argv_test); | 125 | my_free(&argc_test, argv_new, argv_test); |
126 | } | 126 | } |
127 | 127 | ||
128 | { | 128 | { |
129 | char *argv_test[] = {"prog_name", "--arg1=val1", "--extra-opts=@./config-opts.ini", "--extra-opts", "sect1@./config-opts.ini", "--arg2", (char *) NULL}; | 129 | char *argv_test[] = {"prog_name", "--arg1=val1", "--extra-opts=@./config-opts.ini", "--extra-opts", "sect1@./config-opts.ini", |
130 | argc_test=6; | 130 | "--arg2", (char *)NULL}; |
131 | char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank", "--one=two", "--arg1=val1", "--arg2", (char *) NULL}; | 131 | argc_test = 6; |
132 | argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); | 132 | char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank", "--one=two", |
133 | "--arg1=val1", "--arg2", (char *)NULL}; | ||
134 | argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); | ||
133 | ok(array_diff(argc_test, argv_new, 7, argv_known), "twice extra opts using two sections"); | 135 | ok(array_diff(argc_test, argv_new, 7, argv_known), "twice extra opts using two sections"); |
134 | my_free(&argc_test, argv_new, argv_test); | 136 | my_free(&argc_test, argv_new, argv_test); |
135 | } | 137 | } |
136 | 138 | ||
137 | return exit_status(); | 139 | return exit_status(); |
138 | } | 140 | } |
139 | |||
diff --git a/lib/tests/test_opts2.c b/lib/tests/test_opts2.c index 780220e..2349661 100644 --- a/lib/tests/test_opts2.c +++ b/lib/tests/test_opts2.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * This program is free software: you can redistribute it and/or modify | 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 | 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 | 5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. | 6 | * (at your option) any later version. |
7 | * | 7 | * |
8 | * This program is distributed in the hope that it will be useful, | 8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. | 11 | * GNU General Public License for more details. |
12 | * | 12 | * |
13 | * You should have received a copy of the GNU General Public License | 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/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | * | 15 | * |
16 | *****************************************************************************/ | 16 | *****************************************************************************/ |
17 | 17 | ||
18 | #include "common.h" | 18 | #include "common.h" |
19 | #include "utils_base.h" | 19 | #include "utils_base.h" |
@@ -23,23 +23,24 @@ | |||
23 | 23 | ||
24 | void my_free(int *argc, char **newargv, char **argv) { | 24 | void my_free(int *argc, char **newargv, char **argv) { |
25 | /* Free stuff (and print while we're at it) */ | 25 | /* Free stuff (and print while we're at it) */ |
26 | int i, freeflag=1; | 26 | int i, freeflag = 1; |
27 | printf (" Arg(%i): ", *argc+1); | 27 | printf(" Arg(%i): ", *argc + 1); |
28 | printf ("'%s' ", newargv[0]); | 28 | printf("'%s' ", newargv[0]); |
29 | for (i=1; i<*argc; i++) { | 29 | for (i = 1; i < *argc; i++) { |
30 | printf ("'%s' ", newargv[i]); | 30 | printf("'%s' ", newargv[i]); |
31 | /* Stop freeing when we get to the start of the original array */ | 31 | /* Stop freeing when we get to the start of the original array */ |
32 | if (freeflag) { | 32 | if (freeflag) { |
33 | if (newargv[i] == argv[1]) | 33 | if (newargv[i] == argv[1]) |
34 | freeflag=0; | 34 | freeflag = 0; |
35 | else | 35 | else |
36 | free(newargv[i]); | 36 | free(newargv[i]); |
37 | } | 37 | } |
38 | } | 38 | } |
39 | printf ("\n"); | 39 | printf("\n"); |
40 | /* Free only if it's a different array */ | 40 | /* Free only if it's a different array */ |
41 | if (newargv != argv) free(newargv); | 41 | if (newargv != argv) |
42 | *argc=0; | 42 | free(newargv); |
43 | *argc = 0; | ||
43 | } | 44 | } |
44 | 45 | ||
45 | int array_diff(int i1, char **a1, int i2, char **a2) { | 46 | int array_diff(int i1, char **a1, int i2, char **a2) { |
@@ -49,9 +50,10 @@ int array_diff(int i1, char **a1, int i2, char **a2) { | |||
49 | printf(" Argument count doesn't match!\n"); | 50 | printf(" Argument count doesn't match!\n"); |
50 | return 0; | 51 | return 0; |
51 | } | 52 | } |
52 | for (i=0; i<=i1; i++) { | 53 | for (i = 0; i <= i1; i++) { |
53 | if (a1[i]==NULL && a2[i]==NULL) continue; | 54 | if (a1[i] == NULL && a2[i] == NULL) |
54 | if (a1[i]==NULL || a2[i]==NULL) { | 55 | continue; |
56 | if (a1[i] == NULL || a2[i] == NULL) { | ||
55 | printf(" Argument # %i null in one array!\n", i); | 57 | printf(" Argument # %i null in one array!\n", i); |
56 | return 0; | 58 | return 0; |
57 | } | 59 | } |
@@ -63,59 +65,77 @@ int array_diff(int i1, char **a1, int i2, char **a2) { | |||
63 | return 1; | 65 | return 1; |
64 | } | 66 | } |
65 | 67 | ||
66 | int | 68 | int main(int argc, char **argv) { |
67 | main (int argc, char **argv) | 69 | char **argv_new = NULL; |
68 | { | ||
69 | char **argv_new=NULL; | ||
70 | int i, argc_test; | 70 | int i, argc_test; |
71 | 71 | ||
72 | plan_tests(5); | 72 | plan_tests(5); |
73 | 73 | ||
74 | { | 74 | { |
75 | char *argv_test[] = {"prog_name", "arg1", "--extra-opts", "--arg3", "val2", (char *) NULL}; | 75 | char *argv_test[] = {"prog_name", "arg1", "--extra-opts", "--arg3", "val2", (char *)NULL}; |
76 | argc_test=5; | 76 | argc_test = 5; |
77 | char *argv_known[] = {"prog_name", "--foo=bar", "arg1", "--arg3", "val2", (char *) NULL}; | 77 | char *argv_known[] = {"prog_name", "--foo=bar", "arg1", "--arg3", "val2", (char *)NULL}; |
78 | argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); | 78 | argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); |
79 | ok(array_diff(argc_test, argv_new, 5, argv_known), "Default section 1"); | 79 | ok(array_diff(argc_test, argv_new, 5, argv_known), "Default section 1"); |
80 | my_free(&argc_test, argv_new, argv_test); | 80 | my_free(&argc_test, argv_new, argv_test); |
81 | } | 81 | } |
82 | 82 | ||
83 | { | 83 | { |
84 | char *argv_test[] = {"prog_name", "--extra-opts", (char *) NULL}; | 84 | char *argv_test[] = {"prog_name", "--extra-opts", (char *)NULL}; |
85 | argc_test=2; | 85 | argc_test = 2; |
86 | char *argv_known[] = {"prog_name", "--foo=bar", (char *) NULL}; | 86 | char *argv_known[] = {"prog_name", "--foo=bar", (char *)NULL}; |
87 | argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); | 87 | argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); |
88 | ok(array_diff(argc_test, argv_new, 2, argv_known), "Default section 2"); | 88 | ok(array_diff(argc_test, argv_new, 2, argv_known), "Default section 2"); |
89 | my_free(&argc_test, argv_new, argv_test); | 89 | my_free(&argc_test, argv_new, argv_test); |
90 | } | 90 | } |
91 | 91 | ||
92 | { | 92 | { |
93 | char *argv_test[] = {"prog_name", "arg1", "--extra-opts=section1", "--arg3", "val2", (char *) NULL}; | 93 | char *argv_test[] = {"prog_name", "arg1", "--extra-opts=section1", "--arg3", "val2", (char *)NULL}; |
94 | argc_test=5; | 94 | argc_test = 5; |
95 | char *argv_known[] = {"prog_name", "--foobar=baz", "arg1", "--arg3", "val2", (char *) NULL}; | 95 | char *argv_known[] = {"prog_name", "--foobar=baz", "arg1", "--arg3", "val2", (char *)NULL}; |
96 | argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); | 96 | argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); |
97 | ok(array_diff(argc_test, argv_new, 5, argv_known), "Default section 3"); | 97 | ok(array_diff(argc_test, argv_new, 5, argv_known), "Default section 3"); |
98 | my_free(&argc_test, argv_new, argv_test); | 98 | my_free(&argc_test, argv_new, argv_test); |
99 | } | 99 | } |
100 | 100 | ||
101 | { | 101 | { |
102 | char *argv_test[] = {"prog_name", "arg1", "--extra-opts", "-arg3", "val2", (char *) NULL}; | 102 | char *argv_test[] = {"prog_name", "arg1", "--extra-opts", "-arg3", "val2", (char *)NULL}; |
103 | argc_test=5; | 103 | argc_test = 5; |
104 | char *argv_known[] = {"prog_name", "--foo=bar", "arg1", "-arg3", "val2", (char *) NULL}; | 104 | char *argv_known[] = {"prog_name", "--foo=bar", "arg1", "-arg3", "val2", (char *)NULL}; |
105 | argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); | 105 | argv_new = np_extra_opts(&argc_test, argv_test, "check_disk"); |
106 | ok(array_diff(argc_test, argv_new, 5, argv_known), "Default section 4"); | 106 | ok(array_diff(argc_test, argv_new, 5, argv_known), "Default section 4"); |
107 | my_free(&argc_test, argv_new, argv_test); | 107 | my_free(&argc_test, argv_new, argv_test); |
108 | } | 108 | } |
109 | 109 | ||
110 | { | 110 | { |
111 | char *argv_test[] = {"check_tcp", "--extra-opts", "--extra-opts=tcp_long_lines", (char *) NULL}; | 111 | char *argv_test[] = {"check_tcp", "--extra-opts", "--extra-opts=tcp_long_lines", (char *)NULL}; |
112 | argc_test=3; | 112 | argc_test = 3; |
113 | char *argv_known[] = {"check_tcp", "--timeout=10", "--escape", "--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", "--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", "--jail", (char *) NULL}; | 113 | char *argv_known[] = { |
114 | argv_new=np_extra_opts(&argc_test, argv_test, "check_tcp"); | 114 | "check_tcp", |
115 | "--timeout=10", | ||
116 | "--escape", | ||
117 | "--send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda " | ||
118 | "yadda Foo bar BAZ yadda " | ||
119 | "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 " | ||
120 | "yadda Foo bar BAZ " | ||
121 | "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 " | ||
122 | "yadda yadda Foo bar " | ||
123 | "BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda", | ||
124 | "--expect=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda " | ||
125 | "yadda Foo bar BAZ yadda " | ||
126 | "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 " | ||
127 | "yadda Foo bar BAZ " | ||
128 | "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 " | ||
129 | "yadda yadda Foo bar " | ||
130 | "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 " | ||
131 | "yadda yadda yadda Foo " | ||
132 | "bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda", | ||
133 | "--jail", | ||
134 | (char *)NULL}; | ||
135 | argv_new = np_extra_opts(&argc_test, argv_test, "check_tcp"); | ||
115 | ok(array_diff(argc_test, argv_new, 6, argv_known), "Long lines test"); | 136 | ok(array_diff(argc_test, argv_new, 6, argv_known), "Long lines test"); |
116 | my_free(&argc_test, argv_new, argv_test); | 137 | my_free(&argc_test, argv_new, argv_test); |
117 | } | 138 | } |
118 | 139 | ||
119 | return exit_status(); | 140 | return exit_status(); |
120 | } | 141 | } |
121 | |||
diff --git a/lib/tests/test_opts3.c b/lib/tests/test_opts3.c index b64270d..cecea43 100644 --- a/lib/tests/test_opts3.c +++ b/lib/tests/test_opts3.c | |||
@@ -1,31 +1,28 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * This program is free software: you can redistribute it and/or modify | 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 | 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 | 5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. | 6 | * (at your option) any later version. |
7 | * | 7 | * |
8 | * This program is distributed in the hope that it will be useful, | 8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. | 11 | * GNU General Public License for more details. |
12 | * | 12 | * |
13 | * You should have received a copy of the GNU General Public License | 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/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | * | 15 | * |
16 | *****************************************************************************/ | 16 | *****************************************************************************/ |
17 | 17 | ||
18 | #include "extra_opts.h" | 18 | #include "extra_opts.h" |
19 | 19 | ||
20 | int | 20 | int main(int argc, char **argv) { |
21 | main (int argc, char **argv) | ||
22 | { | ||
23 | 21 | ||
24 | /* | 22 | /* |
25 | * This is for testing arguments expected to die. | 23 | * This is for testing arguments expected to die. |
26 | */ | 24 | */ |
27 | argv=np_extra_opts(&argc, argv, argv[0]); | 25 | argv = np_extra_opts(&argc, argv, argv[0]); |
28 | 26 | ||
29 | return 0; | 27 | return 0; |
30 | } | 28 | } |
31 | |||
diff --git a/lib/tests/test_tcp.c b/lib/tests/test_tcp.c index 1954b0f..1b3003e 100644 --- a/lib/tests/test_tcp.c +++ b/lib/tests/test_tcp.c | |||
@@ -1,34 +1,32 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * This program is free software: you can redistribute it and/or modify | 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 | 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 | 5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. | 6 | * (at your option) any later version. |
7 | * | 7 | * |
8 | * This program is distributed in the hope that it will be useful, | 8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. | 11 | * GNU General Public License for more details. |
12 | * | 12 | * |
13 | * You should have received a copy of the GNU General Public License | 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/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | * | 15 | * |
16 | * | 16 | * |
17 | *****************************************************************************/ | 17 | *****************************************************************************/ |
18 | 18 | ||
19 | #include "common.h" | 19 | #include "common.h" |
20 | #include "utils_tcp.h" | 20 | #include "utils_tcp.h" |
21 | #include "tap.h" | 21 | #include "tap.h" |
22 | 22 | ||
23 | int | 23 | int main(void) { |
24 | main(void) | ||
25 | { | ||
26 | char **server_expect; | 24 | char **server_expect; |
27 | int server_expect_count = 3; | 25 | int server_expect_count = 3; |
28 | 26 | ||
29 | plan_tests(9); | 27 | plan_tests(9); |
30 | 28 | ||
31 | server_expect = malloc(sizeof(char*) * server_expect_count); | 29 | server_expect = malloc(sizeof(char *) * server_expect_count); |
32 | 30 | ||
33 | server_expect[0] = strdup("AA"); | 31 | server_expect[0] = strdup("AA"); |
34 | server_expect[1] = strdup("bb"); | 32 | server_expect[1] = strdup("bb"); |
@@ -42,17 +40,13 @@ main(void) | |||
42 | "Test matching any string at the beginning (substring match)"); | 40 | "Test matching any string at the beginning (substring match)"); |
43 | ok(np_expect_match("XX bb AA CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_FAILURE, | 41 | ok(np_expect_match("XX bb AA CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_FAILURE, |
44 | "Test with strings not matching at the beginning"); | 42 | "Test with strings not matching at the beginning"); |
45 | ok(np_expect_match("XX CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_FAILURE, | 43 | ok(np_expect_match("XX CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_FAILURE, "Test matching any string"); |
46 | "Test matching any string"); | 44 | ok(np_expect_match("XX", server_expect, server_expect_count, 0) == NP_MATCH_RETRY, "Test not matching any string"); |
47 | ok(np_expect_match("XX", server_expect, server_expect_count, 0) == NP_MATCH_RETRY, | ||
48 | "Test not matching any string"); | ||
49 | ok(np_expect_match("XX AA bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_SUCCESS, | 45 | ok(np_expect_match("XX AA bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_SUCCESS, |
50 | "Test matching all strings"); | 46 | "Test matching all strings"); |
51 | ok(np_expect_match("XX bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_RETRY, | 47 | ok(np_expect_match("XX bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_RETRY, "Test not matching all strings"); |
52 | "Test not matching all strings"); | ||
53 | ok(np_expect_match("XX XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_RETRY, | 48 | ok(np_expect_match("XX XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_RETRY, |
54 | "Test not matching any string (testing all)"); | 49 | "Test not matching any string (testing all)"); |
55 | 50 | ||
56 | |||
57 | return exit_status(); | 51 | return exit_status(); |
58 | } | 52 | } |
diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c index 01afacd..c3150f0 100644 --- a/lib/tests/test_utils.c +++ b/lib/tests/test_utils.c | |||
@@ -1,20 +1,20 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * This program is free software: you can redistribute it and/or modify | 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 | 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 | 5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. | 6 | * (at your option) any later version. |
7 | * | 7 | * |
8 | * This program is distributed in the hope that it will be useful, | 8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. | 11 | * GNU General Public License for more details. |
12 | * | 12 | * |
13 | * You should have received a copy of the GNU General Public License | 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/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | * | 15 | * |
16 | * | 16 | * |
17 | *****************************************************************************/ | 17 | *****************************************************************************/ |
18 | 18 | ||
19 | #include "common.h" | 19 | #include "common.h" |
20 | #include "utils_base.h" | 20 | #include "utils_base.h" |
@@ -27,331 +27,323 @@ | |||
27 | 27 | ||
28 | #include "utils_base.c" | 28 | #include "utils_base.c" |
29 | 29 | ||
30 | int | 30 | int main(int argc, char **argv) { |
31 | main (int argc, char **argv) | ||
32 | { | ||
33 | char state_path[1024]; | 31 | char state_path[1024]; |
34 | range *range; | 32 | range *range; |
35 | double temp; | 33 | double temp; |
36 | thresholds *thresholds = NULL; | 34 | thresholds *thresholds = NULL; |
37 | int i, rc; | 35 | int i, rc; |
38 | char *temp_string; | 36 | char *temp_string; |
39 | state_key *temp_state_key = NULL; | 37 | state_key *temp_state_key = NULL; |
40 | state_data *temp_state_data; | 38 | state_data *temp_state_data; |
41 | time_t current_time; | 39 | time_t current_time; |
42 | 40 | ||
43 | plan_tests(185); | 41 | plan_tests(185); |
44 | 42 | ||
45 | ok( this_monitoring_plugin==NULL, "monitoring_plugin not initialised"); | 43 | ok(this_monitoring_plugin == NULL, "monitoring_plugin not initialised"); |
46 | 44 | ||
47 | np_init( "check_test", argc, argv ); | 45 | np_init("check_test", argc, argv); |
48 | 46 | ||
49 | ok( this_monitoring_plugin!=NULL, "monitoring_plugin now initialised"); | 47 | ok(this_monitoring_plugin != NULL, "monitoring_plugin now initialised"); |
50 | ok( !strcmp(this_monitoring_plugin->plugin_name, "check_test"), "plugin name initialised" ); | 48 | ok(!strcmp(this_monitoring_plugin->plugin_name, "check_test"), "plugin name initialised"); |
51 | 49 | ||
52 | ok( this_monitoring_plugin->argc==argc, "Argc set" ); | 50 | ok(this_monitoring_plugin->argc == argc, "Argc set"); |
53 | ok( this_monitoring_plugin->argv==argv, "Argv set" ); | 51 | ok(this_monitoring_plugin->argv == argv, "Argv set"); |
54 | 52 | ||
55 | np_set_args(0,0); | 53 | np_set_args(0, 0); |
56 | 54 | ||
57 | ok( this_monitoring_plugin->argc==0, "argc changed" ); | 55 | ok(this_monitoring_plugin->argc == 0, "argc changed"); |
58 | ok( this_monitoring_plugin->argv==0, "argv changed" ); | 56 | ok(this_monitoring_plugin->argv == 0, "argv changed"); |
59 | 57 | ||
60 | np_set_args(argc, argv); | 58 | np_set_args(argc, argv); |
61 | 59 | ||
62 | range = parse_range_string("6"); | 60 | range = parse_range_string("6"); |
63 | ok( range != NULL, "'6' is valid range"); | 61 | ok(range != NULL, "'6' is valid range"); |
64 | ok( range->start == 0, "Start correct"); | 62 | ok(range->start == 0, "Start correct"); |
65 | ok( range->start_infinity == false, "Not using negative infinity"); | 63 | ok(range->start_infinity == false, "Not using negative infinity"); |
66 | ok( range->end == 6, "End correct"); | 64 | ok(range->end == 6, "End correct"); |
67 | ok( range->end_infinity == false, "Not using infinity"); | 65 | ok(range->end_infinity == false, "Not using infinity"); |
68 | free(range); | 66 | free(range); |
69 | 67 | ||
70 | range = parse_range_string("1:12%%"); | 68 | range = parse_range_string("1:12%%"); |
71 | ok( range != NULL, "'1:12%%' is valid - percentages are ignored"); | 69 | ok(range != NULL, "'1:12%%' is valid - percentages are ignored"); |
72 | ok( range->start == 1, "Start correct"); | 70 | ok(range->start == 1, "Start correct"); |
73 | ok( range->start_infinity == false, "Not using negative infinity"); | 71 | ok(range->start_infinity == false, "Not using negative infinity"); |
74 | ok( range->end == 12, "End correct"); | 72 | ok(range->end == 12, "End correct"); |
75 | ok( range->end_infinity == false, "Not using infinity"); | 73 | ok(range->end_infinity == false, "Not using infinity"); |
76 | free(range); | 74 | free(range); |
77 | 75 | ||
78 | range = parse_range_string("-7:23"); | 76 | range = parse_range_string("-7:23"); |
79 | ok( range != NULL, "'-7:23' is valid range"); | 77 | ok(range != NULL, "'-7:23' is valid range"); |
80 | ok( range->start == -7, "Start correct"); | 78 | ok(range->start == -7, "Start correct"); |
81 | ok( range->start_infinity == false, "Not using negative infinity"); | 79 | ok(range->start_infinity == false, "Not using negative infinity"); |
82 | ok( range->end == 23, "End correct"); | 80 | ok(range->end == 23, "End correct"); |
83 | ok( range->end_infinity == false, "Not using infinity"); | 81 | ok(range->end_infinity == false, "Not using infinity"); |
84 | free(range); | 82 | free(range); |
85 | 83 | ||
86 | range = parse_range_string(":5.75"); | 84 | range = parse_range_string(":5.75"); |
87 | ok( range != NULL, "':5.75' is valid range"); | 85 | ok(range != NULL, "':5.75' is valid range"); |
88 | ok( range->start == 0, "Start correct"); | 86 | ok(range->start == 0, "Start correct"); |
89 | ok( range->start_infinity == false, "Not using negative infinity"); | 87 | ok(range->start_infinity == false, "Not using negative infinity"); |
90 | ok( range->end == 5.75, "End correct"); | 88 | ok(range->end == 5.75, "End correct"); |
91 | ok( range->end_infinity == false, "Not using infinity"); | 89 | ok(range->end_infinity == false, "Not using infinity"); |
92 | free(range); | 90 | free(range); |
93 | 91 | ||
94 | range = parse_range_string("~:-95.99"); | 92 | range = parse_range_string("~:-95.99"); |
95 | ok( range != NULL, "~:-95.99' is valid range"); | 93 | ok(range != NULL, "~:-95.99' is valid range"); |
96 | ok( range->start_infinity == true, "Using negative infinity"); | 94 | ok(range->start_infinity == true, "Using negative infinity"); |
97 | ok( range->end == -95.99, "End correct (with rounding errors)"); | 95 | ok(range->end == -95.99, "End correct (with rounding errors)"); |
98 | ok( range->end_infinity == false, "Not using infinity"); | 96 | ok(range->end_infinity == false, "Not using infinity"); |
99 | free(range); | 97 | free(range); |
100 | 98 | ||
101 | range = parse_range_string("12345678901234567890:"); | 99 | range = parse_range_string("12345678901234567890:"); |
102 | temp = atof("12345678901234567890"); /* Can't just use this because number too large */ | 100 | temp = atof("12345678901234567890"); /* Can't just use this because number too large */ |
103 | ok( range != NULL, "'12345678901234567890:' is valid range"); | 101 | ok(range != NULL, "'12345678901234567890:' is valid range"); |
104 | ok( range->start == temp, "Start correct"); | 102 | ok(range->start == temp, "Start correct"); |
105 | ok( range->start_infinity == false, "Not using negative infinity"); | 103 | ok(range->start_infinity == false, "Not using negative infinity"); |
106 | ok( range->end_infinity == true, "Using infinity"); | 104 | ok(range->end_infinity == true, "Using infinity"); |
107 | /* Cannot do a "-1" on temp, as it appears to be same value */ | 105 | /* Cannot do a "-1" on temp, as it appears to be same value */ |
108 | ok( check_range(temp/1.1, range) == true, "12345678901234567890/1.1 - alert"); | 106 | ok(check_range(temp / 1.1, range) == true, "12345678901234567890/1.1 - alert"); |
109 | ok( check_range(temp, range) == false, "12345678901234567890 - no alert"); | 107 | ok(check_range(temp, range) == false, "12345678901234567890 - no alert"); |
110 | ok( check_range(temp*2, range) == false, "12345678901234567890*2 - no alert"); | 108 | ok(check_range(temp * 2, range) == false, "12345678901234567890*2 - no alert"); |
111 | free(range); | 109 | free(range); |
112 | 110 | ||
113 | range = parse_range_string("~:0"); | 111 | range = parse_range_string("~:0"); |
114 | ok( range != NULL, "'~:0' is valid range"); | 112 | ok(range != NULL, "'~:0' is valid range"); |
115 | ok( range->start_infinity == true, "Using negative infinity"); | 113 | ok(range->start_infinity == true, "Using negative infinity"); |
116 | ok( range->end == 0, "End correct"); | 114 | ok(range->end == 0, "End correct"); |
117 | ok( range->end_infinity == false, "Not using infinity"); | 115 | ok(range->end_infinity == false, "Not using infinity"); |
118 | ok( range->alert_on == OUTSIDE, "Will alert on outside of this range"); | 116 | ok(range->alert_on == OUTSIDE, "Will alert on outside of this range"); |
119 | ok( check_range(0.5, range) == true, "0.5 - alert"); | 117 | ok(check_range(0.5, range) == true, "0.5 - alert"); |
120 | ok( check_range(-10, range) == false, "-10 - no alert"); | 118 | ok(check_range(-10, range) == false, "-10 - no alert"); |
121 | ok( check_range(0, range) == false, "0 - no alert"); | 119 | ok(check_range(0, range) == false, "0 - no alert"); |
122 | free(range); | 120 | free(range); |
123 | 121 | ||
124 | range = parse_range_string("@0:657.8210567"); | 122 | range = parse_range_string("@0:657.8210567"); |
125 | ok( range != 0, "@0:657.8210567' is a valid range"); | 123 | ok(range != 0, "@0:657.8210567' is a valid range"); |
126 | ok( range->start == 0, "Start correct"); | 124 | ok(range->start == 0, "Start correct"); |
127 | ok( range->start_infinity == false, "Not using negative infinity"); | 125 | ok(range->start_infinity == false, "Not using negative infinity"); |
128 | ok( range->end == 657.8210567, "End correct"); | 126 | ok(range->end == 657.8210567, "End correct"); |
129 | ok( range->end_infinity == false, "Not using infinity"); | 127 | ok(range->end_infinity == false, "Not using infinity"); |
130 | ok( range->alert_on == INSIDE, "Will alert on inside of this range" ); | 128 | ok(range->alert_on == INSIDE, "Will alert on inside of this range"); |
131 | ok( check_range(32.88, range) == true, "32.88 - alert"); | 129 | ok(check_range(32.88, range) == true, "32.88 - alert"); |
132 | ok( check_range(-2, range) == false, "-2 - no alert"); | 130 | ok(check_range(-2, range) == false, "-2 - no alert"); |
133 | ok( check_range(657.8210567, range) == true, "657.8210567 - alert"); | 131 | ok(check_range(657.8210567, range) == true, "657.8210567 - alert"); |
134 | ok( check_range(0, range) == true, "0 - alert"); | 132 | ok(check_range(0, range) == true, "0 - alert"); |
135 | free(range); | 133 | free(range); |
136 | 134 | ||
137 | range = parse_range_string("@1:1"); | 135 | range = parse_range_string("@1:1"); |
138 | ok( range != NULL, "'@1:1' is a valid range"); | 136 | ok(range != NULL, "'@1:1' is a valid range"); |
139 | ok( range->start == 1, "Start correct"); | 137 | ok(range->start == 1, "Start correct"); |
140 | ok( range->start_infinity == false, "Not using negative infinity"); | 138 | ok(range->start_infinity == false, "Not using negative infinity"); |
141 | ok( range->end == 1, "End correct"); | 139 | ok(range->end == 1, "End correct"); |
142 | ok( range->end_infinity == false, "Not using infinity"); | 140 | ok(range->end_infinity == false, "Not using infinity"); |
143 | ok( range->alert_on == INSIDE, "Will alert on inside of this range" ); | 141 | ok(range->alert_on == INSIDE, "Will alert on inside of this range"); |
144 | ok( check_range(0.5, range) == false, "0.5 - no alert"); | 142 | ok(check_range(0.5, range) == false, "0.5 - no alert"); |
145 | ok( check_range(1, range) == true, "1 - alert"); | 143 | ok(check_range(1, range) == true, "1 - alert"); |
146 | ok( check_range(5.2, range) == false, "5.2 - no alert"); | 144 | ok(check_range(5.2, range) == false, "5.2 - no alert"); |
147 | free(range); | 145 | free(range); |
148 | 146 | ||
149 | range = parse_range_string("1:1"); | 147 | range = parse_range_string("1:1"); |
150 | ok( range != NULL, "'1:1' is a valid range"); | 148 | ok(range != NULL, "'1:1' is a valid range"); |
151 | ok( range->start == 1, "Start correct"); | 149 | ok(range->start == 1, "Start correct"); |
152 | ok( range->start_infinity == false, "Not using negative infinity"); | 150 | ok(range->start_infinity == false, "Not using negative infinity"); |
153 | ok( range->end == 1, "End correct"); | 151 | ok(range->end == 1, "End correct"); |
154 | ok( range->end_infinity == false, "Not using infinity"); | 152 | ok(range->end_infinity == false, "Not using infinity"); |
155 | ok( check_range(0.5, range) == true, "0.5 - alert"); | 153 | ok(check_range(0.5, range) == true, "0.5 - alert"); |
156 | ok( check_range(1, range) == false, "1 - no alert"); | 154 | ok(check_range(1, range) == false, "1 - no alert"); |
157 | ok( check_range(5.2, range) == true, "5.2 - alert"); | 155 | ok(check_range(5.2, range) == true, "5.2 - alert"); |
158 | free(range); | 156 | free(range); |
159 | 157 | ||
160 | range = parse_range_string("2:1"); | 158 | range = parse_range_string("2:1"); |
161 | ok( range == NULL, "'2:1' rejected"); | 159 | ok(range == NULL, "'2:1' rejected"); |
162 | 160 | ||
163 | rc = _set_thresholds(&thresholds, NULL, NULL); | 161 | rc = _set_thresholds(&thresholds, NULL, NULL); |
164 | ok( rc == 0, "Thresholds (NULL, NULL) set"); | 162 | ok(rc == 0, "Thresholds (NULL, NULL) set"); |
165 | ok( thresholds->warning == NULL, "Warning not set"); | 163 | ok(thresholds->warning == NULL, "Warning not set"); |
166 | ok( thresholds->critical == NULL, "Critical not set"); | 164 | ok(thresholds->critical == NULL, "Critical not set"); |
167 | 165 | ||
168 | rc = _set_thresholds(&thresholds, NULL, "80"); | 166 | rc = _set_thresholds(&thresholds, NULL, "80"); |
169 | ok( rc == 0, "Thresholds (NULL, '80') set"); | 167 | ok(rc == 0, "Thresholds (NULL, '80') set"); |
170 | ok( thresholds->warning == NULL, "Warning not set"); | 168 | ok(thresholds->warning == NULL, "Warning not set"); |
171 | ok( thresholds->critical->end == 80, "Critical set correctly"); | 169 | ok(thresholds->critical->end == 80, "Critical set correctly"); |
172 | 170 | ||
173 | rc = _set_thresholds(&thresholds, "5:33", NULL); | 171 | rc = _set_thresholds(&thresholds, "5:33", NULL); |
174 | ok( rc == 0, "Thresholds ('5:33', NULL) set"); | 172 | ok(rc == 0, "Thresholds ('5:33', NULL) set"); |
175 | ok( thresholds->warning->start == 5, "Warning start set"); | 173 | ok(thresholds->warning->start == 5, "Warning start set"); |
176 | ok( thresholds->warning->end == 33, "Warning end set"); | 174 | ok(thresholds->warning->end == 33, "Warning end set"); |
177 | ok( thresholds->critical == NULL, "Critical not set"); | 175 | ok(thresholds->critical == NULL, "Critical not set"); |
178 | 176 | ||
179 | rc = _set_thresholds(&thresholds, "30", "60"); | 177 | rc = _set_thresholds(&thresholds, "30", "60"); |
180 | ok( rc == 0, "Thresholds ('30', '60') set"); | 178 | ok(rc == 0, "Thresholds ('30', '60') set"); |
181 | ok( thresholds->warning->end == 30, "Warning set correctly"); | 179 | ok(thresholds->warning->end == 30, "Warning set correctly"); |
182 | ok( thresholds->critical->end == 60, "Critical set correctly"); | 180 | ok(thresholds->critical->end == 60, "Critical set correctly"); |
183 | ok( get_status(15.3, thresholds) == STATE_OK, "15.3 - ok"); | 181 | ok(get_status(15.3, thresholds) == STATE_OK, "15.3 - ok"); |
184 | ok( get_status(30.0001, thresholds) == STATE_WARNING, "30.0001 - warning"); | 182 | ok(get_status(30.0001, thresholds) == STATE_WARNING, "30.0001 - warning"); |
185 | ok( get_status(69, thresholds) == STATE_CRITICAL, "69 - critical"); | 183 | ok(get_status(69, thresholds) == STATE_CRITICAL, "69 - critical"); |
186 | 184 | ||
187 | rc = _set_thresholds(&thresholds, "-10:-2", "-30:20"); | 185 | rc = _set_thresholds(&thresholds, "-10:-2", "-30:20"); |
188 | ok( rc == 0, "Thresholds ('-30:20', '-10:-2') set"); | 186 | ok(rc == 0, "Thresholds ('-30:20', '-10:-2') set"); |
189 | ok( thresholds->warning->start == -10, "Warning start set correctly"); | 187 | ok(thresholds->warning->start == -10, "Warning start set correctly"); |
190 | ok( thresholds->warning->end == -2, "Warning end set correctly"); | 188 | ok(thresholds->warning->end == -2, "Warning end set correctly"); |
191 | ok( thresholds->critical->start == -30, "Critical start set correctly"); | 189 | ok(thresholds->critical->start == -30, "Critical start set correctly"); |
192 | ok( thresholds->critical->end == 20, "Critical end set correctly"); | 190 | ok(thresholds->critical->end == 20, "Critical end set correctly"); |
193 | ok( get_status(-31, thresholds) == STATE_CRITICAL, "-31 - critical"); | 191 | ok(get_status(-31, thresholds) == STATE_CRITICAL, "-31 - critical"); |
194 | ok( get_status(-29, thresholds) == STATE_WARNING, "-29 - warning"); | 192 | ok(get_status(-29, thresholds) == STATE_WARNING, "-29 - warning"); |
195 | ok( get_status(-11, thresholds) == STATE_WARNING, "-11 - warning"); | 193 | ok(get_status(-11, thresholds) == STATE_WARNING, "-11 - warning"); |
196 | ok( get_status(-10, thresholds) == STATE_OK, "-10 - ok"); | 194 | ok(get_status(-10, thresholds) == STATE_OK, "-10 - ok"); |
197 | ok( get_status(-2, thresholds) == STATE_OK, "-2 - ok"); | 195 | ok(get_status(-2, thresholds) == STATE_OK, "-2 - ok"); |
198 | ok( get_status(-1, thresholds) == STATE_WARNING, "-1 - warning"); | 196 | ok(get_status(-1, thresholds) == STATE_WARNING, "-1 - warning"); |
199 | ok( get_status(19, thresholds) == STATE_WARNING, "19 - warning"); | 197 | ok(get_status(19, thresholds) == STATE_WARNING, "19 - warning"); |
200 | ok( get_status(21, thresholds) == STATE_CRITICAL, "21 - critical"); | 198 | ok(get_status(21, thresholds) == STATE_CRITICAL, "21 - critical"); |
201 | 199 | ||
202 | char *test; | 200 | char *test; |
203 | test = np_escaped_string("bob\\n"); | 201 | test = np_escaped_string("bob\\n"); |
204 | ok( strcmp(test, "bob\n") == 0, "bob\\n ok"); | 202 | ok(strcmp(test, "bob\n") == 0, "bob\\n ok"); |
205 | free(test); | 203 | free(test); |
206 | 204 | ||
207 | test = np_escaped_string("rhuba\\rb"); | 205 | test = np_escaped_string("rhuba\\rb"); |
208 | ok( strcmp(test, "rhuba\rb") == 0, "rhuba\\rb okay"); | 206 | ok(strcmp(test, "rhuba\rb") == 0, "rhuba\\rb okay"); |
209 | free(test); | 207 | free(test); |
210 | 208 | ||
211 | test = np_escaped_string("ba\\nge\\r"); | 209 | test = np_escaped_string("ba\\nge\\r"); |
212 | ok( strcmp(test, "ba\nge\r") == 0, "ba\\nge\\r okay"); | 210 | ok(strcmp(test, "ba\nge\r") == 0, "ba\\nge\\r okay"); |
213 | free(test); | 211 | free(test); |
214 | 212 | ||
215 | test = np_escaped_string("\\rabbi\\t"); | 213 | test = np_escaped_string("\\rabbi\\t"); |
216 | ok( strcmp(test, "\rabbi\t") == 0, "\\rabbi\\t okay"); | 214 | ok(strcmp(test, "\rabbi\t") == 0, "\\rabbi\\t okay"); |
217 | free(test); | 215 | free(test); |
218 | 216 | ||
219 | test = np_escaped_string("and\\\\or"); | 217 | test = np_escaped_string("and\\\\or"); |
220 | ok( strcmp(test, "and\\or") == 0, "and\\\\or okay"); | 218 | ok(strcmp(test, "and\\or") == 0, "and\\\\or okay"); |
221 | free(test); | 219 | free(test); |
222 | 220 | ||
223 | test = np_escaped_string("bo\\gus"); | 221 | test = np_escaped_string("bo\\gus"); |
224 | ok( strcmp(test, "bogus") == 0, "bo\\gus okay"); | 222 | ok(strcmp(test, "bogus") == 0, "bo\\gus okay"); |
225 | free(test); | 223 | free(test); |
226 | 224 | ||
227 | test = np_escaped_string("everything"); | 225 | test = np_escaped_string("everything"); |
228 | ok( strcmp(test, "everything") == 0, "everything okay"); | 226 | ok(strcmp(test, "everything") == 0, "everything okay"); |
229 | 227 | ||
230 | /* np_extract_ntpvar tests (23) */ | 228 | /* np_extract_ntpvar tests (23) */ |
231 | test=np_extract_ntpvar("foo=bar, bar=foo, foobar=barfoo\n", "foo"); | 229 | test = np_extract_ntpvar("foo=bar, bar=foo, foobar=barfoo\n", "foo"); |
232 | ok(test && !strcmp(test, "bar"), "1st test as expected"); | 230 | ok(test && !strcmp(test, "bar"), "1st test as expected"); |
233 | free(test); | 231 | free(test); |
234 | 232 | ||
235 | test=np_extract_ntpvar("foo=bar,bar=foo,foobar=barfoo\n", "bar"); | 233 | test = np_extract_ntpvar("foo=bar,bar=foo,foobar=barfoo\n", "bar"); |
236 | ok(test && !strcmp(test, "foo"), "2nd test as expected"); | 234 | ok(test && !strcmp(test, "foo"), "2nd test as expected"); |
237 | free(test); | 235 | free(test); |
238 | 236 | ||
239 | test=np_extract_ntpvar("foo=bar, bar=foo, foobar=barfoo\n", "foobar"); | 237 | test = np_extract_ntpvar("foo=bar, bar=foo, foobar=barfoo\n", "foobar"); |
240 | ok(test && !strcmp(test, "barfoo"), "3rd test as expected"); | 238 | ok(test && !strcmp(test, "barfoo"), "3rd test as expected"); |
241 | free(test); | 239 | free(test); |
242 | 240 | ||
243 | test=np_extract_ntpvar("foo=bar\n", "foo"); | 241 | test = np_extract_ntpvar("foo=bar\n", "foo"); |
244 | ok(test && !strcmp(test, "bar"), "Single test as expected"); | 242 | ok(test && !strcmp(test, "bar"), "Single test as expected"); |
245 | free(test); | 243 | free(test); |
246 | 244 | ||
247 | test=np_extract_ntpvar("foo=bar, bar=foo, foobar=barfooi\n", "abcd"); | 245 | test = np_extract_ntpvar("foo=bar, bar=foo, foobar=barfooi\n", "abcd"); |
248 | ok(!test, "Key not found 1"); | 246 | ok(!test, "Key not found 1"); |
249 | 247 | ||
250 | test=np_extract_ntpvar("foo=bar\n", "abcd"); | 248 | test = np_extract_ntpvar("foo=bar\n", "abcd"); |
251 | ok(!test, "Key not found 2"); | 249 | ok(!test, "Key not found 2"); |
252 | 250 | ||
253 | test=np_extract_ntpvar("foo=bar=foobar", "foo"); | 251 | test = np_extract_ntpvar("foo=bar=foobar", "foo"); |
254 | ok(test && !strcmp(test, "bar=foobar"), "Strange string 1"); | 252 | ok(test && !strcmp(test, "bar=foobar"), "Strange string 1"); |
255 | free(test); | 253 | free(test); |
256 | 254 | ||
257 | test=np_extract_ntpvar("foo", "foo"); | 255 | test = np_extract_ntpvar("foo", "foo"); |
258 | ok(!test, "Malformed string 1"); | 256 | ok(!test, "Malformed string 1"); |
259 | 257 | ||
260 | test=np_extract_ntpvar("foo,", "foo"); | 258 | test = np_extract_ntpvar("foo,", "foo"); |
261 | ok(!test, "Malformed string 2"); | 259 | ok(!test, "Malformed string 2"); |
262 | 260 | ||
263 | test=np_extract_ntpvar("foo=", "foo"); | 261 | test = np_extract_ntpvar("foo=", "foo"); |
264 | ok(!test, "Malformed string 3"); | 262 | ok(!test, "Malformed string 3"); |
265 | 263 | ||
266 | test=np_extract_ntpvar("foo=,bar=foo", "foo"); | 264 | test = np_extract_ntpvar("foo=,bar=foo", "foo"); |
267 | ok(!test, "Malformed string 4"); | 265 | ok(!test, "Malformed string 4"); |
268 | 266 | ||
269 | test=np_extract_ntpvar(",foo", "foo"); | 267 | test = np_extract_ntpvar(",foo", "foo"); |
270 | ok(!test, "Malformed string 5"); | 268 | ok(!test, "Malformed string 5"); |
271 | 269 | ||
272 | test=np_extract_ntpvar("=foo", "foo"); | 270 | test = np_extract_ntpvar("=foo", "foo"); |
273 | ok(!test, "Malformed string 6"); | 271 | ok(!test, "Malformed string 6"); |
274 | 272 | ||
275 | test=np_extract_ntpvar("=foo,", "foo"); | 273 | test = np_extract_ntpvar("=foo,", "foo"); |
276 | ok(!test, "Malformed string 7"); | 274 | ok(!test, "Malformed string 7"); |
277 | 275 | ||
278 | test=np_extract_ntpvar(",,,", "foo"); | 276 | test = np_extract_ntpvar(",,,", "foo"); |
279 | ok(!test, "Malformed string 8"); | 277 | ok(!test, "Malformed string 8"); |
280 | 278 | ||
281 | test=np_extract_ntpvar("===", "foo"); | 279 | test = np_extract_ntpvar("===", "foo"); |
282 | ok(!test, "Malformed string 9"); | 280 | ok(!test, "Malformed string 9"); |
283 | 281 | ||
284 | test=np_extract_ntpvar(",=,=,", "foo"); | 282 | test = np_extract_ntpvar(",=,=,", "foo"); |
285 | ok(!test, "Malformed string 10"); | 283 | ok(!test, "Malformed string 10"); |
286 | 284 | ||
287 | test=np_extract_ntpvar("=,=,=", "foo"); | 285 | test = np_extract_ntpvar("=,=,=", "foo"); |
288 | ok(!test, "Malformed string 11"); | 286 | ok(!test, "Malformed string 11"); |
289 | 287 | ||
290 | test=np_extract_ntpvar(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "foo"); | 288 | test = np_extract_ntpvar(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "foo"); |
291 | ok(test && !strcmp(test, "bar"), "Random spaces and newlines 1"); | 289 | ok(test && !strcmp(test, "bar"), "Random spaces and newlines 1"); |
292 | free(test); | 290 | free(test); |
293 | 291 | ||
294 | test=np_extract_ntpvar(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "bar"); | 292 | test = np_extract_ntpvar(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "bar"); |
295 | ok(test && !strcmp(test, "foo"), "Random spaces and newlines 2"); | 293 | ok(test && !strcmp(test, "foo"), "Random spaces and newlines 2"); |
296 | free(test); | 294 | free(test); |
297 | 295 | ||
298 | test=np_extract_ntpvar(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "foobar"); | 296 | test = np_extract_ntpvar(" foo=bar ,\n bar=foo\n , foobar=barfoo \n ", "foobar"); |
299 | ok(test && !strcmp(test, "barfoo"), "Random spaces and newlines 3"); | 297 | ok(test && !strcmp(test, "barfoo"), "Random spaces and newlines 3"); |
300 | free(test); | 298 | free(test); |
301 | 299 | ||
302 | test=np_extract_ntpvar(" foo=bar ,\n bar\n \n= \n foo\n , foobar=barfoo \n ", "bar"); | 300 | test = np_extract_ntpvar(" foo=bar ,\n bar\n \n= \n foo\n , foobar=barfoo \n ", "bar"); |
303 | ok(test && !strcmp(test, "foo"), "Random spaces and newlines 4"); | 301 | ok(test && !strcmp(test, "foo"), "Random spaces and newlines 4"); |
304 | free(test); | 302 | free(test); |
305 | 303 | ||
306 | test=np_extract_ntpvar("", "foo"); | 304 | test = np_extract_ntpvar("", "foo"); |
307 | ok(!test, "Empty string return NULL"); | 305 | ok(!test, "Empty string return NULL"); |
308 | 306 | ||
309 | |||
310 | /* This is the result of running ./test_utils */ | 307 | /* This is the result of running ./test_utils */ |
311 | temp_string = (char *) _np_state_generate_key(); | 308 | temp_string = (char *)_np_state_generate_key(); |
312 | ok(!strcmp(temp_string, "e2d17f995fd4c020411b85e3e3d0ff7306d4147e"), "Got hash with exe and no parameters" ) || | 309 | ok(!strcmp(temp_string, "e2d17f995fd4c020411b85e3e3d0ff7306d4147e"), "Got hash with exe and no parameters") || |
313 | diag( "You are probably running in wrong directory. Must run as ./test_utils" ); | 310 | diag("You are probably running in wrong directory. Must run as ./test_utils"); |
314 | |||
315 | 311 | ||
316 | this_monitoring_plugin->argc=4; | 312 | this_monitoring_plugin->argc = 4; |
317 | this_monitoring_plugin->argv[0] = "./test_utils"; | 313 | this_monitoring_plugin->argv[0] = "./test_utils"; |
318 | this_monitoring_plugin->argv[1] = "here"; | 314 | this_monitoring_plugin->argv[1] = "here"; |
319 | this_monitoring_plugin->argv[2] = "--and"; | 315 | this_monitoring_plugin->argv[2] = "--and"; |
320 | this_monitoring_plugin->argv[3] = "now"; | 316 | this_monitoring_plugin->argv[3] = "now"; |
321 | temp_string = (char *) _np_state_generate_key(); | 317 | temp_string = (char *)_np_state_generate_key(); |
322 | ok(!strcmp(temp_string, "bd72da9f78ff1419fad921ea5e43ce56508aef6c"), "Got based on expected argv" ); | 318 | ok(!strcmp(temp_string, "bd72da9f78ff1419fad921ea5e43ce56508aef6c"), "Got based on expected argv"); |
323 | 319 | ||
324 | unsetenv("MP_STATE_PATH"); | 320 | unsetenv("MP_STATE_PATH"); |
325 | temp_string = (char *) _np_state_calculate_location_prefix(); | 321 | temp_string = (char *)_np_state_calculate_location_prefix(); |
326 | ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory" ); | 322 | ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory"); |
327 | 323 | ||
328 | setenv("MP_STATE_PATH", "", 1); | 324 | setenv("MP_STATE_PATH", "", 1); |
329 | temp_string = (char *) _np_state_calculate_location_prefix(); | 325 | temp_string = (char *)_np_state_calculate_location_prefix(); |
330 | ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory even with empty string" ); | 326 | ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory even with empty string"); |
331 | 327 | ||
332 | setenv("MP_STATE_PATH", "/usr/local/nagios/var", 1); | 328 | setenv("MP_STATE_PATH", "/usr/local/nagios/var", 1); |
333 | temp_string = (char *) _np_state_calculate_location_prefix(); | 329 | temp_string = (char *)_np_state_calculate_location_prefix(); |
334 | ok(!strcmp(temp_string, "/usr/local/nagios/var"), "Got default directory" ); | 330 | ok(!strcmp(temp_string, "/usr/local/nagios/var"), "Got default directory"); |
335 | |||
336 | 331 | ||
332 | ok(temp_state_key == NULL, "temp_state_key initially empty"); | ||
337 | 333 | ||
338 | ok(temp_state_key==NULL, "temp_state_key initially empty"); | 334 | this_monitoring_plugin->argc = 1; |
339 | |||
340 | this_monitoring_plugin->argc=1; | ||
341 | this_monitoring_plugin->argv[0] = "./test_utils"; | 335 | this_monitoring_plugin->argv[0] = "./test_utils"; |
342 | np_enable_state(NULL, 51); | 336 | np_enable_state(NULL, 51); |
343 | temp_state_key = this_monitoring_plugin->state; | 337 | temp_state_key = this_monitoring_plugin->state; |
344 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); | 338 | ok(!strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name"); |
345 | ok( !strcmp(temp_state_key->name, "e2d17f995fd4c020411b85e3e3d0ff7306d4147e"), "Got generated filename" ); | 339 | ok(!strcmp(temp_state_key->name, "e2d17f995fd4c020411b85e3e3d0ff7306d4147e"), "Got generated filename"); |
346 | |||
347 | 340 | ||
348 | np_enable_state("allowedchars_in_keyname", 77); | 341 | np_enable_state("allowedchars_in_keyname", 77); |
349 | temp_state_key = this_monitoring_plugin->state; | 342 | temp_state_key = this_monitoring_plugin->state; |
350 | sprintf(state_path, "/usr/local/nagios/var/%lu/check_test/allowedchars_in_keyname", (unsigned long)geteuid()); | 343 | sprintf(state_path, "/usr/local/nagios/var/%lu/check_test/allowedchars_in_keyname", (unsigned long)geteuid()); |
351 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); | 344 | ok(!strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name"); |
352 | ok( !strcmp(temp_state_key->name, "allowedchars_in_keyname"), "Got key name with valid chars" ); | 345 | ok(!strcmp(temp_state_key->name, "allowedchars_in_keyname"), "Got key name with valid chars"); |
353 | ok( !strcmp(temp_state_key->_filename, state_path), "Got internal filename" ); | 346 | ok(!strcmp(temp_state_key->_filename, state_path), "Got internal filename"); |
354 | |||
355 | 347 | ||
356 | /* Don't do this test just yet. Will die */ | 348 | /* Don't do this test just yet. Will die */ |
357 | /* | 349 | /* |
@@ -363,73 +355,65 @@ main (int argc, char **argv) | |||
363 | np_enable_state("funnykeyname", 54); | 355 | np_enable_state("funnykeyname", 54); |
364 | temp_state_key = this_monitoring_plugin->state; | 356 | temp_state_key = this_monitoring_plugin->state; |
365 | sprintf(state_path, "/usr/local/nagios/var/%lu/check_test/funnykeyname", (unsigned long)geteuid()); | 357 | sprintf(state_path, "/usr/local/nagios/var/%lu/check_test/funnykeyname", (unsigned long)geteuid()); |
366 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); | 358 | ok(!strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name"); |
367 | ok( !strcmp(temp_state_key->name, "funnykeyname"), "Got key name" ); | 359 | ok(!strcmp(temp_state_key->name, "funnykeyname"), "Got key name"); |
368 | 360 | ||
369 | 361 | ok(!strcmp(temp_state_key->_filename, state_path), "Got internal filename"); | |
370 | 362 | ok(temp_state_key->data_version == 54, "Version set"); | |
371 | ok( !strcmp(temp_state_key->_filename, state_path), "Got internal filename" ); | ||
372 | ok( temp_state_key->data_version==54, "Version set" ); | ||
373 | 363 | ||
374 | temp_state_data = np_state_read(); | 364 | temp_state_data = np_state_read(); |
375 | ok( temp_state_data==NULL, "Got no state data as file does not exist" ); | 365 | ok(temp_state_data == NULL, "Got no state data as file does not exist"); |
376 | |||
377 | 366 | ||
378 | /* | 367 | /* |
379 | temp_fp = fopen("var/statefile", "r"); | 368 | temp_fp = fopen("var/statefile", "r"); |
380 | if (temp_fp==NULL) | 369 | if (temp_fp==NULL) |
381 | printf("Error opening. errno=%d\n", errno); | 370 | printf("Error opening. errno=%d\n", errno); |
382 | printf("temp_fp=%s\n", temp_fp); | 371 | printf("temp_fp=%s\n", temp_fp); |
383 | ok( _np_state_read_file(temp_fp) == true, "Can read state file" ); | 372 | ok( _np_state_read_file(temp_fp) == true, "Can read state file" ); |
384 | fclose(temp_fp); | 373 | fclose(temp_fp); |
385 | */ | 374 | */ |
386 | 375 | ||
387 | temp_state_key->_filename="var/statefile"; | 376 | temp_state_key->_filename = "var/statefile"; |
388 | temp_state_data = np_state_read(); | 377 | temp_state_data = np_state_read(); |
389 | ok( this_monitoring_plugin->state->state_data!=NULL, "Got state data now" ) || diag("Are you running in right directory? Will get coredump next if not"); | 378 | ok(this_monitoring_plugin->state->state_data != NULL, "Got state data now") || |
390 | ok( this_monitoring_plugin->state->state_data->time==1234567890, "Got time" ); | 379 | diag("Are you running in right directory? Will get coredump next if not"); |
391 | ok( !strcmp((char *)this_monitoring_plugin->state->state_data->data, "String to read"), "Data as expected" ); | 380 | ok(this_monitoring_plugin->state->state_data->time == 1234567890, "Got time"); |
381 | ok(!strcmp((char *)this_monitoring_plugin->state->state_data->data, "String to read"), "Data as expected"); | ||
392 | 382 | ||
393 | temp_state_key->data_version=53; | 383 | temp_state_key->data_version = 53; |
394 | temp_state_data = np_state_read(); | 384 | temp_state_data = np_state_read(); |
395 | ok( temp_state_data==NULL, "Older data version gives NULL" ); | 385 | ok(temp_state_data == NULL, "Older data version gives NULL"); |
396 | temp_state_key->data_version=54; | 386 | temp_state_key->data_version = 54; |
397 | 387 | ||
398 | temp_state_key->_filename="var/nonexistent"; | 388 | temp_state_key->_filename = "var/nonexistent"; |
399 | temp_state_data = np_state_read(); | 389 | temp_state_data = np_state_read(); |
400 | ok( temp_state_data==NULL, "Missing file gives NULL" ); | 390 | ok(temp_state_data == NULL, "Missing file gives NULL"); |
401 | ok( this_monitoring_plugin->state->state_data==NULL, "No state information" ); | 391 | ok(this_monitoring_plugin->state->state_data == NULL, "No state information"); |
402 | 392 | ||
403 | temp_state_key->_filename="var/oldformat"; | 393 | temp_state_key->_filename = "var/oldformat"; |
404 | temp_state_data = np_state_read(); | 394 | temp_state_data = np_state_read(); |
405 | ok( temp_state_data==NULL, "Old file format gives NULL" ); | 395 | ok(temp_state_data == NULL, "Old file format gives NULL"); |
406 | 396 | ||
407 | temp_state_key->_filename="var/baddate"; | 397 | temp_state_key->_filename = "var/baddate"; |
408 | temp_state_data = np_state_read(); | 398 | temp_state_data = np_state_read(); |
409 | ok( temp_state_data==NULL, "Bad date gives NULL" ); | 399 | ok(temp_state_data == NULL, "Bad date gives NULL"); |
410 | 400 | ||
411 | temp_state_key->_filename="var/missingdataline"; | 401 | temp_state_key->_filename = "var/missingdataline"; |
412 | temp_state_data = np_state_read(); | 402 | temp_state_data = np_state_read(); |
413 | ok( temp_state_data==NULL, "Missing data line gives NULL" ); | 403 | ok(temp_state_data == NULL, "Missing data line gives NULL"); |
414 | |||
415 | |||
416 | |||
417 | 404 | ||
418 | unlink("var/generated"); | 405 | unlink("var/generated"); |
419 | temp_state_key->_filename="var/generated"; | 406 | temp_state_key->_filename = "var/generated"; |
420 | current_time=1234567890; | 407 | current_time = 1234567890; |
421 | np_state_write_string(current_time, "String to read"); | 408 | np_state_write_string(current_time, "String to read"); |
422 | ok(system("cmp var/generated var/statefile")==0, "Generated file same as expected"); | 409 | ok(system("cmp var/generated var/statefile") == 0, "Generated file same as expected"); |
423 | |||
424 | |||
425 | |||
426 | 410 | ||
427 | unlink("var/generated_directory/statefile"); | 411 | unlink("var/generated_directory/statefile"); |
428 | unlink("var/generated_directory"); | 412 | unlink("var/generated_directory"); |
429 | temp_state_key->_filename="var/generated_directory/statefile"; | 413 | temp_state_key->_filename = "var/generated_directory/statefile"; |
430 | current_time=1234567890; | 414 | current_time = 1234567890; |
431 | np_state_write_string(current_time, "String to read"); | 415 | np_state_write_string(current_time, "String to read"); |
432 | ok(system("cmp var/generated_directory/statefile var/statefile")==0, "Have created directory"); | 416 | ok(system("cmp var/generated_directory/statefile var/statefile") == 0, "Have created directory"); |
433 | 417 | ||
434 | /* This test to check cannot write to dir - can't automate yet */ | 418 | /* This test to check cannot write to dir - can't automate yet */ |
435 | /* | 419 | /* |
@@ -438,15 +422,13 @@ main (int argc, char **argv) | |||
438 | np_state_write_string(current_time, "String to read"); | 422 | np_state_write_string(current_time, "String to read"); |
439 | */ | 423 | */ |
440 | 424 | ||
441 | 425 | temp_state_key->_filename = "var/generated"; | |
442 | temp_state_key->_filename="var/generated"; | ||
443 | time(¤t_time); | 426 | time(¤t_time); |
444 | np_state_write_string(0, "String to read"); | 427 | np_state_write_string(0, "String to read"); |
445 | temp_state_data = np_state_read(); | 428 | temp_state_data = np_state_read(); |
446 | /* Check time is set to current_time */ | 429 | /* Check time is set to current_time */ |
447 | ok(system("cmp var/generated var/statefile > /dev/null")!=0, "Generated file should be different this time"); | 430 | ok(system("cmp var/generated var/statefile > /dev/null") != 0, "Generated file should be different this time"); |
448 | ok(this_monitoring_plugin->state->state_data->time-current_time<=1, "Has time generated from current time"); | 431 | ok(this_monitoring_plugin->state->state_data->time - current_time <= 1, "Has time generated from current time"); |
449 | |||
450 | 432 | ||
451 | /* Don't know how to automatically test this. Need to be able to redefine die and catch the error */ | 433 | /* Don't know how to automatically test this. Need to be able to redefine die and catch the error */ |
452 | /* | 434 | /* |
@@ -454,23 +436,16 @@ main (int argc, char **argv) | |||
454 | np_state_write_string(0, "Bad file"); | 436 | np_state_write_string(0, "Bad file"); |
455 | */ | 437 | */ |
456 | 438 | ||
457 | |||
458 | np_cleanup(); | 439 | np_cleanup(); |
459 | 440 | ||
460 | ok(this_monitoring_plugin==NULL, "Free'd this_monitoring_plugin"); | 441 | ok(this_monitoring_plugin == NULL, "Free'd this_monitoring_plugin"); |
461 | 442 | ||
462 | ok(mp_suid() == false, "Test aren't suid"); | 443 | ok(mp_suid() == false, "Test aren't suid"); |
463 | 444 | ||
464 | /* base states with random case */ | 445 | /* base states with random case */ |
465 | char *states[] = { | 446 | char *states[] = {"Ok", "wArnINg", "cRiTIcaL", "UnKNoWN", NULL}; |
466 | "Ok", | 447 | |
467 | "wArnINg", | 448 | for (i = 0; states[i] != NULL; i++) { |
468 | "cRiTIcaL", | ||
469 | "UnKNoWN", | ||
470 | NULL | ||
471 | }; | ||
472 | |||
473 | for (i=0; states[i]!=NULL; i++) { | ||
474 | /* out of the random case states, create the lower and upper versions + numeric string one */ | 449 | /* out of the random case states, create the lower and upper versions + numeric string one */ |
475 | char *statelower = strdup(states[i]); | 450 | char *statelower = strdup(states[i]); |
476 | char *stateupper = strdup(states[i]); | 451 | char *stateupper = strdup(states[i]); |
@@ -488,23 +463,23 @@ main (int argc, char **argv) | |||
488 | char testname[64] = "Translate state string: "; | 463 | char testname[64] = "Translate state string: "; |
489 | int tlen = strlen(testname); | 464 | int tlen = strlen(testname); |
490 | 465 | ||
491 | strcpy(testname+tlen, states[i]); | 466 | strcpy(testname + tlen, states[i]); |
492 | ok(i==mp_translate_state(states[i]), testname); | 467 | ok(i == mp_translate_state(states[i]), testname); |
493 | 468 | ||
494 | strcpy(testname+tlen, statelower); | 469 | strcpy(testname + tlen, statelower); |
495 | ok(i==mp_translate_state(statelower), testname); | 470 | ok(i == mp_translate_state(statelower), testname); |
496 | 471 | ||
497 | strcpy(testname+tlen, stateupper); | 472 | strcpy(testname + tlen, stateupper); |
498 | ok(i==mp_translate_state(stateupper), testname); | 473 | ok(i == mp_translate_state(stateupper), testname); |
499 | 474 | ||
500 | strcpy(testname+tlen, statenum); | 475 | strcpy(testname + tlen, statenum); |
501 | ok(i==mp_translate_state(statenum), testname); | 476 | ok(i == mp_translate_state(statenum), testname); |
502 | } | 477 | } |
503 | ok(ERROR==mp_translate_state("warningfewgw"), "Translate state string with garbage"); | 478 | ok(ERROR == mp_translate_state("warningfewgw"), "Translate state string with garbage"); |
504 | ok(ERROR==mp_translate_state("00"), "Translate state string: bad numeric string 1"); | 479 | ok(ERROR == mp_translate_state("00"), "Translate state string: bad numeric string 1"); |
505 | ok(ERROR==mp_translate_state("01"), "Translate state string: bad numeric string 2"); | 480 | ok(ERROR == mp_translate_state("01"), "Translate state string: bad numeric string 2"); |
506 | ok(ERROR==mp_translate_state("10"), "Translate state string: bad numeric string 3"); | 481 | ok(ERROR == mp_translate_state("10"), "Translate state string: bad numeric string 3"); |
507 | ok(ERROR==mp_translate_state(""), "Translate state string: empty string"); | 482 | ok(ERROR == mp_translate_state(""), "Translate state string: empty string"); |
508 | 483 | ||
509 | return exit_status(); | 484 | return exit_status(); |
510 | } | 485 | } |