summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2017-02-27 22:13:32 +0100
committerMichael Stahl <mstahl@redhat.com>2017-02-28 11:01:19 +0100
commite7f463cea58fc87e114008a726b4ea7489f36aa9 (patch)
tree0f230c43e351df55ee4a59425eebf0a24fda7d83 /sw
parente7729f458409f7fef2b7dab752205e3b230acb65 (diff)
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
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/odfexport/data/ooo321_stylepagenumber.odtbin0 -> 8558 bytes
-rw-r--r--sw/qa/extras/odfexport/odfexport.cxx31
-rw-r--r--sw/source/core/unocore/unoparagraph.cxx6
-rw-r--r--sw/source/core/unocore/unostyle.cxx6
-rw-r--r--sw/source/filter/xml/xmlimpit.cxx3
5 files changed, 42 insertions, 4 deletions
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 000000000000..aae70e1063c5
--- /dev/null
+++ b/sw/qa/extras/odfexport/data/ooo321_stylepagenumber.odt
Binary files differ
diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx
index 43aee578696c..3354ce2ad0c0 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 c0dc4ae01677..de1042970cce 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 6e2c9e009903..54eca80fa57f 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 500b4564c954..b695f721786c 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 );
}