some more serde tests
Some checks failed
Rust/spacepackets/pipeline/head There was a failure building this commit
Some checks failed
Rust/spacepackets/pipeline/head There was a failure building this commit
This commit is contained in:
@ -238,8 +238,7 @@ impl Error for TlvLvError {
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[cfg(feature = "serde")]
|
||||
use postcard::{from_bytes, to_allocvec};
|
||||
|
||||
use crate::tests::generic_serde_test;
|
||||
|
||||
#[test]
|
||||
fn test_crc_from_bool() {
|
||||
@ -268,26 +267,26 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature="serde")]
|
||||
#[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::<PduType>(&output).unwrap(), pdu_type);
|
||||
generic_serde_test(PduType::FileData);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature="serde")]
|
||||
#[cfg(feature = "serde")]
|
||||
fn test_serde_impl_direction() {
|
||||
let direction = Direction::TowardsReceiver;
|
||||
let output = to_allocvec(&direction).unwrap();
|
||||
assert_eq!(from_bytes::<Direction>(&output).unwrap(), direction);
|
||||
generic_serde_test(Direction::TowardsReceiver);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature="serde")]
|
||||
#[cfg(feature = "serde")]
|
||||
fn test_serde_impl_transmission_mode() {
|
||||
let mode = TransmissionMode::Unacknowledged;
|
||||
let output = to_allocvec(&mode).unwrap();
|
||||
assert_eq!(from_bytes::<TransmissionMode>(&output).unwrap(), mode);
|
||||
generic_serde_test(TransmissionMode::Unacknowledged);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "serde")]
|
||||
fn test_serde_fault_handler_code() {
|
||||
generic_serde_test(FaultHandlerCode::NoticeOfCancellation);
|
||||
}
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ mod tests {
|
||||
|
||||
use super::*;
|
||||
#[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) {
|
||||
assert_eq!(ack_pdu.condition_code(), ConditionCode::NoError);
|
||||
@ -320,7 +320,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature="serde")]
|
||||
#[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);
|
||||
@ -329,7 +329,6 @@ mod tests {
|
||||
ConditionCode::NoError,
|
||||
TransactionStatus::Active,
|
||||
);
|
||||
let output = to_allocvec(&ack_pdu).unwrap();
|
||||
assert_eq!(from_bytes::<AckPdu>(&output).unwrap(), ack_pdu);
|
||||
generic_serde_test(ack_pdu);
|
||||
}
|
||||
}
|
||||
|
@ -168,6 +168,8 @@ mod tests {
|
||||
};
|
||||
use crate::cfdp::pdu::{FileDirectiveType, PduHeader};
|
||||
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) {
|
||||
assert_eq!(eof_pdu.file_checksum(), 0x01020304);
|
||||
@ -283,4 +285,13 @@ mod tests {
|
||||
verify_state(&eof_pdu, LargeFileFlag::Large);
|
||||
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::{ConditionCode, CrcFlag, Direction, LargeFileFlag, TransmissionMode};
|
||||
#[cfg(feature = "serde")]
|
||||
use postcard::{from_bytes, to_allocvec};
|
||||
|
||||
fn generic_finished_pdu(
|
||||
crc_flag: CrcFlag,
|
||||
@ -491,4 +493,19 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user