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_option2.inc,v $
13 '* last change: $Author: jsi $ $Date: 2008-06-13 10:27:11 $
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 : thorsten.bosbach@sun.com
36 '* short description : Tools library for options testcases
38 '\***********************************************************************
40 function OptionTabPageZaehler ( SollAnzahl as Integer, optional Ausnahme as Boolean )
41 'parameter Ausnahme is depracted
43 Kontext "ExtrasOptionenDlg"
44 IstAnzahl = Optionsliste.GetItemCount - iSectionNumber
45 if Ausnahme = FALSE then
46 if IstAnzahl <> SollAnzahl then WarnLog "Number of tabpages old : " + SollAnzahl + " new : " + IstAnzahl
48 OptionTabPageZaehler = IstAnzahl
51 '-------------------------------------------------------------------------
53 sub ToPosInOptionlist ( Sprung as Integer )
56 Optionsliste.TypeKeys "<HOME>"
58 Optionsliste.TypeKeys "-<DOWN>"
60 Optionsliste.Select Sprung
61 Optionsliste.TypeKeys "+"
64 '-------------------------------------------------------------------------
66 sub DialogeFuerTypenKontrollieren
67 ' Complete test for path-options, for all entries the file-dialog or the path-dialog will be opened
70 Dim iErrorCount as integer
71 dim iExitCounter as integer : iExitCounter = 0
73 Typ.TypeKeys "<Down><Down><Home>"
76 for i=1 to Typ.GetItemCount
77 if i<>1 then Typ.TypeKeys "<Down>"
78 printlog " "+typ.getText
79 if ( bAsianLan <> TRUE ) then
83 do while( iExitCounter <= 10 )
86 if ( active.exists() ) then
87 iErrorCount = iErrorCount + 1
88 if (iErrorCount > 1) then
89 Warnlog active.getText
91 qaErrorlog "#i69014# gallery path doesn't exist: '" + active.getText + "'"
92 printlog active.getText
97 if OeffnenDlg.Exists() then
98 if ( Dateityp.IsVisible ) then
99 Warnlog "The normal FileOpen-Dialog is visible with the Filetype-Listbox => BUG!"
105 Kontext "PfadeAuswaehlen"
106 if ( PfadeAuswaehlen.exists() ) then
107 PfadeAuswaehlen.Cancel
111 iExitCounter = iExitCounter + 1
115 Warnlog "Error on entry " & i & "!"
120 if ( Bearbeiten.IsEnabled ) then
123 do while( iExitCounter <= 10 )
126 if active.exists () then
127 iErrorCount = iErrorCount + 1
128 if (iErrorCount > 1) then
129 Warnlog active.getText
131 qaErrorlog "WorkAround for #109107# has to come up only once @'Add-Ins'! else BUG!"
136 if OeffnenDlg.Exists() then
137 if ( Dateityp.IsVisible ) then
138 Warnlog "The normal FileOpen-Dialog is visible with the Filetype-Listbox => BUG!"
144 Kontext "PfadeAuswaehlen"
145 if ( PfadeAuswaehlen.exists() ) then
146 PfadeAuswaehlen.Cancel
155 Warnlog "Error on entry " & i & "!"
160 if iCount > 3 then Warnlog "There are more than 3 entries are disabled!"
164 '-------------------------------------------------------------------------
166 function hSetMacroSecurity( iLevel as integer ) as integer
168 '///<h3>Set macro security level via GUI</h3>
169 '///<i>Set the macro security by accessing the Tools/Options->
170 '///+ OpenOffice.org/Security::Macro... Tabpage</i><br><br>
172 '///<u>Parameter(s):</u><br>
175 '///+<li>Desired macro security level (Integer). Following symbolic names are defined:</li>
177 '///+<li>GC_MACRO_SECURITY_LEVEL_LOW (0) for low security</li>
178 '///+<li>GC_MACRO_SECURITY_LEVEL_MEDIUM (1) for medium security</li>
179 '///+<li>GC_MACRO_SECURITY_LEVEL_HIGH (2) for high security</li>
180 '///+<li>GC_MACRO_SECURITY_LEVEL_VERYHIGH (3) for very high security</li>
186 '///<u>Returns:</u><br>
188 '///+<li>Previous security level (Integer)</li>
190 '///+<li>GC_MACRO_SECURITY_LEVEL_LOW (0) for low security</li>
191 '///+<li>GC_MACRO_SECURITY_LEVEL_MEDIUM (1) for medium security</li>
192 '///+<li>GC_MACRO_SECURITY_LEVEL_HIGH (2) for high security</li>
193 '///+<li>GC_MACRO_SECURITY_LEVEL_VERYHIGH (3) for very high security</li>
194 '///+<li>-1 on error</li>
200 '///Switch between macro security levels in Tools/Options
202 const CFN = "hSetMacroSecurity::"
203 dim iOldSecurityLevel as integer
205 dim caLevel( 3 ) as string
207 caLevel( 1 ) = "medium"
208 caLevel( 2 ) = "high"
209 caLevel( 3 ) = "very high"
211 if ( ( iLevel < GC_MACRO_SECURITY_LEVEL_LOW ) or ( iLevel > GC_MACRO_SECURITY_LEVEL_VERYHIGH ) ) then
212 warnlog( CFN & "Invalid index (0...3) passed to function: " & ilevel )
213 hSetMacroSecurity() = -1
217 '///+<li>Open Tools/Options -> OpenOffice.org/Security</li>
219 hToolsOptions( "Staroffice" , "Security" )
221 '///+<li>Click on the macro security button</li>
222 Kontext "TabSecurity"
223 if ( MacroSecurity.exists( 2 ) ) then
224 MacroSecurity.click()
226 '///+<li>Ensure we are on the Security Level page</li>
228 if ( Active.exists( 2 ) ) then
231 active.setpage TabSecurityLevel
233 '///+<li>Get the current setting (=returnvalue)</li>
234 Kontext "TabSecurityLevel"
235 if ( TabSecurityLevel.exists( 2 ) ) then
236 if ( veryhigh.isChecked() ) then
237 iOldSecurityLevel = GC_MACRO_SECURITY_LEVEL_VERYHIGH
238 elseif( high.isChecked() ) then
239 iOldSecurityLevel = GC_MACRO_SECURITY_LEVEL_HIGH
240 elseif( medium.isChecked() ) then
241 iOldSecurityLevel = GC_MACRO_SECURITY_LEVEL_MEDIUM
242 elseif( low.isChecked() ) then
243 iOldSecurityLevel = GC_MACRO_SECURITY_LEVEL_LOW
246 printlog( CFN & "Security Tabpage not available. Aborting." )
247 kontext "OptionenDlg"
248 if ( OptionenDlg.exists( 2 ) ) then
251 warnlog( CFN & "Unrecoverable error, status unknown." )
253 hSetMacroSecurity() = -1
257 '///+<li>Set the new security level</li>
259 case GC_MACRO_SECURITY_LEVEL_LOW : low.check()
260 case GC_MACRO_SECURITY_LEVEL_MEDIUM : medium.check()
261 case GC_MACRO_SECURITY_LEVEL_HIGH : high.check()
262 case GC_MACRO_SECURITY_LEVEL_VERYHIGH : veryhigh.check()
265 printlog( CFN & "Setting macro security level to " & caLevel( iLevel ) )
268 printlog( CFN & "Macro Security Dialog did not open. Aborting." )
269 kontext "OptionenDlg"
270 if ( OptionenDlg.exists( 2 ) ) then
273 warnlog( CFN & "Unrecoverable error, status unknown." )
275 hSetMacroSecurity() = -1
279 '///+<li>Close Tools/Options</li>
280 TabSecurityLevel.ok()
282 warnlog( CFN & "The Macro Security Button is not available" )
283 iOldSecurityLevel = -1
285 Kontext "OptionenDLG"
288 hSetMacroSecurity() = iOldSecurityLevel
291 '*******************************************************************************
293 function hGetMacroSecurityAPI() as integer
296 '///<h3>Retrieve the macro security level via API</h3>
297 '///<i>Use remote UNO to quickly retrieve the current macro security level.
298 '///+ This function runs silent unless an error is encountered.</i><br><br>
300 '///<u>Parameter(s):</u><br>
302 '///+<li>No input parameters</li>
306 '///<u>Returns:</u><br>
308 '///+<li>Macro Security Level (Integer)</li>
310 '///+<li>GC_MACRO_SECURITY_LEVEL_LOW (0) for low security</li>
311 '///+<li>GC_MACRO_SECURITY_LEVEL_MEDIUM (1) for medium security</li>
312 '///+<li>GC_MACRO_SECURITY_LEVEL_HIGH (2) for high security</li>
313 '///+<li>GC_MACRO_SECURITY_LEVEL_VERYHIGH (3) for very high security</li>
314 '///+<li>-1 = Error</li>
318 const CFN = "hGetMacroSecurityAPI::"
320 dim oUnoOfficeConnection as object
321 dim oUnoConfigurationAccess as object
322 dim aPropertyValue( 1 ) As new com.sun.star.beans.PropertyValue
323 dim iLevel as integer
328 oUnoOfficeConnection=hGetUnoService(TRUE)
329 oUnoConfigurationAccess=oUnoOfficeConnection.createInstance("com.sun.star.configuration.ConfigurationProvider")
331 aPropertyValue( 0 ).Name = "nodepath"
332 aPropertyValue( 0 ).Value = "/org.openoffice.Office.Common/Security/Scripting"
333 aPropertyValue( 1 ).Name = "lazywrite"
334 aPropertyValue( 1 ).Value = FALSE
336 xViewRoot=oUnoConfigurationAccess.createInstanceWithArguments( "com.sun.star.configuration.ConfigurationUpdateAccess", aPropertyValue() )
337 iLevel = xViewRoot.getByName( "MacroSecurityLevel" )
342 warnlog( CFN & "Failed to retrieve macro security Level via API" )
347 hGetMacroSecurityAPI() = iLevel
352 '*******************************************************************************
354 function hSetMacroSecurityAPI( iSecLevel as integer ) as integer
357 '///<h3>Set macro security level using API</h3>
358 '///<i>Set the macro security using remote uno. This implementation does exactly
359 '///+ the same as hSetMacroSecurity but is considerably faster</i><br><br>
361 '///<u>Parameter(s):</u><br>
364 '///+<li>Desired macro security level (Integer). Following symbolic names are defined:</li>
366 '///+<li>GC_MACRO_SECURITY_LEVEL_LOW (0) for low security</li>
367 '///+<li>GC_MACRO_SECURITY_LEVEL_MEDIUM (1) for medium security</li>
368 '///+<li>GC_MACRO_SECURITY_LEVEL_HIGH (2) for high security</li>
369 '///+<li>GC_MACRO_SECURITY_LEVEL_VERYHIGH (3) for very high security</li>
375 '///<u>Returns:</u><br>
377 '///+<li>Previous security level (Integer)</li>
379 '///+<li>GC_MACRO_SECURITY_LEVEL_LOW (0) for low security</li>
380 '///+<li>GC_MACRO_SECURITY_LEVEL_MEDIUM (1) for medium security</li>
381 '///+<li>GC_MACRO_SECURITY_LEVEL_HIGH (2) for high security</li>
382 '///+<li>GC_MACRO_SECURITY_LEVEL_VERYHIGH (3) for very high security</li>
383 '///+<li>-1 on error</li>
387 const CFN = "hSetMacroSecurityAPI::"
389 dim oUnoOfficeConnection as object
390 dim oUnoConfigurationAccess as object
391 dim aPropertyValue( 1 ) As new com.sun.star.beans.PropertyValue
392 dim iLevel as integer
395 dim caLevel( 3 ) as string
397 caLevel( 1 ) = "medium"
398 caLevel( 2 ) = "high"
399 caLevel( 3 ) = "very high"
401 aPropertyValue( 0 ).Name = "nodepath"
402 aPropertyValue( 0 ).Value = "/org.openoffice.Office.Common/Security/Scripting"
403 aPropertyValue( 1 ).Name = "lazywrite"
404 aPropertyValue( 1 ).Value = FALSE
406 '///<u>Description:</u>
411 '///+<li>Verify input parameter, quit function with a warning on error</li>
412 if ( iSecLevel < GC_MACRO_SECURITY_LEVEL_LOW or iSecLevel > GC_MACRO_SECURITY_LEVEL_VERYHIGH ) then
414 warnlog( CFN & "Invalid security level passed to function: " & iSecLevel )
415 hSetMacroSecurityAPI() = -1
421 '///+<li>Get current security level, set the new one</li>
424 oUnoOfficeConnection=hGetUnoService(TRUE)
425 oUnoConfigurationAccess=oUnoOfficeConnection.createInstance("com.sun.star.configuration.ConfigurationProvider")
427 xViewRoot=oUnoConfigurationAccess.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess",aPropertyValue())
428 iLevel = xViewRoot.getByName( "MacroSecurityLevel" ) ' Get the current value
429 xViewRoot.setPropertyValue( "MacroSecurityLevel" , iSecLevel ) ' Set the new value
430 xViewRoot.commitChanges()
433 'printlog( CFN & "Setting macro security level to " & caLevel( iSecLevel )
437 warnlog( CFN & "Failed to get/set new macro security level via API:" & iSecLevel )
443 hSetMacroSecurityAPI() = iLevel
447 '*******************************************************************************
449 function hIsOOoImprovementTabVisible() as boolean
451 ' This function tries to find out whether the OOo Improvement Program
452 ' Tabpage in Tools/Options is visible or not.
454 dim oUnoConnect as object
455 dim oOOoImprovementController as object
456 dim bExists as boolean
457 const CFN = "hIsOOoImprovementTabVisible()::"
459 oUnoConnect = hGetUnoService( TRUE )
460 if ( isNull( oUnoConnect ) ) then
461 warnlog( CFN & "Failed to establish UNO connection, hGetUnoService failed" )
462 hIsOOoImprovementTabVisible() = FALSE
466 oOOoImprovementController = oUnoConnect.createInstance( "com.sun.star.oooimprovement.CoreController" )
467 bExists = oOOoImprovementController.showBuiltinOptionsPage( 1 )
469 'printlog( CFN & "The OOo Improvement Program Tabpage is visible" )
470 hIsOOoImprovementTabVisible() = TRUE
472 printlog( CFN & "The OOo Improvement Program Tabpage is not visible" )
473 hIsOOoImprovementTabVisible() = FALSE
476 warnlog( CFN & "Method com.sun.star.oooimprovement.CoreController.showBuiltinOptionsPage() not available." )
477 printlog( CFN & "This indicates that the OOo Improvement Program feature is not included in this build." )
478 hIsOOoImprovementTabVisible() = FALSE
484 '*******************************************************************************
486 function hEnableOOoImprovementProgramUNO() as boolean
488 ' This function tries to enable the OOo Improvement Program (switch it on)
489 dim oUnoOfficeConnection as object
490 dim oUnoConfigurationAccess as object
491 dim aPropertyValue(1) As new com.sun.star.beans.PropertyValue ' Array of pairs: Property with Value
494 const CFN = "hEnableOOoImprovementProgramUNO()::"
496 aPropertyValue(0).Name = "nodepath"
497 aPropertyValue(0).Value = "/org.openoffice.Office.OOoImprovement.Settings/Participation"
498 aPropertyValue(1).Name = "lazywrite"
499 aPropertyValue(1).Value = False
501 oUnoOfficeConnection = hGetUnoService( TRUE )
502 if ( isNull( oUnoOfficeConnection )) then
503 warnlog( CFN & "Failed to establish UNO connection, hGetUnoService failed" )
504 hEnableOOoImprovementProgramUNO() = FALSE
506 oUnoConfigurationAccess = oUnoOfficeConnection.createInstance("com.sun.star.configuration.ConfigurationProvider")
507 xViewRoot = oUnoConfigurationAccess.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess",aPropertyValue())
508 xViewRoot.replaceByName( "ShowedInvitation", TRUE )
509 xViewRoot.replaceByName( "InvitationAccepted", TRUE )
510 xViewRoot.commitChanges()
511 hEnableOOoImprovementProgramUNO() = TRUE
512 if ( xViewRoot.hasPendingChanges() ) then
513 hEnableOOoImprovementProgramUNO() = FALSE
520 '*******************************************************************************
522 function hDisableOOoImprovementProgramUNO() as boolean
524 ' This function tries to enable the OOo Improvement Program (switch it on)
525 dim oUnoOfficeConnection as object
526 dim oUnoConfigurationAccess as object
527 dim aPropertyValue(1) As new com.sun.star.beans.PropertyValue ' Array of pairs: Property with Value
530 const CFN = "hDisableOOoImprovementProgramUNO()::"
532 aPropertyValue(0).Name = "nodepath"
533 aPropertyValue(0).Value = "/org.openoffice.Office.OOoImprovement.Settings/Participation"
534 aPropertyValue(1).Name = "lazywrite"
535 aPropertyValue(1).Value = False
537 oUnoOfficeConnection = hGetUnoService( TRUE )
538 if ( isNull( oUnoOfficeConnection )) then
539 warnlog( CFN & "Failed to establish UNO connection, hGetUnoService failed" )
540 hDisableOOoImprovementProgramUNO() = FALSE
542 oUnoConfigurationAccess = oUnoOfficeConnection.createInstance("com.sun.star.configuration.ConfigurationProvider")
543 xViewRoot = oUnoConfigurationAccess.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess",aPropertyValue())
544 xViewRoot.replaceByName( "ShowedInvitation", TRUE )
545 xViewRoot.replaceByName( "InvitationAccepted", FALSE )
546 xViewRoot.commitChanges()
547 hDisableOOoImprovementProgramUNO() = TRUE
548 if ( xViewRoot.hasPendingChanges() ) then
549 hDisableOOoImprovementProgramUNO() = FALSE