From 38f5e3ba5f002e5637c92ba5193aaec43c106489 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 6 Dec 2023 16:16:21 +0100 Subject: [PATCH] something is wrong with the function coverage.. --- src/cfdp/pdu/file_data.rs | 37 +++++++++++++++++++++++++++++++++++++ src/ecss/mod.rs | 18 ++++++++++++++++++ src/ecss/scheduling.rs | 20 ++++++++++++++++++++ src/ecss/tc.rs | 11 +++++++++++ 4 files changed, 86 insertions(+) diff --git a/src/cfdp/pdu/file_data.rs b/src/cfdp/pdu/file_data.rs index 8575922..63dfdbf 100644 --- a/src/cfdp/pdu/file_data.rs +++ b/src/cfdp/pdu/file_data.rs @@ -248,6 +248,8 @@ mod tests { use crate::cfdp::pdu::tests::{TEST_DEST_ID, TEST_SEQ_NUM, TEST_SRC_ID}; use crate::cfdp::pdu::{CommonPduConfig, PduHeader}; use crate::cfdp::{Direction, SegmentMetadataFlag, SegmentationControl, TransmissionMode}; + #[cfg(feature = "serde")] + use postcard::{from_bytes, to_allocvec}; #[test] fn test_basic() { @@ -445,4 +447,39 @@ mod tests { let fd_pdu_read_back = fd_pdu_read_back.unwrap(); assert_eq!(fd_pdu_read_back, fd_pdu); } + + #[test] + #[cfg(feature = "serde")] + fn test_serde_serialization() { + let common_conf = + CommonPduConfig::new_with_byte_fields(TEST_SRC_ID, TEST_DEST_ID, TEST_SEQ_NUM).unwrap(); + let pdu_header = PduHeader::new_for_file_data_default(common_conf, 0); + let file_data: [u8; 4] = [1, 2, 3, 4]; + let fd_pdu = FileDataPdu::new_no_seg_metadata(pdu_header, 10, &file_data); + let output = to_allocvec(&fd_pdu).unwrap(); + let output_converted_back: FileDataPdu = from_bytes(&output).unwrap(); + assert_eq!(output_converted_back, fd_pdu); + } + + #[test] + #[cfg(feature = "serde")] + fn test_serde_serialization_with_seg_metadata() { + let common_conf = + CommonPduConfig::new_with_byte_fields(TEST_SRC_ID, TEST_DEST_ID, TEST_SEQ_NUM).unwrap(); + let pdu_header = PduHeader::new_for_file_data( + common_conf, + 0, + SegmentMetadataFlag::Present, + SegmentationControl::WithRecordBoundaryPreservation, + ); + let file_data: [u8; 4] = [1, 2, 3, 4]; + let seg_metadata: [u8; 4] = [4, 3, 2, 1]; + let segment_meta = + SegmentMetadata::new(RecordContinuationState::StartAndEnd, Some(&seg_metadata)) + .unwrap(); + let fd_pdu = FileDataPdu::new_with_seg_metadata(pdu_header, segment_meta, 10, &file_data); + let output = to_allocvec(&fd_pdu).unwrap(); + let output_converted_back: FileDataPdu = from_bytes(&output).unwrap(); + assert_eq!(output_converted_back, fd_pdu); + } } diff --git a/src/ecss/mod.rs b/src/ecss/mod.rs index 533e2b3..c373ecf 100644 --- a/src/ecss/mod.rs +++ b/src/ecss/mod.rs @@ -500,4 +500,22 @@ mod tests { fn test_serde_pus_service_id() { generic_serde_test(PusServiceId::Verification); } + + #[test] + #[cfg(feature = "serde")] + fn test_serde_ptc() { + generic_serde_test(Ptc::AbsoluteTime); + } + + #[test] + #[cfg(feature = "serde")] + fn test_serde_pfc_unsigned() { + generic_serde_test(PfcUnsigned::EightBytes); + } + + #[test] + #[cfg(feature = "serde")] + fn test_serde_pfc_real() { + generic_serde_test(PfcReal::Double); + } } diff --git a/src/ecss/scheduling.rs b/src/ecss/scheduling.rs index c6c36ea..d9b50b1 100644 --- a/src/ecss/scheduling.rs +++ b/src/ecss/scheduling.rs @@ -76,6 +76,8 @@ pub enum TimeWindowType { #[cfg(test)] mod tests { use super::*; + #[cfg(feature = "serde")] + use crate::tests::generic_serde_test; #[test] fn test_bool_conv_0() { @@ -102,4 +104,22 @@ mod tests { let subservice: Subservice = 22u8.try_into().unwrap(); assert_eq!(subservice, Subservice::TcCreateScheduleGroup); } + + #[test] + #[cfg(feature = "serde")] + fn test_serde_subservice_id() { + generic_serde_test(Subservice::TcEnableScheduling); + } + + #[test] + #[cfg(feature = "serde")] + fn test_serde_sched_status() { + generic_serde_test(SchedStatus::Enabled); + } + + #[test] + #[cfg(feature = "serde")] + fn test_serde_time_window_type() { + generic_serde_test(TimeWindowType::SelectAll); + } } diff --git a/src/ecss/tc.rs b/src/ecss/tc.rs index c761126..7e7c938 100644 --- a/src/ecss/tc.rs +++ b/src/ecss/tc.rs @@ -882,6 +882,8 @@ mod tests { use crate::{CcsdsPacket, SequenceFlags}; use alloc::string::ToString; use alloc::vec::Vec; + #[cfg(feature = "serde")] + use postcard::{from_bytes, to_allocvec}; fn base_ping_tc_full_ctor() -> PusTcCreator<'static> { let mut sph = SpHeader::tc_unseg(0x02, 0x34, 0).unwrap(); @@ -1258,4 +1260,13 @@ mod tests { panic!("unexpected error {error}") } } + + #[test] + #[cfg(feature = "serde")] + fn test_serialization_tc_serde() { + let pus_tc = base_ping_tc_simple_ctor(); + let output = to_allocvec(&pus_tc).unwrap(); + let output_converted_back: PusTcCreator = from_bytes(&output).unwrap(); + assert_eq!(output_converted_back, pus_tc); + } }