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

Generated by: LCOV version 1.10