add unittests for vec conversion
All checks were successful
Rust/spacepackets/pipeline/pr-main This commit looks good
Rust/spacepackets/pipeline/head This commit looks good

This commit is contained in:
2023-11-24 16:34:06 +01:00
parent 4e90bbdc04
commit b82a93757c
6 changed files with 83 additions and 19 deletions

View File

@ -905,6 +905,20 @@ mod tests {
verify_crc_no_app_data(&test_buf);
}
#[test]
fn test_writing_into_vec() {
let pus_tc = base_ping_tc_simple_ctor();
let tc_vec = pus_tc.to_vec().expect("Error writing TC to buffer");
assert_eq!(tc_vec.len(), 13);
let (tc_from_raw, size) = PusTcReader::new(tc_vec.as_slice())
.expect("Creating PUS TC struct from raw buffer failed");
assert_eq!(size, 13);
verify_test_tc_with_reader(&tc_from_raw, false, 13);
assert!(tc_from_raw.user_data().is_empty());
verify_test_tc_raw(&tc_vec);
verify_crc_no_app_data(&tc_vec);
}
#[test]
fn test_update_func() {
let mut sph = SpHeader::tc_unseg(0x02, 0x34, 0).unwrap();

View File

@ -999,7 +999,7 @@ mod tests {
#[test]
fn test_setters() {
let timestamp = dummy_timestamp();
let mut pus_tm = base_ping_reply_full_ctor(&timestamp);
let mut pus_tm = base_ping_reply_full_ctor(timestamp);
pus_tm.set_sc_time_ref_status(0b1010);
pus_tm.set_dest_id(0x7fff);
pus_tm.set_msg_counter(0x1f1f);
@ -1010,10 +1010,21 @@ mod tests {
assert_eq!(pus_tm.apid(), 0x7ff);
}
#[test]
fn test_write_into_vec() {
let timestamp = dummy_timestamp();
let pus_tm = base_ping_reply_full_ctor(timestamp);
let tm_vec = pus_tm.to_vec().expect("Serialization failed");
assert_eq!(tm_vec.len(), 22);
let (tm_deserialized, size) =
PusTmReader::new(tm_vec.as_slice(), 7).expect("Deserialization failed");
assert_eq!(tm_vec.len(), size);
verify_ping_reply_with_reader(&tm_deserialized, false, 22, dummy_timestamp());
}
#[test]
fn test_deserialization_no_source_data() {
let timestamp = dummy_timestamp();
let pus_tm = base_ping_reply_full_ctor(&timestamp);
let pus_tm = base_ping_reply_full_ctor(timestamp);
let mut buf: [u8; 32] = [0; 32];
let ser_len = pus_tm
.write_to_bytes(&mut buf)
@ -1045,7 +1056,7 @@ mod tests {
#[test]
fn test_target_buf_too_small() {
let timestamp = dummy_timestamp();
let pus_tm = base_ping_reply_full_ctor(&timestamp);
let pus_tm = base_ping_reply_full_ctor(timestamp);
let mut buf: [u8; 16] = [0; 16];
let res = pus_tm.write_to_bytes(&mut buf);
assert!(res.is_err());