LCOV - code coverage report
Current view: top level - sw/qa/extras/htmlexport - htmlexport.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 113 113 100.0 %
Date: 2014-11-03 Functions: 93 95 97.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #include <swmodeltestbase.hxx>
      11             : 
      12             : #include <com/sun/star/awt/Gradient.hpp>
      13             : #include <com/sun/star/drawing/FillStyle.hpp>
      14             : #include <rtl/byteseq.hxx>
      15             : 
      16             : #include <swmodule.hxx>
      17             : #include <swdll.hxx>
      18             : #include <usrpref.hxx>
      19             : 
      20             : #include <test/htmltesttools.hxx>
      21             : 
      22          24 : class HtmlExportTest : public SwModelTestBase, public HtmlTestTools
      23             : {
      24             : private:
      25             :     FieldUnit m_eUnit;
      26             : 
      27             : public:
      28          24 :     HtmlExportTest() :
      29             :         SwModelTestBase("/sw/qa/extras/htmlexport/data/", "HTML (StarWriter)"),
      30          24 :         m_eUnit(FUNIT_NONE)
      31          24 :     {}
      32             : 
      33             : private:
      34          28 :     bool mustCalcLayoutOf(const char* filename) SAL_OVERRIDE
      35             :     {
      36          28 :         return OString(filename) != "fdo62336.docx";
      37             :     }
      38             : 
      39           6 :     bool mustTestImportOf(const char* filename) const SAL_OVERRIDE
      40             :     {
      41           6 :         return OString(filename) != "fdo62336.docx";
      42             :     }
      43             : 
      44          22 :     void preTest(const char* filename) SAL_OVERRIDE
      45             :     {
      46          22 :         if (getTestName().indexOf("SkipImage") != -1)
      47           6 :             setFilterOptions("SkipImages");
      48             :         else
      49          16 :             setFilterOptions("");
      50             : 
      51          22 :         if (OString(filename) == "charborder.odt")
      52             :         {
      53             :             // FIXME if padding-top gets exported as inches, not cms, we get rounding errors.
      54           4 :             SwGlobals::ensure(); // make sure that SW_MOD() is not 0
      55           4 :             SwMasterUsrPref* pPref = const_cast<SwMasterUsrPref*>(SW_MOD()->GetUsrPref(false));
      56           4 :             m_eUnit = pPref->GetMetric();
      57           4 :             pPref->SetMetric(FUNIT_CM);
      58             :         }
      59          22 :     }
      60             : 
      61          22 :     void postTest(const char* filename) SAL_OVERRIDE
      62             :     {
      63          22 :         if (OString(filename) == "charborder.odt")
      64             :         {
      65           4 :             SwMasterUsrPref* pPref = const_cast<SwMasterUsrPref*>(SW_MOD()->GetUsrPref(false));
      66           4 :             pPref->SetMetric(m_eUnit);
      67             :         }
      68          22 :     }
      69             : };
      70             : 
      71             : #define DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(TestName, filename) DECLARE_SW_ROUNDTRIP_TEST(TestName, filename, HtmlExportTest)
      72             : 
      73          32 : DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testFdo81276, "fdo81276.html")
      74             : {
      75           4 :     uno::Reference<container::XNameAccess> xPageStyles(getStyles("PageStyles"));
      76           8 :     uno::Reference<beans::XPropertySet> xStyle(xPageStyles->getByName("HTML"), uno::UNO_QUERY);
      77             :     // some rounding going on here?
      78           4 :     CPPUNIT_ASSERT(abs(sal_Int32(29700) - getProperty<sal_Int32>(xStyle, "Width")) < 10);
      79           4 :     CPPUNIT_ASSERT(abs(sal_Int32(21006) - getProperty<sal_Int32>(xStyle, "Height")) < 10);
      80           4 :     CPPUNIT_ASSERT(abs(sal_Int32(500) - getProperty<sal_Int32>(xStyle, "LeftMargin")) < 10);
      81           4 :     CPPUNIT_ASSERT(abs(sal_Int32(500) - getProperty<sal_Int32>(xStyle, "RightMargin")) < 10);
      82           4 :     CPPUNIT_ASSERT(abs(sal_Int32(2000) - getProperty<sal_Int32>(xStyle, "TopMargin")) < 10);
      83           8 :     CPPUNIT_ASSERT(abs(sal_Int32(500) - getProperty<sal_Int32>(xStyle, "BottomMargin")) < 10);
      84           4 : }
      85             : 
      86          28 : DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testFdo62336, "fdo62336.docx")
      87             : {
      88             :     // The problem was essentially a crash during table export as docx/rtf/html
      89             :     // If either of no-calc-layout or no-test-import is enabled, the crash does not occur
      90           2 : }
      91             : 
      92          32 : DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testCharacterBorder, "charborder.odt")
      93             : {
      94             : 
      95           4 :     uno::Reference<beans::XPropertySet> xRun(getRun(getParagraph(1),1), uno::UNO_QUERY);
      96             :     // Different Border
      97             :     {
      98           4 :         CPPUNIT_ASSERT_BORDER_EQUAL(table::BorderLine2(0x6666FF,12,12,12,3,37), getProperty<table::BorderLine2>(xRun,"CharTopBorder"));
      99           4 :         CPPUNIT_ASSERT_BORDER_EQUAL(table::BorderLine2(0xFF9900,0,99,0,2,99), getProperty<table::BorderLine2>(xRun,"CharLeftBorder"));
     100           4 :         CPPUNIT_ASSERT_BORDER_EQUAL(table::BorderLine2(0xFF0000,0,169,0,1,169), getProperty<table::BorderLine2>(xRun,"CharBottomBorder"));
     101           4 :         CPPUNIT_ASSERT_BORDER_EQUAL(table::BorderLine2(0x0000FF,0,169,0,0,169), getProperty<table::BorderLine2>(xRun,"CharRightBorder"));
     102             :     }
     103             : 
     104             :     // Different Padding
     105             :     {
     106           4 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(450), getProperty<sal_Int32>(xRun,"CharTopBorderDistance"));
     107           4 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(550), getProperty<sal_Int32>(xRun,"CharLeftBorderDistance"));
     108           4 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(150), getProperty<sal_Int32>(xRun,"CharBottomBorderDistance"));
     109           4 :         CPPUNIT_ASSERT_EQUAL(sal_Int32(250), getProperty<sal_Int32>(xRun,"CharRightBorderDistance"));
     110           4 :     }
     111             : 
     112             :     // No shadow
     113           4 : }
     114             : 
     115             : #define DECLARE_HTMLEXPORT_TEST(TestName, filename) DECLARE_SW_EXPORT_TEST(TestName, filename, HtmlExportTest)
     116             : 
     117          20 : DECLARE_HTMLEXPORT_TEST(testExportOfImages, "textAndImage.docx")
     118             : {
     119           2 :     htmlDocPtr pDoc = parseHtml(maTempFile);
     120           2 :     CPPUNIT_ASSERT(pDoc);
     121             : 
     122           2 :     assertXPath(pDoc, "/html/body", 1);
     123           2 :     assertXPath(pDoc, "/html/body/p/font/img", 1);
     124           2 : }
     125             : 
     126          20 : DECLARE_HTMLEXPORT_TEST(testExportOfImagesWithSkipImageEnabled, "textAndImage.docx")
     127             : {
     128           2 :     htmlDocPtr pDoc = parseHtml(maTempFile);
     129           2 :     CPPUNIT_ASSERT(pDoc);
     130             : 
     131           2 :     assertXPath(pDoc, "/html/body", 1);
     132           2 :     assertXPath(pDoc, "/html/body/p/font/img", 0);
     133           2 : }
     134             : 
     135          20 : DECLARE_HTMLEXPORT_TEST(testSkipImageEmbedded, "skipimage-embedded.doc")
     136             : {
     137             :     // Embedded spreadsheet was exported as image, so content was lost. Make
     138             :     // sure it's exported as HTML instead.
     139           2 :     htmlDocPtr pDoc = parseHtml(maTempFile);
     140           2 :     CPPUNIT_ASSERT(pDoc);
     141             : 
     142             :     // This was 0.
     143           2 :     assertXPath(pDoc, "//table", 1);
     144             :     // This was 2, the HTML header was in the document two times.
     145           2 :     assertXPath(pDoc, "//meta[@name='generator']", 1);
     146             :     // This was 0, <table> was directly under <p>, which caused errors in the parser.
     147           2 :     assertXPath(pDoc, "//span/table", 1);
     148           2 : }
     149             : 
     150          20 : DECLARE_HTMLEXPORT_TEST(testSkipImageEmbeddedDocument, "skipimage-embedded-document.docx")
     151             : {
     152             :     // Similar to testSkipImageEmbedded, but with an embedded Writer object,
     153             :     // not a Calc one, and this time OOXML, not WW8.
     154           2 :     htmlDocPtr pDoc = parseHtml(maTempFile);
     155           2 :     CPPUNIT_ASSERT(pDoc);
     156             : 
     157             :     // This was 2, the HTML header was in the document two times.
     158           2 :     assertXPath(pDoc, "//meta[@name='generator']", 1);
     159             :     // Text of embedded document was missing.
     160           2 :     assertXPathContent(pDoc, "/html/body/p/span/p/span", "Inner.");
     161           2 : }
     162             : 
     163          20 : DECLARE_HTMLEXPORT_TEST(testExportImageProperties, "HTMLImage.odt")
     164             : {
     165           2 :     htmlDocPtr pDoc = parseHtml(maTempFile);
     166           2 :     CPPUNIT_ASSERT(pDoc);
     167             : 
     168           2 :     assertXPath(pDoc, "/html/body", 1);
     169             : 
     170           2 :     assertXPath(pDoc, "/html/body/p/map/area", "shape", "poly");
     171           2 :     assertXPath(pDoc, "/html/body/p/map/area", "href", "http://www.microsoft.com/");
     172           2 :     assertXPath(pDoc, "/html/body/p/map/area", "target", "_self");
     173           2 :     assertXPath(pDoc, "/html/body/p/map/area", "alt", "microsoft");
     174             : 
     175           2 :     assertXPath(pDoc, "/html/body/p/a", 1);
     176           2 :     assertXPath(pDoc, "/html/body/p/a", "href", "http://www.google.com/");
     177             : 
     178           2 :     assertXPath(pDoc, "/html/body/p/a/font", 1);
     179           2 :     assertXPath(pDoc, "/html/body/p/a/font", "color", "#ff0000");
     180             : 
     181           2 :     assertXPath(pDoc, "/html/body/p/a/font/img", 1);
     182           2 :     assertXPath(pDoc, "/html/body/p/a/font/img", "name", "Text");
     183           2 :     assertXPath(pDoc, "/html/body/p/a/font/img", "alt", "Four colors");
     184           2 :     assertXPath(pDoc, "/html/body/p/a/font/img", "align", "middle");
     185             : 
     186             :     // Probably the DPI in OSX is different and Twip -> Pixel conversion produces
     187             :     // different results - so disable OSX for now.
     188             :     //
     189             :     // It would make sense to switch to use CSS and use "real world" units instead
     190             :     // i.e. (style="margin: 0cm 1.5cm; width: 1cm; height: 1cm")
     191             : #ifndef MACOSX
     192           2 :     assertXPath(pDoc, "/html/body/p/a/font/img", "hspace", "38");
     193           2 :     assertXPath(pDoc, "/html/body/p/a/font/img", "vspace", "19");
     194           2 :     assertXPath(pDoc, "/html/body/p/a/font/img", "width", "222");
     195           2 :     assertXPath(pDoc, "/html/body/p/a/font/img", "height", "222");
     196           2 :     assertXPath(pDoc, "/html/body/p/a/font/img", "border", "3");
     197             : #endif
     198           2 :     assertXPath(pDoc, "/html/body/p/a/font/img", "usemap", "#map1");
     199           2 : }
     200             : 
     201          20 : DECLARE_HTMLEXPORT_TEST(testExportCheckboxRadioButtonState, "checkbox-radiobutton.doc")
     202             : {
     203           2 :     htmlDocPtr pDoc = parseHtml(maTempFile);
     204           2 :     CPPUNIT_ASSERT(pDoc);
     205             : 
     206           2 :     assertXPath(pDoc, "/html/body", 1);
     207           2 :     assertXPath(pDoc, "/html/body/p[1]/input", "type", "checkbox");
     208           2 :     assertXPath(pDoc, "/html/body/p[1]/input", "checked", "checked");
     209           2 :     assertXPath(pDoc, "/html/body/p[2]/input", "type", "checkbox");
     210           2 :     assertXPathNoAttribute(pDoc, "/html/body/p[2]/input", "checked");
     211           2 :     assertXPath(pDoc, "/html/body/form/p[1]/input", "type", "checkbox");
     212           2 :     assertXPath(pDoc, "/html/body/form/p[1]/input", "checked", "checked");
     213           2 :     assertXPath(pDoc, "/html/body/form/p[2]/input", "type", "checkbox");
     214           2 :     assertXPathNoAttribute(pDoc, "/html/body/form/p[2]/input", "checked");
     215           2 :     assertXPath(pDoc, "/html/body/form/p[3]/input", "type", "radio");
     216           2 :     assertXPath(pDoc, "/html/body/form/p[3]/input", "checked", "checked");
     217           2 :     assertXPath(pDoc, "/html/body/form/p[4]/input", "type", "radio");
     218           2 :     assertXPathNoAttribute(pDoc, "/html/body/form/p[4]/input", "checked");
     219           2 : }
     220             : 
     221           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     222             : 
     223             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10