LCOV - code coverage report
Current view: top level - sw/qa/core - filters-test.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 30 30 100.0 %
Date: 2012-08-25 Functions: 16 17 94.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 81 164 49.4 %

           Branch data     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                 :        261 : SO2_DECL_REF(SwDocShell)
      54 [ +  - ][ +  - ]:        174 : SO2_IMPL_REF(SwDocShell)
      55                 :            : 
      56                 :            : using namespace ::com::sun::star;
      57                 :            : 
      58                 :            : /* Implementation of Filters test */
      59                 :            : 
      60 [ +  - ][ +  - ]:          9 : class SwFiltersTest
                 [ -  + ]
      61                 :            :     : public test::FiltersTest
      62                 :            :     , public test::BootstrapFixture
      63                 :            : {
      64                 :            : public:
      65                 :            :     bool load(const rtl::OUString &rFilter, const rtl::OUString &rURL, const rtl::OUString &rUserData);
      66                 :            :     virtual void setUp();
      67                 :            : 
      68                 :            :     // Ensure CVEs remain unbroken
      69                 :            :     void testCVEs();
      70                 :            : 
      71 [ +  - ][ +  - ]:          6 :     CPPUNIT_TEST_SUITE(SwFiltersTest);
         [ +  - ][ +  - ]
                 [ #  # ]
      72 [ +  - ][ +  - ]:          3 :     CPPUNIT_TEST(testCVEs);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      73 [ +  - ][ +  - ]:          6 :     CPPUNIT_TEST_SUITE_END();
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      74                 :            : 
      75                 :            : private:
      76                 :            :     uno::Reference<uno::XInterface> m_xWriterComponent;
      77                 :            : };
      78                 :            : 
      79                 :         87 : bool SwFiltersTest::load(const rtl::OUString &rFilter, const rtl::OUString &rURL,
      80                 :            :     const rtl::OUString &rUserData)
      81                 :            : {
      82                 :            :     SfxFilter* pFilter = new SfxFilter(
      83                 :            :         rFilter,
      84                 :            :         rtl::OUString(), 0, 0, rtl::OUString(), 0, rtl::OUString(),
      85 [ +  - ][ +  - ]:         87 :         rUserData, rtl::OUString() );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      86                 :            : 
      87 [ +  - ][ +  - ]:         87 :     SwDocShellRef xDocShRef = new SwDocShell;
      88 [ +  - ][ +  - ]:         87 :     SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ);
         [ +  - ][ +  - ]
      89         [ +  - ]:         87 :     pSrcMed->SetFilter(pFilter);
      90                 :            : 
      91         [ +  + ]:         87 :     if (rUserData == FILTER_TEXT_DLG)
      92                 :            :     {
      93                 :            :         pSrcMed->GetItemSet()->Put(
      94 [ +  - ][ +  - ]:          9 :             SfxStringItem(SID_FILE_FILTEROPTIONS, rtl::OUString("UTF8,LF,Liberation Mono,en-US")));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      95                 :            :     }
      96                 :            : 
      97         [ +  - ]:         87 :     bool bLoaded = xDocShRef->DoLoad(pSrcMed);
      98         [ +  - ]:         87 :     if (xDocShRef.Is())
      99         [ +  - ]:         87 :         xDocShRef->DoClose();
     100         [ +  - ]:         87 :     return bLoaded;
     101                 :            : }
     102                 :            : 
     103                 :          3 : void SwFiltersTest::testCVEs()
     104                 :            : {
     105                 :            :     testDir(rtl::OUString("Staroffice XML (Writer)"),
     106                 :            :             getURLFromSrc("/sw/qa/core/data/xml/"),
     107 [ +  - ][ +  - ]:          3 :             rtl::OUString(FILTER_XML));
     108                 :            : 
     109                 :            :     testDir(rtl::OUString("MS Word 97"),
     110                 :            :             getURLFromSrc("/sw/qa/core/data/ww8/"),
     111 [ +  - ][ +  - ]:          3 :             rtl::OUString(FILTER_WW8));
     112                 :            : 
     113                 :            :     testDir(rtl::OUString("Text (encoded)"),
     114                 :            :             getURLFromSrc("/sw/qa/core/data/txt/"),
     115 [ +  - ][ +  - ]:          3 :             rtl::OUString(FILTER_TEXT_DLG));
     116                 :          3 : }
     117                 :            : 
     118                 :          3 : void SwFiltersTest::setUp()
     119                 :            : {
     120                 :          3 :     test::BootstrapFixture::setUp();
     121                 :            : 
     122                 :            :     //This is a bit of a fudge, we do this to ensure that SwGlobals::ensure,
     123                 :            :     //which is a private symbol to us, gets called
     124                 :            :     m_xWriterComponent =
     125         [ +  - ]:          6 :         getMultiServiceFactory()->createInstance(rtl::OUString(
     126 [ +  - ][ +  - ]:          3 :         RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Writer.TextDocument")));
                 [ +  - ]
     127 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT_MESSAGE("no writer component!", m_xWriterComponent.is());
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     128                 :          3 : }
     129                 :            : 
     130                 :          3 : CPPUNIT_TEST_SUITE_REGISTRATION(SwFiltersTest);
     131                 :            : 
     132 [ +  - ][ +  - ]:         12 : CPPUNIT_PLUGIN_IMPLEMENT();
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
     133                 :            : 
     134                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10