diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-09-20 14:30:39 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-09-20 15:49:36 +0200 |
commit | 78afe29f3d56e589be4e0d25573eef32377548eb (patch) | |
tree | daf2795617e95fd4226ba216494df4b683f6d019 /sw | |
parent | e4fe4a2918fbca0dc38441261a0f890720538639 (diff) |
move some test from odfexport to odfexport2
to trim the long run time of odfexport
Change-Id: Ib2c2f13796ecea14a3aede51442005c08487c128
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140240
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/odfexport/odfexport.cxx | 490 | ||||
-rw-r--r-- | sw/qa/extras/odfexport/odfexport2.cxx | 506 |
2 files changed, 506 insertions, 490 deletions
diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx index fb3aa5e3412b..9c723e240380 100644 --- a/sw/qa/extras/odfexport/odfexport.cxx +++ b/sw/qa/extras/odfexport/odfexport.cxx @@ -2741,496 +2741,6 @@ CPPUNIT_TEST_FIXTURE(Test, testImageMimetype) assertXPath(pXmlDoc, "/office:document-content/office:body/office:text/text:p/draw:frame/draw:image[@draw:mime-type='image/svg+xml']"); } -CPPUNIT_TEST_FIXTURE(Test, testEmbeddedFontProps) -{ - loadAndReload("embedded-font-props.odt"); - CPPUNIT_ASSERT_EQUAL(1, getPages()); -#if !defined(MACOSX) - // Test that font style/weight of embedded fonts is exposed. - // Test file is a normal ODT, except EmbedFonts is set to true in settings.xml. - xmlDocUniquePtr pXmlDoc = parseExport("content.xml"); - // These failed, the attributes were missing. - assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[1]", "font-style", "normal"); - assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[1]", "font-weight", "normal"); - assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[2]", "font-style", "normal"); - assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[2]", "font-weight", "bold"); - assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[3]", "font-style", "italic"); - assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[3]", "font-weight", "normal"); - assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[4]", "font-style", "italic"); - assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[4]", "font-weight", "bold"); -#endif -} - -DECLARE_ODFEXPORT_TEST(testTdf100492, "tdf100492.odt") -{ - CPPUNIT_ASSERT_EQUAL(2, getShapes()); - CPPUNIT_ASSERT_EQUAL(1, getPages()); - uno::Reference<drawing::XShape> xShape = getShape(1); - CPPUNIT_ASSERT(xShape.is()); - - // Save the first shape to a SVG - uno::Reference<drawing::XGraphicExportFilter> xGraphicExporter = drawing::GraphicExportFilter::create(comphelper::getProcessComponentContext()); - uno::Reference<lang::XComponent> xSourceDoc(xShape, uno::UNO_QUERY); - xGraphicExporter->setSourceDocument(xSourceDoc); - - SvMemoryStream aStream; - uno::Reference<io::XOutputStream> xOutputStream(new utl::OStreamWrapper(aStream)); - uno::Sequence<beans::PropertyValue> aDescriptor( comphelper::InitPropertySequence({ - { "OutputStream", uno::Any(xOutputStream) }, - { "FilterName", uno::Any(OUString("SVG")) } - })); - xGraphicExporter->filter(aDescriptor); - aStream.Seek(STREAM_SEEK_TO_BEGIN); - - // TODO: Disabled. Parsing of SVG gives just root node without any children. - // Reason of such behavior unclear. So XPATH assert fails. - - // Parse resulting SVG as XML file. - // xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); - - // Check amount of paths required to draw an arrow. - // Since there are still some empty paths in output test can fail later. There are just two - // really used and visible paths. - //assertXPath(pXmlDoc, "/svg/path", 4); -} - -DECLARE_ODFEXPORT_TEST(testTdf77961, "tdf77961.odt") -{ - CPPUNIT_ASSERT_EQUAL(1, getPages()); - uno::Reference<container::XNameAccess> xStyles(getStyles("PageStyles")); - uno::Reference<beans::XPropertySet> xStyle(xStyles->getByName("Standard"), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL( false , getProperty<bool>(xStyle, "GridDisplay")); - CPPUNIT_ASSERT_EQUAL( false , getProperty<bool>(xStyle, "GridPrint")); -} - -DECLARE_ODFEXPORT_TEST(testReferenceLanguage, "referencelanguage.odt") -{ - CPPUNIT_ASSERT_EQUAL(2, getPages()); - // Test loext:reference-language attribute of reference fields - // (used from LibreOffice 6.1, and proposed for next ODF) - OUString const aFieldTexts[] = { "A 2", "Az Isten", "Az 50-esek", - "A 2018-asok", "Az egyebek", "A fejezetek", - u"Az „Őseinket...”", "a 2", - "Az v", "az 1", "Az e)", "az 1", - "Az (5)", "az 1", "A 2", "az 1" }; - uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); - // update "A (4)" to "Az (5)" - uno::Reference<util::XRefreshable>(xTextFieldsSupplier->getTextFields(), uno::UNO_QUERY_THROW)->refresh(); - - uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); - uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); - - uno::Any aHu(OUString("Hu")); - uno::Any ahu(OUString("hu")); - for (size_t i = 0; i < SAL_N_ELEMENTS(aFieldTexts); i++) - { - uno::Any aField = xFields->nextElement(); - uno::Reference<lang::XServiceInfo> xServiceInfo(aField, uno::UNO_QUERY); - if (xServiceInfo->supportsService("com.sun.star.text.textfield.GetReference")) - { - uno::Reference<beans::XPropertySet> xPropertySet(aField, uno::UNO_QUERY); - uno::Any aLang = xPropertySet->getPropertyValue("ReferenceFieldLanguage"); - CPPUNIT_ASSERT_EQUAL(true, aLang == aHu || aLang == ahu); - uno::Reference<text::XTextContent> xField(aField, uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(aFieldTexts[i], xField->getAnchor()->getString()); - } - } -} - -CPPUNIT_TEST_FIXTURE(Test, testRubyPosition) -{ - loadAndReload("ruby-position.odt"); - CPPUNIT_ASSERT_EQUAL(1, getPages()); - xmlDocUniquePtr pXmlDoc = parseExport("content.xml"); - - assertXPath(pXmlDoc, "//style:style[@style:family='ruby']/style:ruby-properties[@loext:ruby-position='inter-character']", 1); - assertXPath(pXmlDoc, "//style:style[@style:family='ruby']/style:ruby-properties[@style:ruby-position='below']", 1); -} - -DECLARE_ODFEXPORT_TEST(testAllowOverlap, "allow-overlap.odt") -{ - CPPUNIT_ASSERT_EQUAL(2, getShapes()); - CPPUNIT_ASSERT_EQUAL(1, getPages()); - uno::Reference<drawing::XShape> xShape = getShape(1); - // Without the accompanying fix in place, this test would have failed with: - // - Expression: !getProperty<bool>(xShape, "AllowOverlap") - // i.e. the custom AllowOverlap=false shape property was lost on import/export. - CPPUNIT_ASSERT(!getProperty<bool>(xShape, "AllowOverlap")); - xShape = getShape(2); - CPPUNIT_ASSERT(!getProperty<bool>(xShape, "AllowOverlap")); -} - -CPPUNIT_TEST_FIXTURE(Test, testSignatureLineProperties) -{ - loadAndReload("signatureline-properties.fodt"); - uno::Reference<drawing::XShape> xShape = getShape(1); - CPPUNIT_ASSERT(xShape.is()); - - CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xShape, "IsSignatureLine")); - CPPUNIT_ASSERT_EQUAL(OUString("{3C24159B-3B98-4F60-AB52-00E7721758E9}"), - getProperty<OUString>(xShape, "SignatureLineId")); - CPPUNIT_ASSERT_EQUAL(OUString("John Doe"), - getProperty<OUString>(xShape, "SignatureLineSuggestedSignerName")); - CPPUNIT_ASSERT_EQUAL(OUString("Farmer"), - getProperty<OUString>(xShape, "SignatureLineSuggestedSignerTitle")); - CPPUNIT_ASSERT_EQUAL(OUString("john@farmers.org"), - getProperty<OUString>(xShape, "SignatureLineSuggestedSignerEmail")); - CPPUNIT_ASSERT_EQUAL(OUString("Please farm here."), - getProperty<OUString>(xShape, "SignatureLineSigningInstructions")); - CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xShape, "SignatureLineCanAddComment")); - CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xShape, "SignatureLineShowSignDate")); - - // tdf#130917 This needs to be always set when importing a doc, ooxml export expects it. - uno::Reference<graphic::XGraphic> xUnsignedGraphic; - uno::Reference<beans::XPropertySet> xProps(xShape, uno::UNO_QUERY); - xProps->getPropertyValue("SignatureLineUnsignedImage") >>= xUnsignedGraphic; - CPPUNIT_ASSERT_EQUAL(true, xUnsignedGraphic.is()); -} - -DECLARE_ODFEXPORT_TEST(testQrCodeGenProperties, "qrcode-properties.odt") -{ - CPPUNIT_ASSERT_EQUAL(1, getShapes()); - CPPUNIT_ASSERT_EQUAL(1, getPages()); - uno::Reference<drawing::XShape> xShape = getShape(1); - CPPUNIT_ASSERT(xShape.is()); - - css::drawing::BarCode aBarCode = getProperty<css::drawing::BarCode>(xShape, "BarCodeProperties"); - - CPPUNIT_ASSERT_EQUAL(OUString("www.libreoffice.org"), - aBarCode.Payload); - CPPUNIT_ASSERT_EQUAL(css::drawing::BarCodeErrorCorrection::LOW, - aBarCode.ErrorCorrection); - CPPUNIT_ASSERT_EQUAL(sal_Int32(5), - aBarCode.Border); -} - -DECLARE_ODFEXPORT_TEST(testChapterNumberingNewLine, "chapter-number-new-line.odt") -{ - CPPUNIT_ASSERT_EQUAL(1, getPages()); - uno::Reference<text::XChapterNumberingSupplier> xNumberingSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xNumberingRules = xNumberingSupplier->getChapterNumberingRules(); - comphelper::SequenceAsHashMap hashMap(xNumberingRules->getByIndex(0)); - - //This failed Actual Value was LISTTAB instead of NEWLINE - CPPUNIT_ASSERT_EQUAL( - sal_Int16(SvxNumberFormat::NEWLINE), hashMap["LabelFollowedBy"].get<sal_Int16>()); -} - -DECLARE_ODFEXPORT_TEST(testSpellOutNumberingTypes, "spellout-numberingtypes.odt") -{ - CPPUNIT_ASSERT_EQUAL(1, getPages()); - // ordinal indicator, ordinal and cardinal number numbering styles (from LibreOffice 6.1) - OUString const aFieldTexts[] = { "1st", "Erste", "Eins", "1.", "Premier", "Un", u"1ᵉʳ", "First", "One" }; - // fallback for old platforms without std::codecvt and std::regex supports - OUString const aFieldTextFallbacks[] = { "Ordinal-number 1", "Ordinal 1", "1" }; - uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); - // update text field content - uno::Reference<util::XRefreshable>(xTextFieldsSupplier->getTextFields(), uno::UNO_QUERY_THROW)->refresh(); - - uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); - uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); - - for (size_t i = 0; i < SAL_N_ELEMENTS(aFieldTexts); i++) - { - uno::Any aField = xFields->nextElement(); - uno::Reference<lang::XServiceInfo> xServiceInfo(aField, uno::UNO_QUERY); - if (xServiceInfo->supportsService("com.sun.star.text.textfield.PageNumber")) - { - uno::Reference<text::XTextContent> xField(aField, uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(true, aFieldTexts[i].equals(xField->getAnchor()->getString()) || - aFieldTextFallbacks[i%3].equals(xField->getAnchor()->getString())); - } - } -} - -// MAILMERGE Add conditional to expand / collapse bookmarks -DECLARE_ODFEXPORT_TEST(tdf101856_overlapped, "tdf101856_overlapped.odt") -{ - CPPUNIT_ASSERT_EQUAL(1, getPages()); - // get bookmark interface - uno::Reference<text::XBookmarksSupplier> xBookmarksSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xBookmarksByIdx(xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY); - uno::Reference<container::XNameAccess> xBookmarksByName = xBookmarksSupplier->getBookmarks(); - - // check: we have 2 bookmarks - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xBookmarksByIdx->getCount()); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("BookmarkNonHidden")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("BookmarkHidden")); - - // <text:bookmark-start text:name="BookmarkNonHidden"/> - uno::Reference<beans::XPropertySet> xBookmark1(xBookmarksByName->getByName("BookmarkNonHidden"), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(xBookmark1, UNO_NAME_BOOKMARK_CONDITION)); - CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(xBookmark1, UNO_NAME_BOOKMARK_HIDDEN)); - - // <text:bookmark-start text:name="BookmarkHidden"/> - uno::Reference<beans::XPropertySet> xBookmark2(xBookmarksByName->getByName("BookmarkHidden"), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(xBookmark2, UNO_NAME_BOOKMARK_CONDITION)); - CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xBookmark2, UNO_NAME_BOOKMARK_HIDDEN)); -} - -// MAILMERGE Add conditional to expand / collapse bookmarks -DECLARE_ODFEXPORT_TEST(tdf101856, "tdf101856.odt") -{ - CPPUNIT_ASSERT_EQUAL(1, getPages()); - // get bookmark interface - uno::Reference<text::XBookmarksSupplier> xBookmarksSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xBookmarksByIdx(xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY); - uno::Reference<container::XNameAccess> xBookmarksByName = xBookmarksSupplier->getBookmarks(); - - // check: we have 2 bookmarks - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(5), xBookmarksByIdx->getCount()); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("BookmarkVisible")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("BookmarkHidden")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("BookmarkVisibleWithCondition")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("BookmarkNotHiddenWithCondition")); - CPPUNIT_ASSERT(xBookmarksByName->hasByName("BookmarkHiddenWithCondition")); - - // <text:bookmark-start text:name="BookmarkVisible"/> - uno::Reference<beans::XPropertySet> xBookmark1(xBookmarksByName->getByName("BookmarkVisible"), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(xBookmark1, UNO_NAME_BOOKMARK_CONDITION)); - CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(xBookmark1, UNO_NAME_BOOKMARK_HIDDEN)); - - // <text:bookmark-start text:name="BookmarkHidden" loext:condition="" loext:hidden="true"/> - uno::Reference<beans::XPropertySet> xBookmark2(xBookmarksByName->getByName("BookmarkHidden"), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(xBookmark2, UNO_NAME_BOOKMARK_CONDITION)); - CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xBookmark2, UNO_NAME_BOOKMARK_HIDDEN)); - - // <text:bookmark-start text:name="BookmarkVisibleWithCondition" loext:condition="0==1" loext:hidden="true"/> - uno::Reference<beans::XPropertySet> xBookmark3(xBookmarksByName->getByName("BookmarkVisibleWithCondition"), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("0==1"), getProperty<OUString>(xBookmark3, UNO_NAME_BOOKMARK_CONDITION)); - CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xBookmark3, UNO_NAME_BOOKMARK_HIDDEN)); - - // <text:bookmark-start text:name="BookmarkNotHiddenWithCondition" loext:condition="1==1" loext:hidden="false"/> - // - // The following test doesn't work, while during output in the case of loext:hidden="false". - // no additional parameters are written. Implementation should be reviewed. - // -// uno::Reference<beans::XPropertySet> xBookmark4(xBookmarksByName->getByName("BookmarkNotHiddenWithCondition"), uno::UNO_QUERY); -// CPPUNIT_ASSERT_EQUAL(OUString("1==1"), getProperty<OUString>(xBookmark4, UNO_NAME_BOOKMARK_CONDITION)); -// CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(xBookmark4, UNO_NAME_BOOKMARK_HIDDEN)); - - // <text:bookmark-start text:name="BookmarkHiddenWithCondition" loext:condition="1==1" loext:hidden="true"/> - uno::Reference<beans::XPropertySet> xBookmark5(xBookmarksByName->getByName("BookmarkHiddenWithCondition"), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("1==1"), getProperty<OUString>(xBookmark5, UNO_NAME_BOOKMARK_CONDITION)); - CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xBookmark5, UNO_NAME_BOOKMARK_HIDDEN)); -} - -DECLARE_ODFEXPORT_TEST(tdf118502, "tdf118502.odt") -{ - CPPUNIT_ASSERT_EQUAL(1, getShapes()); - CPPUNIT_ASSERT_EQUAL(1, getPages()); - uno::Reference<drawing::XShape> xShape = getShape(1); - // Make sure the replacement graphic is still there - // (was gone because the original graphic was not recognized during load) - auto xReplacementGraphic - = getProperty<uno::Reference<graphic::XGraphic>>(xShape, "ReplacementGraphic"); - CPPUNIT_ASSERT(xReplacementGraphic.is()); -} - -CPPUNIT_TEST_FIXTURE(Test, tdf99631) -{ - loadAndReload("tdf99631.docx"); - // check import of VisualArea settings of the embedded XLSX OLE objects - xmlDocUniquePtr pXmlDoc = parseExport("Object 1/settings.xml"); - assertXPathContent(pXmlDoc, "//config:config-item[@config:name='VisibleAreaWidth']", "4516"); - assertXPathContent(pXmlDoc, "//config:config-item[@config:name='VisibleAreaHeight']", "903"); - - xmlDocUniquePtr pXmlDoc2 = parseExport("Object 2/settings.xml"); - assertXPathContent(pXmlDoc2, "//config:config-item[@config:name='VisibleAreaWidth']", "4516"); - assertXPathContent(pXmlDoc2, "//config:config-item[@config:name='VisibleAreaHeight']", "1355"); -} - -CPPUNIT_TEST_FIXTURE(Test, tdf128504) -{ - loadAndReload("tdf128504.docx"); - uno::Reference<text::XTextRange> xPara = getParagraph(6); - uno::Reference<beans::XPropertySet> xRun(getRun(xPara,1), uno::UNO_QUERY); - OUString unVisitedStyleName = getProperty<OUString>(xRun, "UnvisitedCharStyleName"); - CPPUNIT_ASSERT(!unVisitedStyleName.equalsIgnoreAsciiCase("Internet Link")); - OUString visitedStyleName = getProperty<OUString>(xRun, "VisitedCharStyleName"); - CPPUNIT_ASSERT(!visitedStyleName.equalsIgnoreAsciiCase("Visited Internet Link")); -} - -DECLARE_ODFEXPORT_TEST(tdf121658, "tdf121658.odt") -{ - CPPUNIT_ASSERT_EQUAL(1, getPages()); - uno::Reference<container::XNameAccess> xParaStyles(getStyles("ParagraphStyles")); - uno::Reference<beans::XPropertySet> xStyle1(xParaStyles->getByName( - "Standard"), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xStyle1, "ParaHyphenationNoCaps")); -} - -DECLARE_ODFEXPORT_TEST(tdf149248, "tdf149248.odt") -{ - CPPUNIT_ASSERT_EQUAL(1, getPages()); - CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(getParagraph(2), "ParaHyphenationNoLastWord")); - CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(getParagraph(4), "ParaHyphenationNoLastWord")); -} - -DECLARE_ODFEXPORT_TEST(testTdf150394, "tdf150394.odt") -{ - // crashes at import time - CPPUNIT_ASSERT_EQUAL(1, getPages()); -} - -DECLARE_ODFEXPORT_TEST(tdf149324, "tdf149324.odt") -{ - CPPUNIT_ASSERT_EQUAL(1, getPages()); - CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), getProperty<sal_uInt16>(getParagraph(2), "ParaHyphenationMinWordLength")); - CPPUNIT_ASSERT_EQUAL(sal_uInt16(7), getProperty<sal_uInt16>(getParagraph(4), "ParaHyphenationMinWordLength")); -} - -DECLARE_ODFEXPORT_TEST(tdf149420, "tdf149420.odt") -{ - CPPUNIT_ASSERT_EQUAL(1, getPages()); - CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), getProperty<sal_uInt16>(getParagraph(2), "ParaHyphenationZone")); - CPPUNIT_ASSERT_EQUAL(sal_uInt16(567), getProperty<sal_uInt16>(getParagraph(4), "ParaHyphenationZone")); -} - -DECLARE_ODFEXPORT_TEST(testArabicZeroNumbering, "arabic-zero-numbering.odt") -{ - CPPUNIT_ASSERT_EQUAL(1, getPages()); - auto xNumberingRules - = getProperty<uno::Reference<container::XIndexAccess>>(getParagraph(1), "NumberingRules"); - comphelper::SequenceAsHashMap aMap(xNumberingRules->getByIndex(0)); - // Without the accompanying fix in place, this test would have failed with: - // - Expected: 64 - // - Actual : 4 - // i.e. numbering type was ARABIC, not ARABIC_ZERO. - CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(style::NumberingType::ARABIC_ZERO), - aMap["NumberingType"].get<sal_uInt16>()); -} - -DECLARE_ODFEXPORT_TEST(testArabicZero3Numbering, "arabic-zero3-numbering.odt") -{ - CPPUNIT_ASSERT_EQUAL(1, getPages()); - auto xNumberingRules - = getProperty<uno::Reference<container::XIndexAccess>>(getParagraph(1), "NumberingRules"); - comphelper::SequenceAsHashMap aMap(xNumberingRules->getByIndex(0)); - // Without the accompanying fix in place, this test would have failed with: - // - Expected: 65 - // - Actual : 4 - // i.e. numbering type was ARABIC, not ARABIC_ZERO3. - CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(style::NumberingType::ARABIC_ZERO3), - aMap["NumberingType"].get<sal_uInt16>()); -} - -DECLARE_ODFEXPORT_TEST(testArabicZero4Numbering, "arabic-zero4-numbering.odt") -{ - CPPUNIT_ASSERT_EQUAL(1, getPages()); - auto xNumberingRules - = getProperty<uno::Reference<container::XIndexAccess>>(getParagraph(1), "NumberingRules"); - comphelper::SequenceAsHashMap aMap(xNumberingRules->getByIndex(0)); - // Without the accompanying fix in place, this test would have failed with: - // - Expected: 66 - // - Actual : 4 - // i.e. numbering type was ARABIC, not ARABIC_ZERO4. - CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(style::NumberingType::ARABIC_ZERO4), - aMap["NumberingType"].get<sal_uInt16>()); -} - -DECLARE_ODFEXPORT_TEST(testArabicZero5Numbering, "arabic-zero5-numbering.odt") -{ - CPPUNIT_ASSERT_EQUAL(1, getPages()); - auto xNumberingRules - = getProperty<uno::Reference<container::XIndexAccess>>(getParagraph(1), "NumberingRules"); - comphelper::SequenceAsHashMap aMap(xNumberingRules->getByIndex(0)); - // Without the accompanying fix in place, this test would have failed with: - // - Expected: 67 - // - Actual : 4 - // i.e. numbering type was ARABIC, not ARABIC_ZERO5. - CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(style::NumberingType::ARABIC_ZERO5), - aMap["NumberingType"].get<sal_uInt16>()); -} - -DECLARE_ODFEXPORT_TEST(testRovasNumbering, "rovas-numbering.odt") -{ - CPPUNIT_ASSERT_EQUAL(1, getPages()); - auto xNumberingRules - = getProperty<uno::Reference<container::XIndexAccess>>(getParagraph(1), "NumberingRules"); - comphelper::SequenceAsHashMap aMap(xNumberingRules->getByIndex(0)); - // Without the accompanying fix in place, this test would have failed with: - // - Expected: 68 - // - Actual : 4 - // i.e. numbering type was ARABIC, not SZEKELY_ROVAS. - CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(style::NumberingType::SZEKELY_ROVAS), - aMap["NumberingType"].get<sal_uInt16>()); -} - -DECLARE_ODFEXPORT_TEST(testPageContentTop, "page-content-top.odt") -{ - CPPUNIT_ASSERT_EQUAL(1, getShapes()); - CPPUNIT_ASSERT_EQUAL(1, getPages()); - uno::Reference<beans::XPropertySet> xShape(getShape(1), uno::UNO_QUERY); - sal_Int16 nExpected = text::RelOrientation::PAGE_PRINT_AREA_TOP; - CPPUNIT_ASSERT_EQUAL(nExpected, getProperty<sal_Int16>(xShape, "VertOrientRelation")); -} - -DECLARE_ODFEXPORT_TEST(testPageContentBottom, "page-content-bottom.odt") -{ - CPPUNIT_ASSERT_EQUAL(1, getShapes()); - CPPUNIT_ASSERT_EQUAL(1, getPages()); - uno::Reference<beans::XPropertySet> xShape(getShape(1), uno::UNO_QUERY); - sal_Int16 nExpected = text::RelOrientation::PAGE_PRINT_AREA_BOTTOM; - CPPUNIT_ASSERT_EQUAL(nExpected, getProperty<sal_Int16>(xShape, "VertOrientRelation")); -} - -CPPUNIT_TEST_FIXTURE(Test, tdf124470) -{ - loadAndReload("tdf124470TableAndEmbeddedUsedFonts.odt"); - // Table styles were exported out of place, inside font-face-decls. - // Without the fix in place, this will fail already in ODF validation: - // "content.xml[2,2150]: Error: tag name "style:style" is not allowed. Possible tag names are: <font-face>" - - CPPUNIT_ASSERT_EQUAL(1, getPages()); - - xmlDocUniquePtr pXmlDoc = parseExport("content.xml"); - - assertXPath(pXmlDoc, "/office:document-content/office:font-face-decls/style:style", 0); - assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/style:style[@style:family='table']", 1); - assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/style:style[@style:family='table-column']", 2); - assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/style:style[@style:family='paragraph']", 1); -} - -CPPUNIT_TEST_FIXTURE(Test, tdf135942) -{ - loadAndReload("nestedTableInFooter.odt"); - // All table autostyles should be collected, including nested, and must not crash. - - CPPUNIT_ASSERT_EQUAL(1, getPages()); - - xmlDocUniquePtr pXmlDoc = parseExport("styles.xml"); - - assertXPath(pXmlDoc, "/office:document-styles/office:automatic-styles/style:style[@style:family='table']", 2); -} - -CPPUNIT_TEST_FIXTURE(Test, tdf150927) -{ - // Similar to tdf135942 - - loadAndReload("table-in-frame-in-table-in-header-base.odt"); - // All table autostyles should be collected, including nested, and must not crash. - - CPPUNIT_ASSERT_EQUAL(1, getPages()); - - xmlDocUniquePtr pXmlDoc = parseExport("styles.xml"); - - assertXPath(pXmlDoc, "/office:document-styles/office:automatic-styles/style:style[@style:family='table']", 2); -} - -DECLARE_ODFEXPORT_TEST(testGutterLeft, "gutter-left.odt") -{ - CPPUNIT_ASSERT_EQUAL(1, getPages()); - uno::Reference<beans::XPropertySet> xPageStyle; - getStyles("PageStyles")->getByName("Standard") >>= xPageStyle; - sal_Int32 nGutterMargin{}; - xPageStyle->getPropertyValue("GutterMargin") >>= nGutterMargin; - // Without the accompanying fix in place, this test would have failed with: - // - Expected: 1270 - // - Actual : 0 - // i.e. gutter margin was lost. - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1270), nGutterMargin); -} CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/extras/odfexport/odfexport2.cxx b/sw/qa/extras/odfexport/odfexport2.cxx index 018f7afd0cb6..d51bc245a4c3 100644 --- a/sw/qa/extras/odfexport/odfexport2.cxx +++ b/sw/qa/extras/odfexport/odfexport2.cxx @@ -9,12 +9,27 @@ #include <swmodeltestbase.hxx> +#include <com/sun/star/drawing/BarCode.hpp> +#include <com/sun/star/drawing/BarCodeErrorCorrection.hpp> +#include <com/sun/star/drawing/GraphicExportFilter.hpp> +#include <com/sun/star/drawing/XGraphicExportFilter.hpp> +#include <com/sun/star/io/XOutputStream.hpp> #include <com/sun/star/style/VerticalAlignment.hpp> #include <com/sun/star/text/ColumnSeparatorStyle.hpp> +#include <com/sun/star/text/XBookmarksSupplier.hpp> +#include <com/sun/star/text/XChapterNumberingSupplier.hpp> #include <com/sun/star/text/XTextColumns.hpp> +#include <com/sun/star/text/XTextFieldsSupplier.hpp> #include <com/sun/star/text/XTextTable.hpp> #include <com/sun/star/text/XTextTablesSupplier.hpp> +#include <com/sun/star/util/XRefreshable.hpp> #include <unotools/localedatawrapper.hxx> +#include <unotools/streamwrap.hxx> +#include <comphelper/processfactory.hxx> +#include <comphelper/propertysequence.hxx> +#include <comphelper/sequenceashashmap.hxx> +#include <unoprnms.hxx> +#include <docsh.hxx> class Test : public SwModelTestBase { @@ -28,6 +43,497 @@ public: }; +CPPUNIT_TEST_FIXTURE(Test, testEmbeddedFontProps) +{ + loadAndReload("embedded-font-props.odt"); + CPPUNIT_ASSERT_EQUAL(1, getPages()); +#if !defined(MACOSX) + // Test that font style/weight of embedded fonts is exposed. + // Test file is a normal ODT, except EmbedFonts is set to true in settings.xml. + xmlDocUniquePtr pXmlDoc = parseExport("content.xml"); + // These failed, the attributes were missing. + assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[1]", "font-style", "normal"); + assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[1]", "font-weight", "normal"); + assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[2]", "font-style", "normal"); + assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[2]", "font-weight", "bold"); + assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[3]", "font-style", "italic"); + assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[3]", "font-weight", "normal"); + assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[4]", "font-style", "italic"); + assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[4]", "font-weight", "bold"); +#endif +} + +DECLARE_ODFEXPORT_TEST(testTdf100492, "tdf100492.odt") +{ + CPPUNIT_ASSERT_EQUAL(2, getShapes()); + CPPUNIT_ASSERT_EQUAL(1, getPages()); + uno::Reference<drawing::XShape> xShape = getShape(1); + CPPUNIT_ASSERT(xShape.is()); + + // Save the first shape to a SVG + uno::Reference<drawing::XGraphicExportFilter> xGraphicExporter = drawing::GraphicExportFilter::create(comphelper::getProcessComponentContext()); + uno::Reference<lang::XComponent> xSourceDoc(xShape, uno::UNO_QUERY); + xGraphicExporter->setSourceDocument(xSourceDoc); + + SvMemoryStream aStream; + uno::Reference<io::XOutputStream> xOutputStream(new utl::OStreamWrapper(aStream)); + uno::Sequence<beans::PropertyValue> aDescriptor( comphelper::InitPropertySequence({ + { "OutputStream", uno::Any(xOutputStream) }, + { "FilterName", uno::Any(OUString("SVG")) } + })); + xGraphicExporter->filter(aDescriptor); + aStream.Seek(STREAM_SEEK_TO_BEGIN); + + // TODO: Disabled. Parsing of SVG gives just root node without any children. + // Reason of such behavior unclear. So XPATH assert fails. + + // Parse resulting SVG as XML file. + // xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); + + // Check amount of paths required to draw an arrow. + // Since there are still some empty paths in output test can fail later. There are just two + // really used and visible paths. + //assertXPath(pXmlDoc, "/svg/path", 4); +} + +DECLARE_ODFEXPORT_TEST(testTdf77961, "tdf77961.odt") +{ + CPPUNIT_ASSERT_EQUAL(1, getPages()); + uno::Reference<container::XNameAccess> xStyles(getStyles("PageStyles")); + uno::Reference<beans::XPropertySet> xStyle(xStyles->getByName("Standard"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL( false , getProperty<bool>(xStyle, "GridDisplay")); + CPPUNIT_ASSERT_EQUAL( false , getProperty<bool>(xStyle, "GridPrint")); +} + +DECLARE_ODFEXPORT_TEST(testReferenceLanguage, "referencelanguage.odt") +{ + CPPUNIT_ASSERT_EQUAL(2, getPages()); + // Test loext:reference-language attribute of reference fields + // (used from LibreOffice 6.1, and proposed for next ODF) + OUString const aFieldTexts[] = { "A 2", "Az Isten", "Az 50-esek", + "A 2018-asok", "Az egyebek", "A fejezetek", + u"Az „Őseinket...”", "a 2", + "Az v", "az 1", "Az e)", "az 1", + "Az (5)", "az 1", "A 2", "az 1" }; + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + // update "A (4)" to "Az (5)" + uno::Reference<util::XRefreshable>(xTextFieldsSupplier->getTextFields(), uno::UNO_QUERY_THROW)->refresh(); + + uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + + uno::Any aHu(OUString("Hu")); + uno::Any ahu(OUString("hu")); + for (size_t i = 0; i < SAL_N_ELEMENTS(aFieldTexts); i++) + { + uno::Any aField = xFields->nextElement(); + uno::Reference<lang::XServiceInfo> xServiceInfo(aField, uno::UNO_QUERY); + if (xServiceInfo->supportsService("com.sun.star.text.textfield.GetReference")) + { + uno::Reference<beans::XPropertySet> xPropertySet(aField, uno::UNO_QUERY); + uno::Any aLang = xPropertySet->getPropertyValue("ReferenceFieldLanguage"); + CPPUNIT_ASSERT_EQUAL(true, aLang == aHu || aLang == ahu); + uno::Reference<text::XTextContent> xField(aField, uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(aFieldTexts[i], xField->getAnchor()->getString()); + } + } +} + +CPPUNIT_TEST_FIXTURE(Test, testRubyPosition) +{ + loadAndReload("ruby-position.odt"); + CPPUNIT_ASSERT_EQUAL(1, getPages()); + xmlDocUniquePtr pXmlDoc = parseExport("content.xml"); + + assertXPath(pXmlDoc, "//style:style[@style:family='ruby']/style:ruby-properties[@loext:ruby-position='inter-character']", 1); + assertXPath(pXmlDoc, "//style:style[@style:family='ruby']/style:ruby-properties[@style:ruby-position='below']", 1); +} + +DECLARE_ODFEXPORT_TEST(testAllowOverlap, "allow-overlap.odt") +{ + CPPUNIT_ASSERT_EQUAL(2, getShapes()); + CPPUNIT_ASSERT_EQUAL(1, getPages()); + uno::Reference<drawing::XShape> xShape = getShape(1); + // Without the accompanying fix in place, this test would have failed with: + // - Expression: !getProperty<bool>(xShape, "AllowOverlap") + // i.e. the custom AllowOverlap=false shape property was lost on import/export. + CPPUNIT_ASSERT(!getProperty<bool>(xShape, "AllowOverlap")); + xShape = getShape(2); + CPPUNIT_ASSERT(!getProperty<bool>(xShape, "AllowOverlap")); +} + +CPPUNIT_TEST_FIXTURE(Test, testSignatureLineProperties) +{ + loadAndReload("signatureline-properties.fodt"); + uno::Reference<drawing::XShape> xShape = getShape(1); + CPPUNIT_ASSERT(xShape.is()); + + CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xShape, "IsSignatureLine")); + CPPUNIT_ASSERT_EQUAL(OUString("{3C24159B-3B98-4F60-AB52-00E7721758E9}"), + getProperty<OUString>(xShape, "SignatureLineId")); + CPPUNIT_ASSERT_EQUAL(OUString("John Doe"), + getProperty<OUString>(xShape, "SignatureLineSuggestedSignerName")); + CPPUNIT_ASSERT_EQUAL(OUString("Farmer"), + getProperty<OUString>(xShape, "SignatureLineSuggestedSignerTitle")); + CPPUNIT_ASSERT_EQUAL(OUString("john@farmers.org"), + getProperty<OUString>(xShape, "SignatureLineSuggestedSignerEmail")); + CPPUNIT_ASSERT_EQUAL(OUString("Please farm here."), + getProperty<OUString>(xShape, "SignatureLineSigningInstructions")); + CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xShape, "SignatureLineCanAddComment")); + CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xShape, "SignatureLineShowSignDate")); + + // tdf#130917 This needs to be always set when importing a doc, ooxml export expects it. + uno::Reference<graphic::XGraphic> xUnsignedGraphic; + uno::Reference<beans::XPropertySet> xProps(xShape, uno::UNO_QUERY); + xProps->getPropertyValue("SignatureLineUnsignedImage") >>= xUnsignedGraphic; + CPPUNIT_ASSERT_EQUAL(true, xUnsignedGraphic.is()); +} + +DECLARE_ODFEXPORT_TEST(testQrCodeGenProperties, "qrcode-properties.odt") +{ + CPPUNIT_ASSERT_EQUAL(1, getShapes()); + CPPUNIT_ASSERT_EQUAL(1, getPages()); + uno::Reference<drawing::XShape> xShape = getShape(1); + CPPUNIT_ASSERT(xShape.is()); + + css::drawing::BarCode aBarCode = getProperty<css::drawing::BarCode>(xShape, "BarCodeProperties"); + + CPPUNIT_ASSERT_EQUAL(OUString("www.libreoffice.org"), + aBarCode.Payload); + CPPUNIT_ASSERT_EQUAL(css::drawing::BarCodeErrorCorrection::LOW, + aBarCode.ErrorCorrection); + CPPUNIT_ASSERT_EQUAL(sal_Int32(5), + aBarCode.Border); +} + +DECLARE_ODFEXPORT_TEST(testChapterNumberingNewLine, "chapter-number-new-line.odt") +{ + CPPUNIT_ASSERT_EQUAL(1, getPages()); + uno::Reference<text::XChapterNumberingSupplier> xNumberingSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xNumberingRules = xNumberingSupplier->getChapterNumberingRules(); + comphelper::SequenceAsHashMap hashMap(xNumberingRules->getByIndex(0)); + + //This failed Actual Value was LISTTAB instead of NEWLINE + CPPUNIT_ASSERT_EQUAL( + sal_Int16(SvxNumberFormat::NEWLINE), hashMap["LabelFollowedBy"].get<sal_Int16>()); +} + +DECLARE_ODFEXPORT_TEST(testSpellOutNumberingTypes, "spellout-numberingtypes.odt") +{ + CPPUNIT_ASSERT_EQUAL(1, getPages()); + // ordinal indicator, ordinal and cardinal number numbering styles (from LibreOffice 6.1) + OUString const aFieldTexts[] = { "1st", "Erste", "Eins", "1.", "Premier", "Un", u"1ᵉʳ", "First", "One" }; + // fallback for old platforms without std::codecvt and std::regex supports + OUString const aFieldTextFallbacks[] = { "Ordinal-number 1", "Ordinal 1", "1" }; + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + // update text field content + uno::Reference<util::XRefreshable>(xTextFieldsSupplier->getTextFields(), uno::UNO_QUERY_THROW)->refresh(); + + uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + + for (size_t i = 0; i < SAL_N_ELEMENTS(aFieldTexts); i++) + { + uno::Any aField = xFields->nextElement(); + uno::Reference<lang::XServiceInfo> xServiceInfo(aField, uno::UNO_QUERY); + if (xServiceInfo->supportsService("com.sun.star.text.textfield.PageNumber")) + { + uno::Reference<text::XTextContent> xField(aField, uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(true, aFieldTexts[i].equals(xField->getAnchor()->getString()) || + aFieldTextFallbacks[i%3].equals(xField->getAnchor()->getString())); + } + } +} + +// MAILMERGE Add conditional to expand / collapse bookmarks +DECLARE_ODFEXPORT_TEST(tdf101856_overlapped, "tdf101856_overlapped.odt") +{ + CPPUNIT_ASSERT_EQUAL(1, getPages()); + // get bookmark interface + uno::Reference<text::XBookmarksSupplier> xBookmarksSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xBookmarksByIdx(xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY); + uno::Reference<container::XNameAccess> xBookmarksByName = xBookmarksSupplier->getBookmarks(); + + // check: we have 2 bookmarks + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xBookmarksByIdx->getCount()); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("BookmarkNonHidden")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("BookmarkHidden")); + + // <text:bookmark-start text:name="BookmarkNonHidden"/> + uno::Reference<beans::XPropertySet> xBookmark1(xBookmarksByName->getByName("BookmarkNonHidden"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(xBookmark1, UNO_NAME_BOOKMARK_CONDITION)); + CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(xBookmark1, UNO_NAME_BOOKMARK_HIDDEN)); + + // <text:bookmark-start text:name="BookmarkHidden"/> + uno::Reference<beans::XPropertySet> xBookmark2(xBookmarksByName->getByName("BookmarkHidden"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(xBookmark2, UNO_NAME_BOOKMARK_CONDITION)); + CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xBookmark2, UNO_NAME_BOOKMARK_HIDDEN)); +} + +// MAILMERGE Add conditional to expand / collapse bookmarks +DECLARE_ODFEXPORT_TEST(tdf101856, "tdf101856.odt") +{ + CPPUNIT_ASSERT_EQUAL(1, getPages()); + // get bookmark interface + uno::Reference<text::XBookmarksSupplier> xBookmarksSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xBookmarksByIdx(xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY); + uno::Reference<container::XNameAccess> xBookmarksByName = xBookmarksSupplier->getBookmarks(); + + // check: we have 2 bookmarks + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(5), xBookmarksByIdx->getCount()); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("BookmarkVisible")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("BookmarkHidden")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("BookmarkVisibleWithCondition")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("BookmarkNotHiddenWithCondition")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("BookmarkHiddenWithCondition")); + + // <text:bookmark-start text:name="BookmarkVisible"/> + uno::Reference<beans::XPropertySet> xBookmark1(xBookmarksByName->getByName("BookmarkVisible"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(xBookmark1, UNO_NAME_BOOKMARK_CONDITION)); + CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(xBookmark1, UNO_NAME_BOOKMARK_HIDDEN)); + + // <text:bookmark-start text:name="BookmarkHidden" loext:condition="" loext:hidden="true"/> + uno::Reference<beans::XPropertySet> xBookmark2(xBookmarksByName->getByName("BookmarkHidden"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(xBookmark2, UNO_NAME_BOOKMARK_CONDITION)); + CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xBookmark2, UNO_NAME_BOOKMARK_HIDDEN)); + + // <text:bookmark-start text:name="BookmarkVisibleWithCondition" loext:condition="0==1" loext:hidden="true"/> + uno::Reference<beans::XPropertySet> xBookmark3(xBookmarksByName->getByName("BookmarkVisibleWithCondition"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("0==1"), getProperty<OUString>(xBookmark3, UNO_NAME_BOOKMARK_CONDITION)); + CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xBookmark3, UNO_NAME_BOOKMARK_HIDDEN)); + + // <text:bookmark-start text:name="BookmarkNotHiddenWithCondition" loext:condition="1==1" loext:hidden="false"/> + // + // The following test doesn't work, while during output in the case of loext:hidden="false". + // no additional parameters are written. Implementation should be reviewed. + // +// uno::Reference<beans::XPropertySet> xBookmark4(xBookmarksByName->getByName("BookmarkNotHiddenWithCondition"), uno::UNO_QUERY); +// CPPUNIT_ASSERT_EQUAL(OUString("1==1"), getProperty<OUString>(xBookmark4, UNO_NAME_BOOKMARK_CONDITION)); +// CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(xBookmark4, UNO_NAME_BOOKMARK_HIDDEN)); + + // <text:bookmark-start text:name="BookmarkHiddenWithCondition" loext:condition="1==1" loext:hidden="true"/> + uno::Reference<beans::XPropertySet> xBookmark5(xBookmarksByName->getByName("BookmarkHiddenWithCondition"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("1==1"), getProperty<OUString>(xBookmark5, UNO_NAME_BOOKMARK_CONDITION)); + CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xBookmark5, UNO_NAME_BOOKMARK_HIDDEN)); +} + +DECLARE_ODFEXPORT_TEST(tdf118502, "tdf118502.odt") +{ + CPPUNIT_ASSERT_EQUAL(1, getShapes()); + CPPUNIT_ASSERT_EQUAL(1, getPages()); + uno::Reference<drawing::XShape> xShape = getShape(1); + // Make sure the replacement graphic is still there + // (was gone because the original graphic was not recognized during load) + auto xReplacementGraphic + = getProperty<uno::Reference<graphic::XGraphic>>(xShape, "ReplacementGraphic"); + CPPUNIT_ASSERT(xReplacementGraphic.is()); +} + +CPPUNIT_TEST_FIXTURE(Test, tdf99631) +{ + loadAndReload("tdf99631.docx"); + // check import of VisualArea settings of the embedded XLSX OLE objects + xmlDocUniquePtr pXmlDoc = parseExport("Object 1/settings.xml"); + assertXPathContent(pXmlDoc, "//config:config-item[@config:name='VisibleAreaWidth']", "4516"); + assertXPathContent(pXmlDoc, "//config:config-item[@config:name='VisibleAreaHeight']", "903"); + + xmlDocUniquePtr pXmlDoc2 = parseExport("Object 2/settings.xml"); + assertXPathContent(pXmlDoc2, "//config:config-item[@config:name='VisibleAreaWidth']", "4516"); + assertXPathContent(pXmlDoc2, "//config:config-item[@config:name='VisibleAreaHeight']", "1355"); +} + +CPPUNIT_TEST_FIXTURE(Test, tdf128504) +{ + loadAndReload("tdf128504.docx"); + uno::Reference<text::XTextRange> xPara = getParagraph(6); + uno::Reference<beans::XPropertySet> xRun(getRun(xPara,1), uno::UNO_QUERY); + OUString unVisitedStyleName = getProperty<OUString>(xRun, "UnvisitedCharStyleName"); + CPPUNIT_ASSERT(!unVisitedStyleName.equalsIgnoreAsciiCase("Internet Link")); + OUString visitedStyleName = getProperty<OUString>(xRun, "VisitedCharStyleName"); + CPPUNIT_ASSERT(!visitedStyleName.equalsIgnoreAsciiCase("Visited Internet Link")); +} + +DECLARE_ODFEXPORT_TEST(tdf121658, "tdf121658.odt") +{ + CPPUNIT_ASSERT_EQUAL(1, getPages()); + uno::Reference<container::XNameAccess> xParaStyles(getStyles("ParagraphStyles")); + uno::Reference<beans::XPropertySet> xStyle1(xParaStyles->getByName( + "Standard"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xStyle1, "ParaHyphenationNoCaps")); +} + +DECLARE_ODFEXPORT_TEST(tdf149248, "tdf149248.odt") +{ + CPPUNIT_ASSERT_EQUAL(1, getPages()); + CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(getParagraph(2), "ParaHyphenationNoLastWord")); + CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(getParagraph(4), "ParaHyphenationNoLastWord")); +} + +DECLARE_ODFEXPORT_TEST(testTdf150394, "tdf150394.odt") +{ + // crashes at import time + CPPUNIT_ASSERT_EQUAL(1, getPages()); +} + +DECLARE_ODFEXPORT_TEST(tdf149324, "tdf149324.odt") +{ + CPPUNIT_ASSERT_EQUAL(1, getPages()); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), getProperty<sal_uInt16>(getParagraph(2), "ParaHyphenationMinWordLength")); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(7), getProperty<sal_uInt16>(getParagraph(4), "ParaHyphenationMinWordLength")); +} + +DECLARE_ODFEXPORT_TEST(tdf149420, "tdf149420.odt") +{ + CPPUNIT_ASSERT_EQUAL(1, getPages()); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), getProperty<sal_uInt16>(getParagraph(2), "ParaHyphenationZone")); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(567), getProperty<sal_uInt16>(getParagraph(4), "ParaHyphenationZone")); +} + +DECLARE_ODFEXPORT_TEST(testArabicZeroNumbering, "arabic-zero-numbering.odt") +{ + CPPUNIT_ASSERT_EQUAL(1, getPages()); + auto xNumberingRules + = getProperty<uno::Reference<container::XIndexAccess>>(getParagraph(1), "NumberingRules"); + comphelper::SequenceAsHashMap aMap(xNumberingRules->getByIndex(0)); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 64 + // - Actual : 4 + // i.e. numbering type was ARABIC, not ARABIC_ZERO. + CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(style::NumberingType::ARABIC_ZERO), + aMap["NumberingType"].get<sal_uInt16>()); +} + +DECLARE_ODFEXPORT_TEST(testArabicZero3Numbering, "arabic-zero3-numbering.odt") +{ + CPPUNIT_ASSERT_EQUAL(1, getPages()); + auto xNumberingRules + = getProperty<uno::Reference<container::XIndexAccess>>(getParagraph(1), "NumberingRules"); + comphelper::SequenceAsHashMap aMap(xNumberingRules->getByIndex(0)); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 65 + // - Actual : 4 + // i.e. numbering type was ARABIC, not ARABIC_ZERO3. + CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(style::NumberingType::ARABIC_ZERO3), + aMap["NumberingType"].get<sal_uInt16>()); +} + +DECLARE_ODFEXPORT_TEST(testArabicZero4Numbering, "arabic-zero4-numbering.odt") +{ + CPPUNIT_ASSERT_EQUAL(1, getPages()); + auto xNumberingRules + = getProperty<uno::Reference<container::XIndexAccess>>(getParagraph(1), "NumberingRules"); + comphelper::SequenceAsHashMap aMap(xNumberingRules->getByIndex(0)); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 66 + // - Actual : 4 + // i.e. numbering type was ARABIC, not ARABIC_ZERO4. + CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(style::NumberingType::ARABIC_ZERO4), + aMap["NumberingType"].get<sal_uInt16>()); +} + +DECLARE_ODFEXPORT_TEST(testArabicZero5Numbering, "arabic-zero5-numbering.odt") +{ + CPPUNIT_ASSERT_EQUAL(1, getPages()); + auto xNumberingRules + = getProperty<uno::Reference<container::XIndexAccess>>(getParagraph(1), "NumberingRules"); + comphelper::SequenceAsHashMap aMap(xNumberingRules->getByIndex(0)); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 67 + // - Actual : 4 + // i.e. numbering type was ARABIC, not ARABIC_ZERO5. + CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(style::NumberingType::ARABIC_ZERO5), + aMap["NumberingType"].get<sal_uInt16>()); +} + +DECLARE_ODFEXPORT_TEST(testRovasNumbering, "rovas-numbering.odt") +{ + CPPUNIT_ASSERT_EQUAL(1, getPages()); + auto xNumberingRules + = getProperty<uno::Reference<container::XIndexAccess>>(getParagraph(1), "NumberingRules"); + comphelper::SequenceAsHashMap aMap(xNumberingRules->getByIndex(0)); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 68 + // - Actual : 4 + // i.e. numbering type was ARABIC, not SZEKELY_ROVAS. + CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(style::NumberingType::SZEKELY_ROVAS), + aMap["NumberingType"].get<sal_uInt16>()); +} + +DECLARE_ODFEXPORT_TEST(testPageContentTop, "page-content-top.odt") +{ + CPPUNIT_ASSERT_EQUAL(1, getShapes()); + CPPUNIT_ASSERT_EQUAL(1, getPages()); + uno::Reference<beans::XPropertySet> xShape(getShape(1), uno::UNO_QUERY); + sal_Int16 nExpected = text::RelOrientation::PAGE_PRINT_AREA_TOP; + CPPUNIT_ASSERT_EQUAL(nExpected, getProperty<sal_Int16>(xShape, "VertOrientRelation")); +} + +DECLARE_ODFEXPORT_TEST(testPageContentBottom, "page-content-bottom.odt") +{ + CPPUNIT_ASSERT_EQUAL(1, getShapes()); + CPPUNIT_ASSERT_EQUAL(1, getPages()); + uno::Reference<beans::XPropertySet> xShape(getShape(1), uno::UNO_QUERY); + sal_Int16 nExpected = text::RelOrientation::PAGE_PRINT_AREA_BOTTOM; + CPPUNIT_ASSERT_EQUAL(nExpected, getProperty<sal_Int16>(xShape, "VertOrientRelation")); +} + +CPPUNIT_TEST_FIXTURE(Test, tdf124470) +{ + loadAndReload("tdf124470TableAndEmbeddedUsedFonts.odt"); + // Table styles were exported out of place, inside font-face-decls. + // Without the fix in place, this will fail already in ODF validation: + // "content.xml[2,2150]: Error: tag name "style:style" is not allowed. Possible tag names are: <font-face>" + + CPPUNIT_ASSERT_EQUAL(1, getPages()); + + xmlDocUniquePtr pXmlDoc = parseExport("content.xml"); + + assertXPath(pXmlDoc, "/office:document-content/office:font-face-decls/style:style", 0); + assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/style:style[@style:family='table']", 1); + assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/style:style[@style:family='table-column']", 2); + assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/style:style[@style:family='paragraph']", 1); +} + +CPPUNIT_TEST_FIXTURE(Test, tdf135942) +{ + loadAndReload("nestedTableInFooter.odt"); + // All table autostyles should be collected, including nested, and must not crash. + + CPPUNIT_ASSERT_EQUAL(1, getPages()); + + xmlDocUniquePtr pXmlDoc = parseExport("styles.xml"); + + assertXPath(pXmlDoc, "/office:document-styles/office:automatic-styles/style:style[@style:family='table']", 2); +} + +CPPUNIT_TEST_FIXTURE(Test, tdf150927) +{ + // Similar to tdf135942 + + loadAndReload("table-in-frame-in-table-in-header-base.odt"); + // All table autostyles should be collected, including nested, and must not crash. + + CPPUNIT_ASSERT_EQUAL(1, getPages()); + + xmlDocUniquePtr pXmlDoc = parseExport("styles.xml"); + + assertXPath(pXmlDoc, "/office:document-styles/office:automatic-styles/style:style[@style:family='table']", 2); +} + +DECLARE_ODFEXPORT_TEST(testGutterLeft, "gutter-left.odt") +{ + CPPUNIT_ASSERT_EQUAL(1, getPages()); + uno::Reference<beans::XPropertySet> xPageStyle; + getStyles("PageStyles")->getByName("Standard") >>= xPageStyle; + sal_Int32 nGutterMargin{}; + xPageStyle->getPropertyValue("GutterMargin") >>= nGutterMargin; + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1270 + // - Actual : 0 + // i.e. gutter margin was lost. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1270), nGutterMargin); +} + DECLARE_ODFEXPORT_TEST(testTdf52065_centerTabs, "testTdf52065_centerTabs.odt") { CPPUNIT_ASSERT_EQUAL(1, getPages()); |