summaryrefslogtreecommitdiff
path: root/o3tl
diff options
context:
space:
mode:
authorThorsten Behrens <tbehrens@suse.com>2013-03-23 20:44:26 +0100
committerThorsten Behrens <tbehrens@suse.com>2013-03-23 20:46:39 +0100
commitfb8dd00d597495e8622a54dfd724ccc99d1fe999 (patch)
treea9448aae86b9a15b93ff69a21b49ac19e1601e37 /o3tl
parent45e4a5ef5347f7e2fe90a0d411e3749f24008c3a (diff)
Validate cow_wrapper static default pattern.
A bunch of objects use the optimization to assign one single, unique default object to default-ctored instances, and decide on whether any given object is in 'default' state by ptr-comparing against this one unique instance. Simulating that pattern here. Change-Id: I88f7d8488d81bcf1a01ab6b63121e003b8f0ade9
Diffstat (limited to 'o3tl')
-rw-r--r--o3tl/qa/cow_wrapper_clients.cxx50
-rw-r--r--o3tl/qa/cow_wrapper_clients.hxx24
-rw-r--r--o3tl/qa/test-cow_wrapper.cxx23
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();
};