38 TEST_CASE(
"'packet_v2::header_complete' determines whether the given bytes " 39 "at least represent a complete header.",
"[packet_v2]")
41 auto heartbeat = to_vector_with_sig(HeartbeatV2());
42 auto ping = to_vector(PingV2());
43 auto set_mode = to_vector_with_sig(SetModeV2());
44 auto mission_set_current = to_vector(MissionSetCurrentV2());
45 auto encapsulated_data = to_vector_with_sig(EncapsulatedDataV2());
46 auto param_ext_request_list = to_vector(ParamExtRequestListV2());
47 SECTION(
"Returns true when at least a complete header is given.")
52 mission_set_current.resize(25);
53 encapsulated_data.resize(30);
61 SECTION(
"Returns false when an incomplete header is given.")
66 mission_set_current.resize(2);
67 encapsulated_data.resize(1);
68 param_ext_request_list.resize(0);
76 SECTION(
"Returns false when the magic byte is wrong.")
80 set_mode.front() = 0xFE;
81 mission_set_current.front() = 0xFE;
82 encapsulated_data.front() = 0xFE;
83 param_ext_request_list.front() = 0xFE;
94 TEST_CASE(
"'packet_v2::header' returns a structure pointer to the given " 95 "header data.",
"[packet_v2]")
97 auto heartbeat = to_vector_with_sig(HeartbeatV2());
98 auto ping = to_vector(PingV2());
99 auto set_mode = to_vector_with_sig(SetModeV2());
100 auto mission_set_current = to_vector(MissionSetCurrentV2());
101 auto encapsulated_data = to_vector_with_sig(EncapsulatedDataV2());
102 auto param_ext_request_list = to_vector(ParamExtRequestListV2());
103 SECTION(
"Header contains a magic value.")
112 SECTION(
"Header stores the packet length.")
121 SECTION(
"Header has incompatibility flags.")
124 MAVLINK_IFLAG_SIGNED) ==
true);
126 MAVLINK_IFLAG_SIGNED) ==
false);
128 MAVLINK_IFLAG_SIGNED) ==
true);
130 MAVLINK_IFLAG_SIGNED) ==
false);
132 MAVLINK_IFLAG_SIGNED) ==
true);
134 MAVLINK_IFLAG_SIGNED) ==
false);
136 SECTION(
"Header has compatibility flags.")
145 SECTION(
"Header has a sequence number.")
154 SECTION(
"Header has a system ID.")
163 SECTION(
"Header has a component ID.")
172 SECTION(
"Header has a message ID.")
181 SECTION(
"Returns nullptr when an incomplete header is given.")
186 mission_set_current.resize(2);
187 encapsulated_data.resize(1);
188 param_ext_request_list.resize(0);
196 SECTION(
"Returns nullptr when the magic byte is wrong.")
200 set_mode.front() = 0xFE;
201 mission_set_current.front() = 0xFE;
202 encapsulated_data.front() = 0xFE;
203 param_ext_request_list.front() = 0xFE;
214 TEST_CASE(
"'packet_v2::packet_complete' determines whether the given bytes " 215 "represent a complete packet.",
"[packet_v2]")
217 auto heartbeat = to_vector_with_sig(HeartbeatV2());
218 auto ping = to_vector(PingV2());
219 auto set_mode = to_vector_with_sig(SetModeV2());
220 auto mission_set_current = to_vector(MissionSetCurrentV2());
221 auto encapsulated_data = to_vector_with_sig(EncapsulatedDataV2());
222 auto param_ext_request_list = to_vector(ParamExtRequestListV2());
223 SECTION(
"Returns true when a complete packet is given.")
232 SECTION(
"Returns false when the magic byte is wrong.")
236 set_mode.front() = 0xFE;
237 mission_set_current.front() = 0xFE;
238 encapsulated_data.front() = 0xFE;
239 param_ext_request_list.front() = 0xFE;
247 SECTION(
"Returns false when the packet is too short.")
252 mission_set_current.pop_back();
253 encapsulated_data.pop_back();
254 param_ext_request_list.pop_back();
262 SECTION(
"Returns false when the packet is too long.")
265 ping.push_back(0x00);
266 set_mode.push_back(0x00);
267 mission_set_current.push_back(0x00);
268 encapsulated_data.push_back(0x00);
269 param_ext_request_list.push_back(0x00);
280 TEST_CASE(
"'packet_v2::is_signed' determines whether the given bytes " 281 "represent a signed packet.",
"[packet_v2]")
283 auto heartbeat = to_vector_with_sig(HeartbeatV2());
284 auto ping = to_vector(PingV2());
285 auto set_mode = to_vector_with_sig(SetModeV2());
286 auto mission_set_current = to_vector(MissionSetCurrentV2());
287 auto encapsulated_data = to_vector_with_sig(EncapsulatedDataV2());
288 auto param_ext_request_list = to_vector(ParamExtRequestListV2());
289 SECTION(
"Returns true when the packet is signed.")
295 SECTION(
"Returns false when the packet is not signed.")
301 SECTION(
"Throws and error when the header is invalid.")
305 set_mode.front() = 0xFE;
306 mission_set_current.resize(2);
307 encapsulated_data.resize(1);
308 param_ext_request_list.resize(0);
322 std::invalid_argument);
326 "Header is incomplete or invalid.");
329 "Header is incomplete or invalid.");
332 "Header is incomplete or invalid.");
335 "Header is incomplete or invalid.");
338 "Header is incomplete or invalid.");
341 "Header is incomplete or invalid.");
346 TEST_CASE(
"packet_v2::Packet's can be constructed.",
"[packet_v2::Packet]")
351 MissionSetCurrentV2 mission_set_current;
352 EncapsulatedDataV2 encapsulated_data;
353 ParamExtRequestListV2 param_ext_request_list;
354 SECTION(
"With proper arguments and no signature.")
363 SECTION(
"With proper arguments and a signature.")
375 SECTION(
"And ensures a complete header is given.")
386 "Packet (9 bytes) is shorter than a v2.0 header (10 bytes).");
388 SECTION(
"And ensures packets begin with the magic byte (0xFD).")
395 "Invalid packet starting byte (0xAD), " 396 "v2.0 packets should start with 0xFD.");
398 SECTION(
"And ensures the message ID is valid.")
405 "Packet ID (#255) is not part of the '" 406 MAVLINK_DIALECT
"' MAVLink dialect.");
412 "Packet ID (#5000) is not part of the '" 413 MAVLINK_DIALECT
"' MAVLink dialect.");
415 SECTION(
"And ensures the packet is the correct length (without signature).")
418 auto heartbeat_data = to_vector(
heartbeat);
419 heartbeat_data.push_back(0x00);
423 "Packet is 22 bytes, should be 21 bytes.");
425 auto ping_data = to_vector(
ping);
426 ping_data.pop_back();
430 "Packet is 25 bytes, should be 26 bytes.");
432 auto set_mode_data = to_vector(set_mode);
433 set_mode_data.push_back(0x00);
437 "Packet is 19 bytes, should be 18 bytes.");
439 auto mission_set_current_data = to_vector(mission_set_current);
440 mission_set_current_data.pop_back();
445 "Packet is 13 bytes, should be 14 bytes.");
447 auto encapsulated_data_data = to_vector(encapsulated_data);
448 encapsulated_data_data.push_back(0x00);
453 "Packet is 268 bytes, should be 267 bytes.");
455 auto param_ext_request_list_data = to_vector(param_ext_request_list);
456 param_ext_request_list_data.pop_back();
461 "Packet is 13 bytes, should be 14 bytes.");
463 SECTION(
"And ensures the packet is the correct length (with signature).")
466 auto heartbeat_data = to_vector_with_sig(
heartbeat);
467 heartbeat_data.push_back(0x00);
471 "Signed packet is 35 bytes, should be 34 bytes.");
473 auto ping_data = to_vector_with_sig(
ping);
474 ping_data.pop_back();
478 "Signed packet is 38 bytes, should be 39 bytes.");
480 auto set_mode_data = to_vector_with_sig(set_mode);
481 set_mode_data.push_back(0x00);
485 "Signed packet is 32 bytes, should be 31 bytes.");
487 auto mission_set_current_data = to_vector_with_sig(mission_set_current);
488 mission_set_current_data.pop_back();
493 "Signed packet is 26 bytes, should be 27 bytes.");
495 auto encapsulated_data_data = to_vector_with_sig(encapsulated_data);
496 encapsulated_data_data.push_back(0x00);
501 "Signed packet is 281 bytes, should be 280 bytes.");
503 auto param_ext_request_list_data =
504 to_vector_with_sig(param_ext_request_list);
505 param_ext_request_list_data.pop_back();
510 "Signed packet is 26 bytes, should be 27 bytes.");
515 TEST_CASE(
"packet_v2::Packet's are comparable.",
"[packet_v2::Packet]")
544 TEST_CASE(
"packet_v2::Packet's are copyable.",
"[packet_v2::Packet]")
552 TEST_CASE(
"packet_v2::Packet's are movable.",
"[packet_v2::Packet]")
560 TEST_CASE(
"packet_v2::Packet's are assignable.",
"[Packet]")
570 TEST_CASE(
"packet_v2::Packet's are assignable (by move semantics).",
"[Packet]")
580 TEST_CASE(
"packet_v2::Packet's contain raw packet data and make it accessible.",
581 "[packet_v2::Packet]")
583 auto heartbeat = to_vector_with_sig(HeartbeatV2());
584 auto ping = to_vector(PingV2());
585 auto set_mode = to_vector_with_sig(SetModeV2());
586 auto mission_set_current = to_vector(MissionSetCurrentV2());
587 auto encapsulated_data = to_vector_with_sig(EncapsulatedDataV2());
588 auto param_ext_request_list = to_vector_with_sig(ParamExtRequestListV2());
598 param_ext_request_list);
602 TEST_CASE(
"packet_v2::Packet's have a version.",
"[packet_v2::Packet]")
604 auto heartbeat = to_vector_with_sig(HeartbeatV2());
605 auto ping = to_vector(PingV2());
606 auto set_mode = to_vector_with_sig(SetModeV2());
607 auto mission_set_current = to_vector(MissionSetCurrentV2());
608 auto encapsulated_data = to_vector_with_sig(EncapsulatedDataV2());
609 auto param_ext_request_list = to_vector(ParamExtRequestListV2());
620 TEST_CASE(
"packet_v2::Packet's have an ID.",
"[packet_v2::Packet]")
622 auto heartbeat = to_vector_with_sig(HeartbeatV2());
623 auto ping = to_vector(PingV2());
624 auto set_mode = to_vector_with_sig(SetModeV2());
625 auto mission_set_current = to_vector(MissionSetCurrentV2());
626 auto encapsulated_data = to_vector_with_sig(EncapsulatedDataV2());
627 auto param_ext_request_list = to_vector(ParamExtRequestListV2());
637 TEST_CASE(
"packet_v2::Packet's have a name.",
"[packet_v2::Packet]")
639 auto heartbeat = to_vector_with_sig(HeartbeatV2());
640 auto ping = to_vector(PingV2());
641 auto set_mode = to_vector_with_sig(SetModeV2());
642 auto mission_set_current = to_vector(MissionSetCurrentV2());
643 auto encapsulated_data = to_vector_with_sig(EncapsulatedDataV2());
644 auto param_ext_request_list = to_vector(ParamExtRequestListV2());
653 "PARAM_EXT_REQUEST_LIST");
657 TEST_CASE(
"packet_v2::Packet's have a source address.",
"[packet_v2::Packet]")
659 auto heartbeat = to_vector_with_sig(HeartbeatV2());
660 auto ping = to_vector(PingV2());
661 auto set_mode = to_vector_with_sig(SetModeV2());
662 auto mission_set_current = to_vector(MissionSetCurrentV2());
663 auto encapsulated_data = to_vector_with_sig(EncapsulatedDataV2());
664 auto param_ext_request_list = to_vector(ParamExtRequestListV2());
678 TEST_CASE(
"packet_v2::Packet's optionally have a destination address.",
679 "[packet_v2::Packet]")
681 auto heartbeat = to_vector_with_sig(HeartbeatV2());
682 auto ping = to_vector(PingV2());
683 auto set_mode = to_vector_with_sig(SetModeV2());
684 auto mission_set_current = to_vector(MissionSetCurrentV2());
685 auto encapsulated_data = to_vector_with_sig(EncapsulatedDataV2());
686 auto param_ext_request_list = to_vector(ParamExtRequestListV2());
696 std::bad_optional_access);
703 TEST_CASE(
"packet_v2::Packet's optionally have a source connection.",
704 "[packet_v2::Packet]")
707 SECTION(
"Defaults to nullptr.")
709 REQUIRE(
heartbeat.connection() ==
nullptr);
711 SECTION(
"Can be set with the 'connection' method.")
713 fakeit::Mock<Filter> mock_filter;
715 auto conn = std::make_shared<Connection>(
"SOURCE", filter);
717 REQUIRE(
heartbeat.connection() !=
nullptr);
724 TEST_CASE(
"packet_v2::Packet's are printable.",
"[packet_v2::Packet]")
726 auto heartbeat = to_vector_with_sig(HeartbeatV2());
727 auto ping = to_vector(PingV2());
728 auto set_mode = to_vector_with_sig(SetModeV2());
729 auto mission_set_current = to_vector(MissionSetCurrentV2());
730 auto encapsulated_data = to_vector_with_sig(EncapsulatedDataV2());
731 auto param_ext_request_list = to_vector(ParamExtRequestListV2());
734 "HEARTBEAT (#0) from 127.1 (v2.0)");
737 "PING (#4) from 192.168 to 127.1 (v2.0)");
740 "SET_MODE (#11) from 172.0 to 123.0 (v2.0)");
743 "MISSION_SET_CURRENT (#41) from 255.0 to 0.0 (v2.0)");
746 "ENCAPSULATED_DATA (#131) from 224.255 (v2.0)");
749 "PARAM_EXT_REQUEST_LIST (#321) from 0.255 to 32.64 (v2.0)");
std::string str(const T &object)
bool packet_complete(const std::vector< uint8_t > &data)
bool header_complete(const std::vector< uint8_t > &data)
packet_v2::Packet packet_b(to_vector(SetModeV2()))
std::string name(unsigned long id)
TEST_CASE("'packet_v2::header_complete' determines whether the given bytes " "at least represent a complete header.", "[packet_v2]")
const struct mavlink::v2_header * header(const std::vector< uint8_t > &data)
std::shared_ptr< T > mock_shared(fakeit::Mock< T > &mock)
bool is_signed(const std::vector< uint8_t > &data)