Skip to content

Commit

Permalink
Add test case for shared-data, reusing the mock-up class
Browse files Browse the repository at this point in the history
  • Loading branch information
ropez committed Feb 7, 2010
1 parent e520174 commit dd1c260
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ add_executable(testrunner ${test_SOURCES})
target_link_libraries(testrunner pieces ${CPPUNIT_LIBRARIES} ${OPENTHREADS_LIBRARIES})

set(tests
TestSharedData
TestAutoPointer
TestByteArray
TestByteArraySlicing
Expand Down
33 changes: 32 additions & 1 deletion src/test/test_smart_pointers.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <Pieces/SharedData>
#include <Pieces/AutoPointer>
#include <Pieces/global>

using pcs::AutoPointer;

namespace {
class MockObject
class MockObject : public pcs::SharedData
{
public:
static int count;
Expand All @@ -25,6 +26,36 @@ class MockObject
int MockObject::count = 0;
}

class TestSharedData : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestSharedData);
CPPUNIT_TEST(testReferenceCount);
CPPUNIT_TEST_SUITE_END();

public:
void testReferenceCount() {
MockObject o;
o.ref();
CPPUNIT_ASSERT(!o.shared());
o.ref();
CPPUNIT_ASSERT(o.shared());
o.ref();
CPPUNIT_ASSERT(o.shared());

bool v;
v = o.deref();
CPPUNIT_ASSERT(o.shared());
CPPUNIT_ASSERT(v);
v = o.deref();
CPPUNIT_ASSERT(!o.shared());
CPPUNIT_ASSERT(v);
v = o.deref();
CPPUNIT_ASSERT(!o.shared());
CPPUNIT_ASSERT(!v);
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestSharedData);

class TestAutoPointer : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestAutoPointer);
Expand Down

0 comments on commit dd1c260

Please sign in to comment.