Skip to content

Commit

Permalink
fixup: use separate test function for std::exception
Browse files Browse the repository at this point in the history
  • Loading branch information
KonradBkd committed Nov 15, 2024
1 parent d1662de commit 434ccad
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions SilKit/source/capi/Test_CapiExceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ class Test_CapiExceptions : public testing::Test
class UnknownException : public std::exception
{
public:
UnknownException(const char* message)
{
}
UnknownException() {}
UnknownException(const char* /*message*/) {}
};

template <typename T>
Expand All @@ -48,6 +47,15 @@ try
}
CAPI_CATCH_EXCEPTIONS

// Not all compilers support std::exception with const char* initialization, so treat that std::exception separately
SilKit_ReturnCode TestStdExceptionToErrorCode()
try
{
throw std::exception();
}
CAPI_CATCH_EXCEPTIONS


// Each catch branch of CapiImpl.hpp CAPI_CATCH_EXCEPTIONS is tested for the expected return code
TEST_F(Test_CapiExceptions, catch_exception_macro)
{
Expand All @@ -65,8 +73,8 @@ TEST_F(Test_CapiExceptions, catch_exception_macro)

EXPECT_EQ(TestExceptionToErrorCode<SilKit::SilKitError>(), SilKit_ReturnCode_UNSPECIFIEDERROR);
EXPECT_EQ(TestExceptionToErrorCode<std::runtime_error>(), SilKit_ReturnCode_UNSPECIFIEDERROR);
EXPECT_EQ(TestExceptionToErrorCode<std::exception>(), SilKit_ReturnCode_UNSPECIFIEDERROR);
EXPECT_EQ(TestExceptionToErrorCode<UnknownException>(), SilKit_ReturnCode_UNSPECIFIEDERROR);
EXPECT_EQ(TestStdExceptionToErrorCode(), SilKit_ReturnCode_UNSPECIFIEDERROR);
}

// Test that the C-API return code results in the correct exception
Expand Down

0 comments on commit 434ccad

Please sign in to comment.