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 2008 by Sun Microsystems, Inc.
7 '* OpenOffice.org - a multi-platform office productivity suite
9 '* $RCSfile: basic_usertemplate.inc,v $
13 '* last change: $Author: jsi $ $Date: 2008-06-16 12:18:13 $
15 '* This file is part of OpenOffice.org.
17 '* OpenOffice.org is free software: you can redistribute it and/or modify
18 '* it under the terms of the GNU Lesser General Public License version 3
19 '* only, as published by the Free Software Foundation.
21 '* OpenOffice.org is distributed in the hope that it will be useful,
22 '* but WITHOUT ANY WARRANTY; without even the implied warranty of
23 '* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 '* GNU Lesser General Public License version 3 for more details
25 '* (a copy is included in the LICENSE file that accompanied this code).
27 '* You should have received a copy of the GNU Lesser General Public License
28 '* version 3 along with OpenOffice.org. If not, see
29 '* <http://www.openoffice.org/license.html>
30 '* for a copy of the LGPLv3 License.
32 '/******************************************************************************
34 '* owner : joerg.skottke@sun.com
36 '* short description : My Macros/standard execution with user defined template
38 '\******************************************************************************
40 testcase tMacroUsertemplate
42 '///<H1>My Macros/standard execution with user defined template</H1>
45 ' requires: Default template path, default security level (medium)
48 ' This test checks for some really weird behavior. A macro is created
49 ' for the standard lib in My Macros - this means the macro is stored with
50 ' the application, not the document.
51 ' When creating a document based on a user-created template the macro
52 ' will not execute, instead a com.sun.star... errormessage is displayed
54 dim brc as boolean ' returncode
55 dim irc as integer ' returncode
57 dim cMacroName as string ' Temp variable to store the name of current macro
59 const DOC_IDENTIFIER = "A test document for tMacroUserTemplate"
61 dim sPathOut as string ' output path for workfile
62 const FILEOUT = "tMacroUserTemplate"
63 const FILTER = "writer8_template"
65 dim iCurrentNode as integer
67 sPathOut = convertpath( gOfficePath & "user\template\" )
68 hDeleteFile( sPathOut & FILEOUT & ".ott" )
70 '///+<li>Create one single document with identification string</li>
72 kontext "DocumentWriter"
73 DocumentWriter.typeKeys( DOC_IDENTIFIER )
75 '///+<li>Open a plain new document</li>
76 brc = hCreateDocument()
78 '///+<li>Open Basic Organizer</li>
79 brc = hOpenBasicOrganizerFromDoc()
81 '///+<li>Select My Macros/Standard/Module1/main</li>
82 iCurrentNode = hSelectNodeByName( MakroAus, "Module1" )
83 if ( iCurrentNode = 0 ) then
84 warnlog( "#i73521# - The expected node could not be found. Aborting test" )
91 ' verify that we replace the correct macro. if not: Abort
92 if ( MakroListe.getItemCount() > 0 ) then
93 cMacroName = MakroListe.getSelText()
94 if ( lcase( cMacroName ) <> "main" ) then
95 warnlog( "Test abort: Incorrect macro is selected: " & cMacroName )
96 printlog( "This should have been the <Main> Macro" )
103 warnlog( "There is no macro listed for the current module, the test cannot continue" )
110 '///+<li>Open Basic Ide by clicking Edit...</li>
113 '///+<li>Overwrite existing macro: Insert macro that prints messagebox</li>
116 '///+<li>Close IDE</li>
119 '///+<li>Close document</li>
122 '///+<li>Open a plain new document</li>
125 '///+<li>Open Run Macro-Dialog</li>
128 '///+<li>Execute the macro - this should work</li>
129 cMacroName = hExecScript_tMacroUserTemplate() ' local function, see below
130 if ( lcase( cMacroName ) <> "main" ) then
131 warnlog( "Test abort: Incorrect macro is selected: " & cMacroName )
132 printlog( "This should have been the <Main> Macro" )
133 ScriptSelector.cancel()
134 brc = hDestroyDocument()
141 '///+<li>Close the Macro-dialog</li>
143 if ( active.exists( 3 ) ) then
144 printlog( "Messagebox: " & active.getText() )
147 warnlog( "The Macro has not been executed" )
150 '///+<li>Close document</li>
151 brc = hDestroyDocument()
153 '///+<li>Open a plain new document</li>
154 brc = hCreateDocument()
156 '///+<li>Save it as {...work/user/template/MyTemplate} (template, autosuffix)</li>
158 printlog( "Save as template" )
159 hFileSaveAsWithFilterKill( sPathOut & FILEOUT, FILTER )
161 '///+<li>Close document</li>
164 '///+<li>Open "Templates and Documents"</li>
166 printlog( "File New from Template" )
169 '///+<li>Find MyTemplate (note: No suffix displayed)</li>
170 irc = hFindTemplate( FILEOUT )
172 '///+<li>Create a new document based ton this template</li>
173 hSelectDocumentObject( irc, 1 )
175 '///+<li>Open Run Macro-Dialog</li>
177 printlog( "Run Macro..." )
180 '///+<li>Execute the macro - this should work</li>
181 cMacroName = hExecScript_tMacroUserTemplate() ' local function, see below
182 if ( lcase( cMacroName ) <> "main" ) then
183 warnlog( "Test abort: Incorrect macro is selected: " & cMacroName )
184 printlog( "This should have been the <Main> Macro" )
185 ScriptSelector.cancel()
194 '///#i58527 - com.sun.star...
196 if ( active.exists( 3 ) ) then
198 if ( instr( active.getText() , "com.sun" ) <> 0 ) then
199 warnlog( "#i58527# - unable to run macro with user-template loaded" )
202 if ( active.getText() = "TTMacro3" ) then
203 printlog( "The macro was executed" )
205 printlog( "Unknown dialog: " & hRemoveLineBreaks( active.getText() ) )
210 warnlog( "Macro not executed / no warning" )
213 '///+<li>Close document</li>
217 '///+<li>Cleanup: Delete the template</li>
218 hDeleteFile( sPathOut & FILEOUT & ".ott" )
224 '*******************************************************************************
226 function hExecScript_tMacroUserTemplate() as string
228 Kontext "ScriptSelector"
229 hSelectTopNode( LibraryTreeList )
230 hExpandNode( LibraryTreeList , 1 )
231 hSelectNode( LibraryTreeList , 2 )
232 hExpandNode( LibraryTreeList , 2 )
233 hSelectNode( LibraryTreeList , 3 )
235 hExecScript_tMacroUserTemplate() = ScriptList.getSelText()