what is this
Some checks failed
Rust/spacepackets/pipeline/head There was a failure building this commit

This commit is contained in:
Robin Müller 2023-12-05 18:35:08 +01:00
parent ed4c8af164
commit c19e8e6464
Signed by: muellerr
GPG Key ID: A649FB78196E3849
2 changed files with 47 additions and 1 deletions

View File

@ -886,6 +886,41 @@ mod tests {
assert!(tlv_empty.value().is_empty()); assert!(tlv_empty.value().is_empty());
} }
#[test]
fn test_write_buf_too_small() {
let mut buf: [u8; 2] = [0; 2];
let fs_request =
FilestoreRequestTlv::new_create_file(Lv::new_from_str(TLV_TEST_STR_0).unwrap())
.unwrap();
let error = fs_request.write_to_bytes(&mut buf);
assert!(error.is_err());
let error = error.unwrap_err();
if let ByteConversionError::ToSliceTooSmall { found, expected } = error {
assert_eq!(found, 2);
assert_eq!(expected, 13);
} else {
panic!("unexpected error {:?}", error);
}
}
#[test]
fn test_read_from_buf_too_small() {
let buf: [u8; 1] = [0; 1];
let error = FilestoreRequestTlv::from_bytes(&buf);
assert!(error.is_err());
let error = error.unwrap_err();
if let TlvLvError::ByteConversion(ByteConversionError::FromSliceTooSmall {
found,
expected,
}) = error
{
assert_eq!(found, 1);
assert_eq!(expected, 2);
} else {
panic!("unexpected error {:?}", error);
}
}
#[test] #[test]
fn test_buf_too_large() { fn test_buf_too_large() {
let buf_too_large: [u8; u8::MAX as usize + 1] = [0; u8::MAX as usize + 1]; let buf_too_large: [u8; u8::MAX as usize + 1] = [0; u8::MAX as usize + 1];
@ -1132,7 +1167,10 @@ mod tests {
assert_eq!(written_len, 2 + 1 + lv_0.len_full() + 1); assert_eq!(written_len, 2 + 1 + lv_0.len_full() + 1);
assert_eq!(buf[0], TlvType::FilestoreResponse as u8); assert_eq!(buf[0], TlvType::FilestoreResponse as u8);
assert_eq!(buf[1], written_len as u8 - 2); assert_eq!(buf[1], written_len as u8 - 2);
assert_eq!((buf[2] >> 4) & 0b1111, FilestoreActionCode::CreateFile as u8); assert_eq!(
(buf[2] >> 4) & 0b1111,
FilestoreActionCode::CreateFile as u8
);
assert_eq!(buf[2] & 0b1111, 0b0001); assert_eq!(buf[2] & 0b1111, 0b0001);
let lv_read_back = Lv::from_bytes(&buf[3..]).unwrap(); let lv_read_back = Lv::from_bytes(&buf[3..]).unwrap();
assert_eq!(lv_0, lv_read_back); assert_eq!(lv_0, lv_read_back);

View File

@ -2252,6 +2252,14 @@ mod tests {
assert_eq!(stamp_small.ms_of_day(), 500); assert_eq!(stamp_small.ms_of_day(), 500);
} }
#[test]
fn test_update_from_now() {
let mut stamp = TimeProvider::new_with_u16_days(0, 0);
stamp.update_from_now();
let dt = stamp.as_date_time();
assert!(dt.year() > 2020);
}
#[test] #[test]
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
fn test_serialization() { fn test_serialization() {