60 lines
1.0 KiB
C++
60 lines
1.0 KiB
C++
//
|
|
// Created by erki on 25/10/23.
|
|
//
|
|
|
|
#include <catch2/catch.hpp>
|
|
|
|
#include <atomic>
|
|
|
|
#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<bool> 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<int> 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<int> i) -> int {
|
|
return *i;
|
|
};
|
|
|
|
int a = 5;
|
|
const int test = call(&a);
|
|
CHECK(assert_flag == false);
|
|
CHECK(a == test);
|
|
}
|