LCOV - code coverage report
Current view: top level - libreoffice/sd/qa/unit - filters-test.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 79 82 96.3 %
Date: 2012-12-27 Functions: 16 17 94.1 %
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             :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4             :  *
       5             :  * The contents of this file are subject to the Mozilla Public License Version
       6             :  * 1.1 (the "License"); you may not use this file except in compliance with
       7             :  * the License. You may obtain a copy of the License at
       8             :  * http://www.mozilla.org/MPL/
       9             :  *
      10             :  * Software distributed under the License is distributed on an "AS IS" basis,
      11             :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12             :  * for the specific language governing rights and limitations under the
      13             :  * License.
      14             :  *
      15             :  * The Initial Developer of the Original Code is
      16             :  *       Michael Meeks <michael.meeks@suse.com>
      17             :  * Portions created by the Initial Developer are Copyright (C) 2011 the
      18             :  * Initial Developer. All Rights Reserved.
      19             :  *
      20             :  * Contributor(s):
      21             :  *   Caolán McNamara <caolanm@redhat.com>
      22             :  *
      23             :  * Alternatively, the contents of this file may be used under the terms of
      24             :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      25             :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      26             :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      27             :  * instead of those above.
      28             :  */
      29             : 
      30             : #include <sal/config.h>
      31             : #include <unotest/filters-test.hxx>
      32             : #include <test/bootstrapfixture.hxx>
      33             : #include <rtl/strbuf.hxx>
      34             : #include <osl/file.hxx>
      35             : #include <com/sun/star/lang/XComponent.hpp>
      36             : #include <com/sun/star/document/XFilter.hpp>
      37             : 
      38             : #include <sfx2/app.hxx>
      39             : #include <sfx2/docfilt.hxx>
      40             : #include <sfx2/docfile.hxx>
      41             : #include <sfx2/sfxmodelfactory.hxx>
      42             : #include <svl/stritem.hxx>
      43             : 
      44             : #include <svx/svdtext.hxx>
      45             : #include <svx/svdotext.hxx>
      46             : 
      47             : #include "drawdoc.hxx"
      48             : #include "../source/ui/inc/DrawDocShell.hxx"
      49             : 
      50             : #include <osl/process.h>
      51             : #include <osl/thread.h>
      52             : 
      53             : /* Implementation of Filters test */
      54             : 
      55             : using namespace ::com::sun::star;
      56             : 
      57           6 : class SdFiltersTest
      58             :     : public test::FiltersTest
      59             :     , public test::BootstrapFixture
      60             : {
      61             : public:
      62             :     SdFiltersTest();
      63             : 
      64             :     ::sd::DrawDocShellRef loadURL( const rtl::OUString &rURL );
      65             :     virtual bool load( const rtl::OUString &rFilter,
      66             :         const rtl::OUString &rURL, const rtl::OUString &rUserData,
      67             :         unsigned int nFilterFlags, unsigned int nClipboardID,
      68             :         unsigned int nFilterVersion);
      69             : 
      70             :     virtual void setUp();
      71             :     virtual void tearDown();
      72             : 
      73             :     void test();
      74             :     // Ensure CVEs remain unbroken
      75             :     void testCVEs();
      76             :     void testN778859();
      77             : 
      78           2 :     CPPUNIT_TEST_SUITE(SdFiltersTest);
      79           1 :     CPPUNIT_TEST(test);
      80           1 :     CPPUNIT_TEST(testN778859);
      81           1 :     CPPUNIT_TEST(testCVEs);
      82           2 :     CPPUNIT_TEST_SUITE_END();
      83             : 
      84             : private:
      85             :     uno::Reference<document::XFilter> m_xFilter;
      86             :     uno::Reference<uno::XInterface> m_xDrawComponent;
      87             : };
      88             : 
      89             : #define PPTX_FORMAT_TYPE 268959811
      90             : 
      91             : struct FileFormat {
      92             :     const char* pName; const char* pFilterName; const char* pTypeName; sal_uLong nFormatType;
      93             : };
      94             : 
      95             : // cf. sc/qa/unit/filters-test.cxx and filters/...*.xcu to fill out.
      96             : FileFormat aFileFormats[] = {
      97             :     { "pptx" , "Impress MS PowerPoint 2007 XML", "MS PowerPoint 2007 XML", PPTX_FORMAT_TYPE },
      98             :     { 0, 0, 0, 0 }
      99             : };
     100             : 
     101           2 : ::sd::DrawDocShellRef SdFiltersTest::loadURL( const rtl::OUString &rURL )
     102             : {
     103           2 :     FileFormat *pFmt = NULL;
     104             : 
     105           2 :     for (size_t i = 0; i < SAL_N_ELEMENTS (aFileFormats); i++)
     106             :     {
     107           2 :         pFmt = aFileFormats + i;
     108           2 :         if (pFmt->pName && rURL.endsWithIgnoreAsciiCaseAsciiL (pFmt->pName, strlen (pFmt->pName)))
     109           2 :             break;
     110             :     }
     111           2 :     CPPUNIT_ASSERT_MESSAGE( "missing filter info", pFmt && pFmt->pName != NULL );
     112             : 
     113           2 :     sal_uInt32 nFormat = 0;
     114           2 :     if (pFmt->nFormatType)
     115           2 :         nFormat = SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS;
     116             :     SfxFilter* aFilter = new SfxFilter(
     117             :         rtl::OUString::createFromAscii( pFmt->pFilterName ),
     118             :         rtl::OUString(), pFmt->nFormatType, nFormat,
     119             :         rtl::OUString::createFromAscii( pFmt->pTypeName ),
     120             :         0, rtl::OUString(), rtl::OUString(), /* userdata */
     121           2 :         rtl::OUString("private:factory/sdraw*") );
     122           2 :     aFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT);
     123             : 
     124           2 :     ::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell();
     125           2 :     SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ);
     126           2 :     pSrcMed->SetFilter(aFilter);
     127           2 :     if ( !xDocShRef->DoLoad(pSrcMed) )
     128             :     {
     129           0 :         if (xDocShRef.Is())
     130           0 :             xDocShRef->DoClose();
     131           0 :         CPPUNIT_ASSERT_MESSAGE( "failed to load", false );
     132             :     }
     133             : 
     134           2 :     return xDocShRef;
     135             : }
     136             : 
     137           1 : void SdFiltersTest::test()
     138             : {
     139           1 :     ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/a.pptx"));
     140           1 :     CPPUNIT_ASSERT_MESSAGE( "failed to load", xDocShRef.Is() );
     141           1 :     CPPUNIT_ASSERT_MESSAGE( "not in destruction", !xDocShRef->IsInDestruction() );
     142             : 
     143           1 :     SdDrawDocument *pDoc = xDocShRef->GetDoc();
     144           1 :     CPPUNIT_ASSERT_MESSAGE( "no document", pDoc != NULL );
     145             : 
     146             :     // cf. SdrModel svx/svdmodel.hxx ...
     147             : 
     148           1 :     CPPUNIT_ASSERT_MESSAGE( "wrong page count", pDoc->GetPageCount() == 3);
     149             : 
     150           1 :     const SdrPage *pPage = pDoc->GetPage (1);
     151           1 :     CPPUNIT_ASSERT_MESSAGE( "no page", pPage != NULL );
     152             : 
     153           1 :     sal_uIntPtr nObjs = pPage->GetObjCount();
     154           4 :     for (sal_uIntPtr i = 0; i < nObjs; i++)
     155             :     {
     156           3 :         SdrObject *pObj = pPage->GetObj(i);
     157           3 :         SdrObjKind eKind = (SdrObjKind) pObj->GetObjIdentifier();
     158           3 :         SdrTextObj *pTxt = dynamic_cast<SdrTextObj *>( pObj );
     159             :         (void)pTxt; (void)eKind;
     160             :     }
     161             : 
     162           1 :     CPPUNIT_ASSERT_MESSAGE( "changed", !pDoc->IsChanged() );
     163           1 :     xDocShRef->DoClose();
     164           1 : }
     165             : 
     166           1 : void SdFiltersTest::testN778859()
     167             : {
     168           1 :     ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/pptx/n778859.pptx"));
     169           1 :     CPPUNIT_ASSERT_MESSAGE( "failed to load", xDocShRef.Is() );
     170           1 :     CPPUNIT_ASSERT_MESSAGE( "not in destruction", !xDocShRef->IsInDestruction() );
     171             : 
     172           1 :     SdDrawDocument *pDoc = xDocShRef->GetDoc();
     173           1 :     CPPUNIT_ASSERT_MESSAGE( "no document", pDoc != NULL );
     174           1 :     const SdrPage *pPage = pDoc->GetPage(1);
     175           1 :     CPPUNIT_ASSERT_MESSAGE( "no page", pPage != NULL );
     176             :     {
     177             :         // Get the object
     178           1 :         SdrObject *pObj = pPage->GetObj(1);
     179           1 :         SdrTextObj *pTxtObj = dynamic_cast<SdrTextObj *>( pObj );
     180           1 :         CPPUNIT_ASSERT(!pTxtObj->IsAutoFit());
     181           1 :     }
     182           1 : }
     183             : 
     184           7 : bool SdFiltersTest::load(const rtl::OUString &rFilter, const rtl::OUString &rURL,
     185             :     const rtl::OUString &rUserData, unsigned int nFilterFlags, unsigned int nClipboardID,
     186             :     unsigned int nFilterVersion)
     187             : {
     188             :     SfxFilter aFilter(
     189             :         rFilter,
     190             :         rtl::OUString(), nFilterFlags, nClipboardID, rtl::OUString(), 0, rtl::OUString(),
     191           7 :         rUserData, rtl::OUString() );
     192           7 :     aFilter.SetVersion(nFilterVersion);
     193             : 
     194           7 :     ::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell();
     195           7 :     SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ);
     196           7 :     pSrcMed->SetFilter(&aFilter);
     197           7 :     bool bLoaded = xDocShRef->DoLoad(pSrcMed);
     198           7 :     xDocShRef->DoClose();
     199           7 :     return bLoaded;
     200             : }
     201             : 
     202           1 : void SdFiltersTest::testCVEs()
     203             : {
     204             : #ifndef DISABLE_CVE_TESTS
     205             :     testDir(rtl::OUString("MS PowerPoint 97"),
     206             :             getURLFromSrc("/sd/qa/unit/data/ppt/"),
     207           1 :             rtl::OUString("sdfilt"));
     208             : 
     209             :     testDir(rtl::OUString("draw8"),
     210             :             getURLFromSrc("/sd/qa/unit/data/odg/"),
     211           1 :             rtl::OUString("sdfilt"));
     212             : #endif
     213           1 : }
     214             : 
     215           3 : SdFiltersTest::SdFiltersTest()
     216             : {
     217           3 : }
     218             : 
     219           3 : void SdFiltersTest::setUp()
     220             : {
     221           3 :     test::BootstrapFixture::setUp();
     222             : 
     223             :     // This is a bit of a fudge, we do this to ensure that ScGlobals::ensure,
     224             :     // which is a private symbol to us, gets called
     225             :     m_xDrawComponent =
     226           3 :         getMultiServiceFactory()->createInstance("com.sun.star.comp.Draw.PresentationDocument");
     227           3 :     CPPUNIT_ASSERT_MESSAGE("no impress component!", m_xDrawComponent.is());
     228           3 : }
     229             : 
     230           3 : void SdFiltersTest::tearDown()
     231             : {
     232           3 :     uno::Reference< lang::XComponent >( m_xDrawComponent, uno::UNO_QUERY_THROW )->dispose();
     233           3 :     test::BootstrapFixture::tearDown();
     234           3 : }
     235             : 
     236           1 : CPPUNIT_TEST_SUITE_REGISTRATION(SdFiltersTest);
     237             : 
     238           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     239             : 
     240             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10