1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
#include "../lib/libcompat.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "check.h"
#include "check_msg.h"
#include "check_check.h"
START_TEST(test_send)
{
TestResult *tr;
setup_messaging();
send_ctx_info(CK_CTX_SETUP);
send_loc_info("abc123.c", 10);
send_ctx_info(CK_CTX_TEST);
send_loc_info("abc124.c", 22);
send_loc_info("abc125.c", 25);
send_failure_info("Oops");
tr = receive_test_result(0);
teardown_messaging();
fail_unless (tr != NULL,
"No test result received");
fail_unless (tr_ctx(tr) == CK_CTX_TEST,
"Bad CTX received");
fail_unless (strcmp(tr_msg(tr), "Oops") == 0,
"Bad failure msg received");
fail_unless (strcmp(tr_lfile(tr), "abc125.c") == 0,
"Bad loc file received");
fail_unless (tr_lno(tr) == 25,
"Bad loc line received");
if (tr != NULL)
free(tr);
}
END_TEST
START_TEST(test_send_big)
{
TestResult *tr;
int i;
setup_messaging();
send_ctx_info(CK_CTX_SETUP);
send_loc_info("abc123.c", 10);
for (i = 0; i < 10000; i++) {
send_ctx_info(CK_CTX_TEST);
send_loc_info("abc124.c", i);
}
tr = receive_test_result(0);
teardown_messaging();
fail_unless (tr != NULL,
"No test result received");
fail_unless (tr_ctx(tr) == CK_CTX_TEST,
"Bad CTX received");
fail_unless (strcmp(tr_lfile(tr), "abc124.c") == 0,
"Bad loc file received");
fail_unless (tr_lno(tr) == i -1,
"Bad loc line received");
if (tr != NULL)
free(tr);
}
END_TEST
START_TEST(test_send_test_error)
{
TestResult *tr;
setup_messaging();
send_ctx_info(CK_CTX_SETUP);
send_loc_info("abc123.c", 10);
send_ctx_info(CK_CTX_TEST);
send_loc_info("abc124.c", 22);
send_loc_info("abc125.c", 25);
tr = receive_test_result(1);
teardown_messaging();
fail_unless (tr != NULL,
"No test result received");
fail_unless (tr_ctx(tr) == CK_CTX_TEST,
"Bad CTX received");
fail_unless (strcmp(tr_lfile(tr), "abc125.c") == 0,
"Bad loc file received");
fail_unless (tr_lno(tr) == 25,
"Bad loc line received");
if (tr != NULL)
free(tr);
}
END_TEST
START_TEST(test_send_with_passing_teardown)
{
TestResult *tr;
setup_messaging();
send_ctx_info(CK_CTX_SETUP);
send_loc_info("abc123.c", 10);
send_ctx_info(CK_CTX_TEST);
send_loc_info("abc124.c", 22);
send_loc_info("abc125.c", 25);
send_ctx_info(CK_CTX_TEARDOWN);
send_loc_info("abc126.c", 54);
tr = receive_test_result(0);
teardown_messaging();
fail_unless (tr != NULL,
"No test result received");
fail_unless (tr_ctx(tr) == CK_CTX_TEST,
"Bad CTX received");
fail_unless (tr_msg(tr) == NULL,
"Bad failure msg received");
fail_unless (strcmp(tr_lfile(tr), "abc125.c") == 0,
"Bad loc file received");
fail_unless (tr_lno(tr) == 25,
"Bad loc line received");
if (tr != NULL)
free(tr);
}
END_TEST
START_TEST(test_send_with_error_teardown)
{
TestResult *tr;
setup_messaging();
send_ctx_info(CK_CTX_SETUP);
send_loc_info("abc123.c", 10);
send_ctx_info(CK_CTX_TEST);
send_loc_info("abc124.c", 22);
send_loc_info("abc125.c", 25);
send_ctx_info(CK_CTX_TEARDOWN);
send_loc_info("abc126.c", 54);
tr = receive_test_result(1);
teardown_messaging();
fail_unless (tr != NULL,
"No test result received");
fail_unless (tr_ctx(tr) == CK_CTX_TEARDOWN,
"Bad CTX received");
fail_unless (tr_msg(tr) == NULL,
"Bad failure msg received");
fail_unless (strcmp(tr_lfile(tr), "abc126.c") == 0,
"Bad loc file received");
fail_unless (tr_lno(tr) == 54,
"Bad loc line received");
if (tr != NULL)
free(tr);
}
END_TEST
Suite *make_msg_suite (void)
{
Suite *s;
TCase *tc;
s = suite_create("Msg");
tc = tcase_create("Core Tests");
tcase_add_test(tc, test_send);
tcase_add_test(tc, test_send_big);
tcase_add_test(tc, test_send_test_error);
tcase_add_test(tc, test_send_with_passing_teardown);
tcase_add_test(tc, test_send_with_error_teardown);
suite_add_tcase(s, tc);
return s;
}
|