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: t_set_standard_controls.inc,v $
13 '* last change: $Author: jsi $ $Date: 2008-06-13 10:27:08 $
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 : helge.delfs@sun.com
36 '* short description : Tool library for setting controls and verifying the functionality
38 '**************************************************************************************************
40 ' #0 fSetListBoxByItem 'Function to select item in list box
41 ' #0 fSetListBoxByString 'Function to select item by string in list box
42 ' #0 fSetSpinFieldByString 'Function to set a string in a spin field control
43 ' #0 fSetSpinFieldByButton 'Function to set a spin field control by using 'more' or 'less' button
44 ' #0 fSetSpinFieldByLimit 'Function to set a spin field control to minimum or maximum value
45 ' #0 fSetComboBoxByItem 'Function to select item in combo box
46 ' #0 fSetComboBoxByString 'Function to select item in combo box
47 ' #0 fSetComboBoxByText 'Function to Edit Field part of a combo box
48 ' #0 fSetCheckBox 'Function to (un)check a check box
49 ' #0 fSetRadioButton 'Function to check a radio button
50 ' #0 fSetTextBox 'Function to set a textbox
52 '\************************************************************************************************
54 '///<u><b>Library for abtracted handling of several control types</b></u>
55 '///+Note: This functions are designed to be called by wrapping functions
56 '///+All functions are designed to return error codes depending on the behaviour of the action applied.
57 '///<b>Return codes:</b>
58 '///+<ul><li>Error 0: Success</li>
59 '///+<li>Error 1: The basic action beeing applied caused a serious problem, e.g. a crash</li>
60 '///+<li>Error 2 TO 9: A functional problem occured.</li>
61 '///+<li>Error 11 TO 19: Wrong marginal conditions end up in Failure, e.g. control not visible</li></ul>
62 '/// NOTE: This errors can also be used for 'negative' testing.
63 '///+<ul><li>Error 42: Wrong input. Probably only of interest during test development</li>
64 '///+<li>Error 99: Unexpected behaviour - Shouldn't normally occur</li></ul>
66 '///+<ul><li>Only Errors 42 and 99 throw 'warnlogs'</li>
67 '///+<li>All other errors are silent!</li>
68 '///+<li>They only throw QAErrorlogs the give a hint what probably went wrong.</li>
69 '///+<li>Expected Errors MUST exclusivly be handled by the calling routine!</li></ul>
70 '///+<p><font size=-1><i>The idea and the first implementation of this library has been made by Peter Junge (pj at openoffice.org)</i></font></p>
73 function fSetTextBox ( oThisTextBox as OBJECT , sThisText as STRING ) as INTEGER
75 'Function to set a text box
77 '+OBJECT oThisTextBox (text box name in declaration)
78 '+STRING sThisText (text to be set in text box control)
79 ' Return (Error-codes):
81 '+1 = Serious problem trying to set value
82 '+2 = Value was not set
83 '+11 = Text box is not visible
84 '+12 = Text box is not enabled
85 '+99 = Unexpected error
88 dim iListLength as INTEGER
89 dim sResultInUI as STRING
93 printlog "Setting text in Text Box Edit field"
94 ' Check if desired Text box is visible
95 if NOT oThisTextBox.IsVisible then
96 QAErrorLog "Error 11: Text box is not visible"
100 ' Check if desired Text box is enabled
101 if NOT oThisTextBox.IsEnabled then
102 QAErrorLog "Error 12: Text box is not enabled"
106 ' Try to set text on Text Box
108 oThisTextBox.setText sThisText
110 ' Throw error 1 and quit on serious problem
111 qaErrorLog "Error 1: Set text on Text box seems to cause a serious problem."
115 'Verify (against input) if text was set correctly
116 sResultInUI = oThisTextBox.GetText
117 if sResultInUI = sThisText then
119 printlog "Set '" & sThisText & "' in 'text box' control PASSED."
121 QAErrorLog "Error 2: Setting '" & sThisText & "' in 'text box' control failed!"
125 if fSetTextBox = 99 then
126 warnlog "Error 99: Something unexpected happened!!"
130 '--------------------------------------------------------------------
132 function fSetListBoxByItem ( oThisListBox as OBJECT , iThisValue as INTEGER ) as INTEGER
133 fSetListBoxByItem = 99
134 'Function to select item in list box
136 '+OBJECT oThisListBox (list box name in declaration)
137 '+INTEGER iThisValue (item number to be selected in list box control)
138 'Return (Error-codes):
140 '+ 1 = Serious problem trying to set value
141 '+ 2 = Value was not set
142 '+11 = List box is not visible
143 '+12 = List box is not enabled
144 '+13 = Item number to be selected out of list range
145 '+99 = Unexpected error
147 dim iListLength as INTEGER
148 dim iResultFromUI as INTEGER
152 printlog "Setting Item in list box"
153 'Check if desired list box is visible
154 if NOT oThisListBox.IsVisible then
155 QAErrorLog "Error 11: List box is not visible"
156 fSetListBoxByItem = 11
159 'Check if desired list box is enabled
160 if NOT oThisListBox.IsEnabled then
161 QAErrorLog "Error 12: List box is not enabled"
162 fSetListBoxByItem = 12
165 'Check if input value is within list length
166 iListLength = oThisListBox.GetItemCount
167 if iThisValue < 1 OR iThisValue > iListLength then
168 QAErrorLog "Error 13: Item number out of list range"
169 fSetListBoxByItem = 13
172 'Try to set value in List Box
174 oThisListBox.select iThisValue
176 'Throw error 1 and quit on serious problem
177 QAErrorLog "Error 1: Set value on list box seems to cause a serious problem."
178 fSetListBoxByItem = 1
181 'Verify (against input) if item was set correctly
182 iResultFromUI = oThisListBox.GetSelIndex
183 if iResultFromUI = iThisValue then
184 fSetListBoxByItem = 0
185 printlog ">> Set value in list box seems to work"
187 QAErrorLog "Error 2: Set value in list box failed."
188 fSetListBoxByItem = 2
191 if fSetListBoxByItem = 99 then
192 warnlog "Error 99: Something unexpected happened!!"
196 '--------------------------------------------------------------------
198 function fSetListBoxByString ( oThisListBox as OBJECT , sThisString as STRING ) as INTEGER
199 fSetListBoxByString = 99
200 'Function to select item by string in list box
202 '+OBJECT oThisListBox (list box name in declaration)
203 '+STRING sThisString (string trying to match in list box items)
204 'Return(E rror-codes):
206 '+ 1 = Serious problem trying to set value
207 '+ 2 = Value was not set
208 '+11 = List box is not visible
209 '+12 = List box is not enabled
210 '+13 = String to be selected doesn't exist in list box
211 '+99 = Unexpected error
213 dim iIndex as INTEGER
214 dim iListLength as INTEGER
215 dim bStringIsInList as BOOLEAN
216 dim sUIStringNow as STRING
218 bStringIsInList = FALSE
221 printlog "** Setting Item in list box"
222 'Check if desired list box is visible
223 if NOT oThisListBox.IsVisible then
224 qaErrorLog "Error 11: List box is not visible"
225 fSetListBoxByString = 11
228 'Check if desired list box is enabled
229 if NOT oThisListBox.IsEnabled then
230 qaErrorLog "Error 12: List box is not enabled"
231 fSetListBoxByString = 12
234 'Check if input value is existent in list entries
235 iListLength = oThisListBox.GetItemCount
236 for iIndex = 1 to iListLength
237 if oThisListBox.GetItemText ( iIndex ) = sThisString then
238 bStringIsInList = TRUE
241 if bStringIsInList then
242 printlog "OK, String exists in list box"
244 qaErrorLog "Error 13: Input String not found in list entries"
245 fSetListBoxByString = 13
248 'Try to set value in List Box
250 oThisListBox.select sThisString
252 'Throw error 1 and quit on serious problem
253 qaErrorLog "Error 1: Set value on list box seems to cause a serious problem."
254 fSetListBoxByString = 1
257 'Verify (against input) if item was set correctly
258 sUIStringNow = oThisListBox.GetSelText
259 if sUIStringNow = sThisString then
260 fSetListBoxByString = 0
261 printlog "Setting value in list box is OK"
263 qaErrorLog "Error 2: Set value in list box failed."
264 fSetListBoxByString = 2
267 if fSetListBoxByString = 99 then
268 warnlog "Error 99: Something unexpected happened!!"
272 '--------------------------------------------------------------------
274 function fSetSpinFieldByString ( oThisSpinField as OBJECT , sThisString as STRING ) as INTEGER
275 fSetSpinFieldByString = 99
276 'Function to set a string in a spin field control
278 '+OBJECT oThisSpinField (spin field name in declaration)
279 '+STRING sThisString (string to set in spin field control)
280 'Return (Error codes):
282 '+ 1 = Serious problem trying to set value
283 '+11 = Spin field is not visible
284 '+12 = Spin field is not enabled
285 '+99 = Unexpected error
287 printlog "Setting value in spin field"
288 'Check if desired spin field is visible
289 if NOT oThisSpinField.IsVisible then
290 qaErrorLog "Error 11: Spin field is not visible"
291 fSetSpinFieldByString = 11
294 'Check if desired spin field is enabled
295 if NOT oThisSpinField.IsEnabled then
296 qaErrorLog "Error 12: Spin field is not enabled"
297 fSetSpinFieldByString = 12
300 'Try to set value in spin field
302 oThisSpinField.setText sThisString
303 fSetSpinFieldByString = 0
305 'Throw error 1 and quit on serious problem
306 qaErrorLog "Error 1: Setting value on spin field seems to cause a serious problem."
307 fSetSpinFieldByString = 1
310 if fSetSpinFieldByString = 99 then
311 warnlog "Error 99: Something unexpected happened!!"
315 '--------------------------------------------------------------------
317 function fSetSpinFieldByButton ( oThisSpinField as OBJECT , sMoreOrLess as STRING , OPTIONAL iTimes as INTEGER ) as INTEGER
318 fSetSpinFieldByButton = 99
319 'Function to set a spin field control by using More or Less button
321 '+OBJECT oThisSpinField (spin field control name in declaration
322 '+STRING sMoreOrLess has to be <i>more</i> or <i>less</i> (to click on 'More' or 'Less' button in spin field)
323 '+<i>optional</i> INTEGER iTimes (How often to click if more than once)
324 'Return (Error codes):
326 '+ 1 = Serious problem trying to set value
327 '+11 = Spin field is not visible
328 '+12 = Spin field is not enabled
329 '+42 = User error, input doesn't match
330 '+99 = Unexpected error
332 'toggle spin field as least once
333 if isMissing ( iTimes ) then
336 printlog "Toggle value in spin field"
337 'Check if desired spin field is visible
338 if NOT oThisSpinField.IsVisible then
339 qaErrorLog "Error 11: Spin field is not visible"
340 fSetSpinFieldByButton = 11
343 'Check if desired spin field is enabled
344 if NOT oThisSpinField.IsEnabled then
345 qaErrorLog "Error 12: Spin field is not enabled"
346 fSetSpinFieldByButton = 12
349 'Try to toggle value in spin field
351 select case lcase ( sMoreOrLess )
352 case "more" : oThisSpinField.more ( iTimes )
353 case "less" : oThisSpinField.less ( iTimes )
355 fSetSpinFieldByButton = 42
356 warnlog "USER ERROR: Input doesn't match!"
359 fSetSpinFieldByButton = 0
361 'Throw error 1 and quit on serious problem
362 qaErrorLog "Error 1: Try to toggle spin field seems to cause a serious problem."
363 fSetSpinFieldByButton = 1
366 if fSetSpinFieldByButton = 99 then
367 warnlog "Error 99: Something unexpected happened!!"
371 '--------------------------------------------------------------------
373 function fSetSpinFieldByLimit ( oThisSpinField as OBJECT , sMinOrMax as STRING ) as INTEGER
374 fSetSpinFieldByLimit = 99
375 'Function to set a spin field control to minimum or maximum value
377 '+OBJECT oThisSpinField (spin field name in declaration
378 '+STRING sMinOrMax has to be <i>min</i> or <i>max</i> (to set spin field to minimum or maximum value)
379 'Return (Error codes):
381 '+ 1 = Serious problem trying to set value
382 '+11 = Spin field is not visible
383 '+12 = Spin field is not enabled
384 '+42 = User error, input doesn't match
385 '+99 = Unexpected error
387 printlog "Set spin field control to minimum or maximum value"
388 'Check if desired spin field is visible
389 if NOT oThisSpinField.IsVisible then
390 qaErrorLog "Error 11: Spin field is not visible"
391 fSetSpinFieldByLimit = 11
394 'Check if desired spin field is enabled
395 if NOT oThisSpinField.IsEnabled then
396 qaErrorLog "Error 12: spin field is not enabled"
397 fSetSpinFieldByLimit = 12
400 'Try to set spin field to minimum or maximum value
402 select case lcase ( sMinOrMax )
403 case "max" : oThisSpinField.toMax
404 case "min" : oThisSpinField.toMin
406 fSetSpinFieldByLimit = 42
407 warnlog "USER ERROR: Input doesn't match!"
410 fSetSpinFieldByLimit = 0
412 'Throw error 1 and quit on serious problem
413 qaErrorLog "Error 1: Trying to set spin field to minimum or maximum value seems to cause a serious problem."
414 fSetSpinFieldByLimit = 1
417 if fSetSpinFieldByLimit = 99 then
418 warnlog "Error 99: Something unexpected happened!!"
422 '--------------------------------------------------------------------
424 function fSetComboBoxByItem ( oThisComboBox as OBJECT , iThisValue as INTEGER ) as INTEGER
425 'This is an alias for 'fSetListBoxByItem'
427 'Function to select item in combo box
429 '+OBJECT oThisComboBox (combo box name in declaration)
430 '+INTEGER iThisValue (item number to be selected in Combo box)
431 'Return (Error codes):
433 '+ 1 = Serious problem trying to set value
434 '+ 2 = Value was not set
435 '+11 = Combo box is not visible
436 '+12 = Combo box is not enabled
437 '+13 = Item number to be selected out of list range
438 '+99 = Unexpected error
439 fSetComboBoxByItem = fSetListBoxByItem ( oThisComboBox , iThisValue )
442 '--------------------------------------------------------------------
444 function fSetComboBoxByString ( oThisComboBox as OBJECT , iThisString as STRING ) as INTEGER
445 'This is an alias for 'fSetListBoxByString'
446 'Function to select item in combo box
448 '+OBJECT oThisComboBox (combo box name in declaration)
449 '+STRING iThisString (string to be selected in combo box control)
450 'Return (Error codes):
452 '+ 1 = Serious problem trying to set value
453 '+ 2 = Value was not set
454 '+11 = Combo box is not visible
455 '+12 = Combo box is not enabled
456 '+13 = String to be selected doesn't exist in list box
457 '+99 = Unexpected error
458 fSetComboBoxByString = fSetListBoxByString ( oThisComboBox , iThisString )
461 '--------------------------------------------------------------------
463 function fSetComboBoxByText ( oThisComboBox as OBJECT , sThisText as STRING , OPTIONAL bVerifyAgainstEntries as BOOLEAN ) as INTEGER
464 fSetComboBoxByText = 99
465 'Function to Edit Field part of a combo box
467 '+OBJECT oThisComboBox (combo box name in declaration)
468 '+STRING sThisText (Text to be set in combo box edit field
469 '+<i>optional</i> BOOLEAN bVerifyAgainstEntries (Check if setting the text succeeded)
470 'Return (Error codes):
472 '+ 1 = Serious problem trying to set value
473 '+ 2 = Value was not set
474 '+11 = Combo box is not visible
475 '+12 = Combo box is not enabled
476 '+13 = String to be selected doesn't exist in list box (if <i>optional</i> input parameter has been used)
477 '+99 = Unexpected error
479 dim iIndex as INTEGER
480 dim iListLength as INTEGER
481 dim bStringIsInList as BOOLEAN
482 dim sStringinUI as STRING
484 bStringIsInList = FALSE
487 'Only check Edit Field against list box if 'bVerifyAgainstEntries' is explizitly TRUE
488 if isMissing ( bVerifyAgainstEntries ) then
489 bVerifyAgainstEntries = FALSE
492 printlog "Setting text in Combo Box Edit field"
493 'Check if desired combo box is visible
494 if NOT oThisComboBox.IsVisible then
495 qaErrorLog "Error 11: Combo box is not visible"
496 fSetComboBoxByText = 11
499 'Check if desired combo box is enabled
500 if NOT oThisComboBox.IsEnabled then
501 qaErrorLog "Error 12: Combo box is not enabled"
502 fSetComboBoxByText = 12
505 'Check if input value is existent in list entries (optinal if desired)
506 if bVerifyAgainstEntries then
507 iListLength = oThisComboBox.GetItemCount
508 for iIndex = 1 to iListLength
509 if oThisComboBox.GetItemText ( iIndex ) = sThisText then
510 bStringIsInList = TRUE
513 if bStringIsInList then
514 printlog "OK, string exists in list box control"
516 qaErrorLog "Error 13: Input string not found in list entries"
517 fSetComboBoxByText = 13
521 'Trying to set text on combo box
523 oThisComboBox.setText sThisText
525 'Throw error 1 and quit on serious problem
526 qaErrorLog "Error 1: Set text in combo box seems to cause a serious problem."
527 fSetComboBoxByText = 1
530 'Verify (against input) if text was set correctly
531 sStringinUI = oThisComboBox.GetSelText
532 if sStringinUI = sThisText then
533 fSetComboBoxByText = 0
534 printlog "Setting text in Combo box works"
536 qaErrorLog "Error 2: Set text in Combo box failed."
537 fSetComboBoxByText = 2
540 if fSetComboBoxByText = 99 then
541 warnlog "Error 99: Something unexpected happened!!"
545 '--------------------------------------------------------------------
547 function fSetCheckBox ( oThisCheckBox as OBJECT , bCheck as BOOLEAN ) as INTEGER
549 'Function to (un)check a check box
551 '+OBJECT oThisCheckBox (check box name in declaration)
552 '+BOOLEAN bCheck (check or uncheck the check box control)
553 'Return (Error codes):
555 '+ 1 = Serious problem trying to check the box
556 '+ 2 = Box was not checked
557 '+11 = Check box is not visible
558 '+12 = Check box is not enabled
559 '+99 = Unexpected error
561 printlog "Checking check box"
562 'Check if desired check box is visible
563 if NOT oThisCheckBox.IsVisible then
564 qaErrorLog "Error 11: Check box is not visible"
568 'Check if desired check box is enabled
569 if NOT oThisCheckBox.IsEnabled then
570 qaErrorLog "Error 12: Check box is not enabled"
574 'Try to check check box control
579 oThisCheckBox.Uncheck
582 'Throw error 1 and quit on serious problem
584 qaErrorLog "Error 1: Checking check box control cause into a serious problem."
586 qaErrorLog "Error 1: Unchecking check box control cause into a serious problem."
591 'Verify (against input) if check box is checked
592 if oThisCheckBox.IsChecked = bCheck then
594 printlog "Check check box seems to work"
596 qaErrorLog "Error 2: Check check box failed."
599 if fSetCheckBox = 99 then
600 warnlog "Error 99: Something unexpected happened!!"
604 '--------------------------------------------------------------------
606 function fSetRadioButton ( oThisRadioButton as OBJECT ) as INTEGER
608 'Function to check a radio button
610 '+OBJECT oThisRadioButton (radio button name in declaration)
611 'Return (Error codes):
613 '+ 1 = Serious problem trying to check the radio button
614 '+ 2 = Radio button was not checked
615 '+11 = Radio button is not visible
616 '+12 := Radio button is not enabled
617 '+99 := Unexpected error
618 printlog "Checking radio button"
619 'Check if desired radio button is visible
620 if NOT oThisRadioButton.IsVisible then
621 qaErrorLog "Error 11: Radio button is not visible"
625 'Check if desired radio button is enabled
626 if NOT oThisRadioButton.IsEnabled then
627 qaErrorLog "Error 12: Radio button is not enabled"
631 'Try to check Radio Button
633 oThisRadioButton.Check
635 'Throw error 1 and quit on serious problem
636 qaErrorLog "Error 1: Check radio button seems to cause a serious problem."
640 'Verify if radio button is checked
641 if oThisRadioButton.IsChecked = TRUE then
643 printlog "Check radio button seems to work"
645 qaErrorLog "Error 2: Check radio button failed."
648 if fSetRadioButton = 99 then
649 warnlog "Error 99: Something unexpected happened!!"