erki a7495db03f
All checks were successful
CI & Unit Tests / Unit-Tests (push) Successful in 1m34s
Utility: add notnull
2023-10-25 11:39:55 +03:00

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);
}