45 #include "CUnit/Basic.h"
59 static char output_buffer[4096];
61 static void Output(
const char* text)
63 strncpy(output_buffer, text,
sizeof(output_buffer));
64 output_buffer[
sizeof(output_buffer) - 1] =
'\0';
79 static void TestMsgInitRundown(
void)
81 int BLOCK0_LOW = 10240;
82 int BLOCK0_HIGH = 10245;
83 const char* BLOCK0_MESSAGES[] = {
84 "ALPHA",
"BETA",
"GAMMA",
"DELTA",
"EPSILON",
"ZETA"
116 static void TestMsgRegisterText(
void)
120 int BLOCK1_LOW = 20480;
121 int BLOCK1_HIGH = 20485;
122 const char* BLOCK1_MESSAGES[] = {
123 "ALPHA",
"BETA",
"GAMMA",
"DELTA",
"EPSILON",
"ZETA"
126 int BLOCK2_LOW = 30720;
127 int BLOCK2_HIGH = 30725;
128 const char* BLOCK2_MESSAGES[] = {
129 "ALEPH",
"BETH",
"GIMMEL",
"DALET",
"HEY",
"VAV"
141 for (i = BLOCK1_LOW; i <= BLOCK1_HIGH; ++i) {
142 CU_ASSERT_STRING_EQUAL(
MsgText(i), BLOCK1_MESSAGES[i - BLOCK1_LOW]);
145 for (i = BLOCK2_LOW; i <= BLOCK2_HIGH; ++i) {
146 CU_ASSERT_STRING_EQUAL(
MsgText(i), BLOCK2_MESSAGES[i - BLOCK2_LOW]);
162 static void TestMsgGetSetOutput(
void)
164 int BLOCK3_LOW = 40960;
165 int BLOCK3_HIGH = 40965;
166 const char* BLOCK3_MESSAGES[] = {
167 "A",
"B",
"C",
"D",
"E",
"F"
199 static void TestMsgLog(
void)
201 int BLOCK4_LOW = 51200;
202 int BLOCK4_HIGH = 51201;
203 const char* BLOCK4_MESSAGES[] = {
204 "There are %d %ss in the store",
211 MsgRegister(BLOCK4_LOW, BLOCK4_HIGH, BLOCK4_MESSAGES, Output);
213 status =
MsgLog(BLOCK4_LOW, 15,
"orange");
214 CU_ASSERT_EQUAL(status, BLOCK4_LOW);
215 CU_ASSERT_STRING_EQUAL(output_buffer,
"There are 15 oranges in the store");
217 status =
MsgLog(BLOCK4_HIGH, 10,
"lord",
"leaping");
218 CU_ASSERT_EQUAL(status, BLOCK4_HIGH);
219 CU_ASSERT_STRING_EQUAL(output_buffer,
"10 lords a leaping");
246 {
"TestMsgInitRundown", TestMsgInitRundown},
247 {
"TestMsgRegisterText", TestMsgRegisterText},
248 {
"TestMsgGetSetOutput", TestMsgGetSetOutput},
249 {
"TestMsgLog", TestMsgLog},
void MsgNoOutput(const char *text)
int TcuCreateSuite(const char *title, int(*init)(), int(*teardown)(), struct test_testdef *tests)
int MsgLog(int status,...)
const char * MsgText(int status)
MSG_OUTPUT_FUNCTION MsgGetOutput(int status)
int MsgFindCodeBlock(int status)
void MsgRegister(int min, int max, const char **message, MSG_OUTPUT_FUNCTION output)
void MsgSetOutput(int code, MSG_OUTPUT_FUNCTION output)
void MsgDefaultOutput(const char *text)