home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / d / d009_2 / 1.ddi / SAMPLES / GENERAL / TUTOR.MS$ / TUTOR.bin
Encoding:
Text File  |  1992-02-12  |  8.4 KB  |  284 lines

  1. '******************************** TUTOR.MST  **********************************
  2. 'Demonstrates:  This will test several components of the Windows WRITE.EXE.
  3. '
  4. 'Required Files: MSTEST.INC, WRITE.EXE
  5. '
  6. 'Uses: TESTSCRN, TESTCTRL, TESTEVENT.
  7. '
  8. 'Complexity Level: INTRODUCTORY
  9. '
  10. 'Notes: Assumes WRITE.EXE is in the PATH.  This example also creates a screen
  11. '       image file (TUTOR.WTS) to demonstrate TESTSCRN.
  12. '
  13. '******************************************************************************
  14.  
  15. Declare Sub Init
  16. Declare Sub Windows
  17. Declare Sub Menus
  18. Declare Sub EnterData
  19. Declare Sub Dialogs
  20. Declare Sub TestBold
  21. Declare Sub EndTest
  22.  
  23. '******************************************************************************
  24. ' CONST
  25. '******************************************************************************
  26.  
  27. Const AppName$ = "Write"
  28.  
  29. Global WinHandle%, logfile%, ErrCount, MenuName$(7)
  30.  
  31. '******************************************************************************
  32. ' DEFINES
  33. '******************************************************************************
  34.  
  35. '$DEFINE TESTSCRN
  36. '$DEFINE TESTCTRL
  37. '$DEFINE TESTEVNT
  38.  
  39. '******************************************************************************
  40. ' INCLUDES
  41. '******************************************************************************
  42.  
  43. '$INCLUDE 'mstest.inc'
  44.  
  45. '******************************************************************************
  46. ' Main program code
  47. '******************************************************************************
  48.  
  49. ON ERROR GOTO ErrorTrap
  50.  
  51.    Init            '*** Initialize logging, global constants.
  52.    Windows         '*** Test various windowing features of app.
  53.    Menus           '*** Test various menus.
  54.    EnterData       '*** Show keystrokes.
  55.    Dialogs         '*** Test the save dialog.
  56.    TestBold        '*** Demonstrate saving screen image.
  57.    EndTest         '*** Shut down.
  58.  
  59. END
  60.  
  61. '******************************************************************************
  62. ' TRAPS
  63. '******************************************************************************
  64.  
  65. ErrorTrap:
  66.  
  67.    SELECT CASE Err
  68.       CASE ERR_INVALID_PATH
  69.          PRINT "Path not found.  Error number ", Err
  70.          PRINT " on line ", ERL
  71.          PRINT " in script ", ERF
  72.          PRINT ERROR$        ' The error message.
  73.          END
  74.      CASE ERR_CANT_OPEN_FILE
  75.         PRINT "Can't Open File.  Error number ", Err
  76.         PRINT " on line ", ERL
  77.         PRINT " in script ", ERF
  78.         PRINT ERROR$        ' The error message.
  79.         END
  80.      CASE ELSE
  81.         PRINT "Unexpected error: Number ", Err
  82.         PRINT " on line ", ERL
  83.         PRINT " in script ", ERF
  84.         PRINT ERROR$        ' The error message.
  85.         END
  86.    END SELECT
  87.  
  88.  
  89. '******************************************************************************
  90. ' SUBs and FUNCTIONs
  91. '******************************************************************************
  92.  
  93.  
  94.  
  95. '******************************************************************************
  96. ' SUB Init sets up several variables that are used thoughout the test.
  97. '******************************************************************************
  98. SUB Init STATIC
  99.  
  100.    ErrCount = 0
  101.    logfile = FREEFILE
  102.    MenuName(0) = "&File"
  103.    MenuName(1) = "&Edit"
  104.    MenuName(2) = "&Search"
  105.    MenuName(3) = "&Character"
  106.    MenuName(4) = "&Paragraph"
  107.    MenuName(5) = "&Document"
  108.    MenuName(6) = "&Help"
  109.  
  110.    'Set log file and write header to file.
  111.  
  112.    PRINT, "**********************************************"
  113.    PRINT, "STARTING TEST OF WRITE.EXE APPLICATION"
  114.    PRINT, "       " + DATETIME$
  115.    PRINT, "**********************************************"
  116.  
  117.    'Run the Windows WRITE.EXE program and get its window handle.
  118.  
  119.    RUN AppName$, NOWAIT
  120.    WinHandle = WGetActWnd(0)
  121.  
  122. END SUB
  123.  
  124. '******************************************************************************
  125. ' SUB Window will size WRITE and set it's position.
  126. '******************************************************************************
  127.  
  128. SUB Windows STATIC
  129.  
  130.    DIM i%
  131.  
  132.    'Position and size the form.
  133.  
  134.    WSetWndPos WinHandle, 50, 50
  135.    WSetWndSiz WinHandle, 300, 200
  136.  
  137.    'Adjust the window to several locations.
  138.  
  139.    For i = 1 to 10
  140.       WAdjWndSiz WinHandle, 4*i, 4*i
  141.    Next i
  142.  
  143.    'Maximize the window.
  144.  
  145.    WMaxWnd WinHandle
  146.    WMinWnd WinHandle
  147.    WResWnd WinHandle
  148.  
  149. END SUB
  150.  
  151. '******************************************************************************
  152. ' SUB Menu will check to see if the correct amount of menus exist and check
  153. ' to see if they are Enabled correctly.
  154. '******************************************************************************
  155.  
  156. SUB Menus STATIC
  157.    DIM i%, ret%
  158.  
  159.    'Determine if there are seven menus.
  160.  
  161.    IF WMenuCount() <> 7 THEN
  162.       PRINT, "Wrong Number of menu items"
  163.       ErrCount = ErrCount + 1
  164.    ENDIF
  165.  
  166.    For i = 1 to 7
  167.  
  168.       'Check to see if the names are correct.  This example will fail
  169.       'for Windows 3.1 WRITE.EXE, since the "&Search" menu was changed
  170.       'to the "Fi&nd" menu.
  171.       IF WMenuExists(MenuName(i-1)) = FALSE  THEN
  172.          PRINT,  "Menu item does not exist..."
  173.          ErrCount = ErrCount + 1
  174.       ENDIF
  175.  
  176.       'Make sure they are all Enabled.
  177.       IF WMenuEnabled(MenuName(i-1)) = FALSE THEN
  178.          PRINT, "Menu item not enabled..." + MenuName(i-1)
  179.          ErrCount = ErrCount + 1
  180.       ENDIF
  181.  
  182.    Next i
  183.  
  184. END SUB
  185.  
  186. '******************************************************************************
  187. ' SUB EnterData will enter text into the WRITE document.
  188. '******************************************************************************
  189.  
  190. SUB EnterData STATIC
  191.  
  192.    DoKeys "Uppercase letters from A to Z:  ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  193.    DoKeys "{ENTER}"
  194.    DoKeys "Lowercase letters from a to z:  abcdefghijklmnopqrstuvwxyz"
  195.    DoKeys "{ENTER}"
  196.    DoKeys "Numbers from 0 to 9:  0123456789"
  197.    DoKeys "{ENTER}"
  198.    DoKeys "Numbers from 9 to 0:  9876543210"
  199.    DoKeys "{ENTER}"
  200.  
  201. END SUB
  202.  
  203. '******************************************************************************
  204. ' SUB Dialogs brings up the Goto Page and checks to see if the items of the
  205. ' dialog box are correct.
  206. '******************************************************************************
  207.  
  208. SUB Dialogs STATIC
  209.  
  210.   'Hot Key for the "Goto Page" dialog box.
  211.    DoKeys "{F4}"
  212.  
  213.   'Check to see that the buttons exist and are Enabled.
  214.    ret% = WButtonExists("OK")
  215.    ret% = WButtonExists("Cancel")
  216.    ret% = WButtonEnabled("OK")
  217.  
  218.    'Make sure there is a "Page Number" label.
  219.    IF WEditExists("&Page Number:") = FALSE THEN
  220.       PRINT, "Goto Page dialog box - edit box name incorrect"
  221.       ErrCount = ErrCount + 1
  222.    ENDIF
  223.  
  224.    'Check to see if the edit box contains "1".
  225.    IF EditSelText("&Page Number:") <> "1" THEN
  226.       PRINT, "Goto Page dialog box edit text incorrect"
  227.       ErrCount = ErrCount + 1
  228.    ENDIF
  229.  
  230.    'Close the dialog box.
  231.    WButtonClick "Cancel"
  232.  
  233. END SUB
  234.  
  235. '******************************************************************************
  236. ' SUB TestBold will demonstrate how to save an image to file and then later
  237. ' compare the image to another screen.
  238. '******************************************************************************
  239.  
  240. SUB TestBold STATIC
  241.  
  242.    ret% = fDumpWindow("tutor.wts",WinHandle,0,0,FALSE)
  243.  
  244.    DoKeys "^{HOME}"    'Goto beginning of file.
  245.    DoKeys "+{END}"     'Select the first line (SHIFT + END).
  246.    DoKeys "^B"         'Make the first line bold (CTRL + B).
  247.  
  248.    IF fCompWindow("tutor.wts", WinHandle, 0, FALSE, FALSE) = 0 THEN
  249.       PRINT, "Bold failed..."
  250.       ErrCount = ErrCount + 1
  251.    ENDIF
  252.  
  253. END SUB
  254.  
  255.  
  256. '******************************************************************************
  257. ' SUB EndTest will save the output of the WRITE.EXE document.  If TUTOR.WRI
  258. ' exists, the you will need to overwrite the file, else just save the file.
  259. '******************************************************************************
  260.  
  261. SUB EndTest STATIC
  262.  
  263.    IF NOT EXISTS("tutor.wri") THEN
  264.       DoKeys "%FX"
  265.       DoKeys "y"
  266.       DoKeys "tutor.wri"
  267.       WButtonClick "OK"
  268.    ELSE
  269.       DoKeys "%FX"
  270.       DoKeys "y"
  271.       DoKeys "tutor.wri"
  272.       WButtonClick "OK"
  273.       DoKeys "y"
  274.    END IF
  275.  
  276.    PRINT, "**********************************************"
  277.    PRINT, "SUCCESSFULLY COMPLETED WRITE.EXE TEST"
  278.    PRINT, "       " + DATETIME$
  279.    PRINT, "Total of ", ErrCount, " errors detected"
  280.    PRINT, "**********************************************"
  281.  
  282. END SUB
  283.  
  284.