43 #include "CUnit/Basic.h"
57 static char output_buffer[4096];
59 static void Output(
const char* text)
61 strncpy(output_buffer, text,
sizeof(output_buffer));
62 output_buffer[
sizeof(output_buffer) - 1] =
'\0';
77 static void TestMsgInitRundown(
void)
79 int BLOCK0_LOW = 10240;
80 int BLOCK0_HIGH = 10245;
81 const char* BLOCK0_MESSAGES[] = {
82 "ALPHA",
"BETA",
"GAMMA",
"DELTA",
"EPSILON",
"ZETA"
114 static void TestMsgRegisterText(
void)
118 int BLOCK1_LOW = 20480;
119 int BLOCK1_HIGH = 20485;
120 const char* BLOCK1_MESSAGES[] = {
121 "ALPHA",
"BETA",
"GAMMA",
"DELTA",
"EPSILON",
"ZETA"
124 int BLOCK2_LOW = 30720;
125 int BLOCK2_HIGH = 30725;
126 const char* BLOCK2_MESSAGES[] = {
127 "ALEPH",
"BETH",
"GIMMEL",
"DALET",
"HEY",
"VAV"
139 for (i = BLOCK1_LOW; i <= BLOCK1_HIGH; ++i) {
140 CU_ASSERT_STRING_EQUAL(
MsgText(i), BLOCK1_MESSAGES[i - BLOCK1_LOW]);
143 for (i = BLOCK2_LOW; i <= BLOCK2_HIGH; ++i) {
144 CU_ASSERT_STRING_EQUAL(
MsgText(i), BLOCK2_MESSAGES[i - BLOCK2_LOW]);
160 static void TestMsgGetSetOutput(
void)
162 int BLOCK3_LOW = 40960;
163 int BLOCK3_HIGH = 40965;
164 const char* BLOCK3_MESSAGES[] = {
165 "A",
"B",
"C",
"D",
"E",
"F"
197 static void TestMsgLog(
void)
199 int BLOCK4_LOW = 51200;
200 int BLOCK4_HIGH = 51201;
201 const char* BLOCK4_MESSAGES[] = {
202 "There are %d %ss in the store",
209 MsgRegister(BLOCK4_LOW, BLOCK4_HIGH, BLOCK4_MESSAGES, Output);
211 status =
MsgLog(BLOCK4_LOW, 15,
"orange");
212 CU_ASSERT_EQUAL(status, BLOCK4_LOW);
213 CU_ASSERT_STRING_EQUAL(output_buffer,
"There are 15 oranges in the store");
215 status =
MsgLog(BLOCK4_HIGH, 10,
"lord",
"leaping");
216 CU_ASSERT_EQUAL(status, BLOCK4_HIGH);
217 CU_ASSERT_STRING_EQUAL(output_buffer,
"10 lords a leaping");
244 {
"TestMsgInitRundown", TestMsgInitRundown},
245 {
"TestMsgRegisterText", TestMsgRegisterText},
246 {
"TestMsgGetSetOutput", TestMsgGetSetOutput},
247 {
"TestMsgLog", TestMsgLog},