Skip to content

Commit

Permalink
[eclipse-iceoryx#213] split the big test_is_compatible_to into small …
Browse files Browse the repository at this point in the history
…tests
  • Loading branch information
xieyuschen committed Oct 10, 2024
1 parent ccec2bc commit 88aba3d
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 88aba3d

Please sign in to comment.