1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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
;
19 class VBATest
: public test::BootstrapFixture
22 VBATest() : BootstrapFixture(true, false) {}
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
[] = {
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
53 "stringplusdouble.vb",
54 #ifndef WIN32 // missing 64bit Currency marshalling.
55 "win32compat.vb", // windows compatibility hooks.
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
] );
70 myMacro
.LoadSourceFromFile( sMacroURL
);
71 SbxVariableRef pReturn
= myMacro
.Run();
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
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() );
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
);
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();
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
);
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" );
141 // Avoid "this method is empty and should be removed" warning
146 // Put the test suite in the registry
148 // Put the test suite in the registry
149 CPPUNIT_TEST_SUITE_REGISTRATION(VBATest
);
151 CPPUNIT_PLUGIN_IMPLEMENT();
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */