Skip to content

Commit 26496bc

Browse files
committed
[eclipse-iceoryx#690] Test slice builder
1 parent 452692b commit 26496bc

File tree

2 files changed

+85
-4
lines changed

2 files changed

+85
-4
lines changed

iceoryx2/src/service/builder/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ impl<S: Service> Builder<S> {
121121
/// Create a new builder to create a
122122
/// [`MessagingPattern::RequestResponse`](crate::service::messaging_pattern::MessagingPattern::RequestResponse) [`Service`].
123123
pub fn request_response<
124-
RequestPayload: Debug + ZeroCopySend,
125-
ResponsePayload: Debug + ZeroCopySend,
124+
RequestPayload: Debug + ZeroCopySend + ?Sized,
125+
ResponsePayload: Debug + ZeroCopySend + ?Sized,
126126
>(
127127
self,
128128
) -> request_response::Builder<RequestPayload, (), ResponsePayload, (), S> {
@@ -180,8 +180,8 @@ impl<ServiceType: service::Service> BuilderWithServiceType<ServiceType> {
180180
}
181181

182182
fn request_response<
183-
RequestPayload: Debug + ZeroCopySend,
184-
ResponsePayload: Debug + ZeroCopySend,
183+
RequestPayload: Debug + ZeroCopySend + ?Sized,
184+
ResponsePayload: Debug + ZeroCopySend + ?Sized,
185185
>(
186186
self,
187187
) -> request_response::Builder<RequestPayload, (), ResponsePayload, (), ServiceType> {

iceoryx2/tests/service_request_response_builder_tests.rs

+81
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,87 @@ mod service_request_response {
11441144
assert_that!(sut.static_config().response_message_type_details().payload.alignment, eq core::mem::align_of::<ResponsePayload>());
11451145
}
11461146

1147+
#[test]
1148+
fn create_service_with_request_slice_type_works<Sut: Service>() {
1149+
let config = generate_isolated_config();
1150+
let service_name = generate_service_name();
1151+
let node = NodeBuilder::new().config(&config).create::<Sut>().unwrap();
1152+
1153+
let sut_create = node
1154+
.service_builder(&service_name)
1155+
.request_response::<[u64], u64>()
1156+
.create();
1157+
assert_that!(sut_create, is_ok);
1158+
1159+
let sut_open_fail = node
1160+
.service_builder(&service_name)
1161+
.request_response::<u64, u64>()
1162+
.open();
1163+
assert_that!(sut_open_fail.err(), eq Some(RequestResponseOpenError::IncompatibleRequestType));
1164+
1165+
let sut_open = node
1166+
.service_builder(&service_name)
1167+
.request_response::<[u64], u64>()
1168+
.open();
1169+
assert_that!(sut_open, is_ok);
1170+
}
1171+
1172+
#[test]
1173+
fn create_service_with_response_slice_type_works<Sut: Service>() {
1174+
let config = generate_isolated_config();
1175+
let service_name = generate_service_name();
1176+
let node = NodeBuilder::new().config(&config).create::<Sut>().unwrap();
1177+
1178+
let sut_create = node
1179+
.service_builder(&service_name)
1180+
.request_response::<u64, [u64]>()
1181+
.create();
1182+
assert_that!(sut_create, is_ok);
1183+
1184+
let sut_open_fail = node
1185+
.service_builder(&service_name)
1186+
.request_response::<u64, u64>()
1187+
.open();
1188+
assert_that!(sut_open_fail.err(), eq Some(RequestResponseOpenError::IncompatibleResponseType));
1189+
1190+
let sut_open = node
1191+
.service_builder(&service_name)
1192+
.request_response::<u64, [u64]>()
1193+
.open();
1194+
assert_that!(sut_open, is_ok);
1195+
}
1196+
1197+
#[test]
1198+
fn create_service_with_request_and_response_slice_type_works<Sut: Service>() {
1199+
let config = generate_isolated_config();
1200+
let service_name = generate_service_name();
1201+
let node = NodeBuilder::new().config(&config).create::<Sut>().unwrap();
1202+
1203+
let sut_create = node
1204+
.service_builder(&service_name)
1205+
.request_response::<[u64], [u64]>()
1206+
.create();
1207+
assert_that!(sut_create, is_ok);
1208+
1209+
let sut_open_fail = node
1210+
.service_builder(&service_name)
1211+
.request_response::<[u64], u64>()
1212+
.open();
1213+
assert_that!(sut_open_fail.err(), eq Some(RequestResponseOpenError::IncompatibleResponseType));
1214+
1215+
let sut_open_fail = node
1216+
.service_builder(&service_name)
1217+
.request_response::<u64, [u64]>()
1218+
.open();
1219+
assert_that!(sut_open_fail.err(), eq Some(RequestResponseOpenError::IncompatibleRequestType));
1220+
1221+
let sut_open = node
1222+
.service_builder(&service_name)
1223+
.request_response::<[u64], [u64]>()
1224+
.open();
1225+
assert_that!(sut_open, is_ok);
1226+
}
1227+
11471228
#[instantiate_tests(<iceoryx2::service::ipc::Service>)]
11481229
mod ipc {}
11491230

0 commit comments

Comments
 (0)