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

Michael Stahl mstahl at redhat.com
Tue Feb 28 10:06:32 UTC 2017


 sw/qa/extras/odfexport/data/ooo321_stylepagenumber.odt |binary
 sw/qa/extras/odfexport/odfexport.cxx                   |   31 +++++++++++++++++
 sw/source/core/unocore/unoparagraph.cxx                |    6 ++-
 sw/source/core/unocore/unostyle.cxx                    |    6 ++-
 sw/source/filter/xml/xmlimpit.cxx                      |    3 +
 5 files changed, 42 insertions(+), 4 deletions(-)

New commits:
commit e7f463cea58fc87e114008a726b4ea7489f36aa9
Author: Michael Stahl <mstahl at redhat.com>
Date:   Mon Feb 27 22:13:32 2017 +0100

    tdf#77111 sw: add unit test, fix getting PageNumberOffset property
    
    There are 2 places where the style:page-number attribute is handled, in
    XMLNumberWithAutoInsteadZeroPropHdl (for paragraphs) and
    SvXMLExportItemMapper/SvXMLImportItemMapper (for tables)
    
    Apparently for the paragraph case, 0 was never written to mean "auto",
    this happened only for tables (see
    7edaf190e2b18fe5dd9b7dd8d8e7e24b2ff26520).
    
    The test reveals that SwXParagraph::Impl::GetSinglePropertyValue_Impl()
    was kinda broken by 7d9bb549d498d6beed2c4050c402d09643febdfa, which
    converts void values of "short" properties to short(0), wrongly assuming
    that the Any contains a long.  (Fortunately this is then mapped to
    "auto" in XMLNumberWithAutoInsteadZeroPropHdl.)
    
    Change-Id: I3dc6d5533ac96955440b1589f1999d06750101af

diff --git a/sw/qa/extras/odfexport/data/ooo321_stylepagenumber.odt b/sw/qa/extras/odfexport/data/ooo321_stylepagenumber.odt
new file mode 100644
index 0000000..aae70e1
Binary files /dev/null and b/sw/qa/extras/odfexport/data/ooo321_stylepagenumber.odt differ
diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx
index 43aee57..3354ce2 100644
--- a/sw/qa/extras/odfexport/odfexport.cxx
+++ b/sw/qa/extras/odfexport/odfexport.cxx
@@ -548,6 +548,37 @@ DECLARE_ODFEXPORT_TEST(testFdo58949, "fdo58949.docx")
     CPPUNIT_ASSERT_EQUAL(true, bool(xNameAccess->hasByName("Obj102")));
 }
 
+DECLARE_ODFEXPORT_TEST(testStylePageNumber, "ooo321_stylepagenumber.odt")
+{
+    uno::Reference<text::XTextContent> xTable1(getParagraphOrTable(1));
+// actually no break attribute is written in this case
+//    CPPUNIT_ASSERT_EQUAL(style::BreakType_PAGE_BEFORE, getProperty<style::BreakType>(xTable1, "BreakType"));
+    CPPUNIT_ASSERT_EQUAL(OUString("Left Page"), getProperty<OUString>(xTable1, "PageDescName"));
+    CPPUNIT_ASSERT_EQUAL(sal_Int16(1), getProperty<sal_Int16>(xTable1, "PageNumberOffset"));
+
+    uno::Reference<text::XTextContent> xPara1(getParagraphOrTable(2));
+    CPPUNIT_ASSERT_EQUAL(OUString("Right Page"), getProperty<OUString>(xPara1, "PageDescName"));
+    CPPUNIT_ASSERT_EQUAL(sal_Int16(1), getProperty<sal_Int16>(xPara1, "PageNumberOffset"));
+
+    // i#114163 tdf#77111: OOo < 3.3 bug, it wrote "auto" as "0" for tables
+    uno::Reference<beans::XPropertySet> xTable0(getParagraphOrTable(3), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("Left Page"), getProperty<OUString>(xTable0, "PageDescName"));
+    CPPUNIT_ASSERT_EQUAL(uno::Any(), xTable0->getPropertyValue("PageNumberOffset"));
+
+    uno::Reference<beans::XPropertySet> xPara0(getParagraphOrTable(4), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("Right Page"), getProperty<OUString>(xPara0, "PageDescName"));
+    CPPUNIT_ASSERT_EQUAL(uno::Any(), xPara0->getPropertyValue("PageNumberOffset"));
+
+    uno::Reference<container::XNameAccess> xParaStyles(getStyles("ParagraphStyles"), uno::UNO_QUERY);
+    uno::Reference<beans::XPropertySet> xStyle1(xParaStyles->getByName("stylewithbreak1"), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("Right Page"), getProperty<OUString>(xStyle1, "PageDescName"));
+    CPPUNIT_ASSERT_EQUAL(sal_Int16(1), getProperty<sal_Int16>(xStyle1, "PageNumberOffset"));
+
+    uno::Reference<beans::XPropertySet> xStyle0(xParaStyles->getByName("stylewithbreak0"), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("First Page"), getProperty<OUString>(xStyle0, "PageDescName"));
+    CPPUNIT_ASSERT_EQUAL(uno::Any(), xStyle0->getPropertyValue("PageNumberOffset"));
+}
+
 DECLARE_ODFEXPORT_TEST(testCharacterBorder, "charborder.odt")
 {
     // Make sure paragraph and character attributes don't interfere
diff --git a/sw/source/core/unocore/unoparagraph.cxx b/sw/source/core/unocore/unoparagraph.cxx
index c0dc4ae..de10429 100644
--- a/sw/source/core/unocore/unoparagraph.cxx
+++ b/sw/source/core/unocore/unoparagraph.cxx
@@ -495,8 +495,10 @@ void SwXParagraph::Impl::GetSinglePropertyValue_Impl(
             // since the sfx uInt16 item now exports a sal_Int32, we may have to fix this here
             sal_Int32 nValue(0);
 
-            rAny >>= nValue;
-            rAny <<= static_cast< sal_Int16 >(nValue);
+            if (rAny >>= nValue)
+            {
+                rAny <<= static_cast<sal_Int16>(nValue);
+            }
         }
 
         //UUUU check for needed metric translation
diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index 6e2c9e0..54eca80 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -3989,8 +3989,10 @@ uno::Sequence< uno::Any > SwXAutoStyle::GetPropertyValues_Impl(
             {
                 // since the sfx uint16 item now exports a sal_Int32, we may have to fix this here
                 sal_Int32 nValue = 0;
-                aTarget >>= nValue;
-                aTarget <<= (sal_Int16)nValue;
+                if (aTarget >>= nValue)
+                {
+                    aTarget <<= static_cast<sal_Int16>(nValue);
+                }
             }
 
             // check for needed metric translation
diff --git a/sw/source/filter/xml/xmlimpit.cxx b/sw/source/filter/xml/xmlimpit.cxx
index 500b456..b695f72 100644
--- a/sw/source/filter/xml/xmlimpit.cxx
+++ b/sw/source/filter/xml/xmlimpit.cxx
@@ -786,6 +786,9 @@ bool SvXMLImportItemMapper::PutXMLValue(
                 sal_Int32 nVal;
                 bOk = ::sax::Converter::convertNumber(
                         nVal, rValue, 0, USHRT_MAX);
+                // i#114163 tdf#77111: OOo < 3.3 had a bug where it wrote
+                // "auto" as "0" for tables - now that we support a real offset
+                //  0, this fake "0" MUST NOT be imported as offset 0!
                 if( bOk && nVal > 0 )
                     rPageDesc.SetNumOffset( (sal_uInt16)nVal );
             }


More information about the Libreoffice-commits mailing list