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: 238 239 99.6 %
Date: 2012-12-27 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           3 : 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           2 :     CPPUNIT_TEST_SUITE(Test);
      71             : #if !defined(MACOSX) && !defined(WNT)
      72           1 :     CPPUNIT_TEST(run);
      73             : #endif
      74           2 :     CPPUNIT_TEST_SUITE_END();
      75             : 
      76             : private:
      77             :     void run();
      78             : };
      79             : 
      80           1 : 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           1 :     };
     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           1 :     };
     113           1 :     std::vector<const char*> vBlacklist(aBlacklist, aBlacklist + SAL_N_ELEMENTS(aBlacklist));
     114           1 :     header();
     115          25 :     for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
     116             :     {
     117          24 :         MethodEntry<Test>& rEntry = aMethods[i];
     118          24 :         load("/sw/qa/extras/ooxmlexport/data/", rEntry.pName);
     119             :         // If the testcase is stored in some other format, it's pointless to test.
     120          24 :         if (OString(rEntry.pName).endsWith(".docx") && std::find(vBlacklist.begin(), vBlacklist.end(), rEntry.pName) == vBlacklist.end())
     121          19 :             (this->*rEntry.pMethod)();
     122          24 :         reload("Office Open XML Text");
     123          24 :         (this->*rEntry.pMethod)();
     124          24 :         finish();
     125           1 :     }
     126           1 : }
     127             : 
     128           2 : void Test::testZoom()
     129             : {
     130           2 :     uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
     131           2 :     uno::Reference<view::XViewSettingsSupplier> xViewSettingsSupplier(xModel->getCurrentController(), uno::UNO_QUERY);
     132           2 :     uno::Reference<beans::XPropertySet> xPropertySet(xViewSettingsSupplier->getViewSettings());
     133           2 :     sal_Int16 nValue = 0;
     134           2 :     xPropertySet->getPropertyValue("ZoomValue") >>= nValue;
     135           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int16(42), nValue);
     136           2 : }
     137             : 
     138           1 : void Test::defaultTabStopNotInStyles()
     139             : {
     140             : // The default tab stop was mistakenly exported to a style.
     141             : // xray ThisComponent.StyleFamilies(1)(0).ParaTabStop
     142           1 :     uno::Reference< container::XNameAccess > paragraphStyles = getStyles( "ParagraphStyles" );
     143           1 :     uno::Reference< beans::XPropertySet > properties( paragraphStyles->getByName( "Standard" ), uno::UNO_QUERY );
     144             :     uno::Sequence< style::TabStop > stops = getProperty< uno::Sequence< style::TabStop > >(
     145           1 :         paragraphStyles->getByName( "Standard" ), "ParaTabStops" );
     146             : // There actually be be one tab stop, but it will be the default.
     147           1 :     CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(1), stops.getLength());
     148           1 :     CPPUNIT_ASSERT_EQUAL( style::TabAlign_DEFAULT, stops[ 0 ].Alignment );
     149           1 : }
     150             : 
     151           2 : void Test::testFdo38244()
     152             : {
     153             :     /*
     154             :      * Comments attached to a range was imported without the range, check for the fieldmark start/end positions.
     155             :      *
     156             :      * oParas = ThisComponent.Text.createEnumeration
     157             :      * oPara = oParas.nextElement
     158             :      * oRuns = oPara.createEnumeration
     159             :      * oRun = oRuns.nextElement
     160             :      * oRun = oRuns.nextElement 'TextFieldStart
     161             :      * oRun = oRuns.nextElement
     162             :      * oRun = oRuns.nextElement 'TextFieldEnd
     163             :      * xray oRun.TextPortionType
     164             :      */
     165           2 :     uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
     166           2 :     uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
     167           2 :     uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
     168           2 :     uno::Reference<container::XEnumerationAccess> xRunEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY);
     169           2 :     uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration();
     170           2 :     xRunEnum->nextElement();
     171           2 :     uno::Reference<beans::XPropertySet> xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY);
     172           2 :     CPPUNIT_ASSERT_EQUAL(OUString("TextFieldStart"), getProperty<OUString>(xPropertySet, "TextPortionType"));
     173           2 :     xRunEnum->nextElement();
     174           2 :     xPropertySet.set(xRunEnum->nextElement(), uno::UNO_QUERY);
     175           2 :     CPPUNIT_ASSERT_EQUAL(OUString("TextFieldEnd"), getProperty<OUString>(xPropertySet, "TextPortionType"));
     176             : 
     177             :     /*
     178             :      * Initials were not imported.
     179             :      *
     180             :      * oFields = ThisComponent.TextFields.createEnumeration
     181             :      * oField = oFields.nextElement
     182             :      * xray oField.Initials
     183             :      */
     184           2 :     uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
     185           2 :     uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
     186           2 :     uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
     187           2 :     xPropertySet.set(xFields->nextElement(), uno::UNO_QUERY);
     188           2 :     CPPUNIT_ASSERT_EQUAL(OUString("M"), getProperty<OUString>(xPropertySet, "Initials"));
     189             : 
     190             :     /*
     191             :      * There was a fake empty paragraph at the end of the comment text.
     192             :      *
     193             :      * oFields = ThisComponent.TextFields.createEnumeration
     194             :      * oField = oFields.nextElement
     195             :      * oParas = oField.TextRange.createEnumeration
     196             :      * oPara = oParas.nextElement
     197             :      * oPara = oParas.nextElement
     198             :      */
     199             : 
     200           2 :     xParaEnumAccess.set(getProperty< uno::Reference<container::XEnumerationAccess> >(xPropertySet, "TextRange"), uno::UNO_QUERY);
     201           2 :     xParaEnum = xParaEnumAccess->createEnumeration();
     202           2 :     xParaEnum->nextElement();
     203           2 :     bool bCaught = false;
     204             :     try
     205             :     {
     206           2 :         xParaEnum->nextElement();
     207             :     }
     208           4 :     catch (container::NoSuchElementException&)
     209             :     {
     210           2 :         bCaught = true;
     211             :     }
     212           2 :     CPPUNIT_ASSERT_EQUAL(true, bCaught);
     213           2 : }
     214             : 
     215           1 : void Test::testMathEscape()
     216             : {
     217           1 :     CPPUNIT_ASSERT_EQUAL(OUString("\\{ left [ right ] left ( right ) \\}"), getFormula(getRun(getParagraph(1), 1)));
     218           1 : }
     219             : 
     220           1 : void Test::testFdo51034()
     221             : {
     222             :     // The problem was that the 'l' param of the HYPERLINK field was parsed with = "#", not += "#".
     223           1 :     CPPUNIT_ASSERT_EQUAL(OUString("http://Www.google.com/#a"), getProperty<OUString>(getRun(getParagraph(1), 1), "HyperLinkURL"));
     224           1 : }
     225             : 
     226             : // Construct the expected formula from UTF8, as there may be such characters.
     227             : // Remove all spaces, as LO export/import may change that.
     228             : // Replace symbol - (i.e. U+2212) with ASCII - , LO does this change and it shouldn't matter.
     229             : #define CHECK_FORMULA( expected, actual ) \
     230             :     CPPUNIT_ASSERT_EQUAL( \
     231             :         OUString( expected, strlen( expected ), RTL_TEXTENCODING_UTF8 ) \
     232             :             .replaceAll( " ", "" ).replaceAll( OUString( "−", strlen( "−" ), RTL_TEXTENCODING_UTF8 ), "-" ), \
     233             :         OUString( actual ).replaceAll( " ", "" ).replaceAll( OUString( "−", strlen( "−" ), RTL_TEXTENCODING_UTF8 ), "-" ))
     234             : 
     235           2 : void Test::testMathAccents()
     236             : {
     237           4 :     CHECK_FORMULA(
     238             :         "acute {a} grave {a} check {a} breve {a} circle {a} widevec {a} widetilde {a}"
     239             :             " widehat {a} dot {a} widevec {a} widevec {a} widetilde {a} underline {a}",
     240           2 :         getFormula( getRun( getParagraph( 1 ), 1 )));
     241           2 : }
     242             : 
     243           2 : void Test::testMathD()
     244             : {
     245           2 :     CHECK_FORMULA( "left (x mline y mline z right )", getFormula( getRun( getParagraph( 1 ), 1 )));
     246           2 :     CHECK_FORMULA( "left (1 right )", getFormula( getRun( getParagraph( 1 ), 2 )));
     247           2 :     CHECK_FORMULA( "left [2 right ]", getFormula( getRun( getParagraph( 1 ), 3 )));
     248           2 :     CHECK_FORMULA( "left ldbracket 3 right rdbracket", getFormula( getRun( getParagraph( 1 ), 4 )));
     249           2 :     CHECK_FORMULA( "left lline 4 right rline", getFormula( getRun( getParagraph( 1 ), 5 )));
     250           2 :     CHECK_FORMULA( "left ldline 5 right rdline", getFormula( getRun( getParagraph( 1 ), 6 )));
     251           2 :     CHECK_FORMULA( "left langle 6 right rangle", getFormula( getRun( getParagraph( 1 ), 7 )));
     252           2 :     CHECK_FORMULA( "left langle a mline b right rangle", getFormula( getRun( getParagraph( 1 ), 8 )));
     253           2 :     CHECK_FORMULA( "left ({x} over {y} right )", getFormula( getRun( getParagraph( 1 ), 9 )));
     254           2 : }
     255             : 
     256           2 : void Test::testMathEscaping()
     257             : {
     258           2 :     CHECK_FORMULA( "− ∞ < x < ∞", getFormula( getRun( getParagraph( 1 ), 1 )));
     259           2 : }
     260             : 
     261           2 : void Test::testMathLim()
     262             : {
     263           2 :     CHECK_FORMULA( "lim from {x → 1} {x}", getFormula( getRun( getParagraph( 1 ), 1 )));
     264           2 : }
     265             : 
     266           2 : void Test::testMathMalformedXml()
     267             : {
     268           2 :     CPPUNIT_ASSERT_EQUAL( 0, getLength());
     269           2 : }
     270             : 
     271           2 : void Test::testMathMatrix()
     272             : {
     273           2 :     CHECK_FORMULA( "left [matrix {1 # 2 ## 3 # 4} right ]", getFormula( getRun( getParagraph( 1 ), 1 )));
     274           2 : }
     275             : 
     276           1 : void Test::testMathMso2k7()
     277             : {
     278           1 :     CHECK_FORMULA( "A = π {r} ^ {2}", getFormula( getRun( getParagraph( 1 ), 1 )));
     279             : // TODO check the stack/binom difference
     280             : //    CHECK_FORMULA( "{left (x+a right )} ^ {n} = sum from {k=0} to {n} {left (binom {n} {k} right ) {x} ^ {k} {a} ^ {n-k}}",
     281           2 :     CHECK_FORMULA( "{left (x+a right )} ^ {n} = sum from {k=0} to {n} {left (stack {n # k} right ) {x} ^ {k} {a} ^ {n-k}}",
     282           1 :         getFormula( getRun( getParagraph( 2 ), 1 )));
     283           2 :     CHECK_FORMULA( "{left (1+x right )} ^ {n} =1+ {nx} over {1!} + {n left (n-1 right ) {x} ^ {2}} over {2!} +…",
     284           1 :         getFormula( getRun( getParagraph( 3 ), 1 )));
     285             : // TODO check (cos/sin miss {})
     286             : //    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 )}",
     287           2 :     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 )}",
     288           1 :         getFormula( getRun( getParagraph( 4 ), 1 )));
     289           1 :     CHECK_FORMULA( "{a} ^ {2} + {b} ^ {2} = {c} ^ {2}", getFormula( getRun( getParagraph( 5 ), 1 )));
     290           2 :     CHECK_FORMULA( "x = {- b ± sqrt {{b} ^ {2} -4 ac}} over {2 a}",
     291           1 :         getFormula( getRun( getParagraph( 6 ), 1 )));
     292           2 :     CHECK_FORMULA(
     293             :         "{e} ^ {x} =1+ {x} over {1!} + {{x} ^ {2}} over {2!} + {{x} ^ {3}} over {3!} +…,    -∞<x<∞",
     294           1 :         getFormula( getRun( getParagraph( 7 ), 1 )));
     295           2 :     CHECK_FORMULA(
     296             : //        "sin {α} ± sin {β} =2 sin {{1} over {2} left (α±β right )} cos {{1} over {2} left (α∓β right )}",
     297             : // TODO check (cos/in miss {})
     298             :         "sin α ± sin β =2 sin {1} over {2} left (α±β right ) cos {1} over {2} left (α∓β right )",
     299           1 :         getFormula( getRun( getParagraph( 8 ), 1 )));
     300           2 :     CHECK_FORMULA(
     301             : //        "cos {α} + cos {β} =2 cos {{1} over {2} left (α+β right )} cos {{1} over {2} left (α-β right )}",
     302             : // TODO check (cos/sin miss {})
     303             :         "cos α + cos β =2 cos {1} over {2} left (α+β right ) cos {1} over {2} left (α-β right )",
     304           1 :         getFormula( getRun( getParagraph( 9 ), 1 )));
     305           1 : }
     306             : 
     307           2 : void Test::testMathNary()
     308             : {
     309           2 :     CHECK_FORMULA( "lllint from {1} to {2} {x + 1}", getFormula( getRun( getParagraph( 1 ), 1 )));
     310           2 :     CHECK_FORMULA( "prod from {a} {b}", getFormula( getRun( getParagraph( 1 ), 2 )));
     311           2 :     CHECK_FORMULA( "sum to {2} {x}", getFormula( getRun( getParagraph( 1 ), 3 )));
     312           2 : }
     313             : 
     314           2 : void Test::testMathOverbraceUnderbrace()
     315             : {
     316           2 :     CHECK_FORMULA( "{abcd} overbrace {4}", getFormula( getRun( getParagraph( 1 ), 1 )));
     317           2 :     CHECK_FORMULA( "{xyz} underbrace {3}", getFormula( getRun( getParagraph( 2 ), 1 )));
     318           2 : }
     319             : 
     320           2 : void Test::testMathOverstrike()
     321             : {
     322           2 :     CHECK_FORMULA( "overstrike {abc}", getFormula( getRun( getParagraph( 1 ), 1 )));
     323           2 : }
     324             : 
     325           2 : void Test::testMathPlaceholders()
     326             : {
     327           2 :     CHECK_FORMULA( "sum from <?> to <?> <?>", getFormula( getRun( getParagraph( 1 ), 1 )));
     328           2 : }
     329             : 
     330           2 : void Test::testMathRad()
     331             : {
     332           2 :     CHECK_FORMULA( "sqrt {4}", getFormula( getRun( getParagraph( 1 ), 1 )));
     333           2 :     CHECK_FORMULA( "nroot {3} {x + 1}", getFormula( getRun( getParagraph( 1 ), 2 )));
     334           2 : }
     335             : 
     336           2 : void Test::testMathSubscripts()
     337             : {
     338           2 :     CHECK_FORMULA( "{x} ^ {y} + {e} ^ {x}", getFormula( getRun( getParagraph( 1 ), 1 )));
     339           2 :     CHECK_FORMULA( "{x} ^ {b}", getFormula( getRun( getParagraph( 1 ), 2 )));
     340           2 :     CHECK_FORMULA( "{x} rsub {b}", getFormula( getRun( getParagraph( 1 ), 3 )));
     341           2 :     CHECK_FORMULA( "{a} rsub {c} rsup {b}", getFormula( getRun( getParagraph( 1 ), 4 )));
     342           2 :     CHECK_FORMULA( "{x} lsub {2} lsup {1}", getFormula( getRun( getParagraph( 1 ), 5 )));
     343           4 :     CHECK_FORMULA( "{{x csup {6} csub {3}} lsub {4} lsup {5}} rsub {2} rsup {1}",
     344           2 :         getFormula( getRun( getParagraph( 1 ), 6 )));
     345           2 : }
     346             : 
     347           2 : void Test::testMathVerticalStacks()
     348             : {
     349           2 :     CHECK_FORMULA( "{a} over {b}", getFormula( getRun( getParagraph( 1 ), 1 )));
     350           2 :     CHECK_FORMULA( "{a} / {b}", getFormula( getRun( getParagraph( 2 ), 1 )));
     351             : // TODO check these
     352             : //    CHECK_FORMULA( "binom {a} {b}", getFormula( getRun( getParagraph( 3 ), 1 )));
     353             : //    CHECK_FORMULA( "binom {a} {binom {b} {c}}", getFormula( getRun( getParagraph( 4 ), 1 )));
     354           2 : }
     355             : 
     356           2 : void Test::testTablePosition()
     357             : {
     358           2 :     sal_Int32 xCoordsFromOffice[] = { 2500, -1000, 0, 0 };
     359           2 :     sal_Int32 cellLeftMarginFromOffice[] = { 250, 100, 0, 0 };
     360             : 
     361           2 :     uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
     362           2 :     uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
     363           2 :     uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables( ), uno::UNO_QUERY);
     364             : 
     365          10 :     for (int i=0; i<4; i++) {
     366           8 :         uno::Reference<text::XTextTable> xTable1 (xTables->getByIndex(i), uno::UNO_QUERY);
     367             :         // Verify X coord
     368           8 :         uno::Reference<view::XSelectionSupplier> xCtrl(xModel->getCurrentController(), uno::UNO_QUERY);
     369           8 :         xCtrl->select(uno::makeAny(xTable1));
     370           8 :         uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(xCtrl, uno::UNO_QUERY);
     371           8 :         uno::Reference<text::XTextViewCursor> xCursor(xTextViewCursorSupplier->getViewCursor(), uno::UNO_QUERY);
     372           8 :         awt::Point pos = xCursor->getPosition();
     373          16 :         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Incorrect X coord computed from docx",
     374           8 :             xCoordsFromOffice[i], pos.X, 1);
     375             : 
     376             :         // Verify left margin of 1st cell :
     377             :         //  * Office left margins are measured relative to the right of the border
     378             :         //  * LO left spacing is measured from the center of the border
     379           8 :         uno::Reference<table::XCell> xCell = xTable1->getCellByName("A1");
     380           8 :         uno::Reference< beans::XPropertySet > xPropSet(xCell, uno::UNO_QUERY_THROW);
     381           8 :         sal_Int32 aLeftMargin = -1;
     382           8 :         xPropSet->getPropertyValue("LeftBorderDistance") >>= aLeftMargin;
     383           8 :         uno::Any aLeftBorder = xPropSet->getPropertyValue("LeftBorder");
     384           8 :         table::BorderLine2 aLeftBorderLine;
     385           8 :         aLeftBorder >>= aLeftBorderLine;
     386          16 :         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Incorrect left spacing computed from docx cell margin",
     387           8 :             cellLeftMarginFromOffice[i], aLeftMargin - 0.5 * aLeftBorderLine.LineWidth, 1);
     388          10 :     }
     389           2 : }
     390             : 
     391           2 : void Test::testFdo47669()
     392             : {
     393             :     /*
     394             :      * Problem: we created imbalance </w:hyperlink> which shouldn't be there,
     395             :      * resulting in loading error: missing last character of hyperlink text
     396             :      * and content after it wasn't loaded.
     397             :      */
     398           2 :     getParagraph(1, "This is a hyperlink with anchor. Also, this sentence should be seen.");
     399           2 :     getRun(getParagraph(1), 2, "hyperlink with anchor");
     400           2 :     CPPUNIT_ASSERT_EQUAL(OUString("http://www.google.com/#a"), getProperty<OUString>(getRun(getParagraph(1), 2), "HyperLinkURL"));
     401           2 : }
     402             : 
     403             : struct SingleLineBorders {
     404             :     sal_Int16 top, bottom, left, right;
     405          48 :     SingleLineBorders(int t=0, int b=0, int l=0, int r=0)
     406          48 :         : top(t), bottom(b), left(l), right(r) {}
     407          96 :     sal_Int16 getBorder(int i) const
     408             :     {
     409          96 :         switch (i) {
     410          24 :             case 0: return top;
     411          24 :             case 1: return bottom;
     412          24 :             case 2: return left;
     413          24 :             case 3: return right;
     414           0 :             default: assert(false); return 0;
     415             :         }
     416             :     }
     417             : };
     418           2 : void Test::testTableBorders() {
     419           2 :     uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
     420           2 :     uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
     421           2 :     uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables( ), uno::UNO_QUERY);
     422           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount());
     423           2 :     uno::Reference<text::XTextTable> xTextTable (xTables->getByIndex(0), uno::UNO_QUERY);
     424             : 
     425           2 :     std::map<OUString, SingleLineBorders> cellBorders;
     426           2 :     cellBorders[OUString("A1")] = SingleLineBorders(106, 106, 106, 106);
     427           2 :     cellBorders[OUString("B1")] = SingleLineBorders(106, 0, 106, 35);
     428           2 :     cellBorders[OUString("C1")] = SingleLineBorders(106, 106, 35, 106);
     429           2 :     cellBorders[OUString("A2")] = SingleLineBorders(106, 35, 106, 0);
     430           2 :     cellBorders[OUString("B2")] = SingleLineBorders(0, 0, 0, 0);
     431           2 :     cellBorders[OUString("C2")] = SingleLineBorders(106, 106, 0, 106);
     432           2 :     cellBorders[OUString("A3")] = SingleLineBorders(35, 35, 106, 106);
     433           2 :     cellBorders[OUString("B3")] = SingleLineBorders(0, 106, 106, 106);
     434           2 :     cellBorders[OUString("C3")] = SingleLineBorders(106, 106, 106, 106);
     435           2 :     cellBorders[OUString("A4")] = SingleLineBorders(35, 106, 106, 35);
     436           2 :     cellBorders[OUString("B4")] = SingleLineBorders(106, 106, 35, 106);
     437           2 :     cellBorders[OUString("C4")] = SingleLineBorders(106, 106, 106, 106);
     438             : 
     439             :     const OUString borderNames[] = {
     440             :         OUString("TopBorder"),
     441             :         OUString("BottomBorder"),
     442             :         OUString("LeftBorder"),
     443             :         OUString("RightBorder"),
     444          10 :     };
     445             : 
     446           2 :     uno::Sequence<OUString> const cells = xTextTable->getCellNames();
     447           2 :     sal_Int32 nLength = cells.getLength();
     448           2 :     CPPUNIT_ASSERT_EQUAL((sal_Int32)cellBorders.size(), nLength);
     449             : 
     450          26 :     for (sal_Int32 i = 0; i < nLength; ++i)
     451             :     {
     452          24 :         uno::Reference<table::XCell> xCell = xTextTable->getCellByName(cells[i]);
     453          24 :         uno::Reference< beans::XPropertySet > xPropSet(xCell, uno::UNO_QUERY_THROW);
     454          24 :         const SingleLineBorders& borders = cellBorders[cells[i]];
     455             : 
     456         120 :         for (sal_Int32 j = 0; j < 4; ++j)
     457             :         {
     458          96 :             uno::Any aBorder = xPropSet->getPropertyValue(borderNames[j]);
     459          96 :             table::BorderLine aBorderLine;
     460          96 :             if (aBorder >>= aBorderLine)
     461             :             {
     462          96 :                 std::stringstream message;
     463          96 :                 message << cells[i] << "'s " << borderNames[j] << " is incorrect";
     464         192 :                 CPPUNIT_ASSERT_EQUAL_MESSAGE(message.str(),
     465         192 :                         borders.getBorder(j), aBorderLine.OuterLineWidth);
     466             :             }
     467          96 :         }
     468          34 :     }
     469           2 : }
     470             : 
     471           1 : void Test::testFdo51550()
     472             : {
     473             :     // The problem was that we lacked the fallback to export the replacement graphic for OLE objects.
     474           1 :     uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
     475           1 :     uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
     476           1 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xDraws->getCount());
     477           1 : }
     478             : 
     479           2 : void Test::testN789482()
     480             : {
     481             :     // The problem was that w:del was exported before w:hyperlink, resulting in an invalid XML.
     482           2 :     uno::Reference<text::XTextRange> xParagraph = getParagraph(1);
     483           2 :     getRun(xParagraph, 1, "Before. ");
     484             : 
     485           2 :     CPPUNIT_ASSERT_EQUAL(OUString("Delete"), getProperty<OUString>(getRun(xParagraph, 2), "RedlineType"));
     486           2 :     CPPUNIT_ASSERT_EQUAL(sal_True, getProperty<sal_Bool>(getRun(xParagraph, 2), "IsStart"));
     487             : 
     488           2 :     getRun(xParagraph, 3, "www.test.com");
     489           2 :     CPPUNIT_ASSERT_EQUAL(OUString("http://www.test.com/"), getProperty<OUString>(getRun(xParagraph, 3), "HyperLinkURL"));
     490             : 
     491           2 :     CPPUNIT_ASSERT_EQUAL(OUString("Delete"), getProperty<OUString>(getRun(xParagraph, 4), "RedlineType"));
     492           2 :     CPPUNIT_ASSERT_EQUAL(sal_False, getProperty<sal_Bool>(getRun(xParagraph, 4), "IsStart"));
     493             : 
     494           2 :     getRun(xParagraph, 5, " After.");
     495           2 : }
     496             : 
     497           1 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
     498             : 
     499           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     500             : 
     501             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10