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

Generated by: LCOV version 1.10