1 'encoding UTF-8 Do not remove or change this line!
2 '*******************************************************************************
3 ' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 ' Copyright 2000, 2010 Oracle and/or its affiliates.
7 ' OpenOffice.org - a multi-platform office productivity suite
9 ' This file is part of OpenOffice.org.
11 ' OpenOffice.org is free software: you can redistribute it and/or modify
12 ' it under the terms of the GNU Lesser General Public License version 3
13 ' only, as published by the Free Software Foundation.
15 ' OpenOffice.org is distributed in the hope that it will be useful,
16 ' but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ' GNU Lesser General Public License version 3 for more details
19 ' (a copy is included in the LICENSE file that accompanied this code).
21 ' You should have received a copy of the GNU Lesser General Public License
22 ' version 3 along with OpenOffice.org. If not, see
23 ' <http://www.openoffice.org/license.html>
24 ' for a copy of the LGPLv3 License.
26 '/******************************************************************************
28 '* owner : gregor.hartmann@oracle.com
30 '* short description : Test VBA compatibility switches
32 '\******************************************************************************
34 testcase tBasicVBACompatXLSM_XLSB()
36 printlog( "Functionality of macros in XLSM/XLSB files" )
37 ' Based on issue #i111007
39 const IMPORT_EXCEL_MACROS = TRUE
40 const EXEC_EXCEL_MACROS = TRUE
43 const MODULE_COUNT = 7
45 const MODULE_NOT_FOUND = 0
49 const THE_MODULE_THAT_BEHAVES_DIFFERENTLY = 6
51 const RELATIVE_PATH = "framework/optional/input/vba-compat/"
53 ' We have two files to load, on e .xlsm and one .xlsb
54 dim cFileList( FILE_COUNT ) as string
55 cFileList( 1 ) = "vba-project.xlsm"
56 cFileList( 2 ) = "vba-project.xlsb"
58 ' both documents import the same modules
59 dim cTestModuleList( MODULE_COUNT )
60 cTestModuleList( 1 ) = "MyChartModule"
61 cTestModuleList( 2 ) = "MyCodeModule"
62 cTestModuleList( 3 ) = "MyPrivateClassModule"
63 cTestModuleList( 4 ) = "MyPublicClassModule"
64 cTestModuleList( 5 ) = "MySheetModule"
65 cTestModuleList( 6 ) = "MyUserForm"
66 cTestModuleList( 7 ) = "MyWorkbookModule"
68 dim cTestFile as string
69 dim iCurrentFile as integer
70 dim iCurrentModule as integer
72 printlog( "Set macro security to low" )
73 hSetMacroSecurityAPI( GC_MACRO_SECURITY_LEVEL_LOW )
75 printlog( "Open Tools/Options" )
76 hSetExcelBasicImportMode( IMPORT_EXCEL_MACROS, EXEC_EXCEL_MACROS )
78 for iCurrentFile = 1 to FILE_COUNT
80 cTestFile = gTesttoolPath & RELATIVE_PATH & cFileList( iCurrentFile )
82 printlog( "Loading document: " & cTestFile )
83 hFileOpen( cTestFile )
85 for iCurrentModule = 1 to MODULE_COUNT
88 printlog( "Tryng to execute macro: " & cTestModuleList( iCurrentModule ) )
92 if ( Makro.exists( MAX_DELAY ) ) then
94 if ( hSelectNodeByName( MakroAus, cTestModuleList( iCurrentModule ) ) <> MODULE_NOT_FOUND ) then
96 printlog( "Execute the default macro <Test> for the current module" )
98 if ( hClickButton( Ausfuehren ) <> RC_TIMEOUT ) then
99 if ( iCurrentModule = THE_MODULE_THAT_BEHAVES_DIFFERENTLY ) then
100 ' Fuzzy matching message string
101 hTestMacroType2( cTestModuleList( iCurrentModule ) )
103 ' Exact matching message string
104 hTestMacroType1( cTestModuleList( iCurrentModule ) )
107 warnlog( "No executable macro found for the current module / <Run> button is disabled" )
110 warnlog( "the expected macro module could not be found" )
113 warnlog( "BASIC Macro organizer did not open" )
118 printlog( "Close the document" )
123 hSetExcelImportModeDefault()
124 hSetMacroSecurityAPI( GC_MACRO_SECURITY_LEVEL_DEFAULT )
128 '*******************************************************************************
130 function hTestMacroType1( cMessage as string ) as boolean
135 if ( Active.exists( 2 ) ) then
136 if ( Active.getText() = cMessage ) then
137 printlog( "Correct macro has been executed" )
138 hTestMacroType1() = true
140 warnlog( "Incorrect macro executed: " )
141 printlog( "Expected: " & cMessage )
142 printlog( "Found...: " & Active.getText() )
143 hTestMacroType1() = false
150 warnlog( "Messagebox missing, macro was not executed" )
151 hTestMacroType1() = false
156 '*******************************************************************************
158 function hTestMacroType2( cMessage as string ) as boolean
162 dim iCurrentMessage as integer
164 for iCurrentMessage = 1 to 2
167 if ( Active.exists( 2 ) ) then
168 if ( instr( Active.getText() , cMessage ) > 0 ) then
169 printlog( "Correct macro has been executed" )
170 hTestMacroType2() = true
172 warnlog( "Incorrect macro executed: " )
173 printlog( "Expected: " & cMessage )
174 printlog( "Found...: " & Active.getText() )
175 hTestMacroType2() = false
182 warnlog( "Messagebox missing, macro not executed" )
183 hTestMacroType2() = false