check_check_msg.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Check: a unit test framework for C
  3. * Copyright (C) 2001, 2002 Arien Malec
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the
  17. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  18. * MA 02110-1301, USA.
  19. */
  20. #include "../lib/libcompat.h"
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include "check.h"
  25. #include "check_msg.h"
  26. #include "check_check.h"
  27. #include "check_list.h"
  28. #include "check_impl.h"
  29. START_TEST(test_send)
  30. {
  31. TestResult *tr;
  32. setup_messaging();
  33. send_ctx_info(CK_CTX_SETUP);
  34. send_loc_info("abc123.c", 10);
  35. send_ctx_info(CK_CTX_TEST);
  36. send_loc_info("abc124.c", 22);
  37. send_loc_info("abc125.c", 25);
  38. send_failure_info("Oops");
  39. tr = receive_test_result(0);
  40. teardown_messaging();
  41. ck_assert_msg (tr != NULL,
  42. "No test result received");
  43. ck_assert_msg (tr_ctx(tr) == CK_CTX_TEST,
  44. "Bad CTX received");
  45. ck_assert_msg (strcmp(tr_msg(tr), "Oops") == 0,
  46. "Bad failure msg received");
  47. ck_assert_msg (strcmp(tr_lfile(tr), "abc125.c") == 0,
  48. "Bad loc file received");
  49. ck_assert_msg (tr_lno(tr) == 25,
  50. "Bad loc line received");
  51. if (tr != NULL)
  52. free(tr);
  53. }
  54. END_TEST
  55. START_TEST(test_send_big)
  56. {
  57. TestResult *tr;
  58. int i;
  59. setup_messaging();
  60. send_ctx_info(CK_CTX_SETUP);
  61. send_loc_info("abc123.c", 10);
  62. for (i = 0; i < 10000; i++) {
  63. send_ctx_info(CK_CTX_TEST);
  64. send_loc_info("abc124.c", i);
  65. }
  66. tr = receive_test_result(0);
  67. teardown_messaging();
  68. ck_assert_msg (tr != NULL,
  69. "No test result received");
  70. ck_assert_msg (tr_ctx(tr) == CK_CTX_TEST,
  71. "Bad CTX received");
  72. ck_assert_msg (strcmp(tr_lfile(tr), "abc124.c") == 0,
  73. "Bad loc file received");
  74. ck_assert_msg (tr_lno(tr) == i -1,
  75. "Bad loc line received");
  76. if (tr != NULL)
  77. tr_free(tr);
  78. }
  79. END_TEST
  80. START_TEST(test_send_test_error)
  81. {
  82. TestResult *tr;
  83. setup_messaging();
  84. send_ctx_info(CK_CTX_SETUP);
  85. send_loc_info("abc123.c", 10);
  86. send_ctx_info(CK_CTX_TEST);
  87. send_loc_info("abc124.c", 22);
  88. send_loc_info("abc125.c", 25);
  89. tr = receive_test_result(1);
  90. teardown_messaging();
  91. ck_assert_msg (tr != NULL,
  92. "No test result received");
  93. ck_assert_msg (tr_ctx(tr) == CK_CTX_TEST,
  94. "Bad CTX received");
  95. ck_assert_msg (strcmp(tr_lfile(tr), "abc125.c") == 0,
  96. "Bad loc file received");
  97. ck_assert_msg (tr_lno(tr) == 25,
  98. "Bad loc line received");
  99. if (tr != NULL)
  100. tr_free(tr);
  101. }
  102. END_TEST
  103. START_TEST(test_send_with_passing_teardown)
  104. {
  105. TestResult *tr;
  106. setup_messaging();
  107. send_ctx_info(CK_CTX_SETUP);
  108. send_loc_info("abc123.c", 10);
  109. send_ctx_info(CK_CTX_TEST);
  110. send_loc_info("abc124.c", 22);
  111. send_loc_info("abc125.c", 25);
  112. send_ctx_info(CK_CTX_TEARDOWN);
  113. send_loc_info("abc126.c", 54);
  114. tr = receive_test_result(0);
  115. teardown_messaging();
  116. ck_assert_msg (tr != NULL,
  117. "No test result received");
  118. ck_assert_msg (tr_ctx(tr) == CK_CTX_TEST,
  119. "Bad CTX received");
  120. ck_assert_msg (tr_msg(tr) == NULL,
  121. "Bad failure msg received");
  122. ck_assert_msg (strcmp(tr_lfile(tr), "abc125.c") == 0,
  123. "Bad loc file received");
  124. ck_assert_msg (tr_lno(tr) == 25,
  125. "Bad loc line received");
  126. if (tr != NULL)
  127. tr_free(tr);
  128. }
  129. END_TEST
  130. START_TEST(test_send_with_error_teardown)
  131. {
  132. TestResult *tr;
  133. setup_messaging();
  134. send_ctx_info(CK_CTX_SETUP);
  135. send_loc_info("abc123.c", 10);
  136. send_ctx_info(CK_CTX_TEST);
  137. send_loc_info("abc124.c", 22);
  138. send_loc_info("abc125.c", 25);
  139. send_ctx_info(CK_CTX_TEARDOWN);
  140. send_loc_info("abc126.c", 54);
  141. tr = receive_test_result(1);
  142. teardown_messaging();
  143. ck_assert_msg (tr != NULL,
  144. "No test result received");
  145. ck_assert_msg (tr_ctx(tr) == CK_CTX_TEARDOWN,
  146. "Bad CTX received");
  147. ck_assert_msg (tr_msg(tr) == NULL,
  148. "Bad failure msg received");
  149. ck_assert_msg (strcmp(tr_lfile(tr), "abc126.c") == 0,
  150. "Bad loc file received");
  151. ck_assert_msg (tr_lno(tr) == 54,
  152. "Bad loc line received");
  153. if (tr != NULL)
  154. tr_free(tr);
  155. }
  156. END_TEST
  157. Suite *make_msg_suite (void)
  158. {
  159. Suite *s;
  160. TCase *tc;
  161. s = suite_create("Msg");
  162. tc = tcase_create("Core Tests");
  163. tcase_add_test(tc, test_send);
  164. tcase_add_test(tc, test_send_big);
  165. tcase_add_test(tc, test_send_test_error);
  166. tcase_add_test(tc, test_send_with_passing_teardown);
  167. tcase_add_test(tc, test_send_with_error_teardown);
  168. suite_add_tcase(s, tc);
  169. return s;
  170. }