summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatarina Behrens <Katarina.Behrens@cib.de>2015-05-27 23:00:17 +0200
committerBjörn Michaelsen <bjoern.michaelsen@canonical.com>2015-05-28 13:44:53 +0000
commitf12f5525427d7d743a267ab2e8bf5315d389e9cf (patch)
treeb4067c6f1c24d3321e0c5e73ae08b5df425c784c
parent8c609d7a1ccee5044d8d64f07b59407dfb316324 (diff)
Unit test related to tdf#89783: more than 64k PageDescs
Change-Id: I19207a15e1a3eec2ac097ec007afd7bfc2fd1cf1 Reviewed-on: https://gerrit.libreoffice.org/15941 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Björn Michaelsen <bjoern.michaelsen@canonical.com>
-rw-r--r--sw/qa/core/uwriter.cxx50
1 files changed, 50 insertions, 0 deletions
diff --git a/sw/qa/core/uwriter.cxx b/sw/qa/core/uwriter.cxx
index 966a2aa23bbf..08f8020690b4 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();