From dd7891cdadc5c2e4f9d1c10d229c4c0d7235f8b1 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 22 Mar 2010 20:26:57 +0000 Subject: Add simple testcase for ScopedPtr and SharedPtr The new test verifies that a given object is indeed deleted after the smart pointer leaves scope. svn-id: r48358 --- test/common/ptr.h | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'test/common') diff --git a/test/common/ptr.h b/test/common/ptr.h index 4bd81f8004..ebd978959a 100644 --- a/test/common/ptr.h +++ b/test/common/ptr.h @@ -2,9 +2,30 @@ #include "common/ptr.h" -class PtrTestSuite : public CxxTest::TestSuite -{ +class PtrTestSuite : public CxxTest::TestSuite { public: + + // A simple class which keeps track of all its instances + class InstanceCountingClass { + public: + static int count; + InstanceCountingClass() { count++; } + InstanceCountingClass(const InstanceCountingClass&) { count++; } + ~InstanceCountingClass() { count--; } + }; + + void test_deletion() { + TS_ASSERT_EQUALS(InstanceCountingClass::count, 0); + { + Common::SharedPtr p1(new InstanceCountingClass()); + TS_ASSERT_EQUALS(InstanceCountingClass::count, 1); + + Common::ScopedPtr p2(new InstanceCountingClass()); + TS_ASSERT_EQUALS(InstanceCountingClass::count, 2); + } + TS_ASSERT_EQUALS(InstanceCountingClass::count, 0); + } + void test_assign() { Common::SharedPtr p1(new int(1)); TS_ASSERT(p1.unique()); @@ -81,3 +102,5 @@ class PtrTestSuite : public CxxTest::TestSuite a = b; } }; + +int PtrTestSuite::InstanceCountingClass::count = 0; -- cgit v1.2.3