22 static void setUp(
void) {
27 static void tearDown(
void) {
32 static char FillBuffer(
const char letter) {
33 sut->getSerial()->
Put(letter);
37 static const char * FillBuffer(
const char *
string) {
38 for (
int i = 0;
string[i] !=
'\0'; i++) {
39 sut->getSerial()->
Put(
string[i]);
45 static void test_GetIncompleteString(
void) {
47 FillBuffer(
"$GPRMC,180252.087,V,,,,,0.00,0.");
48 TEST_ASSERT_EQUAL_INT(NULL, sut->
Get());
51 static void test_GetCompleteString(
void) {
53 FillBuffer(
"$GPRMC,180252.087,V,,,,,0.00,0.00,290113,,,N*46\r\n");
54 TEST_ASSERT_EQUAL_MEMORY(line, sut->
Get(), strlen(line) - 2);
57 static void test_GetMultipleStringsNoWait(
void) {
59 FillBuffer(
"$GPRMC,180252.087,V,,,,,0.00,0.00,290113,,,N*46\r\n");
61 FillBuffer(
"$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32\r\n");
63 FillBuffer(
"$GPRMC,1825035232574374,N*46\r\n");
65 TEST_ASSERT_EQUAL_MEMORY(line0, sut->
Get(), strlen(line0) - 2);
66 TEST_ASSERT_EQUAL_MEMORY(line1, sut->
Get(), strlen(line1) - 2);
67 TEST_ASSERT_EQUAL_MEMORY(line2, sut->
Get(), strlen(line2) - 2);
70 static void test_NullAfterString(
void) {
72 FillBuffer(
"$GPRMC,180252.087,V,,,,,0.00,0.00,290113,,,N*46\r\n");
74 TEST_ASSERT_EQUAL_MEMORY(line, sut->
Get(), strlen(line) - 2);
75 TEST_ASSERT_EQUAL_INT(NULL, sut->
Get());
78 static void test_GetPartialStringAtBeginning(
void) {
80 FillBuffer(
".00,N,0.00,K,N*32\r\n");
82 FillBuffer(
"$GPRMC,180252.087,V,,,,,0.00,0.00,290113,,,N*46\r\n");
84 TEST_ASSERT_EQUAL_MEMORY(line1, sut->
Get(), strlen(line1) - 2);
85 TEST_ASSERT_EQUAL_INT(NULL, sut->
Get());
89 static void test_DiscardPgtopSentences(
void) {
91 FillBuffer(
"$GPRMC,180252.087,V,,,,,0.00,0.00,290113,,,N*46\r\n");
93 FillBuffer(
"$PGTOP,11,2*6E\r\n");
94 FillBuffer(
"$PGTOP,11,2O23052*6E\r\n");
95 FillBuffer(
"$PGTOP,11,240509172450125270*6E\r\n");
96 FillBuffer(
"$PGTOP,[){*}){[*}*+{[)+*11,2*6E\r\n");
98 FillBuffer(
"$GPRMC,1825035232574374,N*46\r\n");
100 TEST_ASSERT_EQUAL_MEMORY(line0, sut->
Get(), strlen(line0) - 2);
101 TEST_ASSERT_EQUAL_MEMORY(line2, sut->
Get(), strlen(line2) - 2);
102 TEST_ASSERT_TRUE(sut->
Get() == NULL);
105 static void test_MaxBytesCutoff(
void) {
106 const char * line0 = FillBuffer(
"$GPRMC Dummy Sentence");
108 TEST_ASSERT_EQUAL_MEMORY(line0, sut->
Get(buffer, strlen(line0)+1), strlen(line0));
111 static void test_MaxBytesCutoffWithMoreBytesInBuffer(
void) {
112 const char * line0 = FillBuffer(
"$GPRMC Dummy Sentence");
113 FillBuffer(
"Some noise...");
114 const char * line1 = FillBuffer(
"$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32\r\n");
116 TEST_ASSERT_EQUAL_MEMORY(line0, sut->
Get(buffer, strlen(line0)+1), strlen(line0));
117 TEST_ASSERT_EQUAL_MEMORY(line1, sut->
Get(), strlen(line1) - 2);
120 static void test_SwitchBetweenBuffers(
void) {
121 const int kNmeaLength = 85;
122 char bufferA[kNmeaLength];
123 char bufferB[kNmeaLength];
126 FillBuffer(
"$GPRMC,180252.087,V,,,,,0.00,0.00,290113,,,N*46\r\n");
128 FillBuffer(
"$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32\r\n");
130 FillBuffer(
"$GPRMC,1825035232574374,N*46\r\n");
133 TEST_ASSERT_EQUAL_MEMORY(line0, sut->
Get(bufferA, kNmeaLength), strlen(line0) - 2);
134 TEST_ASSERT_EQUAL_MEMORY(line1, sut->
Get(bufferB, kNmeaLength), strlen(line1) - 2);
135 TEST_ASSERT_EQUAL_MEMORY(line2, sut->
Get(bufferA, kNmeaLength), strlen(line2) - 2);