Skip to content

Commit 95d1a94

Browse files
committed
iox-#1032 Extend testing support for refactored 'IOX_REQUIRE'
1 parent 4b2d66a commit 95d1a94

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

iceoryx_hoofs/test/moduletests/error_reporting/test_error_reporting_macros.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ TEST_F(ErrorReportingMacroApi_test, reportConditionalNoError)
128128
IOX_TESTING_EXPECT_OK();
129129
}
130130

131-
TEST_F(ErrorReportingMacroApi_test, requireConditionSatisfied)
131+
TEST_F(ErrorReportingMacroApi_test, checkRequireConditionSatisfied)
132132
{
133133
::testing::Test::RecordProperty("TEST_ID", "3c684878-20f8-426f-bb8b-7576b567d04f");
134134
auto f = []() { IOX_REQUIRE(true, ""); };
@@ -138,14 +138,15 @@ TEST_F(ErrorReportingMacroApi_test, requireConditionSatisfied)
138138
IOX_TESTING_EXPECT_OK();
139139
}
140140

141-
TEST_F(ErrorReportingMacroApi_test, requireConditionNotSatisfied)
141+
TEST_F(ErrorReportingMacroApi_test, checkRequireConditionViolate)
142142
{
143143
::testing::Test::RecordProperty("TEST_ID", "fb62d315-8854-401b-82af-6161ae45a34e");
144144
auto f = []() { IOX_REQUIRE(false, ""); };
145145

146146
runInTestThread(f);
147147

148148
IOX_TESTING_EXPECT_PANIC();
149+
IOX_TESTING_EXPECT_REQUIRED_CONDITION_VIOLATION();
149150
}
150151

151152
TEST_F(ErrorReportingMacroApi_test, checkPreconditionSatisfied)

iceoryx_hoofs/testing/error_reporting/testing_support.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ bool hasError()
3131
return ErrorHandler::instance().hasError();
3232
}
3333

34+
bool hasRequiredConditionViolation()
35+
{
36+
auto code = iox::er::ErrorCode{iox::er::ErrorCode::REQUIRED_CONDITION_VIOLATION};
37+
return ErrorHandler::instance().hasViolation(code);
38+
}
39+
3440
bool hasPreconditionViolation()
3541
{
3642
auto code = iox::er::ErrorCode{iox::er::ErrorCode::PRECONDITION_VIOLATION};
@@ -45,7 +51,7 @@ bool hasAssumptionViolation()
4551

4652
bool hasViolation()
4753
{
48-
return hasPreconditionViolation() || hasAssumptionViolation();
54+
return hasRequiredConditionViolation() || hasPreconditionViolation() || hasAssumptionViolation();
4955
}
5056

5157
bool isInNormalState()

iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/error_reporting/testing_support.hpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ bool hasPanicked();
5050
/// @brief indicates whether the test error handler registered any error
5151
bool hasError();
5252

53+
/// @brief indicates whether the test error handler registered a required condition violation
54+
bool hasRequiredConditionViolation();
55+
5356
/// @brief indicates whether the test error handler registered a precondition violation
5457
bool hasPreconditionViolation();
5558

@@ -120,11 +123,11 @@ inline void runInTestThread(Function&& testFunction, Args&&... args)
120123

121124
#define IOX_TESTING_ASSERT_NO_ERROR() ASSERT_FALSE(iox::testing::hasError())
122125

123-
#define IOX_TESTING_ASSERT_VIOLATION() \
124-
ASSERT_TRUE(iox::testing::hasPreconditionViolation() || iox::testing::hasAssumptionViolation())
126+
#define IOX_TESTING_ASSERT_VIOLATION() ASSERT_TRUE(iox::testing::hasViolation())
127+
128+
#define IOX_TESTING_ASSERT_NO_VIOLATION() ASSERT_FALSE(iox::testing::hasViolation())
125129

126-
#define IOX_TESTING_ASSERT_NO_VIOLATION() \
127-
ASSERT_FALSE(iox::testing::hasPreconditionViolation() || iox::testing::hasAssumptionViolation())
130+
#define IOX_TESTING_ASSERT_REQUIRED_CONDITION_VIOLATION() ASSERT_TRUE(iox::testing::hasRequiredConditionViolation())
128131

129132
#define IOX_TESTING_ASSERT_PRECONDITION_VIOLATION() ASSERT_TRUE(iox::testing::hasPreconditionViolation())
130133

@@ -142,11 +145,11 @@ inline void runInTestThread(Function&& testFunction, Args&&... args)
142145

143146
#define IOX_TESTING_EXPECT_NO_ERROR() EXPECT_FALSE(iox::testing::hasError())
144147

145-
#define IOX_TESTING_EXPECT_VIOLATION() \
146-
EXPECT_TRUE(iox::testing::hasPreconditionViolation() || iox::testing::hasAssumptionViolation())
148+
#define IOX_TESTING_EXPECT_VIOLATION() EXPECT_TRUE(iox::testing::hasViolation())
149+
150+
#define IOX_TESTING_EXPECT_NO_VIOLATION() EXPECT_FALSE(iox::testing::hasViolation())
147151

148-
#define IOX_TESTING_EXPECT_NO_VIOLATION() \
149-
EXPECT_FALSE(iox::testing::hasPreconditionViolation() || iox::testing::hasAssumptionViolation())
152+
#define IOX_TESTING_EXPECT_REQUIRED_CONDITION_VIOLATION() EXPECT_TRUE(iox::testing::hasRequiredConditionViolation())
150153

151154
#define IOX_TESTING_EXPECT_PRECONDITION_VIOLATION() EXPECT_TRUE(iox::testing::hasPreconditionViolation())
152155

0 commit comments

Comments
 (0)