2013-03-07 16:23:45 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
2013-04-24 17:14:03 +01:00
|
|
|
* This file is part of the LibreOffice project.
|
2013-03-07 16:23:45 +00:00
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
#include "basictest.hxx"
|
2013-03-11 15:50:54 +00:00
|
|
|
#include <comphelper/processfactory.hxx>
|
2016-01-30 22:12:35 +01:00
|
|
|
#include <unotools/syslocaleoptions.hxx>
|
|
|
|
|
2016-05-21 19:38:48 +09:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <odbcinst.h>
|
|
|
|
#endif
|
|
|
|
|
2013-03-07 16:23:45 +00:00
|
|
|
using namespace ::com::sun::star;
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
class VBATest : public test::BootstrapFixture
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
VBATest() : BootstrapFixture(true, false) {}
|
|
|
|
void testMiscVBAFunctions();
|
2013-03-15 17:19:53 +00:00
|
|
|
void testMiscOLEStuff();
|
2013-03-07 16:23:45 +00:00
|
|
|
// Adds code needed to register the test suite
|
|
|
|
CPPUNIT_TEST_SUITE(VBATest);
|
|
|
|
|
|
|
|
// Declares the method as a test to call
|
|
|
|
CPPUNIT_TEST(testMiscVBAFunctions);
|
2013-03-15 17:19:53 +00:00
|
|
|
CPPUNIT_TEST(testMiscOLEStuff);
|
2013-03-07 16:23:45 +00:00
|
|
|
|
|
|
|
// End of test suite definition
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
void VBATest::testMiscVBAFunctions()
|
|
|
|
{
|
|
|
|
const char* macroSource[] = {
|
|
|
|
"bytearraystring.vb",
|
2014-05-13 05:23:49 +02:00
|
|
|
"cdec.vb",
|
2013-03-11 15:50:54 +00:00
|
|
|
// datevalue test seems to depend on both locale and language
|
|
|
|
// settings, should try and rewrite the test to deal with that
|
|
|
|
// for some reason tinderboxes don't seem to complain leaving enabled
|
|
|
|
// for the moment
|
2013-03-07 16:23:45 +00:00
|
|
|
"datevalue.vb",
|
|
|
|
"partition.vb",
|
|
|
|
"strconv.vb",
|
|
|
|
"dateserial.vb",
|
|
|
|
"format.vb",
|
|
|
|
"replace.vb",
|
2014-09-19 12:23:46 +01:00
|
|
|
"stringplusdouble.vb",
|
2017-02-10 21:07:11 +01:00
|
|
|
"chr.vb",
|
2017-02-27 22:37:05 +01:00
|
|
|
"abs.vb",
|
|
|
|
"array.vb",
|
|
|
|
"asc.vb",
|
|
|
|
"atn.vb",
|
|
|
|
"cbool.vb",
|
2017-03-03 15:54:01 +01:00
|
|
|
"cdate.vb",
|
|
|
|
"cdbl.vb",
|
2017-03-05 23:57:15 +01:00
|
|
|
"choose.vb",
|
2017-03-09 22:08:57 +01:00
|
|
|
"cos.vb",
|
2017-03-10 21:27:07 +01:00
|
|
|
"cint.vb",
|
|
|
|
"clng.vb",
|
2017-03-17 15:56:32 +01:00
|
|
|
"csng.vb",
|
|
|
|
"cstr.vb",
|
2017-03-18 14:38:09 +01:00
|
|
|
"cvdate.vb",
|
|
|
|
"cverr.vb",
|
|
|
|
"dateadd.vb",
|
2017-03-29 22:13:54 +02:00
|
|
|
"datediff.vb",
|
|
|
|
"datepart.vb",
|
2017-04-01 17:45:15 +02:00
|
|
|
"day.vb",
|
|
|
|
"error.vb",
|
|
|
|
"exp.vb",
|
|
|
|
"fix.vb",
|
2017-04-09 13:44:25 +02:00
|
|
|
"hex.vb",
|
|
|
|
"hour.vb",
|
2017-04-06 20:39:39 +02:00
|
|
|
"formatnumber.vb",
|
2017-04-09 13:44:25 +02:00
|
|
|
"iif.vb",
|
|
|
|
"instr.vb",
|
2017-04-12 18:29:59 +02:00
|
|
|
"instrrev.vb",
|
|
|
|
"int.vb",
|
add VBA test cases
tests: ISARRAY, ISDATE, ISEMPTY, ISERROR, ISMISSING,
ISNULL, ISNUMERIC, ISOBJECT, JOIN, LBOUND, LCASE
Change-Id: I0b0dacd0d62bf00680f33866ce7ec0152eec27e0
Reviewed-on: https://gerrit.libreoffice.org/36509
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Zdenek Crhonek <zcrhonek@gmail.com>
2017-04-13 11:32:29 +02:00
|
|
|
"iserror.vb",
|
|
|
|
"ismissing.vb",
|
|
|
|
"isnull.vb",
|
|
|
|
"isobject.vb",
|
|
|
|
"join.vb",
|
|
|
|
"lbound.vb",
|
|
|
|
"isarray.vb",
|
|
|
|
"isdate.vb",
|
|
|
|
"isempty.vb",
|
|
|
|
"isnumeric.vb",
|
|
|
|
"lcase.vb",
|
2017-04-14 18:30:13 +02:00
|
|
|
"left.vb",
|
|
|
|
"len.vb",
|
|
|
|
"log.vb",
|
|
|
|
"ltrim.vb",
|
|
|
|
"mid.vb",
|
|
|
|
"minute.vb",
|
|
|
|
"mirr.vb",
|
|
|
|
"month.vb",
|
2014-09-19 14:45:06 +01:00
|
|
|
#ifndef WIN32 // missing 64bit Currency marshalling.
|
2014-09-19 13:54:11 +01:00
|
|
|
"win32compat.vb", // windows compatibility hooks.
|
2014-09-19 14:45:06 +01:00
|
|
|
#endif
|
2014-09-19 13:54:11 +01:00
|
|
|
"win32compatb.vb" // same methods, different signatures.
|
2013-03-07 16:23:45 +00:00
|
|
|
};
|
2016-03-09 14:14:18 +01:00
|
|
|
OUString sMacroPathURL = m_directories.getURLFromSrc("/basic/qa/vba_tests/");
|
2013-03-07 16:23:45 +00:00
|
|
|
// Some test data expects the uk locale
|
2016-01-30 22:12:35 +01:00
|
|
|
LanguageTag aLocale(LANGUAGE_ENGLISH_UK);
|
|
|
|
SvtSysLocaleOptions aLocalOptions;
|
|
|
|
aLocalOptions.SetLocaleConfigString( aLocale.getBcp47() );
|
|
|
|
|
2013-03-07 16:23:45 +00:00
|
|
|
for ( sal_uInt32 i=0; i<SAL_N_ELEMENTS( macroSource ); ++i )
|
|
|
|
{
|
2016-07-01 14:07:52 +03:00
|
|
|
OUString sMacroURL = sMacroPathURL
|
|
|
|
+ OUString::createFromAscii( macroSource[ i ] );
|
2013-03-07 16:23:45 +00:00
|
|
|
|
|
|
|
MacroSnippet myMacro;
|
|
|
|
myMacro.LoadSourceFromFile( sMacroURL );
|
|
|
|
SbxVariableRef pReturn = myMacro.Run();
|
2017-01-25 12:03:58 +02:00
|
|
|
if ( pReturn.is() )
|
2013-03-07 16:23:45 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "macro result for %s\n", macroSource[ i ] );
|
|
|
|
fprintf(stderr, "macro returned:\n%s\n", OUStringToOString( pReturn->GetOUString(), RTL_TEXTENCODING_UTF8 ).getStr() );
|
|
|
|
}
|
2016-10-05 22:00:51 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE("No return variable huh?", pReturn.get() != nullptr );
|
2016-07-22 09:14:24 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Result not as expected", OUString("OK"), pReturn->GetOUString() );
|
2013-03-07 16:23:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-15 17:19:53 +00:00
|
|
|
void VBATest::testMiscOLEStuff()
|
2013-03-11 15:50:54 +00:00
|
|
|
{
|
Partially fix VBATest::testMiscOLEStuff for Win64
On Windows x64 there are two ODBCs - one for each bitness.
A 64-bit build gets 64-bit ODBC, and there is no provider named
"Microsoft Excel Driver (*.xls)", no normally the test is simply
skipped. But if MS Excel is installed, then it installs provider
"Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)", that was
detected by previous code, but not used inside the VBAs. So, VBAs
tried to use "Microsoft Excel Driver (*.xls)" unavailable to them.
This patch allows using Excel's provider as well, thus allowing
developer to test against 64-bit-specific regressions.
However, the last test uses Microsoft.Jet.OLEDB.4.0 provider,
that is unavailable on Win64. There are substitutions -
Microsoft.ACE.OLEDB.12.0 and Microsoft.ACE.OLEDB.15.0,
but there is no easy way to test if they are installed. Thus,
that test is disabled on Win64 for now.
Also, possible buffer overflow fixed, when byte count was passed
to SQLGetInstalledDriversW instead of char count.
Change-Id: Ib5c55251f0e92b3078a46aee173b5061439445ae
Reviewed-on: https://gerrit.libreoffice.org/32019
Reviewed-by: Tor Lillqvist <tml@collabora.com>
Tested-by: Tor Lillqvist <tml@collabora.com>
2016-12-14 20:09:14 +03:00
|
|
|
// Not much point even trying to run except on Windows.
|
|
|
|
// (Without Excel doesn't really do anything anyway,
|
|
|
|
// see "so skip test" below.)
|
|
|
|
#if defined(_WIN32)
|
2013-11-13 23:50:48 +01:00
|
|
|
// test if we have the necessary runtime environment
|
|
|
|
// to run the OLE tests.
|
|
|
|
uno::Reference< lang::XMultiServiceFactory > xOLEFactory;
|
|
|
|
uno::Reference< uno::XComponentContext > xContext(
|
|
|
|
comphelper::getProcessComponentContext() );
|
|
|
|
if( xContext.is() )
|
|
|
|
{
|
|
|
|
uno::Reference<lang::XMultiComponentFactory> xSMgr = xContext->getServiceManager();
|
2015-10-29 15:48:45 +02:00
|
|
|
xOLEFactory.set( xSMgr->createInstanceWithContext( "com.sun.star.bridge.OleObjectFactory", xContext ),
|
|
|
|
uno::UNO_QUERY );
|
2013-11-13 23:50:48 +01:00
|
|
|
}
|
|
|
|
bool bOk = false;
|
|
|
|
if( xOLEFactory.is() )
|
|
|
|
{
|
|
|
|
uno::Reference< uno::XInterface > xADODB = xOLEFactory->createInstance( "ADODB.Connection" );
|
2016-05-21 19:38:48 +09:00
|
|
|
bOk = xADODB.is();
|
2013-11-13 23:50:48 +01:00
|
|
|
}
|
|
|
|
if ( !bOk )
|
2013-03-11 15:50:54 +00:00
|
|
|
return; // can't do anything, skip test
|
|
|
|
|
Partially fix VBATest::testMiscOLEStuff for Win64
On Windows x64 there are two ODBCs - one for each bitness.
A 64-bit build gets 64-bit ODBC, and there is no provider named
"Microsoft Excel Driver (*.xls)", no normally the test is simply
skipped. But if MS Excel is installed, then it installs provider
"Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)", that was
detected by previous code, but not used inside the VBAs. So, VBAs
tried to use "Microsoft Excel Driver (*.xls)" unavailable to them.
This patch allows using Excel's provider as well, thus allowing
developer to test against 64-bit-specific regressions.
However, the last test uses Microsoft.Jet.OLEDB.4.0 provider,
that is unavailable on Win64. There are substitutions -
Microsoft.ACE.OLEDB.12.0 and Microsoft.ACE.OLEDB.15.0,
but there is no easy way to test if they are installed. Thus,
that test is disabled on Win64 for now.
Also, possible buffer overflow fixed, when byte count was passed
to SQLGetInstalledDriversW instead of char count.
Change-Id: Ib5c55251f0e92b3078a46aee173b5061439445ae
Reviewed-on: https://gerrit.libreoffice.org/32019
Reviewed-by: Tor Lillqvist <tml@collabora.com>
Tested-by: Tor Lillqvist <tml@collabora.com>
2016-12-14 20:09:14 +03:00
|
|
|
const int nBufSize = 1024 * 4;
|
2017-04-10 10:13:41 +02:00
|
|
|
wchar_t sBuf[nBufSize];
|
|
|
|
SQLGetInstalledDriversW( sBuf, nBufSize, nullptr );
|
2016-05-21 19:38:48 +09:00
|
|
|
|
2017-04-10 10:13:41 +02:00
|
|
|
const wchar_t *pODBCDriverName = sBuf;
|
2016-05-21 19:38:48 +09:00
|
|
|
bool bFound = false;
|
2017-04-10 10:13:41 +02:00
|
|
|
for (; wcslen( pODBCDriverName ) != 0; pODBCDriverName += wcslen( pODBCDriverName ) + 1 ) {
|
|
|
|
if( wcscmp( pODBCDriverName, L"Microsoft Excel Driver (*.xls)" ) == 0 ||
|
|
|
|
wcscmp( pODBCDriverName, L"Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)" ) == 0 ) {
|
2016-05-21 19:38:48 +09:00
|
|
|
bFound = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !bFound )
|
|
|
|
return; // can't find ODBC driver needed test, so skip test
|
|
|
|
|
2013-03-11 15:50:54 +00:00
|
|
|
const char* macroSource[] = {
|
|
|
|
"ole_ObjAssignNoDflt.vb",
|
|
|
|
"ole_ObjAssignToNothing.vb",
|
Partially fix VBATest::testMiscOLEStuff for Win64
On Windows x64 there are two ODBCs - one for each bitness.
A 64-bit build gets 64-bit ODBC, and there is no provider named
"Microsoft Excel Driver (*.xls)", no normally the test is simply
skipped. But if MS Excel is installed, then it installs provider
"Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)", that was
detected by previous code, but not used inside the VBAs. So, VBAs
tried to use "Microsoft Excel Driver (*.xls)" unavailable to them.
This patch allows using Excel's provider as well, thus allowing
developer to test against 64-bit-specific regressions.
However, the last test uses Microsoft.Jet.OLEDB.4.0 provider,
that is unavailable on Win64. There are substitutions -
Microsoft.ACE.OLEDB.12.0 and Microsoft.ACE.OLEDB.15.0,
but there is no easy way to test if they are installed. Thus,
that test is disabled on Win64 for now.
Also, possible buffer overflow fixed, when byte count was passed
to SQLGetInstalledDriversW instead of char count.
Change-Id: Ib5c55251f0e92b3078a46aee173b5061439445ae
Reviewed-on: https://gerrit.libreoffice.org/32019
Reviewed-by: Tor Lillqvist <tml@collabora.com>
Tested-by: Tor Lillqvist <tml@collabora.com>
2016-12-14 20:09:14 +03:00
|
|
|
#if !defined(_WIN64)
|
|
|
|
// This test uses Microsoft.Jet.OLEDB.4.0 Provider, that is unavailable on Win64
|
2013-03-15 17:19:53 +00:00
|
|
|
"ole_dfltObjDflMethod.vb",
|
Partially fix VBATest::testMiscOLEStuff for Win64
On Windows x64 there are two ODBCs - one for each bitness.
A 64-bit build gets 64-bit ODBC, and there is no provider named
"Microsoft Excel Driver (*.xls)", no normally the test is simply
skipped. But if MS Excel is installed, then it installs provider
"Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)", that was
detected by previous code, but not used inside the VBAs. So, VBAs
tried to use "Microsoft Excel Driver (*.xls)" unavailable to them.
This patch allows using Excel's provider as well, thus allowing
developer to test against 64-bit-specific regressions.
However, the last test uses Microsoft.Jet.OLEDB.4.0 provider,
that is unavailable on Win64. There are substitutions -
Microsoft.ACE.OLEDB.12.0 and Microsoft.ACE.OLEDB.15.0,
but there is no easy way to test if they are installed. Thus,
that test is disabled on Win64 for now.
Also, possible buffer overflow fixed, when byte count was passed
to SQLGetInstalledDriversW instead of char count.
Change-Id: Ib5c55251f0e92b3078a46aee173b5061439445ae
Reviewed-on: https://gerrit.libreoffice.org/32019
Reviewed-by: Tor Lillqvist <tml@collabora.com>
Tested-by: Tor Lillqvist <tml@collabora.com>
2016-12-14 20:09:14 +03:00
|
|
|
#endif
|
2013-03-11 15:50:54 +00:00
|
|
|
};
|
|
|
|
|
2016-03-09 14:14:18 +01:00
|
|
|
OUString sMacroPathURL = m_directories.getURLFromSrc("/basic/qa/vba_tests/");
|
2013-03-11 15:50:54 +00:00
|
|
|
|
Partially fix VBATest::testMiscOLEStuff for Win64
On Windows x64 there are two ODBCs - one for each bitness.
A 64-bit build gets 64-bit ODBC, and there is no provider named
"Microsoft Excel Driver (*.xls)", no normally the test is simply
skipped. But if MS Excel is installed, then it installs provider
"Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)", that was
detected by previous code, but not used inside the VBAs. So, VBAs
tried to use "Microsoft Excel Driver (*.xls)" unavailable to them.
This patch allows using Excel's provider as well, thus allowing
developer to test against 64-bit-specific regressions.
However, the last test uses Microsoft.Jet.OLEDB.4.0 provider,
that is unavailable on Win64. There are substitutions -
Microsoft.ACE.OLEDB.12.0 and Microsoft.ACE.OLEDB.15.0,
but there is no easy way to test if they are installed. Thus,
that test is disabled on Win64 for now.
Also, possible buffer overflow fixed, when byte count was passed
to SQLGetInstalledDriversW instead of char count.
Change-Id: Ib5c55251f0e92b3078a46aee173b5061439445ae
Reviewed-on: https://gerrit.libreoffice.org/32019
Reviewed-by: Tor Lillqvist <tml@collabora.com>
Tested-by: Tor Lillqvist <tml@collabora.com>
2016-12-14 20:09:14 +03:00
|
|
|
uno::Sequence< uno::Any > aArgs(2);
|
2013-03-11 15:50:54 +00:00
|
|
|
// path to test document
|
Partially fix VBATest::testMiscOLEStuff for Win64
On Windows x64 there are two ODBCs - one for each bitness.
A 64-bit build gets 64-bit ODBC, and there is no provider named
"Microsoft Excel Driver (*.xls)", no normally the test is simply
skipped. But if MS Excel is installed, then it installs provider
"Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)", that was
detected by previous code, but not used inside the VBAs. So, VBAs
tried to use "Microsoft Excel Driver (*.xls)" unavailable to them.
This patch allows using Excel's provider as well, thus allowing
developer to test against 64-bit-specific regressions.
However, the last test uses Microsoft.Jet.OLEDB.4.0 provider,
that is unavailable on Win64. There are substitutions -
Microsoft.ACE.OLEDB.12.0 and Microsoft.ACE.OLEDB.15.0,
but there is no easy way to test if they are installed. Thus,
that test is disabled on Win64 for now.
Also, possible buffer overflow fixed, when byte count was passed
to SQLGetInstalledDriversW instead of char count.
Change-Id: Ib5c55251f0e92b3078a46aee173b5061439445ae
Reviewed-on: https://gerrit.libreoffice.org/32019
Reviewed-by: Tor Lillqvist <tml@collabora.com>
Tested-by: Tor Lillqvist <tml@collabora.com>
2016-12-14 20:09:14 +03:00
|
|
|
OUString sPath = m_directories.getPathFromSrc("/basic/qa/vba_tests/data/ADODBdata.xls");
|
2013-03-11 17:31:43 +00:00
|
|
|
sPath = sPath.replaceAll( "/", "\\" );
|
2013-03-11 15:50:54 +00:00
|
|
|
|
2017-02-03 08:54:47 +02:00
|
|
|
aArgs[ 0 ] <<= sPath;
|
2017-04-10 10:13:41 +02:00
|
|
|
aArgs[ 1 ] <<= OUString(
|
|
|
|
reinterpret_cast<sal_Unicode const *>(pODBCDriverName));
|
2013-03-11 15:50:54 +00:00
|
|
|
|
|
|
|
for ( sal_uInt32 i=0; i<SAL_N_ELEMENTS( macroSource ); ++i )
|
|
|
|
{
|
2016-07-01 14:07:52 +03:00
|
|
|
OUString sMacroURL = sMacroPathURL
|
|
|
|
+ OUString::createFromAscii( macroSource[ i ] );
|
2013-03-11 15:50:54 +00:00
|
|
|
MacroSnippet myMacro;
|
|
|
|
myMacro.LoadSourceFromFile( sMacroURL );
|
|
|
|
SbxVariableRef pReturn = myMacro.Run( aArgs );
|
2017-01-25 12:03:58 +02:00
|
|
|
if ( pReturn.is() )
|
2013-03-11 15:50:54 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "macro result for %s\n", macroSource[ i ] );
|
2013-03-11 17:31:43 +00:00
|
|
|
fprintf(stderr, "macro returned:\n%s\n", OUStringToOString( pReturn->GetOUString(), RTL_TEXTENCODING_UTF8 ).getStr() );
|
2013-03-11 15:50:54 +00:00
|
|
|
}
|
2016-10-14 16:59:40 +02:00
|
|
|
CPPUNIT_ASSERT_MESSAGE("No return variable huh?", pReturn.get() != nullptr );
|
2017-04-28 14:21:30 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Result not as expected", OUString("OK"), pReturn->GetOUString() );
|
2013-03-11 15:50:54 +00:00
|
|
|
}
|
2015-03-26 09:22:42 +02:00
|
|
|
#else
|
|
|
|
// Avoid "this method is empty and should be removed" warning
|
|
|
|
(void) 42;
|
2013-11-13 23:50:48 +01:00
|
|
|
#endif
|
2013-03-11 15:50:54 +00:00
|
|
|
}
|
|
|
|
|
2013-03-07 16:23:45 +00:00
|
|
|
// Put the test suite in the registry
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(VBATest);
|
2016-01-30 22:12:35 +01:00
|
|
|
}
|
2013-03-07 16:23:45 +00:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|