check_tcp: Properly deal will partial recv(3)s
[monitoring-plugins.git] / lib / tests / test_tcp.c
blobae6dc1f41a52c41b0e8937fda6c0c5d57b82aeb8
1 /*****************************************************************************
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
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/>.
17 *****************************************************************************/
19 #include "common.h"
20 #include "utils_tcp.h"
21 #include "tap.h"
23 int
24 main (int argc, char **argv)
26 char** server_expect;
27 int server_expect_count = 3;
28 plan_tests(9);
30 server_expect = malloc(sizeof(char*) * server_expect_count);
32 server_expect[0] = strdup("AA");
33 server_expect[1] = strdup("bb");
34 server_expect[2] = strdup("CC");
36 ok(np_expect_match("AA bb CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_SUCCESS,
37 "Test matching any string at the beginning (first expect string)");
38 ok(np_expect_match("bb AA CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_SUCCESS,
39 "Test matching any string at the beginning (second expect string)");
40 ok(np_expect_match("b", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_RETRY,
41 "Test matching any string at the beginning (substring match)");
42 ok(np_expect_match("XX bb AA CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_FAILURE,
43 "Test with strings not matching at the beginning");
44 ok(np_expect_match("XX CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_FAILURE,
45 "Test matching any string");
46 ok(np_expect_match("XX", server_expect, server_expect_count, 0) == NP_MATCH_RETRY,
47 "Test not matching any string");
48 ok(np_expect_match("XX AA bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_SUCCESS,
49 "Test matching all strings");
50 ok(np_expect_match("XX bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_RETRY,
51 "Test not matching all strings");
52 ok(np_expect_match("XX XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_RETRY,
53 "Test not matching any string (testing all)");
56 return exit_status();