Skip to content

Commit bfc4ba9

Browse files
committed
iox-#1613 Use IOX_EXPECT_FATAL_FAILURE in iceoryx_binding_c tests
1 parent 6858160 commit bfc4ba9

File tree

5 files changed

+31
-17
lines changed

5 files changed

+31
-17
lines changed

iceoryx_binding_c/source/c_runtime.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//
1616
// SPDX-License-Identifier: Apache-2.0
1717

18+
#include "iceoryx_hoofs/cxx/requires.hpp"
1819
#include "iceoryx_posh/runtime/posh_runtime.hpp"
1920

2021
using namespace iox;
@@ -26,16 +27,9 @@ extern "C" {
2627

2728
void iox_runtime_init(const char* const name)
2829
{
29-
if (name == nullptr)
30-
{
31-
LogError() << "Runtime name is a nullptr!";
32-
std::terminate();
33-
}
34-
else if (strnlen(name, iox::MAX_RUNTIME_NAME_LENGTH + 1) > MAX_RUNTIME_NAME_LENGTH)
35-
{
36-
LogError() << "Runtime name has more than 100 characters!";
37-
std::terminate();
38-
}
30+
iox::cxx::Expects(name != nullptr && "Runtime name is a nullptr!");
31+
iox::cxx::Expects(strnlen(name, iox::MAX_RUNTIME_NAME_LENGTH + 1) <= MAX_RUNTIME_NAME_LENGTH
32+
&& "Runtime name has more than 100 characters!");
3933

4034
PoshRuntime::initRuntime(RuntimeName_t(iox::TruncateToCapacity, name));
4135
}

iceoryx_binding_c/test/moduletests/test_publisher.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
//
1616
// SPDX-License-Identifier: Apache-2.0
1717

18+
#include "iceoryx_binding_c/error_handling/error_handling.hpp"
1819
#include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp"
1920
#include "iceoryx_binding_c/internal/cpp2c_publisher.hpp"
21+
#include "iceoryx_hoofs/testing/fatal_failure.hpp"
2022
#include "iceoryx_posh/internal/popo/building_blocks/chunk_queue_popper.hpp"
2123
#include "iceoryx_posh/internal/popo/ports/publisher_port_roudi.hpp"
2224
#include "iceoryx_posh/internal/popo/ports/publisher_port_user.hpp"
@@ -37,6 +39,7 @@ extern "C" {
3739
namespace
3840
{
3941
using namespace ::testing;
42+
using namespace iox::testing;
4043
using namespace iox::capro;
4144
using namespace iox::cxx;
4245
using namespace iox::mepoo;
@@ -137,7 +140,8 @@ TEST(iox_pub_test_DeathTest, initPublisherWithNotInitializedPublisherOptionsTerm
137140
iox_pub_options_t options;
138141
iox_pub_storage_t storage;
139142

140-
EXPECT_DEATH({ iox_pub_init(&storage, "a", "b", "c", &options); }, ".*");
143+
IOX_EXPECT_FATAL_FAILURE<iox::CBindingError>([&] { iox_pub_init(&storage, "a", "b", "c", &options); },
144+
iox::CBindingError::BINDING_C__PUBLISHER_OPTIONS_NOT_INITIALIZED);
141145
}
142146

143147
TEST_F(iox_pub_test, initPublisherWithDefaultOptionsWorks)

iceoryx_binding_c/test/moduletests/test_runtime.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ extern "C" {
1818
#include "iceoryx_binding_c/runtime.h"
1919
}
2020

21+
#include "iceoryx_hoofs/error_handling/error_handling.hpp"
22+
#include "iceoryx_hoofs/testing/fatal_failure.hpp"
2123
#include "iceoryx_posh/iceoryx_posh_types.hpp"
2224
#include "iceoryx_posh/testing/roudi_gtest.hpp"
2325

2426
namespace
2527
{
2628
using namespace iox;
2729
using namespace iox::runtime;
30+
using namespace iox::testing;
2831

2932
class BindingC_Runtime_test : public RouDi_GTest
3033
{
@@ -69,13 +72,19 @@ TEST_F(BindingC_Runtime_test, RuntimeNameLengthIsOutOfLimit)
6972
::testing::Test::RecordProperty("TEST_ID", "8fd6735d-f331-4c9c-9a91-3f06d3856d15");
7073
std::string tooLongName(iox::MAX_RUNTIME_NAME_LENGTH + 1, 's');
7174

72-
EXPECT_DEATH({ iox_runtime_init(tooLongName.c_str()); }, ".*");
75+
IOX_EXPECT_FATAL_FAILURE<iox::HoofsError>(
76+
[&] {
77+
iox_runtime_init(tooLongName.c_str());
78+
;
79+
},
80+
iox::HoofsError::EXPECTS_ENSURES_FAILED);
7381
}
7482

7583
TEST_F(BindingC_Runtime_test, RuntimeNameIsNullptr)
7684
{
7785
::testing::Test::RecordProperty("TEST_ID", "eb1b76c9-5420-42a9-88b3-db2e36e332de");
78-
EXPECT_DEATH({ iox_runtime_init(nullptr); }, ".*");
86+
IOX_EXPECT_FATAL_FAILURE<iox::HoofsError>([&] { iox_runtime_init(nullptr); },
87+
iox::HoofsError::EXPECTS_ENSURES_FAILED);
7988
}
8089

8190
TEST_F(BindingC_Runtime_test, GetInstanceNameIsNullptr)

iceoryx_binding_c/test/moduletests/test_service_discovery.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414
//
1515
// SPDX-License-Identifier: Apache-2.0
1616

17+
#include "iceoryx_hoofs/error_handling/error_handling.hpp"
18+
#include "iceoryx_hoofs/testing/fatal_failure.hpp"
1719
#include "iceoryx_posh/runtime/service_discovery.hpp"
1820
#include "iceoryx_posh/testing/roudi_gtest.hpp"
1921

2022
using namespace iox;
2123
using namespace iox::runtime;
24+
using namespace iox::testing;
2225

2326
extern "C" {
2427
#include "iceoryx_binding_c/publisher.h"
@@ -63,7 +66,8 @@ description_vector iox_service_discovery_test::searchResult;
6366
TEST(iox_service_discovery_DeathTest, InitServiceDiscoveryWithNullptrForStorageTerminates)
6467
{
6568
::testing::Test::RecordProperty("TEST_ID", "be551a9e-7dcf-406a-a74c-7dcb1ee16c30");
66-
EXPECT_DEATH({ iox_service_discovery_init(nullptr); }, ".*");
69+
IOX_EXPECT_FATAL_FAILURE<iox::HoofsError>([&] { iox_service_discovery_init(nullptr); },
70+
iox::HoofsError::EXPECTS_ENSURES_FAILED);
6771
}
6872

6973
/// @note We test only if the arguments of iox_service_discovery_find_service are correctly passed to

iceoryx_binding_c/test/moduletests/test_subscriber.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
//
1616
// SPDX-License-Identifier: Apache-2.0
1717

18+
#include "iceoryx_binding_c/error_handling/error_handling.hpp"
1819
#include "iceoryx_binding_c/internal/cpp2c_enum_translation.hpp"
1920
#include "iceoryx_binding_c/internal/cpp2c_subscriber.hpp"
21+
#include "iceoryx_hoofs/testing/fatal_failure.hpp"
2022
#include "iceoryx_posh/internal/mepoo/memory_manager.hpp"
2123
#include "iceoryx_posh/internal/popo/building_blocks/chunk_queue_popper.hpp"
2224
#include "iceoryx_posh/internal/popo/building_blocks/chunk_queue_pusher.hpp"
@@ -28,6 +30,7 @@
2830

2931
using namespace iox;
3032
using namespace iox::popo;
33+
using namespace iox::testing;
3134

3235
extern "C" {
3336
#include "iceoryx_binding_c/chunk.h"
@@ -130,14 +133,14 @@ TEST_F(iox_sub_test, initSubscriberWithNullptrForStorageReturnsNullptr)
130133
EXPECT_EQ(iox_sub_init(nullptr, "all", "glory", "hypnotoad", &options), nullptr);
131134
}
132135

133-
// this crashes if the fixture is used, therefore a test without a fixture
134-
TEST(iox_sub_test_DeathTest, initSubscriberWithNotInitializedPublisherOptionsTerminates)
136+
TEST_F(iox_sub_test, initSubscriberWithNotInitializedSubscriberOptionsTerminates)
135137
{
136138
::testing::Test::RecordProperty("TEST_ID", "6a33309e-fe21-45f6-815a-eebe0136c572");
137139
iox_sub_options_t options;
138140
iox_sub_storage_t storage;
139141

140-
EXPECT_DEATH({ iox_sub_init(&storage, "a", "b", "c", &options); }, ".*");
142+
IOX_EXPECT_FATAL_FAILURE<iox::CBindingError>([&] { iox_sub_init(&storage, "a", "b", "c", &options); },
143+
iox::CBindingError::BINDING_C__SUBSCRIBER_OPTIONS_NOT_INITIALIZED);
141144
}
142145

143146
TEST_F(iox_sub_test, initSubscriberWithDefaultOptionsWorks)

0 commit comments

Comments
 (0)