[Libreoffice-commits] core.git: o3tl/qa

Thorsten Behrens tbehrens at suse.com
Sat Mar 23 12:47:03 PDT 2013


 o3tl/qa/cow_wrapper_clients.cxx |   50 ++++++++++++++++++++++++++++++++++++++++
 o3tl/qa/cow_wrapper_clients.hxx |   24 +++++++++++++++++++
 o3tl/qa/test-cow_wrapper.cxx    |   23 ++++++++++++++++++
 3 files changed, 97 insertions(+)

New commits:
commit fb8dd00d597495e8622a54dfd724ccc99d1fe999
Author: Thorsten Behrens <tbehrens at suse.com>
Date:   Sat Mar 23 20:44:26 2013 +0100

    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

diff --git a/o3tl/qa/cow_wrapper_clients.cxx b/o3tl/qa/cow_wrapper_clients.cxx
index f468d43..bfb53f2 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 23ab578..e2dad61 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 ba261fa..e368206 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();
 };
 


More information about the Libreoffice-commits mailing list