'encoding UTF-8 Do not remove or change this line!
'**************************************************************
'
' Licensed to the Apache Software Foundation (ASF) under one
' or more contributor license agreements. See the NOTICE file
' distributed with this work for additional information
' regarding copyright ownership. The ASF licenses this file
' to you under the Apache License, Version 2.0 (the
' "License"); you may not use this file except in compliance
' with the License. You may obtain a copy of the License at
'
' http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing,
' software distributed under the License is distributed on an
' "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
' KIND, either express or implied. See the License for the
' specific language governing permissions and limitations
' under the License.
'
'**************************************************************
'*
'* short description : Test scripting-organizers / document-attached scripts
'*
'\******************************************************************************
function hCreateScriptingObject( cName as string ) as boolean
'///
Create a new scripting object for the current module
'///Starting point: Script organizer is open, module selected
'///Input:
'///
'///+- Name of the module (string)
'///
'///+- Any name the organizer can accept
'///
'///
'///Returns:
'///
'///+- Errorcondition
'///
'///+- TRUE on success
'///+- FALSE on failure or invalid user input
'///
'///
'///Description:
'///
const CFN = "hNewScriptingObject::"
'///+- Verify that the "Create..." button is enabled
if ( PBCreate.isEnabled() ) then
'///+- Click "Create..." to open the naming dialog
hClickButton( PBCreate )
'///+- Name the new script
Kontext "ScriptNameDlg"
if ( ScriptNameDlg.exists( 2 ) ) then
EFObjectName.setText( cName )
ScriptNameDlg.OK()
hCreateScriptingObject() = true
endif
else
printlog( CFN & "Button is disabled" )
hCreateScriptingObject() = false
endif
'///+- Verify that we are back on the script organizer
kontext "ScriptOrganizer"
if ( not ScriptOrganizer.exists( 2 ) ) then
warnlog( CFN & "Could not return to ScriptOrganizer" )
hCreateScriptingObject() = false
endif
'///
end function
'*******************************************************************************
function hRenameScriptingObject( cName as string ) as boolean
'///Rename the selected script
'///Starting point: Script organizer is open, a script is selected
'///Input:
'///
'///+- New name of the script
'///
'///+- Any name the script organizer does accept
'///
'///
'///Returns:
'///
'///+- Errorcondition
'///
'///+- TRUE on success
'///+- FALSE on failure or invalid user input
'///
'///
'///Description:
'///
const CFN = "hRenameScriptingObject::"
hRenameScriptingObject() = true
'///+- Click "Rename..." to open the renaming dialog
hClickButton( PBRename )
'///+- Name the new script
Kontext "ScriptNameDlg"
if ( ScriptNameDlg.exists( 2 ) ) then
EFObjectName.setText( cName )
hCloseDialog( ScriptNameDlg, "ok" )
'///+- Test for any messagebox, try to close it with OK
kontext "active"
if ( active.exists( 1 ) ) then
printlog( CFN & active.getText() )
hRenameScriptingObject() = false
active.OK()
endif
endif
'///+- Verify that we are back on the script organizer
kontext "ScriptOrganizer"
if ( not ScriptOrganizer.exists( 2 ) ) then
warnlog( CFN & "Could not return to ScriptOrganizer" )
hRenameScriptingObject() = false
endif
'///
end function
'*******************************************************************************
function hDeleteScript( cName as string , bSuccess as boolean ) as boolean
'///Delete the selected script
'///Starting point: Script organizer is open, a script is selected
'///Input:
'///
'///+- Name of the script (string)
'///
'///+- For debugging purpose only, the name will be used for warnlogs
'///+- May be an empty string (not recommended)
'///
'///+- Expected result (boolean)
'///
'///+- TRUE: The script is expected to be deleted without warnings/errors
'///+- FALSE: The script should not be deletable
'///
'///
'///Returns:
'///
'///+- Errorcondition (boolean) - see description
'///
'///+- TRUE on success (expected outcome)
'///+- FALSE on failure
'///
'///
'///Description:
'///
const CFN = "hDeleteScript::"
'///+- Test for the possible conditions:
'///
'///+- Delete is correctly enabled (success)
kontext "ScriptOrganizer"
if ( PBDelete.isEnabled() and bSuccess ) then
hClickButton( PBDelete )
kontext "active"
if ( Active.exists( 1 ) ) then
printlog( CFN & active.getText() )
active.yes()
endif
kontext "active"
if ( active.exists( 1 ) ) then
qaerrorlog( CFN & "Message: Failed to delete object: " & cName )
printlog( CFN & active.getText() )
active.ok()
endif
hDeleteScript() = true
'///+- Delete is disabled correctly (success)
elseif ( ( not PBDelete.isEnabled() ) and ( not bSuccess ) ) then
printlog( CFN & "Delete-Button disabled for non-deletable object: " & cName )
hDeleteScript() = true
'///+- Delete is enabled but should not be (failure)
elseif ( PBDelete.isEnabled() and ( not bSuccess ) ) then
hClickButton( PBDelete )
kontext "active"
if ( active.exists( 1 ) ) then
printlog( CFN & "Delete-Button enabled for non deletable object" )
printlog( CFN & active.getText() )
active.yes()
endif
kontext "active"
if ( active.exists( 2 ) ) then
printlog( CFN & "Message: Failed to delete object" )
printlog( CFN & active.getText() )
active.ok()
endif
hDeleteScript() = false
'///+- Delete is incorrectly disabled (failure)
elseif ( ( not PBDelete.isEnabled() ) and bSuccess ) then
printlog( CFN & "Delete-Button disabled for deletable object" )
hDeleteScript() = false
else
warnlog( CFN & "Unknown condition in if-statement" )
hDeleteScript() = false
endif
'///
'///
end function
'*******************************************************************************
function hOpenScriptOrganizer( iDialog as integer ) as boolean
'///Open the ScriptOrganizers and verify that they are open
'///Starting point: Any document
'///Input:
'///
'///+- Dialog-ID (integer)
'///
'///+- 1 = BeanShell organizer
'///+- 2 = JavaScript organizer
'///+- 3 = Python script organizer
'///
'///
'///Returns:
'///
'///+- Errorcondition
'///
'///+- TRUE if the expected organizer is open
'///+- FALSE if the expected organizer is not open
'///
'///
'///Description:
'///
const CFN = "hOpenScriptOrganizer::"
'///- Call the associated slot
select case iDialog
case 1 : ToolsMacrosOrganizeMacrosBeanShell
case 2 : ToolsMacrosOrganizeMacrosJavaScript
case 3 : ToolsMacrosOrganizeMacrosPython
end select
'///- Verify that the dialog is open, return TRUE if yes
kontext "ScriptOrganizer"
if ( ScriptOrganizer.exists( 5 ) ) then
hOpenScriptOrganizer() = true
printlog( "Script Organizer is open" )
else
hOpenScriptOrganizer() = false
warnlog( CFN & "Slot failed, dialog not open" )
endif
'///
end function