[Scummvm-cvs-logs] SF.net SVN: scummvm:[48358] scummvm/trunk/test/common/ptr.h
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Mon Mar 22 21:26:58 CET 2010
Revision: 48358
http://scummvm.svn.sourceforge.net/scummvm/?rev=48358&view=rev
Author: fingolfin
Date: 2010-03-22 20:26:57 +0000 (Mon, 22 Mar 2010)
Log Message:
-----------
Add simple testcase for ScopedPtr and SharedPtr
The new test verifies that a given object is indeed deleted after
the smart pointer leaves scope.
Modified Paths:
--------------
scummvm/trunk/test/common/ptr.h
Modified: scummvm/trunk/test/common/ptr.h
===================================================================
--- scummvm/trunk/test/common/ptr.h 2010-03-22 15:57:46 UTC (rev 48357)
+++ scummvm/trunk/test/common/ptr.h 2010-03-22 20:26:57 UTC (rev 48358)
@@ -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 @@
a = b;
}
};
+
+int PtrTestSuite::InstanceCountingClass::count = 0;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list