/* -*- 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/. */ #include #include #include #include #include #include #include class Test : public SwModelTestBase { public: Test() : SwModelTestBase("/sw/qa/extras/odfexport/data/", "writer8") {} bool mustValidate(const char* /*filename*/) const override { return true; } }; CPPUNIT_TEST_FIXTURE(Test, tdf151100) { // Similar to tdf135942 loadAndReload("tdf151100.docx"); // 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']", 1); } DECLARE_ODFEXPORT_TEST(testTdf52065_centerTabs, "testTdf52065_centerTabs.odt") { CPPUNIT_ASSERT_EQUAL(1, getPages()); sal_Int32 nTabStop = parseDump("//body/txt[4]/Text[3]", "nWidth").toInt32(); // Without the fix, the text was unseen, with a tabstop width of 64057. It should be 3057 CPPUNIT_ASSERT(nTabStop < 4000); CPPUNIT_ASSERT(3000 < nTabStop); CPPUNIT_ASSERT_EQUAL(OUString(u"Pečiatka zamestnávateľa"), parseDump("//body/txt[4]/Text[4]", "Portion")); } DECLARE_ODFEXPORT_TEST(testTdf104254_noHeaderWrapping, "tdf104254_noHeaderWrapping.odt") { CPPUNIT_ASSERT_EQUAL(1, getShapes()); CPPUNIT_ASSERT_EQUAL(1, getPages()); xmlDocUniquePtr pXmlDoc = parseLayoutDump(); sal_Int32 nParaHeight = getXPath(pXmlDoc, "//header/txt[1]/infos/bounds", "height").toInt32(); // The wrapping on header images is supposed to be ignored (since OOo for MS compat reasons), // thus making the text run underneath the image. Before, height was 1104. Now it is 552. CPPUNIT_ASSERT_MESSAGE("Paragraph should fit on a single line", nParaHeight < 600); } DECLARE_ODFEXPORT_TEST(testTdf131025_noZerosInTable, "tdf131025_noZerosInTable.odt") { uno::Reference xSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xTables = xSupplier->getTextTables(); uno::Reference xTable(xTables->getByName("Table1"), uno::UNO_QUERY); uno::Reference xCell(xTable->getCellByName("C3"), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("5 gp"), xCell->getString()); } DECLARE_ODFEXPORT_TEST(testTdf143793_noBodyWrapping, "tdf143793_noBodyWrapping.odt") { CPPUNIT_ASSERT_EQUAL(2, getShapes()); // Preserve old document wrapping. Compat "Use OOo 1.1 text wrapping around objects" // Originally, the body text did not wrap around spill-over header images CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fits on one page", 1, getPages() ); xmlDocUniquePtr pXmlDoc = parseLayoutDump(); sal_Int32 nParaHeight = getXPath(pXmlDoc, "//page[1]/header/txt[1]/infos/bounds", "height").toInt32(); // The header text should wrap around the header image in OOo 1.1 and prior, // thus taking up two lines instead of one. One line is 276. It should be 552. CPPUNIT_ASSERT_MESSAGE("Header text should fill two lines", nParaHeight > 400); } CPPUNIT_TEST_FIXTURE(Test, testTdf137199) { loadAndReload("tdf137199.docx"); CPPUNIT_ASSERT_EQUAL(OUString(">1<"), getProperty(getParagraph(1), "ListLabelString")); CPPUNIT_ASSERT_EQUAL(OUString("1)"), getProperty(getParagraph(2), "ListLabelString")); CPPUNIT_ASSERT_EQUAL(OUString("HELLO1WORLD!"), getProperty(getParagraph(3), "ListLabelString")); CPPUNIT_ASSERT_EQUAL(OUString("HELLO2WORLD!"), getProperty(getParagraph(4), "ListLabelString")); } DECLARE_ODFEXPORT_TEST(testTdf143605, "tdf143605.odt") { CPPUNIT_ASSERT_EQUAL(1, getPages()); // With numbering type "none" there should be just prefix & suffix CPPUNIT_ASSERT_EQUAL(OUString("."), getProperty(getParagraph(1), "ListLabelString")); } CPPUNIT_TEST_FIXTURE(Test, testListFormatDocx) { loadAndReload("listformat.docx"); // Ensure in resulting ODT we also have not just prefix/suffix, but custom delimiters CPPUNIT_ASSERT_EQUAL(OUString(">1<"), getProperty(getParagraph(1), "ListLabelString")); CPPUNIT_ASSERT_EQUAL(OUString(">>1/1<<"), getProperty(getParagraph(2), "ListLabelString")); CPPUNIT_ASSERT_EQUAL(OUString(">>1/1/1<<"), getProperty(getParagraph(3), "ListLabelString")); CPPUNIT_ASSERT_EQUAL(OUString(">>1/1/2<<"), getProperty(getParagraph(4), "ListLabelString")); // Check also that in numbering styles we have num-list-format defined xmlDocUniquePtr pXmlDoc = parseExport("styles.xml"); assertXPath(pXmlDoc, "/office:document-styles/office:styles/text:list-style[@style:name='WWNum1']/" "text:list-level-style-number[@text:level='1']", "num-list-format", ">%1%<"); assertXPath(pXmlDoc, "/office:document-styles/office:styles/text:list-style[@style:name='WWNum1']/" "text:list-level-style-number[@text:level='2']", "num-list-format", ">>%1%/%2%<<"); assertXPath(pXmlDoc, "/office:document-styles/office:styles/text:list-style[@style:name='WWNum1']/" "text:list-level-style-number[@text:level='3']", "num-list-format", ">>%1%/%2%/%3%<<"); // But for compatibility there are still prefix/suffix assertXPath(pXmlDoc, "/office:document-styles/office:styles/text:list-style[@style:name='WWNum1']/" "text:list-level-style-number[@text:level='1']", "num-prefix", ">"); assertXPath(pXmlDoc, "/office:document-styles/office:styles/text:list-style[@style:name='WWNum1']/" "text:list-level-style-number[@text:level='1']", "num-suffix", "<"); assertXPath(pXmlDoc, "/office:document-styles/office:styles/text:list-style[@style:name='WWNum1']/" "text:list-level-style-number[@text:level='2']", "num-prefix", ">>"); assertXPath(pXmlDoc, "/office:document-styles/office:styles/text:list-style[@style:name='WWNum1']/" "text:list-level-style-number[@text:level='2']", "num-suffix", "<<"); assertXPath(pXmlDoc, "/office:document-styles/office:styles/text:list-style[@style:name='WWNum1']/" "text:list-level-style-number[@text:level='3']", "num-prefix", ">>"); assertXPath(pXmlDoc, "/office:document-styles/office:styles/text:list-style[@style:name='WWNum1']/" "text:list-level-style-number[@text:level='3']", "num-suffix", "<<"); } DECLARE_ODFEXPORT_TEST(testShapeWithHyperlink, "shape-with-hyperlink.odt") { CPPUNIT_ASSERT_EQUAL(1, getShapes()); CPPUNIT_ASSERT_EQUAL(1, getPages()); if (xmlDocUniquePtr pXmlDoc = parseExport("content.xml")) { // Check how conversion from prefix/suffix to list format did work assertXPath(pXmlDoc, "/office:document-content/office:body/office:text/text:p/draw:a", "href", "http://shape.com/"); } } DECLARE_ODFEXPORT_TEST(testShapesHyperlink, "shapes-hyperlink.odt") { CPPUNIT_ASSERT_EQUAL(1, getPages()); CPPUNIT_ASSERT_EQUAL(5, getShapes()); uno::Reference const xPropSet1(getShape(1), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("http://libreoffice.org/"), getProperty(xPropSet1, "Hyperlink")); uno::Reference const xPropSet2(getShape(2), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("http://libreoffice2.org/"), getProperty(xPropSet2, "Hyperlink")); uno::Reference const xPropSet3(getShape(3), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("http://libreoffice3.org/"), getProperty(xPropSet3, "Hyperlink")); uno::Reference const xPropSet4(getShape(4), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("http://libreoffice4.org/"), getProperty(xPropSet4, "Hyperlink")); uno::Reference const xPropSet5(getShape(5), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("http://libreoffice5.org/"), getProperty(xPropSet5, "Hyperlink")); } DECLARE_ODFEXPORT_TEST(testListFormatOdt, "listformat.odt") { CPPUNIT_ASSERT_EQUAL(1, getPages()); // Ensure in resulting ODT we also have not just prefix/suffix, but custom delimiters CPPUNIT_ASSERT_EQUAL(OUString(">1<"), getProperty(getParagraph(1), "ListLabelString")); CPPUNIT_ASSERT_EQUAL(OUString(">>1.1<<"), getProperty(getParagraph(2), "ListLabelString")); CPPUNIT_ASSERT_EQUAL(OUString(">>1.1.1<<"), getProperty(getParagraph(3), "ListLabelString")); CPPUNIT_ASSERT_EQUAL(OUString(">>1.1.2<<"), getProperty(getParagraph(4), "ListLabelString")); if (xmlDocUniquePtr pXmlDoc = parseExport("content.xml")) { // Check how conversion from prefix/suffix to list format did work assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/text:list-style[@style:name='L1']/" "text:list-level-style-number[@text:level='1']", "num-list-format", ">%1%<"); assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/text:list-style[@style:name='L1']/" "text:list-level-style-number[@text:level='2']", "num-list-format", ">>%1%.%2%<<"); assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/text:list-style[@style:name='L1']/" "text:list-level-style-number[@text:level='3']", "num-list-format", ">>%1%.%2%.%3%<<"); // But for compatibility there are still prefix/suffix as they were before assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/text:list-style[@style:name='L1']/" "text:list-level-style-number[@text:level='1']", "num-prefix", ">"); assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/text:list-style[@style:name='L1']/" "text:list-level-style-number[@text:level='1']", "num-suffix", "<"); assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/text:list-style[@style:name='L1']/" "text:list-level-style-number[@text:level='2']", "num-prefix", ">>"); assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/text:list-style[@style:name='L1']/" "text:list-level-style-number[@text:level='2']", "num-suffix", "<<"); assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/text:list-style[@style:name='L1']/" "text:list-level-style-number[@text:level='3']", "num-prefix", ">>"); assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/text:list-style[@style:name='L1']/" "text:list-level-style-number[@text:level='3']", "num-suffix", "<<"); } } CPPUNIT_TEST_FIXTURE(Test, testStyleLink) { // Given a document with a para and a char style that links each other, when loading that // document: load(mpTestDocumentPath, "style-link.fodt"); // Then make sure the char style links the para one: uno::Any aCharStyle = getStyles("CharacterStyles")->getByName("List Paragraph Char"); // Without the accompanying fix in place, this test would have failed with: // - Expected: List Paragraph // - Actual : // i.e. the linked style was lost on import. CPPUNIT_ASSERT_EQUAL(OUString("List Paragraph"), getProperty(aCharStyle, "LinkStyle")); uno::Any aParaStyle = getStyles("ParagraphStyles")->getByName("List Paragraph"); // Without the accompanying fix in place, this test would have failed with: // - Expected: List Paragraph Char // - Actual : // i.e. the linked style was lost on import. CPPUNIT_ASSERT_EQUAL(OUString("List Paragraph Char"), getProperty(aParaStyle, "LinkStyle")); } CPPUNIT_TEST_FIXTURE(Test, tdf120972) { loadAndReload("table_number_format_3.docx"); xmlDocUniquePtr pXmlDoc = parseExport("content.xml"); OUString cDecimal(SvtSysLocale().GetLocaleData().getNumDecimalSep()[0]); assertXPath( pXmlDoc, "//style:style[@style:name='P1']/style:paragraph-properties/style:tab-stops/style:tab-stop", "char", cDecimal); assertXPath( pXmlDoc, "//style:style[@style:name='P2']/style:paragraph-properties/style:tab-stops/style:tab-stop", "char", cDecimal); } DECLARE_ODFEXPORT_TEST(testSectionColumnSeparator, "section-columns-separator.fodt") { // tdf#150235: due to wrong types used in column export, 'style:height' and 'style:style' // attributes were exported incorrectly for 'style:column-sep' element auto xSection = getProperty>(getParagraph(1), "TextSection"); auto xColumns = getProperty>(xSection, "TextColumns"); CPPUNIT_ASSERT(xColumns); CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xColumns->getColumnCount()); // Without the accompanying fix in place, this test would have failed with: // - Expected: 50 // - Actual : 100 CPPUNIT_ASSERT_EQUAL(static_cast(50), getProperty(xColumns, "SeparatorLineRelativeHeight")); // Without the accompanying fix in place, this test would have failed with: // - Expected: 2 // - Actual : 0 CPPUNIT_ASSERT_EQUAL(css::text::ColumnSeparatorStyle::DOTTED, getProperty(xColumns, "SeparatorLineStyle")); // Check the rest of the properties, too CPPUNIT_ASSERT_EQUAL(true, getProperty(xColumns, "IsAutomatic")); CPPUNIT_ASSERT_EQUAL(sal_Int32(600), getProperty(xColumns, "AutomaticDistance")); CPPUNIT_ASSERT_EQUAL(sal_Int32(9), getProperty(xColumns, "SeparatorLineWidth")); CPPUNIT_ASSERT_EQUAL(Color(0x99, 0xAA, 0xBB), getProperty(xColumns, "SeparatorLineColor")); CPPUNIT_ASSERT_EQUAL( css::style::VerticalAlignment_BOTTOM, getProperty(xColumns, "SeparatorLineVerticalAlignment")); CPPUNIT_ASSERT_EQUAL(true, getProperty(xColumns, "SeparatorLineIsOn")); } CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */