add some more tests
This commit is contained in:
parent
a8f1da4117
commit
14b85992e8
@ -13,7 +13,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
## Added
|
||||
|
||||
- Added `value` and `to_vec` methods for the `UnsignedEnum` trait. The value is returned as
|
||||
as `u64`.
|
||||
as `u64`. Renamed former `value` method on `GenericUnsignedByteField` to `value_typed`.
|
||||
- Added `value_const` const function for `UnsignedByteField` type.
|
||||
- Added `value_typed` const functions for `GenericUnsignedByteField` and `GenericEcssEnumWrapper`.
|
||||
|
||||
# [v0.9.0] 2024-02-07
|
||||
|
||||
|
@ -324,6 +324,10 @@ impl<TYPE: Copy + Into<u64>> GenericEcssEnumWrapper<TYPE> {
|
||||
PacketTypeCodes::Enumerated
|
||||
}
|
||||
|
||||
pub const fn value_typed(&self) -> TYPE {
|
||||
self.field.value_typed()
|
||||
}
|
||||
|
||||
pub fn new(val: TYPE) -> Self {
|
||||
Self {
|
||||
field: GenericUnsignedByteField::new(val),
|
||||
@ -401,6 +405,7 @@ mod tests {
|
||||
.expect("To byte conversion of u8 failed");
|
||||
assert_eq!(buf[1], 1);
|
||||
assert_eq!(my_enum.value(), 1);
|
||||
assert_eq!(my_enum.value_typed(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -415,6 +420,7 @@ mod tests {
|
||||
assert_eq!(buf[1], 0x1f);
|
||||
assert_eq!(buf[2], 0x2f);
|
||||
assert_eq!(my_enum.value(), 0x1f2f);
|
||||
assert_eq!(my_enum.value_typed(), 0x1f2f);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -447,6 +453,7 @@ mod tests {
|
||||
assert_eq!(buf[3], 0x3f);
|
||||
assert_eq!(buf[4], 0x4f);
|
||||
assert_eq!(my_enum.value(), 0x1f2f3f4f);
|
||||
assert_eq!(my_enum.value_typed(), 0x1f2f3f4f);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -467,6 +474,23 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_enum_u64() {
|
||||
let mut buf = [0; 8];
|
||||
let my_enum = EcssEnumU64::new(0x1f2f3f4f5f);
|
||||
my_enum
|
||||
.write_to_be_bytes(&mut buf)
|
||||
.expect("To byte conversion of u64 failed");
|
||||
assert_eq!(buf[3], 0x1f);
|
||||
assert_eq!(buf[4], 0x2f);
|
||||
assert_eq!(buf[5], 0x3f);
|
||||
assert_eq!(buf[6], 0x4f);
|
||||
assert_eq!(buf[7], 0x5f);
|
||||
assert_eq!(my_enum.value(), 0x1f2f3f4f5f);
|
||||
assert_eq!(my_enum.value_typed(), 0x1f2f3f4f5f);
|
||||
assert_eq!(u64::from_be_bytes(buf), 0x1f2f3f4f5f);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pus_error_display() {
|
||||
let unsupport_version = PusError::VersionNotSupported(super::PusVersion::EsaPus);
|
||||
|
@ -246,7 +246,7 @@ impl<TYPE: Copy + ToBeBytes + Into<u64>> UnsignedEnum for GenericUnsignedByteFie
|
||||
expected: self.size(),
|
||||
});
|
||||
}
|
||||
buf[0..self.size()].copy_from_slice(self.value.to_be_bytes().as_ref());
|
||||
buf[..self.size()].copy_from_slice(self.value.to_be_bytes().as_ref());
|
||||
Ok(self.value.written_len())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user