'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 : check the internal file dialog ( extended tests )
'*
'\******************************************************************************
function hSaveLoadDelSuccess( cFile as string ) as integer
'///
Successfully save, close, load, close and delete a file
'///Uses: framework\tools\t_stringtools.inc
'///Input:
'///
'///+- Filename incl. extension (string)
'///
'///Returns:
'///
'///+- Errorcode (integer)
'///
'///+- 0 = all ok
'///+- 1 = Saving failed
'///+- 2 = Closing the file failed
'///+- 3 = Reloading failed
'///+- 4 = Closing the file failed
'///+- 5 = Deleting failed
'///+- -1 = Post operation error
'///
'///
'///Description:
'///
dim brc as boolean
dim cFileExt as string : cFileExt = cFile & hGetSuffix( "current" )
const CFN = "hSaveLoadDelSuccess::"
printlog( "" )
printlog( CFN & "Enter with option: " & cFile & "/" & cFileExt )
'///+- Close the navigator if it exists
kontext "Navigator"
hCloseDialog( Navigator, "close,optional" )
'///+- Save the current file, overwriting existing
brc = hSaveFileExpectSuccess( cFile , TRUE ) ' save and overwrite
if ( brc ) then
'///+- Close the file
brc = hDestroyDocument()
if ( brc ) then
'///+- Reload the file
brc = hLoadFileExpectSuccess( cFileExt )
if ( brc ) then
'///+- Close the document
brc = hDestroyDocument()
if ( brc ) then
'///+- Delete the file via FileOpen
brc = hDeleteFileViaFileOpen( cFileExt )
if ( brc ) then
printlog( CFN & "Save, close, load, close, delete ok" )
hSaveLoadDelSuccess() = 0
else
warnlog( CFN & "Failed to delete file" )
hSaveLoadDelSuccess() = 5
endif
else
warnlog( CFN & "Failed to close file" )
hSaveLoadDelSuccess() = 4
endif
else
warnlog( CFN & "Failed to load file" )
hSaveLoadDelSuccess() = 3
endif
else
warnlog( CFN & "Closing file failed" )
hSaveLoadDelSuccess() = 2
endif
else
warnlog( CFN & "Saving failed" )
hSaveLoadDelSuccess() = 1
endif
'///+- Close possible Messagebox (#i33946#)
kontext "active"
if ( active.exists( 1 ) ) then
printlog( CFN & "Unexpected message: " & active.getText() )
qaerrorlog( "#i33946# - message when deleting last document in folder" )
active.ok()
hSaveLoadDelSuccess() = 6
endif
'///+- Close document
brc = hDestroyDocument()
'///
end function
'*******************************************************************************
function hLoadFileExpectSuccess( fpath as string ) as boolean
'///Load a file where failure is expected
'///Uses: framework\tools\t_stringtools.inc
'///This function is quite similar to hLoadFile but does much less
'///+ errorhandling so the information of the type of failure is a little
'///+ more exact
'///Input:
'///
'///+- Filename incl. extension (string)
'///
'///Returns:
'///
'///+- Errorcondition (boolean)
'///
'///+- TRUE = File was loaded without problems
'///+- FALSE = Any error
'///
'///
'///Description:
'///
dim brc as boolean : brc = true
const CFN = "hLoadFileExpectSuccess::"
printlog( CFN & "Enter with option: " & fpath )
'///+- Click FileOpen (or use the menu)
hUseAsyncSlot( "FileOpen" )
'///+- Enter the filename (with extension)
'printlog( " - Type the filepath/name into the entryfield" )
Kontext "OeffnenDLG"
if ( OeffnenDlg.exists( 1 ) ) then
DateiName.setText( fpath )
'///+- Click "Open"
'printlog( " - Click 'Open'" )
oeffnen.click()
'///+- Watch out for an unexpected messagebox
Kontext "Active"
if ( Active.Exists( 1 ) ) then
printlog( "Unexpected active: " & active.getText() )
Active.OK()
Kontext "OeffnenDLG"
OeffnenDLG.cancel()
brc = false
endif
'///+recover in case of error so the test has a chance to continue
' try to recover in case of failure so the test can continue.
Kontext "OeffnenDLG"
if ( Oeffnen.exists( 1 ) ) then
warnlog( "The file was not opened, it doesn't appear to exist" )
OeffnenDLG.cancel()
brc = false
endif
else
warnlog( CFN & "File Open dialog did not open" )
endif
'///+- Return the errorcode
printlog( CFN & "Exit with result: " & brc )
hLoadFileExpectSuccess() = brc
'///
end function
'*******************************************************************************
function hSaveFileExpectSuccess( fpath as string , bReplace as boolean ) as boolean
'///Save a file with optional replace where success is expected
'///Uses: framework\tools\t_stringtools.inc
'///Input:
'///
'///+- Filename incl. extension (string)
'///+- Replace file (boolean)
'///
'///+- TRUE = Replace the file
'///+- FALSE = Do not replace the file
'///
'///
'///Returns:
'///
'///+- Errorcondition (boolean)
'///
'///+- TRUE = There was an error loading the file (as expected)
'///+- FALSE = The file was loaded without problems/any other error
'///
'///
'///Description:
'///
const CFN = "hSaveFileExpectSuccess::"
dim brc as boolean : brc = true
dim iDocumentCount as integer
printlog( CFN & "Enter with options: " & fpath & ", " & bReplace )
'///+- Make sure we start from the backing window
hFileCloseAll()
'///+- Open a new document
hCreateDocument()
'///+- Click "Save As..."
hUseAsyncSlot( "FileSaveAs" )
Kontext "SpeichernDlg"
if ( SpeichernDlg.exists( 1 ) ) then
'///+- Enter a filename (with extension)
Dateiname.setText( hGetWorkPath() & fpath )
'///+- Click "Save"
speichern.click()
'///+- If the file exists, say "yes" to replace it
if ( bReplace ) then
Kontext "Active"
if ( active.exists( 2 ) ) then
printlog( CFN & "Overwriting file" )
printlog( "Message: " & active.getText() )
try
active.yes()
catch
warnlog( CFN & "Unexpected active - no YES button available." )
printlog( CFN & "if any this should have been overwrite warning." )
endcatch
endif
endif
'///+- Handle any unexpected errormessage with "OK"
Kontext "Active"
if ( active.exists( 2 ) ) then
printlog( CFN & "Unexpected active: " & active.getText() )
brc = false
active.ok()
endif
'///+- The FileSave dialog should be closed at this point
kontext "SpeichernDlg"
if ( SpeichernDlg.exists( 1 ) ) then
warnlog( CFN & "File Save dialog is still open, it should be closed" )
SpeichernDlg.cancel()
endif
else
warnlog( CFN & "Failed to open File Open dialog" )
brc = false
endif
'///+- Verify that exactly one document is open
if( getDocumentCount <> 1 ) then
warnlog( CFN & "Incorrect number of open documents" )
brc = false
endif
printlog( CFN & "Exit with result: " & brc )
hSaveFileExpectSuccess() = brc
'///
end function
'*******************************************************************************
function hSaveFileExpectFailure( fpath as string , errortype as integer ) as boolean
'///Save a file where failure is expected
'///Uses: framework\tools\t_stringtools.inc
'///Input:
'///
'///+- Filename incl. extension (string)
'///+- Errortype (Integer). Valid options are:
'///
'///+- 0 = Invalid characters in string
'///+- 1 = Filename is interpreted as device
'///
'///
'///Returns:
'///
'///+- Errorcondition (boolean)
'///
'///+- TRUE = There was an error saving the file (as expected)
'///+- FALSE = The file was saved without problems/any other error
'///
'///
'///Description:
'///
' currently we have two different kinds of failure
' 1. File cannot be saved due to invalid character(s)
' This is errortype = 0
' 2. File cannot be saved because the given name is interpreted as device
' This is errortype = 1
' This sequence tries to save a document with an invalid name. The errormsg
' is closed, the filedialog cancelled and the file closed.
dim brc as boolean : brc = false
dim cMsg as string
const CFN = "hSaveFileExpectFailure::"
'///+- Open an new document
hCreateDocument()
'///+- Click "Save As;"
printlog( "" )
printlog( CFN & "Enter with options: " & fpath & ", " & errortype )
hUseAsyncSlot( "FileSaveAs" )
'///+- Enter the filename
kontext "SpeichernDlg"
if ( SpeichernDlg.exists( 1 ) ) then
Kontext "SpeichernDlg"
Dateiname.setText( fpath )
'///+- Click "Save"
speichern.click()
'///
'///+- Handle invalid characters (Errormessages)
select case( errortype )
case 0:
brc = false
Kontext "Active"
if ( Active.exists( 1 ) ) then
printlog( CFN & "Check for possible overwrite warning..." )
try
Active.yes()
printlog( CFN & "Closed Messagebox with " )
printlog( CFN & "This was the overwrite warning" )
catch
endcatch
endif
Kontext "Active"
if ( Active.exists( 1 ) ) then
cMsg = active.getText()
try
Active.ok()
printlog( CFN & "Closed Save-Failure warning with " )
brc = true
catch
qaerrorlog( CFN & "Unknown dialog encountered, failed:" )
printlog( cMSG )
endcatch
endif
case 1:
Kontext "Active"
if ( Active.exists( 1 ) ) then
printlog( CFN & "Expected active: " & active.getText() )
Active.OK()
Kontext "SpeichernDLG"
if ( SpeichernDlg.exists( 1 ) ) then
SpeichernDLG.cancel()
brc = true
else
warnlog( CFN & "File Save dialog is missing. Bad!" )
brc = false
endif
else
warnlog( CFN & "Errormessage for '/', '\' or ':' is missing" )
brc = false
endif
end select
else
warnlog( CFN & "Failed to open File Save dialog" )
endif
'///
'///+- Close the document
hDestroyDocument()
'///+- Return errorcondition
printlog( CFN & "Exit with status: " & brc )
hSaveFileExpectFailure() = brc
'///
end function
'*******************************************************************************
function hDeleteFileViaFileOpen( cFile as String ) as boolean
'///Delete a file using the File Open dialog
'///Uses: framework\tools\t_stringtools.inc
'///Input:
'///
'///+- Filename incl. extension (string)
'///
'///Returns:
'///
'///+- Errorcondition (boolean)
'///
'///+- TRUE = File was deleted
'///+- FALSE = Any other condition
'///
'///
'///Description:
'///
' This sub deletes a file by name. No errors or warnings are expected.
' if everything goes well, we're back to the originating document after
' completion.
dim iSelectedFilePosition as integer
dim brc as boolean
const CFN = "hDeleteFileViaFileOpen::"
printlog( CFN & "Enter with option: " & cFile )
' Test for wildcards - the dialog cannot handle those
if ( instr( cFile , "?" ) <> 0 ) then
warnlog( CFN & "Incorrect call to function, wildcards are not allowed" )
hDeleteFileViaFileOpen() = false
exit function
endif
' Test for wildcards - the dialog cannot handle those
if ( instr( cFile , "*" ) <> 0 ) then
warnlog( CFN & "Incorrect call to function, wildcards are not allowed" )
hDeleteFileViaFileOpen() = false
exit function
endif
'///+- Click "File Open"
hUseAsyncSlot( "FileOpen" )
'///+- Look for the requested file, get the position from the filelist
Kontext "OeffnenDLG"
iSelectedFilePosition = hFindFileObjectViaFileOpen( cFile )
'///+- If the file exists, delete it + verify, if not: Warn and exit
if ( iSelectedFilePosition > 0 ) then
' Enable for debug
'printlog( CFN & "Requested file: " & cFile )
'printlog( CFN & "Object is at..: " & iSelectedFilePosition )
'printlog( CFN & "Object name is: " & DateiAuswahl.getSelText() )
DateiAuswahl.TypeKeys( "" )
' Confirm deletion. This dialog should always pop up when deleting
Kontext "ConfirmDelete"
if ( ConfirmDelete.exists( 1 ) ) then
Delete.click()
printlog( CFN & "Deleted file: " & cFile )
else
warnlog( CFN & "Messagebox to confirm deletion of file is missing" )
endif
' Handle possible Warnings/Errormessages. If no errors happen,
' verify that the file has been deleted. Note that this dialog will not
' change the returnvalue.
Kontext "Active"
if( Active.exists( 1 ) ) then
warnlog( CFN & "Unexpected active: " & active.getText() )
Active.OK()
endif
' Verify that the file does no longer exist in the filelist.
iSelectedFilePosition = hFindFileObjectViaFileOpen( cFile )
if ( iSelectedFilePosition = 0 ) then
brc = true
else
brc = false
endif
else
brc = false
warnlog( CFN & "File not found in workdir: " & cFile )
endif
'///+- Cancel the FileOpen dialog
kontext "OeffnenDlg"
OeffnenDlg.cancel()
'///+- Return errorcondition
printlog( CFN & "Exit with result: " & brc )
hDeleteFileViaFileOpen() = brc
'///
end function
'*******************************************************************************
function hNameGen_append( iDecChar as long ) as string
'///Create a filename with specified character at the end
'///Input:
'///
'///+- Character as number (integer)
'///
'///+- Only positive numbers are allowed
'///+- Respect integer boundaries
'///
'///
'///Returns:
'///
'///+- A filename containing a special character at the end (before suffix)
'///
'///Description:
'///
dim cFile as string
const CFN = "hNameGen_append::"
'///+- Create a string "test", append ascii char
cFile = "test" & CHR$( iDecChar )
printlog( CFN & "ASCII " & iDecChar & " appended, len = " & len( cFile ) )
if ( len( cFile ) <> 5 ) then
warnlog( CFN & "Character not appended" )
endif
'///+- Return the new filename
hNameGen_append() = cFile
'///
end function
'*******************************************************************************
function hNameGen_lead( iDecChar as long ) as string
'///Create a filename with specified character at the beginning
'///Input:
'///
'///+- Character as number (integer)
'///
'///+- Only positive numbers are allowed
'///+- Respect integer boundaries
'///
'///
'///Returns:
'///
'///+- A filename containing a special character at the beginning
'///
'///Description:
'///
dim cFile as string
const CFN = "hNameGen_lead::"
'///+- Create a string beginning with ascii char and append "test"
cFile = CHR$( iDecChar ) & "test"
printlog( CFN & "ASCII " & iDecChar & " prepended, len = " & len( cFile ) )
if ( len( cFile ) <> 5 ) then
warnlog( CFN & "Character not prepended" )
endif
'///+- Return the new filename
hNamegen_lead() = cFile
'///
end function
'*******************************************************************************
function hFindFileObjectViaFileOpen( cName as string ) as integer
'///Get the position of a filesystem object in filelist of fileopen dialog
'///Note that the filepicker must be open in order to use this function.
'///The object with the given name is selected when leaving the function.
'///Input:
'///
'///+- Filename incl. extension (string) but without any pathseparator
'///
'///Returns:
'///
'///+- Position of the object in the filepicker list
'///
'///+- 0: Object not found
'///+- > 0: Position
'///
'///
'///Description:
'///
const CFN = "hFindFileObjectViaFileOpen::"
dim iCurrentObject as integer
dim cCurrentName as string
dim iFileOpenItemCount as integer
dim iPos as integer : iPos = 0
dim cPath as string : cPath = cName
dim iPathItems as integer
dim asPathList( 100 ) as string
dim iWait as integer ' some increment variable
printlog( CFN & "Enter with option (File): " & cName )
'///+- If a fully qualified path has been provided we have to split it up
iPathItems = DirNameList( cPath, asPathList() )
'printlog( CFN & "iPathItems (new): " & iPathItems )
if ( iPathItems > 3 ) then
cName = asPathList( iPathItems )
printlog( CFN & "CNAME from plist: " & cName )
'///+- And walk to the directory
cPath = left( cPath , ( len ( cPath ) - len( cName ) ) - 1 )
printlog( CFN & "CPATH from plist: " & cPath )
kontext "OeffnenDlg"
if ( OeffnenDlg.exists( 1 ) ) then
Dateiname.setText( cPath )
Oeffnen.click()
else
warnlog( CFN & "File Open dialog is not open" )
hFindFileObjectViaFileOpen() = 0
exit function
endif
endif
'///+- get the number of items in the filepicker
kontext "OeffnenDlg"
iWait = 0
while ( DateiAuswahl.getItemCount() = 0 )
wait( 100 )
iWait = iWait + 1
if ( iWait = 10 ) then
warnlog( "Filepicker is not populated within reasonable timeframe, aborting" )
kontext "OeffnenDlg"
OeffnenDlg.Close()
hFindFileObjectViaFileOpen() = 0
exit function
else
printlog( "Waiting for filepicker list to populate..." )
endif
wend
iFileOpenItemCount = DateiAuswahl.getItemCount()
'///+- Jump to the first item in the filelist and select it with SPACE
DateiAuswahl.typeKeys( "" )
DateiAuswahl.typeKeys( "" )
'///+- Navigate through the list until we find the requested object
for iCurrentObject = 1 to iFileOpenItemCount
cCurrentName = DateiAuswahl.getSelText()
if ( cCurrentName = cName ) then
iPos = iCurrentObject
exit for
endif
DateiAuswahl.typeKeys( "" )
next iCurrentObject
'///+- Print some info to the log
if ( iPos > 0 ) then
printlog( CFN & "Exit: Found item [" & cName & "] at pos: " & iPos )
else
printlog( CFN & "Exit: Requested item [" & cName & "] was not found." )
endif
'///+- return the position or 0 on failure
hFindFileObjectViaFileOpen() = iPos
'///
end function