summaryrefslogtreecommitdiff
path: root/testautomation/global/tools/includes/optional/t_stringtools.inc
diff options
context:
space:
mode:
Diffstat (limited to 'testautomation/global/tools/includes/optional/t_stringtools.inc')
-rwxr-xr-x[-rw-r--r--]testautomation/global/tools/includes/optional/t_stringtools.inc140
1 files changed, 71 insertions, 69 deletions
diff --git a/testautomation/global/tools/includes/optional/t_stringtools.inc b/testautomation/global/tools/includes/optional/t_stringtools.inc
index 0fc34d89ecf6..914d8b7c6ab4 100644..100755
--- a/testautomation/global/tools/includes/optional/t_stringtools.inc
+++ b/testautomation/global/tools/includes/optional/t_stringtools.inc
@@ -33,46 +33,11 @@
function hRemoveLineBreaks( cString as string ) as string
- '///<h3>Remove linebreaks and tabs from a string</h3>
- '///<i>Used to &quot;beautify&quot; content of messageboxes when printed to the log</i><br><br>
- '///<u>Parameter(s):</u>
- '///<ol>
- '///+<li>Content of a messagebox as captured with .getText() (string)</li>
- '///</ol>
- '///<u>Returns</u>:
- '///<ol>
- '///+<li>A string without tabs, linebreaks and linefeed (string)</li>
- '///</ol>
- '///<u>Description</u>:
- '///<ul>
- '///+<li>Walk through the string, replace linebreaks, tabs etc. with spaces</li>
-
- ' Function (undocumented) to remove LF and CR from strings.
- ' When a messagebox appears with multiple lines of text this usually
- ' breaks the output of the printlog into multiple lines making it
- ' hard to read. So this function puts the entire text in one line.
-
- dim iCharPos as integer
- dim cCurrentChar as string
- dim cNewString as string
-
- ' walk through the string character by character and replace those
- ' characters that break the line. Tabs and linebreaks become spaces
- for iCharPos = 1 to len( cString )
-
- cCurrentChar = mid( cString , iCharPos , 1 )
-
- select case cCurrentChar
- case CHR$(13) : cNewString = cNewString & " " ' replace linebreak
- case CHR$(10) : ' Simply ignore linefeed
- case CHR$(09) : cNewString = cNewString & " " ' replace tab with space
- case else : cNewString = cNewString & cCurrentChar ' append char
- end select
-
- next iCharPos
-
- hRemoveLineBreaks() = cNewString
- '///</ul>
+ dim myString as string : myString = cString
+ myString = hStringReplaceChar( myString, CHR$(09), " " )
+ myString = hStringReplaceChar( myString, CHR$(13), " " )
+ myString = hStringReplaceChar( myString, CHR$(10), "" )
+ hRemoveLineBreaks() = myString
end function
@@ -101,35 +66,41 @@ function hCompareSubStrings( cRef as string, cSub as string ) as integer
'///<ul>
const CFN = "hCompareSubStrings::"
+ const RETVAL_INVALID_PARAMETER = -1
+ const RETVAL_MATCH_NONE = 0
+ const RETVAL_MATCH_EXACT = 1
+ const RETVAL_MATCH_SUBSTRING = 2
'///+<li>Test function parameters</li>
if ( ( cRef = "" ) or ( cSub = "" ) ) then
warnlog( CFN & "invalid parameter(s): Empty string passed." )
- hCompareSubStrings() = -1
+ hCompareSubStrings() = RETVAL_INVALID_PARAMETER
exit function
endif
dim irc as integer
'///+<li>Test if we have a substring</li>
- if ( instr( cRef, cSub ) > 0 ) then
- irc = 2
+ if ( instr( cRef, cSub ) ) then
+ irc = RETVAL_MATCH_SUBSTRING
else
- irc = 0
+ irc = RETVAL_MATCH_NONE
endif
'///+<li>Test if we have an exact match</li>
- if ( irc = 2 ) then
+ if ( irc = RETVAL_MATCH_SUBSTRING ) then
if ( ( cRef = cSub ) and ( len( cRef ) = len( cSub ) ) ) then
- irc = 1
+ irc = RETVAL_MATCH_EXACT
endif
endif
-
- select case irc
- case 0 : printlog( CFN & "No matching substring found" )
- case 1 : printlog( CFN & "Strings are identical" )
- case 2 : printlog( CFN & "String is substring" )
- end select
+
+ if ( GVERBOSE ) then
+ select case irc
+ case RETVAL_MATCH_NONE : printlog( CFN & "No matching substring found" )
+ case RETVAL_MATCH_EXACT : printlog( CFN & "Strings are identical" )
+ case RETVAL_MATCH_SUBSTRING : printlog( CFN & "String is substring" )
+ end select
+ endif
hCompareSubStrings() = irc
'///</ul>
@@ -162,8 +133,7 @@ function hGetDirTreeLevel( cFullPath as string ) as integer
dim iCurrentChar as integer
dim cCurrentChar as string
- dim iSeparatorCount as integer
- iSeparatorCount = 0
+ dim iSeparatorCount as integer : iSeparatorCount = 0
'///+<li>Walk through the string</li>
'///<ul>
@@ -173,9 +143,7 @@ function hGetDirTreeLevel( cFullPath as string ) as integer
cCurrentChar = mid( cFullPath , iCurrentChar , 1 )
'///+<li>If it is a separtator, increase the counter</li>
- if ( cCurrentChar = gPathSigne ) then
- iSeparatorCount = iSeparatorCount + 1
- endif
+ if ( cCurrentChar = gPathSigne ) then iSeparatorCount = iSeparatorCount + 1
next iCurrentChar
'///</ul>
@@ -232,7 +200,7 @@ function hGetStringFromStaticTextField( oControl as object ) as string
dim cCopy as string
dim cText as string
- printlog( CFN & "Enter" )
+ if ( GVERBOSE ) then printlog( CFN & "Enter" )
'///<u>Description:</u>
'///<ul>
@@ -250,14 +218,14 @@ function hGetStringFromStaticTextField( oControl as object ) as string
oControl.typeKeys( cCopy )
cText = getClipboardText()
- printlog( CFN & "Exit with result: " & cText )
+ if ( GVERBOSE ) then printlog( CFN & "Exit with result: " & cText )
else
ctext = ""
- qaerrorlog( CFN & "Exit: Control exists but is not visible" )
+ warnlog( CFN & "Exit: Control exists but is not visible" )
endif
else
cText = ""
- qaerrorlog( CFN & "Exit: Control does not exist in this context" )
+ warnlog( CFN & "Exit: Control does not exist in this context" )
endif
'///</ul>
@@ -304,17 +272,16 @@ function hConvertStringToLong( cValue as string ) as long
'///</ol>
const CFN = "hConvertStringToLong::"
- printlog( CFN & "Enter with option: " & cValue )
- dim brc as boolean 'a multi purpose boolean returnvalue
+ const ONE_CHARACTER = 1
- dim iLen as integer
- iLen = len( cValue )
+ if ( GVERBOSE ) then printlog( CFN & "Enter with option: " & cValue )
+
+ dim iLen as integer : iLen = len( cValue )
dim iChar as integer
dim cChar as string
- dim cStringValue as string
- cStringValue = ""
+ dim cStringValue as string : cStringValue = ""
'///<u>Description:</u>
'///<ul>
@@ -323,7 +290,7 @@ function hConvertStringToLong( cValue as string ) as long
for iChar = 1 to iLen
'///+<li>Get the current character</li>
- cChar = mid( cValue , iChar , 1 )
+ cChar = mid( cValue , iChar , ONE_CHARACTER )
'///+<li>Copy valid characters to temporary string, drop invalid, exit on first space or other character</li>
select case cChar
@@ -344,10 +311,45 @@ function hConvertStringToLong( cValue as string ) as long
next iChar
'///</ul>
- printlog( CFN & "Exit with value: " & cStringValue )
+ if ( GVERBOSE ) then printlog( CFN & "Exit with value: " & cStringValue )
'///+<li>Convert string to long integer and return to calling function</li>
hConvertStringToLong() = val( cStringValue )
'///</ul>
end function
+
+'*******************************************************************************
+
+function hStringReplace( cString as string, search_string as string, replace_with as string ) as string
+
+ const CFN = "hStringReplace(): "
+
+ dim search_string_position as string
+ dim search_string_found as boolean : search_string_found = true
+ dim len_search_string as integer : len_search_string = len( search_string )
+ dim len_replace_with as integer : len_replace_with = len( replace_with )
+ dim myString as string : myString = cString
+
+ if ( GVERBOSE ) then printlog( CFN & "Replace all <" & search_string & "> with <" & replace_with & "> in <" & myString & ">" )
+
+ if ( not instr( replace_with, search_string ) and len_search_string >= len_replace_with ) then
+ do while( search_string_found )
+ search_string_position = instr( myString, search_string )
+ if ( search_string_position > 0 ) then
+ mid( myString, search_string_position, len( search_string ), replace_with )
+ else
+ search_string_found = false
+ endif
+ loop
+ else
+ warnlog( CFN & "Function used incorrectly" )
+ warnlog( CFN & "Replace all <" & search_string & "> with <" & replace_with & "> in <" & myString & ">" )
+ warnlog( CFN & "The new string must be of equal length or shorter than the string to be replaced" )
+ warnlog( CFN & "The new string may not contain the string to be replaced (e.g. replace 'a' with 'ha' is not allowed)" )
+ endif
+
+ if ( GVERBOSE ) then printlog( CFN & "Return string is <" & myString & ">" )
+ hStringReplace() = myString
+
+end function