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: scriptorganizer_tools.inc,v $
13 '* last change: $Author: jsk $ $Date: 2008-06-20 08:03:54 $
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 : Test scripting-organizers / document-attached scripts
38 '\******************************************************************************
40 function hCreateScriptingObject( cName as string ) as boolean
42 '///<h3>Create a new scripting object for the current module</h3>
43 '///<i>Starting point: Script organizer is open, module selected</i><br>
46 '///+<li>Name of the module (string)</li>
48 '///+<li>Any name the organizer can accept</li>
53 '///+<li>Errorcondition</li>
55 '///+<li>TRUE on success</li>
56 '///+<li>FALSE on failure or invalid user input</li>
59 '///<u>Description</u>:
63 const CFN = "hNewScriptingObject::"
66 '///+<li>Verify the function parameter</li>
67 if ( cName = "" ) then
68 warnlog( CFN & "Empty Name for scripting object passed to function" )
69 hCreateScriptingObject() = false
73 '///+<li>Verify that the "Create..." button exists</li>
74 Kontext "ScriptOrganizer"
75 if ( not PBCreate.exists( 2 ) ) then
76 warnlog( CFN & "Create-button does not exist" )
77 hCreateScriptingObject() = false
81 '///+<li>Verify that the "Create..." button is enabled</li>
82 if ( PBCreate.isEnabled() ) then
84 '///+<li>Click "Create..." to open the naming dialog</li>
87 '///+<li>Name the new script</li>
88 Kontext "ScriptNameDlg"
89 if ( ScriptNameDlg.exists( 2 ) ) then
91 EFObjectName.setText( cName )
98 printlog( CFN & "Button is disabled" )
102 '///+<li>Verify that we are back on the script organizer</li>
103 kontext "ScriptOrganizer"
104 if ( not ScriptOrganizer.exists( 2 ) ) then
105 warnlog( CFN & "Could not return to ScriptOrganizer" )
109 hCreateScriptingObject() = brc
114 '*******************************************************************************
116 function hRenameScriptingObject( cName as string ) as boolean
118 '///<h3>Rename the selected script</h3>
119 '///<i>Starting point: Script organizer is open, a script is selected</i><br>
122 '///+<li>New name of the script</li>
124 '///+<li>Any name the script organizer does accept</li>
129 '///+<li>Errorcondition</li>
131 '///+<li>TRUE on success</li>
132 '///+<li>FALSE on failure or invalid user input</li>
135 '///<u>Description</u>:
138 use "global\tools\includes\optional\t_stringtools.inc"
140 const CFN = "hRenameScriptingObject::"
141 dim cMessage as string
146 '///+<li>Verify the function parameter</li>
147 if ( cName = "" ) then
148 warnlog( CFN & "Empty Name for scripting object passed to function" )
149 hRenameScriptingObject() = false
153 '///+<li>Verify that the "Rename..." button exists</li>
154 Kontext "ScriptOrganizer"
155 if ( not PBRename.exists( 2 ) ) then
156 warnlog( CFN & "Rename button does not exist, aborting" )
157 hRenameScriptingObject() = false
161 '///+<li>Verify that the "Rename..." button is enabled</li>
162 if ( PBRename.isEnabled() ) then
164 '///+<li>Click "Rename..." to open the renaming dialog</li>
167 '///+<li>Name the new script</li>
168 Kontext "ScriptNameDlg"
169 if ( ScriptNameDlg.exists( 2 ) ) then
171 EFObjectName.setText( cName )
174 '///+<li>Test for any messagebox, try to close it with OK</li>
176 if ( active.exists( 1 ) ) then
177 cMessage = hRemoveLineBreaks( active.getText )
178 printlog( CFN & cMessage )
187 '///+<li>Verify that we are back on the script organizer</li>
188 kontext "ScriptOrganizer"
189 if ( not ScriptOrganizer.exists( 2 ) ) then
190 warnlog( CFN & "Could not return to ScriptOrganizer" )
194 hRenameScriptingObject() = brc
199 '*******************************************************************************
201 function hDeleteScript( cName as string , bSuccess as boolean ) as boolean
203 '///<h3>Delete the selected script</h3>
204 '///<i>Starting point: Script organizer is open, a script is selected</i><br>
207 '///+<li>Name of the script (string)</li>
209 '///+<li>For debugging purpose only, the name will be used for warnlogs</li>
210 '///+<li>May be an empty string (not recommended)</li>
212 '///+<li>Expected result (boolean)</li>
214 '///+<li>TRUE: The script is expected to be deleted without warnings/errors</li>
215 '///+<li>FALSE: The script should not be deletable</li>
220 '///+<li>Errorcondition (boolean) - see description</li>
222 '///+<li>TRUE on success (expected outcome)</li>
223 '///+<li>FALSE on failure</li>
226 '///<u>Description</u>:
229 use "global\tools\includes\optional\t_stringtools.inc"
231 const CFN = "hDeleteScript::"
233 dim cMessage as string
235 '///+<li>Test for the possible conditions:</li>
237 '///+<li>Delete is correctly enabled (success)</li>
238 kontext "ScriptOrganizer"
239 if ( PBDelete.isEnabled() and bSuccess ) then
243 cMessage = active.getText()
244 cMessage = hRemoveLineBreaks( cMessage )
245 printlog( CFN & cMessage )
249 if ( active.exists( 1 ) ) then
250 cMessage = active.getText()
251 cMessage = hRemoveLineBreaks( cMessage )
252 qaerrorlog( CFN & "Message: Failed to delete object: " & cName )
253 printlog( CFN & cMessage )
256 hDeleteScript() = true
258 '///+<li>Delete is disabled correctly (success)</li>
259 elseif ( ( not PBDelete.isEnabled() ) and ( not bSuccess ) ) then
261 printlog( CFN & "Delete-Button disabled for non-deletable object: " & cName )
262 hDeleteScript() = true
264 '///+<li>Delete is enabled but should not be (failure)</li>
265 elseif ( PBDelete.isEnabled() and ( not bSuccess ) ) then
270 if ( active.exists( 1 ) ) then
271 cMessage = active.getText()
272 cMessage = hRemoveLineBreaks( cMessage )
273 printlog( CFN & "Delete-Button enabled for non deletable object" )
274 printlog( CFN & cMessage )
279 if ( active.exists( 2 ) ) then
280 cMessage = active.getText()
281 cMessage = hRemoveLineBreaks( cMessage )
282 printlog( CFN & "Message: Failed to delete object" )
283 printlog( CFN & cMessage )
286 hDeleteScript() = false
288 '///+<li>Delete is incorrectly disabled (failure)</li>
289 elseif ( ( not PBDelete.isEnabled() ) and bSuccess ) then
291 printlog( CFN & "Delete-Button disabled for deletable object" )
292 hDeleteScript() = false
296 warnlog( CFN & "Unknown condition in if-statement" )
297 hDeleteScript() = false
305 '*******************************************************************************
307 function hOpenScriptOrganizer( iDialog as integer ) as boolean
309 '///<h3>Open the ScriptOrganizers and verify that they are open</h3>
310 '///<i>Starting point: Any document</i><br>
313 '///+<li>Dialog-ID (integer)</li>
315 '///+<li>1 = BeanShell organizer</li>
316 '///+<li>2 = JavaScript organizer</li>
317 '///+<li>3 = Python script organizer</li>
322 '///+<li>Errorcondition</li>
324 '///+<li>TRUE if the expected organizer is open</li>
325 '///+<li>FALSE if the expected organizer is not open</li>
328 '///<u>Description</u>:
331 const CFN = "hOpenScriptOrganizer::"
333 '///<li>Call the associated slot</li>
335 case 1 : ToolsMacrosOrganizeMacrosBeanShell
336 case 2 : ToolsMacrosOrganizeMacrosJavaScript
337 case 3 : ToolsMacrosOrganizeMacrosPython
340 '///<li>Verify that the dialog is open, return TRUE if yes</li>
341 kontext "ScriptOrganizer"
342 if ( ScriptOrganizer.exists( 5 ) ) then
343 hOpenScriptOrganizer() = true
344 printlog( CFN & "Dialog is open" )
346 hopenScriptOrganizer() = false
347 warnlog( CFN & "Slot failed, dialog not open" )
354 '*******************************************************************************
356 function hCloseScriptOrganizer() as boolean
358 '///<h3>Close a Script Organizer (Cancel)</h3>
359 '///<i>Starting point: Any open Script Organizer</i><br>
362 '///+<li>Nothing</li>
366 '///+<li>Errorcondition (boolean)</li>
368 '///+<li>TRUE if the Script Organizer was closed</li>
369 '///+<li>FALSE if the Script Organizer is still open</li>
372 '///<u>Description</u>:
376 const CFN = "hCloseScriptOrganizer::"
378 hCloseScriptOrganizer() = false
380 '///+<li>Try to close the script </li>
381 kontext "ScriptOrganizer"
382 if ( ScriptOrganizer.exists( 5 ) ) then
383 ScriptOrganizer.cancel()
384 hCloseScriptOrganizer() = true
391 '*******************************************************************************
393 function hOpenRunMacroDialog() as boolean
395 '///<h3>Open the "Run Macro" dialog</h3>
396 '///<i>Starting point: Any document</i><br>
399 '///+<li>Nothing</li>
403 '///+<li>Errorcondition</li>
405 '///+<li>TRUE if dialog is open</li>
406 '///+<li>FALSE if the Script Selector does not exist</li>
409 '///<u>Description</u>:
413 '///+<li>Execute the ToolsMacrosRunMacro slot</li>
416 '///+<li>Verify that the dialog is present</li>
417 kontext "ScriptSelector"
418 if ( ScriptSelector.exists( 2 ) ) then
419 hOpenRunMacroDialog() = true
421 hOpenRunMacroDialog() = false