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