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

Katarina Behrens Katarina.Behrens at cib.de
Thu May 28 06:45:25 PDT 2015


 sw/qa/core/uwriter.cxx |   50 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

New commits:
commit f12f5525427d7d743a267ab2e8bf5315d389e9cf
Author: Katarina Behrens <Katarina.Behrens at cib.de>
Date:   Wed May 27 23:00:17 2015 +0200

    Unit test related to tdf#89783: more than 64k PageDescs
    
    Change-Id: I19207a15e1a3eec2ac097ec007afd7bfc2fd1cf1
    Reviewed-on: https://gerrit.libreoffice.org/15941
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Björn Michaelsen <bjoern.michaelsen at canonical.com>

diff --git a/sw/qa/core/uwriter.cxx b/sw/qa/core/uwriter.cxx
index 966a2aa..08f8020 100644
--- a/sw/qa/core/uwriter.cxx
+++ b/sw/qa/core/uwriter.cxx
@@ -62,6 +62,7 @@
 #include "IMark.hxx"
 #include "ring.hxx"
 #include "calbck.hxx"
+#include "pagedesc.hxx"
 
 typedef tools::SvRef<SwDocShell> SwDocShellRef;
 
@@ -109,6 +110,7 @@ public:
     void testFormulas();
     void testIntrusiveRing();
     void testClientModify();
+    void test64kPageDescs();
 
     CPPUNIT_TEST_SUITE(SwDocTest);
 
@@ -141,6 +143,7 @@ public:
     CPPUNIT_TEST(testFormulas);
     CPPUNIT_TEST(testIntrusiveRing);
     CPPUNIT_TEST(testClientModify);
+    CPPUNIT_TEST(test64kPageDescs);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -1565,6 +1568,53 @@ void SwDocTest::testClientModify()
     CPPUNIT_ASSERT_EQUAL(aClient2.m_nNotifyCount,1);
 }
 
+void SwDocTest::test64kPageDescs()
+{
+    size_t nPageDescCount = 65536; // USHRT_MAX + 1
+
+    for (size_t i = 0; i < nPageDescCount; ++i)
+    {
+        OUString aName = OUString("Page") + OUString::number(i);
+        m_pDoc->MakePageDesc( aName );
+    }
+
+    size_t nCount = m_pDoc->GetPageDescCnt();
+    // +1 because Writer always creates a dummy page desc
+    // in a new SwDoc
+    CPPUNIT_ASSERT_EQUAL( nPageDescCount + 1, nCount );
+
+    const SwPageDesc &rDesc = m_pDoc->GetPageDesc( nPageDescCount );
+    SwPageDesc &rZeroDesc = m_pDoc->GetPageDesc( 0 );
+    CPPUNIT_ASSERT_EQUAL( OUString("Page65535"), rDesc.GetName() );
+
+    SwPageDesc aDesc( rDesc );
+    const OUString aChanged("Changed01");
+    aDesc.SetName( aChanged );
+    m_pDoc->ChgPageDesc( nPageDescCount, aDesc );
+
+    size_t nPos;
+    SwPageDesc *pDesc = m_pDoc->FindPageDesc( aChanged, &nPos );
+    CPPUNIT_ASSERT( pDesc != NULL );
+    CPPUNIT_ASSERT( nPos == nPageDescCount );
+
+    // check if we didn't mess up PageDesc at pos 0
+    // (happens with 16bit int overflow)
+    OUString aZeroName = rZeroDesc.GetName();
+    rZeroDesc = m_pDoc->GetPageDesc( 0 );
+    CPPUNIT_ASSERT_EQUAL( aZeroName, rZeroDesc.GetName() );
+
+    m_pDoc->DelPageDesc( aChanged, nPos );
+    pDesc = m_pDoc->FindPageDesc( aChanged, &nPos );
+    // not there anymore
+    CPPUNIT_ASSERT( pDesc == NULL );
+    CPPUNIT_ASSERT( nPos == SIZE_MAX );
+
+    // check if PageDesc at pos 0 is still there
+    pDesc = m_pDoc->FindPageDesc( aZeroName, &nPos );
+    CPPUNIT_ASSERT( pDesc != NULL );
+    CPPUNIT_ASSERT( nPos == 0 );
+}
+
 void SwDocTest::setUp()
 {
     BootstrapFixture::setUp();


More information about the Libreoffice-commits mailing list