also added a unittest
Some checks failed
Rust/spacepackets/pipeline/head There was a failure building this commit
Rust/spacepackets/pipeline/pr-main There was a failure building this commit

This commit is contained in:
2023-08-10 20:22:07 +02:00
parent fd893fbf89
commit a3da71668f
2 changed files with 26 additions and 12 deletions

View File

@ -220,10 +220,20 @@ impl CommonPduConfig {
)
}
pub fn source_id(&self) -> UnsignedByteField {
self.source_entity_id
}
pub fn dest_id(&self) -> UnsignedByteField {
self.dest_entity_id
}
}
impl Default for CommonPduConfig {
/// The defaults for the source ID, destination ID and the transaction sequence number is the
/// [UnsignedByteFieldU8] with an intitial value of 0
pub fn new_with_defaults() -> Self {
// new can not fail for these input parameters
fn default() -> Self {
// The new function can not fail for these input parameters.
Self::new(
UnsignedByteFieldU8::new(0),
UnsignedByteFieldU8::new(0),
@ -235,14 +245,6 @@ impl CommonPduConfig {
)
.unwrap()
}
pub fn source_id(&self) -> UnsignedByteField {
self.source_entity_id
}
pub fn dest_id(&self) -> UnsignedByteField {
self.dest_entity_id
}
}
pub const FIXED_HEADER_LEN: usize = 4;
@ -683,6 +685,18 @@ mod tests {
assert_eq!(pdu_header.header_len(), 7);
}
#[test]
fn test_basic_state_default() {
let default_conf = CommonPduConfig::default();
assert_eq!(default_conf.source_id(), UnsignedByteFieldU8::new(0).into());
assert_eq!(default_conf.dest_id(), UnsignedByteFieldU8::new(0).into());
assert_eq!(default_conf.transaction_seq_num, UnsignedByteFieldU8::new(0).into());
assert_eq!(default_conf.trans_mode, TransmissionMode::Acknowledged);
assert_eq!(default_conf.direction, Direction::TowardsReceiver);
assert_eq!(default_conf.crc_flag, CrcFlag::NoCrc);
assert_eq!(default_conf.file_flag, LargeFileFlag::Normal);
}
#[test]
fn test_serialization_1() {
let src_id = UnsignedByteFieldU8::new(1);