2020-02-03 12:05:46 +00:00
|
|
|
#ifdef TESTS_BUILD
|
|
|
|
#include <cstring>
|
2022-02-05 12:59:15 +00:00
|
|
|
#include <doctest.h>
|
2020-08-15 15:47:01 +00:00
|
|
|
#include "../CInterface/Core.hpp"
|
2020-02-03 12:05:46 +00:00
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("When throwing exception, what() is readable") {
|
2020-02-22 14:07:16 +00:00
|
|
|
bool hasCaught = false;
|
2020-02-03 12:05:46 +00:00
|
|
|
try {
|
2020-08-17 10:18:01 +00:00
|
|
|
THROW("foobar");
|
2020-08-15 13:10:48 +00:00
|
|
|
} catch (const ArbUt::Exception& e) {
|
2020-02-22 14:07:16 +00:00
|
|
|
hasCaught = true;
|
2020-02-03 12:05:46 +00:00
|
|
|
INFO(e.what());
|
2021-11-21 11:39:07 +00:00
|
|
|
REQUIRE(std::string(e.what()) == "[ExceptionTests.cpp:9] \"foobar\"");
|
2020-02-03 12:05:46 +00:00
|
|
|
}
|
2020-02-22 14:07:16 +00:00
|
|
|
REQUIRE(hasCaught);
|
2020-02-03 12:05:46 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("C Interface exception") {
|
2020-08-15 15:47:01 +00:00
|
|
|
ExceptionHandler::SetLastArbUtException("foo", ArbUt::Exception("foobar"), 1);
|
|
|
|
REQUIRE(std::string(ExceptionHandler::GetLastException()) == "[foo] foobar");
|
2020-08-15 17:54:59 +00:00
|
|
|
|
|
|
|
#if !WINDOWS
|
|
|
|
#ifndef DEBUG
|
2020-08-15 17:59:23 +00:00
|
|
|
REQUIRE(std::string(ExceptionHandler::GetLastExceptionStacktrace()) != "");
|
2020-08-15 17:54:59 +00:00
|
|
|
#else
|
2020-08-15 15:47:01 +00:00
|
|
|
REQUIRE(std::string(ExceptionHandler::GetLastExceptionStacktrace()) ==
|
|
|
|
"ExceptionTests.cpp[20] ____C_A_T_C_H____T_E_S_T____3()\n");
|
2020-08-15 17:54:59 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2020-08-15 15:47:01 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 12:05:46 +00:00
|
|
|
#endif
|