From bf13a432b8f6446b0347a10fc67ff14e20e35626 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 6 Dec 2023 01:33:26 +0100 Subject: [PATCH] add some more serde test --- src/cfdp/mod.rs | 27 +++++++++++++++++++++++++++ src/cfdp/pdu/ack.rs | 16 ++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/cfdp/mod.rs b/src/cfdp/mod.rs index 0cd7897..0dc05da 100644 --- a/src/cfdp/mod.rs +++ b/src/cfdp/mod.rs @@ -237,6 +237,9 @@ impl Error for TlvLvError { #[cfg(test)] mod tests { use super::*; + #[cfg(feature = "serde")] + use postcard::{from_bytes, to_allocvec}; + #[test] fn test_crc_from_bool() { @@ -263,4 +266,28 @@ mod tests { let fault_handler_code = FaultHandlerCode::try_from(fault_handler_code_raw).unwrap(); assert_eq!(fault_handler_code, FaultHandlerCode::NoticeOfSuspension); } + + #[test] + #[cfg(feature="serde")] + fn test_serde_impl_pdu_type() { + let pdu_type = PduType::FileData; + let output = to_allocvec(&pdu_type).unwrap(); + assert_eq!(from_bytes::(&output).unwrap(), pdu_type); + } + + #[test] + #[cfg(feature="serde")] + fn test_serde_impl_direction() { + let direction = Direction::TowardsReceiver; + let output = to_allocvec(&direction).unwrap(); + assert_eq!(from_bytes::(&output).unwrap(), direction); + } + + #[test] + #[cfg(feature="serde")] + fn test_serde_impl_transmission_mode() { + let mode = TransmissionMode::Unacknowledged; + let output = to_allocvec(&mode).unwrap(); + assert_eq!(from_bytes::(&output).unwrap(), mode); + } } diff --git a/src/cfdp/pdu/ack.rs b/src/cfdp/pdu/ack.rs index 355a44b..0e6708d 100644 --- a/src/cfdp/pdu/ack.rs +++ b/src/cfdp/pdu/ack.rs @@ -200,6 +200,8 @@ mod tests { }; use super::*; + #[cfg(feature = "serde")] + use postcard::{from_bytes, to_allocvec}; fn verify_state(ack_pdu: &AckPdu, expected_crc_flag: CrcFlag, expected_dir: Direction) { assert_eq!(ack_pdu.condition_code(), ConditionCode::NoError); @@ -316,4 +318,18 @@ mod tests { ); verify_state(&ack_pdu, CrcFlag::WithCrc, Direction::TowardsSender); } + + #[test] + #[cfg(feature="serde")] + fn test_ack_pdu_serialization() { + let pdu_conf = common_pdu_conf(CrcFlag::WithCrc, LargeFileFlag::Normal); + let pdu_header = PduHeader::new_no_file_data(pdu_conf, 0); + let ack_pdu = AckPdu::new_for_eof_pdu( + pdu_header, + ConditionCode::NoError, + TransactionStatus::Active, + ); + let output = to_allocvec(&ack_pdu).unwrap(); + assert_eq!(from_bytes::(&output).unwrap(), ack_pdu); + } }