diff options
Diffstat (limited to 'zencore/zencore.cpp')
| -rw-r--r-- | zencore/zencore.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/zencore/zencore.cpp b/zencore/zencore.cpp index 8b45d273d..2a7c5755e 100644 --- a/zencore/zencore.cpp +++ b/zencore/zencore.cpp @@ -33,6 +33,9 @@ namespace zen { +AssertImpl AssertImpl::DefaultAssertImpl; +AssertImpl* AssertImpl::CurrentAssertImpl = &AssertImpl::DefaultAssertImpl; + ////////////////////////////////////////////////////////////////////////// bool @@ -120,6 +123,53 @@ zencore_forcelinktests() zen::usonpackage_forcelink(); zen::crypto_forcelink(); } +} // namespace zen + +# include <zencore/testing.h> + +namespace zen { + +TEST_CASE("Assert.Default") +{ + bool A = true; + bool B = false; + CHECK_THROWS_WITH(ZEN_ASSERT(A == B), "A == B"); +} + +TEST_CASE("Assert.Custom") +{ + struct MyAssertImpl : AssertImpl + { + ZEN_FORCENOINLINE ZEN_DEBUG_SECTION MyAssertImpl() : PrevAssertImpl(CurrentAssertImpl) { CurrentAssertImpl = this; } + virtual ZEN_FORCENOINLINE ZEN_DEBUG_SECTION ~MyAssertImpl() { CurrentAssertImpl = PrevAssertImpl; } + virtual void ZEN_FORCENOINLINE ZEN_DEBUG_SECTION OnAssert(const char* Filename, + int LineNumber, + const char* FunctionName, + const char* Msg) + { + AssertFileName = Filename; + Line = LineNumber; + FuncName = FunctionName; + Message = Msg; + } + AssertImpl* PrevAssertImpl; + + const char* AssertFileName = nullptr; + int Line = -1; + const char* FuncName = nullptr; + const char* Message = nullptr; + }; + + MyAssertImpl MyAssert; + bool A = true; + bool B = false; + CHECK_THROWS_WITH(ZEN_ASSERT(A == B), "A == B"); + CHECK(MyAssert.AssertFileName != nullptr); + CHECK(MyAssert.Line != -1); + CHECK(MyAssert.FuncName != nullptr); + CHECK(strcmp(MyAssert.Message, "A == B") == 0); +} + #endif } // namespace zen |