LCOV - code coverage report
Current view: top level - libreoffice/sw/qa/core - filters-test.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 32 32 100.0 %
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 or as specified alternatively below. You may obtain a copy of
       8             :  * the License at 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             :  * Major Contributor(s):
      16             :  * Copyright (C) 2011 Red Hat, Inc., Caolán McNamara <caolanm@redhat.com>
      17             :  *  (initial developer)
      18             :  *
      19             :  * All Rights Reserved.
      20             :  *
      21             :  * For minor contributions see the git repository.
      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 <unotest/filters-test.hxx>
      31             : #include <test/bootstrapfixture.hxx>
      32             : 
      33             : #include <cppuhelper/implbase1.hxx>
      34             : 
      35             : #include <comphelper/processfactory.hxx>
      36             : 
      37             : #include <sfx2/app.hxx>
      38             : #include <sfx2/docfilt.hxx>
      39             : #include <sfx2/docfile.hxx>
      40             : #include <sfx2/sfxmodelfactory.hxx>
      41             : #include <sfx2/sfxsids.hrc>
      42             : 
      43             : #include <svl/stritem.hxx>
      44             : 
      45             : #include "init.hxx"
      46             : #include "iodetect.hxx"
      47             : #include "swtypes.hxx"
      48             : #include "doc.hxx"
      49             : #include "docsh.hxx"
      50             : #include "shellres.hxx"
      51             : #include "docufld.hxx"
      52             : 
      53          93 : SV_DECL_REF(SwDocShell)
      54          62 : SV_IMPL_REF(SwDocShell)
      55             : 
      56             : using namespace ::com::sun::star;
      57             : 
      58             : /* Implementation of Filters test */
      59             : 
      60           3 : class SwFiltersTest
      61             :     : public test::FiltersTest
      62             :     , public test::BootstrapFixture
      63             : {
      64             : public:
      65             :     virtual bool load( const rtl::OUString &rFilter, const rtl::OUString &rURL,
      66             :         const rtl::OUString &rUserData, unsigned int nFilterFlags,
      67             :         unsigned int nClipboardID, unsigned int nFilterVersion);
      68             :     virtual void setUp();
      69             : 
      70             :     // Ensure CVEs remain unbroken
      71             :     void testCVEs();
      72             : 
      73           2 :     CPPUNIT_TEST_SUITE(SwFiltersTest);
      74           1 :     CPPUNIT_TEST(testCVEs);
      75           2 :     CPPUNIT_TEST_SUITE_END();
      76             : 
      77             : private:
      78             :     uno::Reference<uno::XInterface> m_xWriterComponent;
      79             : };
      80             : 
      81          31 : bool SwFiltersTest::load(const rtl::OUString &rFilter, const rtl::OUString &rURL,
      82             :     const rtl::OUString &rUserData, unsigned int nFilterFlags,
      83             :         unsigned int nClipboardID, unsigned int nFilterVersion)
      84             : {
      85             :     SfxFilter* pFilter = new SfxFilter(
      86             :         rFilter, rtl::OUString(), nFilterFlags,
      87             :         nClipboardID, rtl::OUString(), 0, rtl::OUString(),
      88          31 :         rUserData, rtl::OUString());
      89          31 :     pFilter->SetVersion(nFilterVersion);
      90             : 
      91          31 :     SwDocShellRef xDocShRef = new SwDocShell;
      92          31 :     SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ);
      93          31 :     pSrcMed->SetFilter(pFilter);
      94             : 
      95          31 :     if (rUserData == FILTER_TEXT_DLG)
      96             :     {
      97             :         pSrcMed->GetItemSet()->Put(
      98           3 :             SfxStringItem(SID_FILE_FILTEROPTIONS, rtl::OUString("UTF8,LF,Liberation Mono,en-US")));
      99             :     }
     100             : 
     101          31 :     bool bLoaded = xDocShRef->DoLoad(pSrcMed);
     102          31 :     if (xDocShRef.Is())
     103          31 :         xDocShRef->DoClose();
     104          31 :     return bLoaded;
     105             : }
     106             : 
     107             : #define isstorage 1
     108             : 
     109           1 : void SwFiltersTest::testCVEs()
     110             : {
     111             :     testDir(rtl::OUString("Staroffice XML (Writer)"),
     112             :             getURLFromSrc("/sw/qa/core/data/xml/"),
     113             :             rtl::OUString(FILTER_XML),
     114             :             SFX_FILTER_IMPORT | SFX_FILTER_OWN | SFX_FILTER_DEFAULT,
     115           1 :             isstorage, SOFFICE_FILEFORMAT_CURRENT);
     116             : 
     117             :     testDir(rtl::OUString("writer8"),
     118             :             getURLFromSrc("/sw/qa/core/data/odt/"),
     119             :             rtl::OUString(FILTER_XML),
     120             :             SFX_FILTER_IMPORT | SFX_FILTER_OWN | SFX_FILTER_DEFAULT,
     121           1 :             isstorage, SOFFICE_FILEFORMAT_CURRENT);
     122             : 
     123             :     testDir(rtl::OUString("MS Word 97"),
     124             :             getURLFromSrc("/sw/qa/core/data/ww8/"),
     125           1 :             rtl::OUString(FILTER_WW8));
     126             : 
     127             :     testDir(rtl::OUString("Text (encoded)"),
     128             :             getURLFromSrc("/sw/qa/core/data/txt/"),
     129           1 :             rtl::OUString(FILTER_TEXT_DLG));
     130           1 : }
     131             : 
     132           1 : void SwFiltersTest::setUp()
     133             : {
     134           1 :     test::BootstrapFixture::setUp();
     135             : 
     136             :     //This is a bit of a fudge, we do this to ensure that SwGlobals::ensure,
     137             :     //which is a private symbol to us, gets called
     138             :     m_xWriterComponent =
     139           2 :         getMultiServiceFactory()->createInstance(rtl::OUString(
     140           1 :         RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Writer.TextDocument")));
     141           1 :     CPPUNIT_ASSERT_MESSAGE("no writer component!", m_xWriterComponent.is());
     142           1 : }
     143             : 
     144           1 : CPPUNIT_TEST_SUITE_REGISTRATION(SwFiltersTest);
     145             : 
     146           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     147             : 
     148             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10