38 TEST_CASE(
"'packet_v1::header_complete' determines whether the given bytes " 39 "at least represent a complete header.",
"[packet_v1]")
41 auto heartbeat = to_vector(HeartbeatV1());
42 auto ping = to_vector(PingV1());
43 auto set_mode = to_vector(SetModeV1());
44 auto encapsulated_data = to_vector(EncapsulatedDataV1());
45 SECTION(
"Returns true when at least a complete header is given.")
55 SECTION(
"Returns false when an incomplete header is given.")
60 encapsulated_data.resize(0);
66 SECTION(
"Returns false when the magic byte is wrong.")
70 set_mode.front() = 0xFD;
71 encapsulated_data.front() = 0xFD;
80 TEST_CASE(
"'packet_v1::header' returns a structure pointer to the given " 81 "header data.",
"[packet_v1]")
83 auto heartbeat = to_vector(HeartbeatV1());
84 auto ping = to_vector(PingV1());
85 auto set_mode = to_vector(SetModeV1());
86 auto encapsulated_data = to_vector(EncapsulatedDataV1());
87 SECTION(
"Header contains a magic value.")
94 SECTION(
"Header stores the payload length.")
101 SECTION(
"Header has a sequence number.")
108 SECTION(
"Header has a system ID.")
115 SECTION(
"Header has a component ID.")
122 SECTION(
"Header has a message ID.")
129 SECTION(
"Returns nullptr when an incomplete header is given.")
134 encapsulated_data.resize(0);
140 SECTION(
"Returns nullptr when the magic byte is wrong.")
144 set_mode.front() = 0xFD;
145 encapsulated_data.front() = 0xFD;
154 TEST_CASE(
"'packet_v1::packet_complete' determines whether the given bytes " 155 "represent a complete packet.",
"[packet_v1]")
157 auto heartbeat = to_vector(HeartbeatV1());
158 auto ping = to_vector(PingV1());
159 auto set_mode = to_vector(SetModeV1());
160 auto encapsulated_data = to_vector(EncapsulatedDataV1());
161 SECTION(
"Returns true when a complete packet is given.")
168 SECTION(
"Returns false when the magic byte is wrong.")
172 set_mode.front() = 0xFD;
173 encapsulated_data.front() = 0xFD;
179 SECTION(
"Returns false when the packet is too short.")
184 encapsulated_data.pop_back();
190 SECTION(
"Returns false when the packet is too long.")
193 ping.push_back(0x00);
194 set_mode.push_back(0x00);
195 encapsulated_data.push_back(0x00);
204 TEST_CASE(
"packet_v1::Packet's can be constructed.",
"[packet_v1::Packet]")
209 EncapsulatedDataV1 encapsulated_data;
210 SECTION(
"With proper arguments.")
217 SECTION(
"And ensures a complete header is given.")
225 "Packet (5 bytes) is shorter than a v1.0 header (6 bytes).");
227 SECTION(
"And ensures packets begins with the magic byte (0xFE).")
234 "Invalid packet starting byte (0xAD), " 235 "v1.0 packets should start with 0xFE.");
237 SECTION(
"And ensures the message ID is valid.")
244 "Packet ID (#255) is not part of the '" 245 MAVLINK_DIALECT
"' MAVLink dialect.");
247 SECTION(
"And ensures the packet is the correct length.")
250 auto heartbeat_data = to_vector(
heartbeat);
251 heartbeat_data.pop_back();
256 "Packet is 16 bytes, should be 17 bytes.");
258 auto ping_data = to_vector(
ping);
259 ping_data.push_back(0x00);
264 "Packet is 23 bytes, should be 22 bytes.");
266 auto set_mode_data = to_vector(set_mode);
267 set_mode_data.pop_back();
272 "Packet is 13 bytes, should be 14 bytes.");
274 auto encapsulated_data_data = to_vector(encapsulated_data);
275 encapsulated_data_data.push_back(0x00);
280 "Packet is 264 bytes, should be 263 bytes.");
285 TEST_CASE(
"packet_v1::Packet's are comparable.",
"[packet_v1::Packet]")
308 TEST_CASE(
"packet_v1::Packet's are copyable.",
"[packet_v1::Packet]")
316 TEST_CASE(
"packet_v1::Packet's are movable.",
"[packet_v1::Packet]")
324 TEST_CASE(
"packet_v1::Packet's are assignable.",
"[Packet]")
334 TEST_CASE(
"packet_v1::Packet's are assignable (by move semantics).",
"[Packet]")
344 TEST_CASE(
"packet_v1::Packet's contain raw packet data and make it accessible.",
345 "[packet_v1::Packet]")
347 auto heartbeat = to_vector(HeartbeatV1());
348 auto ping = to_vector(PingV1());
349 auto set_mode = to_vector(SetModeV1());
350 auto encapsulated_data = to_vector(EncapsulatedDataV1());
358 TEST_CASE(
"packet_v1::Packet's have a version.",
"[packet_v1::Packet]")
360 auto heartbeat = to_vector(HeartbeatV1());
361 auto ping = to_vector(PingV1());
362 auto set_mode = to_vector(SetModeV1());
363 auto encapsulated_data = to_vector(EncapsulatedDataV1());
372 TEST_CASE(
"packet_v1::Packet's have an ID.",
"[packet_v1::Packet]")
374 auto heartbeat = to_vector(HeartbeatV1());
375 auto ping = to_vector(PingV1());
376 auto set_mode = to_vector(SetModeV1());
377 auto encapsulated_data = to_vector(EncapsulatedDataV1());
385 TEST_CASE(
"packet_v1::Packet's have a name.",
"[packet_v1::Packet]")
387 auto heartbeat = to_vector(HeartbeatV1());
388 auto ping = to_vector(PingV1());
389 auto set_mode = to_vector(SetModeV1());
390 auto encapsulated_data = to_vector(EncapsulatedDataV1());
398 TEST_CASE(
"packet_v1::Packet's have a source address.",
"[packet_v1::Packet]")
400 auto heartbeat = to_vector(HeartbeatV1());
401 auto ping = to_vector(PingV1());
402 auto set_mode = to_vector(SetModeV1());
403 auto encapsulated_data = to_vector(EncapsulatedDataV1());
412 TEST_CASE(
"packet_v1::Packet's optionally have a destination address.",
413 "[packet_v1::Packet]")
415 auto heartbeat = to_vector(HeartbeatV1());
416 auto ping = to_vector(PingV1());
417 auto set_mode = to_vector(SetModeV1());
418 auto encapsulated_data = to_vector(EncapsulatedDataV1());
425 std::bad_optional_access);
429 TEST_CASE(
"packet_v1::Packet's optionally have a source connection.",
430 "[packet_v1::Packet]")
433 SECTION(
"Defaults to nullptr.")
435 REQUIRE(
heartbeat.connection() ==
nullptr);
437 SECTION(
"Can be set with the 'connection' method.")
439 fakeit::Mock<Filter> mock_filter;
441 auto conn = std::make_shared<Connection>(
"SOURCE", filter);
443 REQUIRE(
heartbeat.connection() !=
nullptr);
450 TEST_CASE(
"packet_v1::Packet's are printable.",
"[packet_v1::Packet]")
452 auto heartbeat = to_vector(HeartbeatV1());
453 auto ping = to_vector(PingV1());
454 auto set_mode = to_vector(SetModeV1());
455 auto encapsulated_data = to_vector(EncapsulatedDataV1());
458 "HEARTBEAT (#0) from 127.1 (v1.0)");
461 "PING (#4) from 192.168 to 127.1 (v1.0)");
464 "SET_MODE (#11) from 172.0 to 123.0 (v1.0)");
467 "ENCAPSULATED_DATA (#131) from 224.255 (v1.0)");
std::string str(const T &object)
std::string name(unsigned long id)
TEST_CASE("'packet_v1::header_complete' determines whether the given bytes " "at least represent a complete header.", "[packet_v1]")
std::shared_ptr< T > mock_shared(fakeit::Mock< T > &mock)
bool header_complete(const std::vector< uint8_t > &data)
packet_v1::Packet packet_b(to_vector(SetModeV1()))
const struct mavlink::v1_header * header(const std::vector< uint8_t > &data)
bool packet_complete(const std::vector< uint8_t > &data)