test_packet.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * C++ unit test for dispatch.h
3  *********************************************************************/
4 
5 #include <gtest/gtest.h>
6 
7 // File under test
8 #include "../src/dispatch.h"
9 
10 // Test verifying packet sync byte
11 TEST(PACKET, sync)
12 {
13  // Test the validatePacket() function
14  Packet packet;
15  memset(&packet, 0x00, sizeof(packet));
16  packet.sync = 0xE7 + 1;
17  while (packet.sync != 0xE7) {
18  ASSERT_FALSE(validatePacket(&packet));
19  packet.sync++;
20  }
21  ASSERT_TRUE(validatePacket(&packet));
22 }
23 
24 // Test verifying packet checksum
25 TEST(PACKET, chksum3)
26 {
27  Packet packet;
28 
29  // Packet of all zero
30  memset(&packet, 0x00, sizeof(packet));
31  packet.sync = 0xE7;
32  packet.chksum3 = 0x00;
33  ASSERT_TRUE(validatePacket(&packet));
34  packet.chksum3++;
35  while (packet.chksum3 != 0x00) {
36  ASSERT_FALSE(validatePacket(&packet));
37  packet.chksum3++;
38  }
39 
40  // Packet of all 13
41  memset(&packet, 13, sizeof(packet));
42  packet.sync = 0xE7;
43  packet.chksum3 = (uint8_t)(13*70);
44  ASSERT_TRUE(validatePacket(&packet));
45  packet.chksum3++;
46  while (packet.chksum3 != (uint8_t)(13*70)) {
47  ASSERT_FALSE(validatePacket(&packet));
48  packet.chksum3++;
49  }
50 
51  // Packet of all 191
52  memset(&packet, 191, sizeof(packet));
53  packet.sync = 0xE7;
54  packet.chksum3 = (uint8_t)(191*70);
55  ASSERT_TRUE(validatePacket(&packet));
56  packet.chksum3++;
57  while (packet.chksum3 != (uint8_t)(191*70)) {
58  ASSERT_FALSE(validatePacket(&packet));
59  packet.chksum3++;
60  }
61 }
62 
63 int main(int argc, char **argv)
64 {
65  testing::InitGoogleTest(&argc, argv);
66  return RUN_ALL_TESTS();
67 }
68 
TEST(PACKET, sync)
Definition: test_packet.cpp:11
static bool validatePacket(const Packet *packet)
Definition: dispatch.h:151
int main(int argc, char **argv)
Definition: test_packet.cpp:63
uint8_t sync
Definition: dispatch.h:90
uint8_t chksum3
Definition: dispatch.h:112


oxford_gps_eth
Author(s): Kevin Hallenbeck
autogenerated on Sun Aug 9 2020 04:05:34