Skip to content

Commit

Permalink
move coverage improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Dec 3, 2023
1 parent 44383c1 commit a253550
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
32 changes: 28 additions & 4 deletions src/cfdp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -195,7 +195,7 @@ pub enum TlvLvError {

impl From<ByteConversionError> for TlvLvError {
fn from(value: ByteConversionError) -> Self {
Self::ByteConversionError(value)
Self::ByteConversion(value)
}
}

Expand All @@ -210,7 +210,7 @@ impl Display for TlvLvError {
u8::MAX
)
}
TlvLvError::ByteConversionError(e) => {
TlvLvError::ByteConversion(e) => {
write!(f, "{}", e)
}
TlvLvError::InvalidTlvTypeField((found, expected)) => {
Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/cfdp/tlv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
})
Expand Down

0 comments on commit a253550

Please sign in to comment.