aboutsummaryrefslogtreecommitdiff
path: root/test/common/ptr.h
diff options
context:
space:
mode:
Diffstat (limited to 'test/common/ptr.h')
-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());
+ }
+};