aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohannes Schickel2008-03-28 06:03:59 +0000
committerJohannes Schickel2008-03-28 06:03:59 +0000
commite29b4bb0cd4b4c71a3a53646b0eb728e7f156063 (patch)
tree5322a4a5791066416b84d72bc5c26a8dc01c8732 /test
parentdc1a7004e949a5c1b8936f73387905e0f96f7e5c (diff)
downloadscummvm-rg350-e29b4bb0cd4b4c71a3a53646b0eb728e7f156063.tar.gz
scummvm-rg350-e29b4bb0cd4b4c71a3a53646b0eb728e7f156063.tar.bz2
scummvm-rg350-e29b4bb0cd4b4c71a3a53646b0eb728e7f156063.zip
Committed shared pointer implementation of patch #1895703 "COMMON: Managed List".
Unlike the patch on the tracker this commit includes documentation for SharedPtr. svn-id: r31287
Diffstat (limited to 'test')
-rw-r--r--test/common/ptr.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/common/ptr.h b/test/common/ptr.h
new file mode 100644
index 0000000000..b6f2e950ca
--- /dev/null
+++ b/test/common/ptr.h
@@ -0,0 +1,36 @@
+#include <cxxtest/TestSuite.h>
+
+#include "common/ptr.h"
+
+class PtrTestSuite : public CxxTest::TestSuite
+{
+ public:
+ void test_assign() {
+ Common::SharedPtr<int> p1(new int(1));
+ TS_ASSERT(p1.unique());
+ TS_ASSERT_EQUALS(*p1, 1);
+
+ {
+ Common::SharedPtr<int> p2 = p1;
+ TS_ASSERT(!p1.unique());
+ TS_ASSERT(p1.refCount() == p2.refCount());
+ TS_ASSERT(p1.refCount() == 2);
+ TS_ASSERT(p1 == p2);
+ TS_ASSERT_EQUALS(*p2, 1);
+ {
+ Common::SharedPtr<int> p3;
+ p3 = p2;
+ TS_ASSERT(p3 == p2 && p3 == p1);
+ TS_ASSERT(p1.refCount() == 3);
+ TS_ASSERT_EQUALS(*p3, 1);
+ *p3 = 0;
+ TS_ASSERT_EQUALS(*p3, 0);
+ }
+ TS_ASSERT_EQUALS(*p2, 0);
+ TS_ASSERT(p1.refCount() == 2);
+ }
+
+ TS_ASSERT_EQUALS(*p1, 0);
+ TS_ASSERT(p1.unique());
+ }
+};