Skip to content

Commit

Permalink
tests: Use COMMON_MSG_HEADER values over hardcoded numbers
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 cc94c3b commit f490aeb
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
45 changes: 45 additions & 0 deletions tests/mav_frame_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
pub mod test_shared;

mod mav_frame_tests {
// NOTE: No header
pub const HEARTBEAT_V2: &[u8] = &[
crate::test_shared::COMMON_MSG_HEADER.sequence,
crate::test_shared::COMMON_MSG_HEADER.system_id,
crate::test_shared::COMMON_MSG_HEADER.component_id,
0x00, // msg ID
0x00,
0x00,
0x05, // payload - custom_mode
0x00, //
0x00, //
0x00, //
0x02, // mav_type
0x03, // autopilot
0x59, // base_mode
0x03, // system_status
0x03, // mavlink_version
0x10, // checksum
0xf0,
];

#[test]
pub fn test_deser() {
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"),
};
assert_eq!(msg.custom_mode, heartbeat_msg.custom_mode);
assert_eq!(msg.mavtype, heartbeat_msg.mavtype);
assert_eq!(msg.autopilot, heartbeat_msg.autopilot);
assert_eq!(msg.base_mode, heartbeat_msg.base_mode);
assert_eq!(msg.system_status, heartbeat_msg.system_status);
assert_eq!(msg.mavlink_version, heartbeat_msg.mavlink_version);
}
}
6 changes: 3 additions & 3 deletions tests/v1_encode_decode_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ mod test_v1_encode_decode {
pub const HEARTBEAT_V1: &'static [u8] = &[
mavlink::MAV_STX,
0x09,
0xef,
0x01,
0x01,
crate::test_shared::COMMON_MSG_HEADER.sequence,
crate::test_shared::COMMON_MSG_HEADER.system_id,
crate::test_shared::COMMON_MSG_HEADER.component_id,
0x00,
0x05,
0x00,
Expand Down
6 changes: 3 additions & 3 deletions tests/v2_encode_decode_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ mod test_v2_encode_decode {
0x09, //payload len
0, //incompat flags
0, //compat flags
0xef, //seq 239
0x01, //sys ID
0x01, //comp ID
crate::test_shared::COMMON_MSG_HEADER.sequence,
crate::test_shared::COMMON_MSG_HEADER.system_id,
crate::test_shared::COMMON_MSG_HEADER.component_id,
0x00,
0x00,
0x00, //msg ID
Expand Down

0 comments on commit f490aeb

Please sign in to comment.