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 <comphelper/processfactory.hxx>
11 #include <unotools/syslocaleoptions.hxx>
20 using namespace ::com::sun::star
;
24 class VBATest
: public test::BootstrapFixture
27 VBATest() : BootstrapFixture(true, false) {}
28 void testMiscVBAFunctions();
29 void testMiscOLEStuff();
30 // Adds code needed to register the test suite
31 CPPUNIT_TEST_SUITE(VBATest
);
33 // Declares the method as a test to call
34 CPPUNIT_TEST(testMiscVBAFunctions
);
35 CPPUNIT_TEST(testMiscOLEStuff
);
37 // End of test suite definition
38 CPPUNIT_TEST_SUITE_END();
42 void VBATest::testMiscVBAFunctions()
44 const char* macroSource
[] = {
47 "cdec.vb", // currently CDec is implemented only on Windows
50 // datevalue test seems to depend on both locale and language
51 // settings, should try and rewrite the test to deal with that
52 // for some reason tinderboxes don't seem to complain leaving enabled
60 "stringplusdouble.vb",
114 #ifndef WIN32 // missing 64bit Currency marshalling.
115 "win32compat.vb", // windows compatibility hooks.
117 "win32compatb.vb" // same methods, different signatures.
119 OUString sMacroPathURL
= m_directories
.getURLFromSrc("/basic/qa/vba_tests/");
120 // Some test data expects the uk locale
121 LanguageTag
aLocale(LANGUAGE_ENGLISH_UK
);
122 SvtSysLocaleOptions aLocalOptions
;
123 aLocalOptions
.SetLocaleConfigString( aLocale
.getBcp47() );
125 for ( sal_uInt32 i
=0; i
<SAL_N_ELEMENTS( macroSource
); ++i
)
127 OUString sMacroURL
= sMacroPathURL
128 + OUString::createFromAscii( macroSource
[ i
] );
130 MacroSnippet myMacro
;
131 myMacro
.LoadSourceFromFile( sMacroURL
);
132 SbxVariableRef pReturn
= myMacro
.Run();
135 fprintf(stderr
, "macro result for %s\n", macroSource
[ i
] );
136 fprintf(stderr
, "macro returned:\n%s\n", OUStringToOString( pReturn
->GetOUString(), RTL_TEXTENCODING_UTF8
).getStr() );
138 CPPUNIT_ASSERT_MESSAGE("No return variable huh?", pReturn
.get() != nullptr );
139 CPPUNIT_ASSERT_EQUAL_MESSAGE("Result not as expected", OUString("OK"), pReturn
->GetOUString() );
143 void VBATest::testMiscOLEStuff()
145 // Not much point even trying to run except on Windows.
146 // (Without Excel doesn't really do anything anyway,
147 // see "so skip test" below.)
149 // test if we have the necessary runtime environment
150 // to run the OLE tests.
151 uno::Reference
< lang::XMultiServiceFactory
> xOLEFactory
;
152 uno::Reference
< uno::XComponentContext
> xContext(
153 comphelper::getProcessComponentContext() );
156 uno::Reference
<lang::XMultiComponentFactory
> xSMgr
= xContext
->getServiceManager();
157 xOLEFactory
.set( xSMgr
->createInstanceWithContext( "com.sun.star.bridge.OleObjectFactory", xContext
),
161 if( xOLEFactory
.is() )
163 uno::Reference
< uno::XInterface
> xADODB
= xOLEFactory
->createInstance( "ADODB.Connection" );
167 return; // can't do anything, skip test
169 const int nBufSize
= 1024 * 4;
170 wchar_t sBuf
[nBufSize
];
171 SQLGetInstalledDriversW( sBuf
, nBufSize
, nullptr );
173 const wchar_t *pODBCDriverName
= sBuf
;
175 for (; wcslen( pODBCDriverName
) != 0; pODBCDriverName
+= wcslen( pODBCDriverName
) + 1 ) {
176 if( wcscmp( pODBCDriverName
, L
"Microsoft Excel Driver (*.xls)" ) == 0 ||
177 wcscmp( pODBCDriverName
, L
"Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)" ) == 0 ) {
183 return; // can't find ODBC driver needed test, so skip test
185 const char* macroSource
[] = {
186 "ole_ObjAssignNoDflt.vb",
187 "ole_ObjAssignToNothing.vb",
189 // This test uses Microsoft.Jet.OLEDB.4.0 Provider, that is unavailable on Win64
190 "ole_dfltObjDflMethod.vb",
194 OUString sMacroPathURL
= m_directories
.getURLFromSrc("/basic/qa/vba_tests/");
196 uno::Sequence
< uno::Any
> aArgs(2);
197 // path to test document
198 OUString sPath
= m_directories
.getPathFromSrc("/basic/qa/vba_tests/data/ADODBdata.xls");
199 sPath
= sPath
.replaceAll( "/", "\\" );
201 aArgs
[ 0 ] <<= sPath
;
202 aArgs
[ 1 ] <<= OUString(
203 reinterpret_cast<sal_Unicode
const *>(pODBCDriverName
));
205 for ( sal_uInt32 i
=0; i
<SAL_N_ELEMENTS( macroSource
); ++i
)
207 OUString sMacroURL
= sMacroPathURL
208 + OUString::createFromAscii( macroSource
[ i
] );
209 MacroSnippet myMacro
;
210 myMacro
.LoadSourceFromFile( sMacroURL
);
211 SbxVariableRef pReturn
= myMacro
.Run( aArgs
);
214 fprintf(stderr
, "macro result for %s\n", macroSource
[ i
] );
215 fprintf(stderr
, "macro returned:\n%s\n", OUStringToOString( pReturn
->GetOUString(), RTL_TEXTENCODING_UTF8
).getStr() );
217 CPPUNIT_ASSERT_MESSAGE("No return variable huh?", pReturn
.get() != nullptr );
218 CPPUNIT_ASSERT_EQUAL_MESSAGE("Result not as expected", OUString("OK"), pReturn
->GetOUString() );
221 // Avoid "this method is empty and should be removed" warning
226 // Put the test suite in the registry
227 CPPUNIT_TEST_SUITE_REGISTRATION(VBATest
);
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */