diff options
author | Max Horn | 2010-03-22 20:26:57 +0000 |
---|---|---|
committer | Max Horn | 2010-03-22 20:26:57 +0000 |
commit | dd7891cdadc5c2e4f9d1c10d229c4c0d7235f8b1 (patch) | |
tree | 6ed21ab4b9c9ec662ed11923e517ed7ffa40a6d1 /test/common/ptr.h | |
parent | 86653687d7369a46ac25ef4a3cd513b401807c67 (diff) | |
download | scummvm-rg350-dd7891cdadc5c2e4f9d1c10d229c4c0d7235f8b1.tar.gz scummvm-rg350-dd7891cdadc5c2e4f9d1c10d229c4c0d7235f8b1.tar.bz2 scummvm-rg350-dd7891cdadc5c2e4f9d1c10d229c4c0d7235f8b1.zip |
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
Diffstat (limited to 'test/common/ptr.h')
-rw-r--r-- | test/common/ptr.h | 27 |
1 files changed, 25 insertions, 2 deletions
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<InstanceCountingClass> p1(new InstanceCountingClass()); + TS_ASSERT_EQUALS(InstanceCountingClass::count, 1); + + Common::ScopedPtr<InstanceCountingClass> p2(new InstanceCountingClass()); + TS_ASSERT_EQUALS(InstanceCountingClass::count, 2); + } + TS_ASSERT_EQUALS(InstanceCountingClass::count, 0); + } + void test_assign() { Common::SharedPtr<int> p1(new int(1)); TS_ASSERT(p1.unique()); @@ -81,3 +102,5 @@ class PtrTestSuite : public CxxTest::TestSuite a = b; } }; + +int PtrTestSuite::InstanceCountingClass::count = 0; |