diff options
Diffstat (limited to 'o3tl')
-rw-r--r-- | o3tl/qa/cow_wrapper_clients.cxx | 50 | ||||
-rw-r--r-- | o3tl/qa/cow_wrapper_clients.hxx | 24 | ||||
-rw-r--r-- | o3tl/qa/test-cow_wrapper.cxx | 23 |
3 files changed, 97 insertions, 0 deletions
diff --git a/o3tl/qa/cow_wrapper_clients.cxx b/o3tl/qa/cow_wrapper_clients.cxx index f468d4306bcf..bfb53f22a9bd 100644 --- a/o3tl/qa/cow_wrapper_clients.cxx +++ b/o3tl/qa/cow_wrapper_clients.cxx @@ -18,6 +18,7 @@ */ #include "cow_wrapper_clients.hxx" +#include <rtl/instance.hxx> namespace o3tltests { @@ -169,6 +170,55 @@ bool cow_wrapper_client3::operator<( const cow_wrapper_client3& rRHS ) const return maImpl < rRHS.maImpl; } +// --------------------------------------------------------------------------- + +namespace { struct theDefaultClient4 : public rtl::Static< o3tl::cow_wrapper< int >, + theDefaultClient4 > {}; } + +cow_wrapper_client4::cow_wrapper_client4() : + maImpl(theDefaultClient4::get()) +{ +} + +cow_wrapper_client4::cow_wrapper_client4( int nVal ) : + maImpl( nVal ) +{ +} + +cow_wrapper_client4::~cow_wrapper_client4() +{ +} + +cow_wrapper_client4::cow_wrapper_client4( const cow_wrapper_client4& rSrc ) : + maImpl(rSrc.maImpl) +{ +} + +cow_wrapper_client4& cow_wrapper_client4::operator=( const cow_wrapper_client4& rSrc ) +{ + maImpl = rSrc.maImpl; + + return *this; +} + +bool cow_wrapper_client4::is_default() const +{ + return maImpl.same_object(theDefaultClient4::get()); +} + +bool cow_wrapper_client4::operator==( const cow_wrapper_client4& rRHS ) const +{ + return maImpl == rRHS.maImpl; +} +bool cow_wrapper_client4::operator!=( const cow_wrapper_client4& rRHS ) const +{ + return maImpl != rRHS.maImpl; +} +bool cow_wrapper_client4::operator<( const cow_wrapper_client4& rRHS ) const +{ + return maImpl < rRHS.maImpl; +} + } // namespace o3tltests /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/o3tl/qa/cow_wrapper_clients.hxx b/o3tl/qa/cow_wrapper_clients.hxx index 23ab57845195..e2dad61d23bd 100644 --- a/o3tl/qa/cow_wrapper_clients.hxx +++ b/o3tl/qa/cow_wrapper_clients.hxx @@ -115,6 +115,30 @@ private: o3tl::cow_wrapper< cow_wrapper_client2_impl, o3tl::ThreadSafeRefCountingPolicy > maImpl; }; +/** test default-object comparison - have default-ctored-client4 share + the same static impl instance, check if isDefault does the right + thing + */ +class cow_wrapper_client4 +{ +public: + cow_wrapper_client4(); + explicit cow_wrapper_client4(int); + ~cow_wrapper_client4(); + + cow_wrapper_client4( const cow_wrapper_client4& ); + cow_wrapper_client4& operator=( const cow_wrapper_client4& ); + + bool is_default() const; + + bool operator==( const cow_wrapper_client4& rRHS ) const; + bool operator!=( const cow_wrapper_client4& rRHS ) const; + bool operator<( const cow_wrapper_client4& rRHS ) const; + +private: + o3tl::cow_wrapper< int > maImpl; +}; + } // namespace o3tltests #endif /* INCLUDED_COW_WRAPPER_CLIENTS_HXX */ diff --git a/o3tl/qa/test-cow_wrapper.cxx b/o3tl/qa/test-cow_wrapper.cxx index ba261fa3c3f3..e3682064dc75 100644 --- a/o3tl/qa/test-cow_wrapper.cxx +++ b/o3tl/qa/test-cow_wrapper.cxx @@ -139,12 +139,35 @@ public: test( aTestObj7, aTestObj8, aTestObj9 ); } + void testStaticDefault() + { + cow_wrapper_client4 aTestObj1; + cow_wrapper_client4 aTestObj2; + cow_wrapper_client4 aTestObj3(4); + + CPPUNIT_ASSERT_MESSAGE("aTestObj1.is_default()", + aTestObj1.is_default() ); + CPPUNIT_ASSERT_MESSAGE("aTestObj2.is_default()", + aTestObj2.is_default() ); + CPPUNIT_ASSERT_MESSAGE("!aTestObj3.is_default()", + !aTestObj3.is_default() ); + aTestObj1 = aTestObj2; + CPPUNIT_ASSERT_MESSAGE("aTestObj1.is_default() #2", + aTestObj1.is_default() ); + CPPUNIT_ASSERT_MESSAGE("aTestObj2.is_default() #2", + aTestObj2.is_default() ); + aTestObj1 = aTestObj3; + CPPUNIT_ASSERT_MESSAGE("!aTestObj1.is_default()", + !aTestObj1.is_default() ); + } + // Change the following lines only, if you add, remove or rename // member functions of the current class, // because these macros are need by auto register mechanism. CPPUNIT_TEST_SUITE(cow_wrapper_test); CPPUNIT_TEST(testCowWrapper); + CPPUNIT_TEST(testStaticDefault); CPPUNIT_TEST_SUITE_END(); }; |