aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/refcount.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zencore/refcount.cpp')
-rw-r--r--src/zencore/refcount.cpp65
1 files changed, 65 insertions, 0 deletions
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 <zencore/refcount.h>
+
+#include <zencore/testing.h>
+
+#include <functional>
+
+namespace zen {
+
+//////////////////////////////////////////////////////////////////////////
+//
+// Testing related code follows...
+//
+
+#if ZEN_WITH_TESTS
+
+struct TestRefClass : public RefCounted
+{
+ ~TestRefClass()
+ {
+ if (OnDestroy)
+ OnDestroy();
+ }
+
+ using RefCounted::RefCount;
+
+ std::function<void()> OnDestroy;
+};
+
+void
+refcount_forcelink()
+{
+}
+
+TEST_CASE("RefPtr")
+{
+ RefPtr<TestRefClass> Ref;
+ Ref = new TestRefClass;
+
+ bool IsDestroyed = false;
+ Ref->OnDestroy = [&] { IsDestroyed = true; };
+
+ CHECK(IsDestroyed == false);
+ CHECK(Ref->RefCount() == 1);
+
+ RefPtr<TestRefClass> Ref2;
+ Ref2 = Ref;
+
+ CHECK(IsDestroyed == false);
+ CHECK(Ref->RefCount() == 2);
+
+ RefPtr<TestRefClass> Ref3;
+ Ref2 = Ref3;
+
+ CHECK(IsDestroyed == false);
+ CHECK(Ref->RefCount() == 1);
+ Ref = Ref3;
+
+ CHECK(IsDestroyed == true);
+}
+
+#endif
+
+} // namespace zen