/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
namespace
{ class Test : public SwModelTestBase
{ public:
Test() : SwModelTestBase(u"/sw/qa/extras/odfexport/data/"_ustr, u"writer8"_ustr) {}
};
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(u"styles.xml"_ustr); // 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", u"normal");
assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[1]", "font-weight", u"normal");
assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[2]", "font-style", u"normal");
assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[2]", "font-weight", u"bold");
assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[3]", "font-style", u"italic");
assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[3]", "font-weight", u"normal");
assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[4]", "font-style", u"italic");
assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation Serif']/svg:font-face-src/svg:font-face-uri[4]", "font-weight", u"bold"); #endif
}
CPPUNIT_TEST_FIXTURE(Test, tdf166627)
{
loadAndReload("font_used_in_header_only.fodt"); // Liberation Sans wasn't embedded before fix, because it was only seen used in header
// There should be four files embedded for the font
assertXPath(
pXmlDoc, "//style:font-face[@style:name='Liberation Sans']/svg:font-face-src/svg:font-face-uri", 4);
// 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);
// 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);
}
// fo:hyphenation-keep="page" defined in direct paragraph formatting
loadAndReload("tdf132599_page.fodt"); // This was 2 (not truncated hyphenated line)
CPPUNIT_ASSERT_EQUAL(3, getPages());
}
// fo:hyphenation-keep="auto" defined in direct paragraph formatting
loadAndReload("tdf132599_auto.fodt"); // not truncated hyphenated line
CPPUNIT_ASSERT_EQUAL(2, getPages());
}
// fo:hyphenation-keep="page" loext:hyphenation-keep-type="spread"
loadAndReload("tdf132599_spread.fodt"); // shift last line of right page, resulting 3 pages
CPPUNIT_ASSERT_EQUAL(3, getPages());
}
// fo:hyphenation-keep="page" loext:hyphenation-keep-type="spread"
loadAndReload("tdf132599_spread-left-page.fodt"); // do not shift last line of left page // This was 4 (shifted last line of left page, when it's hyphenated)
CPPUNIT_ASSERT_EQUAL(3, getPages());
}
// last line of the left column is shifted, according to // fo:hyphenation-keep="page" loext:hyphenation-keep-type="column"
loadAndReload("tdf132599_column.fodt"); // shift last line of the first column, resulting 3 pages
CPPUNIT_ASSERT_EQUAL(3, getPages());
}
// last line of the not last column is not shifted, according to // fo:hyphenation-keep="page" loext:hyphenation-keep-type="page"
loadAndReload("tdf132599_page_in_not_last_column.fodt"); // do not shift last line of the first column, resulting 2 pages
CPPUNIT_ASSERT_EQUAL(2, getPages());
}
// last line of the last column is shifted, according to // fo:hyphenation-keep="page" loext:hyphenation-keep-type="page"
loadAndReload("tdf132599_page_in_last_column.fodt"); // shift last line of the first page, resulting 3 pages
CPPUNIT_ASSERT_EQUAL(3, getPages());
}
// last full line of the paragraph column is not hyphenated // fo:hyphenation-keep="page" loext:hyphenation-keep-type="always"
loadAndReload("tdf132599_always.fodt");
CPPUNIT_ASSERT_EQUAL(1, getPages());
// last full line of the table is not hyphenated on page 1 // fo:hyphenation-keep="page" loext:hyphenation-keep-type=""
loadAndReload("tdf132599_page_in_table.fodt"); // This was 2 (not handling hyphenation-keep in tables)
CPPUNIT_ASSERT_EQUAL(3, getPages());
// fo:hyphenation-keep="page" defined in text body style
loadAndReload("tdf160518_page_in_text_body_style.fodt");
CPPUNIT_ASSERT_EQUAL(3, getPages());
}
// fo:hyphenation-keep="auto" defined in text body style
loadAndReload("tdf160518_auto_in_text_body_style.fodt");
CPPUNIT_ASSERT_EQUAL(2, getPages());
}
// fo:hyphenation-keep="page" defined in direct paragraph formatting
loadAndReload("tdf165354_page.fodt"); // This was 3 in tdf132599, but now 2, shifting only the last hyphenated word, // not the full line, because of loext:hyphenation-keep-line=true
CPPUNIT_ASSERT_EQUAL(2, getPages());
}
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, u"AllowOverlap"_ustr));
xShape = getShape(2);
CPPUNIT_ASSERT(!getProperty<bool>(xShape, u"AllowOverlap"_ustr));
}
// 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(u"SignatureLineUnsignedImage"_ustr) >>= xUnsignedGraphic;
CPPUNIT_ASSERT_EQUAL(true, xUnsignedGraphic.is());
}
//This failed Actual Value was LISTTAB instead of NEWLINE
CPPUNIT_ASSERT_EQUAL(
sal_Int16(SvxNumberFormat::NEWLINE), hashMap[u"LabelFollowedBy"_ustr].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[] = { u"1st"_ustr, u"Erste"_ustr, u"Eins"_ustr, u"1."_ustr, u"Premier"_ustr, u"Un"_ustr, u"1ᵉʳ"_ustr, u"First"_ustr, u"One"_ustr }; // fallback for old platforms without std::codecvt and std::regex supports
OUString const aFieldTextFallbacks[] = { u"Ordinal-number 1"_ustr, u"Ordinal 1"_ustr, u"1"_ustr };
uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); // update text field content
uno::Reference<util::XRefreshable>(xTextFieldsSupplier->getTextFields(), uno::UNO_QUERY_THROW)->refresh();
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(u"com.sun.star.text.textfield.PageNumber"_ustr))
{
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()));
}
}
}
DECLARE_ODFEXPORT_TEST(tdf133507_contextualSpacingSection, "tdf133507_contextualSpacingSection.odt")
{ // Previously this was one page (no UL spacing) or three pages (every para had spacing)
CPPUNIT_ASSERT_EQUAL(2, getPages());
}
// check: we have 2 bookmarks
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xBookmarksByIdx->getCount());
CPPUNIT_ASSERT(xBookmarksByName->hasByName(u"BookmarkNonHidden"_ustr));
CPPUNIT_ASSERT(xBookmarksByName->hasByName(u"BookmarkHidden"_ustr));
// <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));
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, u"ReplacementGraphic"_ustr);
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(u"Object 1/settings.xml"_ustr);
assertXPathContent(pXmlDoc, "//config:config-item[@config:name='VisibleAreaWidth']", u"4516");
assertXPathContent(pXmlDoc, "//config:config-item[@config:name='VisibleAreaHeight']", u"903");
// Without the fix in place, this test would have failed with // - Expected: 3150 // - Actual : 5851
CPPUNIT_ASSERT_EQUAL(sal_Int64(3150) , getProperty<sal_Int64>(xTableRows->getByIndex(0), u"Height"_ustr));
}
DECLARE_ODFEXPORT_TEST(testThemeCrash, "tdf156905.odt")
{ // first it started to crash at import time, later at export time
CPPUNIT_ASSERT_EQUAL(4, getPages());
}
DECLARE_ODFEXPORT_TEST(testTdf150394, "tdf150394.odt")
{ // crashes at import time
CPPUNIT_ASSERT_EQUAL(1, getPages());
}
DECLARE_ODFEXPORT_TEST(testArabicZeroNumbering, "arabic-zero-numbering.odt")
{
CPPUNIT_ASSERT_EQUAL(1, getPages()); auto xNumberingRules
= getProperty<uno::Reference<container::XIndexAccess>>(getParagraph(1), u"NumberingRules"_ustr);
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[u"NumberingType"_ustr].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), u"NumberingRules"_ustr);
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[u"NumberingType"_ustr].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), u"NumberingRules"_ustr);
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[u"NumberingType"_ustr].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), u"NumberingRules"_ustr);
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[u"NumberingType"_ustr].get<sal_uInt16>());
}
DECLARE_ODFEXPORT_TEST(testRovasNumbering, "rovas-numbering.odt")
{
CPPUNIT_ASSERT_EQUAL(1, getPages()); auto xNumberingRules
= getProperty<uno::Reference<container::XIndexAccess>>(getParagraph(1), u"NumberingRules"_ustr);
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[u"NumberingType"_ustr].get<sal_uInt16>());
}
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>"
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.