Skip to content

Commit

Permalink
[#213] split the big test_is_compatible_to into small tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuschen committed Oct 10, 2024
1 parent 46ae5df commit 64fe776
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion iceoryx2/src/service/static_config/message_type_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ mod tests {
}

#[test]
fn test_is_compatible_to() {
fn test_is_compatible_to_failed_when_types_differ() {
let left = MessageTypeDetails::from::<i64, i64, i8>(TypeVariant::FixedSize);
let right = MessageTypeDetails::from::<i64, i64, u8>(TypeVariant::FixedSize);
let sut = left.is_compatible_to(&right);
Expand All @@ -361,6 +361,11 @@ mod tests {
let right = MessageTypeDetails::from::<i64, i64, i32>(TypeVariant::FixedSize);
let sut = left.is_compatible_to(&right);
assert_that!(sut, eq false);
}

#[test]
fn test_is_compatible_to_succeed_when_rhs_aligment_is_bigger() {
let left = MessageTypeDetails::from::<i64, i64, i64>(TypeVariant::FixedSize);

// right may have a different alignment from left.
// but note that the header alignment must be the same
Expand Down Expand Up @@ -392,4 +397,35 @@ mod tests {
let sut = right.is_compatible_to(&left);
assert_that!(sut, eq false);
}

#[test]
fn test_is_compatible_to_fail_when_rhs_aligment_is_smaller() {
let left = MessageTypeDetails::from::<i64, i64, i64>(TypeVariant::FixedSize);

// right may have a different alignment from left.
// but note that the header alignment must be the same
let right = MessageTypeDetails {
header: TypeDetail {
variant: TypeVariant::FixedSize,
type_name: "i64".to_string(),
size: 8,
alignment: ALIGNMENT,
},
user_header: TypeDetail {
variant: TypeVariant::FixedSize,
type_name: "i64".to_string(),
size: 8,
alignment: 2 * ALIGNMENT,
},
payload: TypeDetail {
variant: TypeVariant::FixedSize,
type_name: "i64".to_string(),
size: 8,
alignment: 2 * ALIGNMENT,
},
};
// bigger to smaller is invalid.
let sut = right.is_compatible_to(&left);
assert_that!(sut, eq false);
}
}

0 comments on commit 64fe776

Please sign in to comment.