LCOV - code coverage report
Current view: top level - libreoffice/sw/qa/extras/ww8import - ww8import.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 103 103 100.0 %
Date: 2012-12-27 Functions: 17 18 94.4 %
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/drawing/XDrawPageSupplier.hpp>
      29             : #include <com/sun/star/table/BorderLine2.hpp>
      30             : #include <com/sun/star/table/TableBorder.hpp>
      31             : #include <com/sun/star/text/XDependentTextField.hpp>
      32             : #include <com/sun/star/text/XTextFramesSupplier.hpp>
      33             : #include <com/sun/star/text/XTextTablesSupplier.hpp>
      34             : 
      35             : #include <vcl/svapp.hxx>
      36             : 
      37             : #include <swmodeltestbase.hxx>
      38             : #include <bordertest.hxx>
      39             : 
      40           3 : class Test : public SwModelTestBase
      41             : {
      42             : public:
      43             :     void testN757910();
      44             :     void testN760294();
      45             :     void testN750255();
      46             :     void testN652364();
      47             :     void testN757118();
      48             :     void testN757905();
      49             :     void testAllGapsWord();
      50             : 
      51           2 :     CPPUNIT_TEST_SUITE(Test);
      52             : #if !defined(MACOSX) && !defined(WNT)
      53           1 :     CPPUNIT_TEST(run);
      54             : #endif
      55           2 :     CPPUNIT_TEST_SUITE_END();
      56             : 
      57             : private:
      58             :     void run();
      59             : };
      60             : 
      61           1 : void Test::run()
      62             : {
      63             :     MethodEntry<Test> aMethods[] = {
      64             :         {"n757910.doc", &Test::testN757910},
      65             :         {"n760294.doc", &Test::testN760294},
      66             :         {"n750255.doc", &Test::testN750255},
      67             :         {"n652364.doc", &Test::testN652364},
      68             :         {"n757118.doc", &Test::testN757118},
      69             :         {"n757905.doc", &Test::testN757905},
      70             :         {"all_gaps_word.doc", &Test::testAllGapsWord},
      71           1 :     };
      72           1 :     header();
      73           8 :     for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
      74             :     {
      75           7 :         MethodEntry<Test>& rEntry = aMethods[i];
      76           7 :         load("/sw/qa/extras/ww8import/data/", rEntry.pName);
      77           7 :         (this->*rEntry.pMethod)();
      78           7 :         finish();
      79             :     }
      80           1 : }
      81             : 
      82           1 : void Test::testN757910()
      83             : {
      84             :     // The internal margin was larger than 0.28cm
      85           1 :     uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
      86           1 :     uno::Reference<container::XIndexAccess> xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY);
      87           1 :     uno::Reference<beans::XPropertySet> xPropertySet(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
      88           1 :     sal_Int32 nValue = 0;
      89           1 :     xPropertySet->getPropertyValue("LeftBorderDistance") >>= nValue;
      90           1 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(280), nValue);
      91             : 
      92             :     // The border width was zero
      93           1 :     table::BorderLine2 aBorder;
      94           1 :     xPropertySet->getPropertyValue("LeftBorder") >>= aBorder;
      95           1 :     CPPUNIT_ASSERT(aBorder.LineWidth > 0);
      96           1 : }
      97             : 
      98           1 : void Test::testN760294()
      99             : {
     100           1 :     uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
     101           1 :     uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
     102           1 :     uno::Reference<beans::XPropertySet> xTable(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
     103           1 :     table::TableBorder aTableBorder;
     104           1 :     xTable->getPropertyValue("TableBorder") >>= aTableBorder;
     105           1 :     CPPUNIT_ASSERT_EQUAL(aTableBorder.TopLine.InnerLineWidth, aTableBorder.TopLine.OuterLineWidth);
     106           1 :     CPPUNIT_ASSERT_EQUAL(aTableBorder.TopLine.InnerLineWidth, aTableBorder.TopLine.LineDistance);
     107           1 : }
     108             : 
     109           1 : void Test::testN750255()
     110             : {
     111             : /*
     112             : Column break without columns on the page is a page break, so check those paragraphs
     113             : are on page 2 (page style 'Convert 1') and page 3 (page style 'Convert 2')
     114             : enum = ThisComponent.Text.createEnumeration
     115             : enum.nextElement
     116             : para1 = enum.nextElement
     117             : xray para1.String
     118             : xray para1.PageStyleName
     119             : para2 = enum.nextElement
     120             : xray para2.String
     121             : xray para2.PageStyleName
     122             : */
     123           1 :     uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
     124           1 :     uno::Reference<container::XEnumerationAccess> paraEnumAccess(textDocument->getText(), uno::UNO_QUERY);
     125             :     // list of paragraphs
     126           1 :     uno::Reference<container::XEnumeration> paraEnum = paraEnumAccess->createEnumeration();
     127             :     // go to 1st paragraph
     128           1 :     (void) paraEnum->nextElement();
     129             :     // get the 2nd and 3rd paragraph
     130           1 :     uno::Reference<uno::XInterface> paragraph1(paraEnum->nextElement(), uno::UNO_QUERY);
     131           1 :     uno::Reference<uno::XInterface> paragraph2(paraEnum->nextElement(), uno::UNO_QUERY);
     132           1 :     uno::Reference<text::XTextRange> text1(paragraph1, uno::UNO_QUERY);
     133           1 :     uno::Reference<text::XTextRange> text2(paragraph2, uno::UNO_QUERY);
     134           1 :     CPPUNIT_ASSERT_EQUAL( OUString( "one" ), text1->getString());
     135           1 :     CPPUNIT_ASSERT_EQUAL( OUString( "two" ), text2->getString());
     136           1 :     uno::Reference<beans::XPropertySet> paragraphProperties1(paragraph1, uno::UNO_QUERY);
     137           1 :     uno::Reference<beans::XPropertySet> paragraphProperties2(paragraph2, uno::UNO_QUERY);
     138           1 :     OUString pageStyle1, pageStyle2;
     139           1 :     paragraphProperties1->getPropertyValue( "PageStyleName" ) >>= pageStyle1;
     140           1 :     paragraphProperties2->getPropertyValue( "PageStyleName" ) >>= pageStyle2;
     141           1 :     CPPUNIT_ASSERT_EQUAL( OUString( "Convert 1" ), pageStyle1 );
     142           1 :     CPPUNIT_ASSERT_EQUAL( OUString( "Convert 2" ), pageStyle2 );
     143             : 
     144           1 : }
     145             : 
     146           1 : void Test::testN652364()
     147             : {
     148             : /*
     149             : Related to 750255 above, column break with columns on the page however should be a column break.
     150             : enum = ThisComponent.Text.createEnumeration
     151             : enum.nextElement
     152             : para1 = enum.nextElement
     153             : xray para1.String
     154             : xray para1.PageStyleName
     155             : enum.nextElement
     156             : para2 = enum.nextElement
     157             : xray para2.String
     158             : xray para2.PageStyleName
     159             : */
     160           1 :     uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
     161           1 :     uno::Reference<container::XEnumerationAccess> paraEnumAccess(textDocument->getText(), uno::UNO_QUERY);
     162             :     // list of paragraphs
     163           1 :     uno::Reference<container::XEnumeration> paraEnum = paraEnumAccess->createEnumeration();
     164             :     // get the 2nd and 4th paragraph
     165           1 :     (void) paraEnum->nextElement();
     166           1 :     uno::Reference<uno::XInterface> paragraph1(paraEnum->nextElement(), uno::UNO_QUERY);
     167           1 :     (void) paraEnum->nextElement();
     168           1 :     uno::Reference<uno::XInterface> paragraph2(paraEnum->nextElement(), uno::UNO_QUERY);
     169           1 :     uno::Reference<text::XTextRange> text1(paragraph1, uno::UNO_QUERY);
     170           1 :     uno::Reference<text::XTextRange> text2(paragraph2, uno::UNO_QUERY);
     171           1 :     CPPUNIT_ASSERT_EQUAL( OUString( "text1" ), text1->getString());
     172           1 :     CPPUNIT_ASSERT_EQUAL( OUString( "text2" ), text2->getString());
     173           1 :     uno::Reference<beans::XPropertySet> paragraphProperties1(paragraph1, uno::UNO_QUERY);
     174           1 :     uno::Reference<beans::XPropertySet> paragraphProperties2(paragraph2, uno::UNO_QUERY);
     175           1 :     OUString pageStyle1, pageStyle2;
     176           1 :     paragraphProperties1->getPropertyValue( "PageStyleName" ) >>= pageStyle1;
     177           1 :     paragraphProperties2->getPropertyValue( "PageStyleName" ) >>= pageStyle2;
     178             :     // "Standard" is the style for the first page (2nd is "Convert 1").
     179           1 :     CPPUNIT_ASSERT_EQUAL( OUString( "Standard" ), pageStyle1 );
     180           1 :     CPPUNIT_ASSERT_EQUAL( OUString( "Standard" ), pageStyle2 );
     181           1 : }
     182             : 
     183           1 : void Test::testN757118()
     184             : {
     185             : /*
     186             : Two pairs of horizontal rules (one absolute width, one relative width)
     187             : have the same width (full page width, half page width).
     188             : xray ThisComponent.DrawPage.getByIndex(0).BoundRect
     189             : */
     190           1 :     uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
     191           1 :     uno::Reference<drawing::XDrawPageSupplier> drawPageSupplier(textDocument, uno::UNO_QUERY);
     192           1 :     uno::Reference<drawing::XDrawPage> drawPage = drawPageSupplier->getDrawPage();
     193           1 :     uno::Reference<drawing::XShape> rule1, rule2, rule3, rule4;
     194           1 :     drawPage->getByIndex(0) >>= rule1;
     195           1 :     drawPage->getByIndex(1) >>= rule2;
     196           1 :     drawPage->getByIndex(2) >>= rule3;
     197           1 :     drawPage->getByIndex(3) >>= rule4;
     198           1 :     uno::Reference<beans::XPropertySet> ruleProperties1(rule1, uno::UNO_QUERY);
     199           1 :     uno::Reference<beans::XPropertySet> ruleProperties2(rule2, uno::UNO_QUERY);
     200           1 :     uno::Reference<beans::XPropertySet> ruleProperties3(rule3, uno::UNO_QUERY);
     201           1 :     uno::Reference<beans::XPropertySet> ruleProperties4(rule4, uno::UNO_QUERY);
     202           1 :     awt::Rectangle boundRect1, boundRect2, boundRect3, boundRect4;
     203           1 :     ruleProperties1->getPropertyValue( "BoundRect" ) >>= boundRect1;
     204           1 :     ruleProperties2->getPropertyValue( "BoundRect" ) >>= boundRect2;
     205           1 :     ruleProperties3->getPropertyValue( "BoundRect" ) >>= boundRect3;
     206           1 :     ruleProperties4->getPropertyValue( "BoundRect" ) >>= boundRect4;
     207             :     // compare, allow for < 5 differences because of rounding errors
     208           1 :     CPPUNIT_ASSERT( abs( boundRect1.Width - boundRect3.Width ) < 5 );
     209           1 :     CPPUNIT_ASSERT( abs( boundRect2.Width - boundRect4.Width ) < 5 );
     210           1 : }
     211             : 
     212           1 : void Test::testN757905()
     213             : {
     214             :     // The problem was that the paragraph had only a single fly
     215             :     // (as-character-anchored), and the height of that was smallar than the
     216             :     // paragraph height. When in Word-compat mode, we should take the max of
     217             :     // the two, not just the height of the fly.
     218             : 
     219           1 :     OUString aHeight = parseDump("/root/page/body/txt/infos/bounds", "height");
     220           1 :     CPPUNIT_ASSERT(sal_Int32(31) < aHeight.toInt32());
     221           1 : }
     222             : 
     223           1 : void Test::testAllGapsWord()
     224             : {
     225           1 :     BorderTest borderTest;
     226           1 :     borderTest.testTheBorders(mxComponent);
     227           1 : }
     228             : 
     229             : 
     230           1 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
     231             : 
     232           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     233             : 
     234             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10