Skip to content

Commit 9308256

Browse files
committed
iox-#1613 Use EXPECT_FATAL_FAILURE in iceoryx_hoofs tests
1 parent be1c220 commit 9308256

File tree

6 files changed

+185
-149
lines changed

6 files changed

+185
-149
lines changed

iceoryx_hoofs/test/moduletests/test_concurrent_loffli.cpp

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

18+
#include "iceoryx_hoofs/error_handling/error_handling.hpp"
1819
#include "iceoryx_hoofs/internal/concurrent/loffli.hpp"
20+
#include "iceoryx_hoofs/testing/fatal_failure.hpp"
1921
#include "test.hpp"
2022

2123
#include <algorithm>
@@ -25,6 +27,7 @@
2527
namespace
2628
{
2729
using namespace ::testing;
30+
using namespace iox::testing;
2831

2932
constexpr uint32_t Size{4};
3033
using LoFFLiTestSubjects = Types<iox::concurrent::LoFFLi>;
@@ -53,32 +56,38 @@ class LoFFLi_test : public Test
5356
TYPED_TEST(LoFFLi_test, Misuse_NullptrMemory)
5457
{
5558
::testing::Test::RecordProperty("TEST_ID", "ab877f29-cab0-48ae-a2c0-054633b6415a");
59+
5660
decltype(this->m_loffli) loFFLi;
57-
// @todo iox-#1613 remove EXPECT_DEATH
58-
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c)
59-
EXPECT_DEATH(loFFLi.init(nullptr, 1), ".*");
61+
62+
EXPECT_FATAL_FAILURE<iox::HoofsError>(
63+
[&] { loFFLi.init(nullptr, 1); }, iox::HoofsError::EXPECTS_ENSURES_FAILED, iox::ErrorLevel::FATAL);
6064
}
6165

6266
TYPED_TEST(LoFFLi_test, Misuse_ZeroSize)
6367
{
6468
::testing::Test::RecordProperty("TEST_ID", "fb9c797b-22b4-4572-a7a2-eaf13574dbac");
65-
// NOLINTNEXTLINE(hicpp-avoid-c-arrays, cppcoreguidelines-avoid-c-arrays) needed to test LoFFLi::init
69+
70+
// NOLINTBEGIN(hicpp-avoid-c-arrays, cppcoreguidelines-avoid-c-arrays) needed to test LoFFLi::init
6671
uint32_t memoryLoFFLi[4];
6772
decltype(this->m_loffli) loFFLi;
68-
// @todo iox-#1613 remove EXPECT_DEATH
69-
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c)
70-
EXPECT_DEATH(loFFLi.init(&memoryLoFFLi[0], 0), ".*");
73+
74+
EXPECT_FATAL_FAILURE<iox::HoofsError>(
75+
[&] { loFFLi.init(&memoryLoFFLi[0], 0); }, iox::HoofsError::EXPECTS_ENSURES_FAILED, iox::ErrorLevel::FATAL);
76+
// NOLINTEND(hicpp-avoid-c-arrays, cppcoreguidelines-avoid-c-arrays)
7177
}
7278

7379
TYPED_TEST(LoFFLi_test, Misuse_SizeToLarge)
7480
{
7581
::testing::Test::RecordProperty("TEST_ID", "14b4b82c-ae2b-4bd2-97cf-93fcea87f050");
76-
// NOLINTNEXTLINE(hicpp-avoid-c-arrays, cppcoreguidelines-avoid-c-arrays) needed to test LoFFLi::init
82+
83+
// NOLINTBEGIN(hicpp-avoid-c-arrays, cppcoreguidelines-avoid-c-arrays) needed to test LoFFLi::init
7784
uint32_t memoryLoFFLi[4];
7885
decltype(this->m_loffli) loFFLi;
79-
// @todo iox-#1613 remove EXPECT_DEATH
80-
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c)
81-
EXPECT_DEATH(loFFLi.init(&memoryLoFFLi[0], UINT32_MAX - 1), ".*");
86+
87+
EXPECT_FATAL_FAILURE<iox::HoofsError>([&] { loFFLi.init(&memoryLoFFLi[0], UINT32_MAX - 1); },
88+
iox::HoofsError::EXPECTS_ENSURES_FAILED,
89+
iox::ErrorLevel::FATAL);
90+
// NOLINTEND(hicpp-avoid-c-arrays, cppcoreguidelines-avoid-c-arrays)
8291
}
8392

8493

iceoryx_hoofs/test/moduletests/test_cxx_function_ref.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717

1818
#include "iceoryx_hoofs/cxx/attributes.hpp"
1919
#include "iceoryx_hoofs/cxx/function_ref.hpp"
20+
#include "iceoryx_hoofs/error_handling/error_handling.hpp"
21+
#include "iceoryx_hoofs/testing/fatal_failure.hpp"
2022
#include "test.hpp"
2123

22-
2324
namespace
2425
{
2526
using namespace ::testing;
2627
using namespace iox::cxx;
28+
using namespace iox::testing;
2729

2830
constexpr int FREE_FUNC_TEST_VALUE = 42 + 42;
2931
constexpr int FUNCTOR_TEST_VALUE = 11;
@@ -162,15 +164,16 @@ TEST_F(function_refTest, CreateValidByMoveAssignResultEqual)
162164
TEST_F(function_refDeathTest, CallMovedFromLeadsToTermination)
163165
{
164166
::testing::Test::RecordProperty("TEST_ID", "3402f27e-ced5-483f-ab39-0069cfd172ac");
167+
165168
auto lambda = []() -> int { return 7654; };
166169
function_ref<int()> sut1{lambda};
167170
function_ref<int()> sut2{std::move(sut1)};
171+
168172
// NOLINTJUSTIFICATION Use after move is tested here
169-
// NOLINTBEGIN(bugprone-use-after-move, hicpp-invalid-access-moved, cppcoreguidelines-pro-type-vararg,
170-
// cppcoreguidelines-avoid-goto)
171-
EXPECT_DEATH(sut1(), ""); // ERROR: Empty function_ref invoked
172-
// NOLINTEND(bugprone-use-after-move, hicpp-invalid-access-moved, cppcoreguidelines-pro-type-vararg,
173-
// cppcoreguidelines-avoid-goto)
173+
// NOLINTBEGIN(bugprone-use-after-move, hicpp-invalid-access-moved)
174+
EXPECT_FATAL_FAILURE<iox::HoofsError>(
175+
[&] { sut1(); }, iox::HoofsError::EXPECTS_ENSURES_FAILED, iox::ErrorLevel::FATAL);
176+
// NOLINTEND(bugprone-use-after-move, hicpp-invalid-access-moved)
174177
}
175178

176179
TEST_F(function_refTest, CreateValidAndSwapResultEqual)

iceoryx_hoofs/test/moduletests/test_cxx_list.cpp

Lines changed: 63 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@
1717

1818
#include "iceoryx_hoofs/cxx/attributes.hpp"
1919
#include "iceoryx_hoofs/cxx/list.hpp"
20+
#include "iceoryx_hoofs/error_handling/error_handling.hpp"
2021
#include "iceoryx_hoofs/log/logging.hpp"
22+
#include "iceoryx_hoofs/testing/fatal_failure.hpp"
2123
#include "test.hpp"
2224

2325

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

2932
constexpr uint64_t TESTLISTCAPACITY{10U};
3033
constexpr int64_t TEST_LIST_ELEMENT_DEFAULT_VALUE{-99L};
@@ -149,15 +152,6 @@ int64_t iteratorTraitReturnDoubleValue(IterType iter)
149152
IterValueType m_value = *iter;
150153
return (2 * m_value); // will only work for integer-convertible m_value types
151154
}
152-
153-
// in context of EXPECT_DEATH tests, dummyFunc() shall help suppressing following warning :
154-
// -Wunused-comparison
155-
// reason: the warning is already addressed with the internal handling, which shall be tested here
156-
bool dummyFunc(bool whatever)
157-
{
158-
IOX_LOG(ERROR) << "Never get here - ever " << whatever;
159-
return whatever;
160-
}
161155
} // namespace
162156

163157

@@ -272,15 +266,19 @@ TEST_F(list_test, FullWhenFilledWithCapacityElements)
272266
TEST_F(list_test, FullWhenFilledWithMoreThanCapacityElements)
273267
{
274268
::testing::Test::RecordProperty("TEST_ID", "585bb3d9-112c-4db8-af5e-e4c646723515");
275-
for (uint64_t i = 0U; i < sut.capacity(); ++i)
276-
{
277-
sut.emplace_front();
278-
}
279269

280-
EXPECT_THAT(sut.full(), Eq(true));
281-
/// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH
282-
/// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c)
283-
EXPECT_DEATH(sut.emplace_front(), "");
270+
EXPECT_FATAL_FAILURE<iox::HoofsError>(
271+
[&] {
272+
for (uint64_t i = 0U; i < sut.capacity(); ++i)
273+
{
274+
sut.emplace_front();
275+
}
276+
277+
EXPECT_THAT(sut.full(), Eq(true));
278+
sut.emplace_front();
279+
},
280+
iox::HoofsError::EXPECTS_ENSURES_FAILED,
281+
iox::ErrorLevel::FATAL);
284282
}
285283
TEST_F(list_test, NotFullWhenFilledWithCapacityAndEraseOneElements)
286284
{
@@ -727,9 +725,8 @@ TEST_F(list_test, EmplaceBackWithMoreThanCapacityElements)
727725
}
728726
else
729727
{
730-
/// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH
731-
/// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c)
732-
EXPECT_DEATH(sut1.emplace_back(cnt), "");
728+
EXPECT_FATAL_FAILURE<iox::HoofsError>(
729+
[&] { sut1.emplace_back(cnt); }, iox::HoofsError::EXPECTS_ENSURES_FAILED, iox::ErrorLevel::FATAL);
733730
}
734731
++cnt;
735732
}
@@ -763,9 +760,8 @@ TEST_F(list_test, EmplaceWithWrongListIterator)
763760
++cnt;
764761
}
765762

766-
/// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH
767-
/// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c)
768-
EXPECT_DEATH(sut11.emplace(iterOfSut2, cnt), "");
763+
EXPECT_FATAL_FAILURE<iox::HoofsError>(
764+
[&] { sut11.emplace(iterOfSut2, cnt); }, iox::HoofsError::EXPECTS_ENSURES_FAILED, iox::ErrorLevel::FATAL);
769765
}
770766

771767
TEST_F(list_test, PushFrontConstCustomSuccessfullWhenSpaceAvailableLValue)
@@ -1499,39 +1495,45 @@ TEST_F(list_test, IteratorComparisonOfDifferentLists)
14991495

15001496
auto iterSut1 = sut11.begin();
15011497
auto iterSut2 = sut12.begin();
1502-
/// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH
1503-
/// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c)
1504-
EXPECT_DEATH(dummyFunc(iterSut1 == iterSut2), "");
1498+
1499+
EXPECT_FATAL_FAILURE<iox::HoofsError>([&] { IOX_DISCARD_RESULT(iterSut1 == iterSut2); },
1500+
iox::HoofsError::EXPECTS_ENSURES_FAILED,
1501+
iox::ErrorLevel::FATAL);
15051502

15061503
iterSut1 = sut11.begin();
15071504
iterSut2 = sut12.begin();
1508-
/// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH
1509-
/// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c)
1510-
EXPECT_DEATH(dummyFunc(iterSut1 == iterSut2), "");
1505+
1506+
EXPECT_FATAL_FAILURE<iox::HoofsError>([&] { IOX_DISCARD_RESULT(iterSut1 == iterSut2); },
1507+
iox::HoofsError::EXPECTS_ENSURES_FAILED,
1508+
iox::ErrorLevel::FATAL);
15111509

15121510
iterSut1 = sut11.end();
15131511
iterSut2 = sut12.end();
1514-
/// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH
1515-
/// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c)
1516-
EXPECT_DEATH(dummyFunc(iterSut1 == iterSut2), "");
1512+
1513+
EXPECT_FATAL_FAILURE<iox::HoofsError>([&] { IOX_DISCARD_RESULT(iterSut1 == iterSut2); },
1514+
iox::HoofsError::EXPECTS_ENSURES_FAILED,
1515+
iox::ErrorLevel::FATAL);
15171516

15181517
iterSut1 = sut11.begin();
15191518
iterSut2 = sut12.begin();
1520-
/// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH
1521-
/// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c)
1522-
EXPECT_DEATH(dummyFunc(iterSut1 != iterSut2), "");
1519+
1520+
EXPECT_FATAL_FAILURE<iox::HoofsError>([&] { IOX_DISCARD_RESULT(iterSut1 != iterSut2); },
1521+
iox::HoofsError::EXPECTS_ENSURES_FAILED,
1522+
iox::ErrorLevel::FATAL);
15231523

15241524
iterSut1 = sut11.begin();
15251525
iterSut2 = sut12.begin();
1526-
/// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH
1527-
/// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c)
1528-
EXPECT_DEATH(dummyFunc(iterSut1 != iterSut2), "");
1526+
1527+
EXPECT_FATAL_FAILURE<iox::HoofsError>([&] { IOX_DISCARD_RESULT(iterSut1 != iterSut2); },
1528+
iox::HoofsError::EXPECTS_ENSURES_FAILED,
1529+
iox::ErrorLevel::FATAL);
15291530

15301531
iterSut1 = sut11.end();
15311532
iterSut2 = sut12.end();
1532-
/// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH
1533-
/// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c)
1534-
EXPECT_DEATH(dummyFunc(iterSut1 != iterSut2), "");
1533+
1534+
EXPECT_FATAL_FAILURE<iox::HoofsError>([&] { IOX_DISCARD_RESULT(iterSut1 != iterSut2); },
1535+
iox::HoofsError::EXPECTS_ENSURES_FAILED,
1536+
iox::ErrorLevel::FATAL);
15351537
}
15361538

15371539

@@ -2313,9 +2315,9 @@ TEST_F(list_test, invalidIteratorErase)
23132315
++iter;
23142316
sut.erase(iter);
23152317

2316-
/// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH
2317-
/// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c)
2318-
EXPECT_DEATH(sut.erase(iter), "");
2318+
2319+
EXPECT_FATAL_FAILURE<iox::HoofsError>(
2320+
[&] { sut.erase(iter); }, iox::HoofsError::EXPECTS_ENSURES_FAILED, iox::ErrorLevel::FATAL);
23192321
}
23202322

23212323
TEST_F(list_test, invalidIteratorIncrement)
@@ -2331,9 +2333,8 @@ TEST_F(list_test, invalidIteratorIncrement)
23312333
++iter;
23322334
sut.erase(iter);
23332335

2334-
/// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH
2335-
/// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c)
2336-
EXPECT_DEATH(++iter, "");
2336+
EXPECT_FATAL_FAILURE<iox::HoofsError>(
2337+
[&] { ++iter; }, iox::HoofsError::EXPECTS_ENSURES_FAILED, iox::ErrorLevel::FATAL);
23372338
}
23382339

23392340
TEST_F(list_test, invalidIteratorDecrement)
@@ -2349,9 +2350,8 @@ TEST_F(list_test, invalidIteratorDecrement)
23492350
++iter;
23502351
sut.erase(iter);
23512352

2352-
/// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH
2353-
/// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c)
2354-
EXPECT_DEATH(--iter, "");
2353+
EXPECT_FATAL_FAILURE<iox::HoofsError>(
2354+
[&] { --iter; }, iox::HoofsError::EXPECTS_ENSURES_FAILED, iox::ErrorLevel::FATAL);
23552355
}
23562356

23572357
TEST_F(list_test, invalidIteratorComparison)
@@ -2367,9 +2367,10 @@ TEST_F(list_test, invalidIteratorComparison)
23672367
++iter;
23682368
auto iter2 IOX_MAYBE_UNUSED = sut.erase(iter);
23692369

2370-
/// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH
2371-
/// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c)
2372-
EXPECT_DEATH(dummyFunc(sut.cbegin() == iter), "");
2370+
2371+
EXPECT_FATAL_FAILURE<iox::HoofsError>([&] { IOX_DISCARD_RESULT(sut.cbegin() == iter); },
2372+
iox::HoofsError::EXPECTS_ENSURES_FAILED,
2373+
iox::ErrorLevel::FATAL);
23732374
}
23742375

23752376
TEST_F(list_test, invalidIteratorComparisonUnequal)
@@ -2385,9 +2386,9 @@ TEST_F(list_test, invalidIteratorComparisonUnequal)
23852386
++iter;
23862387
auto iter2 = sut.erase(iter);
23872388

2388-
/// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH
2389-
/// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c)
2390-
EXPECT_DEATH(dummyFunc(iter2 != iter), "");
2389+
2390+
EXPECT_FATAL_FAILURE<iox::HoofsError>(
2391+
[&] { IOX_DISCARD_RESULT(iter2 != iter); }, iox::HoofsError::EXPECTS_ENSURES_FAILED, iox::ErrorLevel::FATAL);
23912392
}
23922393

23932394
TEST_F(list_test, invalidIteratorDereferencing)
@@ -2403,9 +2404,8 @@ TEST_F(list_test, invalidIteratorDereferencing)
24032404
++iter;
24042405
auto iter2 IOX_MAYBE_UNUSED = sut.erase(iter);
24052406

2406-
/// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH
2407-
/// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c)
2408-
EXPECT_DEATH(dummyFunc((*iter).m_value), "");
2407+
EXPECT_FATAL_FAILURE<iox::HoofsError>(
2408+
[&] { IOX_DISCARD_RESULT((*iter).m_value); }, iox::HoofsError::EXPECTS_ENSURES_FAILED, iox::ErrorLevel::FATAL);
24092409
}
24102410

24112411
TEST_F(list_test, invalidIteratorAddressOfOperator)
@@ -2421,9 +2421,10 @@ TEST_F(list_test, invalidIteratorAddressOfOperator)
24212421
++iter;
24222422
auto iter2 IOX_MAYBE_UNUSED = sut.erase(iter);
24232423

2424-
/// @NOLINTJUSTIFICATION @todo iox-#1613 remove EXPECT_DEATH
2425-
/// @NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c)
2426-
EXPECT_DEATH(dummyFunc(iter->m_value == 12U), "");
2424+
2425+
EXPECT_FATAL_FAILURE<iox::HoofsError>([&] { IOX_DISCARD_RESULT(iter->m_value == 12U); },
2426+
iox::HoofsError::EXPECTS_ENSURES_FAILED,
2427+
iox::ErrorLevel::FATAL);
24272428
}
24282429

24292430
TEST_F(list_test, ListIsCopyableViaMemcpy)

iceoryx_hoofs/test/moduletests/test_design_functional_interface_expect.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@
1313
// limitations under the License.
1414
//
1515
// SPDX-License-Identifier: Apache-2.0
16-
//
16+
1717
#include "iceoryx_hoofs/error_handling/error_handling.hpp"
18-
#include "iceoryx_hoofs/testing/mocks/error_handler_mock.hpp"
18+
#include "iceoryx_hoofs/testing/fatal_failure.hpp"
1919
#include "test_design_functional_interface_types.hpp"
2020

2121
namespace
2222
{
2323
using namespace test_design_functional_interface;
2424
using namespace ::testing;
25+
using namespace iox::testing;
2526

2627
// the macro is used as code generator to make the tests more readable. because of the
2728
// template nature of those tests this cannot be implemented in the same readable fashion
@@ -83,11 +84,8 @@ void ExpectDoesCallTerminateWhenObjectIsInvalid(const ExpectCall& callExpect)
8384
{
8485
SutType sut = FactoryType::createInvalidObject();
8586
{
86-
auto handle =
87-
iox::ErrorHandlerMock::setTemporaryErrorHandler<iox::HoofsError>([&](auto, auto) { std::terminate(); });
88-
// @todo iox-#1613 remove EXPECT_DEATH
89-
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-avoid-goto, cert-err33-c)
90-
EXPECT_DEATH(callExpect(sut), ".*");
87+
EXPECT_FATAL_FAILURE<iox::HoofsError>(
88+
[&] { callExpect(sut); }, iox::HoofsError::EXPECTS_ENSURES_FAILED, iox::ErrorLevel::FATAL);
9189
}
9290
}
9391

0 commit comments

Comments
 (0)