// // Created by erki on 25/10/23. // #include #include #ifdef NDEBUG #undef NDEBUG #define NDEBUG_WAS_DEFINED #endif #include "utility_assert.hpp" #include "utility_notnull.hpp" #ifdef NDEBUG_WAS_DEFINED #define NDEBUG #endif namespace { std::atomic assert_flag = false; void assertCallback(const char*, const char*, const int) { assert_flag = true; } }// namespace TEST_CASE("Assert is tripped if nullptr passed.", "[utility],[notnull]") { assert_flag = false; Utility::Assert::setHandler(assertCallback); REQUIRE(assert_flag == false); auto call = [](Utility::NotNull i) -> void {}; call(nullptr); CHECK(assert_flag == true); } TEST_CASE("Assert is not tripped if valid pointer is passed.", "[utility],[notnull]") { assert_flag = false; Utility::Assert::setHandler(assertCallback); REQUIRE(assert_flag == false); auto call = [](Utility::NotNull i) -> int { return *i; }; int a = 5; const int test = call(&a); CHECK(assert_flag == false); CHECK(a == test); }