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
This commit is contained in:
Johannes Schickel 2008-03-28 06:03:59 +00:00
parent dc1a7004e9
commit e29b4bb0cd
5 changed files with 212 additions and 9 deletions

36
test/common/ptr.h Normal file
View file

@ -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());
}
};