31 static void setUp(
void) {
35 static void tearDown(
void) {
41 static void test_PinsConnected(
void) {
49 TEST_ASSERT_TRUE((
INA & (1 <<
ctspin)) != 0);
52 TEST_ASSERT_TRUE((
INA & (1 <<
ctspin)) == 0);
60 TEST_ASSERT_TRUE((
INA & (1 <<
rxpin)) != 0);
63 TEST_ASSERT_TRUE((
INA & (1 <<
rxpin)) == 0);
66 static void test_Start(
void) {
69 TEST_ASSERT_TRUE(result);
72 static void test_SetsPinDirectionsCorrectly(
void) {
81 const char value =
'A';
83 TEST_ASSERT_EQUAL_INT(value, sut.
Get(
MAXTIME));
86 static void cog_DoNothing(
void * arg) {
87 waitcnt(CLKFREQ * 50 + CNT);
90 static int help_CountNumberOfFreeCogs(
void) {
91 const int stacksize =
sizeof (_thread_state_t) +
sizeof (
int) * 10;
92 int * cog_stack = (
int*) malloc(stacksize);
93 int cog_id = cogstart(cog_DoNothing, NULL, cog_stack, stacksize);
98 free_cogs = help_CountNumberOfFreeCogs() + 1;
107 static void test_StopStopsCog(
void) {
108 int beforeCount = help_CountNumberOfFreeCogs();
110 TEST_ASSERT_EQUAL_INT(beforeCount + 1, help_CountNumberOfFreeCogs());
113 static void test_DestructorCallsStop(
void) {
116 int beforeCount = help_CountNumberOfFreeCogs();
120 TEST_ASSERT_EQUAL_INT(beforeCount - 1, help_CountNumberOfFreeCogs());
123 TEST_ASSERT_EQUAL_INT(beforeCount, help_CountNumberOfFreeCogs());
130 static void test_PutCGetC(
void) {
135 static void test_PutCGetCLowerByteBound(
void) {
140 static void test_PutCGetCUpperByteBound(
void) {
145 static void test_GetCCheckNoPutC(
void) {
149 static void test_GetCCheck(
void) {
154 static void test_GetCCheckNoWait(
void) {
156 TEST_ASSERT_EQUAL_INT(
'T', sut.
Get(1));
159 static void test_GetCCheckTimeTimeout(
void) {
160 TEST_ASSERT_EQUAL_INT(-1, sut.
Get(1));
163 static void test_GetCValidateTimeoutDuration(
void) {
165 const int kTimeoutDuration = 10 * 1000;
166 const int kMaximumTimeoutDelta = 100;
168 for (
int i = 0; i < 10; i++) {
169 unsigned int start_CNT = CNT;
170 sut.
Get(kTimeoutDuration / 1000);
171 unsigned int actual_timeout_duration = (CNT - start_CNT) / (CLKFREQ / 1000000);
172 TEST_ASSERT_INT_WITHIN(kMaximumTimeoutDelta, kTimeoutDuration, actual_timeout_duration);
178 static void test_RxTxNoExtraTxChars(
void) {
188 static void test_PutBufferFormatted(
void) {
207 static void test_PutBufferNoPointer(
void) {
208 TEST_ASSERT_EQUAL_INT(0, sut.
PutFormatted((
char *) NULL));
223 static void test_PutS(
void) {
255 static void test_GetFlush(
void) {
258 waitcnt(CLKFREQ / 100 + CNT);
263 static void test_GetFlushEmptyBuffer(
void) {
275 static void test_SetBaud(
void) {
276 TEST_ASSERT_TRUE(sut.
SetBaud(9600));
279 static void test_SetBaudTooHigh(
void) {
280 TEST_ASSERT_EQUAL_INT(0, sut.
SetBaud(1000000));
283 static void test_SetBaudToZero(
void) {
284 TEST_ASSERT_EQUAL_INT(0, sut.
SetBaud(0));
287 static void test_SetBaudTransmitAfterBaudChange(
void) {
293 static void test_Setbaudclock(
void) {
299 static void test_PutPrintfReturnsWrittenBytes(
void) {
301 char inputBuffer[size];
303 TEST_ASSERT_EQUAL_INT(17, sut.
PutFormatted(
"My:%i, Your:%i", 123, -531));
304 TEST_ASSERT_EQUAL_INT(17, sut.
Get(inputBuffer, 17,
MAXTIME));
308 static void test_PutPrintfBasic(
void) {
311 char inputBuffer[size];
312 for (
int i = 0; i < size; i++) {
318 TEST_ASSERT_EQUAL_STRING(
"My number: 123.", inputBuffer);
323 static void test_PutPrintfMultipleIntegers(
void) {
325 char inputBuffer[size];
326 for (
int i = 0; i < size; i++) {
332 TEST_ASSERT_EQUAL_STRING(
"My:123, Your:-531", inputBuffer);
335 static void test_PutPrintfNoSpecifiers(
void) {
336 char string[] =
"Hello, World.";
338 char inputBuffer[size];
339 for (
int i = 0; i < size; i++) {
345 TEST_ASSERT_EQUAL_STRING(
string, inputBuffer);
348 static void test_PutPrintfHexSpecifiers(
void) {
350 char inputBuffer[size];
351 for (
int i = 0; i < size; i++) {
356 TEST_ASSERT_EQUAL_STRING(
"My:AB, Your:CDE", inputBuffer);
359 static void test_PutPrintfDecpad(
void) {
361 char inputBuffer[size];
362 for (
int i = 0; i < size; i++) {
367 TEST_ASSERT_EQUAL_STRING(
"My: 1234", inputBuffer);
370 static void test_PutPrintfDecpadSmaller(
void) {
372 char inputBuffer[size];
373 for (
int i = 0; i < size; i++) {
378 TEST_ASSERT_EQUAL_STRING(
"My:1234", inputBuffer);
381 static void test_PutPrinfHexpad(
void) {
383 char inputBuffer[size];
384 for (
int i = 0; i < size; i++) {
389 TEST_ASSERT_EQUAL_STRING(
"My: 1234", inputBuffer);
392 static void test_PutPrinfHexpadTooSmall(
void) {
394 char inputBuffer[size];
395 for (
int i = 0; i < size; i++) {
400 TEST_ASSERT_EQUAL_STRING(
"My:1234", inputBuffer);
403 static void test_PutPrinfHexpadZero(
void) {
405 char inputBuffer[size];
406 for (
int i = 0; i < size; i++) {
411 TEST_ASSERT_EQUAL_STRING(
"My:0000001234", inputBuffer);
414 static void test_PutPrintfChar(
void) {
416 char inputBuffer[size];
417 for (
int i = 0; i < size; i++) {
422 TEST_ASSERT_EQUAL_STRING(
"My:a", inputBuffer);
425 static void test_PutPrintfString(
void) {
427 char inputBuffer[size];
428 for (
int i = 0; i < size; i++) {
433 TEST_ASSERT_EQUAL_STRING(
"My:World", inputBuffer);
436 static void test_PutPrinfAllTogether(
void) {
438 char inputBuffer[size];
439 for (
int i = 0; i < size; i++) {
442 sut.
PutFormatted(
"%x%i%s%c%03x%4i", 0x23, 32,
"hello",
'w', 0xF, 13);
444 TEST_ASSERT_EQUAL_STRING(
"2332hellow00F 13", inputBuffer);
447 static void test_PutPrintfPercentSignAtEndOfStringDisappears(
void) {
448 const int size = strlen(
"Hello");
449 char inputBuffer[size];
453 TEST_ASSERT_EQUAL_MEMORY(
"Hello''", inputBuffer, size);
457 static void test_PutPrintfTwoPercentSigns(
void) {
458 const int size = strlen(
"Hello% ");
459 char inputBuffer[size];
462 TEST_ASSERT_EQUAL_MEMORY(
"Hello% ", inputBuffer, size);
467 static void test_GetBuffer(
void) {
468 char string[] =
"Hello World!";
470 char inputBuffer[size + 1];
471 inputBuffer[size] = 0;
473 TEST_ASSERT_EQUAL_INT(size, sut.
Get(inputBuffer, size,
MAXTIME));
474 TEST_ASSERT_EQUAL_STRING(
string, inputBuffer);
477 static void test_GetBufferString(
void) {
478 char string[] =
"Hello World!\n";
482 TEST_ASSERT_EQUAL_INT(size, sut.
Get(buffer,
'\n'));
483 TEST_ASSERT_EQUAL_STRING(
string, buffer);
488 static void transmitAlphabet(
void * param) {
490 for (
int i =
'A'; i <=
'z'; i++) {
492 waitcnt(CLKFREQ / 1000 + CNT);
499 static void test_CTSPinBasic(
void) {
503 int stacksize =
sizeof (_thread_state_t) +
sizeof (
int)*8;
504 int *
stack = (
int*) malloc(stacksize);
505 cogstart(transmitAlphabet, NULL, stack, stacksize);
507 waitcnt(CLKFREQ * 5 / 1000 + CNT);
516 while (current != -1) {
525 waitcnt(CLKFREQ / 10 + CNT);
527 for (
int i = last + 1; i <=
'z'; i++) {
531 TEST_ASSERT_EQUAL_INT(-1, sut.
Get(0));
536 static void test_PutBuffer(
void) {
537 char data [] =
"Hello, long string!";
538 const int length = strlen(data) + 1;
540 char inputbuffer[length];
542 TEST_ASSERT_EQUAL_INT(length, sut.
Put(data, length));
546 TEST_ASSERT_EQUAL_STRING(data, inputbuffer);
550 static void test_PutBufferNullTerminatedString(
void) {
551 char data [] =
"Hello, long string!";
552 const int length = strlen(data);
554 char inputbuffer[length];
556 TEST_ASSERT_EQUAL_INT(length, sut.
Put(data));
560 TEST_ASSERT_EQUAL_MEMORY(data, inputbuffer, length);
566 static void test_GetCountEmpty(
void) {
567 TEST_ASSERT_EQUAL_INT(0, sut.
GetCount());
570 static void test_GetCountOne(
void) {
572 waitcnt(CLKFREQ / 100 + CNT);
573 TEST_ASSERT_EQUAL_INT(1, sut.
GetCount());
576 static void test_GetCountFew(
void) {
580 waitcnt(CLKFREQ / 100 + CNT);
584 static void test_GetCountWrapAround(
void) {
594 waitcnt(CLKFREQ / 100 + CNT);
595 TEST_ASSERT_EQUAL_INT(3, sut.
GetCount());