00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <stdlib.h>
00041 #include <stdio.h>
00042 #include <string.h>
00043 #include <time.h>
00044
00045 #include "CUnit/Basic.h"
00046
00047 #include "ksm/message.h"
00048 #include "test_routines.h"
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 static char output_buffer[4096];
00060
00061 static void Output(const char* text)
00062 {
00063 strncpy(output_buffer, text, sizeof(output_buffer));
00064 output_buffer[sizeof(output_buffer) - 1] = '\0';
00065
00066 return;
00067 }
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 static void TestMsgInitRundown(void)
00080 {
00081 int BLOCK0_LOW = 10240;
00082 int BLOCK0_HIGH = 10245;
00083 const char* BLOCK0_MESSAGES[] = {
00084 "ALPHA", "BETA", "GAMMA", "DELTA", "EPSILON", "ZETA"
00085 };
00086
00087 MsgInit();
00088
00089
00090
00091 CU_ASSERT_EQUAL(MsgFindCodeBlock(BLOCK0_LOW), -1);
00092
00093
00094
00095 MsgRegister(BLOCK0_LOW, BLOCK0_HIGH, BLOCK0_MESSAGES, MsgNoOutput);
00096 CU_ASSERT_NOT_EQUAL(MsgFindCodeBlock(BLOCK0_LOW), -1);
00097
00098
00099
00100 MsgRundown();
00101 CU_ASSERT_EQUAL(MsgFindCodeBlock(BLOCK0_LOW), -1);
00102
00103 return;
00104 }
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 static void TestMsgRegisterText(void)
00117 {
00118 int i;
00119
00120 int BLOCK1_LOW = 20480;
00121 int BLOCK1_HIGH = 20485;
00122 const char* BLOCK1_MESSAGES[] = {
00123 "ALPHA", "BETA", "GAMMA", "DELTA", "EPSILON", "ZETA"
00124 };
00125
00126 int BLOCK2_LOW = 30720;
00127 int BLOCK2_HIGH = 30725;
00128 const char* BLOCK2_MESSAGES[] = {
00129 "ALEPH", "BETH", "GIMMEL", "DALET", "HEY", "VAV"
00130 };
00131
00132 MsgInit();
00133
00134
00135
00136 MsgRegister(BLOCK1_LOW, BLOCK1_HIGH, BLOCK1_MESSAGES, MsgNoOutput);
00137 MsgRegister(BLOCK2_LOW, BLOCK2_HIGH, BLOCK2_MESSAGES, MsgNoOutput);
00138
00139
00140
00141 for (i = BLOCK1_LOW; i <= BLOCK1_HIGH; ++i) {
00142 CU_ASSERT_STRING_EQUAL(MsgText(i), BLOCK1_MESSAGES[i - BLOCK1_LOW]);
00143 }
00144
00145 for (i = BLOCK2_LOW; i <= BLOCK2_HIGH; ++i) {
00146 CU_ASSERT_STRING_EQUAL(MsgText(i), BLOCK2_MESSAGES[i - BLOCK2_LOW]);
00147 }
00148
00149 MsgRundown();
00150
00151 return;
00152 }
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162 static void TestMsgGetSetOutput(void)
00163 {
00164 int BLOCK3_LOW = 40960;
00165 int BLOCK3_HIGH = 40965;
00166 const char* BLOCK3_MESSAGES[] = {
00167 "A", "B", "C", "D", "E", "F"
00168 };
00169
00170 MsgInit();
00171
00172
00173
00174
00175
00176
00177
00178 MsgRegister(BLOCK3_LOW, BLOCK3_HIGH, BLOCK3_MESSAGES, MsgNoOutput);
00179 CU_ASSERT_PTR_EQUAL((void*) MsgGetOutput(BLOCK3_LOW), (void*) MsgNoOutput);
00180
00181
00182
00183 MsgSetOutput(BLOCK3_HIGH, MsgDefaultOutput);
00184 CU_ASSERT_PTR_EQUAL((void*) MsgGetOutput(BLOCK3_LOW), (void*) MsgDefaultOutput);
00185
00186 MsgRundown();
00187
00188 return;
00189 }
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 static void TestMsgLog(void)
00200 {
00201 int BLOCK4_LOW = 51200;
00202 int BLOCK4_HIGH = 51201;
00203 const char* BLOCK4_MESSAGES[] = {
00204 "There are %d %ss in the store",
00205 "%d %ss a %s"
00206 };
00207 int status;
00208
00209 MsgInit();
00210
00211 MsgRegister(BLOCK4_LOW, BLOCK4_HIGH, BLOCK4_MESSAGES, Output);
00212
00213 status = MsgLog(BLOCK4_LOW, 15, "orange");
00214 CU_ASSERT_EQUAL(status, BLOCK4_LOW);
00215 CU_ASSERT_STRING_EQUAL(output_buffer, "There are 15 oranges in the store");
00216
00217 status = MsgLog(BLOCK4_HIGH, 10, "lord", "leaping");
00218 CU_ASSERT_EQUAL(status, BLOCK4_HIGH);
00219 CU_ASSERT_STRING_EQUAL(output_buffer, "10 lords a leaping");
00220
00221 MsgRundown();
00222
00223 return;
00224 }
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242 int TestMsg(void);
00243 int TestMsg(void)
00244 {
00245 struct test_testdef tests[] = {
00246 {"TestMsgInitRundown", TestMsgInitRundown},
00247 {"TestMsgRegisterText", TestMsgRegisterText},
00248 {"TestMsgGetSetOutput", TestMsgGetSetOutput},
00249 {"TestMsgLog", TestMsgLog},
00250 {NULL, NULL}
00251 };
00252
00253 return TcuCreateSuite("Msg", NULL, NULL, tests);
00254 }