libpropeller
Making PropellerGCC Easier
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
gpsparser.test.h
Go to the documentation of this file.
1 #include <string.h>
2 #include "unity.h"
4 
7 
8 
9 // TODO(SRLM) Get rid of the hardcoded test pins.
10 const int kPIN_USER_1 = 18;
11 const int kPIN_USER_2 = 19;
12 
13 /* Hardware:
14 All tests requires that pins 18 and 19 be connected by a resistor.
15  */
16 
18 
19 class UnityTests {
20 public:
21 
22  static void setUp(void) {
23  sut = new GPSParser();
24  sut->Start(kPIN_USER_1, kPIN_USER_2, 9600);
25  }
26 
27  static void tearDown(void) {
28  delete sut;
29  sut = NULL;
30  }
31 
32  static char FillBuffer(const char letter) {
33  sut->getSerial()->Put(letter);
34  return letter;
35  }
36 
37  static const char * FillBuffer(const char * string) {
38  for (int i = 0; string[i] != '\0'; i++) {
39  sut->getSerial()->Put(string[i]);
40  }
41 
42  return string;
43  }
44 
45  static void test_GetIncompleteString(void) {
46  //const char * line =
47  FillBuffer("$GPRMC,180252.087,V,,,,,0.00,0.");
48  TEST_ASSERT_EQUAL_INT(NULL, sut->Get());
49  }
50 
51  static void test_GetCompleteString(void) {
52  const char * line =
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);
55  }
56 
57  static void test_GetMultipleStringsNoWait(void) {
58  const char * line0 =
59  FillBuffer("$GPRMC,180252.087,V,,,,,0.00,0.00,290113,,,N*46\r\n");
60  const char * line1 =
61  FillBuffer("$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32\r\n");
62  const char * line2 =
63  FillBuffer("$GPRMC,1825035232574374,N*46\r\n");
64 
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);
68  }
69 
70  static void test_NullAfterString(void) {
71  const char * line =
72  FillBuffer("$GPRMC,180252.087,V,,,,,0.00,0.00,290113,,,N*46\r\n");
73 
74  TEST_ASSERT_EQUAL_MEMORY(line, sut->Get(), strlen(line) - 2);
75  TEST_ASSERT_EQUAL_INT(NULL, sut->Get());
76  }
77 
78  static void test_GetPartialStringAtBeginning(void) {
79  //const char * line0 =
80  FillBuffer(".00,N,0.00,K,N*32\r\n");
81  const char * line1 =
82  FillBuffer("$GPRMC,180252.087,V,,,,,0.00,0.00,290113,,,N*46\r\n");
83 
84  TEST_ASSERT_EQUAL_MEMORY(line1, sut->Get(), strlen(line1) - 2);
85  TEST_ASSERT_EQUAL_INT(NULL, sut->Get());
86 
87  }
88 
89  static void test_DiscardPgtopSentences(void) {
90  const char * line0 =
91  FillBuffer("$GPRMC,180252.087,V,,,,,0.00,0.00,290113,,,N*46\r\n");
92  //const char * line1 =
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");
97  const char * line2 =
98  FillBuffer("$GPRMC,1825035232574374,N*46\r\n");
99 
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);
103  }
104 
105  static void test_MaxBytesCutoff(void) {
106  const char * line0 = FillBuffer("$GPRMC Dummy Sentence");
107  char buffer[100];
108  TEST_ASSERT_EQUAL_MEMORY(line0, sut->Get(buffer, strlen(line0)+1), strlen(line0));
109  }
110 
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");
115  char buffer[100];
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);
118  }
119 
120  static void test_SwitchBetweenBuffers(void) {
121  const int kNmeaLength = 85;
122  char bufferA[kNmeaLength];
123  char bufferB[kNmeaLength];
124 
125  const char * line0 =
126  FillBuffer("$GPRMC,180252.087,V,,,,,0.00,0.00,290113,,,N*46\r\n");
127  const char * line1 =
128  FillBuffer("$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32\r\n");
129  const char * line2 =
130  FillBuffer("$GPRMC,1825035232574374,N*46\r\n");
131 
132 
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);
136 
137  }
138 };
139 /*
140 Sample GPS Data, no Fix:
141 
142 $GPRMC,180252.087,V,,,,,0.00,0.00,290113,,,N*46
143 $GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
144 $PGTOP,11,2*6E
145 $GPGGA,180253.087,,,,,0,0,,,M,,M,,*4A
146 $GPGSA,A,1,,,,,,,,,,,,,,,*1E
147 $GPRMC,180253.087,V,,,,,0.00,0.00,290113,,,N*47
148 $GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
149 $PGTOP,11,2*6E
150 $GPGGA,180254.087,,,,,0,0,,,M,,M,,*4D
151 $GPGSA,A,1,,,,,,,,,,,,,,,*1E
152 $GPRMC,180254.087,V,,,,,0.00,0.00,290113,,,N*40
153 $GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
154 $PGTOP,11,2*6E
155 $GPGGA,180255.087,,,,,0,0,,,M,,M,,*4C
156 $GPGSA,A,1,,,,,,,,,,,,,,,*1E
157 $GPGSV,1,1,00*79
158 $GPRMC,180255.087,V,,,,,0.00,0.00,290113,,,N*41
159 $GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
160 
161  */