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 35 additions and 5 deletions
Showing only changes of commit a2535502ea - Show all commits

View File

@ -27,6 +27,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
allow those fields to have different widths.
- Removed the `PusError::RawDataTooShort` variant which is already covered by
`PusError::ByteConversionError` variant.
- Ranamed `TlvLvError::ByteConversionError` to `TlvLvError::ByteConversion`.
## Removed
- Removed `PusError::NoRawData` and renamed `PusError::IncorrectCrc` to
`PusError::ChecksumFailure`.
# [v0.7.0-beta.2] 2023-09-26

View File

@ -180,7 +180,7 @@ pub const NULL_CHECKSUM_U32: [u8; 4] = [0; 4];
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum TlvLvError {
DataTooLarge(usize),
ByteConversionError(ByteConversionError),
ByteConversion(ByteConversionError),
/// First value: Found value. Second value: Expected value if there is one.
InvalidTlvTypeField((u8, Option<u8>)),
/// Logically invalid value length detected. The value length may not exceed 255 bytes.
@ -195,7 +195,7 @@ pub enum TlvLvError {
impl From<ByteConversionError> for TlvLvError {
fn from(value: ByteConversionError) -> Self {
Self::ByteConversionError(value)
Self::ByteConversion(value)
}
}
@ -210,7 +210,7 @@ impl Display for TlvLvError {
u8::MAX
)
}
TlvLvError::ByteConversionError(e) => {
TlvLvError::ByteConversion(e) => {
write!(f, "{}", e)
}
TlvLvError::InvalidTlvTypeField((found, expected)) => {
@ -236,8 +236,32 @@ impl Display for TlvLvError {
impl Error for TlvLvError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
TlvLvError::ByteConversionError(e) => Some(e),
TlvLvError::ByteConversion(e) => Some(e),
_ => None,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_crc_from_bool() {
assert_eq!(CrcFlag::from(false), CrcFlag::NoCrc);
}
#[test]
fn test_crc_flag_to_bool() {
let is_true: bool = CrcFlag::WithCrc.into();
assert!(is_true);
let is_false: bool = CrcFlag::NoCrc.into();
assert!(!is_false);
}
#[test]
fn test_default_checksum_type() {
let checksum = ChecksumType::default();
assert_eq!(checksum, ChecksumType::NullChecksum);
}
}

View File

@ -241,7 +241,7 @@ impl EntityIdTlv {
self.entity_id
.write_to_be_bytes(&mut buf[2..2 + self.entity_id.size()])?;
Tlv::new(TlvType::EntityId, &buf[2..2 + self.entity_id.size()]).map_err(|e| match e {
TlvLvError::ByteConversionError(e) => e,
TlvLvError::ByteConversion(e) => e,
// All other errors are impossible.
_ => panic!("unexpected TLV error"),
})