42 #pragma clang diagnostic push 43 #pragma clang diagnostic ignored "-Wweak-vtables" 47 class PacketTestClass :
public Packet 50 PacketTestClass(
const PacketTestClass &other) =
default;
51 PacketTestClass(PacketTestClass &&other) =
default;
52 PacketTestClass(std::vector<uint8_t> data)
57 ~PacketTestClass() =
default;
59 virtual ::Packet::Version
version()
const 63 virtual unsigned long id()
const 67 virtual std::string
name()
const 69 return "MISSION_CURRENT";
75 virtual std::optional<MAVAddress>
dest()
const 79 PacketTestClass &
operator=(
const PacketTestClass &other) =
default;
80 PacketTestClass &
operator=(PacketTestClass &&other) =
default;
84 #pragma clang diagnostic pop 90 TEST_CASE(
"Packet's can be constructed.",
"[Packet]")
92 std::vector<uint8_t> data = {0, 7, 7, 3, 4};
93 REQUIRE_NOTHROW(PacketTestClass({}));
94 REQUIRE_NOTHROW(PacketTestClass({1, 3, 3, 7}));
95 REQUIRE_NOTHROW(PacketTestClass(data));
103 REQUIRE(PacketTestClass({1, 3, 3, 7}) == PacketTestClass({1, 3, 3, 7}));
105 PacketTestClass({1, 3, 3, 7}) == PacketTestClass({0, 7, 7, 3, 4}));
110 PacketTestClass({1, 3, 3, 7}) != PacketTestClass({0, 7, 7, 3, 4}));
112 PacketTestClass({1, 3, 3, 7}) != PacketTestClass({1, 3, 3, 7}));
119 PacketTestClass original({1, 3, 3, 7});
120 PacketTestClass copy(original);
121 REQUIRE(copy == PacketTestClass({1, 3, 3, 7}));
127 PacketTestClass original({1, 3, 3, 7});
128 PacketTestClass moved(std::move(original));
129 REQUIRE(moved == PacketTestClass({1, 3, 3, 7}));
135 PacketTestClass
packet_a({1, 3, 3, 7});
136 PacketTestClass
packet_b({0, 7, 7, 3, 4});
137 REQUIRE(
packet_a == PacketTestClass({1, 3, 3, 7}));
139 REQUIRE(
packet_a == PacketTestClass({0, 7, 7, 3, 4}));
143 TEST_CASE(
"Packet's are assignable (by move semantics).",
"[Packet]")
145 PacketTestClass
packet_a({1, 3, 3, 7});
146 PacketTestClass
packet_b({0, 7, 7, 3, 4});
147 REQUIRE(
packet_a == PacketTestClass({1, 3, 3, 7}));
149 REQUIRE(
packet_a == PacketTestClass({0, 7, 7, 3, 4}));
153 TEST_CASE(
"Packet's contain raw packet data and make it accessible.",
157 PacketTestClass({1, 3, 3, 7}).data() ==
158 std::vector<uint8_t>({1, 3, 3, 7}));
160 PacketTestClass({1, 3, 3, 7}).data() ==
161 std::vector<uint8_t>({1, 0, 5, 3}));
167 REQUIRE(PacketTestClass({}).version() ==
Packet::V1);
173 REQUIRE(PacketTestClass({}).
id() == 42);
179 REQUIRE(PacketTestClass({}).
name() ==
"MISSION_CURRENT");
183 TEST_CASE(
"Packet's have a source address.",
"[Packet]")
185 REQUIRE(PacketTestClass({}).source() ==
MAVAddress(
"3.14"));
189 TEST_CASE(
"Packet's optionally have a destination address.",
"[Packet]")
191 REQUIRE(PacketTestClass({}).dest().value() ==
MAVAddress(
"2.71"));
195 TEST_CASE(
"Packet's optionally have a source connection.",
"[Packet]")
197 SECTION(
"Defaults to nullptr.")
199 REQUIRE(PacketTestClass({}).connection() ==
nullptr);
201 SECTION(
"Can be set with the 'connection' method.")
203 fakeit::Mock<Filter> mock_filter;
205 auto conn = std::make_shared<Connection>(
"SOURCE", filter);
206 PacketTestClass packet({});
207 packet.connection(conn);
208 REQUIRE(packet.connection() !=
nullptr);
209 REQUIRE(packet.connection() == conn);
210 REQUIRE(
str(*packet.connection()) ==
"SOURCE");
218 str(PacketTestClass({})) ==
219 "MISSION_CURRENT (#42) from 3.14 to 2.71 (v1.0)");
std::string str(const T &object)
Packet & operator=(const Packet &other)=default
virtual unsigned long id() const =0
PacketTestClass packet_b({0, 7, 7, 3, 4})
std::string name(unsigned long id)
virtual std::optional< MAVAddress > dest() const =0
virtual std::string name() const =0
TEST_CASE("Packet's can be constructed.", "[Packet]")
virtual MAVAddress source() const =0
std::shared_ptr< T > mock_shared(fakeit::Mock< T > &mock)
virtual Version version() const =0