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 tBasicVBACompatThisWorkBook()
36 printlog( "Functionality of .thisWorkbook" )
37 ' Based on issue #i110672
39 const IMPORT_EXCEL_MACROS = TRUE
40 const EXEC_EXCEL_MACROS = TRUE
41 const DOCUMENT_NAME = "vba-thisworkbook.xls"
42 const LIBRARY_NAME = "Standard"
43 const MODULE_NAME = "Module1"
44 const EXPECTED_MACRO_COUNT = 2
45 const MAX_REPEAT_COUNT = 2
48 dim macro_identifier( EXPECTED_MACRO_COUNT )
49 macro_identifier( 1 ) = "Test 1 passed."
50 macro_identifier( 2 ) = "Test 2 passed."
52 dim cTestFile as string
53 cTestFile = gTesttoolPath & "framework/optional/input/vba-compat/" & DOCUMENT_NAME
55 dim iMacroPosition as integer
56 dim iCurrentMacro as integer
57 dim iRepeat as integer
59 printlog( "Set macro security to low" )
60 hSetMacroSecurityAPI( GC_MACRO_SECURITY_LEVEL_LOW )
62 printlog( "Open Tools/Options" )
63 hSetExcelBasicImportMode( IMPORT_EXCEL_MACROS, EXEC_EXCEL_MACROS )
65 printlog( "Load the test file" )
66 hFileOpen( cTestFile )
68 printlog( "Execute the procedure twice to trigger issue 111553" )
69 for iRepeat = 1 to MAX_REPEAT_COUNT
74 if ( Makro.exists( MAX_WAIT ) ) then
76 iMacroPosition = hSelectNodeByName( MakroAus, DOCUMENT_NAME )
77 hExpandNode( MakroAus, iMacroPosition )
79 printlog( "Move to node <" & LIBRARY_NAME & ">" )
80 iMacroPosition = hSelectNextNode( MakroAus )
81 if ( not hVerifyNodeName( MakroAus, LIBRARY_NAME ) ) then
82 warnlog( "This is not the expected library" )
85 printlog( "Move to node <" & MODULE_NAME & ">" )
86 hSelectNextNode( MakroAus )
87 if ( not hVerifyNodeName( MakroAus, MODULE_NAME ) ) then
88 warnlog( "This is not the expected module" )
91 printlog( "Click <Ausfuehren> to execute the macro" )
92 iMacroPosition = hClickButton( Ausfuehren )
94 printlog( "Check for two expected messageboxes" )
95 for iCurrentMacro = 1 to EXPECTED_MACRO_COUNT
98 printlog( "Check for messagebox: " & macro_identifier( iCurrentMacro ) )
99 if ( Active.exists( MAX_WAIT ) ) then
101 if ( Active.getText() = macro_identifier( iCurrentMacro ) ) then
102 printlog( "Correct macro executed" )
104 printlog( "Macro execution error, trying to identify..." )
105 if ( instr( Active.getText(), "BASIC runtime error." ) > 0 ) then
106 if ( iRepeat = MAX_REPEAT_COUNT ) then
107 warnlog( "#i111533 - Cannot execute ThisWorkbook macro twice" )
112 warnlog( "Executing macro failed" )
116 warnlog( "Unknown messagebox. Aborting test" )
124 warnlog( "Expected messagebox not displayed within reasonable timeframe" )
130 warnlog( "A macro with the name <" & MODULE_NAME & "> could not be found" )
136 printlog( "Cleanup" )
138 hSetExcelImportModeDefault()
139 hSetMacroSecurityAPI( GC_MACRO_SECURITY_LEVEL_DEFAULT )