home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / d / d009_2 / 1.ddi / SAMPLES / TSTSUITE / TSTSUITE.FT$ / TSTSUITE.bin
Encoding:
Text File  |  1992-02-12  |  9.7 KB  |  290 lines

  1. '******************************** TSTSUITE.FTI ********************************
  2. 'Demonstrates:  A sample Include file for multiple FASTTEST test scripts in a
  3. '               suite
  4. '
  5. 'Required Files: FASTTEST.INC
  6. '
  7. 'Uses: FASTTEST.INC
  8. '
  9. 'Complexity Level: INTERMEDIATE
  10. '
  11. 'Notes: Assumes target application (NOTEPAD.EXE) is in the PATH and
  12. '       LOG_FILE is in parent directory.
  13. '
  14. '******************************************************************************
  15.  
  16. Declare Sub Initialize ()
  17. Declare Sub Cleanup ()
  18. Declare Sub StartLog (testName$)
  19. Declare Sub EndLog (logFile$, resultFile$)
  20. Declare Sub EditCut ()
  21. Declare Sub EditPaste ()
  22. Declare Sub FileNewClear ()
  23. Declare Sub FileOpen (fileName$)
  24. Declare Function FileExit (YesNoCancel$, fileName$, replace%) As Integer
  25. Declare Function SaveFile (YesNoCancel$, fileName$, replace%) As Integer
  26. Declare Function SrchFind (Target$) As Integer
  27. Declare Function VerifyEditAndClipBoard (editStr$, clipStr$) As Integer
  28.  
  29. '$Include 'FASTTEST.INC'
  30.  
  31.  
  32. '******************************************************************************
  33. ' CONSTs
  34. '******************************************************************************
  35.  
  36. '  File names and numbers
  37. Const PROGRAM_NAME  = "NOTEPAD.EXE"             ' Target application
  38. Const LOG_FILE      = "..\FTSUITE.LOG"         ' Main log file
  39. Const RESULT_FILE   = "FTRESULT.TXT"             ' Results file
  40. Const TEMP_FILE     = "FILEMENU.TMP"
  41.  
  42. '  Log and result file strings
  43. Const PASS          = "        passed "
  44. Const FAIL          = "        FAILED "
  45. Const ERRSTR        = " *** ERROR - "
  46.  
  47. '  Function return codes
  48. Const SUCCESS           = TRUE
  49. Const R_FILECREATED     = 1
  50. Const R_CREATEABORTED   = 2
  51. Const R_REPLACE         = 3
  52. Const R_REPLACEABORTED  = 4
  53. Const R_ERRORNODIALOG   = 5
  54. Const R_NODIALOG        = 6
  55. Const R_NOTFOUND        = 7
  56. Const R_CLIPNOMATCH     = 8
  57. Const R_EDITNOMATCH     = 16
  58.  
  59. '  Static / Dialog title strings
  60. Const PROGRAM_TITLE         = "NotePad"
  61. Const SAVE_AS_DIALOG_TITLE  = "Save As"
  62. Const FIND_DIALOG_TITLE     = "Find"
  63.  
  64. '  Application specific keys
  65. CONST K_YES     = "Y"
  66. CONST K_NO      = "N"
  67. CONST K_CANCEL  = "ESC"
  68. Const K_BOF     = "HOME"
  69. Const K_SELALL  = "END"
  70.  
  71. '  Menu definitions
  72. Const FILE_MENU     = "&File"
  73. Const FILE_NEW      = "&New"
  74. Const FILE_OPEN     = "&Open..."
  75. Const FILE_EXIT     = "E&xit"
  76.  
  77. Const EDIT_MENU     = "&Edit"
  78. Const EDIT_CUT      = "Cu&t"
  79. Const EDIT_PASTE    = "&Paste"
  80.  
  81. Const SEARCH_MENU   = "&Search"
  82. Const SEARCH_FIND   = "&Find..."
  83.  
  84. Const SYSMENU_CLOSE = "&Close"
  85.  
  86.  
  87. '******************************************************************************
  88. ' SUBs and FUNCTIONs
  89. '******************************************************************************
  90.  
  91.  
  92. '******************************************************************************
  93. 'SUB Initialize opens the log and result files and starts the target application
  94. '******************************************************************************
  95. Sub Initialize () Static
  96.   xDeleteFileIfExists RESULT_FILE
  97.   xSetLogOptions LOG_DISK
  98.   xSetLogFileName RESULT_FILE
  99.   xStartApp PROGRAM_NAME, ""
  100. End Sub
  101.  
  102.  
  103. '******************************************************************************
  104. 'SUB StartLog writes the current test name to the log and result files
  105. '******************************************************************************
  106. Sub StartLog (testName$) Static
  107.   xAppendFile LOG_FILE, testName$
  108.   xLog testName$
  109. End Sub
  110.  
  111.  
  112. '******************************************************************************
  113. 'SUB EndLog writes pass/fail information to the log file and specific results
  114. 'to the result file (if any).
  115. '******************************************************************************
  116. Sub EndLog (logFile$, resultFile$) Static
  117.   XAppendFile LOG_FILE, logFile$
  118.   If resultFile$ <> "" Then
  119.     xLogFailure resultFile$
  120.   Else
  121.     xLog logFile$
  122.   End If
  123. End Sub
  124.  
  125.  
  126. '******************************************************************************
  127. 'SUB Cleanup closes the target application and log and result files
  128. '******************************************************************************
  129. Sub CleanUp () Static
  130.   hWnd% = WFndWnd(PROGRAM_TITLE, FW_PART Or FW_NOFOCUS Or FW_NOCASE)
  131.   If hWnd% <> 0 and WSysMenuExists(hWnd%) Then
  132.     wSysMenu(hWnd%)
  133.     WMenu SYSMENU_CLOSE
  134.   End If
  135.   Close
  136. End Sub
  137.  
  138.  
  139.  
  140. '******************************************************************************
  141. 'SUB FileNewClear calls SUB DoCommand to choose the "New" option from the
  142. '"File" menu without saving any changes.
  143. '******************************************************************************
  144. Sub FileNewClear () Static
  145.   xSelectMenuItem FILE_MENU, FILE_NEW, ""
  146.   If BDialogBoxExists(PROGRAM_TITLE) Then
  147.     xAlt K_NO
  148.   End If
  149. End Sub
  150.  
  151.  
  152. '******************************************************************************
  153. 'FUNCTION FileOpen chooses the "Open" option from the "File" menu to open an
  154. 'existing file.
  155. '******************************************************************************
  156. Sub FileOpen (fileName$) Static
  157.   xSelectMenuItem FILE_MENU, FILE_OPEN, ""
  158.   xEnter fileName$
  159. End Sub
  160.  
  161.  
  162. '******************************************************************************
  163. 'FUNCTION FileExit chooses the "Exit" option from the "File" menu to exit the
  164. 'target application, answering the save file dialog(s) if necessary.
  165. '******************************************************************************
  166. Function FileExit (YesNoCancel$, fileName$, replace%) Static As Integer
  167.   xSelectMenuItem FILE_MENU, FILE_EXIT, ""
  168.   result% = SaveFile (YesNoCancel$, fileName$, replace%)
  169.   FileExit = result%
  170. End Function
  171.  
  172.  
  173. '******************************************************************************
  174. 'FUNCTION SaveFile answers the appropriate file save dialog(s) if they exist
  175. '(determined by using the TESTCTRL routines WFndWnd and WFndWndC).
  176. '******************************************************************************
  177. Function SaveFile (YesNoCancel$, fileName$, replace%) Static As Integer
  178.  
  179.   SaveFile = SUCCESS
  180.  
  181.   'Check to see if Notepad is prompting to save the current file
  182.   If BDialogBoxExists(PROGRAM_TITLE) Then
  183.     If YesNoCancel$ <> K_CANCEL Then
  184.       xAlt YesNoCancel$
  185.     Else
  186.       xKey YesNoCancel$
  187.     End if
  188.  
  189.     'K_YES indicates we want to save current file - respond to Save dialog
  190.     If YesNoCancel$ = K_YES Then
  191.       If WFndWnd(SAVE_AS_DIALOG_TITLE, FW_PART Or FW_NOFOCUS Or FW_NOCASE) Then
  192.         xEnter fileName$
  193.  
  194.         'Check to see if we are saving over an existing file
  195.         If BDialogBoxExists(PROGRAM_TITLE) Then
  196.           If replace% Then
  197.             xAlt K_YES
  198.             SaveFile = R_REPLACED
  199.           Else
  200.             xAlt K_NO
  201.             SaveFile = R_REPLACEABORT
  202.           End If
  203.         End If
  204.       Else
  205.         SaveFile = R_ERRORNODIALOG
  206.       End If
  207.     End If
  208.   Else
  209.     SaveFile = R_NODIALOG
  210.   End If
  211. End Function
  212.  
  213.  
  214. '******************************************************************************
  215. 'SUB EditCut Chooses the "Cut" option from the "Edit" menu to copy the currently
  216. 'selected text from the application's edit field to the cipboard.
  217. '******************************************************************************
  218. Sub EditCut () Static
  219.   xSelectMenuItem EDIT_MENU, EDIT_CUT, ""
  220. End Sub
  221.  
  222.  
  223. '******************************************************************************
  224. 'SUB EditPaste Chooses the "Paste" option from the "Edit" menu to copy the
  225. 'currently clipboard contents to the application's edit field.
  226. '******************************************************************************
  227. Sub EditPaste () Static
  228.   xSelectMenuItem EDIT_MENU, EDIT_PASTE, ""
  229. End Sub
  230.  
  231.  
  232. '******************************************************************************
  233. 'FUNCTION SrchFind Chooses the "Find" option from the "Search" menu to attempt
  234. 'to locate the specified text in the target applications edit field.  If the
  235. 'application dialog indicating Find failed does not exist, the text selected by
  236. 'Find is Cut to the clipboard and compared with the target$.
  237. '******************************************************************************
  238. Function SrchFind (target$) Static As Integer
  239.  
  240.   xSelectMenuItem SEARCH_MENU, SEARCH_FIND, ""
  241.   xEnter target$
  242.  
  243.   If BDialogBoxExists(PROGRAM_TITLE) Then
  244.     SrchFind = R_NOTFOUND
  245.     xEnter ""
  246.     If BDialogBoxExists(FIND_DIALOG_TITLE) Then
  247.       xKey K_CANCEL
  248.     End If
  249.   Else
  250.     If BDialogBoxExists(FIND_DIALOG_TITLE) Then
  251.       xKey K_CANCEL
  252.     End If
  253.     EditCut
  254.     If BClipBoardCmp(target$) Then
  255.       SrchFind = SUCCESS
  256.     Else
  257.       SrchFind = R_ERRORNODIALOG
  258.     End If
  259.   End If
  260.  
  261. End Function
  262.  
  263.  
  264. '******************************************************************************
  265. 'FUNCTION VerifyEditAndClipBoard checks that the application edit field (current
  266. 'text is retrieved using TESTCTRLs EditText() function) and the clipboard both
  267. 'contain the specified text.  Since the target application does not have a label
  268. 'control associated with its main edit field, an empty string is passed to
  269. 'EditText();  this will fail if the application edit control does not have the
  270. 'focus at the time VerifyEditAndClipboard is called.
  271. '******************************************************************************
  272. Function VerifyEditAndClipboard (editStr$, clipStr$) Static As Integer
  273.  
  274.     If BEditTextExists(editStr$) Then
  275.       If BClipBoardCmp(clipStr$) Then
  276.         VerifyEditAndClipboard = R_CLIPNOMATCH Or R_EDITNOMATCH
  277.       Else
  278.         VerifyEditAndClipboard = R_EDITNOMATCH
  279.       End If
  280.     Else
  281.       If Not BClipBoardCmp(clipStr$) Then
  282.         VerifyEditAndClipboard = R_CLIPNOMATCH
  283.       Else
  284.         VerifyEditAndClipboard = SUCCESS
  285.       End If
  286.     End If
  287.  
  288. End Function
  289.  
  290.