LCOV - code coverage report
Current view: top level - libreoffice/sw/qa/extras/ooxmlexport - ooxmlexport.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 245 246 99.6 %
Date: 2012-12-17 Functions: 36 37 97.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       3             :  *
       4             :  * The contents of this file are subject to the Mozilla Public License Version
       5             :  * 1.1 (the "License"); you may not use this file except in compliance with
       6             :  * the License. You may obtain a copy of the License at
       7             :  * http://www.mozilla.org/MPL/
       8             :  *
       9             :  * Software distributed under the License is distributed on an "AS IS" basis,
      10             :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      11             :  * for the specific language governing rights and limitations under the
      12             :  * License.
      13             :  *
      14             :  * The Initial Developer of the Original Code is
      15             :  *       Miklos Vajna <vmiklos@suse.cz> (SUSE, Inc.)
      16             :  * Portions created by the Initial Developer are Copyright (C) 2012 the
      17             :  * Initial Developer. All Rights Reserved.
      18             :  *
      19             :  * Contributor(s):
      20             :  *
      21             :  * Alternatively, the contents of this file may be used under the terms of
      22             :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      23             :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      24             :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      25             :  * instead of those above.
      26             :  */
      27             : 
      28             : #include <com/sun/star/frame/XStorable.hpp>
      29             : #include <com/sun/star/style/TabStop.hpp>
      30             : #include <com/sun/star/view/XViewSettingsSupplier.hpp>
      31             : #include <com/sun/star/text/XTextFrame.hpp>
      32             : #include <com/sun/star/text/XTextTable.hpp>
      33             : #include <com/sun/star/text/XTextFramesSupplier.hpp>
      34             : #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
      35             : #include <com/sun/star/style/ParagraphAdjust.hpp>
      36             : #include <com/sun/star/view/XSelectionSupplier.hpp>
      37             : #include <com/sun/star/table/BorderLine2.hpp>
      38             : 
      39             : #include <unotools/tempfile.hxx>
      40             : #include <swmodeltestbase.hxx>
      41             : 
      42           6 : class Test : public SwModelTestBase
      43             : {
      44             : public:
      45             :     void testZoom();
      46             :     void defaultTabStopNotInStyles();
      47             :     void testFdo38244();
      48             :     void testMathEscape();
      49             :     void testFdo51034();
      50             :     void testMathAccents();
      51             :     void testMathD();
      52             :     void testMathEscaping();
      53             :     void testMathLim();
      54             :     void testMathMalformedXml();
      55             :     void testMathMatrix();
      56             :     void testMathMso2k7();
      57             :     void testMathNary();
      58             :     void testMathOverbraceUnderbrace();
      59             :     void testMathOverstrike();
      60             :     void testMathPlaceholders();
      61             :     void testMathRad();
      62             :     void testMathSubscripts();
      63             :     void testMathVerticalStacks();
      64             :     void testTablePosition();
      65             :     void testFdo47669();
      66             :     void testTableBorders();
      67             :     void testFdo51550();
      68             :     void testN789482();
      69             : 
      70           4 :     CPPUNIT_TEST_SUITE(Test);
      71             : #if !defined(MACOSX) && !defined(WNT)
      72           2 :     CPPUNIT_TEST(run);
      73             : #endif
      74           4 :     CPPUNIT_TEST_SUITE_END();
      75             : 
      76             : private:
      77             :     void run();
      78             : };
      79             : 
      80           2 : void Test::run()
      81             : {
      82             :     MethodEntry<Test> aMethods[] = {
      83             :         {"zoom.docx", &Test::testZoom},
      84             :         {"empty.odt", &Test::defaultTabStopNotInStyles},
      85             :         {"fdo38244.docx", &Test::testFdo38244},
      86             :         {"math-escape.docx", &Test::testMathEscape},
      87             :         {"fdo51034.odt", &Test::testFdo51034},
      88             :         {"math-accents.docx", &Test::testMathAccents},
      89             :         {"math-d.docx", &Test::testMathD},
      90             :         {"math-escaping.docx", &Test::testMathEscaping},
      91             :         {"math-lim.docx", &Test::testMathLim},
      92             :         {"math-malformed_xml.docx", &Test::testMathMalformedXml},
      93             :         {"math-matrix.docx", &Test::testMathMatrix},
      94             :         {"math-mso2k7.docx", &Test::testMathMso2k7},
      95             :         {"math-nary.docx", &Test::testMathNary},
      96             :         {"math-overbrace_underbrace.docx", &Test::testMathOverbraceUnderbrace},
      97             :         {"math-overstrike.docx", &Test::testMathOverstrike},
      98             :         {"math-placeholders.docx", &Test::testMathPlaceholders},
      99             :         {"math-rad.docx", &Test::testMathRad},
     100             :         {"math-subscripts.docx", &Test::testMathSubscripts},
     101             :         {"math-vertical_stacks.docx", &Test::testMathVerticalStacks},
     102             :         {"table-position.docx", &Test::testTablePosition},
     103             :         {"fdo47669.docx", &Test::testFdo47669},
     104             :         {"table-borders.docx", &Test::testTableBorders},
     105             :         {"fdo51550.odt", &Test::testFdo51550},
     106             :         {"n789482.docx", &Test::testN789482},
     107           2 :     };
     108             :     // Don't test the first import of these, for some reason those tests fail
     109             :     const char* aBlacklist[] = {
     110             :         "math-escape.docx",
     111             :         "math-mso2k7.docx",
     112           2 :     };
     113           2 :     std::vector<const char*> vBlacklist(aBlacklist, aBlacklist + SAL_N_ELEMENTS(aBlacklist));
     114          50 :     for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
     115             :     {
     116          48 :         MethodEntry<Test>& rEntry = aMethods[i];
     117          48 :         mxComponent = loadFromDesktop(getURLFromSrc("/sw/qa/extras/ooxmlexport/data/") + OUString::createFromAscii(rEntry.pName));
     118             :         // If the testcase is stored in some other format, it's pointless to test.
     119          48 :         if (OString(rEntry.pName).endsWith(".docx") && std::find(vBlacklist.begin(), vBlacklist.end(), rEntry.pName) == vBlacklist.end())
     120          38 :             (this->*rEntry.pMethod)();
     121          48 :         uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
     122          48 :         uno::Sequence<beans::PropertyValue> aArgs(1);
     123          48 :         aArgs[0].Name = "FilterName";
     124          48 :         aArgs[0].Value <<= OUString("Office Open XML Text");
     125          48 :         utl::TempFile aTempFile;
     126          48 :         aTempFile.EnableKillingFile();
     127          48 :         xStorable->storeToURL(aTempFile.GetURL(), aArgs);
     128          48 :         uno::Reference<lang::XComponent> xComponent(xStorable, uno::UNO_QUERY);
     129          48 :         xComponent->dispose();
     130          48 :         mxComponent = loadFromDesktop(aTempFile.GetURL());
     131          48 :         (this->*rEntry.pMethod)();
     132          50 :     }
     133           2 : }
     134             : 
     135           4 : void Test::testZoom()
     136             : {
     137           4 :     uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
     138           4 :     uno::Reference<view::XViewSettingsSupplier> xViewSettingsSupplier(xModel->getCurrentController(), uno::UNO_QUERY);
     139           4 :     uno::Reference<beans::XPropertySet> xPropertySet(xViewSettingsSupplier->getViewSettings());
     140           4 :     sal_Int16 nValue = 0;
     141           4 :     xPropertySet->getPropertyValue("ZoomValue") >>= nValue;
     142           4 :     CPPUNIT_ASSERT_EQUAL(sal_Int16(42), nValue);
     143           4 : }
     144             : 
     145           2 : void Test::defaultTabStopNotInStyles()
     146             : {
     147             : // The default tab stop was mistakenly exported to a style.
     148             : // xray ThisComponent.StyleFamilies(1)(0).ParaTabStop
     149           2 :     uno::Reference< container::XNameAccess > paragraphStyles = getStyles( "ParagraphStyles" );
     150           2 :     uno::Reference< beans::XPropertySet > properties( paragraphStyles->getByName( "Standard" ), uno::UNO_QUERY );
     151             :     uno::Sequence< style::TabStop > stops = getProperty< uno::Sequence< style::TabStop > >(
     152           2 :         paragraphStyles->getByName( "Standard" ), "ParaTabStops" );
     153             : // There actually be be one tab stop, but it will be the default.
     154           2 :     CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(1), stops.getLength());
     155           2 :     CPPUNIT_ASSERT_EQUAL( style::TabAlign_DEFAULT, stops[ 0 ].Alignment );
     156           2 : }
     157             : 
     158           4 : void Test::testFdo38244()
     159             : {
     160             :     /*
     161             :      * Comments attached to a range was imported without the range, check for the fieldmark start/end positions.
     162             :      *
     163             :      * oParas = ThisComponent.Text.createEnumeration
     164             :      * oPara = oParas.nextElement
     165             :      * oRuns = oPara.createEnumeration
     166             :      * oRun = oRuns.nextElement
     167             :      * oRun = oRuns.nextElement 'TextFieldStart
     168             :      * oRun = oRuns.nextElement
     169             :      * oRun = oRuns.nextElement 'TextFieldEnd
     170             :      * xray oRun.TextPortionType
     171             :      */
     172           4 :     uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
     173           4 :     uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
     174           4 :     uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
     175           4 :     uno::Reference<container::XEnumerationAccess> xRunEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY);
     176           4 :     uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration();
     177           4 :     xRunEnum->nextElement();
     178           4 :     uno::Reference<beans::XPropertySet> xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY);
     179           4 :     CPPUNIT_ASSERT_EQUAL(OUString("TextFieldStart"), getProperty<OUString>(xPropertySet, "TextPortionType"));
     180           4 :     xRunEnum->nextElement();
     181           4 :     xPropertySet.set(xRunEnum->nextElement(), uno::UNO_QUERY);
     182           4 :     CPPUNIT_ASSERT_EQUAL(OUString("TextFieldEnd"), getProperty<OUString>(xPropertySet, "TextPortionType"));
     183             : 
     184             :     /*
     185             :      * Initials were not imported.
     186             :      *
     187             :      * oFields = ThisComponent.TextFields.createEnumeration
     188             :      * oField = oFields.nextElement
     189             :      * xray oField.Initials
     190             :      */
     191           4 :     uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
     192           4 :     uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
     193           4 :     uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
     194           4 :     xPropertySet.set(xFields->nextElement(), uno::UNO_QUERY);
     195           4 :     CPPUNIT_ASSERT_EQUAL(OUString("M"), getProperty<OUString>(xPropertySet, "Initials"));
     196             : 
     197             :     /*
     198             :      * There was a fake empty paragraph at the end of the comment text.
     199             :      *
     200             :      * oFields = ThisComponent.TextFields.createEnumeration
     201             :      * oField = oFields.nextElement
     202             :      * oParas = oField.TextRange.createEnumeration
     203             :      * oPara = oParas.nextElement
     204             :      * oPara = oParas.nextElement
     205             :      */
     206             : 
     207           4 :     xParaEnumAccess.set(getProperty< uno::Reference<container::XEnumerationAccess> >(xPropertySet, "TextRange"), uno::UNO_QUERY);
     208           4 :     xParaEnum = xParaEnumAccess->createEnumeration();
     209           4 :     xParaEnum->nextElement();
     210           4 :     bool bCaught = false;
     211             :     try
     212             :     {
     213           4 :         xParaEnum->nextElement();
     214             :     }
     215           8 :     catch (container::NoSuchElementException&)
     216             :     {
     217           4 :         bCaught = true;
     218             :     }
     219           4 :     CPPUNIT_ASSERT_EQUAL(true, bCaught);
     220           4 : }
     221             : 
     222           2 : void Test::testMathEscape()
     223             : {
     224           2 :     CPPUNIT_ASSERT_EQUAL(OUString("\\{ left [ right ] left ( right ) \\}"), getFormula(getRun(getParagraph(1), 1)));
     225           2 : }
     226             : 
     227           2 : void Test::testFdo51034()
     228             : {
     229             :     // The problem was that the 'l' param of the HYPERLINK field was parsed with = "#", not += "#".
     230           2 :     CPPUNIT_ASSERT_EQUAL(OUString("http://Www.google.com/#a"), getProperty<OUString>(getRun(getParagraph(1), 1), "HyperLinkURL"));
     231           2 : }
     232             : 
     233             : // Construct the expected formula from UTF8, as there may be such characters.
     234             : // Remove all spaces, as LO export/import may change that.
     235             : // Replace symbol - (i.e. U+2212) with ASCII - , LO does this change and it shouldn't matter.
     236             : #define CHECK_FORMULA( expected, actual ) \
     237             :     CPPUNIT_ASSERT_EQUAL( \
     238             :         OUString( expected, strlen( expected ), RTL_TEXTENCODING_UTF8 ) \
     239             :             .replaceAll( " ", "" ).replaceAll( OUString( "−", strlen( "−" ), RTL_TEXTENCODING_UTF8 ), "-" ), \
     240             :         OUString( actual ).replaceAll( " ", "" ).replaceAll( OUString( "−", strlen( "−" ), RTL_TEXTENCODING_UTF8 ), "-" ))
     241             : 
     242           4 : void Test::testMathAccents()
     243             : {
     244           8 :     CHECK_FORMULA(
     245             :         "acute {a} grave {a} check {a} breve {a} circle {a} widevec {a} widetilde {a}"
     246             :             " widehat {a} dot {a} widevec {a} widevec {a} widetilde {a} underline {a}",
     247           4 :         getFormula( getRun( getParagraph( 1 ), 1 )));
     248           4 : }
     249             : 
     250           4 : void Test::testMathD()
     251             : {
     252           4 :     CHECK_FORMULA( "left (x mline y mline z right )", getFormula( getRun( getParagraph( 1 ), 1 )));
     253           4 :     CHECK_FORMULA( "left (1 right )", getFormula( getRun( getParagraph( 1 ), 2 )));
     254           4 :     CHECK_FORMULA( "left [2 right ]", getFormula( getRun( getParagraph( 1 ), 3 )));
     255           4 :     CHECK_FORMULA( "left ldbracket 3 right rdbracket", getFormula( getRun( getParagraph( 1 ), 4 )));
     256           4 :     CHECK_FORMULA( "left lline 4 right rline", getFormula( getRun( getParagraph( 1 ), 5 )));
     257           4 :     CHECK_FORMULA( "left ldline 5 right rdline", getFormula( getRun( getParagraph( 1 ), 6 )));
     258           4 :     CHECK_FORMULA( "left langle 6 right rangle", getFormula( getRun( getParagraph( 1 ), 7 )));
     259           4 :     CHECK_FORMULA( "left langle a mline b right rangle", getFormula( getRun( getParagraph( 1 ), 8 )));
     260           4 :     CHECK_FORMULA( "left ({x} over {y} right )", getFormula( getRun( getParagraph( 1 ), 9 )));
     261           4 : }
     262             : 
     263           4 : void Test::testMathEscaping()
     264             : {
     265           4 :     CHECK_FORMULA( "− ∞ < x < ∞", getFormula( getRun( getParagraph( 1 ), 1 )));
     266           4 : }
     267             : 
     268           4 : void Test::testMathLim()
     269             : {
     270           4 :     CHECK_FORMULA( "lim from {x → 1} {x}", getFormula( getRun( getParagraph( 1 ), 1 )));
     271           4 : }
     272             : 
     273           4 : void Test::testMathMalformedXml()
     274             : {
     275           4 :     CPPUNIT_ASSERT_EQUAL( 0, getLength());
     276           4 : }
     277             : 
     278           4 : void Test::testMathMatrix()
     279             : {
     280           4 :     CHECK_FORMULA( "left [matrix {1 # 2 ## 3 # 4} right ]", getFormula( getRun( getParagraph( 1 ), 1 )));
     281           4 : }
     282             : 
     283           2 : void Test::testMathMso2k7()
     284             : {
     285           2 :     CHECK_FORMULA( "A = π {r} ^ {2}", getFormula( getRun( getParagraph( 1 ), 1 )));
     286             : // TODO check the stack/binom difference
     287             : //    CHECK_FORMULA( "{left (x+a right )} ^ {n} = sum from {k=0} to {n} {left (binom {n} {k} right ) {x} ^ {k} {a} ^ {n-k}}",
     288           4 :     CHECK_FORMULA( "{left (x+a right )} ^ {n} = sum from {k=0} to {n} {left (stack {n # k} right ) {x} ^ {k} {a} ^ {n-k}}",
     289           2 :         getFormula( getRun( getParagraph( 2 ), 1 )));
     290           4 :     CHECK_FORMULA( "{left (1+x right )} ^ {n} =1+ {nx} over {1!} + {n left (n-1 right ) {x} ^ {2}} over {2!} +…",
     291           2 :         getFormula( getRun( getParagraph( 3 ), 1 )));
     292             : // TODO check (cos/sin miss {})
     293             : //    CHECK_FORMULA( "f left (x right ) = {a} rsub {0} + sum from {n=1} to {∞} {left ({a} rsub {n} cos {{nπx} over {L}} + {b} rsub {n} sin {{nπx} over {L}} right )}",
     294           4 :     CHECK_FORMULA( "f left (x right ) = {a} rsub {0} + sum from {n=1} to {∞} {left ({a} rsub {n} cos {nπx} over {L} + {b} rsub {n} sin {nπx} over {L} right )}",
     295           2 :         getFormula( getRun( getParagraph( 4 ), 1 )));
     296           2 :     CHECK_FORMULA( "{a} ^ {2} + {b} ^ {2} = {c} ^ {2}", getFormula( getRun( getParagraph( 5 ), 1 )));
     297           4 :     CHECK_FORMULA( "x = {- b ± sqrt {{b} ^ {2} -4 ac}} over {2 a}",
     298           2 :         getFormula( getRun( getParagraph( 6 ), 1 )));
     299           4 :     CHECK_FORMULA(
     300             :         "{e} ^ {x} =1+ {x} over {1!} + {{x} ^ {2}} over {2!} + {{x} ^ {3}} over {3!} +…,    -∞<x<∞",
     301           2 :         getFormula( getRun( getParagraph( 7 ), 1 )));
     302           4 :     CHECK_FORMULA(
     303             : //        "sin {α} ± sin {β} =2 sin {{1} over {2} left (α±β right )} cos {{1} over {2} left (α∓β right )}",
     304             : // TODO check (cos/in miss {})
     305             :         "sin α ± sin β =2 sin {1} over {2} left (α±β right ) cos {1} over {2} left (α∓β right )",
     306           2 :         getFormula( getRun( getParagraph( 8 ), 1 )));
     307           4 :     CHECK_FORMULA(
     308             : //        "cos {α} + cos {β} =2 cos {{1} over {2} left (α+β right )} cos {{1} over {2} left (α-β right )}",
     309             : // TODO check (cos/sin miss {})
     310             :         "cos α + cos β =2 cos {1} over {2} left (α+β right ) cos {1} over {2} left (α-β right )",
     311           2 :         getFormula( getRun( getParagraph( 9 ), 1 )));
     312           2 : }
     313             : 
     314           4 : void Test::testMathNary()
     315             : {
     316           4 :     CHECK_FORMULA( "lllint from {1} to {2} {x + 1}", getFormula( getRun( getParagraph( 1 ), 1 )));
     317           4 :     CHECK_FORMULA( "prod from {a} {b}", getFormula( getRun( getParagraph( 1 ), 2 )));
     318           4 :     CHECK_FORMULA( "sum to {2} {x}", getFormula( getRun( getParagraph( 1 ), 3 )));
     319           4 : }
     320             : 
     321           4 : void Test::testMathOverbraceUnderbrace()
     322             : {
     323           4 :     CHECK_FORMULA( "{abcd} overbrace {4}", getFormula( getRun( getParagraph( 1 ), 1 )));
     324           4 :     CHECK_FORMULA( "{xyz} underbrace {3}", getFormula( getRun( getParagraph( 2 ), 1 )));
     325           4 : }
     326             : 
     327           4 : void Test::testMathOverstrike()
     328             : {
     329           4 :     CHECK_FORMULA( "overstrike {abc}", getFormula( getRun( getParagraph( 1 ), 1 )));
     330           4 : }
     331             : 
     332           4 : void Test::testMathPlaceholders()
     333             : {
     334           4 :     CHECK_FORMULA( "sum from <?> to <?> <?>", getFormula( getRun( getParagraph( 1 ), 1 )));
     335           4 : }
     336             : 
     337           4 : void Test::testMathRad()
     338             : {
     339           4 :     CHECK_FORMULA( "sqrt {4}", getFormula( getRun( getParagraph( 1 ), 1 )));
     340           4 :     CHECK_FORMULA( "nroot {3} {x + 1}", getFormula( getRun( getParagraph( 1 ), 2 )));
     341           4 : }
     342             : 
     343           4 : void Test::testMathSubscripts()
     344             : {
     345           4 :     CHECK_FORMULA( "{x} ^ {y} + {e} ^ {x}", getFormula( getRun( getParagraph( 1 ), 1 )));
     346           4 :     CHECK_FORMULA( "{x} ^ {b}", getFormula( getRun( getParagraph( 1 ), 2 )));
     347           4 :     CHECK_FORMULA( "{x} rsub {b}", getFormula( getRun( getParagraph( 1 ), 3 )));
     348           4 :     CHECK_FORMULA( "{a} rsub {c} rsup {b}", getFormula( getRun( getParagraph( 1 ), 4 )));
     349           4 :     CHECK_FORMULA( "{x} lsub {2} lsup {1}", getFormula( getRun( getParagraph( 1 ), 5 )));
     350           8 :     CHECK_FORMULA( "{{x csup {6} csub {3}} lsub {4} lsup {5}} rsub {2} rsup {1}",
     351           4 :         getFormula( getRun( getParagraph( 1 ), 6 )));
     352           4 : }
     353             : 
     354           4 : void Test::testMathVerticalStacks()
     355             : {
     356           4 :     CHECK_FORMULA( "{a} over {b}", getFormula( getRun( getParagraph( 1 ), 1 )));
     357           4 :     CHECK_FORMULA( "{a} / {b}", getFormula( getRun( getParagraph( 2 ), 1 )));
     358             : // TODO check these
     359             : //    CHECK_FORMULA( "binom {a} {b}", getFormula( getRun( getParagraph( 3 ), 1 )));
     360             : //    CHECK_FORMULA( "binom {a} {binom {b} {c}}", getFormula( getRun( getParagraph( 4 ), 1 )));
     361           4 : }
     362             : 
     363           4 : void Test::testTablePosition()
     364             : {
     365           4 :     sal_Int32 xCoordsFromOffice[] = { 2500, -1000, 0, 0 };
     366           4 :     sal_Int32 cellLeftMarginFromOffice[] = { 250, 100, 0, 0 };
     367             : 
     368           4 :     uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
     369           4 :     uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
     370           4 :     uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables( ), uno::UNO_QUERY);
     371             : 
     372          20 :     for (int i=0; i<4; i++) {
     373          16 :         uno::Reference<text::XTextTable> xTable1 (xTables->getByIndex(i), uno::UNO_QUERY);
     374             :         // Verify X coord
     375          16 :         uno::Reference<view::XSelectionSupplier> xCtrl(xModel->getCurrentController(), uno::UNO_QUERY);
     376          16 :         xCtrl->select(uno::makeAny(xTable1));
     377          16 :         uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(xCtrl, uno::UNO_QUERY);
     378          16 :         uno::Reference<text::XTextViewCursor> xCursor(xTextViewCursorSupplier->getViewCursor(), uno::UNO_QUERY);
     379          16 :         awt::Point pos = xCursor->getPosition();
     380          32 :         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Incorrect X coord computed from docx",
     381          16 :             xCoordsFromOffice[i], pos.X, 1);
     382             : 
     383             :         // Verify left margin of 1st cell :
     384             :         //  * Office left margins are measured relative to the right of the border
     385             :         //  * LO left spacing is measured from the center of the border
     386          16 :         uno::Reference<table::XCell> xCell = xTable1->getCellByName("A1");
     387          16 :         uno::Reference< beans::XPropertySet > xPropSet(xCell, uno::UNO_QUERY_THROW);
     388          16 :         sal_Int32 aLeftMargin = -1;
     389          16 :         xPropSet->getPropertyValue("LeftBorderDistance") >>= aLeftMargin;
     390          16 :         uno::Any aLeftBorder = xPropSet->getPropertyValue("LeftBorder");
     391          16 :         table::BorderLine2 aLeftBorderLine;
     392          16 :         aLeftBorder >>= aLeftBorderLine;
     393          32 :         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Incorrect left spacing computed from docx cell margin",
     394          16 :             cellLeftMarginFromOffice[i], aLeftMargin - 0.5 * aLeftBorderLine.LineWidth, 1);
     395          20 :     }
     396           4 : }
     397             : 
     398           4 : void Test::testFdo47669()
     399             : {
     400             :     /*
     401             :      * Problem: we created imbalance </w:hyperlink> which shouldn't be there,
     402             :      * resulting in loading error: missing last character of hyperlink text
     403             :      * and content after it wasn't loaded.
     404             :      */
     405           4 :     getParagraph(1, "This is a hyperlink with anchor. Also, this sentence should be seen.");
     406           4 :     getRun(getParagraph(1), 2, "hyperlink with anchor");
     407           4 :     CPPUNIT_ASSERT_EQUAL(OUString("http://www.google.com/#a"), getProperty<OUString>(getRun(getParagraph(1), 2), "HyperLinkURL"));
     408           4 : }
     409             : 
     410             : struct SingleLineBorders {
     411             :     sal_Int16 top, bottom, left, right;
     412          96 :     SingleLineBorders(int t=0, int b=0, int l=0, int r=0)
     413          96 :         : top(t), bottom(b), left(l), right(r) {}
     414         192 :     sal_Int16 getBorder(int i) const
     415             :     {
     416         192 :         switch (i) {
     417          48 :             case 0: return top;
     418          48 :             case 1: return bottom;
     419          48 :             case 2: return left;
     420          48 :             case 3: return right;
     421           0 :             default: assert(false); return 0;
     422             :         }
     423             :     }
     424             : };
     425           4 : void Test::testTableBorders() {
     426           4 :     uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
     427           4 :     uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
     428           4 :     uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables( ), uno::UNO_QUERY);
     429           4 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount());
     430           4 :     uno::Reference<text::XTextTable> xTextTable (xTables->getByIndex(0), uno::UNO_QUERY);
     431             : 
     432           4 :     std::map<OUString, SingleLineBorders> cellBorders;
     433           4 :     cellBorders[OUString("A1")] = SingleLineBorders(106, 106, 106, 106);
     434           4 :     cellBorders[OUString("B1")] = SingleLineBorders(106, 0, 106, 35);
     435           4 :     cellBorders[OUString("C1")] = SingleLineBorders(106, 106, 35, 106);
     436           4 :     cellBorders[OUString("A2")] = SingleLineBorders(106, 35, 106, 0);
     437           4 :     cellBorders[OUString("B2")] = SingleLineBorders(0, 0, 0, 0);
     438           4 :     cellBorders[OUString("C2")] = SingleLineBorders(106, 106, 0, 106);
     439           4 :     cellBorders[OUString("A3")] = SingleLineBorders(35, 35, 106, 106);
     440           4 :     cellBorders[OUString("B3")] = SingleLineBorders(0, 106, 106, 106);
     441           4 :     cellBorders[OUString("C3")] = SingleLineBorders(106, 106, 106, 106);
     442           4 :     cellBorders[OUString("A4")] = SingleLineBorders(35, 106, 106, 35);
     443           4 :     cellBorders[OUString("B4")] = SingleLineBorders(106, 106, 35, 106);
     444           4 :     cellBorders[OUString("C4")] = SingleLineBorders(106, 106, 106, 106);
     445             : 
     446             :     const OUString borderNames[] = {
     447             :         OUString("TopBorder"),
     448             :         OUString("BottomBorder"),
     449             :         OUString("LeftBorder"),
     450             :         OUString("RightBorder"),
     451          20 :     };
     452             : 
     453           4 :     uno::Sequence<OUString> const cells = xTextTable->getCellNames();
     454           4 :     sal_Int32 nLength = cells.getLength();
     455           4 :     CPPUNIT_ASSERT_EQUAL((sal_Int32)cellBorders.size(), nLength);
     456             : 
     457          52 :     for (sal_Int32 i = 0; i < nLength; ++i)
     458             :     {
     459          48 :         uno::Reference<table::XCell> xCell = xTextTable->getCellByName(cells[i]);
     460          48 :         uno::Reference< beans::XPropertySet > xPropSet(xCell, uno::UNO_QUERY_THROW);
     461          48 :         const SingleLineBorders& borders = cellBorders[cells[i]];
     462             : 
     463         240 :         for (sal_Int32 j = 0; j < 4; ++j)
     464             :         {
     465         192 :             uno::Any aBorder = xPropSet->getPropertyValue(borderNames[j]);
     466         192 :             table::BorderLine aBorderLine;
     467         192 :             if (aBorder >>= aBorderLine)
     468             :             {
     469         192 :                 std::stringstream message;
     470         192 :                 message << cells[i] << "'s " << borderNames[j] << " is incorrect";
     471         384 :                 CPPUNIT_ASSERT_EQUAL_MESSAGE(message.str(),
     472         384 :                         borders.getBorder(j), aBorderLine.OuterLineWidth);
     473             :             }
     474         192 :         }
     475          68 :     }
     476           4 : }
     477             : 
     478           2 : void Test::testFdo51550()
     479             : {
     480             :     // The problem was that we lacked the fallback to export the replacement graphic for OLE objects.
     481           2 :     uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
     482           2 :     uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
     483           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xDraws->getCount());
     484           2 : }
     485             : 
     486           4 : void Test::testN789482()
     487             : {
     488             :     // The problem was that w:del was exported before w:hyperlink, resulting in an invalid XML.
     489           4 :     uno::Reference<text::XTextRange> xParagraph = getParagraph(1);
     490           4 :     getRun(xParagraph, 1, "Before. ");
     491             : 
     492           4 :     CPPUNIT_ASSERT_EQUAL(OUString("Delete"), getProperty<OUString>(getRun(xParagraph, 2), "RedlineType"));
     493           4 :     CPPUNIT_ASSERT_EQUAL(sal_True, getProperty<sal_Bool>(getRun(xParagraph, 2), "IsStart"));
     494             : 
     495           4 :     getRun(xParagraph, 3, "www.test.com");
     496           4 :     CPPUNIT_ASSERT_EQUAL(OUString("http://www.test.com/"), getProperty<OUString>(getRun(xParagraph, 3), "HyperLinkURL"));
     497             : 
     498           4 :     CPPUNIT_ASSERT_EQUAL(OUString("Delete"), getProperty<OUString>(getRun(xParagraph, 4), "RedlineType"));
     499           4 :     CPPUNIT_ASSERT_EQUAL(sal_False, getProperty<sal_Bool>(getRun(xParagraph, 4), "IsStart"));
     500             : 
     501           4 :     getRun(xParagraph, 5, " After.");
     502           4 : }
     503             : 
     504           2 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
     505             : 
     506           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     507             : 
     508             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10