update credits
[LibreOffice.git] / basic / qa / cppunit / test_vba.cxx
blobf7ddc6c494ece3414000020b9a1672ed256dc5f8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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;
15 namespace
19 class VBATest : public test::BootstrapFixture
21 public:
22 VBATest() : BootstrapFixture(true, false) {}
23 virtual ~VBATest(){}
24 void testMiscVBAFunctions();
25 void testMiscOLEStuff();
26 // Adds code needed to register the test suite
27 CPPUNIT_TEST_SUITE(VBATest);
29 // Declares the method as a test to call
30 CPPUNIT_TEST(testMiscVBAFunctions);
31 CPPUNIT_TEST(testMiscOLEStuff);
33 // End of test suite definition
34 CPPUNIT_TEST_SUITE_END();
38 void VBATest::testMiscVBAFunctions()
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.
59 OUString sMacroPathURL = getURLFromSrc("/basic/qa/vba_tests/");
60 // Some test data expects the uk locale
61 AllSettings aSettings = Application::GetSettings();
62 aSettings.SetLanguageTag( LanguageTag( LANGUAGE_ENGLISH_UK ) );
63 Application::SetSettings( aSettings );
64 for ( sal_uInt32 i=0; i<SAL_N_ELEMENTS( macroSource ); ++i )
66 OUString sMacroURL( sMacroPathURL );
67 sMacroURL += OUString::createFromAscii( macroSource[ i ] );
69 MacroSnippet myMacro;
70 myMacro.LoadSourceFromFile( sMacroURL );
71 SbxVariableRef pReturn = myMacro.Run();
72 if ( pReturn )
74 fprintf(stderr, "macro result for %s\n", macroSource[ i ] );
75 fprintf(stderr, "macro returned:\n%s\n", OUStringToOString( pReturn->GetOUString(), RTL_TEXTENCODING_UTF8 ).getStr() );
77 CPPUNIT_ASSERT_MESSAGE("No return variable huh?", pReturn != NULL );
78 CPPUNIT_ASSERT_MESSAGE("Result not as expected", pReturn->GetOUString() == "OK" );
82 void VBATest::testMiscOLEStuff()
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() )
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 );
99 bool bOk = false;
100 if( xOLEFactory.is() )
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();
106 if ( !bOk )
107 return; // can't do anything, skip test
109 const char* macroSource[] = {
110 "ole_ObjAssignNoDflt.vb",
111 "ole_ObjAssignToNothing.vb",
112 "ole_dfltObjDflMethod.vb",
115 OUString sMacroPathURL = getURLFromSrc("/basic/qa/vba_tests/");
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( "/", "\\" );
123 aArgs[ 0 ] = uno::makeAny( sPath );
125 for ( sal_uInt32 i=0; i<SAL_N_ELEMENTS( macroSource ); ++i )
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 )
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() );
137 CPPUNIT_ASSERT_MESSAGE("No return variable huh?", pReturn != NULL );
138 CPPUNIT_ASSERT_MESSAGE("Result not as expected", pReturn->GetOUString() == "OK" );
140 #else
141 // Avoid "this method is empty and should be removed" warning
142 (void) 42;
143 #endif
146 // Put the test suite in the registry
148 // Put the test suite in the registry
149 CPPUNIT_TEST_SUITE_REGISTRATION(VBATest);
150 } // namespace
151 CPPUNIT_PLUGIN_IMPLEMENT();
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */