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

Generated by: LCOV version 1.10