add some more tests
This commit is contained in:
@@ -596,6 +596,31 @@ mod tests {
|
|||||||
assert_eq!(primary_header.vc_frame_count(), 5);
|
assert_eq!(primary_header.vc_frame_count(), 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_vcf_count_len_one() {
|
||||||
|
let mut buf: [u8; 16] = [0; 16];
|
||||||
|
// Should be all zeros after writing.
|
||||||
|
buf[6] = 0xff;
|
||||||
|
let mut primary_header = PrimaryHeader::new(
|
||||||
|
0b10100101_11000011,
|
||||||
|
SourceOrDestField::Dest,
|
||||||
|
0b110101,
|
||||||
|
0b1010,
|
||||||
|
0x2345,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
primary_header.set_vc_frame_count(1, 255).unwrap();
|
||||||
|
assert_eq!(primary_header.vc_frame_count_len(), 1);
|
||||||
|
assert_eq!(primary_header.vc_frame_count(), 255);
|
||||||
|
assert_eq!(primary_header.write_to_be_bytes(&mut buf).unwrap(), 8);
|
||||||
|
assert_eq!(buf[6] & 0b111, 1);
|
||||||
|
assert_eq!(buf[7], 255);
|
||||||
|
|
||||||
|
let primary_header = PrimaryHeader::from_bytes(&buf).unwrap();
|
||||||
|
assert_eq!(primary_header.vc_frame_count_len(), 1);
|
||||||
|
assert_eq!(primary_header.vc_frame_count(), 255);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_reading_0() {
|
fn test_reading_0() {
|
||||||
let mut buf: [u8; 8] = [0; 8];
|
let mut buf: [u8; 8] = [0; 8];
|
||||||
@@ -840,4 +865,77 @@ mod tests {
|
|||||||
UslpError::InvalidVersionNumber(0)
|
UslpError::InvalidVersionNumber(0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_primary_header_buf_too_small() {
|
||||||
|
let primary_header = PrimaryHeader::new(
|
||||||
|
0b10100101_11000011,
|
||||||
|
SourceOrDestField::Dest,
|
||||||
|
0b110101,
|
||||||
|
0b1010,
|
||||||
|
0x2345,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
if let Err(ByteConversionError::ToSliceTooSmall { found, expected }) =
|
||||||
|
primary_header.write_to_be_bytes(&mut [0; 4])
|
||||||
|
{
|
||||||
|
assert_eq!(found, 4);
|
||||||
|
assert_eq!(expected, 7);
|
||||||
|
} else {
|
||||||
|
panic!("writing primary header did not fail or failed with wrong error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_applicability_contr_rules() {
|
||||||
|
assert!(ConstructionRule::PacketSpanningMultipleFrames.applicable_to_fixed_len_tfdz());
|
||||||
|
assert!(ConstructionRule::StartOfMapaSduOrVcaSdu.applicable_to_fixed_len_tfdz());
|
||||||
|
assert!(ConstructionRule::ContinuingPortionOfMapaSdu.applicable_to_fixed_len_tfdz());
|
||||||
|
assert!(!ConstructionRule::OctetStream.applicable_to_fixed_len_tfdz());
|
||||||
|
assert!(!ConstructionRule::StartingSegment.applicable_to_fixed_len_tfdz());
|
||||||
|
assert!(!ConstructionRule::ContinuingSegment.applicable_to_fixed_len_tfdz());
|
||||||
|
assert!(!ConstructionRule::LastSegment.applicable_to_fixed_len_tfdz());
|
||||||
|
assert!(!ConstructionRule::NoSegmentation.applicable_to_fixed_len_tfdz());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_header_len_correctness() {
|
||||||
|
let mut tfdh = TransferFrameDataFieldHeader {
|
||||||
|
construction_rule: ConstructionRule::PacketSpanningMultipleFrames,
|
||||||
|
uslp_protocol_id: UslpProtocolId::UserDefinedOctetStream,
|
||||||
|
fhp_or_lvo: Some(0),
|
||||||
|
};
|
||||||
|
assert_eq!(tfdh.len_header(), 3);
|
||||||
|
tfdh = TransferFrameDataFieldHeader {
|
||||||
|
construction_rule: ConstructionRule::StartOfMapaSduOrVcaSdu,
|
||||||
|
uslp_protocol_id: UslpProtocolId::UserDefinedOctetStream,
|
||||||
|
fhp_or_lvo: Some(0),
|
||||||
|
};
|
||||||
|
assert_eq!(tfdh.len_header(), 3);
|
||||||
|
tfdh = TransferFrameDataFieldHeader {
|
||||||
|
construction_rule: ConstructionRule::ContinuingPortionOfMapaSdu,
|
||||||
|
uslp_protocol_id: UslpProtocolId::UserDefinedOctetStream,
|
||||||
|
fhp_or_lvo: Some(0),
|
||||||
|
};
|
||||||
|
assert_eq!(tfdh.len_header(), 3);
|
||||||
|
tfdh = TransferFrameDataFieldHeader {
|
||||||
|
construction_rule: ConstructionRule::OctetStream,
|
||||||
|
uslp_protocol_id: UslpProtocolId::UserDefinedOctetStream,
|
||||||
|
fhp_or_lvo: None,
|
||||||
|
};
|
||||||
|
assert_eq!(tfdh.len_header(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_frame_data_field_header_from_bytes_too_small() {
|
||||||
|
let buf: [u8; 0] = [];
|
||||||
|
assert_eq!(
|
||||||
|
TransferFrameDataFieldHeader::from_bytes(&buf).unwrap_err(),
|
||||||
|
ByteConversionError::FromSliceTooSmall {
|
||||||
|
found: 0,
|
||||||
|
expected: 1
|
||||||
|
}
|
||||||
|
.into()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user