LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/basic/qa/cppunit - test_vba.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 26 65 40.0 %
Date: 2013-07-09 Functions: 10 13 76.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             : #include "basictest.hxx"
      10             : #include <vcl/svapp.hxx>
      11             : #include <comphelper/processfactory.hxx>
      12             : using namespace ::com::sun::star;
      13             : 
      14             : namespace
      15             : {
      16             : 
      17             : 
      18             :     class VBATest : public test::BootstrapFixture
      19             :     {
      20             :         bool hasOLEEnv();
      21             :         public:
      22           1 :         VBATest() : BootstrapFixture(true, false) {}
      23           2 :         ~VBATest(){}
      24             :         void testMiscVBAFunctions();
      25             :         void testMiscOLEStuff();
      26             :         // Adds code needed to register the test suite
      27           2 :         CPPUNIT_TEST_SUITE(VBATest);
      28             : 
      29             :         // Declares the method as a test to call
      30           1 :         CPPUNIT_TEST(testMiscVBAFunctions);
      31             : // not much point even trying to run except on windows
      32             : #if defined(WNT)
      33             :         CPPUNIT_TEST(testMiscOLEStuff);
      34             : #endif
      35             : 
      36             :         // End of test suite definition
      37           2 :         CPPUNIT_TEST_SUITE_END();
      38             : 
      39             :     };
      40             : 
      41           0 : bool VBATest::hasOLEEnv()
      42             : {
      43             :     // test if we have the necessary runtime environment
      44             :     // to run the OLE tests.
      45           0 :     static uno::Reference< lang::XMultiServiceFactory > xOLEFactory;
      46           0 :     if ( !xOLEFactory.is() )
      47             :     {
      48             :         uno::Reference< uno::XComponentContext > xContext(
      49           0 :             comphelper::getProcessComponentContext() );
      50           0 :         if( xContext.is() )
      51             :         {
      52           0 :             uno::Reference<lang::XMultiComponentFactory> xSMgr = xContext->getServiceManager();
      53           0 :             xOLEFactory = uno::Reference<lang::XMultiServiceFactory>(
      54           0 :                 xSMgr->createInstanceWithContext(
      55             :                     "com.sun.star.bridge.OleObjectFactory",
      56           0 :                         xContext ), uno::UNO_QUERY );
      57           0 :         }
      58             :     }
      59           0 :     bool bOk = false;
      60           0 :     if( xOLEFactory.is() )
      61             :     {
      62           0 :         uno::Reference< uno::XInterface > xExcel = xOLEFactory->createInstance( "Excel.Application" );
      63           0 :         uno::Reference< uno::XInterface > xADODB = xOLEFactory->createInstance( "ADODB.Connection" );
      64           0 :        bOk = xExcel.is() && xADODB.is();
      65             :     }
      66           0 :     return bOk;
      67             : }
      68             : 
      69           1 : void VBATest::testMiscVBAFunctions()
      70             : {
      71             :     const char* macroSource[] = {
      72             :         "bytearraystring.vb",
      73             : // datevalue test seems to depend on both locale and language
      74             : // settings, should try and rewrite the test to deal with that
      75             : // for some reason tinderboxes don't seem to complain leaving enabled
      76             : // for the moment
      77             :         "datevalue.vb",
      78             :         "partition.vb",
      79             :         "strconv.vb",
      80             :         "dateserial.vb",
      81             :         "format.vb",
      82             :         "replace.vb",
      83             :         "stringplusdouble.vb"
      84           1 :     };
      85           1 :     OUString sMacroPathURL = getURLFromSrc("/basic/qa/vba_tests/");
      86             :     // Some test data expects the uk locale
      87           2 :     AllSettings aSettings = Application::GetSettings();
      88           1 :     aSettings.SetLanguageTag( LanguageTag( LANGUAGE_ENGLISH_UK ) );
      89           1 :     Application::SetSettings( aSettings );
      90           9 :     for ( sal_uInt32  i=0; i<SAL_N_ELEMENTS( macroSource ); ++i )
      91             :     {
      92           8 :         OUString sMacroURL( sMacroPathURL );
      93           8 :         sMacroURL += OUString::createFromAscii( macroSource[ i ] );
      94             : 
      95          16 :         MacroSnippet myMacro;
      96           8 :         myMacro.LoadSourceFromFile( sMacroURL );
      97          16 :         SbxVariableRef pReturn = myMacro.Run();
      98           8 :         if ( pReturn )
      99             :         {
     100           8 :             fprintf(stderr, "macro result for %s\n", macroSource[ i ] );
     101           8 :             fprintf(stderr, "macro returned:\n%s\n", OUStringToOString( pReturn->GetOUString(), RTL_TEXTENCODING_UTF8 ).getStr() );
     102             :         }
     103           8 :         CPPUNIT_ASSERT_MESSAGE("No return variable huh?", pReturn != NULL );
     104           8 :         CPPUNIT_ASSERT_MESSAGE("Result not as expected", pReturn->GetOUString() == "OK" );
     105           9 :     }
     106           1 : }
     107             : 
     108           0 : void VBATest::testMiscOLEStuff()
     109             : {
     110           0 :     bool bCanRunOleTests = hasOLEEnv();
     111           0 :     if ( !bCanRunOleTests )
     112           0 :         return; // can't do anything, skip test
     113             : 
     114             :     const char* macroSource[] = {
     115             :         "ole_ObjAssignNoDflt.vb",
     116             :         "ole_ObjAssignToNothing.vb",
     117             :         "ole_dfltObjDflMethod.vb",
     118           0 :     };
     119             : 
     120           0 :     OUString sMacroPathURL = getURLFromSrc("/basic/qa/vba_tests/");
     121             : 
     122           0 :     uno::Sequence< uno::Any > aArgs(1);
     123             :     // path to test document
     124           0 :     OUString sPath = getPathFromSrc("/basic/qa/vba_tests/data/");
     125           0 :     sPath += "ADODBdata.xls";
     126           0 :     sPath = sPath.replaceAll( "/", "\\" );
     127             : 
     128           0 :     aArgs[ 0 ] = uno::makeAny( sPath );
     129             : 
     130           0 :     for ( sal_uInt32  i=0; i<SAL_N_ELEMENTS( macroSource ); ++i )
     131             :     {
     132           0 :         OUString sMacroURL( sMacroPathURL );
     133           0 :         sMacroURL += OUString::createFromAscii( macroSource[ i ] );
     134           0 :         MacroSnippet myMacro;
     135           0 :         myMacro.LoadSourceFromFile( sMacroURL );
     136           0 :         SbxVariableRef pReturn = myMacro.Run( aArgs );
     137           0 :         if ( pReturn )
     138             :         {
     139           0 :             fprintf(stderr, "macro result for %s\n", macroSource[ i ] );
     140           0 :             fprintf(stderr, "macro returned:\n%s\n", OUStringToOString( pReturn->GetOUString(), RTL_TEXTENCODING_UTF8 ).getStr() );
     141             :         }
     142           0 :         CPPUNIT_ASSERT_MESSAGE("No return variable huh?", pReturn != NULL );
     143           0 :         CPPUNIT_ASSERT_MESSAGE("Result not as expected", pReturn->GetOUString() == "OK" );
     144           0 :     }
     145             : }
     146             : 
     147             :   // Put the test suite in the registry
     148             : 
     149             :   // Put the test suite in the registry
     150           1 :   CPPUNIT_TEST_SUITE_REGISTRATION(VBATest);
     151             : } // namespace
     152           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     153             : 
     154             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10