'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 : misc functions to handle documents
'*
'\******************************************************************************
function hUseImpressAutopilot( bEnable as boolean ) as boolean
'///
Enable/disable the Impress Autopilot in Tools/Options
'///Starting point: Any plain document
'///
const CFN = "global::tools::includes::optional::t_docfuncs.inc::hUseImpressAutopilot::"
if ( GVERBOSE ) then printlog( CFN & "Enter" )
'///+- Create a new IMPRESS document
gApplication = "IMPRESS"
hCreateDocument()
'///+- Open Tools/Options, go to Presentataion/General page
ToolsOptions
hToolsOptions( gApplication , "General" )
'///+- Check or uncheck to start with autopilot
Kontext "TabSonstigesDraw"
if ( mitAutopilotStarten.exists( 2 ) ) then
if ( bEnable ) then
mitAutopilotStarten.check()
if ( GVERBOSE ) then printlog( CFN & "Enable Impress Autopilot" )
else
mitAutopilotStarten.uncheck()
if ( GVERBOSE ) then printlog( CFN & "Disable Impress Autopilot" )
endif
'///+- Return Status of Checkbox (checked=TRUE)
hUseImpressAutopilot() = mitAutopilotStarten.isChecked()
else
warnlog( CFN & "Cannot find Autopilot Checkbox" )
endif
'///+- Close Tools/Options
Kontext "OptionenDlg"
hCloseDialog( OptionenDlg, "ok" )
'///+- Close IMPRESS document
hDestroyDocument()
'///+- Returncode is undefined
if ( GVERBOSE ) then printlog( CFN & "Exit" )
'///
end function
'*******************************************************************************
function hNumericDocType( doctype as integer ) as string
'///Convert a numeric expression to a gApplication
'///BEWARE: This is a core function used by many testcases!
'///Using file: global/input/applications.txt as reference
'///
const CFN = "global::tools::includes::optional::t_docfuncs.inc::hNumericDocType::"
dim sFile as string
sFile = gTesttoolPath & "global\input\applications.txt"
sFile = convertpath( sFile )
dim sList( 100 ) as string
dim iDocTypes as integer
if ( GVERBOSE ) then printlog( CFN & "Enter" )
'///+- Retrieve matching list from file
hGetDataFileSection( sFile , sList() , "application" , "" , "" )
iDocTypes = val( sList( 0 ) )
'///+- Verify that the functionparameter (documenttype) is valid
if ( ( doctype < 0 ) or ( doctype > iDocTypes ) ) then
warnlog( CFN & "Undefined numeric doctype: " & doctype )
hNumericDocType() = ""
exit function
endif
'///+- Set gApplication to the requested document type
gApplication = hGetValueForKeyAsString( sList() , doctype )
'///+- Set a plain text name as returnvalue for the function
hGetDataFileSection( sFile , sList() , "application_names" , "" , "" )
hNumericDocType() = hGetValueForKeyAsString( sList() , gApplication )
if ( GVERBOSE ) then printlog( CFN & "Exit" )
'///
end function
'*******************************************************************************
function hChangeDoc() as string
'///Function to modify all documenttypes to set the "changed" flag
'///Starting point: Any plain document
'///Input:
'///
'///+- Nothing
'///
'///Returns:
'///
'///+- String, ready to use in printlog
'///
'///+- "Changed <Documenttype>"
'///
'///
'///Description:
'///
sleep()
select case gApplication
'///+- WRITER: Type some text
case "WRITER", "HTML", "MASTERDOCUMENT"
Kontext "DocumentWriter"
DocumentWriter.TypeKeys "This doc is changed!"
hChangeDoc() = "Changed WRITER/HTML/MASTERDOC"
'///+- CALC: Write some text into the current location (usually A1)
case "CALC" : Kontext "DocumentCalc"
DocumentCalc.TypeKeys "This doc is changed!"
hChangeDoc() = "Changed CALC"
'///+- DRAW: Draw a rectangle
case "DRAW" : Kontext "DocumentDraw"
hRechteckErstellen ( 20, 20, 25, 25 )
gMouseClick ( 1, 1 )
hChangeDoc() = "Changed DRAW"
'///+- IMPRESS: Draw a rectangle
case "IMPRESS": Kontext "DocumentImpress"
hRechteckErstellen ( 20, 20, 25, 25 )
gMouseClick ( 1, 1 )
hChangeDoc() = "Changed IMPRESS"
'///+- MATH: Create a simple formaula
case "MATH" : SchreibenInMathdok( "b over c" )
kontext "DocumentMath"
hChangeDoc() = "Changed MATH"
gMouseClick( 50 , 50 )
end select
'///
end function
'*******************************************************************************
function hIdentifyWriterDoc( cString as string, bWarn as boolean ) as boolean
'///Function to validate that the expected WRITER doc has the focus
'///Starting point: Any WRITER document containing some text
'///
use "global\tools\includes\optional\t_stringtools.inc"
const CFN = "global::tools::includes::optional::t_docfuncs.inc::hIdentifyWriterDoc::"
dim cIdentifier as string
dim irc as integer ' some temporary returnvalue
if ( GVERBOSE ) then printlog( CFN & "Enter" )
'///+- Test the function parameter
if ( cString = "" ) then
qaerrorlog( CFN & "Function parameter is empty string. Aborting" )
hIdentifyWriterDoc() = false
exit function
endif
'///+- Verify function prerequisites
kontext "DocumentWriter"
if ( not DocumentWriter.exists() ) then
printlog( CFN & "There is no Writer document. Aborting" )
hIdentifyWriterDoc() = false
exit function
endif
hIdentifyWriterDoc() = true
'///+- Go to the very beginning of the current writer document
kontext "DocumentWriter"
DocumentWriter.typeKeys( "" )
'///+- Select the entire line
DocumentWriter.typeKeys( "" )
'///+- copy the string to the clipboard and store it into a variable
hUseAsyncSlot( "EditCopy" )
cIdentifier = getClipboardText()
'///+- compare the string to the reference (given as parameter)
irc = hCompareSubstrings( cIdentifier, cString )
'///+- Write the result to the printlog if desired
if ( irc = 0 ) then
if ( GVERBOSE ) then printlog( CFN & "The focus is not on the expected document" )
if ( bWarn ) then warnlog ( CFN & "The focus is not on the expected document" )
printlog( CFN & "Expected: " & cString )
printlog( CFN & "Found...: " & cIdentifier )
hIdentifyWriterDoc() = false
else
printlog( CFN & "OK: The document contains the requested string" )
endif
'///+- Return TRUE only if the current document is the expected one
if ( GVERBOSE ) then printlog( CFN & "Exit" )
'///
end function
'*******************************************************************************
function hCreateDocument() as boolean
'///Create anew document, extends hNewDocument() by providing a returnvalue
' TRUE = New document created, FALSE = Failed to create a new document '
const CFN = "global::tools::includes::optional::t_docfuncs.inc::hCreateDocument::"
dim iDocCountBefore as integer
dim iDocCountAfter as integer
iDocCountBefore = getDocumentCount
if ( GVERBOSE ) then printlog( CFN & "Number of open documents before: " & iDocCountBefore )
if ( gApplication = "BACKGROUND" ) then
hFileCloseAll()
hCreateDocument() = true
else
call hNewDocument()
iDocCountAfter = getDocumentCount()
if ( iDocCountAfter = ( iDocCountBefore + 1 ) ) then
hCreateDocument() = true
else
hCreateDocument() = false
endif
endif
if ( GVERBOSE ) then printlog( CFN & "New document created. Open: " & iDocCountAfter )
'///
end function
'*******************************************************************************
function hDocumentTypeKeys( cString as string ) as boolean
'///Type a string to a document
'///The documenttype is determined by gApplication.
'///See hNumericDocType for details and number/gApplication matching
'///Input:
'///
'///+- Keystrokes to be sent to the document (string), e.g.
'///
'///+- "<SHIFT HOME>"
'///+- "<MOD1 A>"
'///+- "<MOD2 Q>"
'///+- "Hello"
'///
'///
'///Returns:
'///
'///+- Errorstatus (boolean)
'///
'///+- TRUE if all went well
'///+- FALSE on any error
'///
'///
'///Description:
'///
const CFN = "global::tools::includes::optional::t_docfuncs.inc::hDocumentTypeKeys::"
if ( GVERBOSE ) then printlog( CFN & "Enter" )
hDocumentTypeKeys() = true
'///+- Set focus to the current documenttype determined by gApplication
'///+- Type the string passed as function parameter
select case gApplication
case "WRITER" : kontext "DocumentWriter"
DocumentWriter.typeKeys( cString )
case "CALC" : kontext "DocumentCalc"
DocumentCalc.typeKeys( cString )
case "IMPRESS" : kontext "DocumentImpress"
DocumentImpress.typeKeys( cString )
case "DRAW" : kontext "DocumentDraw"
DocumentDraw.typeKeys( cString )
case "MATH" : kontext "DocumentMath"
DocumentMath.typeKeys( cString )
case "MASTERDOCUMENT": kontext "DocumentWriter"
DocumentWriter.typeKeys( cString )
case "HTML" : kontext "DocumentWriter"
DocumentWriter.typeKeys( cString )
case else
warnlog( CFN & "Exit: Unknown gApplication: " & gApplication )
hDocumentTypeKeys() = false
exit function
end select
'///+- Print some message to the log on success
printlog( CFN & "Exit: Sent keystroke to " & gApplication )
'///
end function
'*******************************************************************************
function hDestroyDocument() as boolean
const CFN = "global::tools::includes::optional::t_docfuncs.inc::hDestroyDocument: "
dim iDocCount as integer : iDocCount = getDocumentCount()
hDestroyDocument() = false
dim method( 3 ) as string
method( 1 ) = "no,optional"
method( 2 ) = "202,optional"
method( 3 ) = "ok,optional" ' This could be a File I/O error
dim iCurrentMethod as integer
dim bDialogClosed as boolean
if ( iDocCount = 0 ) then exit function
if ( GVERBOSE ) then printlog( CFN & "In.: Open: " & iDocCount )
hUseAsyncSlot( "FileClose" )
for iCurrentMethod = 1 to 3
bDialogClosed = false
Kontext "Active"
if ( Active.exists( 1 ) ) then
printlog( CFN & "Msgbox: " & Active.getText() )
if ( GVERBOSE ) then printlog( CFN & "Method: " & method( iCurrentMethod ) )
bDialogClosed = hCloseDialog( Active, method( iCurrentMethod ) )
else
exit for
endif
if ( iCurrentMethod = 3 and bDialogClosed ) then
warnlog( "Unexpected messagebox was handled" )
endif
next iCurrentMethod
if ( getDocumentCount() = iDocCount ) then hCloseDocument()
if ( getDocumentCount() = iDocCount - 1 ) then hDestroyDocument() = true
if ( GVERBOSE ) then printlog( CFN & "Out: Open: " & getDocumentCount() )
end function
'*******************************************************************************
function hInitSingleDoc() as boolean
hFileCloseAll()
hCreateDocument()
if ( GVERBOSE ) then printlog( "hInitSingleDoc(): Opening document: " & gApplication )
if ( getDocumentCount = 1 ) then
hInitSingleDoc() = true
else
hInitSingleDoc() = false
endif
end function
'*******************************************************************************'*******************************************************************************
function hInitWriteDocIdentifier( cString as string ) as boolean
'///Write a specific string to an open writer document
'///This function verifies that exactly one document is open, that this is a
'///+ Writer document and writes the string to the document
'///Parameter(s):
'///
'///+- A free form string (String) which serves as identifier for the document
'///
'///+- The first character should be uppercase
'///
'///
'///Returns:
'///
'///+- Errorcondition (Boolean)
'///
'///+- TRUE: The string was written correctly
'///+- FALSE: Too many open documents
'///+- FALSE: Not a Writer document
'///+- FALSE: Any other error
'///
'///
const CFN = "global::tools::includes::optional::t_docfuncs.inc::hInitWriteDocIdentifier::"
const RC_TIMEOUT = -1
if ( getDocumentCount = 1 and gApplication = "WRITER" ) then
kontext "DocumentWriter"
DocumentWriter.typeKeys( "" )
DocumentWriter.typeKeys( "" )
DocumentWriter.typeKeys( "" )
DocumentWriter.typekeys( cString )
DocumentWriter.typeKeys( "" )
DocumentWriter.typeKeys( "" )
if ( hUseAsyncSlot( "EditCopy" ) <> RC_TIMEOUT ) then
if ( getClipboardText = cString ) then
printlog( CFN & "Writer document has been successfully modified." )
hInitWriteDocIdentifier() = true
else
warnlog( CFN & "Could not verify document identification string" )
hInitWriteDocIdentifier() = false
endif
else
warnlog( CFN & "Unable to copy text to clipboard using " )
hInitWriteDocIdentifier() = false
endif
else
warnlog ( CFN & "Only one single writer document may be open" )
printlog( CFN & "Number of documents: " & getDocumentCount )
printlog( CFN & "Application........: " & gApplication )
hInitWriteDocIdentifier() = false
endif
end function