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: pbrowser_tools.inc,v $
13 '* last change: $Author: jsi $ $Date: 2008-06-16 12:19:06 $
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 : Tools for working with the property browser for formcontrols
38 '\******************************************************************************
40 private const DEBUG_ENABLE = false
42 function hOpenPropertyBrowser() as boolean
44 '///<h3>Function to open the properties of a selected control</h3>
45 '///<i>The function verifies that the property browser is really open and
46 '///+ ensures that we are on the General tabpage</i><br><br>
58 '///+<li>Errorcondition (boolean)</li>
60 '///+<li>TRUE on successful open of the property browser</li>
61 '///+<li>FALSE on any error</li>
66 '///<u>Description</u>:
69 const CFN = "hOpenPropertyBrowser::"
71 '///+<li>Open the property browser (call slot)</li>
75 '///+<li>Verify that the property browser is open</li>
76 kontext "ControlPropertiesTabControl"
77 if ( ControlPropertiesTabControl.exists( 2 ) ) then
79 '///+<li>Activate General-tabpage</li>
80 ControlPropertiesTabControl.setPage( TabGeneralControl )
82 '///+<li>Verify that the General-tabpage is visible</li>
83 kontext "TabGeneralControl"
84 if ( TabGeneralControl.isVisible() ) then
85 printlog( CFN & "ok" )
86 hOpenPropertyBrowser() = true
88 printlog( CFN & "General-tab is not visible." )
89 hOpenPropertyBrowser() = false
92 printlog( CFN & "Could not open property browser" )
93 hOpenPropertyBrowser() = false
96 hOpenPropertyBrowser() = false
97 printlog( CFN & "Slot <ContextProperties> not available" )
104 '*******************************************************************************
106 function hClosePropertyBrowser() as boolean
108 '///<h3>A function that closes the Property-Browser</h3>
109 '///<i>The property browser is closed by executing the slot (the slot
110 '///+ toggles the dialog).</i><br><br>
114 '///+<li>Nothing</li>
120 '///+<li>Errorcondition (boolean)</li>
122 '///+<li>TRUE if the Property Browser has been closed</li>
123 '///+<li>FALSE if the property browser is not open</li>
124 '///+<li>FALSE if the property browser could not be closed</li>
129 '///<u>Description</u>:
132 const CFN = "hClosePropertyBrowser::"
134 '///+<li>Verify that the property browser is open</li>
135 kontext "ControlPropertiesTabControl"
136 if ( ControlPropertiesTabControl.exists( 1 ) ) then
138 '///+<li>Execute the ContextProperties slot</li>
141 '///+<li>Verify that the property browser is closed</li>
142 if ( ControlPropertiesTabControl.exists() ) then
143 printlog( CFN & "Property browser could not be closed" )
144 hClosePropertyBrowser() = false
146 printlog( CFN & "ok" )
147 hClosePropertyBrowser() = true
150 printlog( CFN & "Property browser is not open" )
151 hClosePropertyBrowser() = false
157 '*******************************************************************************
159 function hPBSetControlName( cControl as string ) as boolean
161 '///<h3>Name a control, with limited errorhandling</h3>
163 '///<i>This function was introduced due to a problem with the property-
164 '///browser not being open fast enough or just refusing to accept input</i><br><br>
168 '///+<li>Text to be inserted in the control "NameText" (string)</li>
174 '///+<li>Errorcondition</li>
176 '///+<li>TRUE: The control name was successfully updated</li>
177 '///+<li>FALSE: Control is not visible within current context</li>
182 const CFN = "hPBSetControlName::"
184 '///<u>Description</u>:
186 '///+<li>Test that the control "NameText" exists</li>
187 kontext "TabGeneralControl"
188 if ( NameText.exists() ) then
189 '///+<li>Set the new name</li>
192 ' Name the control and append some Spaces which should be truncated.
193 printlog( CFN & "Naming control: " & cControl )
194 NameText.setText( cControl )
195 TabGeneralControl.typeKeys( " <RETURN>" )
198 printlog( CFN & "Verifying rename..." )
199 if ( NameText.getText() = cControl ) then
200 printlog( CFN & "Name is set ok: " & cControl )
201 hPBSetControlName() = true
205 ' If the name cannot be set this is in 99% of the cases a timing problem.
206 ' Here is a (costly) workaround.
207 qaerrorlog( CFN & "Name not set correctly, retrying" )
209 NameText.setText( cControl )
210 TabGeneralControl.typeKeys( "<RETURN>" )
213 ' Test again, leave function if good
214 if ( NameText.getText() = cControl ) then
215 printlog( CFN & "Name is set ok: " & cControl )
216 hPBSetControlName() = true
220 warnlog( CFN & "Unable to set control name: " & cControl )
221 hPBSetControlName() = false
224 warnlog( "Unable to name the control." )
225 hPBSetControlName() = false
231 '*******************************************************************************
233 function hPBGetControlName( cControl as string ) as boolean
235 '///<h3>Verify that the expected control is open</h3>
236 '///<i>Use hPBSetControlName( string ) to set the name and when you reopen it
237 '///+ verify that you got the right control wit this function</i><br><br>
241 '///+<li>Name of the control (string)</li>
247 '///+<li>Errorcondition (boolean)</li>
249 '///+<li>TRUE: The control has the correct name</li>
250 '///+<li>FALSE: Any other condition</li>
255 '///<u>Description</u>:
258 dim cControlName as string
259 const CFN = "hPBGetControlName::"
261 '///+<li>If "NameText" exists, retrieve its text</li>
262 kontext "TabGeneralControl"
263 if ( TabGeneralControl.exists( 1 ) ) then
264 if ( TabGeneralControl.isVisible() ) then
266 cControlName = NameText.getText()
268 '///+<li>Verify that the name is correct</li>
269 if ( cControlName = cControl ) then
270 printlog( CFN & "The name of the control is correct: " & cControl )
271 hPBGetControlName() = true
273 warnlog( CFN & "Unexpected control name:" )
274 printlog( CFN & "Found....: " & cControlName )
275 printlog( CFN & "Expected.: " & cControl )
276 hPBGetControlName() = false
279 warnlog( CFN & "Dialog present but tabpage could not be accessed (TabGeneralControl)." )
280 hPBGetControlName() = false
283 warnlog( CFN & "Unable to get the name from the control, dialog not accessible (TabGeneralControl)." )
284 hPBGetControlName() = false
290 '*******************************************************************************
292 function hCheckPropertyPresence ( cSetting as string , iPos as integer ) as boolean
294 '///<h3>Function to determine whether a property is available for a control or not</h3>
295 '///<i>This function takes a string (provided by controlcfg.dat) and looks for an 'x' at.
296 '///+ a given position. If it is found it returns TRUE, FALSE if it is a '-'<br>
297 '///+Note that this function is a terrible workaround for a missing feature: In the current
298 '///+ version of the Testtool we cannot ask which controls are present on a dialog. So this
299 '///+ has to be kept in a list of some sort. This is especially bad for a property browser
300 '///+ test as we need to maintain such a list for 21 controls and a total of 76 (IIRC)
301 '///+ possible properties whereof only a small number (eight, i think) are common for all
302 '///+ controls. The test is barely maintainable, issues have been written but there is
303 '///+ no solution so far.</i><br><br>
308 '///+<li>Configuration string (string)</li>
310 '///+<li>The string must be taken from file "controlcfg.dat"</li>
313 '///+<li>Position of the control (integer)</li>
315 '///+<li>> 0 and < 74 (all possible control config items)</li>
322 '///+<li>Status (boolean)</li>
324 '///+<li>TRUE: The property should exist for the current control</li>
325 '///+<li>FALSE: The property is not expected to exist for this control</li>
330 '///<u>Description</u>:
333 ' this function looks at a given position in the string cSetting for either
335 ' if "x" is found, the function returns true, else false.
338 '///+<li>Find the requested position in the string, set TRUE if it is an "x"</li>
339 if ( mid( cSetting , iPos , 1 ) = "x" ) then
340 hCheckPropertyPresence() = true
342 hCheckPropertyPresence() = false
348 '*******************************************************************************
350 function hSetPBTabPage( iPage as integer ) as boolean
352 '///<h3>A small helper to switch between tabpages in the property-browser</h3>
356 '///+<li>Page-ID (integer)</li>
358 '///+<li>1 = General page</li>
359 '///+<li>2 = Events page</li>
367 '///+<li>Errorcondition (boolean)</li>
369 '///+<li>TRUE on success</li>
370 '///+<li>FALSE on any error</li>
375 '///<u>Description</u>:
378 const CFN = "hSetPBTabPage::"
379 printlog( CFN & "Enter with option: " & iPage )
381 '///+<li>Switch to the requested page</li>
382 kontext "ControlPropertiesTabControl"
383 if ( not ControlPropertiesTabControl.exists( 3 ) ) then
384 printlog( CFN & "Exit: Control Properties Dialog is not open, aborting" )
385 hSetPBTabPage() = false
388 if ( DEBUG_ENABLE ) then
389 printlog( CFN & "Control Properties Dialog is open" )
396 printlog( CFN & "Switching to control properties tabpage" )
397 kontext "ControlPropertiesTabControl"
398 ControlPropertiesTabControl.setPage TabGeneralControl
400 kontext "TabGeneralControl"
401 if ( nametext.exists( 5 ) ) then
402 printlog( CFN & "Exit: Control properties are open (true)" )
403 hSetPBTabPage() = true
406 printlog( CFN & "Exit: Failed to open Control Properties (false)" )
407 hSetPBTabPage() = false
413 printlog( CFN & "Switching to event assignment tabpage" )
414 kontext "ControlPropertiesTabControl"
415 ControlPropertiesTabControl.setPage TabEventsControl
417 kontext "TabEventsControl"
418 if ( PBFocusGained.exists( 5 ) ) then
419 printlog( CFN & "Exit: Events page is open (true)" )
420 hSetPBTabPage() = true
423 printlog( CFN & "Exit: Failed to open events-page (false)" )
424 hSetPBTabPage() = false
430 printlog( CFN & "Invalid parameter passed to function: " & iPage )
431 hSerPBTabPage() = false
439 '*******************************************************************************
441 function hSetLabelName( sLabelName as string ) as boolean
443 '///<h3>Name a control, with limited errorhandling</h3>
445 '///<i>This function was introduced due to a problem with the property-
446 '///browser not being open fast enough or just refusing to accept input</i><br><br>
450 '///+<li>Text to be inserted in the control "NameText" (string)</li>
456 '///+<li>Errorcondition</li>
458 '///+<li>TRUE: The control name was successfully updated</li>
459 '///+<li>FALSE: Control is not visible within current context</li>
464 '///<u>Description</u>:
466 '///+<li>Test that the control "NameText" exists</li>
467 kontext "TabGeneralControl"
468 if ( Label.exists() ) then
469 '///+<li>Set the new name</li>
470 Label.setText( sLabelName )
471 TabGeneralControl.TypeKeys ("<RETURN>" , true)
472 hSetLabelName() = true
474 warnlog( "Unable to name the control." )
475 hSetLabelName() = false