Skip to content

Commit

Permalink
what is this
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Dec 5, 2023
1 parent ed4c8af commit c19e8e6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/cfdp/tlv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,41 @@ mod tests {
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]
fn test_buf_too_large() {
let buf_too_large: [u8; u8::MAX as usize + 1] = [0; u8::MAX as usize + 1];
Expand Down Expand Up @@ -1132,7 +1167,10 @@ mod tests {
assert_eq!(written_len, 2 + 1 + lv_0.len_full() + 1);
assert_eq!(buf[0], TlvType::FilestoreResponse as u8);
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);
let lv_read_back = Lv::from_bytes(&buf[3..]).unwrap();
assert_eq!(lv_0, lv_read_back);
Expand Down
8 changes: 8 additions & 0 deletions src/time/cds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2252,6 +2252,14 @@ mod tests {
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]
#[cfg(feature = "serde")]
fn test_serialization() {
Expand Down

0 comments on commit c19e8e6

Please sign in to comment.