test_packet.cpp
Go to the documentation of this file.
1 
31 #include "create/packet.h"
32 #include "create/types.h"
33 
34 #include "gtest/gtest.h"
35 
36 TEST(PacketTest, Constructor)
37 {
38  create::Packet empty_packet(0, std::string(""));
39  EXPECT_EQ(static_cast<int>(empty_packet.nbytes), 0);
40  EXPECT_EQ(empty_packet.info, std::string(""));
41 
42  create::Packet some_packet(2, std::string("test_packet"));
43  EXPECT_EQ(static_cast<int>(some_packet.nbytes), 2);
44  EXPECT_EQ(some_packet.info, std::string("test_packet"));
45 }
46 
47 TEST(PacketTest, SetValidateAndGetData)
48 {
49  create::Packet packet(2, std::string("test_packet"));
50 
51  // Set some data and validate it
52  const uint16_t some_data = 123;
53  packet.setDataToValidate(some_data);
54  packet.validate();
55  // Confirm data was validated
56  const uint16_t some_data_result = packet.getData();
57  EXPECT_EQ(some_data_result, some_data);
58 
59  // Set zero data and validate it
60  const uint16_t zero_data = 0;
61  packet.setDataToValidate(zero_data);
62  packet.validate();
63  // Confirm data was validated
64  const uint16_t zero_data_result = packet.getData();
65  EXPECT_EQ(zero_data_result, zero_data);
66 
67  // Set some data but do not validate it
68  const uint16_t do_not_validate_data = 321;
69  packet.setDataToValidate(do_not_validate_data);
70  // Confirm data was not validated
71  const uint16_t unvalidated_data_result = packet.getData();
72  EXPECT_NE(unvalidated_data_result, do_not_validate_data);
73 }
const uint8_t nbytes
Definition: packet.h:49
void setDataToValidate(const uint16_t &td)
Definition: packet.cpp:15
uint16_t getData() const
Definition: packet.cpp:30
const std::string info
Definition: packet.h:50
TEST(PacketTest, Constructor)
Definition: test_packet.cpp:36
void validate()
Definition: packet.cpp:20


libcreate
Author(s): Jacob Perron
autogenerated on Sat May 8 2021 03:02:37