LCOV - code coverage report
Current view: top level - sd/qa/unit - filters-test.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 34 34 100.0 %
Date: 2014-11-03 Functions: 13 14 92.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 <sal/config.h>
      11             : #include <unotest/filters-test.hxx>
      12             : #include <test/bootstrapfixture.hxx>
      13             : #include <rtl/strbuf.hxx>
      14             : #include <osl/file.hxx>
      15             : #include <com/sun/star/lang/XComponent.hpp>
      16             : #include <com/sun/star/document/XFilter.hpp>
      17             : 
      18             : #include <sfx2/app.hxx>
      19             : #include <sfx2/docfilt.hxx>
      20             : #include <sfx2/docfile.hxx>
      21             : #include <sfx2/sfxmodelfactory.hxx>
      22             : #include <svl/stritem.hxx>
      23             : 
      24             : #include <svx/svdtext.hxx>
      25             : #include <svx/svdotext.hxx>
      26             : 
      27             : #include "drawdoc.hxx"
      28             : #include "../source/ui/inc/DrawDocShell.hxx"
      29             : 
      30             : #include <osl/process.h>
      31             : #include <osl/thread.h>
      32             : 
      33             : using namespace ::com::sun::star;
      34             : 
      35             : /// Test loading of files to assure they do not crash on load.
      36           4 : class SdFiltersTest
      37             :     : public test::FiltersTest
      38             :     , public test::BootstrapFixture
      39             : {
      40             : public:
      41             :     SdFiltersTest();
      42             : 
      43             :     virtual bool load( const OUString &rFilter,
      44             :         const OUString &rURL, const OUString &rUserData,
      45             :         unsigned int nFilterFlags, unsigned int nClipboardID,
      46             :         unsigned int nFilterVersion) SAL_OVERRIDE;
      47             : 
      48             :     virtual void setUp() SAL_OVERRIDE;
      49             :     virtual void tearDown() SAL_OVERRIDE;
      50             : 
      51             :     // Ensure CVEs remain unbroken
      52             :     void testCVEs();
      53             : 
      54           4 :     CPPUNIT_TEST_SUITE(SdFiltersTest);
      55           2 :     CPPUNIT_TEST(testCVEs);
      56           4 :     CPPUNIT_TEST_SUITE_END();
      57             : 
      58             : private:
      59             :     uno::Reference<uno::XInterface> m_xDrawComponent;
      60             : };
      61             : 
      62          22 : bool SdFiltersTest::load(const OUString &rFilter, const OUString &rURL,
      63             :     const OUString &rUserData, unsigned int nFilterFlags, unsigned int nClipboardID,
      64             :     unsigned int nFilterVersion)
      65             : {
      66             :     SfxFilter aFilter(
      67             :         rFilter,
      68             :         OUString(), nFilterFlags, nClipboardID, OUString(), 0, OUString(),
      69          22 :         rUserData, OUString() );
      70          22 :     aFilter.SetVersion(nFilterVersion);
      71             : 
      72          44 :     ::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell();
      73          22 :     SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ);
      74          22 :     pSrcMed->SetFilter(&aFilter);
      75          22 :     bool bLoaded = xDocShRef->DoLoad(pSrcMed);
      76          22 :     xDocShRef->DoClose();
      77          44 :     return bLoaded;
      78             : }
      79             : 
      80           2 : void SdFiltersTest::testCVEs()
      81             : {
      82             : #ifndef DISABLE_CVE_TESTS
      83             :     testDir(OUString("MS PowerPoint 97"),
      84             :             getURLFromSrc("/sd/qa/unit/data/ppt/"),
      85           2 :             OUString("sdfilt"));
      86             : 
      87             :     testDir(OUString("Impress Office Open XML"),
      88             :             getURLFromSrc("/sd/qa/unit/data/pptx/"),
      89           2 :             OUString(""),  (SFX_FILTER_IMPORT | SFX_FILTER_ALIEN | SFX_FILTER_STARONEFILTER));
      90             : 
      91             :     testDir(OUString("impress8"),
      92             :             getURLFromSrc("/sd/qa/unit/data/odp/"),
      93           2 :             OUString("sdfilt"));
      94             : 
      95             :     testDir(OUString("draw8"),
      96             :             getURLFromSrc("/sd/qa/unit/data/odg/"),
      97           2 :             OUString("sdfilt"));
      98             : 
      99             :     testDir(OUString("CGM - Computer Graphics Metafile"),
     100             :             getURLFromSrc("/sd/qa/unit/data/cgm/"),
     101           2 :             OUString("icg"));
     102             : #endif
     103           2 : }
     104             : 
     105           2 : SdFiltersTest::SdFiltersTest()
     106             : {
     107           2 : }
     108             : 
     109           2 : void SdFiltersTest::setUp()
     110             : {
     111           2 :     test::BootstrapFixture::setUp();
     112             : 
     113             :     // This is a bit of a fudge, we do this to ensure that ScGlobals::ensure,
     114             :     // which is a private symbol to us, gets called
     115           4 :     m_xDrawComponent =
     116           6 :         getMultiServiceFactory()->createInstance("com.sun.star.comp.Draw.PresentationDocument");
     117           2 :     CPPUNIT_ASSERT_MESSAGE("no impress component!", m_xDrawComponent.is());
     118           2 : }
     119             : 
     120           2 : void SdFiltersTest::tearDown()
     121             : {
     122           2 :     uno::Reference< lang::XComponent >( m_xDrawComponent, uno::UNO_QUERY_THROW )->dispose();
     123           2 :     test::BootstrapFixture::tearDown();
     124           2 : }
     125             : 
     126           2 : CPPUNIT_TEST_SUITE_REGISTRATION(SdFiltersTest);
     127             : 
     128           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     129             : 
     130             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10