Skip to content

Commit

Permalink
tests: Add serialization test
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <[email protected]>
  • Loading branch information
patrickelectric committed Nov 20, 2023
1 parent 8c63f80 commit 63a51d8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tests/mav_frame_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@ mod mav_frame_tests {
];

#[test]
pub fn test_deser() {
pub fn test_deser_ser() {
use mavlink::{common::MavMessage, MavFrame, MavlinkVersion};
let frame = MavFrame::<MavMessage>::deser(MavlinkVersion::V2, HEARTBEAT_V2)
.expect("failed to parse message");

assert_eq!(frame.header, crate::test_shared::COMMON_MSG_HEADER);
let heartbeat_msg = crate::test_shared::get_heartbeat_msg();

let mut buffer = [0u8; HEARTBEAT_V2.len()];
frame.ser(&mut buffer);
assert_eq!(buffer[..buffer.len() - 2], HEARTBEAT_V2[..buffer.len() - 2]);

let msg = match frame.msg {
MavMessage::HEARTBEAT(msg) => msg,
_ => panic!("Decoded wrong message type"),
Expand Down

0 comments on commit 63a51d8

Please sign in to comment.