2020-02-03 12:05:46 +00:00
|
|
|
#ifdef TESTS_BUILD
|
|
|
|
#include <cstring>
|
2020-08-15 15:47:01 +00:00
|
|
|
#include "../CInterface/Core.hpp"
|
2020-02-03 12:05:46 +00:00
|
|
|
#include "../extern/catch.hpp"
|
2020-03-22 09:11:53 +00:00
|
|
|
#include "../src/Library/Exceptions/CreatureException.hpp"
|
2020-02-03 12:05:46 +00:00
|
|
|
|
|
|
|
TEST_CASE("When throwing exception, what() is readable", "[Utilities]") {
|
2020-02-22 14:07:16 +00:00
|
|
|
bool hasCaught = false;
|
2020-02-03 12:05:46 +00:00
|
|
|
try {
|
2020-07-26 15:41:11 +00:00
|
|
|
THROW_CREATURE("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());
|
2020-08-15 15:47:01 +00:00
|
|
|
REQUIRE(std::string(e.what()) == "[ExceptionTests.cpp:10] 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-08-15 15:47:01 +00:00
|
|
|
TEST_CASE("C Interface exception", "[Utilities]") {
|
|
|
|
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
|