LCOV - code coverage report
Current view: top level - sc/qa/extras - htmlexporttest.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 49 49 100.0 %
Date: 2015-06-13 12:38:46 Functions: 17 18 94.4 %
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 <sal/config.h>
      11             : 
      12             : #include <com/sun/star/frame/Desktop.hpp>
      13             : #include <com/sun/star/frame/XStorable.hpp>
      14             : #include <com/sun/star/lang/XComponent.hpp>
      15             : 
      16             : #include <test/bootstrapfixture.hxx>
      17             : #include <test/htmltesttools.hxx>
      18             : #include <test/xmltesttools.hxx>
      19             : #include <comphelper/processfactory.hxx>
      20             : #include <unotools/mediadescriptor.hxx>
      21             : #include <unotools/ucbstreamhelper.hxx>
      22             : #include <unotools/localfilehelper.hxx>
      23             : #include <unotest/macros_test.hxx>
      24             : #include <sfx2/docfilt.hxx>
      25             : #include <sfx2/docfile.hxx>
      26             : 
      27             : #include "docsh.hxx"
      28             : 
      29             : using namespace css::uno;
      30             : using namespace css::lang;
      31             : using namespace css::frame;
      32             : using namespace utl;
      33             : 
      34           2 : class ScHTMLExportTest : public test::BootstrapFixture, public unotest::MacrosTest, public XmlTestTools, public HtmlTestTools
      35             : {
      36             :     Reference<XComponent> mxComponent;
      37             :     OUString              maFilterOptions;
      38             : 
      39           2 :     void load(const char* pDir, const char* pName)
      40             :     {
      41           2 :         if (mxComponent.is())
      42           1 :             mxComponent->dispose();
      43           2 :         mxComponent = loadFromDesktop(getURLFromSrc(pDir) + OUString::createFromAscii(pName), "com.sun.star.comp.Calc.SpreadsheetDocument");
      44           2 :     }
      45             : 
      46           2 :     void save(const OUString& aFilterName, TempFile& rTempFile)
      47             :     {
      48           2 :         Reference<XStorable> xStorable(mxComponent, UNO_QUERY);
      49           4 :         MediaDescriptor aMediaDescriptor;
      50           2 :         aMediaDescriptor["FilterName"] <<= aFilterName;
      51           2 :         if (!maFilterOptions.isEmpty())
      52           1 :             aMediaDescriptor["FilterOptions"] <<= maFilterOptions;
      53           4 :         xStorable->storeToURL(rTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
      54           2 :     }
      55             : 
      56             : public:
      57           1 :     ScHTMLExportTest()
      58           1 :     {}
      59             : 
      60           1 :     virtual void setUp() SAL_OVERRIDE
      61             :     {
      62           1 :         test::BootstrapFixture::setUp();
      63           1 :         mxDesktop.set(css::frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory())));
      64           1 :     }
      65             : 
      66           1 :     virtual void tearDown() SAL_OVERRIDE
      67             :     {
      68           1 :         if (mxComponent.is())
      69           1 :             mxComponent->dispose();
      70             : 
      71           1 :         test::BootstrapFixture::tearDown();
      72           1 :     }
      73             : 
      74           1 :     void testHtmlSkipImage()
      75             :     {
      76             :         // need a temp dir, because there's an image exported too
      77           1 :         TempFile aTempDir(0, true);
      78           2 :         OUString const url(aTempDir.GetURL());
      79           2 :         TempFile aTempFile(&url, false);
      80             : 
      81             :         htmlDocPtr pDoc;
      82             : 
      83           1 :         load("/sc/qa/extras/testdocuments/", "BaseForHTMLExport.ods");
      84           1 :         save("HTML (StarCalc)", aTempFile);
      85           1 :         pDoc = parseHtml(aTempFile);
      86           1 :         CPPUNIT_ASSERT (pDoc);
      87             : 
      88           1 :         assertXPath(pDoc, "/html/body", 1);
      89           1 :         assertXPath(pDoc, "/html/body/table/tr/td/img", 1);
      90             : 
      91           1 :         load("/sc/qa/extras/testdocuments/", "BaseForHTMLExport.ods");
      92           1 :         maFilterOptions = "SkipImages";
      93           1 :         save("HTML (StarCalc)", aTempFile);
      94             : 
      95           1 :         pDoc = parseHtml(aTempFile);
      96           1 :         CPPUNIT_ASSERT (pDoc);
      97           1 :         assertXPath(pDoc, "/html/body", 1);
      98           1 :         assertXPath(pDoc, "/html/body/table/tr/td/img", 0);
      99             : 
     100           2 :         utl::removeTree(aTempDir.GetURL());
     101           1 :     }
     102             : 
     103           2 :     CPPUNIT_TEST_SUITE(ScHTMLExportTest);
     104           1 :     CPPUNIT_TEST(testHtmlSkipImage);
     105           5 :     CPPUNIT_TEST_SUITE_END();
     106             : 
     107             : };
     108             : 
     109           1 : CPPUNIT_TEST_SUITE_REGISTRATION(ScHTMLExportTest);
     110             : 
     111           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     112             : 
     113             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11