From 075d17f8ada47e990fe94606c3d21df409223465 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Tue, 2 May 2023 10:01:47 +0200 Subject: moved source directories into `/src` (#264) * moved source directories into `/src` * updated bundle.lua for new `src` path * moved some docs, icon * removed old test trees --- src/zencore/refcount.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/zencore/refcount.cpp (limited to 'src/zencore/refcount.cpp') diff --git a/src/zencore/refcount.cpp b/src/zencore/refcount.cpp new file mode 100644 index 000000000..c6c47b04d --- /dev/null +++ b/src/zencore/refcount.cpp @@ -0,0 +1,65 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#include + +#include + +#include + +namespace zen { + +////////////////////////////////////////////////////////////////////////// +// +// Testing related code follows... +// + +#if ZEN_WITH_TESTS + +struct TestRefClass : public RefCounted +{ + ~TestRefClass() + { + if (OnDestroy) + OnDestroy(); + } + + using RefCounted::RefCount; + + std::function OnDestroy; +}; + +void +refcount_forcelink() +{ +} + +TEST_CASE("RefPtr") +{ + RefPtr Ref; + Ref = new TestRefClass; + + bool IsDestroyed = false; + Ref->OnDestroy = [&] { IsDestroyed = true; }; + + CHECK(IsDestroyed == false); + CHECK(Ref->RefCount() == 1); + + RefPtr Ref2; + Ref2 = Ref; + + CHECK(IsDestroyed == false); + CHECK(Ref->RefCount() == 2); + + RefPtr Ref3; + Ref2 = Ref3; + + CHECK(IsDestroyed == false); + CHECK(Ref->RefCount() == 1); + Ref = Ref3; + + CHECK(IsDestroyed == true); +} + +#endif + +} // namespace zen -- cgit v1.2.3