LCOV - code coverage report
Current view: top level - sw/qa/core - macros-test.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 53 53 100.0 %
Date: 2012-08-25 Functions: 13 14 92.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 114 234 48.7 %

           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) 2010 Red Hat, Inc., Caolán McNamara <caolanm@redhat.com>
      17                 :            :  *  (initial developer)
      18                 :            :  * Copyright (C) 2011 Markus Mohrhard <markus.mohrhard@googlemail.com>
      19                 :            :  *
      20                 :            :  * All Rights Reserved.
      21                 :            :  *
      22                 :            :  * For minor contributions see the git repository.
      23                 :            :  *
      24                 :            :  * Alternatively, the contents of this file may be used under the terms of
      25                 :            :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      26                 :            :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      27                 :            :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      28                 :            :  * instead of those above.
      29                 :            :  */
      30                 :            : 
      31                 :            : #include <sal/config.h>
      32                 :            : #include <unotest/macros_test.hxx>
      33                 :            : #include <test/bootstrapfixture.hxx>
      34                 :            : #include <rtl/strbuf.hxx>
      35                 :            : #include <osl/file.hxx>
      36                 :            : 
      37                 :            : #include <com/sun/star/frame/XDesktop.hpp>
      38                 :            : 
      39                 :            : #include <com/sun/star/lang/XComponent.hpp>
      40                 :            : #include <com/sun/star/frame/XComponentLoader.hpp>
      41                 :            : #include <com/sun/star/document/MacroExecMode.hpp>
      42                 :            : 
      43                 :            : #include <sfx2/app.hxx>
      44                 :            : #include <sfx2/docfilt.hxx>
      45                 :            : #include <sfx2/docfile.hxx>
      46                 :            : #include <sfx2/sfxmodelfactory.hxx>
      47                 :            : #include <svl/intitem.hxx>
      48                 :            : 
      49                 :            : #include <basic/sbxdef.hxx>
      50                 :            : 
      51                 :            : #include "docsh.hxx"
      52                 :            : 
      53                 :            : SO2_DECL_REF(SwDocShell)
      54                 :            : SO2_IMPL_REF(SwDocShell)
      55                 :            : 
      56                 :            : using namespace ::com::sun::star;
      57                 :            : using namespace ::com::sun::star::uno;
      58                 :            : 
      59                 :            : /* Implementation of Macros test */
      60                 :            : 
      61 [ +  - ][ -  + ]:          6 : class SwMacrosTest : public test::BootstrapFixture, public unotest::MacrosTest
      62                 :            : {
      63                 :            : public:
      64                 :            :     SwMacrosTest();
      65                 :            : 
      66                 :            :     SwDocShellRef load(const rtl::OUString &rFilter, const rtl::OUString &rURL,
      67                 :            :         const rtl::OUString &rUserData, const rtl::OUString& rTypeName, sal_uLong nFormatType=0);
      68                 :            : 
      69                 :            :     void createFileURL(const rtl::OUString& aFileBase, const rtl::OUString& aFileExtension, rtl::OUString& rFilePath);
      70                 :            : 
      71                 :            :     virtual void setUp();
      72                 :            :     virtual void tearDown();
      73                 :            : 
      74                 :            :     //void testStarBasic();
      75                 :            :     void testVba();
      76 [ +  - ][ +  - ]:          6 :     CPPUNIT_TEST_SUITE(SwMacrosTest);
         [ +  - ][ +  - ]
                 [ #  # ]
      77                 :            : #if !defined(MACOSX) && !defined(WNT)
      78                 :            :     //enable this test if you want to play with star basic macros in unit tests
      79                 :            :     //works but does nothing useful yet
      80                 :            :     //CPPUNIT_TEST(testStarBasic);
      81 [ +  - ][ +  - ]:          3 :     CPPUNIT_TEST(testVba);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      82                 :            : #endif
      83                 :            : 
      84 [ +  - ][ +  - ]:          6 :     CPPUNIT_TEST_SUITE_END();
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      85                 :            : 
      86                 :            : private:
      87                 :            :     uno::Reference<uno::XInterface> m_xWriterComponent;
      88                 :            :     ::rtl::OUString m_aBaseString;
      89                 :            : };
      90                 :            : 
      91                 :          3 : void SwMacrosTest::createFileURL(const rtl::OUString& aFileBase, const rtl::OUString& aFileExtension, rtl::OUString& rFilePath)
      92                 :            : {
      93         [ +  - ]:          3 :     rtl::OUString aSep(RTL_CONSTASCII_USTRINGPARAM("/"));
      94         [ +  - ]:          3 :     rtl::OUStringBuffer aBuffer( getSrcRootURL() );
      95 [ +  - ][ +  - ]:          3 :     aBuffer.append(m_aBaseString).append(aSep).append(aFileExtension);
                 [ +  - ]
      96 [ +  - ][ +  - ]:          3 :     aBuffer.append(aSep).append(aFileBase).append(aFileExtension);
                 [ +  - ]
      97         [ +  - ]:          3 :     rFilePath = aBuffer.makeStringAndClear();
      98                 :          3 : }
      99                 :            : 
     100                 :            : #if 0
     101                 :            : 
     102                 :            : void SwMacrosTest::testStarBasic()
     103                 :            : {
     104                 :            :     const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("StarBasic."));
     105                 :            :     rtl::OUString aFileExtension(aFileFormats[0].pName, strlen(aFileFormats[0].pName), RTL_TEXTENCODING_UTF8 );
     106                 :            :     rtl::OUString aFileName;
     107                 :            :     createFileURL(aFileNameBase, aFileExtension, aFileName);
     108                 :            :     uno::Reference< com::sun::star::lang::XComponent > xComponent = loadFromDesktop(aFileName);
     109                 :            : 
     110                 :            :     CPPUNIT_ASSERT_MESSAGE("Failed to load StarBasic.ods", xComponent.is());
     111                 :            : 
     112                 :            :     rtl::OUString aURL(RTL_CONSTASCII_USTRINGPARAM("vnd.sun.Star.script:Standard.Module1.Macro1?language=Basic&location=document"));
     113                 :            :     String sUrl = aURL;
     114                 :            :     Any aRet;
     115                 :            :     Sequence< sal_Int16 > aOutParamIndex;
     116                 :            :     Sequence< Any > aOutParam;
     117                 :            :     Sequence< uno::Any > aParams;
     118                 :            : 
     119                 :            :     SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent);
     120                 :            : 
     121                 :            :     CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
     122                 :            : 
     123                 :            :     pFoundShell->CallXScript(xComponent, sUrl, aParams, aRet, aOutParamIndex,aOutParam);
     124                 :            :     pFoundShell->DoClose();
     125                 :            : }
     126                 :            : 
     127                 :            : #endif
     128                 :            : 
     129                 :          3 : void SwMacrosTest::testVba()
     130                 :            : {
     131                 :            :     TestMacroInfo testInfo[] = {
     132                 :            :         {
     133                 :            :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("testVba.")),
     134                 :            :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("vnd.sun.Star.script:Project.NewMacros.Macro1?language=Basic&location=document"))
     135                 :            :         }
     136 [ +  - ][ +  - ]:          6 :     };
           [ #  #  #  # ]
     137         [ +  - ]:          3 :     rtl::OUString aFileExtension( RTL_CONSTASCII_USTRINGPARAM("doc") );
     138         [ +  + ]:          6 :     for ( sal_uInt32  i=0; i<SAL_N_ELEMENTS( testInfo ); ++i )
     139                 :            :     {
     140                 :          3 :         rtl::OUString aFileName;
     141         [ +  - ]:          3 :         createFileURL(testInfo[i].sFileBaseName, aFileExtension, aFileName);
     142         [ +  - ]:          3 :         uno::Reference< com::sun::star::lang::XComponent > xComponent = loadFromDesktop(aFileName);
     143 [ +  - ][ +  - ]:          3 :         rtl::OUStringBuffer sMsg( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Failed to load ")) );
     144         [ +  - ]:          3 :         sMsg.append ( aFileName );
     145 [ +  - ][ +  - ]:          3 :         CPPUNIT_ASSERT_MESSAGE( rtl::OUStringToOString( sMsg.makeStringAndClear(), RTL_TEXTENCODING_UTF8 ).getStr(), xComponent.is() );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     146                 :            : 
     147         [ +  - ]:          3 :         String sUrl = testInfo[i].sMacroUrl;
     148                 :          3 :         Any aRet;
     149         [ +  - ]:          3 :         Sequence< sal_Int16 > aOutParamIndex;
     150         [ +  - ]:          3 :         Sequence< Any > aOutParam;
     151         [ +  - ]:          3 :         Sequence< uno::Any > aParams;
     152                 :            : 
     153         [ +  - ]:          3 :         SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent);
     154                 :            : 
     155 [ +  - ][ +  - ]:          3 :         CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     156 [ +  - ][ +  - ]:          3 :         pFoundShell->CallXScript(xComponent, sUrl, aParams, aRet, aOutParamIndex,aOutParam);
     157                 :          3 :         rtl::OUString aStringRes;
     158                 :          3 :         aRet >>= aStringRes;
     159 [ +  - ][ +  - ]:          3 :         std::cout << "value of Ret " << rtl::OUStringToOString( aStringRes, RTL_TEXTENCODING_UTF8 ).getStr() << std::endl;
         [ +  - ][ +  - ]
     160                 :            :         //CPPUNIT_ASSERT_MESSAGE( "script reported failure",aStringRes == "OK" );
     161         [ +  - ]:          3 :         pFoundShell->DoClose();
     162 [ +  - ][ +  - ]:          9 :     }
         [ +  - ][ +  - ]
           [ +  +  #  # ]
     163                 :          3 : }
     164                 :            : 
     165                 :          3 : SwMacrosTest::SwMacrosTest()
     166 [ +  - ][ +  - ]:          3 :       : m_aBaseString(RTL_CONSTASCII_USTRINGPARAM("/sw/qa/core/data"))
     167                 :            : {
     168                 :          3 : }
     169                 :            : 
     170                 :          3 : void SwMacrosTest::setUp()
     171                 :            : {
     172                 :          3 :     test::BootstrapFixture::setUp();
     173                 :            : 
     174                 :            :     // This is a bit of a fudge, we do this to ensure that SwGlobals::ensure,
     175                 :            :     // which is a private symbol to us, gets called
     176                 :            :     m_xWriterComponent =
     177         [ +  - ]:          6 :         getMultiServiceFactory()->createInstance(rtl::OUString(
     178 [ +  - ][ +  - ]:          3 :         RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Writer.TextDocument")));
                 [ +  - ]
     179 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xWriterComponent.is());
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     180         [ +  - ]:          6 :     mxDesktop = Reference<com::sun::star::frame::XDesktop>( getMultiServiceFactory()->createInstance(
     181 [ +  - ][ +  - ]:          3 :                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ))), UNO_QUERY );
         [ +  - ][ +  - ]
     182 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT_MESSAGE("", mxDesktop.is());
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     183                 :          3 : }
     184                 :            : 
     185                 :          3 : void SwMacrosTest::tearDown()
     186                 :            : {
     187 [ +  - ][ +  - ]:          3 :     uno::Reference< lang::XComponent >( m_xWriterComponent, UNO_QUERY_THROW )->dispose();
     188                 :          3 :     test::BootstrapFixture::tearDown();
     189                 :          3 : }
     190                 :            : 
     191                 :          3 : CPPUNIT_TEST_SUITE_REGISTRATION(SwMacrosTest);
     192                 :            : 
     193 [ +  - ][ +  - ]:         12 : CPPUNIT_PLUGIN_IMPLEMENT();
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
     194                 :            : 
     195                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10