main.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Wslay - The WebSocket Library
  3. *
  4. * Copyright (c) 2011, 2012 Tatsuhiro Tsujikawa
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include <CUnit/Basic.h>
  28. /* include test cases' include files here */
  29. #include "wslay_frame_test.h"
  30. #include "wslay_event_test.h"
  31. #include "wslay_queue_test.h"
  32. static int init_suite1(void)
  33. {
  34. return 0;
  35. }
  36. static int clean_suite1(void)
  37. {
  38. return 0;
  39. }
  40. int main(void)
  41. {
  42. CU_pSuite pSuite = NULL;
  43. unsigned int num_tests_failed;
  44. /* initialize the CUnit test registry */
  45. if (CUE_SUCCESS != CU_initialize_registry())
  46. return CU_get_error();
  47. /* add a suite to the registry */
  48. pSuite = CU_add_suite("libwslay_TestSuite", init_suite1, clean_suite1);
  49. if (NULL == pSuite) {
  50. CU_cleanup_registry();
  51. return CU_get_error();
  52. }
  53. /* add the tests to the suite */
  54. if(!CU_add_test(pSuite, "wslay_frame_context_init",
  55. test_wslay_frame_context_init) ||
  56. !CU_add_test(pSuite, "wslay_frame_recv", test_wslay_frame_recv) ||
  57. !CU_add_test(pSuite, "wslay_frame_recv_1byte",
  58. test_wslay_frame_recv_1byte) ||
  59. !CU_add_test(pSuite, "wslay_frame_recv_fragmented",
  60. test_wslay_frame_recv_fragmented) ||
  61. !CU_add_test(pSuite, "wslay_frame_recv_interleaved_ctrl_frame",
  62. test_wslay_frame_recv_interleaved_ctrl_frame) ||
  63. !CU_add_test(pSuite, "wslay_frame_recv_zero_payloadlen",
  64. test_wslay_frame_recv_zero_payloadlen) ||
  65. !CU_add_test(pSuite, "wslay_frame_recv_too_large_payload",
  66. test_wslay_frame_recv_too_large_payload) ||
  67. !CU_add_test(pSuite, "wslay_frame_recv_ctrl_too_large_payload",
  68. test_wslay_frame_recv_ctrl_frame_too_large_payload) ||
  69. !CU_add_test(pSuite, "wslay_frame_recv_minimum_ext_payload16",
  70. test_wslay_frame_recv_minimum_ext_payload16) ||
  71. !CU_add_test(pSuite, "wslay_frame_recv_minimum_ext_payload64",
  72. test_wslay_frame_recv_minimum_ext_payload64) ||
  73. !CU_add_test(pSuite, "wslay_frame_send", test_wslay_frame_send) ||
  74. !CU_add_test(pSuite, "wslay_frame_send_fragmented",
  75. test_wslay_frame_send_fragmented) ||
  76. !CU_add_test(pSuite, "wslay_frame_send_interleaved_ctrl_frame",
  77. test_wslay_frame_send_interleaved_ctrl_frame) ||
  78. !CU_add_test(pSuite, "wslay_frame_send_1byte_masked",
  79. test_wslay_frame_send_1byte_masked) ||
  80. !CU_add_test(pSuite, "wslay_frame_send_zero_payloadlen",
  81. test_wslay_frame_send_zero_payloadlen) ||
  82. !CU_add_test(pSuite, "wslay_frame_send_too_large_payload",
  83. test_wslay_frame_send_too_large_payload) ||
  84. !CU_add_test(pSuite, "wslay_frame_send_ctrl_frame_too_large_payload",
  85. test_wslay_frame_send_ctrl_frame_too_large_payload) ||
  86. !CU_add_test(pSuite, "wslay_event_send_fragmented_msg",
  87. test_wslay_event_send_fragmented_msg) ||
  88. !CU_add_test(pSuite, "wslay_event_send_fragmented_msg_with_ctrl",
  89. test_wslay_event_send_fragmented_msg_with_ctrl) ||
  90. !CU_add_test(pSuite, "wslay_event_send_fragmented_msg_with_rsv1",
  91. test_wslay_event_send_fragmented_msg_with_rsv1) ||
  92. !CU_add_test(pSuite, "wslay_event_send_msg_with_rsv1",
  93. test_wslay_event_send_msg_with_rsv1) ||
  94. !CU_add_test(pSuite, "wslay_event_send_ctrl_msg_first",
  95. test_wslay_event_send_ctrl_msg_first) ||
  96. !CU_add_test(pSuite, "wslay_event_send_ctrl_msg_with_rsv1",
  97. test_wslay_event_send_ctrl_msg_with_rsv1) ||
  98. !CU_add_test(pSuite, "wslay_event_queue_close",
  99. test_wslay_event_queue_close) ||
  100. !CU_add_test(pSuite, "wslay_event_queue_close_without_code",
  101. test_wslay_event_queue_close_without_code) ||
  102. !CU_add_test(pSuite, "wslay_event_recv_close_without_code",
  103. test_wslay_event_recv_close_without_code) ||
  104. !CU_add_test(pSuite, "wslay_event_reply_close",
  105. test_wslay_event_reply_close) ||
  106. !CU_add_test(pSuite, "wslay_event_no_more_msg",
  107. test_wslay_event_no_more_msg) ||
  108. !CU_add_test(pSuite, "wslay_event_callback_failure",
  109. test_wslay_event_callback_failure) ||
  110. !CU_add_test(pSuite, "wslay_event_no_buffering",
  111. test_wslay_event_no_buffering) ||
  112. !CU_add_test(pSuite, "wslay_event_recv_text_frame_with_rsv1",
  113. test_wslay_event_recv_text_frame_with_rsv1) ||
  114. !CU_add_test(pSuite, "wslay_event_frame_too_big",
  115. test_wslay_event_frame_too_big) ||
  116. !CU_add_test(pSuite, "wslay_event_message_too_big",
  117. test_wslay_event_message_too_big) ||
  118. !CU_add_test(pSuite, "wslay_event_config_set_allowed_rsv_bits",
  119. test_wslay_event_config_set_allowed_rsv_bits) ||
  120. !CU_add_test(pSuite, "wslay_queue", test_wslay_queue)) {
  121. CU_cleanup_registry();
  122. return CU_get_error();
  123. }
  124. /* Run all tests using the CUnit Basic interface */
  125. CU_basic_set_mode(CU_BRM_VERBOSE);
  126. CU_basic_run_tests();
  127. num_tests_failed = CU_get_number_of_tests_failed();
  128. CU_cleanup_registry();
  129. if (CU_get_error() == CUE_SUCCESS) {
  130. return (int)num_tests_failed;
  131. } else {
  132. printf("CUnit Error: %s\n", CU_get_error_msg());
  133. return CU_get_error();
  134. }
  135. }