Skip to content

Commit 276936b

Browse files
committed
iox-#1613 Add test for IOX_FATAL_FAILURE
1 parent a6ffe88 commit 276936b

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright (c) 2022 by Apex.AI Inc. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
17+
#include "iceoryx_hoofs/cxx/requires.hpp"
18+
#include "iceoryx_hoofs/error_handling/error_handling.hpp"
19+
#include "iceoryx_hoofs/testing/fatal_failure.hpp"
20+
21+
#include "test.hpp"
22+
23+
namespace
24+
{
25+
using namespace ::testing;
26+
using namespace ::iox::testing;
27+
28+
TEST(FatalFailure, TriggeringFatalFailureIsDetectedAndDoesNotTerminate)
29+
{
30+
::testing::Test::RecordProperty("TEST_ID", "5463f1c9-eb30-4fd1-85ce-351f03c37fe0");
31+
32+
auto hasFatalFailure = detail::IOX_FATAL_FAILURE_TEST<iox::HoofsError>(
33+
[&] { iox::cxx::Expects(false); },
34+
[&](const auto error, const auto errorLevel) {
35+
EXPECT_THAT(error, Eq(iox::HoofsError::EXPECTS_ENSURES_FAILED));
36+
EXPECT_THAT(errorLevel, Eq(iox::ErrorLevel::FATAL));
37+
},
38+
[&] { GTEST_FAIL() << "This is the non-fatal path and should therefore not be called"; });
39+
40+
EXPECT_TRUE(hasFatalFailure);
41+
}
42+
43+
TEST(FatalFailure, ExpectingFatalFailureWhichDoesNotOccurIsDetected)
44+
{
45+
::testing::Test::RecordProperty("TEST_ID", "f6c1d4f2-cafe-45e3-bbb7-c1373b2e15a8");
46+
47+
auto hasFatalFailure = detail::IOX_FATAL_FAILURE_TEST<iox::HoofsError>(
48+
[&] {},
49+
[&](const auto, const auto) { GTEST_FAIL() << "This is the fatal path and should therefore not be called"; },
50+
[&] { GTEST_SUCCEED() << "This is the non-fatal path and should be called"; });
51+
52+
EXPECT_FALSE(hasFatalFailure);
53+
}
54+
55+
TEST(FatalFailure, UsingExpectFatalFailureWorks)
56+
{
57+
::testing::Test::RecordProperty("TEST_ID", "26393210-9738-462f-9d35-dbd53fbae9d2");
58+
59+
auto hasFatalFailure = IOX_EXPECT_FATAL_FAILURE<iox::HoofsError>([&] { iox::cxx::Expects(false); },
60+
iox::HoofsError::EXPECTS_ENSURES_FAILED);
61+
62+
EXPECT_TRUE(hasFatalFailure);
63+
}
64+
65+
TEST(FatalFailure, UsingExpectNoFatalFailureWorks)
66+
{
67+
::testing::Test::RecordProperty("TEST_ID", "80bf8050-bfaa-4482-b69c-d0c80699bd4b");
68+
69+
auto hasNoFatalFailure = IOX_EXPECT_NO_FATAL_FAILURE<iox::HoofsError>([&] {});
70+
71+
EXPECT_TRUE(hasNoFatalFailure);
72+
}
73+
} // namespace

iceoryx_hoofs/test/mocktests/test_hoofs_mock.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@
1515
//
1616
// SPDX-License-Identifier: Apache-2.0
1717

18+
#include "iceoryx_hoofs/testing/testing_logger.hpp"
19+
1820
#include "test.hpp"
1921

2022
using ::testing::_;
2123

2224
int main(int argc, char* argv[])
2325
{
2426
::testing::InitGoogleTest(&argc, argv);
27+
28+
iox::testing::TestingLogger::init();
29+
2530
return RUN_ALL_TESTS();
2631
}

0 commit comments

Comments
 (0)