[Libreoffice-commits] .: sw/inc sw/qa sw/source

Caolán McNamara caolan at kemper.freedesktop.org
Mon Dec 20 09:12:21 PST 2010


 sw/inc/shellres.hxx               |    9 +++++++--
 sw/qa/core/swdoc-test.cxx         |   32 ++++++++++++++++++++++++++++----
 sw/source/filter/rtf/swparrtf.cxx |    4 ++--
 sw/source/filter/ww1/fltshell.cxx |    2 +-
 sw/source/filter/ww8/ww8par.cxx   |    4 ++--
 sw/source/ui/utlui/initui.cxx     |   21 +++++++++++++++++----
 6 files changed, 57 insertions(+), 15 deletions(-)

New commits:
commit 3449053e9b1e2411d284e1f1ecef6064cd4947fd
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Mon Dec 20 17:10:42 2010 +0000

    Ensure that only the three valid options are possible to use
    
    Originally four cryptic possibilties, only three of which would
    correctly give unique values. So refactor into three possibilties,
    make self-documenting and lock it down with a cppunit test

diff --git a/sw/inc/shellres.hxx b/sw/inc/shellres.hxx
index 9e8f5e0..1471a84 100644
--- a/sw/inc/shellres.hxx
+++ b/sw/inc/shellres.hxx
@@ -85,11 +85,16 @@ struct SW_DLLPUBLIC ShellResource : public Resource
     // die AutoFormat-Redline-Kommentare
     inline const SvStringsDtor&	GetAutoFmtNameLst() const;
 
+    enum PageNameMode
+    {
+        NORMAL_PAGE,
+        FIRST_PAGE,
+        FOLLOW_PAGE
+    };
     // returns for the specific filter the new names of pagedescs
     // This method is for the old code of the specific filters with
     // now localized names
-    String GetPageDescName( USHORT nNo, BOOL bFirst = FALSE,
-                                        BOOL bFollow = FALSE );
+    String GetPageDescName( USHORT nNo, PageNameMode eMode );
 
     ShellResource();
     ~ShellResource();
diff --git a/sw/qa/core/swdoc-test.cxx b/sw/qa/core/swdoc-test.cxx
index fd299ae..b3f89c6 100644
--- a/sw/qa/core/swdoc-test.cxx
+++ b/sw/qa/core/swdoc-test.cxx
@@ -47,6 +47,7 @@
 #include "init.hxx"
 #include "swtypes.hxx"
 #include "doc.hxx"
+#include "shellres.hxx"
 
 using namespace ::com::sun::star;
 
@@ -61,13 +62,12 @@ public:
     virtual void setUp();
     virtual void tearDown();
 
-    void randomTest()
-    {
-        CPPUNIT_ASSERT_MESSAGE("SwDoc::IsRedlineOn()", !m_pDoc->IsRedlineOn());
-    }
+    void testPageDescName();
+    void randomTest();
 
     CPPUNIT_TEST_SUITE(SwDocTest);
     CPPUNIT_TEST(randomTest);
+    CPPUNIT_TEST(testPageDescName);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -76,6 +76,30 @@ private:
     SwDoc *m_pDoc;
 };
 
+void SwDocTest::testPageDescName()
+{
+    ShellResource aShellResources;
+
+    std::vector<rtl::OUString> aResults;
+
+    //These names must be unique for each different combination, otherwise
+    //duplicate page description names may exist, which will causes lookup
+    //by name to be incorrect, and so the corresponding export to .odt
+    aResults.push_back(aShellResources.GetPageDescName(1, ShellResource::NORMAL_PAGE));
+    aResults.push_back(aShellResources.GetPageDescName(1, ShellResource::FIRST_PAGE));
+    aResults.push_back(aShellResources.GetPageDescName(1, ShellResource::FOLLOW_PAGE));
+
+    std::sort(aResults.begin(), aResults.end());
+    aResults.erase(std::unique(aResults.begin(), aResults.end()), aResults.end());
+
+    CPPUNIT_ASSERT_MESSAGE("GetPageDescName results must be unique", aResults.size() == 3);
+}
+
+void SwDocTest::randomTest()
+{
+    CPPUNIT_ASSERT_MESSAGE("SwDoc::IsRedlineOn()", !m_pDoc->IsRedlineOn());
+}
+
 SwDocTest::SwDocTest()
 {
     m_xContext = cppu::defaultBootstrap_InitialComponentContext();
diff --git a/sw/source/filter/rtf/swparrtf.cxx b/sw/source/filter/rtf/swparrtf.cxx
index e64e71d..34a3237 100644
--- a/sw/source/filter/rtf/swparrtf.cxx
+++ b/sw/source/filter/rtf/swparrtf.cxx
@@ -922,7 +922,7 @@ void rtfSections::InsertSegments(bool bNewDoc)
                 else
                 {
                     USHORT nPos = mrReader.pDoc->MakePageDesc(
-                        ViewShell::GetShellRes()->GetPageDescName(nDesc)
+                        ViewShell::GetShellRes()->GetPageDescName(nDesc, ShellResource::NORMAL_PAGE)
                         , 0, false);
                     aIter->mpTitlePage = &mrReader.pDoc->_GetPageDesc(nPos);
                 }
@@ -944,7 +944,7 @@ void rtfSections::InsertSegments(bool bNewDoc)
             {
                 USHORT nPos = mrReader.pDoc->MakePageDesc(
                     ViewShell::GetShellRes()->GetPageDescName(nDesc,
-                        false, aIter->HasTitlePage()),
+                        aIter->HasTitlePage() ? ShellResource::FIRST_PAGE : ShellResource::NORMAL_PAGE),
                         aIter->mpTitlePage, false);
                 aIter->mpPage = &mrReader.pDoc->_GetPageDesc(nPos);
             }
diff --git a/sw/source/filter/ww1/fltshell.cxx b/sw/source/filter/ww1/fltshell.cxx
index 4f036fc..3d746f7 100644
--- a/sw/source/filter/ww1/fltshell.cxx
+++ b/sw/source/filter/ww1/fltshell.cxx
@@ -2014,7 +2014,7 @@ SwPageDesc* SwFltShell::MakePageDesc(SwPageDesc* pFirstPageDesc)
 // fuer dopp. Namen ist gering)
 
     nPos = GetDoc().MakePageDesc( ViewShell::GetShellRes()->GetPageDescName(
-                                   GetDoc().GetPageDescCnt(), FALSE, bFollow ),
+                                   GetDoc().GetPageDescCnt(), bFollow ? ShellResource::FOLLOW_PAGE : ShellResource::NORMAL_PAGE),
                                 pFirstPageDesc, FALSE );
 
     pNewPD =  &((SwPageDesc&)const_cast<const SwDoc &>(GetDoc()).
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index 7b7a20d..0690061 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -3564,7 +3564,7 @@ SwFmtPageDesc wwSectionManager::SetSwFmtPageDesc(mySegIter &rIter,
         else
         {
             USHORT nPos = mrReader.rDoc.MakePageDesc(
-                ViewShell::GetShellRes()->GetPageDescName(mnDesc, true)
+                ViewShell::GetShellRes()->GetPageDescName(mnDesc, ShellResource::FIRST_PAGE)
                 , 0, false);
             rIter->mpTitlePage = &mrReader.rDoc._GetPageDesc(nPos);
         }
@@ -3583,7 +3583,7 @@ SwFmtPageDesc wwSectionManager::SetSwFmtPageDesc(mySegIter &rIter,
     else
     {
         USHORT nPos = mrReader.rDoc.MakePageDesc(
-            ViewShell::GetShellRes()->GetPageDescName(mnDesc),
+            ViewShell::GetShellRes()->GetPageDescName(mnDesc, ShellResource::NORMAL_PAGE),
                 rIter->mpTitlePage, false);
         rIter->mpPage = &mrReader.rDoc._GetPageDesc(nPos);
     }
diff --git a/sw/source/ui/utlui/initui.cxx b/sw/source/ui/utlui/initui.cxx
index 9c755b8..21c545a 100644
--- a/sw/source/ui/utlui/initui.cxx
+++ b/sw/source/ui/utlui/initui.cxx
@@ -198,11 +198,24 @@ ShellResource::~ShellResource()
         delete pAutoFmtNameLst, pAutoFmtNameLst = 0;
 }
 
-String ShellResource::GetPageDescName( USHORT nNo, BOOL bIsFirst, BOOL bFollow )
+String ShellResource::GetPageDescName( USHORT nNo, PageNameMode eMode )
 {
-    String sRet( bIsFirst ? sPageDescFirstName
-                          : bFollow ? sPageDescFollowName
-                                      : sPageDescName );
+    String sRet;
+
+    switch (eMode)
+    {
+        case NORMAL_PAGE:
+            sRet = sPageDescName;
+            break;
+            break;
+        case FIRST_PAGE:
+            sRet = sPageDescFirstName;
+            break;
+        case FOLLOW_PAGE:
+            sRet = sPageDescFollowName;
+            break;
+    }
+
     sRet.SearchAndReplaceAscii( "$(ARG1)", String::CreateFromInt32( nNo ));
     return sRet;
 }


More information about the Libreoffice-commits mailing list