test_packet.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  * C++ unit test for dispatch.h
00003  *********************************************************************/
00004 
00005 #include <gtest/gtest.h>
00006 
00007 // File under test
00008 #include "../src/dispatch.h"
00009 
00010 // Test verifying packet sync byte
00011 TEST(PACKET, sync)
00012 {
00013   // Test the validatePacket() function
00014   Packet packet;
00015   memset(&packet, 0x00, sizeof(packet));
00016   packet.sync = 0xE7 + 1;
00017   while (packet.sync != 0xE7) {
00018     ASSERT_FALSE(validatePacket(&packet));
00019     packet.sync++;
00020   }
00021   ASSERT_TRUE(validatePacket(&packet));
00022 
00023   // Call the unused dispatchAssertSizes() function to get full test coverage
00024   dispatchAssertSizes();
00025 }
00026 
00027 // Test verifying packet checksum
00028 TEST(PACKET, chksum3)
00029 {
00030   Packet packet;
00031 
00032   // Packet of all zero
00033   memset(&packet, 0x00, sizeof(packet));
00034   packet.sync = 0xE7;
00035   packet.chksum3 = 0x00;
00036   ASSERT_TRUE(validatePacket(&packet));
00037   packet.chksum3++;
00038   while (packet.chksum3 != 0x00) {
00039     ASSERT_FALSE(validatePacket(&packet));
00040     packet.chksum3++;
00041   }
00042 
00043   // Packet of all 13
00044   memset(&packet, 13, sizeof(packet));
00045   packet.sync = 0xE7;
00046   packet.chksum3 = (uint8_t)(13*70);
00047   ASSERT_TRUE(validatePacket(&packet));
00048   packet.chksum3++;
00049   while (packet.chksum3 != (uint8_t)(13*70)) {
00050     ASSERT_FALSE(validatePacket(&packet));
00051     packet.chksum3++;
00052   }
00053 
00054   // Packet of all 191
00055   memset(&packet, 191, sizeof(packet));
00056   packet.sync = 0xE7;
00057   packet.chksum3 = (uint8_t)(191*70);
00058   ASSERT_TRUE(validatePacket(&packet));
00059   packet.chksum3++;
00060   while (packet.chksum3 != (uint8_t)(191*70)) {
00061     ASSERT_FALSE(validatePacket(&packet));
00062     packet.chksum3++;
00063   }
00064 }
00065 
00066 int main(int argc, char **argv)
00067 {
00068   testing::InitGoogleTest(&argc, argv);
00069   return RUN_ALL_TESTS();
00070 }
00071 


oxford_gps_eth
Author(s): Kevin Hallenbeck
autogenerated on Wed Jul 10 2019 03:30:07