summaryrefslogtreecommitdiff
path: root/testautomation/global/tools/includes/required
diff options
context:
space:
mode:
authorJoerg Skottke [jsk] <jsk@openoffice.org>2010-09-09 13:11:38 +0200
committerJoerg Skottke [jsk] <jsk@openoffice.org>2010-09-09 13:11:38 +0200
commitd93f1af562e459899b1c2e41405069d0240644d4 (patch)
treed0bd852fedb3f8f2bf713549fa2898dd8f3f68cf /testautomation/global/tools/includes/required
parent04873f78c8cd0594d1beaabe50f8cb38135eb665 (diff)
automationdev300m87: #i112208# - Implemented fuction to work with a local copy of a file which resides anywhere else in the filesystem. The file is then copied to the users work directory and opened from there. This is experimental and the function needs to be called explicitly. The function is another workaround for the paramount problem that we cannot reliably switch a readonly document to edit-mode. Used the opportunity to introduce a new global variable (and fix the case of others, as they are not constants as they were initially planned to be)
Diffstat (limited to 'testautomation/global/tools/includes/required')
-rw-r--r--[-rwxr-xr-x]testautomation/global/tools/includes/required/t_dir.inc40
-rw-r--r--[-rwxr-xr-x]testautomation/global/tools/includes/required/t_files.inc102
2 files changed, 141 insertions, 1 deletions
diff --git a/testautomation/global/tools/includes/required/t_dir.inc b/testautomation/global/tools/includes/required/t_dir.inc
index ee673e6b1c47..a7347d4d498d 100755..100644
--- a/testautomation/global/tools/includes/required/t_dir.inc
+++ b/testautomation/global/tools/includes/required/t_dir.inc
@@ -288,4 +288,44 @@ function GetExtention ( Datei as String ) as string
next i%
GetExtention = Datei
end function
+'
+'-------------------------------------------------------------------------------
+'
+function hSplitString( sString as string, sSeparator as string, iIndex as integer ) as string
+
+ ' This function wraps around the "split" command and returns one single
+ ' item by index. Index = 0 means the *LAST* item is returned as this is
+ ' probably the most commonly used item. If the index is invalid (out of
+ ' bounds) we print a warning and return an error string.
+
+ const CFN & "global::tools::includes::required::t_dir.inc:hSplitString(): "
+ const ERROR_MESSAGE = "Array out of bounds for the requested index in string "
+ const ARRAY_INDEX_CORRECTION = 1 ' The array lower boundary is zero but
+ ' function starts to count with one.
+
+ ' Split the string into its fragments into an array with dynamic boundaries
+ dim sArray() as string: sArray() = split( sString, sSeparator )
+ dim sReturnString as string
+
+ ' Special case: Index out of bounds
+ if ( iIndex > ( ubound( sArray ) + ARRAY_INDEX_CORRECTION ) or iIndex < 0 ) then
+ warnlog( CFN & ERROR_MESSAGE & sString )
+ hSplitString() = ERROR_MESSAGE & sString
+ exit function
+ endif
+
+ ' Special case: Last item requested (this usually is the filename from a path)
+ if ( iIndex = 0 ) then
+ sReturnString = sArray( ubound( sArray() )
+ if ( GVERBOSE ) then printlog( CFN & sReturnString )
+ hSplitString() = sReturnString
+ exit function
+ endif
+
+ ' Default is to return the requested item.
+ sReturnString = sArray( iIndex - ARRAY_INDEX_CORRECTION )
+ if ( GVERBOSE ) then printlog( CFN & sReturnString )
+ hSplitString() = sReturnString
+
+end function
diff --git a/testautomation/global/tools/includes/required/t_files.inc b/testautomation/global/tools/includes/required/t_files.inc
index 4b0ddd09318b..e58ff1861ae4 100755..100644
--- a/testautomation/global/tools/includes/required/t_files.inc
+++ b/testautomation/global/tools/includes/required/t_files.inc
@@ -103,7 +103,7 @@ end function
function hIsNamedDocLoaded( cFileName as string ) as boolean
' Retrieve the current filename from the document properties - which in
- ' comparision to the old approach to retrive the name from the file save
+ ' comparision to the old approach to retrieve the name from the file save
' dialog - gives us the file including its extension. So we only need
' to compare the last characters from a full path to be relatively
' certain that we work with the correct file. There is some small margin of
@@ -501,6 +501,106 @@ end function
'
'-------------------------------------------------------------------------------
'
+function hGetWorkFile( cFileName as string ) as string
+ hGetWorkFile() = hGetWorkPath() & cFileName
+end function
+'
+'-------------------------------------------------------------------------------
+'
+function hGetWorkPath() as string
+
+ ' Retrieve the user's work directory using the API (or fallback)
+
+ dim sPath as string
+ dim oOfficeConnect as object
+ dim oOfficeConfig as object
+ dim bPathIsFromAPI as boolean
+
+ const CFN = "global::tools::includes::required::t_files.inc:hGetWorkPath(): "
+
+ ' Create an UNO service and ask it for the location of Work
+ try
+ oOfficeConnect = hGetUnoService( true )
+ oOfficeConfig = oOfficeConnect.createInstance( "com.sun.star.util.PathSettings" )
+ sPath = convertFromURL( oOfficeConfig.Work )
+ bPathIsFromAPI = true
+ catch
+ printlog( CFN & "Could not access service, connection broken?" )
+ sPath = convertpath( gOfficePath & "user/work" )
+ bPathIsFromAPI = false
+ endcatch
+
+ if ( GVERBOSE ) then
+
+ printlog( CFN & "Path is: " & sPath )
+
+ ' Check path existence
+ if ( FileExists( sPath ) ) then
+ printlog( CFN & "Path exists." )
+ else
+ warnlog( CFN & "Path does not exist." )
+ endif
+
+ ' Inform about the location from where the path was taken
+ if ( bPathIsFromAPI ) then
+ printlog( CFN & "Path was taken from API" )
+ else
+ warnlog( CFN & "Path was taken from (hardcoded) fallback" )
+ endif
+
+ endif
+
+ hGetWorkPath() = sPath & getPathSeparator
+
+end function
+'
+'-------------------------------------------------------------------------------
+'
+function hFileOpenLocally( _sSourcePath as string ) as boolean
+
+ const CFN = "global::tools::includes::required::t_files.inc:hFileOpenLocally(): "
+
+ GVERBOSE = true
+
+ dim sSourcePath as string : sSourcePath = ConvertToURL( _sSourcePath )
+ dim sTargetPath as string
+ dim sTargetFile as string
+
+ ' If the source file does not exist we quit
+ if ( not FileExists( sSourcePath ) then
+ warnlog( CFN & "Source path/file does not exist: " & sSourcePath )
+ hFileOpenLocally() = false
+ exit function
+ endif
+
+ ' Find out what the name of the target file is going to be
+ sTargetFile = hSplitString( sSourcePath, "/", 0 )
+ sTargetPath = hGetWorkFile( sTargetFile )
+
+ if ( FileExists( sTargetPath ) ) then
+ warnlog( CFN & "Target file already exists, replacing it!" )
+ hFileDelete( sTargetPath )
+ endif
+
+ if ( GVERBOSE ) then
+ printlog( CFN & "Copying file" )
+ printlog( CFN & "From: " & sSourcePath )
+ printlog( CFN & "To..: " & sTargetPath )
+ endif
+
+ FileCopy( sSourcePath, sTargetPath )
+
+ ' This is a hook that allows to access the filename under which the file
+ ' has been saved. Due to restrictive coding guidelines we cannot return
+ ' the new filename.
+ gLastWorkFile = sTargetPath
+
+ hFileOpenLocally() = hFileOpen( gLastWorkFile )
+
+end function
+'
+'-------------------------------------------------------------------------------
+'
function hFileCloseAll() as integer
dim iDocumentCount as integer : iDocumentCount = 0