LCOV - code coverage report
Current view: top level - sw/qa/extras/ww8export - ww8export.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 287 288 99.7 %
Date: 2015-06-13 12:38:46 Functions: 308 335 91.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #include <swmodeltestbase.hxx>
      11             : 
      12             : #include <com/sun/star/form/validation/XValidatableFormComponent.hpp>
      13             : #include <com/sun/star/frame/XStorable.hpp>
      14             : #include <com/sun/star/drawing/XControlShape.hpp>
      15             : #include <com/sun/star/beans/XPropertySet.hpp>
      16             : #include <com/sun/star/view/XViewSettingsSupplier.hpp>
      17             : #include <com/sun/star/table/ShadowFormat.hpp>
      18             : #include <com/sun/star/table/TableBorder2.hpp>
      19             : #include <com/sun/star/text/GraphicCrop.hpp>
      20             : #include <com/sun/star/text/XFormField.hpp>
      21             : #include <com/sun/star/view/DocumentZoomType.hpp>
      22             : 
      23          50 : class Test : public SwModelTestBase
      24             : {
      25             : public:
      26          50 :     Test() : SwModelTestBase("/sw/qa/extras/ww8export/data/", "MS Word 97") {}
      27             : 
      28          25 :     bool mustTestImportOf(const char* filename) const SAL_OVERRIDE
      29             :     {
      30             :         // If the testcase is stored in some other format, it's pointless to test.
      31          25 :         return OString(filename).endsWith(".doc");
      32             :     }
      33             : protected:
      34           8 :     bool CjkNumberedListTestHelper(sal_Int16 &nValue)
      35             :     {
      36           8 :         bool isNumber = false;
      37           8 :         uno::Reference<text::XTextRange> xPara(getParagraph(1));
      38          16 :         uno::Reference< beans::XPropertySet > properties( xPara, uno::UNO_QUERY);
      39           8 :         properties->getPropertyValue("NumberingIsNumber") >>= isNumber;
      40           8 :         if (!isNumber)
      41           0 :             return false;
      42          16 :         uno::Reference<container::XIndexAccess> xLevels( properties->getPropertyValue("NumberingRules"), uno::UNO_QUERY);
      43          16 :         uno::Sequence< beans::PropertyValue > aPropertyValue;
      44           8 :         xLevels->getByIndex(0) >>= aPropertyValue;
      45          96 :         for( int j = 0 ; j< aPropertyValue.getLength() ; ++j)
      46             :         {
      47          96 :             beans::PropertyValue aProp= aPropertyValue[j];
      48          96 :             if (aProp.Name == "NumberingType")
      49             :             {
      50           8 :                 nValue = aProp.Value.get<sal_Int16>();
      51           8 :                 return true;
      52             :             }
      53          88 :         }
      54           8 :         return false;
      55             :     }
      56             : };
      57             : 
      58          17 : DECLARE_WW8EXPORT_TEST(testN325936, "n325936.doc")
      59             : {
      60             :     /*
      61             :      * The problem was that the transparent background of the drawing in the
      62             :      * header was exported as non-transparent.
      63             :      *
      64             :      * xray ThisComponent.DrawPage(0).BackColorTransparency
      65             :      */
      66             : 
      67           2 :     uno::Reference<beans::XPropertySet> xPropertySet(getShape(1), uno::UNO_QUERY);
      68           2 :     sal_Int32 nValue = getProperty< sal_Int32 >(getShape(1), "BackColorTransparency");
      69           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(100), nValue);
      70           2 : }
      71             : 
      72          16 : DECLARE_WW8EXPORT_TEST(testFdo45724, "fdo45724.odt")
      73             : {
      74             :     // The text and background color of the control shape was not correct.
      75           1 :     uno::Reference<drawing::XControlShape> xControlShape(getShape(1), uno::UNO_QUERY);
      76           2 :     uno::Reference<form::validation::XValidatableFormComponent> xComponent(xControlShape->getControl(), uno::UNO_QUERY);
      77           1 :     CPPUNIT_ASSERT_EQUAL(COL_WHITE, getProperty<sal_uInt32>(xComponent, "BackgroundColor"));
      78           2 :     CPPUNIT_ASSERT_EQUAL(OUString("xxx"), xComponent->getCurrentValue().get<OUString>());
      79           1 : }
      80             : 
      81          16 : DECLARE_WW8EXPORT_TEST(testFdo46020, "fdo46020.odt")
      82             : {
      83             :     // The footnote in that document wasn't exported, check that it is actually exported
      84           1 :     uno::Reference<text::XFootnotesSupplier> xFootnotesSupplier(mxComponent, uno::UNO_QUERY);
      85           2 :     uno::Reference<container::XIndexAccess> xFootnotes(xFootnotesSupplier->getFootnotes(), uno::UNO_QUERY);
      86           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xFootnotes->getCount());
      87           1 : }
      88             : 
      89          17 : DECLARE_WW8EXPORT_TEST(testFirstHeaderFooter, "first-header-footer.doc")
      90             : {
      91             :     // Test import and export of a section's headerf/footerf properties.
      92             : 
      93             :     // The document has 6 pages. Note that we don't test if 4 or just 2 page
      94             :     // styles are created, the point is that layout should be correct.
      95           2 :     CPPUNIT_ASSERT_EQUAL(OUString("First page header"),  parseDump("/root/page[1]/header/txt/text()"));
      96           2 :     CPPUNIT_ASSERT_EQUAL(OUString("First page footer"),  parseDump("/root/page[1]/footer/txt/text()"));
      97           2 :     CPPUNIT_ASSERT_EQUAL(OUString("Even page header"),   parseDump("/root/page[2]/header/txt/text()"));
      98           2 :     CPPUNIT_ASSERT_EQUAL(OUString("Even page footer"),   parseDump("/root/page[2]/footer/txt/text()"));
      99           2 :     CPPUNIT_ASSERT_EQUAL(OUString("Odd page header"),  parseDump("/root/page[3]/header/txt/text()"));
     100           2 :     CPPUNIT_ASSERT_EQUAL(OUString("Odd page footer"),  parseDump("/root/page[3]/footer/txt/text()"));
     101           2 :     CPPUNIT_ASSERT_EQUAL(OUString("First page header2"), parseDump("/root/page[4]/header/txt/text()"));
     102           2 :     CPPUNIT_ASSERT_EQUAL(OUString("First page footer 2"), parseDump("/root/page[4]/footer/txt/text()"));
     103           2 :     CPPUNIT_ASSERT_EQUAL(OUString("Odd page header 2"), parseDump("/root/page[5]/header/txt/text()"));
     104           2 :     CPPUNIT_ASSERT_EQUAL(OUString("Odd page footer 2"), parseDump("/root/page[5]/footer/txt/text()"));
     105           2 :     CPPUNIT_ASSERT_EQUAL(OUString("Even page header 2"),  parseDump("/root/page[6]/header/txt/text()"));
     106           2 :     CPPUNIT_ASSERT_EQUAL(OUString("Even page footer 2"),  parseDump("/root/page[6]/footer/txt/text()"));
     107           2 : }
     108             : 
     109          17 : DECLARE_WW8EXPORT_TEST(testZoom, "zoom.doc")
     110             : {
     111           2 :     uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
     112           4 :     uno::Reference<view::XViewSettingsSupplier> xViewSettingsSupplier(xModel->getCurrentController(), uno::UNO_QUERY);
     113           4 :     uno::Reference<beans::XPropertySet> xPropertySet(xViewSettingsSupplier->getViewSettings());
     114           2 :     sal_Int16 nValue = 0;
     115           2 :     xPropertySet->getPropertyValue("ZoomValue") >>= nValue;
     116           4 :     CPPUNIT_ASSERT_EQUAL(sal_Int16(42), nValue);
     117           2 : }
     118             : 
     119          17 : DECLARE_WW8EXPORT_TEST(testZoomType, "zoomtype.doc")
     120             : {
     121           2 :     uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
     122           4 :     uno::Reference<view::XViewSettingsSupplier> xViewSettingsSupplier(xModel->getCurrentController(), uno::UNO_QUERY);
     123           4 :     uno::Reference<beans::XPropertySet> xPropertySet(xViewSettingsSupplier->getViewSettings());
     124           2 :     sal_Int16 nValue = 0;
     125           2 :     xPropertySet->getPropertyValue("ZoomType") >>= nValue;
     126           4 :     CPPUNIT_ASSERT_EQUAL(sal_Int16(view::DocumentZoomType::PAGE_WIDTH), nValue);
     127           2 : }
     128             : 
     129          17 : DECLARE_WW8EXPORT_TEST(test56513, "fdo56513.doc")
     130             : {
     131           2 :     CPPUNIT_ASSERT_EQUAL(OUString("This is the header of the first section"),  parseDump("/root/page[1]/header/txt/text()"));
     132           2 :     CPPUNIT_ASSERT_EQUAL(OUString("This is the first page header of the second section"),   parseDump("/root/page[2]/header/txt/text()"));
     133           2 :     CPPUNIT_ASSERT_EQUAL(OUString("This is the non-first-page header of the second section"),  parseDump("/root/page[3]/header/txt/text()"));
     134           2 : }
     135             : 
     136          17 : DECLARE_WW8EXPORT_TEST(testNewPageStylesTable, "new-page-styles.doc")
     137             : {
     138           2 :     CPPUNIT_ASSERT_EQUAL(OUString("Sigma Space Performance Goals and Results (Page 1)*"),  parseDump("/root/page[1]/header/txt/text()"));
     139           2 :     CPPUNIT_ASSERT_EQUAL(OUString("Sigma Space Performance Assessment (Page 2)****"),   parseDump("/root/page[2]/header/txt/text()"));
     140           2 :     CPPUNIT_ASSERT_EQUAL(OUString("Sigma Space Performance Goals: Next Year (Page 3)*******"),  parseDump("/root/page[3]/header/txt/text()"));
     141           2 : }
     142             : 
     143          16 : DECLARE_WW8EXPORT_TEST(testFdo42144, "fdo42144.odt")
     144             : {
     145             :     // Footer wasn't disabled -- instead empty footer was exported.
     146           1 :     uno::Reference<beans::XPropertySet> xStyle(getStyles("PageStyles")->getByName(DEFAULT_STYLE), uno::UNO_QUERY);
     147           1 :     CPPUNIT_ASSERT_EQUAL(false, bool(getProperty<sal_Bool>(xStyle, "FooterIsOn")));
     148           1 : }
     149             : 
     150          16 : DECLARE_WW8EXPORT_TEST(testCharacterBorder, "charborder.odt")
     151             : {
     152           1 :     uno::Reference<beans::XPropertySet> xRun(getRun(getParagraph(1),1), uno::UNO_QUERY);
     153             :     // WW8 has just one border attribute (sprmCBrc) for text border so all side has
     154             :     // the same border
     155             :     // Border
     156             :     {
     157           1 :         const table::BorderLine2 aTopBorder = getProperty<table::BorderLine2>(xRun,"CharTopBorder");
     158           1 :         CPPUNIT_ASSERT_BORDER_EQUAL(table::BorderLine2(0xFF3333,0,318,0,0,318), aTopBorder);
     159           1 :         CPPUNIT_ASSERT_BORDER_EQUAL(aTopBorder, getProperty<table::BorderLine2>(xRun,"CharLeftBorder"));
     160           1 :         CPPUNIT_ASSERT_BORDER_EQUAL(aTopBorder, getProperty<table::BorderLine2>(xRun,"CharBottomBorder"));
     161           1 :         CPPUNIT_ASSERT_BORDER_EQUAL(aTopBorder, getProperty<table::BorderLine2>(xRun,"CharRightBorder"));
     162             :     }
     163             : 
     164             :     // Padding (dptSpace) it is constant 0
     165             :     {
     166           1 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xRun,"CharTopBorderDistance"));
     167           1 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xRun,"CharLeftBorderDistance"));
     168           1 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xRun,"CharBottomBorderDistance"));
     169           1 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xRun,"CharRightBorderDistance"));
     170             :     }
     171             : 
     172             :     // Shadow (fShadow)
     173             :     /* WW8 use just one bool value for shadow so the next conversions
     174             :        are made during an export-import round
     175             :        color: any -> black
     176             :        location: any -> bottom-right
     177             :        width: any -> border width */
     178             :     {
     179           1 :         const table::ShadowFormat aShadow = getProperty<table::ShadowFormat>(xRun, "CharShadowFormat");
     180           1 :         CPPUNIT_ASSERT_EQUAL(COL_BLACK, sal_uInt32(aShadow.Color));
     181           1 :         CPPUNIT_ASSERT_EQUAL(table::ShadowLocation_BOTTOM_RIGHT, aShadow.Location);
     182           1 :         CPPUNIT_ASSERT_EQUAL(sal_Int16(318), aShadow.ShadowWidth);
     183           1 :     }
     184           1 : }
     185             : 
     186          17 : DECLARE_WW8EXPORT_TEST(testFdo77454, "fdo77454.doc")
     187             : {
     188             :     {
     189             :         // check negative crops round-trip
     190             :         text::GraphicCrop const crop =
     191           2 :             getProperty<text::GraphicCrop>(getShape(1), "GraphicCrop");
     192           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int32( -439), crop.Left);
     193           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(-7040), crop.Right);
     194           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int32( -220), crop.Top);
     195           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(-7040), crop.Bottom);
     196             :     }
     197             : 
     198             :     {
     199             :         // check positive crops round-trip
     200             :         text::GraphicCrop const crop =
     201           2 :             getProperty<text::GraphicCrop>(getShape(2), "GraphicCrop");
     202           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(  326), crop.Left);
     203           2 :         CPPUNIT_ASSERT_EQUAL(sal_Int32( 1208), crop.Right);
     204           2 :         CPPUNIT_ASSERT(abs(sal_Int32(1635) -  crop.Top) <= 2);
     205           2 :         CPPUNIT_ASSERT(abs(sal_Int32(  95) - crop.Bottom) <= 2);
     206             :     }
     207           2 : }
     208             : 
     209          17 : DECLARE_WW8EXPORT_TEST(testFdo59530, "fdo59530.doc")
     210             : {
     211             :     // See ooxmlexport's testFdo38244().
     212             :     // Test comment range feature.
     213           2 :     uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
     214           4 :     uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
     215           4 :     uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
     216           4 :     uno::Reference<container::XEnumerationAccess> xRunEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY);
     217           4 :     uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration();
     218           2 :     xRunEnum->nextElement();
     219           4 :     uno::Reference<beans::XPropertySet> xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY);
     220           2 :     CPPUNIT_ASSERT_EQUAL(OUString("Annotation"), getProperty<OUString>(xPropertySet, "TextPortionType"));
     221           2 :     xRunEnum->nextElement();
     222           2 :     xPropertySet.set(xRunEnum->nextElement(), uno::UNO_QUERY);
     223           2 :     CPPUNIT_ASSERT_EQUAL(OUString("AnnotationEnd"), getProperty<OUString>(xPropertySet, "TextPortionType"));
     224             : 
     225             :     // Test initials.
     226           4 :     uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
     227           4 :     uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
     228           4 :     uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
     229           2 :     xPropertySet.set(xFields->nextElement(), uno::UNO_QUERY);
     230           2 :     CPPUNIT_ASSERT_EQUAL(OUString("M"), getProperty<OUString>(xPropertySet, "Initials"));
     231             : 
     232             :     // Test commented text range which spans over more text nodes
     233             :     // Comment starts in the second paragraph
     234           2 :     xRunEnumAccess.set(xParaEnum->nextElement(), uno::UNO_QUERY);
     235           2 :     xRunEnum = xRunEnumAccess->createEnumeration();
     236           2 :     xRunEnum->nextElement();
     237           2 :     xPropertySet.set(xRunEnum->nextElement(), uno::UNO_QUERY);
     238           2 :     CPPUNIT_ASSERT_EQUAL(OUString("Annotation"), getProperty<OUString>(xPropertySet, "TextPortionType"));
     239             :     // Comment ends in the third paragraph
     240           2 :     xRunEnumAccess.set(xParaEnum->nextElement(), uno::UNO_QUERY);
     241           2 :     xRunEnum = xRunEnumAccess->createEnumeration();
     242           2 :     xRunEnum->nextElement();
     243           2 :     xPropertySet.set(xRunEnum->nextElement(), uno::UNO_QUERY);
     244           4 :     CPPUNIT_ASSERT_EQUAL(OUString("AnnotationEnd"), getProperty<OUString>(xPropertySet, "TextPortionType"));
     245           2 : }
     246             : 
     247          17 : DECLARE_WW8EXPORT_TEST(testCommentsNested, "comments-nested.doc")
     248             : {
     249           2 :     uno::Reference<beans::XPropertySet> xOuter(getProperty< uno::Reference<beans::XPropertySet> >(getRun(getParagraph(1), 2), "TextField"), uno::UNO_QUERY);
     250           2 :     CPPUNIT_ASSERT_EQUAL(OUString("Outer"), getProperty<OUString>(xOuter, "Content"));
     251             : 
     252           4 :     uno::Reference<beans::XPropertySet> xInner(getProperty< uno::Reference<beans::XPropertySet> >(getRun(getParagraph(1), 4), "TextField"), uno::UNO_QUERY);
     253           4 :     CPPUNIT_ASSERT_EQUAL(OUString("Inner"), getProperty<OUString>(xInner, "Content"));
     254           2 : }
     255             : 
     256          16 : DECLARE_WW8EXPORT_TEST(testBorderColoursExport, "bordercolours.odt")
     257             : {
     258             :     // This is very close to testBorderColours in ww8import.cxx, but for export
     259             : 
     260             :     // The following 6 colours can only be represented with WW9 (Word 2000)
     261             :     // BRC (BoRder Control) structures.  We can tell that they have been
     262             :     // exported/imported using a WW8 (Word '97) BRC if they instead come
     263             :     // through as one of the 16 colours listed at this link:
     264             :     // http://msdn.microsoft.com/en-us/library/dd773060.aspx
     265           1 :     table::BorderLine2 expectedTop(0xFA670C, 0, 53, 0, 1, 53);
     266           1 :     table::BorderLine2 expectedLeft(0xD99594, 0, 79, 0, 0, 79);
     267           1 :     table::BorderLine2 expectedRight(0xB2A1C7, 53, 53, 53, 3, 159);
     268           1 :     table::BorderLine2 expectedBottom(0xB6DDE8, 0, 106, 0, 14, 106);
     269           1 :     table::BorderLine2 expectedDashedRed(0xFA670C, 0, 53, 0, 2, 53);
     270           1 :     table::BorderLine2 expectedDoubleGreen(0xC2D69B, 26, 106, 26, 4, 159);
     271             : 
     272             :     // Paragraph border
     273             :     uno::Reference<text::XBookmarksSupplier> bookmarksSupplier(mxComponent,
     274           1 :         uno::UNO_QUERY);
     275             :     uno::Reference<container::XNameAccess> bookmarks(
     276           2 :         bookmarksSupplier->getBookmarks(), uno::UNO_QUERY);
     277             :     uno::Reference<text::XTextContent> bookmark(
     278           2 :         bookmarks->getByName("ParagraphBorder"), uno::UNO_QUERY);
     279           2 :     uno::Reference<text::XTextRange> anchor(bookmark->getAnchor());
     280           1 :     table::BorderLine2 border;
     281           1 :     border = getProperty<table::BorderLine2>(anchor, "TopBorder");
     282           1 :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border);
     283           1 :     border = getProperty<table::BorderLine2>(anchor, "LeftBorder");
     284           1 :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedLeft, border);
     285           1 :     border = getProperty<table::BorderLine2>(anchor, "RightBorder");
     286           1 :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border);
     287           1 :     border = getProperty<table::BorderLine2>(anchor, "BottomBorder");
     288           1 :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedBottom, border);
     289             : 
     290             :     // Page border
     291           2 :     OUString pageStyleName = getProperty<OUString>(anchor, "PageStyleName");
     292             :     uno::Reference<style::XStyle> pageStyle(
     293           2 :         getStyles("PageStyles")->getByName(pageStyleName), uno::UNO_QUERY);
     294           1 :     border = getProperty<table::BorderLine2>(pageStyle, "TopBorder");
     295           1 :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border);
     296           1 :     border = getProperty<table::BorderLine2>(pageStyle, "LeftBorder");
     297           1 :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedLeft, border);
     298           1 :     border = getProperty<table::BorderLine2>(pageStyle, "RightBorder");
     299           1 :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border);
     300           1 :     border = getProperty<table::BorderLine2>(pageStyle, "BottomBorder");
     301           1 :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedBottom, border);
     302             : 
     303             :     // Character border
     304           1 :     bookmark.set(bookmarks->getByName("CharBorder"), uno::UNO_QUERY);
     305           1 :     anchor = bookmark->getAnchor();
     306           1 :     border = getProperty<table::BorderLine2>(anchor, "CharTopBorder");
     307           1 :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border);
     308           1 :     border = getProperty<table::BorderLine2>(anchor, "CharLeftBorder");
     309           1 :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border);
     310           1 :     border = getProperty<table::BorderLine2>(anchor, "CharRightBorder");
     311           1 :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border);
     312           1 :     border = getProperty<table::BorderLine2>(anchor, "CharBottomBorder");
     313           1 :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border);
     314             : 
     315             :     // Table border
     316             :     uno::Reference<text::XTextTablesSupplier> tablesSupplier(mxComponent,
     317           2 :         uno::UNO_QUERY);
     318             :     uno::Reference<container::XNameAccess> tables(
     319           2 :         tablesSupplier->getTextTables(), uno::UNO_QUERY);
     320             :     uno::Reference<text::XTextTable> table(
     321           2 :         tables->getByName("Table1"), uno::UNO_QUERY);
     322             :     table::TableBorder2 tableBorder = getProperty<table::TableBorder2>(
     323           1 :         table, "TableBorder2");
     324           1 :     CPPUNIT_ASSERT_EQUAL(expectedTop.Color, tableBorder.TopLine.Color);
     325           1 :     CPPUNIT_ASSERT_EQUAL(expectedLeft.Color, tableBorder.LeftLine.Color);
     326           1 :     CPPUNIT_ASSERT_EQUAL(expectedRight.Color, tableBorder.RightLine.Color);
     327             : #if 0
     328             :     // #if'd out because the "fine dashed" border line style for table borders
     329             :     // does not seem to save or load correctly in odt format at present
     330             :     CPPUNIT_ASSERT_EQUAL(expectedBottom.Color, tableBorder.BottomLine.Color);
     331             : #endif
     332             : 
     333             :     // Table cells
     334             :     uno::Reference<table::XCell> cell(
     335           2 :         table->getCellByName("A2"), uno::UNO_QUERY);
     336           1 :     border = getProperty<table::BorderLine2>(cell, "TopBorder");
     337           1 :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border);
     338           1 :     border = getProperty<table::BorderLine2>(cell, "LeftBorder");
     339           1 :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedLeft, border);
     340           1 :     border = getProperty<table::BorderLine2>(cell, "BottomBorder");
     341             : #if 0
     342             :     // #if'd out because the "fine dashed" border line style for table borders
     343             :     // does not seem to save or load correctly in odt format at present
     344             :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedBottom, border);
     345             : #endif
     346             : 
     347           1 :     cell.set(table->getCellByName("B2"), uno::UNO_QUERY);
     348           1 :     border = getProperty<table::BorderLine2>(cell, "TopBorder");
     349           1 :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedDoubleGreen, border);
     350           1 :     border = getProperty<table::BorderLine2>(cell, "LeftBorder");
     351           1 :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border);
     352           1 :     border = getProperty<table::BorderLine2>(cell, "BottomBorder");
     353           1 :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedDoubleGreen, border);
     354             : 
     355           1 :     cell.set(table->getCellByName("C2"), uno::UNO_QUERY);
     356           1 :     border = getProperty<table::BorderLine2>(cell, "TopBorder");
     357           1 :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedDoubleGreen, border);
     358           1 :     border = getProperty<table::BorderLine2>(cell, "LeftBorder");
     359           1 :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedDashedRed, border);
     360           1 :     border = getProperty<table::BorderLine2>(cell, "RightBorder");
     361           1 :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border);
     362           1 :     border = getProperty<table::BorderLine2>(cell, "BottomBorder");
     363           2 :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedDoubleGreen, border);
     364             : 
     365             :     // Picture border
     366             :     // (#if'd out as they are not yet exported with correct colours)
     367             : #if 0
     368             :     bookmark.set(bookmarks->getByName("PictureBorder"),uno::UNO_QUERY);
     369             :     anchor = bookmark->getAnchor();
     370             :     border = getProperty<table::BorderLine2>(anchor, "TopBorder");
     371             :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border);
     372             :     border = getProperty<table::BorderLine2>(anchor, "LeftBorder");
     373             :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedLeft, border);
     374             :     border = getProperty<table::BorderLine2>(anchor, "RightBorder");
     375             :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border);
     376             :     border = getProperty<table::BorderLine2>(anchor, "BottomBorder");
     377             :     CPPUNIT_ASSERT_BORDER_EQUAL(expectedBottom, border);
     378             : #endif
     379           1 : }
     380             : 
     381          16 : DECLARE_WW8EXPORT_TEST(testRedlineExport1, "redline-export-1.odt")
     382             : {
     383           1 :     uno::Reference<text::XTextRange> xParagraph = getParagraph(1);
     384           2 :     uno::Reference<container::XEnumerationAccess> xRunEnumAccess(xParagraph, uno::UNO_QUERY);
     385           2 :     uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration();
     386             :     //there must be no redline information on the first line before and after reloading
     387           3 :     while (xRunEnum->hasMoreElements())
     388             :     {
     389           1 :         uno::Reference<text::XTextRange> xRun(xRunEnum->nextElement(), uno::UNO_QUERY);
     390           1 :         CPPUNIT_ASSERT_EQUAL(false, hasProperty(xRun, "RedlineType"));
     391           2 :     }
     392           1 : }
     393             : 
     394          16 : DECLARE_WW8EXPORT_TEST(testRedlineExport2, "redline-export-2.odt")
     395             : {
     396             :     //there must be redline information on the first portion of the third paragraph before and after reloading
     397           1 :     CPPUNIT_ASSERT_EQUAL(true, hasProperty(getRun(getParagraph(3), 1), "RedlineType"));
     398           1 : }
     399             : 
     400          16 : DECLARE_WW8EXPORT_TEST(testRedlineExport3, "redline-export-3.odt")
     401             : {
     402             :     //there must be redline information just on the para-break boundary between para one and two
     403           1 :     CPPUNIT_ASSERT_EQUAL(false, hasProperty(getRun(getParagraph(1), 1), "RedlineType"));
     404           1 :     CPPUNIT_ASSERT_EQUAL(true, hasProperty(getRun(getParagraph(1), 2), "RedlineType"));
     405           1 :     CPPUNIT_ASSERT_EQUAL(true, hasProperty(getRun(getParagraph(2), 1), "RedlineType"));
     406           1 :     CPPUNIT_ASSERT_EQUAL(false, hasProperty(getRun(getParagraph(2), 2), "RedlineType"));
     407           1 : }
     408             : 
     409          16 : DECLARE_WW8EXPORT_TEST(testCellBgColor, "cell-bg-color.odt")
     410             : {
     411           1 :     uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
     412           2 :     uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), uno::UNO_QUERY);
     413           2 :     uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
     414           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(0xCC0000), getProperty<sal_Int32>(xTable->getCellByName("A1"), "BackColor"));
     415           1 : }
     416             : 
     417          17 : DECLARE_WW8EXPORT_TEST(testBnc636128, "bnc636128.doc")
     418             : {
     419             :     // Import / export of FFData.cch was missing.
     420           2 :     uno::Reference<text::XFormField> xFormField = getProperty< uno::Reference<text::XFormField> >(getRun(getParagraph(1), 2), "Bookmark");
     421           4 :     uno::Reference<container::XNameContainer> xParameters = xFormField->getParameters();
     422             :     // This resulted in a container.NoSuchElementException.
     423           4 :     CPPUNIT_ASSERT_EQUAL(OUString("5"), xParameters->getByName("MaxLength").get<OUString>());
     424           2 : }
     425             : 
     426             : 
     427          17 : DECLARE_WW8EXPORT_TEST(testWw8Cjklist30, "cjklist30.doc")
     428             : {
     429             :     sal_Int16   numFormat;
     430           2 :     CPPUNIT_ASSERT(CjkNumberedListTestHelper(numFormat));
     431           2 :     CPPUNIT_ASSERT_EQUAL(style::NumberingType::TIAN_GAN_ZH, numFormat);
     432           2 : }
     433             : 
     434          17 : DECLARE_WW8EXPORT_TEST(testWw8Cjklist31, "cjklist31.doc")
     435             : {
     436             :     sal_Int16   numFormat;
     437           2 :     CPPUNIT_ASSERT(CjkNumberedListTestHelper(numFormat));
     438           2 :     CPPUNIT_ASSERT_EQUAL(style::NumberingType::DI_ZI_ZH, numFormat);
     439           2 : }
     440             : 
     441          17 : DECLARE_WW8EXPORT_TEST(testWw8Cjklist34, "cjklist34.doc")
     442             : {
     443             :     sal_Int16   numFormat;
     444           2 :     CPPUNIT_ASSERT(CjkNumberedListTestHelper(numFormat));
     445           2 :     CPPUNIT_ASSERT_EQUAL(style::NumberingType::NUMBER_UPPER_ZH_TW, numFormat);
     446           2 : }
     447             : 
     448          17 : DECLARE_WW8EXPORT_TEST(testWw8Cjklist35, "cjklist35.doc")
     449             : {
     450             :     sal_Int16   numFormat;
     451           2 :     CPPUNIT_ASSERT(CjkNumberedListTestHelper(numFormat));
     452           2 :     CPPUNIT_ASSERT_EQUAL(style::NumberingType::NUMBER_LOWER_ZH, numFormat);
     453           2 : }
     454             : 
     455          17 : DECLARE_WW8EXPORT_TEST(testCommentedTable, "commented-table.doc")
     456             : {
     457             :     // Document has a non-trivial commented text range, as the range contains a table.
     458           2 :     uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
     459           4 :     uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
     460           4 :     uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
     461           4 :     uno::Reference<text::XTextContent> xField(xFields->nextElement(), uno::UNO_QUERY);
     462             :     // After first import, there was an off-by-one during import, so this was "efore.\nA1\nB1\nAfte". (Notice the additional "e" prefix.)
     463             :     // After export and import, things got worse, this was "\nA1\nB1\nAfte".
     464           4 :     CPPUNIT_ASSERT_EQUAL(OUString("fore." SAL_NEWLINE_STRING "A1" SAL_NEWLINE_STRING "B1" SAL_NEWLINE_STRING "Afte"), xField->getAnchor()->getString());
     465           2 : }
     466             : 
     467          16 : DECLARE_WW8EXPORT_TEST(testCommentExport, "comment-export.odt")
     468             : {
     469          20 :     struct TextPortionInfo {
     470             :         OUString sKind;
     471             :         OUString sText;
     472             :         int nAnnotationID;
     473             :     };
     474             : 
     475             :     const TextPortionInfo aTextPortions[] = {
     476             :         {OUString("Annotation"), OUString("Comment on [A...A]"), 0},
     477             :         {OUString("Text"), OUString("[A xx "), 0},
     478             :         {OUString("Annotation"), OUString("Comment on [B...B]"), 1},
     479             :         {OUString("Text"), OUString("[B x "), 0},
     480             :         {OUString("Annotation"), OUString("Comment on [C..C]"), 2},
     481             :         {OUString("Text"), OUString("[C x B]"), 0},
     482             :         {OUString("AnnotationEnd"), OUString(""), 1},
     483             :         {OUString("Text"), OUString(" x C]"), 0},
     484             :         {OUString("AnnotationEnd"), OUString(""), 2},
     485             :         {OUString("Text"), OUString(" xx A]"), 0},
     486             :         {OUString("AnnotationEnd"), OUString(""), 0},
     487             :         {OUString("Text"), OUString(" Comment on a point"), 0},
     488             :         {OUString("Annotation"), OUString("Comment on point"), 3},
     489             :         {OUString("Text"), OUString("x "), 0},
     490             :         {OUString("Annotation"), OUString("Comment on AA...BB"), 4},
     491             :         {OUString("Annotation"), OUString("Comment on AAAAAA"), 5},
     492             :         {OUString("Text"), OUString("AAAAAA"), 0},
     493             :         {OUString("AnnotationEnd"), OUString(""), 5},
     494             :         {OUString("Text"), OUString(" BBBBBB"), 0},
     495             :         {OUString("AnnotationEnd"), OUString(""), 4}
     496          21 :     };
     497             : 
     498           2 :     OUString sNames[6];
     499             : 
     500           1 :     const int nNumberOfTextPortions = sizeof(aTextPortions) / (sizeof(TextPortionInfo));
     501             : 
     502           2 :     uno::Reference<text::XTextRange> xPara = getParagraph(1);
     503             : 
     504          21 :     for (int i = 0; i < nNumberOfTextPortions; ++i)
     505             :     {
     506          20 :         OUString sKind = aTextPortions[i].sKind;
     507          40 :         uno::Reference<text::XTextRange> xRun(getRun(xPara, i + 1), uno::UNO_QUERY);
     508          40 :         uno::Reference<beans::XPropertySet> xPropertySet(xRun, uno::UNO_QUERY);
     509          20 :         CPPUNIT_ASSERT_EQUAL(sKind, getProperty<OUString>(xPropertySet, "TextPortionType"));
     510             : 
     511          20 :         if (sKind == "Text")
     512             :         {
     513             :             // Check if textportion has the correct text
     514           9 :             CPPUNIT_ASSERT_EQUAL(aTextPortions[i].sText, xRun->getString());
     515             :         }
     516          11 :         else if (sKind == "Annotation")
     517             :         {
     518             :             // Check if the comment text is correct and save the name of the comment
     519           6 :             uno::Reference<beans::XPropertySet> xComment(getProperty< uno::Reference<beans::XPropertySet> >(xRun, "TextField"), uno::UNO_QUERY);
     520           6 :             CPPUNIT_ASSERT_EQUAL(aTextPortions[i].sText, getProperty<OUString>(xComment, "Content"));
     521           6 :             sNames[aTextPortions[i].nAnnotationID] = getProperty<OUString>(xComment, "Name");
     522             :         }
     523             :         else // if (sKind == OUString("AnnotationEnd"))
     524             :         {
     525             :             // Check if the correct Annotation ends here (by Name)
     526           5 :             uno::Reference<container::XNamed> xBookmark(getProperty< uno::Reference<beans::XPropertySet> >(xRun, "Bookmark"), uno::UNO_QUERY);
     527           5 :             CPPUNIT_ASSERT_EQUAL(sNames[aTextPortions[i].nAnnotationID], xBookmark->getName());
     528             :         }
     529          41 :     }
     530           1 : }
     531             : 
     532           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     533             : 
     534             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11