main.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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) { return 0; }
  33. static int clean_suite1(void) { return 0; }
  34. int main(void) {
  35. CU_pSuite pSuite = NULL;
  36. unsigned int num_tests_failed;
  37. /* initialize the CUnit test registry */
  38. if (CUE_SUCCESS != CU_initialize_registry())
  39. return CU_get_error();
  40. /* add a suite to the registry */
  41. pSuite = CU_add_suite("libwslay_TestSuite", init_suite1, clean_suite1);
  42. if (NULL == pSuite) {
  43. CU_cleanup_registry();
  44. return CU_get_error();
  45. }
  46. /* add the tests to the suite */
  47. if (!CU_add_test(pSuite, "wslay_frame_context_init",
  48. test_wslay_frame_context_init) ||
  49. !CU_add_test(pSuite, "wslay_frame_recv", test_wslay_frame_recv) ||
  50. !CU_add_test(pSuite, "wslay_frame_recv_1byte",
  51. test_wslay_frame_recv_1byte) ||
  52. !CU_add_test(pSuite, "wslay_frame_recv_fragmented",
  53. test_wslay_frame_recv_fragmented) ||
  54. !CU_add_test(pSuite, "wslay_frame_recv_interleaved_ctrl_frame",
  55. test_wslay_frame_recv_interleaved_ctrl_frame) ||
  56. !CU_add_test(pSuite, "wslay_frame_recv_zero_payloadlen",
  57. test_wslay_frame_recv_zero_payloadlen) ||
  58. !CU_add_test(pSuite, "wslay_frame_recv_too_large_payload",
  59. test_wslay_frame_recv_too_large_payload) ||
  60. !CU_add_test(pSuite, "wslay_frame_recv_ctrl_too_large_payload",
  61. test_wslay_frame_recv_ctrl_frame_too_large_payload) ||
  62. !CU_add_test(pSuite, "wslay_frame_recv_minimum_ext_payload16",
  63. test_wslay_frame_recv_minimum_ext_payload16) ||
  64. !CU_add_test(pSuite, "wslay_frame_recv_minimum_ext_payload64",
  65. test_wslay_frame_recv_minimum_ext_payload64) ||
  66. !CU_add_test(pSuite, "wslay_frame_send", test_wslay_frame_send) ||
  67. !CU_add_test(pSuite, "wslay_frame_send_fragmented",
  68. test_wslay_frame_send_fragmented) ||
  69. !CU_add_test(pSuite, "wslay_frame_send_interleaved_ctrl_frame",
  70. test_wslay_frame_send_interleaved_ctrl_frame) ||
  71. !CU_add_test(pSuite, "wslay_frame_send_1byte_masked",
  72. test_wslay_frame_send_1byte_masked) ||
  73. !CU_add_test(pSuite, "wslay_frame_send_zero_payloadlen",
  74. test_wslay_frame_send_zero_payloadlen) ||
  75. !CU_add_test(pSuite, "wslay_frame_send_too_large_payload",
  76. test_wslay_frame_send_too_large_payload) ||
  77. !CU_add_test(pSuite, "wslay_frame_send_ctrl_frame_too_large_payload",
  78. test_wslay_frame_send_ctrl_frame_too_large_payload) ||
  79. !CU_add_test(pSuite, "wslay_frame_write", test_wslay_frame_write) ||
  80. !CU_add_test(pSuite, "wslay_frame_write_fragmented",
  81. test_wslay_frame_write_fragmented) ||
  82. !CU_add_test(pSuite, "wslay_frame_write_interleaved_ctrl_frame",
  83. test_wslay_frame_write_interleaved_ctrl_frame) ||
  84. !CU_add_test(pSuite, "wslay_frame_write_1byte_masked",
  85. test_wslay_frame_write_1byte_masked) ||
  86. !CU_add_test(pSuite, "wslay_frame_write_zero_payloadlen",
  87. test_wslay_frame_write_zero_payloadlen) ||
  88. !CU_add_test(pSuite, "wslay_frame_write_too_large_payload",
  89. test_wslay_frame_write_too_large_payload) ||
  90. !CU_add_test(pSuite, "wslay_frame_write_ctrl_frame_too_large_payload",
  91. test_wslay_frame_write_ctrl_frame_too_large_payload) ||
  92. !CU_add_test(pSuite, "wslay_event_send_fragmented_msg",
  93. test_wslay_event_send_fragmented_msg) ||
  94. !CU_add_test(pSuite, "wslay_event_send_fragmented_msg_empty_data",
  95. test_wslay_event_send_fragmented_msg_empty_data) ||
  96. !CU_add_test(pSuite, "wslay_event_send_fragmented_msg_with_ctrl",
  97. test_wslay_event_send_fragmented_msg_with_ctrl) ||
  98. !CU_add_test(pSuite, "wslay_event_send_fragmented_msg_with_rsv1",
  99. test_wslay_event_send_fragmented_msg_with_rsv1) ||
  100. !CU_add_test(pSuite, "wslay_event_send_msg_with_rsv1",
  101. test_wslay_event_send_msg_with_rsv1) ||
  102. !CU_add_test(pSuite, "wslay_event_send_ctrl_msg_first",
  103. test_wslay_event_send_ctrl_msg_first) ||
  104. !CU_add_test(pSuite, "wslay_event_send_ctrl_msg_with_rsv1",
  105. test_wslay_event_send_ctrl_msg_with_rsv1) ||
  106. !CU_add_test(pSuite, "wslay_event_queue_close",
  107. test_wslay_event_queue_close) ||
  108. !CU_add_test(pSuite, "wslay_event_queue_close_without_code",
  109. test_wslay_event_queue_close_without_code) ||
  110. !CU_add_test(pSuite, "wslay_event_recv_close_without_code",
  111. test_wslay_event_recv_close_without_code) ||
  112. !CU_add_test(pSuite, "wslay_event_reply_close",
  113. test_wslay_event_reply_close) ||
  114. !CU_add_test(pSuite, "wslay_event_no_more_msg",
  115. test_wslay_event_no_more_msg) ||
  116. !CU_add_test(pSuite, "wslay_event_callback_failure",
  117. test_wslay_event_callback_failure) ||
  118. !CU_add_test(pSuite, "wslay_event_no_buffering",
  119. test_wslay_event_no_buffering) ||
  120. !CU_add_test(pSuite, "wslay_event_recv_text_frame_with_rsv1",
  121. test_wslay_event_recv_text_frame_with_rsv1) ||
  122. !CU_add_test(pSuite, "wslay_event_frame_too_big",
  123. test_wslay_event_frame_too_big) ||
  124. !CU_add_test(pSuite, "wslay_event_message_too_big",
  125. test_wslay_event_message_too_big) ||
  126. !CU_add_test(pSuite, "wslay_event_config_set_allowed_rsv_bits",
  127. test_wslay_event_config_set_allowed_rsv_bits) ||
  128. !CU_add_test(pSuite, "wslay_event_write_fragmented_msg",
  129. test_wslay_event_write_fragmented_msg) ||
  130. !CU_add_test(pSuite, "wslay_event_write_fragmented_msg_empty_data",
  131. test_wslay_event_write_fragmented_msg_empty_data) ||
  132. !CU_add_test(pSuite, "wslay_event_write_fragmented_msg_with_ctrl",
  133. test_wslay_event_write_fragmented_msg_with_ctrl) ||
  134. !CU_add_test(pSuite, "wslay_event_write_fragmented_msg_with_rsv1",
  135. test_wslay_event_write_fragmented_msg_with_rsv1) ||
  136. !CU_add_test(pSuite, "wslay_event_write_msg_with_rsv1",
  137. test_wslay_event_write_msg_with_rsv1) ||
  138. !CU_add_test(pSuite, "wslay_event_write_ctrl_msg_first",
  139. test_wslay_event_write_ctrl_msg_first) ||
  140. !CU_add_test(pSuite, "wslay_queue", test_wslay_queue)) {
  141. CU_cleanup_registry();
  142. return CU_get_error();
  143. }
  144. /* Run all tests using the CUnit Basic interface */
  145. CU_basic_set_mode(CU_BRM_VERBOSE);
  146. CU_basic_run_tests();
  147. num_tests_failed = CU_get_number_of_tests_failed();
  148. CU_cleanup_registry();
  149. if (CU_get_error() == CUE_SUCCESS) {
  150. return (int)num_tests_failed;
  151. } else {
  152. printf("CUnit Error: %s\n", CU_get_error_msg());
  153. return CU_get_error();
  154. }
  155. }