#include "SingletonHolder.h" #include "SharedHandle.h" #include #include namespace aria2 { 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: std::string greeting_; public: M(const std::string& greeting):greeting_(greeting) {} const std::string& greeting() const { return greeting_; } void greeting(const std::string& greeting) { greeting_ = greeting; } }; typedef SharedHandle MHandle; typedef SharedHandle IntHandle; void SingletonHolderTest::testInstance() { MHandle m(new M("Hello world.")); SingletonHolder::instance(m); std::cerr << SingletonHolder::instance()->greeting() << std::endl; SingletonHolder::instance()->greeting("Yes, it worked!"); std::cerr << SingletonHolder::instance()->greeting() << std::endl; IntHandle i(new int(100)); SingletonHolder::instance(i); std::cerr << *SingletonHolder::instance() << std::endl; std::cerr << SingletonHolder::instance()->greeting() << std::endl; } } // namespace aria2