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 21, 2023
1 parent 0283311 commit 31b81b4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tests/mav_frame_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@ 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 msg = match frame.msg {
MavMessage::HEARTBEAT(msg) => msg,
_ => panic!("Decoded wrong message type"),
let buffer = frame.ser();
assert_eq!(buffer, HEARTBEAT_V2[..buffer.len()]);

let MavMessage::HEARTBEAT(msg) = frame.msg else {
panic!("Decoded wrong message type");
};
assert_eq!(msg.custom_mode, heartbeat_msg.custom_mode);
assert_eq!(msg.mavtype, heartbeat_msg.mavtype);
Expand Down

0 comments on commit 31b81b4

Please sign in to comment.