From 31b81b4830111922f32c80349eca603589c5d47c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Mon, 20 Nov 2023 12:48:10 -0300 Subject: [PATCH] tests: Add serialization test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- tests/mav_frame_tests.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/mav_frame_tests.rs b/tests/mav_frame_tests.rs index fac00da30a..6d96c25b23 100644 --- a/tests/mav_frame_tests.rs +++ b/tests/mav_frame_tests.rs @@ -23,7 +23,7 @@ mod mav_frame_tests { ]; #[test] - pub fn test_deser() { + pub fn test_deser_ser() { use mavlink::{common::MavMessage, MavFrame, MavlinkVersion}; let frame = MavFrame::::deser(MavlinkVersion::V2, HEARTBEAT_V2) .expect("failed to parse message"); @@ -31,9 +31,11 @@ mod mav_frame_tests { 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);