' File name: QA_LIB.INC
' Project:  The include file necessary for all tests

' ***************************************************************
' *                                                             *
' *  This file contains the following:                          *
' *                                                             *
' *  A) Wrapped TestBasic Functions.                            *
' *                                                             *
' *                                                             *
' ***************************************************************

'$ INCLUDE 'winapi.inc'
'$ INCLUDE 'Globals.inc'
'$ INCLUDE 'ChatInterfaceControls.inc'
'$ INCLUDE 'VTMInterfaceControls.inc'
'$ INCLUDE 'VBWInterfaceControls.inc'

sReportFailFile = "d:\reports\failure.log"


' **************************************************************
' *                                                            *
' *              Windows Control Functions                     *
' *                                                            *
' **************************************************************

'----------------------------------------------------------------------
'Declarations.
'----------------------------------------------------------------------
Declare Sub _SetWndPos    (hwnd&, _left&, Top&, Reserved=0)
Declare Function _GetWndPosTop (hwnd&=0) AS Long
Declare Function _GetWndPosLeft (hwnd&=0) AS Long
Declare Sub _SetActWnd    (hwnd&, Reserved=0)
Declare Sub _SetWndSiz    (hwnd&, width&, height&, Reserved=0)
Declare Sub _MinWnd       (hwnd&, Reserved=0)
Declare Sub _MaxWnd       (hwnd&, Reserved=0)
Declare Sub _ResWnd       (hwnd&, Reserved=0)
Declare Function _GetInfo (activeWindowHwnd)
Declare Function _WinFind (winCaption$, flags=FW_FOCUS, timeout%=1, controlName$ = "", Reserved=0) As Long
Declare Function _SetWindowPosition(Caption AS String, DistanceFromTop AS Long, DistanceFromLeft AS Long)

'----------------------------------------------------------------------
Function _SetWindowPosition(Caption AS String, DistanceFromTop AS Long, DistanceFromLeft AS Long) AS Long
	windowHwnd = WfndWndC(Caption, NULL, FW_FOCUS OR FW_NOCASE OR FW_PART)
	_SetWndPos (windowHwnd, DistanceFromLeft, DistanceFromTop)
End Function

Function _WinFind (winCaption$, flags = FW_FOCUS, timeout%=1, controlName$ = "", Reserved=0) As Long

   _WinFind = WFndWnd(winCaption$, flags, 10)
   WriteToLogBuffer("Looking for window with caption ''" +  winCaption$ + ".''")
  
   if WFndWnd(winCaption$, flags, 10) = 0 then
	  _Fail("Can't find window with caption ''" +  winCaption$ + ".''")   
   end if

End Function
'----------------------------------------------------------------------
Function _GetInfo (activeWindowHwnd)
End function


'----------------------------------------------------------------------
'Functions
'----------------------------------------------------------------------
Sub _SetWndPos(hwnd&, _left&, Top&, Reserved=0)
   WriteToLogBuffer("Set the window (handle: " + str$(hwnd&) + ") position to: " + str(_left&) + ", " + str(Top&) + " (left, top).")
   WSetWndPos(hwnd&, _left&, Top&)
End Sub

'----------------------------------------------------------------------
Function _GetWndPosTop (hwnd&=0) AS Long
'Declare Function _GetWndPosLeft (hwnd&=0) AS Long
	Dim wndpos As WNDPOS
		WGetWndPos (hwnd&, wndpos, W_ABSOLUTE)
	_GetWndPosTop = wndpos.wTop
    WriteToLogBuffer("The window " + CaptionGet(hwnd&) + " is positioned at " + Str$(wndpos.wTop) + ".")
End Function
'----------------------------------------------------------------------
Function _GetWndPosLeft (hwnd&=0) AS Long
	Dim wndpos As WNDPOS
		WGetWndPos (hwnd&, wndpos, W_ABSOLUTE)
	_GetWndPosLeft = wndpos.wLeft
    WriteToLogBuffer("The window " + CaptionGet(hwnd&) + " is positioned at " + Str$(wndpos.wLeft) + ".")
End Function

'----------------------------------------------------------------------
Sub _SetActWnd(hwnd&, Reserved=0)
   WriteToLogBuffer("Set the active window (handle: " + str$(hwnd&) + ").")
   WSetActWnd(hwnd&)
End Sub
'----------------------------------------------------------------------
Sub _SetWndSiz(hwnd&, width&, height&, Reserved=0)
   WriteToLogBuffer("Resize the active window (handle: " + str$(hwnd&) + ") to: " + str(width&) + ", " + str(height&) + " (width, height).")
   WSetWndSiz( hwnd&, width&, height& )
End Sub
'----------------------------------------------------------------------
Sub _MinWnd(hwnd&, Reserved=0)
   WriteToLogBuffer("Minimize the active window (handle: " + str$(hwnd&) + ").")
   WMinWnd(hwnd&)
End Sub
'----------------------------------------------------------------------
Sub _MaxWnd(hwnd&, Reserved=0)
   WriteToLogBuffer("Maximize the active window (handle: " + str$(hwnd&) + ").")
   WMaxWnd(hwnd&)
End Sub
'----------------------------------------------------------------------
Sub _ResWnd(hwnd&, Reserved=0)
   WriteToLogBuffer("Restore the active window (handle: " + str$(hwnd&) + ").")
   WResWnd(hwnd&)
End Sub
'----------------------------------------------------------------------


' **************************************************************
' *                                                            *
' *              Menu Control Functions                        *
' *                                                            *
' **************************************************************
'----------------------------------------------------------------------
'Declarations
'----------------------------------------------------------------------
Declare Sub      _MenuSelect ( item$, controlName$ = "", timeout%=1, Reserved=0)
Declare Function _MenuExists ( item$, controlName$ = "", timeout%=1, Reserved=0) AS Long
Declare Function _MenuText   ( item$, controlName$ = "", timeout%=1, Reserved=0) AS String
Declare Function _MenuEnabled( item$, controlName$ = "", timeout%=1, Reserved=0) AS Long

'----------------------------------------------------------------------
'Functions
'----------------------------------------------------------------------
Sub _MenuSelect( item$, controlName$ = "", timeout%=1, Reserved=0)
	if _MenuExists ( item$, controlName$, timeout%, Reserved ) then
		WriteToLogBuffer("Open menu item, ''" +  controlName$ + "''.")
		WMenuSelect(item$, timeout%=1)
	else
		WriteToLogBuffer("Sorry! Can't find menu item, ''" +  controlName$ + "'' so I can't tell if it is enabled.")
	end if
End Sub

Function _MenuExists ( item$, controlName$ = "", timeout%=1, Reserved=0) AS Long
  WriteToLogBuffer("Check for the existence of menu item, ''" +  controlName$ + "''.")
  _MenuExists = WMenuExists (item$, timeout%=1)
End Function

Function _MenuText ( item$, controlName$ = "", timeout%=1, Reserved=0) As String
  _MenuText = MenuText(item$, timeout%=1)
  WriteToLogBuffer("Check the text of menu item, ''" +  controlName$ + "''.")
End Function

Function _MenuEnabled( item$, controlName$ = "", timeout%=1, Reserved=0) AS Long
 
 if _MenuExists ( item$, controlName$, timeout%, Reserved ) then
	WriteToLogBuffer("Check to see if menu item, ''" +  controlName$ + "'' is enabled.")
    _MenuEnabled = WMenuEnabled(item$, timeout%)
 else
	WriteToLogBuffer("Sorry! Can't find menu item, ''" +  controlName$ + "'' so I can't tell if it is enabled.")
 end if

End Function


' ***************************************************************
' *                                                             *
' *                                                             *
' *              Control Support Functions                      *
' *                                                             *
' *                                                             *
' ***************************************************************

'----------------------------------------------------------------------
'Declarations
'----------------------------------------------------------------------
 Declare Sub WriteToLogBuffer(sLogBufferString$)
 Declare Sub ClearLogBuffer()
 Declare Sub ResetLogNumber(logNumber&=0)
 Declare Sub WriteToLogFile()
 Declare Sub LogEnabled()
 Declare Sub LogDisabled()
 Declare Function ControlFind(sControl$ = NULL, sClass$ = NULL, lArguments = FW_FOCUS or FW_ACTIVE or FW_NOCASE, timeout% = 1) AS Long

 Function ControlFind(sControl$ = NULL, sClass$ = NULL, lArguments = FW_FOCUS or FW_ACTIVE or FW_NOCASE, timeout% = 1) AS Long
 ControlFind = WFndWndC ( sControl$, sClass$, lArguments, 5)
 End Function

'----------------------------------------------------------------------
'Functions
'----------------------------------------------------------------------
 Sub ResetLogNumber(logNumber&=0)
	iLogBuffer = logNumber&
 End Sub
'----------------------------------------------------------------------
 Sub LogEnabled()
	LoggingState& = 1
 End Sub
'----------------------------------------------------------------------
 Sub LogDisabled()
	LoggingState& = 0
 End Sub
 '----------------------------------------------------------------------
 Sub WriteToLogBuffer(sLogBufferString$)

 Dim sLogFileString As String

   ' If LoggingState& = 1  then

	if iLogBuffer > 9999 then
		iLogBuffer = 1
    end if

	   iLogBuffer = iLogBuffer + 1
		   if lStepPrint  = TRUE then
			  sLogString(iLogBuffer) = "          Step "+ LTRIM$(Str$(iLogBuffer-1)) + ": " + sLogBufferString$
		   else 
		      sLogString(iLogBuffer) = sLogBufferString$
		   End if
  '  End if
 End Sub
'----------------------------------------------------------------------
Sub ClearLogBuffer()

  Dim n As Integer

  For n = 1 to 5000
    sLogString(n) = ""
   ' iLogBuffer = 0
  Next n

End Sub
'----------------------------------------------------------------------
Sub WriteToLogFile()
Open sReportFailFile for APPEND as #1
	For n = 1 to iLogBuffer
		Print #1, sLogString(n)
		Print sLogString(n)
	next
Close

End Sub


' ***************************************************************
' *                                                             *
' *                   Window Support Functions                  *
' *                                                             *
' ***************************************************************
' 

'----------------------------------------------------------------------
'Declarations
'----------------------------------------------------------------------

 Declare Function CaptionGet             (currentHwnd&) AS String
 Declare Function GetCurrentWindowHandle (currentHwnd&) AS Long
 Declare Function CaptionCompare         (currentHwnd&, expectedCaption$, caseSensitive&, sScriptName$) AS Long
 Declare Function FindWindowWithCaption  (targetCaption$, caseSensitive& = FALSE, flags = FW_DEFAULT, className$="", timeout% = 1) AS Long
 Declare Function CloseWindowWithCaption (targetCaption$, caseSensitive& = FALSE, className$="", timeout% = 1) AS Long
 Declare Sub SetWindowFocus (targetHwnd&) 
' Declare Function GetContext(Application$, activeDialog$, ControlType$, ControlExist$)
'----------------------------------------------------------------------

'----------------------------------------------------------------------
'Functions
'----------------------------------------------------------------------

 Function GetCurrentWindowHandle (currentHwnd&) AS Long
   GetCurrentWindowHandle = WGetActWnd (currentHwnd&)
 End Function
'----------------------------------------------------------------------
 Sub SetWindowFocus (targetHwnd&) 
   WSetActWnd (targetHwnd&)
 End Function
'----------------------------------------------------------------------

 'Get the caption of the currently active dialog.
 Function CaptionGet(currentHwnd&) AS String
   _GetInfo (currentHwnd&)
'   CaptionGet = info.Text
   'WriteToLogBuffer("Get the caption of the currently active dialog (which is now ''" + info.Text + "'')." )
 End Function

'----------------------------------------------------------------------
' Compare the caption of any dialog for which 
' you can get an hwnd. If it's not there, 
' a fail is generated. 
'----------------------------------------------------------------------

 Function CaptionCompare(currentHwnd&, expectedCaption$, caseSensitive&, sScriptName$) AS Long
    
    WriteToLogBuffer("Compare the caption of the currently active dialog with ''" + expectedCaption$ + ".''")

    Dim iStringCompare as Short
    Dim currentCaption as String

    currentCaption = CaptionGet(currentHwnd&)
    
    'FALSE = case INsensitive. TRUE = case Sensitive. All compares are PARTIAL.
    if caseSensitive& = FALSE then  
      iStringCompare =  instr( UCASE$(expectedCaption), UCASE$(currentCaption)  ) 
    else
      iStringCompare =  instr(expectedCaption, currentCaption ) 
    end if

    if iStringCompare = 0 then
		_Fail("Caption is: ''" +  CaptionGet(currentHwnd&) + chr$(13) + "'', but should be " +  expectedCaption)
		CaptionCompare = FALSE
   end if
 
 End Function

'----------------------------------------------------------------------
' Find a caption. Optionally set focus and mimimize. 
Function FindWindowWithCaption( targetCaption$, caseSensitive&=FALSE, flags=FW_DEFAULT, className$="", timeout% = 1) AS Long

   if className$ = "" then
      FindWindowWithCaption = WfndWnd  (targetCaption$, flags, timeout% )
   else
      FindWindowWithCaption = WfndWndC (targetCaption$, className$, flags, timeout% )
   end if
   
   if targetCaption$ <> NULL AND targetCaption$ <> "" then
      WriteToLogBuffer("See if a dialog with ''" + targetCaption$ + "'' exists.")
   end if

End Function
'----------------------------------------------------------------------
Function CloseWindowWithCaption( targetCaption$, caseSensitive& = FALSE, className$="", timeout% = 1) AS Long
  Dim lTheTargethWnd AS Long
  lTheTargethWnd = FindWindowWithCaption( targetCaption$, caseSensitive&, flags=FW_FOCUS, className$, timeout%)
  _Play("%{F4}")
  WriteToLogBuffer("Close the dialog with caption, ''" + targetCaption$ + "''.")
End Function

' ***************************************************************
' *                                                             *
' *                         Logging                             *
' *                                                             *
' ***************************************************************

'----------------------------------------------------------------------
'Declarations
'----------------------------------------------------------------------
Declare Function _Runlog (sFailMessage$ = "", sScriptName$ = "", controlName$ = "") AS Long
Declare Function _Fail   (sFailMessage$ = "", sScriptName$ = "", controlName$ = "") AS Long
'----------------------------------------------------------------------
'Functions
'----------------------------------------------------------------------
Function _Runlog (sFailMessage$ = "", sScriptName$ = "", controlName$ = "") AS Long

'Get contextual information for log file.
'-----------------------------------------------------------------------
 _GetInfo(0)
' sProductModuleFile = info.Text
 sScriptName$ = NAME$(0)

 if lCurrentFailState = TRUE then
   sPassFailStatus = sScriptName$ + " failed "  
 else
   sPassFailStatus = sScriptName$ + " passed "  
 end if


End Function
'----------------------------------------------------------------------

Function _Fail(sFailMessage$ = "", sScriptName$ = "", controlName$ = "") AS Long

lCurrentFailState = TRUE
lFailCount = lFailCount + 1
'Complete log fail header
'Open reportDrive+reportPath + reportFailFile for APPEND as #1

'   Print #1, " "
'   Print #1, "------------------------------------------------------------------" 
'   Print #1, "FAIL in: " + sScriptName$ + " on " + Date$ + ": " + Time$

   'Summary log fail header
'   Open reportDrive+reportPath + summaryReportFailFile for APPEND as #2
'   Print #2, " "
'   Print #2, "------------------------------------------------------------------" 
'   Print #2, "FAIL in: " + sScriptName$ + " on " + Date$ + ": " + Time$

'Close
'WriteToLogBuffer("FAIL in: " + sScriptName$ + " on " + Date$ + ": " + Time$ )

    lStepPrint = FALSE
    WriteToLogBuffer("          Error!: " + sFailMessage$ )
    lStepPrint = TRUE


if lVerbose = TRUE then
   WriteToLogFile()
end if

End Function

' ***************************************************************
' *                                                             *
' *  File I/O and string processing                             *
' *                                                             *
' ***************************************************************

'----------------------------------------------------------------------
'Declarations
'----------------------------------------------------------------------

Declare Sub FileCopy(sOldFileName$, sNewFileName$)
Declare Sub FileDelete(FileToDelete$)
Declare Sub FileCompare(sReferenceFile$, sTargetFile$, lMaxErrors&=0, lIgnoreSpaces& = FALSE, lIgnorePaths& = FALSE)
Declare Function StringCompare(sReferenceString$, sTargetString$, lIgnoreSpaces& = FALSE) AS Long
Declare Function RemoveRepetitiveCharacters(stringToBeFiltered$,  repeatingCharacters$ = " ") AS String
Declare Function RemoveCharacters(stringToBeFiltered$, Characters$ = " ") AS String
Declare Function GetEverythingToTheRightOfRightmostChar(sString$, char$) AS String
 
'----------------------------------------------------------------------
'Functions
'----------------------------------------------------------------------
Function GetEverythingToTheRightOfRightmostChar(sString$, char$) AS String
Dim iTheRawStringLength AS Integer
Dim sTheChar            AS String
iTheRawStringLength = len(sString$)

   For n = 1 to iTheRawStringLength-1
   sTheChar = mid$(sString$,iTheRawStringLength-n, 1)
      if sTheChar = char$ then
         GetEverythingToTheRightOfRightmostChar = mid$(sString$, iTheRawStringLength-n+1, iTheRawStringLength-n)
         exit for
      end if
   next

End Function

'----------------------------------------------------------------------

Function GetEverythingToTheLeftOfChar(sString$, char$) As String

	Dim iCharPos As Integer

	iCharPos = InStr(sString$, char$)

		If iCharPos = 0 Then
			msgbox "Character " + char$ + " was not found in string, ''" + sString$ + "''."
		End If

		If iCharPos = 0 Then iCharPos = 1

	GetEverythingToTheLeftOfChar = Left$(sString$, iCharPos - 1)

End Function

'----------------------------------------------------------------------

Function GetEverythingToTheLeftOfRightmostChar(sString$, char$) As String
Dim iTheRawStringLength As Integer
Dim sTheChar            As String
iTheRawStringLength   = Len(sString$)

   For n = 1 To iTheRawStringLength - 1
   sTheChar = Mid$(sString$, iTheRawStringLength - n, 1)
      If sTheChar = char$ Then
          GetEverythingToTheLeftOfRightmostChar = Mid$(sString$, 1, (iTheRawStringLength - n) - 1)
          Exit For
      End If
   Next

End Function

'----------------------------------------------------------------------

Function GetEverythingToTheRightOfChar(sString$, char$) As String

eLen = Len(sString$)
ePos = InStr(sString$, char$)

If ePos = 0 Then
	msgbox "Character " + char$ + " was not found in string, ''" + sString$ + "''."
End If

GetEverythingToTheRightOfChar = Right$(sString$, eLen - ePos)

End Function

'----------------------------------------------------------------------

Function RemoveCharacters(stringToBeFiltered$, Characters$ = " ") AS String
   Dim tempstring$(10000)
   Dim char$(10000)
   Dim lLengthOfStringToBeFiltered AS Long

   lLengthOfStringToBeFiltered = len(stringToBeFiltered$)

   For n = 1 to lLengthOfStringToBeFiltered
   char$(n) = Mid(stringToBeFiltered$, n, 1)
      if char$(n) <> Characters$ then
         FinalString$ = FinalString$ + char$(n)
      end if
   next

   RemoveCharacters = FinalString$
   'Print FinalString$
End Function
'----------------------------------------------------------------------
Function RemoveRepetitiveCharacters(stringToBeFiltered$, repeatingCharacters$ = " ") AS String

   Dim tempstring$(10000)
   Dim char$(10000)
   Dim lLengthOfStringToBeFiltered AS Long

   lLengthOfStringToBeFiltered = len(stringToBeFiltered$)

   For n = 1 to lLengthOfStringToBeFiltered
   char$(n) = Mid(stringToBeFiltered$, n, 1)
      if NOT (char$(n) = repeatingCharacters$ AND char$(n-1) = repeatingCharacters$) then
         FinalString$ = FinalString$ + char$(n)
      end if
   next

   RemoveRepetitiveCharacters = FinalString$
   'Print FinalString$
End Function
'----------------------------------------------------------------------
Function StringCompare(sReferenceString$, sTargetString$, lIgnoreSpaces& = FALSE) AS Long
  
   
   Dim lLengthOfOriginalReferenceString AS Long
   Dim lLengthOfOriginalTargetString    AS Long
   Dim lLengthOfFilteredReferenceString AS Long
   Dim lLengthOfFilteredTargetString    AS Long

 
   if lIgnoreSpaces& = TRUE  then
      sReferenceString$ = RemoveRepetitiveCharacters(sReferenceString$, " ")
      sTargetString$    = RemoveRepetitiveCharacters(sTargetString$,    " ")
   end if

   if sReferenceString$ = sTargetString$ then
      StringCompare = TRUE
   else
      StringCompare = FALSE
 '     Print "Expected " + sReferenceString$ + " but found " + sTargetString$ + "."
      _Fail  ("Expected " + sReferenceString$ + " but found " + sTargetString$ + ".")
   end if

End Function
'----------------------------------------------------------------------
Sub FileCopy(sOriginalFile$, sNewFile$)
   sCurrentlyLoadedFile = sOriginalFile$
   WriteToLogBuffer  ("Copy " + sOriginalFile$ + " to " + sNewFile$ +".")

   if EXISTS (sOriginalFile$) = TRUE then
      COPY sOriginalFile$ TO sNewFile$
      Print "Copying " + sOriginalFile$ + " to " + sNewFile$
    else
      WriteToLogBuffer  (sOriginalFile$ + " not found! Check the path and filename and try again.")
    end if

End Sub
'----------------------------------------------------------------------
Sub FileDelete(FileToDelete$)
   WriteToLogBuffer("Deleting " + FileToDelete$ +".")
   
   if EXISTS (FileToDelete$) = TRUE then
      KILL FileToDelete$
     else
      WriteToLogBuffer(sOriginalFile$ + " not found! Check the path and filename and try again.")
   end if

End Sub
'----------------------------------------------------------------------
Sub FileCompare(sReferenceFile$, sTargetFile$, lMaxErrors&=0, lIgnoreSpaces& = FALSE, lIgnorePaths& = FALSE)

WriteToLogBuffer  ("Comparing reference file: " + sReferenceFile$ + chr$(10) + "        with target file: " + sTargetFile$ +"." + chr$(10))

if lIgnoreSpaces& = TRUE then
WriteToLogBuffer  ("Note: Multiple spaces ignored."+ chr$(10) )
end if

Dim lReferenceFileNumber        AS Long
Dim sReferenceFileBuffer(10000) AS String
Dim lReferenceFileLineNumber    AS Long

Dim lTargetFileNumber           AS Long
Dim sTargetFileBuffer(10000)    AS String
Dim lTargetFileLineNumber       AS Long

Dim lBadStringFlag              AS Long
Dim lBadStringCount             AS Long

Dim sTempString(10000)          AS String

lReferenceFileNumber = Freefile
lTargetFileNumber    = Freefile
lBadStringFlag& = FALSE

'Read in the reference file, line by line, and assign each line to a string variable.
Open sReferenceFile$ for input as lReferenceFileNumber 
   While NOT eof(1)
      lReferenceFileLineNumber = lReferenceFileLineNumber + 1
      Line Input #lReferenceFileNumber, sReferenceFileBuffer(lReferenceFileLineNumber)
      'print sReferenceFileBuffer(lReferenceFileLineNumber)
   Wend
Close lReferenceFileNumber 

'Read in the target file, line by line, and assign each line to a string variable.
Open sTargetFile$ for input as lTargetFileNumber
   While NOT eof(1)
      lTargetFileLineNumber = lTargetFileLineNumber + 1
      Line Input #lTargetFileNumber, sTargetFileBuffer(lTargetFileLineNumber)
      'print sTargetFileBuffer(lTargetFileLineNumber)
   Wend
Close lTargetFileNumber 

LogDisabled()

'Compare the strings in the reference and target files, line by line.
For n = 1 to lReferenceFileLineNumber
      
       if  instr(sReferenceFileBuffer(n),":\") = 0 AND lIgnorePaths& = TRUE then  
          if StringCompare( sReferenceFileBuffer(n), sTargetFileBuffer(n), lIgnoreSpaces&) <> TRUE then
            lBadStringCount = lBadStringCount + 1
            sTempString(lBadStringCount) =  "Line " + str(n) + " of " + sTargetFile$ + chr$(10) + "should have contained: " +  sReferenceFileBuffer(n) + chr$(10) + "but instead contained: " + sTargetFileBuffer(n) 
            'print sTempString(lBadStringCount)
          end if
       else
          if StringCompare( sReferenceFileBuffer(n), sTargetFileBuffer(n), lIgnoreSpaces&) <> TRUE then
            lBadStringCount = lBadStringCount + 1
            sTempString(lBadStringCount) =  "Line " + str(n) + " of " + sTargetFile$ + chr$(10) + "should have contained: " +  sReferenceFileBuffer(n) + chr$(10) + "but instead contained: " + sTargetFileBuffer(n) 
            print sTempString(lBadStringCount)
          end if
       end if
next n

LogEnabled()
'Set the maximum number of errors from optional argument 3 of the FileCompare function. 
'To allow all errors to be written to the log, leave this parameter off.


   For n = 1 to  lBadStringCount
      if sTempString(n) <> "" then
         'Print sTempString(lBadStringCount)
         WriteToLogBuffer( sTempString(n) )
      end if
   next n


if lBadStringCount > 0 then
_Fail("Files were not identical. "+ str(lBadStringCount) + " lines were different.")
end if

End Sub


' ***************************************************************
' *                                                             *
' *  Testing system utilities                                   *
' *                                                             *
' ***************************************************************

'----------------------------------------------------------------------
'Declarations
'----------------------------------------------------------------------
Declare Sub LoadIniFile()
Declare Function FindAndClick(DialogCaption1$, ButtonCaption1$, DialogCaption2$="", ButtonCaption2$="", DialogCaption3$="", ButtonCaption3$="", lRepeatSearch=FALSE) As Long

'-----------------------------------------------------------------------
Sub LoadIniFile()

Dim LoadIni                      As Integer
Dim PropertyLabel                As String
Dim PropertyValue                As String
Dim sInstallVariable(100)        As String
Dim iLineCount                   As Integer
Dim tempIniName                  AS String

For n = 100 To 132
    If Exists(Trim(Chr(n) + ":" + "\testmgr\test.ini")) Then
        tempIniName = Chr(n) + ":"+ "\testmgr\test.ini"
        'MsgBox "The   install directory is on " + sTempDir
    Exit For
    End If
Next

LoadIni = FreeFile
print "Opening " + tempIniName
Open tempIniName For Input As #LoadIni

Do While Not EOF(LoadIni)
    iLineCount = iLineCount + 1
    Line Input #LoadIni, sInstallVariable(iLineCount)
    
    If InStr(sInstallVariable(iLineCount), "=") <> 0 Then
        PropertyLabel = GetEverythingToTheLeftOfChar (sInstallVariable(iLineCount), "=")
        PropertyValue = GetEverythingToTheRightOfChar(sInstallVariable(iLineCount), "=")
        
        Select Case PropertyLabel
 
        Case "LocalApplication"
        LocalApplication = PropertyValue
        Print PropertyLabel + "=" + PropertyValue

        Case "VTMlocation"
        VTMlocation = PropertyValue
        Print PropertyLabel + "=" + PropertyValue
        
        Case "VTMMachineName"
        VTMMachineName = PropertyValue
        Print PropertyLabel + "=" + PropertyValue

        Case "VBWlocation"
        VBWlocation = PropertyValue
        Print PropertyLabel + "=" + PropertyValue

        Case "VBWMachineName"
        VBWMachineName = PropertyValue
        Print PropertyLabel + "=" + PropertyValue

        Case "VBWUserID"
        VBWUserID = PropertyValue
        Print PropertyLabel + "=" + PropertyValue

        Case "VBWPassword"
        VBWPassword = PropertyValue
        Print PropertyLabel + "=" + PropertyValue

		Case "InstallProgramDirValue"
		InstallProgramDirValue = PropertyValue
        Print PropertyLabel + "=" + PropertyValue

		Case "NTStartupFolder"
		NTStartupFolder = PropertyValue
        Print PropertyLabel + "=" + PropertyValue

		Case Else
			Print "An exception is " + PropertyLabel + "=" + PropertyValue
			End Select
        End If
	Loop
Close
End Sub

'-----------------------------------------------
Function FindAndClick(DialogCaption1$, ButtonCaption1$, DialogCaption2$="", ButtonCaption2$="", DialogCaption3$="", ButtonCaption3$="", lRepeatSearch=FALSE) As Long

'*** Main program statements go here.
  
Dim tempHwnd1 AS Long
Dim tempHwnd2 AS Long
Dim tempHwnd3 AS Long
Dim lFoundFlag AS Long

lFoundFlag = FALSE
Sleep 3

    While tempHwnd1 = 0

	tempHwnd1 =  WfndWndc(DialogCaption1$, NULL, FW_FOCUS, 60)
	Sleep 1
	if tempHwnd1 <> 0 then 											    	'If the window is found...
		if WButtonExists(ButtonCaption1$) then								 'And the button exists.
		   if WButtonEnabled(ButtonCaption1$) then							'And the button is enabled.
			  WButtonClick (ButtonCaption1$)  'Click it
				tempHwnd1=0													'And set tempHwnd1 to 0 so the while thing stops.
		      exit while
		   End if
		End if
	End if
	
	'----------------------------------------------------------
	if DialogCaption2$ <> "" then
		tempHwnd2 =  WfndWndc(DialogCaption2$, NULL, FW_Focus, 5)		
		if tempHwnd2 <> 0 then											'But if we happen to see caption 2...
			if WButtonExists(ButtonCaption2$) then						'We see if button 2 exists...
			   if WButtonEnabled(ButtonCaption2$) then							'And the button is enabled.
			      WButtonClick (ButtonCaption2$)							'And if so, we click it.
   			      tempHwnd2=0
			   End if
			End if
		End if
	End if

    '----------------------------------------------------------
	if DialogCaption3$ <> "" then
		tempHwnd3 =  WfndWndc(DialogCaption3$, NULL, FW_Focus, 5)		
		if tempHwnd3 <> 0 then											'But if we happen to see caption 2...
			if WButtonExists(ButtonCaption3$) then						'We see if button 2 exists...
			   if WButtonEnabled(ButtonCaption3$) then							'And the button is enabled.
			      WButtonClick (ButtonCaption3$)							'And if so, we click it.
   			      tempHwnd3=0
			   End if
			End if
		End if
	End if
    '----------------------------------------------------------

	if ButtonCaption1$ = ButtonCaption2$ then
		tempHwnd1 = 0
	End if

	if ButtonCaption1$ = ButtonCaption3$ then
		tempHwnd1 = 0
	End if

	if DialogCaption1$ = DialogCaption2$ then
		tempHwnd1 = 0
	End if
	
	if DialogCaption1$ = DialogCaption3$ then
		tempHwnd1 = 0
	End if

	if lRepeatSearch = TRUE then
		tempHwnd1 = 0
	end if

	Wend

End Function


Hosted by www.Geocities.ws

1