/* * 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 #if !defined(MACOSX) && !defined(WNT) #include #include #include #include #include #include #include #include class Test : public SwModelTestBase { public: Test() : SwModelTestBase("/sw/qa/extras/ww8export/data/", "MS Word 97") {} bool mustTestImportOf(const char* filename) const SAL_OVERRIDE { // If the testcase is stored in some other format, it's pointless to test. return OString(filename).endsWith(".doc"); } }; #define DECLARE_WW8EXPORT_TEST(TestName, filename) DECLARE_SW_ROUNDTRIP_TEST(TestName, filename, Test) DECLARE_WW8EXPORT_TEST(testN325936, "n325936.doc") { /* * The problem was that the transparent background of the drawing in the * header was exported as non-transparent. * * xray ThisComponent.DrawPage(0).BackColorTransparency */ uno::Reference xPropertySet(getShape(1), uno::UNO_QUERY); sal_Int32 nValue = getProperty< sal_Int32 >(getShape(1), "BackColorTransparency"); CPPUNIT_ASSERT_EQUAL(sal_Int32(100), nValue); } DECLARE_WW8EXPORT_TEST(testFdo45724, "fdo45724.odt") { // The text and background color of the control shape was not correct. uno::Reference xControlShape(getShape(1), uno::UNO_QUERY); uno::Reference xComponent(xControlShape->getControl(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(COL_WHITE, getProperty(xComponent, "BackgroundColor")); CPPUNIT_ASSERT_EQUAL(OUString("xxx"), xComponent->getCurrentValue().get()); } DECLARE_WW8EXPORT_TEST(testFdo46020, "fdo46020.odt") { // The footnote in that document wasn't exported, check that it is actually exported uno::Reference xFootnotesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xFootnotes(xFootnotesSupplier->getFootnotes(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xFootnotes->getCount()); } DECLARE_WW8EXPORT_TEST(testFirstHeaderFooter, "first-header-footer.doc") { // Test import and export of a section's headerf/footerf properties. // The document has 6 pages. Note that we don't test if 4 or just 2 page // styles are created, the point is that layout should be correct. CPPUNIT_ASSERT_EQUAL(OUString("First page header"), parseDump("/root/page[1]/header/txt/text()")); CPPUNIT_ASSERT_EQUAL(OUString("First page footer"), parseDump("/root/page[1]/footer/txt/text()")); CPPUNIT_ASSERT_EQUAL(OUString("Even page header"), parseDump("/root/page[2]/header/txt/text()")); CPPUNIT_ASSERT_EQUAL(OUString("Even page footer"), parseDump("/root/page[2]/footer/txt/text()")); CPPUNIT_ASSERT_EQUAL(OUString("Odd page header"), parseDump("/root/page[3]/header/txt/text()")); CPPUNIT_ASSERT_EQUAL(OUString("Odd page footer"), parseDump("/root/page[3]/footer/txt/text()")); CPPUNIT_ASSERT_EQUAL(OUString("First page header2"), parseDump("/root/page[4]/header/txt/text()")); CPPUNIT_ASSERT_EQUAL(OUString("First page footer 2"), parseDump("/root/page[4]/footer/txt/text()")); CPPUNIT_ASSERT_EQUAL(OUString("Odd page header 2"), parseDump("/root/page[5]/header/txt/text()")); CPPUNIT_ASSERT_EQUAL(OUString("Odd page footer 2"), parseDump("/root/page[5]/footer/txt/text()")); CPPUNIT_ASSERT_EQUAL(OUString("Even page header 2"), parseDump("/root/page[6]/header/txt/text()")); CPPUNIT_ASSERT_EQUAL(OUString("Even page footer 2"), parseDump("/root/page[6]/footer/txt/text()")); } DECLARE_WW8EXPORT_TEST(testZoom, "zoom.doc") { uno::Reference xModel(mxComponent, uno::UNO_QUERY); uno::Reference xViewSettingsSupplier(xModel->getCurrentController(), uno::UNO_QUERY); uno::Reference xPropertySet(xViewSettingsSupplier->getViewSettings()); sal_Int16 nValue = 0; xPropertySet->getPropertyValue("ZoomValue") >>= nValue; CPPUNIT_ASSERT_EQUAL(sal_Int16(42), nValue); } DECLARE_WW8EXPORT_TEST(test56513, "fdo56513.doc") { CPPUNIT_ASSERT_EQUAL(OUString("This is the header of the first section"), parseDump("/root/page[1]/header/txt/text()")); CPPUNIT_ASSERT_EQUAL(OUString("This is the first page header of the second section"), parseDump("/root/page[2]/header/txt/text()")); CPPUNIT_ASSERT_EQUAL(OUString("This is the non-first-page header of the second section"), parseDump("/root/page[3]/header/txt/text()")); } DECLARE_WW8EXPORT_TEST(testNewPageStylesTable, "new-page-styles.doc") { CPPUNIT_ASSERT_EQUAL(OUString("Sigma Space Performance Goals and Results (Page 1)*"), parseDump("/root/page[1]/header/txt/text()")); CPPUNIT_ASSERT_EQUAL(OUString("Sigma Space Performance Assessment (Page 2)****"), parseDump("/root/page[2]/header/txt/text()")); CPPUNIT_ASSERT_EQUAL(OUString("Sigma Space Performance Goals: Next Year (Page 3)*******"), parseDump("/root/page[3]/header/txt/text()")); } DECLARE_WW8EXPORT_TEST(testFdo42144, "fdo42144.odt") { // Footer wasn't disabled -- instead empty footer was exported. uno::Reference xStyle(getStyles("PageStyles")->getByName(DEFAULT_STYLE), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(false, bool(getProperty(xStyle, "FooterIsOn"))); } DECLARE_WW8EXPORT_TEST(testCharacterBorder, "charborder.odt") { uno::Reference xRun(getRun(getParagraph(1),1), uno::UNO_QUERY); // WW8 has just one border attribute (sprmCBrc) for text border so all side has // the same border // Border { const table::BorderLine2 aTopBorder = getProperty(xRun,"CharTopBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(table::BorderLine2(0xFF3333,0,318,0,0,318), aTopBorder); CPPUNIT_ASSERT_BORDER_EQUAL(aTopBorder, getProperty(xRun,"CharLeftBorder")); CPPUNIT_ASSERT_BORDER_EQUAL(aTopBorder, getProperty(xRun,"CharBottomBorder")); CPPUNIT_ASSERT_BORDER_EQUAL(aTopBorder, getProperty(xRun,"CharRightBorder")); } // Padding (dptSpace) it is constant 0 { CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty(xRun,"CharTopBorderDistance")); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty(xRun,"CharLeftBorderDistance")); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty(xRun,"CharBottomBorderDistance")); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty(xRun,"CharRightBorderDistance")); } // Shadow (fShadow) /* WW8 use just one bool value for shadow so the next conversions are made during an export-import round color: any -> black location: any -> bottom-right width: any -> border width */ { const table::ShadowFormat aShadow = getProperty(xRun, "CharShadowFormat"); CPPUNIT_ASSERT_EQUAL(COL_BLACK, sal_uInt32(aShadow.Color)); CPPUNIT_ASSERT_EQUAL(table::ShadowLocation_BOTTOM_RIGHT, aShadow.Location); CPPUNIT_ASSERT_EQUAL(sal_Int16(318), aShadow.ShadowWidth); } } DECLARE_WW8EXPORT_TEST(testFdo77454, "fdo77454.doc") { { // check negative crops round-trip text::GraphicCrop const crop = getProperty(getShape(1), "GraphicCrop"); CPPUNIT_ASSERT_EQUAL(sal_Int32( -439), crop.Left); CPPUNIT_ASSERT_EQUAL(sal_Int32(-7040), crop.Right); CPPUNIT_ASSERT_EQUAL(sal_Int32( -220), crop.Top); CPPUNIT_ASSERT_EQUAL(sal_Int32(-7040), crop.Bottom); } { // check positive crops round-trip text::GraphicCrop const crop = getProperty(getShape(2), "GraphicCrop"); CPPUNIT_ASSERT_EQUAL(sal_Int32( 326), crop.Left); CPPUNIT_ASSERT_EQUAL(sal_Int32( 1208), crop.Right); CPPUNIT_ASSERT(abs(sal_Int32(1635) - crop.Top) <= 2); CPPUNIT_ASSERT(abs(sal_Int32( 95) - crop.Bottom) <= 2); } } DECLARE_WW8EXPORT_TEST(testFdo59530, "fdo59530.doc") { // See ooxmlexport's testFdo38244(). // Test comment range feature. uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); uno::Reference xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY); uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); uno::Reference xRunEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY); uno::Reference xRunEnum = xRunEnumAccess->createEnumeration(); xRunEnum->nextElement(); uno::Reference xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("Annotation"), getProperty(xPropertySet, "TextPortionType")); xRunEnum->nextElement(); xPropertySet.set(xRunEnum->nextElement(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("AnnotationEnd"), getProperty(xPropertySet, "TextPortionType")); // Test initials. uno::Reference xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xFieldsAccess(xTextFieldsSupplier->getTextFields()); uno::Reference xFields(xFieldsAccess->createEnumeration()); xPropertySet.set(xFields->nextElement(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("M"), getProperty(xPropertySet, "Initials")); // Test commented text range which spans over more text nodes // Comment starts in the second paragraph xRunEnumAccess.set(xParaEnum->nextElement(), uno::UNO_QUERY); xRunEnum = xRunEnumAccess->createEnumeration(); xRunEnum->nextElement(); xPropertySet.set(xRunEnum->nextElement(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("Annotation"), getProperty(xPropertySet, "TextPortionType")); // Comment ends in the third paragraph xRunEnumAccess.set(xParaEnum->nextElement(), uno::UNO_QUERY); xRunEnum = xRunEnumAccess->createEnumeration(); xRunEnum->nextElement(); xPropertySet.set(xRunEnum->nextElement(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("AnnotationEnd"), getProperty(xPropertySet, "TextPortionType")); } DECLARE_WW8EXPORT_TEST(testCommentsNested, "comments-nested.doc") { uno::Reference xOuter(getProperty< uno::Reference >(getRun(getParagraph(1), 2), "TextField"), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("Outer"), getProperty(xOuter, "Content")); uno::Reference xInner(getProperty< uno::Reference >(getRun(getParagraph(1), 4), "TextField"), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("Inner"), getProperty(xInner, "Content")); } DECLARE_WW8EXPORT_TEST(testBorderColoursExport, "bordercolours.odt") { // This is very close to testBorderColours in ww8import.cxx, but for export // The following 6 colours can only be represented with WW9 (Word 2000) // BRC (BoRder Control) structures. We can tell that they have been // exported/imported using a WW8 (Word '97) BRC if they instead come // through as one of the 16 colours listed at this link: // http://msdn.microsoft.com/en-us/library/dd773060.aspx table::BorderLine2 expectedTop(0xFA670C, 0, 53, 0, 1, 53); table::BorderLine2 expectedLeft(0xD99594, 0, 79, 0, 0, 79); table::BorderLine2 expectedRight(0xB2A1C7, 53, 53, 53, 3, 159); table::BorderLine2 expectedBottom(0xB6DDE8, 0, 106, 0, 14, 106); table::BorderLine2 expectedDashedRed(0xFA670C, 0, 53, 0, 2, 53); table::BorderLine2 expectedDoubleGreen(0xC2D69B, 26, 106, 26, 4, 159); // Paragraph border uno::Reference bookmarksSupplier(mxComponent, uno::UNO_QUERY); uno::Reference bookmarks( bookmarksSupplier->getBookmarks(), uno::UNO_QUERY); uno::Reference bookmark( bookmarks->getByName("ParagraphBorder"), uno::UNO_QUERY); uno::Reference anchor(bookmark->getAnchor()); table::BorderLine2 border; border = getProperty(anchor, "TopBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); border = getProperty(anchor, "LeftBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedLeft, border); border = getProperty(anchor, "RightBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border); border = getProperty(anchor, "BottomBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedBottom, border); // Page border OUString pageStyleName = getProperty(anchor, "PageStyleName"); uno::Reference pageStyle( getStyles("PageStyles")->getByName(pageStyleName), uno::UNO_QUERY); border = getProperty(pageStyle, "TopBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); border = getProperty(pageStyle, "LeftBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedLeft, border); border = getProperty(pageStyle, "RightBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border); border = getProperty(pageStyle, "BottomBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedBottom, border); // Character border bookmark.set(bookmarks->getByName("CharBorder"), uno::UNO_QUERY); anchor = bookmark->getAnchor(); border = getProperty(anchor, "CharTopBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); border = getProperty(anchor, "CharLeftBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); border = getProperty(anchor, "CharRightBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); border = getProperty(anchor, "CharBottomBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); // Table border uno::Reference tablesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference tables( tablesSupplier->getTextTables(), uno::UNO_QUERY); uno::Reference table( tables->getByName("Table1"), uno::UNO_QUERY); table::TableBorder2 tableBorder = getProperty( table, "TableBorder2"); CPPUNIT_ASSERT_EQUAL(expectedTop.Color, tableBorder.TopLine.Color); CPPUNIT_ASSERT_EQUAL(expectedLeft.Color, tableBorder.LeftLine.Color); CPPUNIT_ASSERT_EQUAL(expectedRight.Color, tableBorder.RightLine.Color); #if 0 // #if'd out because the "fine dashed" border line style for table borders // does not seem to save or load correctly in odt format at present CPPUNIT_ASSERT_EQUAL(expectedBottom.Color, tableBorder.BottomLine.Color); #endif // Table cells uno::Reference cell( table->getCellByName("A2"), uno::UNO_QUERY); border = getProperty(cell, "TopBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); border = getProperty(cell, "LeftBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedLeft, border); border = getProperty(cell, "BottomBorder"); #if 0 // #if'd out because the "fine dashed" border line style for table borders // does not seem to save or load correctly in odt format at present CPPUNIT_ASSERT_BORDER_EQUAL(expectedBottom, border); #endif cell.set(table->getCellByName("B2"), uno::UNO_QUERY); border = getProperty(cell, "TopBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedDoubleGreen, border); border = getProperty(cell, "LeftBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border); border = getProperty(cell, "BottomBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedDoubleGreen, border); cell.set(table->getCellByName("C2"), uno::UNO_QUERY); border = getProperty(cell, "TopBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedDoubleGreen, border); border = getProperty(cell, "LeftBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedDashedRed, border); border = getProperty(cell, "RightBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border); border = getProperty(cell, "BottomBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedDoubleGreen, border); // Picture border // (#if'd out as they are not yet exported with correct colours) #if 0 bookmark.set(bookmarks->getByName("PictureBorder"),uno::UNO_QUERY); anchor = bookmark->getAnchor(); border = getProperty(anchor, "TopBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); border = getProperty(anchor, "LeftBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedLeft, border); border = getProperty(anchor, "RightBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border); border = getProperty(anchor, "BottomBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(expectedBottom, border); #endif } #endif CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */