#include #include "SingletonHolder.h" #include "SharedHandle.h" #include using namespace std; class SingletonHolderTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(SingletonHolderTest); CPPUNIT_TEST(testInstance); CPPUNIT_TEST_SUITE_END(); private: public: void setUp() { } void testInstance(); }; CPPUNIT_TEST_SUITE_REGISTRATION( SingletonHolderTest ); class M { private: string _greeting; public: M(const string& greeting):_greeting(greeting) {} const string& greeting() const { return _greeting; } void greeting(const string& greeting) { _greeting = greeting; } }; typedef SharedHandle MHandle; typedef SharedHandle IntHandle; void SingletonHolderTest::testInstance() { MHandle m = new M("Hello world."); SingletonHolder::instance(m); cerr << SingletonHolder::instance()->greeting() << endl; SingletonHolder::instance()->greeting("Yes, it worked!"); cerr << SingletonHolder::instance()->greeting() << endl; IntHandle i = new int(100); SingletonHolder::instance(i); cerr << SingletonHolder::instance() << endl; cerr << SingletonHolder::instance()->greeting() << endl; }