Skip to content

Commit fa7e803

Browse files
committed
split the big test_is_compatible_to into small tests
1 parent 49501f5 commit fa7e803

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

iceoryx2/src/service/static_config/message_type_details.rs

+37-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ mod tests {
351351
}
352352

353353
#[test]
354-
fn test_is_compatible_to() {
354+
fn test_is_compatible_to_failed_when_types_differ() {
355355
let left = MessageTypeDetails::from::<i64, i64, i8>(TypeVariant::FixedSize);
356356
let right = MessageTypeDetails::from::<i64, i64, u8>(TypeVariant::FixedSize);
357357
let sut = left.is_compatible_to(&right);
@@ -361,6 +361,11 @@ mod tests {
361361
let right = MessageTypeDetails::from::<i64, i64, i32>(TypeVariant::FixedSize);
362362
let sut = left.is_compatible_to(&right);
363363
assert_that!(sut, eq false);
364+
}
365+
366+
#[test]
367+
fn test_is_compatible_to_succeed_when_rhs_aligment_is_bigger() {
368+
let left = MessageTypeDetails::from::<i64, i64, i64>(TypeVariant::FixedSize);
364369

365370
// right may have a different alignment from left.
366371
// but note that the header alignment must be the same
@@ -392,4 +397,35 @@ mod tests {
392397
let sut = right.is_compatible_to(&left);
393398
assert_that!(sut, eq false);
394399
}
400+
401+
#[test]
402+
fn test_is_compatible_to_fail_when_rhs_aligment_is_smaller() {
403+
let left = MessageTypeDetails::from::<i64, i64, i64>(TypeVariant::FixedSize);
404+
405+
// right may have a different alignment from left.
406+
// but note that the header alignment must be the same
407+
let right = MessageTypeDetails {
408+
header: TypeDetail {
409+
variant: TypeVariant::FixedSize,
410+
type_name: "i64".to_string(),
411+
size: 8,
412+
alignment: ALIGNMENT,
413+
},
414+
user_header: TypeDetail {
415+
variant: TypeVariant::FixedSize,
416+
type_name: "i64".to_string(),
417+
size: 8,
418+
alignment: 2 * ALIGNMENT,
419+
},
420+
payload: TypeDetail {
421+
variant: TypeVariant::FixedSize,
422+
type_name: "i64".to_string(),
423+
size: 8,
424+
alignment: 2 * ALIGNMENT,
425+
},
426+
};
427+
// bigger to smaller is invalid.
428+
let sut = right.is_compatible_to(&left);
429+
assert_that!(sut, eq false);
430+
}
395431
}

0 commit comments

Comments
 (0)