'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 : tools for the property-browser test
' **
'\******************************************************************************
function hShowMacroControls() as boolean
'///
Tear off the ToolsCollectionBar from the MacroBar
'///Starting point: Basic dialog editor is open and has the focus
'///
const CFN = "hShowMacroControls::"
const MAX_WAIT = 5
const SHORT_WAIT = 1
const VERTICALLY_CENTERED = 50
const HORIZONTALLY_CENTERED = 50
if ( GVERBOSE ) then printlog( CFN & "Enter" )
'///+- Test whether the ToolsCollectionBar is already open. If yes, exit directly
kontext "ToolsCollectionBar"
if ( ToolsCollectionBar.exists( SHORT_WAIT ) ) then
printlog( CFN & "ToolsCollectionBar is already open." )
hShowMacroControls() = true
exit function
endif
'///+- Verify that the Dialog Bar is available
Kontext "DialogBar"
if ( DialogBar.exists( MAX_WAIT ) ) then
'///+- Verify that the controls-button is enabled
try
'///+- Click on the controls-button to open the ToolsCollectionBar
controls.click()
'///+- Tear off the ToolsCollectionBar from the DialogBar
controls.tearOff()
'///+- Verify that the ToolsCollectionBar is visible and can be accessed
kontext "ToolsCollectionBar"
if ( ToolsCollectionBar.exists( MAX_WAIT ) ) then
'///+- Move it to the upper left corner at pos 50/50
ToolsCollectionBar.Move ( HORIZONTALLY_CENTERED , VERTICALLY_CENTERED )
printlog( CFN & "ToolsCollectionBar is open and has been placed" )
hShowMacroControls() = true
else
printlog( CFN & "ToolsCollectionBar is not available. Aborting." )
hShowMacroControls() = false
endif
catch
printlog( CFN & "The Controls-Button is not enabled. Aborting." )
hShowMacroControls() = false
endcatch
else
printlog( CFN & "The Dialog Bar is not available. Aborting." )
hShowMacroControls() = false
endif
'///
end function
'*******************************************************************************
function hGetBasicWorkFile( cMajorID as string ) as string
'///Retrieve a filename, depending on gApplication and Build-ID
'///Structure: work-directory/basic[.suffix]
const CFN = "hGetBasicWorkFile::"
dim sFile as string : sFile = hGetWorkPath() & "basic" & hGetSuffix( cMajorId )
printlog( CFN & sFile & " for " & gApplication & " (" & cMajorID & ")" )
hGetBasicWorkFile() = sFile
end function
'*******************************************************************************
function hOpenBasicIDE() as boolean
'///Open the Basic IDE for the last module listed in the Macro Organizer
'///Starting point: Basic Macro Organizer has focus
const CFN = "hOpenBasicIDE::"
const BUTTON_TIMEOUT = -1
const MAX_WAIT = 2
if ( hSelectTheLastModule( true ) ) then
if ( hClickButton( Bearbeiten) <> BUTTON_TIMEOUT ) then
kontext "BASICIDE"
if ( BasicIDE.exists( MAX_WAIT ) ) then
printlog( "Basic IDE is open" )
BasicIDE.maximize()
hOpenBasicIDE() = true
else
warnlog( CFN & "Failed to open BASIC IDE" )
hOpenBasicIDE() = false
endif
else
warnlog( CFN & "Edit button is not enabled, cannot open BASIC IDE"
hOpenBasicIDE() = false
endif
else
warnlog( CFN & "Unable to select the last module" )
hOpenBasicIDE() = false
endif
end function
'*******************************************************************************
function hCloseBasicIDE() as boolean
'///Close the BASIC-IDE
hCloseCollectionBar()
kontext "BasicIDE"
hCloseBasicIDE() = hDestroyDocument()
end function
'*******************************************************************************
function hReOpenBasicDialog() as boolean
'///Open BASIC-IDE after loading a workfile with documentbound macro
'///Starting point: Focus on document containing at least one macro
const CFN = "hReopenBasicDialog: "
const BUTTON_TIMEOUT = -1
if ( hSelectTheLastModule( true ) ) then
if ( hClickButton( Bearbeiten ) <> BUTTON_TIMEOUT ) then
kontext "BasicIDE"
BasicIde.maximize()
if ( hFindFirstDialog() ) then
printlog( "BASIC IDE is open." )
hReOpenBasicDialog() = true
else
warnlog( CFN & "Could not find any dialog" )
hReOpenBasicDialog() = false
endif
else
warnlog( CFN & "Unable to click Edit button, BASIC IDE not open" )
hReOpenBasicDialog() = false
endif
else
warnlog( CFN & "Could not open the last module for editing." )
hReOpenBasicDialog() = false
endif
end function
'*******************************************************************************
function hFindFirstDialog() as boolean
'///Find the first dialog in the BASIC-IDE
'///Starting point: Basic IDE must be open and has the focus
'///
const CFN = "hFindFirstDialog::"
const REPEAT_COUNT = 5 ' number of times to send a keystroke to BASIC IDE
const MAX_NUMBER_OF_RETRIES = 20
const SELECT_TAB_RIGHT = ""
const SCROLL_UP_LEFT = ""
dim iPosOverTabbar as integer
hFindFirstDialog() = false
'///+- Set focus to Basic IDE, maximize it
kontext "BasicIDE"
BasicIde.maximize()
'///+- move pointer over the tabbar and click until a dialog opens (hopefully)
for iPosOverTabbar = 1 to MAX_NUMBER_OF_RETRIES
BASICIDE.typeKeys( SELECT_TAB_RIGHT )
if ( DialogWindow.Exists() ) then
printlog( "BASIC Dialog window found" )
hFindFirstDialog() = true
DialogWindow.typeKeys( SCROLL_UP_LEFT , REPEAT_COUNT )
exit for
endif
next iPosOverTabbar
'///
end function
'*******************************************************************************
function hSelectDialogPane() as boolean
'///Select the dialog pane in the Basic dialog editor
'///Starting point: Basic dialog editor is open and has the focus
const CFN = "hSelectDialogPane::"
const UP_LEFT = 10
const DOWN_RIGHT = 90
if ( GVERBOSE ) then printlog( CFN & "Enter" )
kontext "BasicIDE"
DialogWindow.mouseDown( DOWN_RIGHT , DOWN_RIGHT )
DialogWindow.mouseMove( UP_LEFT , UP_LEFT )
DialogWindow.mouseUp ( UP_LEFT , UP_LEFT )
printlog( CFN & "Selected dialog pane (not verified)" )
hSelectDialogPane() = true
end function
'*******************************************************************************
function hCloseCollectionBar() as boolean
const CFN = "hCloseCollectionBar(): "
kontext "ToolsCollectionBar"
if ( ToolsCollectionBar.exists() ) then
if ( hCloseDialog( ToolsCollectionBar, "close" ) ) then
printlog( "Closed Macro Controls Float" )
hCloseCollectionBar() = true
else
warnlog( CFN & "Failed to close Macro Controls Float" )
hCloseCollectionBar() = false
endif
else
printlog( "Macro Controls Float not open" )
hCloseCollectionBar() = true
endif
end function
'*******************************************************************************
function hDeleteMacro() as boolean
'///Delete all text in the Basic IDE editor
const CFN = "hDeleteMacro(): "
kontext "BasicIDE"
if ( BasicIDE.exists() ) then
WaitSlot() : Wait( 100 ) : EditWindow.typeKeys( "" )
WaitSlot() : Wait( 100 ) : EditWindow.typeKeys( "" )
WaitSlot() : Wait( 100 ) : EditWindow.typeKeys( "" )
hDeleteMacro() = hIsEditWindowEmpty()
else
warnlog( CFN & "Basic IDE is not open" )
hDeleteMacro() = false
endif
end function
'*******************************************************************************
function hIsEditWindowEmpty() as boolean
'///Test if the Basic-EditWindow is empty
'///Starting point: Basic IDE editor is open and has the focus
const CFN = "hIsEditWindowEmpty(): "
kontext "BasicIDE"
if ( BasicIDE.exists() ) then
SetClipboard( "" )
WaitSlot() : EditWindow.typeKeys( "" )
WaitSlot() : EditWindow.typeKeys( "" )
hUseAsyncSlot( "EditCopy" )
if ( GetClipBoardText() = "" ) then
hIsEditWindowEmpty() = true
else
warnlog( CFN & "Edit window is not empty" )
hIsEditWindowEmpty() = false
endif
else
warnlog( CFN & "BasicIDE is not open" )
hIsEditWindowEmpty() = false
endif
end function
'*******************************************************************************
function hRenameTab( cTabName as string ) as integer
const CFN = "hRenameTab(): "
const MENUITEM_RENAME = 3
const MAX_WAIT = 1000
const RETVAL_SUCCESS = 0
const RETVAL_NO_IDE = 1
const RETVAL_NO_ACCESS = 2
const RETVAL_NO_MENU = 3
dim sFullString as string : sFullString = "" & cTabName & ""
kontext "BasicIDE"
if ( BasicIDE.exists() ) then
try
hRenameTab() = RETVAL_NO_MENU
Tabbar.openContextMenu()
hMenuSelectNr( MENUITEM_RENAME )
Wait( MAX_WAIT )
' At this point the string on the tab should be selected, print the
' string to the log and overwrite it with the new name
hRenameTab() = RETVAL_NO_ACCESS
Tabbar.typeKeys( sFullString , true )
hRenameTab() = RETVAL_SUCCESS
catch
warnlog( CFN & "Failed to rename the current module" )
endcatch
else
warnlog( CFN & "BASIC IDE is not open" )
hRenameTab() = RETVAL_NO_IDE
endif
end function
'*******************************************************************************
function hGetTabNameFromOrganizer() as string
'///Retrieve the name of a tab from the Basic Library Organizer
'///Starting point: Basic IDE is open and has the focus
'///
const CFN = "hGetTabNameFromOrganizer::"
dim cReturnString as string
'///+- Open the Basic Library Organizer
'///+- Go to the Module-Tab
'///+- Get the name of the currently selected item from the Module-list
'///+- Close the Macro Library Organizer
if ( hOpenBasicObjectOrganizer( 1 ) ) then
cReturnString = Modulliste.GetSelText()
TabModule.Close()
printlog( CFN & "Returning Tab-Name: " & cReturnString )
else
cReturnString = "Failure: Macro Organizer not open"
warnlog( CFN & cReturnString )
endif
'///+- Return the name from the Module-list
hGetTabNameFromOrganizer() = cReturnString
'///
end function
'*******************************************************************************
function hNewDialog() as boolean
'///Create a new BASIC dialog
'///Starting point: Basic IDE is open
'///
const CFN = "hNewDialog::"
const MAX_WAIT = 2000
'///+- Open the context menu for the tabbar
kontext "basicide"
Tabbar.OpenContextMenu
'///+- Select the first item (insert)
hMenuSelectNr( 1 )
WaitSlot( MAX_WAIT ) ' sleep( 1 )
'///+- Select the second item (new dialog)
hMenuSelectNr( 2 )
WaitSlot( MAX_WAIT ) ' sleep( 2 )
'///+- Verify that a new dialog is opened and has the focus
if ( DialogWindow.Exists() ) then
printlog( CFN & "New dialog is open" )
hNewDialog() = true
if ( DialogWindow.IsMax() = false ) then
DialogWindow.Maximize()
Wait( MAX_WAIT )
end if
else
warnlog( CFN & "New dialog is not open" )
hNewDialog() = false
endif
'///+- Return TRUE on success, FALSE on failure
'///
end function
'*******************************************************************************
function hNewModule() as boolean
'///Create a new BASIC module
'///Starting point: Basic IDE is open
'///
const CFN = "hNewModule::"
const MAX_WAIT = 2000
'///+- Open the context menu for the tabbar
kontext "basicide"
Tabbar.OpenContextMenu
'///+- Select the first item (insert)
hMenuSelectNr( 1 )
WaitSlot( MAX_WAIT ) ' sleep( 1 )
'///+- Select the first item (new module)
hMenuSelectNr( 1 )
WaitSlot( MAX_WAIT ) ' sleep( 2 )
'///+- Verify that a new module is opened and has the focus
if ( EditWindow.Exists() ) then
printlog( CFN & "New module is open" )
hNewModule() = true
else
warnlog( CFN & "New module is not open" )
hNewModule() = false
endif
'///+- Return TRUE on success, FALSE on failure
'///
end function
'*******************************************************************************
function hHideModule() as boolean
'///Hide a Basic Module from the IDE
'///Starting point: Basic IDE is open and has the focus
'///
const CFN = "hHideModule::"
const MENUENTRY_HIDE = 4
kontext "basicide"
'///+- Open the context menu of the tabbar
try
tabbar.openContextMenu
'///+- Select the fourth entry (Hide)
hMenuSelectNr( MENUENTRY_HIDE )
sleep( 1 )
hHideModule() = true
printlog( CFN & "Success" )
catch
hHideModule() = false
warnlog( CFN & "Failure" )
endcatch
'///+- Return TRUE on success, FALSE on any other condition (not verified)
'///
end function
'*******************************************************************************
function hInitFormControls( cModule as string ) as boolean
'///Get from a new document to the Macro Controls Float in one go
'///Starting point: Plain document
'///This function performs following steps:
'///
'///+- Open the Basic Organizer
'///+- Create a new module for the current document
'///+- Open a new basic dialog
'///+- Open the Macro controls float
'///
'///Description:
'///
const CFN = "hInitFormControls::"
hInitFormControls() = false
'///+- Create and edit a new module for the current document
if ( not hInitBasicIde( cModule ) ) then
warnlog( "Could not create new module" )
hCloseBasicIde()
exit function
endif
kontext "BasicIde"
BasicIde.maximize()
'///+- Create a new dialog.
if ( not hNewDialog() ) then
warnlog( "Could not create Basic-Dialog" )
hCloseBasicIde()
exit function
endif
'///+- Open the macro controls float.
if ( not hShowMacroControls() ) then
warnlog( CFN & "Could not tear off the macro controls float" )
hCloseBasicIde()
exit function
endif
'///+- Return TRUE if all went well, FALSE on any other error
hInitFormControls() = true
'///
'///NOTE: The function will try to cleanup after itself in case of failure
end function
'*******************************************************************************
function hInitBasicIde( cModule as string ) as boolean
'///Get from a new document to the Basic IDE in one go
'///Starting point: New, plain document
const CFN = "hInitBasicIde::"
ToolsMacro_uno
kontext "Makro"
if ( Makro.exists( 2 ) ) then
if ( hCreateModuleForDoc( cModule ) ) then
kontext "BasicIDE"
if ( BasicIDE.exists( 2 ) ) then
BasicIDE.maximize()
hInitBasicIde() = true
else
warnlog( CFN & "Failed to open BASIC IDE" )
hInitBasicIde() = false
endif
else
warnlog( CFN & "Failed to create a module for the current document" )
hInitBasicIde() = false
endif
else
warnlog( CFN & "Failed to open macro organizer" )
hInitBasicIde() = false
endif
end function
'*******************************************************************************
function hInsertMacro( _id as integer ) as boolean
'///Insert a macro into the Basic-IDE edit window by Index
'///Starting point: Basic IDE is open, has the focus
'///
const CFN = "hInsertMacro::"
kontext "basicide"
printlog( CFN & "This function is deprecated" )
'///+- Delete the content of the edit window
if ( not hDeleteMacro() ) then
warnlog( CFN & "Content of Basic-IDE was not deleted" )
hInsertMacro() = false
exit function
endif
'///+- Insert a macro by index (passed as function parameter)
select case _id
case 1 :
' this is a working macro that contains no errors
EditWindow.TypeKeys( "'# TTMacro1: This is a short testscript for automated testing!" )
EditWindow.TypeKeys( "sub main" )
EditWindow.TypeKeys( "print " & Chr (34) + "hallo" & Chr (34) )
EditWindow.TypeKeys( "" )
EditWindow.TypeKeys( "end sub" )
hInsertMacro() = true
printlog( CFN & "Inserted: " & _id )
case 2 :
EditWindow.TypeKeys( "'# TTMacro2: a second module for automated testing!" )
EditWindow.TypeKeys( "" )
hInsertMacro() = true
printlog( CFN & "Inserted: " & _id )
case 3 :
EditWindow.TypeKeys( "'# TTMacro3: Bring up a messagebox" )
EditWindow.TypeKeys( "sub main" )
EditWindow.TypeKeys( " msgbox " & Chr (34) + "TTMacro3" & Chr (34) )
EditWindow.TypeKeys( "" )
EditWindow.TypeKeys( "end sub" )
hInsertMacro() = true
printlog( CFN & "Inserted: " & _id )
end select
'///
end function
'*******************************************************************************
function hTestMacro( _id as integer ) as integer
'///Verify that the correct macro is visible in the IDE edit Window
'///Starting point: Basic IDE is open and has focus
'///
const CFN = "hTestMacro::"
qaerrorlog( CFN & "This function is deprecated, remove me!" )
kontext "basicide"
'///+- Copy the first line in the editwindow to clipboard
EditWindow.TypeKeys( "" )
EditWindow.TypeKeys( "" )
EditCopy
'///+- Compare the string to a unique substring for the macro
select case _id
case 1 :
if ( Instr ( GetClipboardText, "TTMacro1" ) <> 0 ) then
printlog( CFN & "The correct macro is displayed in the editwindow" )
htestMacro() = 1
exit function
endif
case 2 :
if ( Instr ( GetClipboardText, "TTMacro2" ) <> 0 ) then
printlog( CFN & "The correct macro is displayed in the editwindow" )
htestMacro() = 2
exit function
endif
case 3 :
if ( Instr ( GetClipboardText, "TTMacro3" ) <> 0 ) then
printlog( CFN & "The correct macro is displayed in the editwindow" )
htestMacro() = 3
exit function
endif
end select
hTestMacro() = 0
'///
end function
'*******************************************************************************
function hCreateBasicWorkFiles() as string
'///Create a macro, attach it to a file, save the file
'///Starting point: Any plain document or the backing window
'///
const CFN = "hCreateBasicWorkFiles::"
const CMACRO = "TestMacro"
dim sFile as string : sFile = hGetBasicWorkFile( "CURRENT" )
'///+- Open a new document
hCreateDocument()
'///+- Change the document (to save it)
printlog( CFN & hChangeDoc() )
'///+- Open Basic-Organizer, select the document and create a module
if ( not hInitBasicIde( CMACRO ) ) then
printlog( CFN & "Unable to create a module, aborting" )
hDestroyDocument()
hCreateBasicWorkFiles() = ""
exit function
endif
'///+- Insert a macro that triggers a messagebox
if ( not hInsertMacro( 3 ) ) then
printlog( CFN & "Unable to insert macro, aborting" )
hCloseBasicIde()
hDestroyDocument()
hCreateBasicWorkFiles() = ""
exit function
endif
'///+- Close the Basic-IDE
hCloseBasicIde()
'///+- Save the file without autoextension, overwrite existing
if ( not hFileSaveAsKill( sFile ) ) then
printlog( CFN & "Unknown error while saving the file. Resetting" )
ExitRestartTheOffice
hCreateBasicWorkFiles() = ""
exit function
endif
'///+- Close the document
hDestroyDocument()
'///
end function
'*******************************************************************************
function hIDESelectTabByIndex( iIndex as integer ) as string
'///Select a tab within the BASIC-IDE by index
'///The BASIC-IDE has to be open and has the focus. This function
'///+ selects the tab by sending CTRL+PAGEUP or CTRL+PAGEDOWN to the IDE using
'///+ the .typeKeys method. It is assumed that - when opening the IDE - the
'///+ first tab is active. When the specified index has been reached we
'///+ retrieve the name of the current tab by opening the context menu on the
'///+ tab and selecting "Rename". The name (which should be
'///+ highlighted by default) is then copied to the clipboard and returned
'///+ to the calling function.
'///Parameter(s):
'///
'///+- Index of the requested Tab (Integer)
'///
'///+- Index must not be negative
'///+- 0 does nothing (returning the name of the current tab)
'///+- Index must be ≤ present number of tabs
'///+- If Index > number of tabs, the last tab is selected
'///
'///
'///Returns:
'///
'///+- Name of the selected tab (string)
'///
'///+- Always evaluate the returnvalue
'///
'///
const CFN = "hIDESelectTabByIndex::"
printlog( CFN & "Enter with option: " & iIndex )
dim brc as boolean 'a multi purpose boolean returnvalue
dim cTabName as string
dim iCurrentTab as integer
'///Description:
'///
'///+- Set context to BASIC IDE
kontext "BasicIDE"
'///+- Retrieve the accelerator to switch tabs
'///+- Switch tabs
select case iIndex
case 1 :
for iTab = 1 to 20
BasicIDE.typeKeys( "" )
next iTab
case else:
for iTab = 1 to iIndex
BasicIDE.typeKeys( "" )
next iTab
end select
'///+- Select the Tabbar
Kontext "Tabbar"
'///+- Open the context menu
hUseMenu()
'///+- Select "Rename"
hSelectMenuNr( 3 )
'///+- Copy the selected string to the clipboard
hUseAsyncSlot( "EditCopy" )
'///+- Send ESC to the tabbar to deselect the tab
Kontext "Tabbar"
Tabbar.typeKeys( "" )
'///+- Copy the string from clipboard to a local variable
cTabName = getClipboardText
'///+- Print exit message, set return value
if ( GVERBOSE ) then printlog( CFN & "Exit with result: " & cTabName )
hIDESelectTabByIndex() = cTabName
'///
end function