libpropeller
Making PropellerGCC Easier
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
full_duplex_serial.test.h
Go to the documentation of this file.
1 #include <propeller.h>
2 #include "unity.h"
3 #include "full_duplex_serial.h"
4 #include "c++-alloc.h"
5 #include "string.h"
6 
7 #include "board/board_unit_tester.h"
8 
9 const int rxpin = Board::kPinTie1a;
10 const int txpin = Board::kPinTie1b;
11 const int baud = 230400;
12 
13 const int TIMEOUT = 10;
14 
16 
17 class UnityTests {
18 public:
19 
20  static void setUp(void) {
21  sut = new FullDuplexSerial();
22  sut->Start(rxpin, txpin, 0, baud);
23  }
24 
25  static void tearDown(void) {
26  sut->Stop();
27  delete sut;
28  sut = NULL;
29  }
30 
31  static void test_BasicRxTx(void) {
32  char letter = 'A';
33  sut->Put(letter);
34  TEST_ASSERT_EQUAL_INT(letter, sut->Get());
35  }
36 
37  static void test_RxcheckWithNothingInBuffer(void) {
38  TEST_ASSERT_EQUAL_INT(-1, sut->Get(TIMEOUT));
39  }
40 
41  static void test_BasicRxCheckTx(void) {
42  char letter = 'C';
43  sut->Put('C');
44  waitcnt(CLKFREQ / 100 + CNT);
45  TEST_ASSERT_EQUAL_INT(letter, sut->Get(TIMEOUT));
46  }
47 
48  static void test_PutGetMultipleBytes(void) {
49  for (char letter = 'a'; letter <= 'z'; letter++) {
50  sut->Put(letter);
51  waitcnt(CLKFREQ / 100 + CNT);
52  TEST_ASSERT_EQUAL_INT(letter, sut->Get());
53  }
54  }
55 
56  static void test_RxflushClearsBuffer(void) {
57  char letter1 = 'E';
58  char letter2 = 'F';
59  sut->Put(letter1);
60  waitcnt(CLKFREQ / 100 + CNT);
61  sut->GetFlush();
62  sut->Put(letter2);
63  waitcnt(CLKFREQ / 100 + CNT);
64 
65  sut->Get(0);
66  TEST_ASSERT_EQUAL_INT(-1, sut->Get(TIMEOUT));
67  }
68 
69  static void test_PutLongString(void) {
70  char string [] = "Hello, World! I'm a Propeller. What are you?";
71  int length = strlen(string);
72  sut->Put(string);
73  waitcnt(CLKFREQ / 100 + CNT);
74 
75  for (int i = 0; i < length; i++) {
76  TEST_ASSERT_EQUAL_INT(string[i], sut->Get(TIMEOUT));
77  }
78 
79  TEST_ASSERT_EQUAL_INT(-1, sut->Get(TIMEOUT));
80 
81  }
82 
83  static void test_PutEmptyString(void) {
84  char string [] = "";
85  sut->Put(string);
86  waitcnt(CLKFREQ / 100 + CNT);
87  TEST_ASSERT_EQUAL_INT(-1, sut->Get(TIMEOUT));
88  }
89 
90 };