Coverage Update #47

Merged
muellerr merged 35 commits from coverage-update into main 2023-12-06 18:05:57 +01:00
3 changed files with 62 additions and 11 deletions
Showing only changes of commit fc18a01b4c - Show all commits

View File

@ -340,7 +340,10 @@ impl CfdpPdu for MetadataPduReader<'_> {
#[cfg(test)] #[cfg(test)]
pub mod tests { pub mod tests {
use alloc::string::ToString;
use crate::cfdp::lv::Lv; use crate::cfdp::lv::Lv;
use crate::cfdp::pdu::eof::EofPdu;
use crate::cfdp::pdu::metadata::{ use crate::cfdp::pdu::metadata::{
build_metadata_opts_from_slice, build_metadata_opts_from_vec, MetadataGenericParams, build_metadata_opts_from_slice, build_metadata_opts_from_vec, MetadataGenericParams,
MetadataPduCreator, MetadataPduReader, MetadataPduCreator, MetadataPduReader,
@ -348,7 +351,7 @@ pub mod tests {
use crate::cfdp::pdu::tests::{ use crate::cfdp::pdu::tests::{
common_pdu_conf, verify_raw_header, TEST_DEST_ID, TEST_SEQ_NUM, TEST_SRC_ID, common_pdu_conf, verify_raw_header, TEST_DEST_ID, TEST_SEQ_NUM, TEST_SRC_ID,
}; };
use crate::cfdp::pdu::{CfdpPdu, WritablePduPacket}; use crate::cfdp::pdu::{CfdpPdu, PduError, WritablePduPacket};
use crate::cfdp::pdu::{FileDirectiveType, PduHeader}; use crate::cfdp::pdu::{FileDirectiveType, PduHeader};
use crate::cfdp::tlv::{Tlv, TlvType}; use crate::cfdp::tlv::{Tlv, TlvType};
use crate::cfdp::{ use crate::cfdp::{
@ -600,6 +603,45 @@ pub mod tests {
assert_eq!(accumulated_len, pdu_read_back.options().len()); assert_eq!(accumulated_len, pdu_read_back.options().len());
} }
#[test]
fn test_invalid_directive_code() {
let (_, _, metadata_pdu) = generic_metadata_pdu(CrcFlag::NoCrc, LargeFileFlag::Large, &[]);
let mut metadata_vec = metadata_pdu.to_vec().unwrap();
metadata_vec[7] = 0xff;
let metadata_error = MetadataPduReader::from_bytes(&metadata_vec);
assert!(metadata_error.is_err());
let error = metadata_error.unwrap_err();
if let PduError::InvalidDirectiveType { found, expected } = error {
assert_eq!(found, 0xff);
assert_eq!(expected, Some(FileDirectiveType::MetadataPdu));
assert_eq!(
error.to_string(),
"invalid directive type value 255, expected Some(MetadataPdu)"
);
} else {
panic!("Expected InvalidDirectiveType error, got {:?}", error);
}
}
#[test]
fn test_wrong_directive_code() {
let (_, _, metadata_pdu) = generic_metadata_pdu(CrcFlag::NoCrc, LargeFileFlag::Large, &[]);
let mut metadata_vec = metadata_pdu.to_vec().unwrap();
metadata_vec[7] = FileDirectiveType::EofPdu as u8;
let metadata_error = MetadataPduReader::from_bytes(&metadata_vec);
assert!(metadata_error.is_err());
let error = metadata_error.unwrap_err();
if let PduError::WrongDirectiveType { found, expected } = error {
assert_eq!(found, FileDirectiveType::EofPdu);
assert_eq!(expected, FileDirectiveType::MetadataPdu);
assert_eq!(
error.to_string(),
"found directive type EofPdu, expected MetadataPdu"
);
} else {
panic!("Expected InvalidDirectiveType error, got {:?}", error);
}
}
#[test] #[test]
fn test_corrects_pdu_header() { fn test_corrects_pdu_header() {
let pdu_header = PduHeader::new_for_file_data( let pdu_header = PduHeader::new_for_file_data(

View File

@ -55,7 +55,6 @@ pub enum PduError {
found: u8, found: u8,
expected: Option<FileDirectiveType>, expected: Option<FileDirectiveType>,
}, },
InvalidSegmentRequestFormat,
InvalidStartOrEndOfScopeValue, InvalidStartOrEndOfScopeValue,
/// Invalid condition code. Contains the raw detected value. /// Invalid condition code. Contains the raw detected value.
InvalidConditionCode(u8), InvalidConditionCode(u8),
@ -80,9 +79,6 @@ impl Display for PduError {
"invalid PDU entity ID length {raw_id}, only [1, 2, 4, 8] are allowed" "invalid PDU entity ID length {raw_id}, only [1, 2, 4, 8] are allowed"
) )
} }
PduError::InvalidSegmentRequestFormat => {
write!(f, "invalid segment request format for NAK PDU")
}
PduError::InvalidStartOrEndOfScopeValue => { PduError::InvalidStartOrEndOfScopeValue => {
write!(f, "invalid start or end of scope for NAK PDU") write!(f, "invalid start or end of scope for NAK PDU")
} }
@ -855,6 +851,7 @@ mod tests {
// 4 byte fixed header plus three bytes src, dest ID and transaction ID // 4 byte fixed header plus three bytes src, dest ID and transaction ID
assert_eq!(res.unwrap(), 7); assert_eq!(res.unwrap(), 7);
verify_raw_header(&pdu_header, &buf); verify_raw_header(&pdu_header, &buf);
assert_eq!(pdu_header.pdu_datafield_len(), 5);
} }
#[test] #[test]
@ -948,7 +945,10 @@ mod tests {
let error = res.unwrap_err(); let error = res.unwrap_err();
if let PduError::CfdpVersionMissmatch(raw_version) = error { if let PduError::CfdpVersionMissmatch(raw_version) = error {
assert_eq!(raw_version, CFDP_VERSION_2 + 1); assert_eq!(raw_version, CFDP_VERSION_2 + 1);
assert_eq!(error.to_string(), "cfdp version missmatch, found 2, expected 1"); assert_eq!(
error.to_string(),
"cfdp version missmatch, found 2, expected 1"
);
} else { } else {
panic!("invalid exception: {}", error); panic!("invalid exception: {}", error);
} }
@ -1048,6 +1048,10 @@ mod tests {
{ {
assert_eq!(src_id_len, 1); assert_eq!(src_id_len, 1);
assert_eq!(dest_id_len, 2); assert_eq!(dest_id_len, 2);
assert_eq!(
error.to_string(),
"missmatch of PDU source length 1 and destination length 2"
);
} }
} }
@ -1110,7 +1114,7 @@ mod tests {
fn test_pdu_config_clonable_and_comparable() { fn test_pdu_config_clonable_and_comparable() {
let common_pdu_cfg_0 = let common_pdu_cfg_0 =
CommonPduConfig::new_with_byte_fields(UbfU8::new(1), UbfU8::new(2), UbfU8::new(3)) CommonPduConfig::new_with_byte_fields(UbfU8::new(1), UbfU8::new(2), UbfU8::new(3))
.expect("common config creation failed"); .expect("common config creation failed");
let common_pdu_cfg_1 = common_pdu_cfg_0; let common_pdu_cfg_1 = common_pdu_cfg_0;
assert_eq!(common_pdu_cfg_0, common_pdu_cfg_1); assert_eq!(common_pdu_cfg_0, common_pdu_cfg_1);
} }

View File

@ -501,6 +501,8 @@ impl<'a, 'b> PartialEq<NakPduCreator<'a>> for NakPduReader<'b> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use alloc::string::ToString;
use crate::cfdp::{ use crate::cfdp::{
pdu::tests::{common_pdu_conf, verify_raw_header, TEST_DEST_ID, TEST_SEQ_NUM, TEST_SRC_ID}, pdu::tests::{common_pdu_conf, verify_raw_header, TEST_DEST_ID, TEST_SEQ_NUM, TEST_SRC_ID},
PduType, TransmissionMode, PduType, TransmissionMode,
@ -742,11 +744,14 @@ mod tests {
Some(u32_list), Some(u32_list),
); );
assert!(error.is_err()); assert!(error.is_err());
let error = error.unwrap_err();
if let Err(PduError::InvalidStartOrEndOfScopeValue) = error { if let PduError::InvalidStartOrEndOfScopeValue = error {
assert_eq!(error.to_string(), ) assert_eq!(
error.to_string(),
"invalid start or end of scope for NAK PDU"
);
} else { } else {
panic!("API call did not fail"); panic!("unexpected error {error}");
} }
} }