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 // datevalue test seems to depend on both locale and language
48 // settings, should try and rewrite the test to deal with that
49 // for some reason tinderboxes don't seem to complain leaving enabled
57 "stringplusdouble.vb",
58 #ifndef WIN32 // missing 64bit Currency marshalling.
59 "win32compat.vb", // windows compatibility hooks.
61 "win32compatb.vb" // same methods, different signatures.
63 OUString sMacroPathURL
= m_directories
.getURLFromSrc("/basic/qa/vba_tests/");
64 // Some test data expects the uk locale
65 LanguageTag
aLocale(LANGUAGE_ENGLISH_UK
);
66 SvtSysLocaleOptions aLocalOptions
;
67 aLocalOptions
.SetLocaleConfigString( aLocale
.getBcp47() );
69 for ( sal_uInt32 i
=0; i
<SAL_N_ELEMENTS( macroSource
); ++i
)
71 OUString sMacroURL
= sMacroPathURL
72 + OUString::createFromAscii( macroSource
[ i
] );
75 myMacro
.LoadSourceFromFile( sMacroURL
);
76 SbxVariableRef pReturn
= myMacro
.Run();
79 fprintf(stderr
, "macro result for %s\n", macroSource
[ i
] );
80 fprintf(stderr
, "macro returned:\n%s\n", OUStringToOString( pReturn
->GetOUString(), RTL_TEXTENCODING_UTF8
).getStr() );
82 CPPUNIT_ASSERT_MESSAGE("No return variable huh?", pReturn
.get() != nullptr );
83 CPPUNIT_ASSERT_EQUAL_MESSAGE("Result not as expected", OUString("OK"), pReturn
->GetOUString() );
87 void VBATest::testMiscOLEStuff()
89 // Not much point even trying to run except on Windows. Does not work
90 // on 64-bit Windows with Excel installed. (Without Excel doesn't
91 // really do anything anyway, see "so skip test" below.)
92 #if defined(_WIN32) && !defined(_WIN64)
93 // test if we have the necessary runtime environment
94 // to run the OLE tests.
95 uno::Reference
< lang::XMultiServiceFactory
> xOLEFactory
;
96 uno::Reference
< uno::XComponentContext
> xContext(
97 comphelper::getProcessComponentContext() );
100 uno::Reference
<lang::XMultiComponentFactory
> xSMgr
= xContext
->getServiceManager();
101 xOLEFactory
.set( xSMgr
->createInstanceWithContext( "com.sun.star.bridge.OleObjectFactory", xContext
),
105 if( xOLEFactory
.is() )
107 uno::Reference
< uno::XInterface
> xADODB
= xOLEFactory
->createInstance( "ADODB.Connection" );
111 return; // can't do anything, skip test
113 sal_Unicode sBuf
[1024*4];
114 SQLGetInstalledDriversW( sBuf
, sizeof( sBuf
), nullptr );
116 const sal_Unicode
*pODBCDriverName
= sBuf
;
118 for (; wcslen( pODBCDriverName
) != 0; pODBCDriverName
+= wcslen( pODBCDriverName
) + 1 ) {
119 if ( wcsstr( pODBCDriverName
, L
"Microsoft Excel Driver" ) != nullptr ) {
125 return; // can't find ODBC driver needed test, so skip test
127 const char* macroSource
[] = {
128 "ole_ObjAssignNoDflt.vb",
129 "ole_ObjAssignToNothing.vb",
130 "ole_dfltObjDflMethod.vb",
133 OUString sMacroPathURL
= m_directories
.getURLFromSrc("/basic/qa/vba_tests/");
135 uno::Sequence
< uno::Any
> aArgs(1);
136 // path to test document
137 OUString sPath
= m_directories
.getPathFromSrc("/basic/qa/vba_tests/data/")
139 sPath
= sPath
.replaceAll( "/", "\\" );
141 aArgs
[ 0 ] = uno::makeAny( sPath
);
143 for ( sal_uInt32 i
=0; i
<SAL_N_ELEMENTS( macroSource
); ++i
)
145 OUString sMacroURL
= sMacroPathURL
146 + OUString::createFromAscii( macroSource
[ i
] );
147 MacroSnippet myMacro
;
148 myMacro
.LoadSourceFromFile( sMacroURL
);
149 SbxVariableRef pReturn
= myMacro
.Run( aArgs
);
152 fprintf(stderr
, "macro result for %s\n", macroSource
[ i
] );
153 fprintf(stderr
, "macro returned:\n%s\n", OUStringToOString( pReturn
->GetOUString(), RTL_TEXTENCODING_UTF8
).getStr() );
155 CPPUNIT_ASSERT_MESSAGE("No return variable huh?", pReturn
.get() != nullptr );
156 CPPUNIT_ASSERT_MESSAGE("Result not as expected", pReturn
->GetOUString() == "OK" );
159 // Avoid "this method is empty and should be removed" warning
164 // Put the test suite in the registry
165 CPPUNIT_TEST_SUITE_REGISTRATION(VBATest
);
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */