LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/qa/extras/ww8import - ww8import.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 143 143 100.0 %
Date: 2013-07-09 Functions: 22 23 95.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * This file is part of the LibreOffice project.
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       7             :  */
       8             : 
       9             : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
      10             : #include <com/sun/star/table/BorderLine2.hpp>
      11             : #include <com/sun/star/table/TableBorder.hpp>
      12             : #include <com/sun/star/text/XDependentTextField.hpp>
      13             : #include <com/sun/star/text/XTextFramesSupplier.hpp>
      14             : #include <com/sun/star/text/XTextTablesSupplier.hpp>
      15             : 
      16             : #include <vcl/svapp.hxx>
      17             : 
      18             : #include <swmodeltestbase.hxx>
      19             : #include <bordertest.hxx>
      20             : 
      21             : #define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
      22             : 
      23           3 : class Test : public SwModelTestBase
      24             : {
      25             : public:
      26             :     void testN757910();
      27             :     void testN760294();
      28             :     void testN750255();
      29             :     void testN652364();
      30             :     void testN757118();
      31             :     void testN757905();
      32             :     void testAllGapsWord();
      33             :     void testFdo59530();
      34             :     void testI120158();
      35             :     void testN816603();
      36             :     void testN816593();
      37             :     void testPageBorder();
      38             : 
      39           2 :     CPPUNIT_TEST_SUITE(Test);
      40             : #if !defined(MACOSX) && !defined(WNT)
      41           1 :     CPPUNIT_TEST(run);
      42             : #endif
      43           2 :     CPPUNIT_TEST_SUITE_END();
      44             : 
      45             : private:
      46             :     void run();
      47             : };
      48             : 
      49           1 : void Test::run()
      50             : {
      51             :     MethodEntry<Test> aMethods[] = {
      52             :         {"n757910.doc", &Test::testN757910},
      53             :         {"n760294.doc", &Test::testN760294},
      54             :         {"n750255.doc", &Test::testN750255},
      55             :         {"n652364.doc", &Test::testN652364},
      56             :         {"n757118.doc", &Test::testN757118},
      57             :         {"n757905.doc", &Test::testN757905},
      58             :         {"all_gaps_word.doc", &Test::testAllGapsWord},
      59             :         {"fdo59530.doc", &Test::testFdo59530},
      60             :         {"i120158.doc", &Test::testI120158},
      61             :         {"n816603.doc", &Test::testN816603},
      62             :         {"n816593.doc", &Test::testN816593},
      63             :         {"page-border.doc", &Test::testPageBorder},
      64           1 :     };
      65           1 :     header();
      66          13 :     for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
      67             :     {
      68          12 :         MethodEntry<Test>& rEntry = aMethods[i];
      69          12 :         load("/sw/qa/extras/ww8import/data/", rEntry.pName);
      70          12 :         (this->*rEntry.pMethod)();
      71          12 :         finish();
      72             :     }
      73           1 : }
      74             : 
      75           1 : void Test::testN757910()
      76             : {
      77             :     // The internal margin was larger than 0.28cm
      78           1 :     uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
      79           2 :     uno::Reference<container::XIndexAccess> xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY);
      80           2 :     uno::Reference<beans::XPropertySet> xPropertySet(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
      81           1 :     sal_Int32 nValue = 0;
      82           1 :     xPropertySet->getPropertyValue("LeftBorderDistance") >>= nValue;
      83           1 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(280), nValue);
      84             : 
      85             :     // The border width was zero
      86           1 :     table::BorderLine2 aBorder;
      87           1 :     xPropertySet->getPropertyValue("LeftBorder") >>= aBorder;
      88           2 :     CPPUNIT_ASSERT(aBorder.LineWidth > 0);
      89           1 : }
      90             : 
      91           1 : void Test::testN760294()
      92             : {
      93           1 :     uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
      94           2 :     uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
      95           2 :     uno::Reference<beans::XPropertySet> xTable(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
      96           1 :     table::TableBorder aTableBorder;
      97           1 :     xTable->getPropertyValue("TableBorder") >>= aTableBorder;
      98           1 :     CPPUNIT_ASSERT_EQUAL(aTableBorder.TopLine.InnerLineWidth, aTableBorder.TopLine.OuterLineWidth);
      99           2 :     CPPUNIT_ASSERT_EQUAL(aTableBorder.TopLine.InnerLineWidth, aTableBorder.TopLine.LineDistance);
     100           1 : }
     101             : 
     102           1 : void Test::testN750255()
     103             : {
     104             : /*
     105             : Column break without columns on the page is a page break, so check those paragraphs
     106             : are on page 2 (page style 'Convert 1') and page 3 (page style 'Convert 2')
     107             : enum = ThisComponent.Text.createEnumeration
     108             : enum.nextElement
     109             : para1 = enum.nextElement
     110             : xray para1.String
     111             : xray para1.PageStyleName
     112             : para2 = enum.nextElement
     113             : xray para2.String
     114             : xray para2.PageStyleName
     115             : */
     116           1 :     uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
     117           2 :     uno::Reference<container::XEnumerationAccess> paraEnumAccess(textDocument->getText(), uno::UNO_QUERY);
     118             :     // list of paragraphs
     119           2 :     uno::Reference<container::XEnumeration> paraEnum = paraEnumAccess->createEnumeration();
     120             :     // go to 1st paragraph
     121           1 :     (void) paraEnum->nextElement();
     122             :     // get the 2nd and 3rd paragraph
     123           2 :     uno::Reference<uno::XInterface> paragraph1(paraEnum->nextElement(), uno::UNO_QUERY);
     124           2 :     uno::Reference<uno::XInterface> paragraph2(paraEnum->nextElement(), uno::UNO_QUERY);
     125           2 :     uno::Reference<text::XTextRange> text1(paragraph1, uno::UNO_QUERY);
     126           2 :     uno::Reference<text::XTextRange> text2(paragraph2, uno::UNO_QUERY);
     127           1 :     CPPUNIT_ASSERT_EQUAL( OUString( "one" ), text1->getString());
     128           1 :     CPPUNIT_ASSERT_EQUAL( OUString( "two" ), text2->getString());
     129           2 :     uno::Reference<beans::XPropertySet> paragraphProperties1(paragraph1, uno::UNO_QUERY);
     130           2 :     uno::Reference<beans::XPropertySet> paragraphProperties2(paragraph2, uno::UNO_QUERY);
     131           2 :     OUString pageStyle1, pageStyle2;
     132           1 :     paragraphProperties1->getPropertyValue( "PageStyleName" ) >>= pageStyle1;
     133           1 :     paragraphProperties2->getPropertyValue( "PageStyleName" ) >>= pageStyle2;
     134           1 :     CPPUNIT_ASSERT_EQUAL( OUString( "Convert 1" ), pageStyle1 );
     135           2 :     CPPUNIT_ASSERT_EQUAL( OUString( "Convert 2" ), pageStyle2 );
     136             : 
     137           1 : }
     138             : 
     139           1 : void Test::testN652364()
     140             : {
     141             : /*
     142             : Related to 750255 above, column break with columns on the page however should be a column break.
     143             : enum = ThisComponent.Text.createEnumeration
     144             : enum.nextElement
     145             : para1 = enum.nextElement
     146             : xray para1.String
     147             : xray para1.PageStyleName
     148             : enum.nextElement
     149             : para2 = enum.nextElement
     150             : xray para2.String
     151             : xray para2.PageStyleName
     152             : */
     153           1 :     uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
     154           2 :     uno::Reference<container::XEnumerationAccess> paraEnumAccess(textDocument->getText(), uno::UNO_QUERY);
     155             :     // list of paragraphs
     156           2 :     uno::Reference<container::XEnumeration> paraEnum = paraEnumAccess->createEnumeration();
     157             :     // get the 2nd and 4th paragraph
     158           1 :     (void) paraEnum->nextElement();
     159           2 :     uno::Reference<uno::XInterface> paragraph1(paraEnum->nextElement(), uno::UNO_QUERY);
     160           1 :     (void) paraEnum->nextElement();
     161           2 :     uno::Reference<uno::XInterface> paragraph2(paraEnum->nextElement(), uno::UNO_QUERY);
     162           2 :     uno::Reference<text::XTextRange> text1(paragraph1, uno::UNO_QUERY);
     163           2 :     uno::Reference<text::XTextRange> text2(paragraph2, uno::UNO_QUERY);
     164           1 :     CPPUNIT_ASSERT_EQUAL( OUString( "text1" ), text1->getString());
     165           1 :     CPPUNIT_ASSERT_EQUAL( OUString( "text2" ), text2->getString());
     166           2 :     uno::Reference<beans::XPropertySet> paragraphProperties1(paragraph1, uno::UNO_QUERY);
     167           2 :     uno::Reference<beans::XPropertySet> paragraphProperties2(paragraph2, uno::UNO_QUERY);
     168           2 :     OUString pageStyle1, pageStyle2;
     169           1 :     paragraphProperties1->getPropertyValue( "PageStyleName" ) >>= pageStyle1;
     170           1 :     paragraphProperties2->getPropertyValue( "PageStyleName" ) >>= pageStyle2;
     171             :     // "Standard" is the style for the first page (2nd is "Convert 1").
     172           1 :     CPPUNIT_ASSERT_EQUAL( OUString( "Standard" ), pageStyle1 );
     173           2 :     CPPUNIT_ASSERT_EQUAL( OUString( "Standard" ), pageStyle2 );
     174           1 : }
     175             : 
     176           1 : void Test::testN757118()
     177             : {
     178             : /*
     179             : Two pairs of horizontal rules (one absolute width, one relative width)
     180             : have the same width (full page width, half page width).
     181             : xray ThisComponent.DrawPage.getByIndex(0).BoundRect
     182             : */
     183           1 :     uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
     184           2 :     uno::Reference<drawing::XDrawPageSupplier> drawPageSupplier(textDocument, uno::UNO_QUERY);
     185           2 :     uno::Reference<drawing::XDrawPage> drawPage = drawPageSupplier->getDrawPage();
     186           2 :     uno::Reference<drawing::XShape> rule1, rule2, rule3, rule4;
     187           1 :     drawPage->getByIndex(0) >>= rule1;
     188           1 :     drawPage->getByIndex(1) >>= rule2;
     189           1 :     drawPage->getByIndex(2) >>= rule3;
     190           1 :     drawPage->getByIndex(3) >>= rule4;
     191           2 :     uno::Reference<beans::XPropertySet> ruleProperties1(rule1, uno::UNO_QUERY);
     192           2 :     uno::Reference<beans::XPropertySet> ruleProperties2(rule2, uno::UNO_QUERY);
     193           2 :     uno::Reference<beans::XPropertySet> ruleProperties3(rule3, uno::UNO_QUERY);
     194           2 :     uno::Reference<beans::XPropertySet> ruleProperties4(rule4, uno::UNO_QUERY);
     195           1 :     awt::Rectangle boundRect1, boundRect2, boundRect3, boundRect4;
     196           1 :     ruleProperties1->getPropertyValue( "BoundRect" ) >>= boundRect1;
     197           1 :     ruleProperties2->getPropertyValue( "BoundRect" ) >>= boundRect2;
     198           1 :     ruleProperties3->getPropertyValue( "BoundRect" ) >>= boundRect3;
     199           1 :     ruleProperties4->getPropertyValue( "BoundRect" ) >>= boundRect4;
     200             :     // compare, allow for < 5 differences because of rounding errors
     201           1 :     CPPUNIT_ASSERT( abs( boundRect1.Width - boundRect3.Width ) < 5 );
     202           2 :     CPPUNIT_ASSERT( abs( boundRect2.Width - boundRect4.Width ) < 5 );
     203           1 : }
     204             : 
     205           1 : void Test::testN757905()
     206             : {
     207             :     // The problem was that the paragraph had only a single fly
     208             :     // (as-character-anchored), and the height of that was smallar than the
     209             :     // paragraph height. When in Word-compat mode, we should take the max of
     210             :     // the two, not just the height of the fly.
     211             : 
     212           1 :     OUString aHeight = parseDump("/root/page/body/txt/infos/bounds", "height");
     213           1 :     CPPUNIT_ASSERT(sal_Int32(31) < aHeight.toInt32());
     214           1 : }
     215             : 
     216           1 : void Test::testAllGapsWord()
     217             : {
     218           1 :     BorderTest borderTest;
     219           1 :     borderTest.testTheBorders(mxComponent);
     220           1 : }
     221             : 
     222           1 : void Test::testFdo59530()
     223             : {
     224             :     // See ooxmlexport's testFdo38244().
     225             :     // Test comment range feature.
     226           1 :     uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
     227           2 :     uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
     228           2 :     uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
     229           2 :     uno::Reference<container::XEnumerationAccess> xRunEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY);
     230           2 :     uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration();
     231           1 :     xRunEnum->nextElement();
     232           2 :     uno::Reference<beans::XPropertySet> xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY);
     233           1 :     CPPUNIT_ASSERT_EQUAL(OUString("TextFieldStart"), getProperty<OUString>(xPropertySet, "TextPortionType"));
     234           1 :     xRunEnum->nextElement();
     235           1 :     xPropertySet.set(xRunEnum->nextElement(), uno::UNO_QUERY);
     236           1 :     CPPUNIT_ASSERT_EQUAL(OUString("TextFieldEnd"), getProperty<OUString>(xPropertySet, "TextPortionType"));
     237             : 
     238             :     // Test initials.
     239           2 :     uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
     240           2 :     uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
     241           2 :     uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
     242           1 :     xPropertySet.set(xFields->nextElement(), uno::UNO_QUERY);
     243           1 :     CPPUNIT_ASSERT_EQUAL(OUString("346376201"), getProperty<OUString>(xPropertySet, "Name"));
     244           2 :     CPPUNIT_ASSERT_EQUAL(OUString("M"), getProperty<OUString>(xPropertySet, "Initials"));
     245           1 : }
     246             : 
     247           1 : void Test::testI120158()
     248             : {
     249             :     // See https://issues.apache.org/ooo/show_bug.cgi?id=120158
     250           1 :     uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
     251           2 :     uno::Reference<container::XEnumerationAccess> paraEnumAccess(textDocument->getText(), uno::UNO_QUERY);
     252             :     // list of paragraphs
     253           2 :     uno::Reference<container::XEnumeration> paraEnum = paraEnumAccess->createEnumeration();
     254             :     // get contents of 1st paragraph as text
     255           2 :     uno::Reference<uno::XInterface> paragraph0(paraEnum->nextElement(), uno::UNO_QUERY);
     256           2 :     uno::Reference<text::XTextRange> text0(paragraph0, uno::UNO_QUERY);
     257           2 :     OUString sFieldResult = text0->getString();
     258           2 :     CPPUNIT_ASSERT(sFieldResult.endsWith("AM") || sFieldResult.endsWith("PM"));
     259           1 : }
     260             : 
     261           1 : void Test::testN816603()
     262             : {
     263             :     // Bugdoc was 5 page in Word, 1 in Writer due to pointlessly wrapping the
     264             :     // table in a frame. Exact layout may depend on fonts available, etc. --
     265             :     // but at least make sure that our table spans over multiple pages now.
     266           1 :     CPPUNIT_ASSERT(getPages() > 1);
     267           1 : }
     268             : 
     269           1 : void Test::testN816593()
     270             : {
     271           1 :     uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
     272           2 :     uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
     273             :     // Make sure that even if we import the two tables as non-floating, we
     274             :     // still consider them different, and not merge them.
     275           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount());
     276           1 : }
     277             : 
     278           1 : void Test::testPageBorder()
     279             : {
     280             :     // Page border was missing (LineWidth was 0), due to wrong interpretation of pgbApplyTo.
     281           1 :     table::BorderLine2 aBorder = getProperty<table::BorderLine2>(getStyles("PageStyles")->getByName(DEFAULT_STYLE), "TopBorder");
     282           1 :     CPPUNIT_ASSERT_EQUAL(sal_uInt32(TWIP_TO_MM100(6 * 20)), aBorder.LineWidth);
     283           1 : }
     284             : 
     285           1 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
     286             : 
     287           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     288             : 
     289             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10