Coverage Update #47
@ -238,8 +238,7 @@ impl Error for TlvLvError {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
use postcard::{from_bytes, to_allocvec};
|
use crate::tests::generic_serde_test;
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_crc_from_bool() {
|
fn test_crc_from_bool() {
|
||||||
@ -270,24 +269,24 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
fn test_serde_impl_pdu_type() {
|
fn test_serde_impl_pdu_type() {
|
||||||
let pdu_type = PduType::FileData;
|
generic_serde_test(PduType::FileData);
|
||||||
let output = to_allocvec(&pdu_type).unwrap();
|
|
||||||
assert_eq!(from_bytes::<PduType>(&output).unwrap(), pdu_type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
fn test_serde_impl_direction() {
|
fn test_serde_impl_direction() {
|
||||||
let direction = Direction::TowardsReceiver;
|
generic_serde_test(Direction::TowardsReceiver);
|
||||||
let output = to_allocvec(&direction).unwrap();
|
|
||||||
assert_eq!(from_bytes::<Direction>(&output).unwrap(), direction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
fn test_serde_impl_transmission_mode() {
|
fn test_serde_impl_transmission_mode() {
|
||||||
let mode = TransmissionMode::Unacknowledged;
|
generic_serde_test(TransmissionMode::Unacknowledged);
|
||||||
let output = to_allocvec(&mode).unwrap();
|
}
|
||||||
assert_eq!(from_bytes::<TransmissionMode>(&output).unwrap(), mode);
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
fn test_serde_fault_handler_code() {
|
||||||
|
generic_serde_test(FaultHandlerCode::NoticeOfCancellation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,7 +201,7 @@ mod tests {
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
use postcard::{from_bytes, to_allocvec};
|
use crate::tests::generic_serde_test;
|
||||||
|
|
||||||
fn verify_state(ack_pdu: &AckPdu, expected_crc_flag: CrcFlag, expected_dir: Direction) {
|
fn verify_state(ack_pdu: &AckPdu, expected_crc_flag: CrcFlag, expected_dir: Direction) {
|
||||||
assert_eq!(ack_pdu.condition_code(), ConditionCode::NoError);
|
assert_eq!(ack_pdu.condition_code(), ConditionCode::NoError);
|
||||||
@ -329,7 +329,6 @@ mod tests {
|
|||||||
ConditionCode::NoError,
|
ConditionCode::NoError,
|
||||||
TransactionStatus::Active,
|
TransactionStatus::Active,
|
||||||
);
|
);
|
||||||
let output = to_allocvec(&ack_pdu).unwrap();
|
generic_serde_test(ack_pdu);
|
||||||
assert_eq!(from_bytes::<AckPdu>(&output).unwrap(), ack_pdu);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,6 +168,8 @@ mod tests {
|
|||||||
};
|
};
|
||||||
use crate::cfdp::pdu::{FileDirectiveType, PduHeader};
|
use crate::cfdp::pdu::{FileDirectiveType, PduHeader};
|
||||||
use crate::cfdp::{ConditionCode, CrcFlag, LargeFileFlag, PduType, TransmissionMode};
|
use crate::cfdp::{ConditionCode, CrcFlag, LargeFileFlag, PduType, TransmissionMode};
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use crate::tests::generic_serde_test;
|
||||||
|
|
||||||
fn verify_state(&eof_pdu: &EofPdu, file_flag: LargeFileFlag) {
|
fn verify_state(&eof_pdu: &EofPdu, file_flag: LargeFileFlag) {
|
||||||
assert_eq!(eof_pdu.file_checksum(), 0x01020304);
|
assert_eq!(eof_pdu.file_checksum(), 0x01020304);
|
||||||
@ -283,4 +285,13 @@ mod tests {
|
|||||||
verify_state(&eof_pdu, LargeFileFlag::Large);
|
verify_state(&eof_pdu, LargeFileFlag::Large);
|
||||||
assert_eq!(eof_pdu.len_written(), pdu_header.header_len() + 2 + 8 + 4);
|
assert_eq!(eof_pdu.len_written(), pdu_header.header_len() + 2 + 8 + 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
fn test_eof_serde() {
|
||||||
|
let pdu_conf = common_pdu_conf(CrcFlag::NoCrc, LargeFileFlag::Normal);
|
||||||
|
let pdu_header = PduHeader::new_no_file_data(pdu_conf, 0);
|
||||||
|
let eof_pdu = EofPdu::new_no_error(pdu_header, 0x01020304, 12);
|
||||||
|
generic_serde_test(eof_pdu);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -276,6 +276,8 @@ mod tests {
|
|||||||
};
|
};
|
||||||
use crate::cfdp::pdu::{FileDirectiveType, PduHeader};
|
use crate::cfdp::pdu::{FileDirectiveType, PduHeader};
|
||||||
use crate::cfdp::{ConditionCode, CrcFlag, Direction, LargeFileFlag, TransmissionMode};
|
use crate::cfdp::{ConditionCode, CrcFlag, Direction, LargeFileFlag, TransmissionMode};
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use postcard::{from_bytes, to_allocvec};
|
||||||
|
|
||||||
fn generic_finished_pdu(
|
fn generic_finished_pdu(
|
||||||
crc_flag: CrcFlag,
|
crc_flag: CrcFlag,
|
||||||
@ -491,4 +493,19 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_deserialization_with_fs_responses() {}
|
fn test_deserialization_with_fs_responses() {}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
fn test_finished_serialization_serde() {
|
||||||
|
let finished_pdu = generic_finished_pdu(
|
||||||
|
CrcFlag::NoCrc,
|
||||||
|
LargeFileFlag::Normal,
|
||||||
|
DeliveryCode::Complete,
|
||||||
|
FileStatus::Retained,
|
||||||
|
);
|
||||||
|
|
||||||
|
let output = to_allocvec(&finished_pdu).unwrap();
|
||||||
|
let output_converted_back: FinishedPdu = from_bytes(&output).unwrap();
|
||||||
|
assert_eq!(output_converted_back, finished_pdu);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -382,6 +382,8 @@ mod tests {
|
|||||||
use crate::ByteConversionError;
|
use crate::ByteConversionError;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use crate::tests::generic_serde_test;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_enum_u8() {
|
fn test_enum_u8() {
|
||||||
@ -492,4 +494,10 @@ mod tests {
|
|||||||
let pfc = RealPfc::try_from(pfc_raw).unwrap();
|
let pfc = RealPfc::try_from(pfc_raw).unwrap();
|
||||||
assert_eq!(pfc, RealPfc::Double);
|
assert_eq!(pfc, RealPfc::Double);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
fn test_serde_pus_service_id() {
|
||||||
|
generic_serde_test(PusServiceId::Verification);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -860,7 +860,10 @@ impl<'raw_data> PusTmReader<'raw_data> {
|
|||||||
|
|
||||||
impl PartialEq for PusTmReader<'_> {
|
impl PartialEq for PusTmReader<'_> {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.raw_data == other.raw_data
|
self.sec_header == other.sec_header
|
||||||
|
&& self.source_data == other.source_data
|
||||||
|
&& self.sp_header == other.sp_header
|
||||||
|
&& self.crc16 == other.crc16
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -997,7 +1000,11 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::ecss::PusVersion::PusC;
|
use crate::ecss::PusVersion::PusC;
|
||||||
use crate::time::cds::TimeProvider;
|
use crate::time::cds::TimeProvider;
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use crate::time::CcsdsTimeProvider;
|
||||||
use crate::SpHeader;
|
use crate::SpHeader;
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use postcard::{from_bytes, to_allocvec};
|
||||||
|
|
||||||
fn base_ping_reply_full_ctor(timestamp: &[u8]) -> PusTmCreator {
|
fn base_ping_reply_full_ctor(timestamp: &[u8]) -> PusTmCreator {
|
||||||
let mut sph = SpHeader::tm_unseg(0x123, 0x234, 0).unwrap();
|
let mut sph = SpHeader::tm_unseg(0x123, 0x234, 0).unwrap();
|
||||||
@ -1372,4 +1379,35 @@ mod tests {
|
|||||||
panic!("unexpected error {tm_error}")
|
panic!("unexpected error {tm_error}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
fn test_serialization_creator_serde() {
|
||||||
|
let mut sph = SpHeader::tm_unseg(0x123, 0x234, 0).unwrap();
|
||||||
|
let time_provider = TimeProvider::new_with_u16_days(0, 0);
|
||||||
|
let mut stamp_buf: [u8; 8] = [0; 8];
|
||||||
|
let pus_tm =
|
||||||
|
PusTmCreator::new_simple(&mut sph, 17, 2, &time_provider, &mut stamp_buf, &[], true)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let output = to_allocvec(&pus_tm).unwrap();
|
||||||
|
let output_converted_back: PusTmCreator = from_bytes(&output).unwrap();
|
||||||
|
assert_eq!(output_converted_back, pus_tm);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
fn test_serialization_reader_serde() {
|
||||||
|
let mut sph = SpHeader::tm_unseg(0x123, 0x234, 0).unwrap();
|
||||||
|
let time_provider = TimeProvider::new_with_u16_days(0, 0);
|
||||||
|
let mut stamp_buf: [u8; 8] = [0; 8];
|
||||||
|
let pus_tm =
|
||||||
|
PusTmCreator::new_simple(&mut sph, 17, 2, &time_provider, &mut stamp_buf, &[], true)
|
||||||
|
.unwrap();
|
||||||
|
let pus_tm_vec = pus_tm.to_vec().unwrap();
|
||||||
|
let (tm_reader, _) = PusTmReader::new(&pus_tm_vec, time_provider.len_as_bytes()).unwrap();
|
||||||
|
let output = to_allocvec(&tm_reader).unwrap();
|
||||||
|
let output_converted_back: PusTmReader = from_bytes(&output).unwrap();
|
||||||
|
assert_eq!(output_converted_back, tm_reader);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
17
src/lib.rs
17
src/lib.rs
@ -749,7 +749,7 @@ pub mod zc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(test, feature = "std"))]
|
#[cfg(all(test, feature = "std"))]
|
||||||
mod tests {
|
pub(crate) mod tests {
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
@ -759,9 +759,13 @@ mod tests {
|
|||||||
};
|
};
|
||||||
use crate::{SequenceFlags, SpHeader};
|
use crate::{SequenceFlags, SpHeader};
|
||||||
use alloc::vec;
|
use alloc::vec;
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use core::fmt::Debug;
|
||||||
use num_traits::pow;
|
use num_traits::pow;
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
use postcard::{from_bytes, to_allocvec};
|
use postcard::{from_bytes, to_allocvec};
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
|
|
||||||
const CONST_SP: SpHeader = SpHeader::new(
|
const CONST_SP: SpHeader = SpHeader::new(
|
||||||
PacketId::const_tc(true, 0x36),
|
PacketId::const_tc(true, 0x36),
|
||||||
@ -771,10 +775,19 @@ mod tests {
|
|||||||
|
|
||||||
const PACKET_ID_TM: PacketId = PacketId::const_tm(true, 0x22);
|
const PACKET_ID_TM: PacketId = PacketId::const_tm(true, 0x22);
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
pub(crate) fn generic_serde_test<T: Serialize + DeserializeOwned + PartialEq + Debug>(
|
||||||
|
value: T,
|
||||||
|
) {
|
||||||
|
let output: alloc::vec::Vec<u8> = to_allocvec(&value).unwrap();
|
||||||
|
let output_converted_back: T = from_bytes(&output).unwrap();
|
||||||
|
assert_eq!(output_converted_back, value);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn verify_const_packet_id() {
|
fn verify_const_packet_id() {
|
||||||
assert_eq!(PACKET_ID_TM.apid(), 0x22);
|
assert_eq!(PACKET_ID_TM.apid(), 0x22);
|
||||||
assert_eq!(PACKET_ID_TM.sec_header_flag, true);
|
assert!(PACKET_ID_TM.sec_header_flag);
|
||||||
assert_eq!(PACKET_ID_TM.ptype, PacketType::Tm);
|
assert_eq!(PACKET_ID_TM.ptype, PacketType::Tm);
|
||||||
let const_tc_id = PacketId::const_tc(true, 0x23);
|
let const_tc_id = PacketId::const_tc(true, 0x23);
|
||||||
assert_eq!(const_tc_id.ptype, PacketType::Tc);
|
assert_eq!(const_tc_id.ptype, PacketType::Tc);
|
||||||
|
Loading…
Reference in New Issue
Block a user