4
0

test_tcp.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*****************************************************************************
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. *
  17. *****************************************************************************/
  18. #include "common.h"
  19. #include "utils_tcp.h"
  20. #include "tap.h"
  21. int
  22. main(void)
  23. {
  24. char **server_expect;
  25. int server_expect_count = 3;
  26. plan_tests(9);
  27. server_expect = malloc(sizeof(char*) * server_expect_count);
  28. server_expect[0] = strdup("AA");
  29. server_expect[1] = strdup("bb");
  30. server_expect[2] = strdup("CC");
  31. ok(np_expect_match("AA bb CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_SUCCESS,
  32. "Test matching any string at the beginning (first expect string)");
  33. ok(np_expect_match("bb AA CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_SUCCESS,
  34. "Test matching any string at the beginning (second expect string)");
  35. ok(np_expect_match("b", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_RETRY,
  36. "Test matching any string at the beginning (substring match)");
  37. ok(np_expect_match("XX bb AA CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_FAILURE,
  38. "Test with strings not matching at the beginning");
  39. ok(np_expect_match("XX CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_FAILURE,
  40. "Test matching any string");
  41. ok(np_expect_match("XX", server_expect, server_expect_count, 0) == NP_MATCH_RETRY,
  42. "Test not matching any string");
  43. ok(np_expect_match("XX AA bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_SUCCESS,
  44. "Test matching all strings");
  45. ok(np_expect_match("XX bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_RETRY,
  46. "Test not matching all strings");
  47. ok(np_expect_match("XX XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_RETRY,
  48. "Test not matching any string (testing all)");
  49. return exit_status();
  50. }