Skip to content

Commit

Permalink
DO NOT MERGE partial backport of eclipse-iceoryx#932 and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Mar 2, 2022
1 parent 7ae50f1 commit 758eda3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
22 changes: 9 additions & 13 deletions iceoryx_binding_c/source/c_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ ENUM iox_ListenerResult iox_listener_attach_subscriber_event(iox_listener_t cons
const ENUM iox_SubscriberEvent subscriberEvent,
void (*callback)(iox_sub_t))
{
auto result =
self->attachEvent(*subscriber, c2cpp::subscriberEvent(subscriberEvent), createNotificationCallback(*callback));
auto result = self->attachEvent(*subscriber,
c2cpp::subscriberEvent(subscriberEvent),
NotificationCallback<cpp2c_Subscriber, internal::NoType_t>{callback, nullptr});
if (result.has_error())
{
return cpp2c::listenerResult(result.get_error());
Expand All @@ -63,11 +64,9 @@ iox_listener_attach_subscriber_event_with_context_data(iox_listener_t const self
void (*callback)(iox_sub_t, void*),
void* const contextData)
{
NotificationCallback<cpp2c_Subscriber, void> notificationCallback;
notificationCallback.m_callback = callback;
notificationCallback.m_contextData = contextData;

auto result = self->attachEvent(*subscriber, c2cpp::subscriberEvent(subscriberEvent), notificationCallback);
auto result = self->attachEvent(*subscriber,
c2cpp::subscriberEvent(subscriberEvent),
NotificationCallback<cpp2c_Subscriber, void>{callback, contextData});
if (result.has_error())
{
return cpp2c::listenerResult(result.get_error());
Expand All @@ -79,7 +78,8 @@ ENUM iox_ListenerResult iox_listener_attach_user_trigger_event(iox_listener_t co
iox_user_trigger_t const userTrigger,
void (*callback)(iox_user_trigger_t))
{
auto result = self->attachEvent(*userTrigger, createNotificationCallback(*callback));
auto result =
self->attachEvent(*userTrigger, NotificationCallback<UserTrigger, internal::NoType_t>{callback, nullptr});
if (result.has_error())
{
return cpp2c::listenerResult(result.get_error());
Expand All @@ -93,11 +93,7 @@ ENUM iox_ListenerResult iox_listener_attach_user_trigger_event_with_context_data
void*),
void* const contextData)
{
NotificationCallback<UserTrigger, void> notificationCallback;
notificationCallback.m_callback = callback;
notificationCallback.m_contextData = contextData;

auto result = self->attachEvent(*userTrigger, notificationCallback);
auto result = self->attachEvent(*userTrigger, NotificationCallback<UserTrigger, void>{callback, contextData});
if (result.has_error())
{
return cpp2c::listenerResult(result.get_error());
Expand Down
6 changes: 3 additions & 3 deletions iceoryx_binding_c/source/c_wait_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ iox_WaitSetResult iox_ws_attach_subscriber_state(iox_ws_t const self,
void (*callback)(iox_sub_t))
{
auto result = self->attachState(
*subscriber, c2cpp::subscriberState(subscriberState), eventId, createNotificationCallback(*callback));
*subscriber, c2cpp::subscriberState(subscriberState), eventId, {callback, nullptr});
return (result.has_error()) ? cpp2c::waitSetResult(result.get_error()) : iox_WaitSetResult::WaitSetResult_SUCCESS;
}

Expand All @@ -141,7 +141,7 @@ iox_WaitSetResult iox_ws_attach_subscriber_event(iox_ws_t const self,
void (*callback)(iox_sub_t))
{
auto result = self->attachEvent(
*subscriber, c2cpp::subscriberEvent(subscriberEvent), eventId, createNotificationCallback(*callback));
*subscriber, c2cpp::subscriberEvent(subscriberEvent), eventId, {callback, nullptr});
return (result.has_error()) ? cpp2c::waitSetResult(result.get_error()) : iox_WaitSetResult::WaitSetResult_SUCCESS;
}

Expand All @@ -166,7 +166,7 @@ iox_WaitSetResult iox_ws_attach_user_trigger_event(iox_ws_t const self,
const uint64_t eventId,
void (*callback)(iox_user_trigger_t))
{
auto result = self->attachEvent(*userTrigger, eventId, createNotificationCallback(*callback));
auto result = self->attachEvent(*userTrigger, eventId, {callback, nullptr});
return (result.has_error()) ? cpp2c::waitSetResult(result.get_error()) : iox_WaitSetResult::WaitSetResult_SUCCESS;
}

Expand Down
1 change: 1 addition & 0 deletions iceoryx_binding_c/test/moduletests/test_chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Chunk_test : public RouDi_GTest

void TearDown() override
{
iox_pub_deinit(publisher);
}

iox_pub_storage_t publisherStorage;
Expand Down
4 changes: 3 additions & 1 deletion iceoryx_binding_c/test/moduletests/test_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ TEST_F(iox_pub_test, initPublisherWithDefaultOptionsWorks)
iox_pub_options_init(&options);
iox_pub_storage_t storage;

EXPECT_NE(iox_pub_init(&storage, "a", "b", "c", &options), nullptr);
auto ptr = iox_pub_init(&storage, "a", "b", "c", &options);
EXPECT_NE(ptr, nullptr);
iox_pub_deinit(ptr);
}

TEST_F(iox_pub_test, initialStateOfIsOfferedIsAsExpected)
Expand Down
8 changes: 5 additions & 3 deletions iceoryx_binding_c/test/moduletests/test_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ TEST_F(iox_sub_test, initSubscriberWithDefaultOptionsWorks)
iox_sub_options_init(&options);
iox_sub_storage_t storage;

EXPECT_NE(iox_sub_init(&storage, "a", "b", "c", &options), nullptr);
auto ptr = iox_sub_init(&storage, "a", "b", "c", &options);
EXPECT_NE(ptr, nullptr);
iox_sub_deinit(ptr);
}

TEST_F(iox_sub_test, initialStateNotSubscribed)
Expand Down Expand Up @@ -376,7 +378,7 @@ TEST_F(iox_sub_test, hasDataTriggersWaitSetWithCorrectCallback)
TEST_F(iox_sub_test, deinitSubscriberDetachesTriggerFromWaitSet)
{
// malloc is used since iox_sub_deinit calls the d'tor of cpp2c_Subscriber
auto subscriber = new (malloc(sizeof(cpp2c_Subscriber))) cpp2c_Subscriber();
auto subscriber = new cpp2c_Subscriber();
subscriber->m_portData = &m_portPtr;

iox_ws_attach_subscriber_state(
Expand All @@ -386,7 +388,7 @@ TEST_F(iox_sub_test, deinitSubscriberDetachesTriggerFromWaitSet)

EXPECT_EQ(m_waitSet->size(), 0U);

free(subscriber);
// free(subscriber);
}

TEST_F(iox_sub_test, correctServiceDescriptionReturned)
Expand Down
4 changes: 2 additions & 2 deletions iceoryx_binding_c/test/moduletests/test_wait_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ class iox_ws_test : public Test
{
delete m_sut;

for (uint64_t i = 0U; i < MAX_NUMBER_OF_ATTACHMENTS_PER_WAITSET; ++i)
for (auto trigger: m_userTrigger)
{
iox_user_trigger_deinit(m_userTrigger[i]);
iox_user_trigger_deinit(trigger);
}
}

Expand Down

0 comments on commit 758eda3

Please sign in to comment.