home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / d / d009_2 / 1.ddi / FTESTUTL.MS$ / FTESTUTL.bin
Encoding:
Text File  |  1992-02-03  |  25.9 KB  |  1,205 lines

  1. 'FTESTUtl.inc - definitions for Fast Test Utility routines
  2. '
  3. '  Copyright (c) 1991-1992, Microsoft Corporation. All rights reserved.
  4. '
  5. 'Purpose:
  6. ' This file defines the utility functions of the Fast Test functionality
  7. '
  8. 'NOTES:
  9. ' See FASTTEST.INC for description of the Error catching that is coded
  10. ' throughout this module.
  11.  
  12.  
  13. '**********************************************************
  14. '***************** File Subroutines ***********************
  15. '**********************************************************
  16.  
  17.  
  18. '
  19. ' XFileExists(stFileSpec$)
  20. '
  21. ' Description:
  22. '       Checks that stFileSpec$  exists.
  23. '       logs a failure if it can't find it (them; accept wildcards)
  24. '
  25. ' Parameters:
  26. '       stFileSpec$  - file specification
  27. '
  28. ' Returns:
  29. '       nothing
  30. '
  31. ' Example:
  32. '       XFileExists "*.bak"
  33. '
  34. '
  35. SUB XFileExists(stFileSpec$) STATIC
  36.     IF NOT EXISTS(stFileSpec$) THEN
  37.         XLogFailure stFileSpec$ + " doesn't exist"
  38.     END IF
  39. END SUB
  40.  
  41. '
  42. ' XFileNotExists(stFileSpec$)
  43. '
  44. ' Description:
  45. '       Checks that stFileSpec$ doesn't exist.
  46. '       logs a failure if it finds it (them; accepts wildcards)
  47. '
  48. ' Parameters:
  49. '       stFileSpec$  - file specification
  50. '
  51. ' Returns:
  52. '       nothing
  53. '
  54. ' Example:
  55. '       XFileNotExists "*.bak"
  56. '
  57. '
  58. SUB XFileNotExists(stFileSpec$) STATIC
  59.     IF EXISTS(stFileSpec$) THEN
  60.         XLogFailure stFileSpec$ + " exists"
  61.     END IF
  62. END SUB
  63.  
  64. '
  65. ' BFileExists(stFileSpec$)
  66. '
  67. ' Description:
  68. '       Checks if stFileSpec$ exists
  69. '
  70. ' Parameters:
  71. '       stFileSpec$  - file specification
  72. '
  73. ' Returns:
  74. '       TRUE if it exists, FALSE if not
  75. '
  76. '
  77. '
  78. FUNCTION BFileExists%(stFileSpec$) STATIC
  79.     BFileExists = EXISTS(stFileSpec$)
  80. END FUNCTION
  81.  
  82.  
  83. '
  84. ' XFileCmp(stFileSpec1$,stFileSpec2$)
  85. '
  86. ' Description:
  87. '       Compares two files, line by line
  88. '       Logs a Failure if the files don't exist or are different
  89. '
  90. ' Parameters:
  91. '       stFileSpec1$,stFileSpec2  - file specifications
  92. '
  93. ' Returns:
  94. '       nothing
  95. '
  96. ' Example:
  97. '       XFileCmp "Foo.dat","foo.bsl"
  98. '
  99. '
  100. '
  101. SUB XFileCmp(stFileSpec1$,stFileSpec2$) STATIC
  102.     DIM fh1%    ' file handle of first file
  103.     DIM fh2%    ' file handle of second file
  104.     DIM line1$  ' line from first file
  105.     DIM line2$  ' line from second file
  106.     DIM done    ' flag to stop looping
  107.     DIM diff    ' flag to indicate if files compare
  108.  
  109.     gErrorType = ET_NEXT
  110.     fh1% = FREEFILE
  111.     OPEN stFileSpec1$ FOR INPUT AS #fh1%
  112.     fh2% = FREEFILE
  113.     OPEN stFileSpec2$ FOR INPUT AS #fh2%
  114.  
  115.     IF gfError THEN
  116.         XLogFailure "Could not open files for XFileCmp"
  117.         gErrorType = ET_NOTHING
  118.         gfError = FALSE
  119.         EXIT SUB
  120.     END IF
  121.  
  122.  
  123.     done = FALSE
  124.     diff = FALSE
  125.  
  126.     IF EOF(fh1%) AND EOF(fh2%) THEN
  127.         done = TRUE
  128.  
  129.     ELSEIF EOF(fh1%) OR EOF(fh2%) THEN
  130.         diff = TRUE
  131.         done = TRUE
  132.     END IF
  133.  
  134.  
  135.     WHILE NOT done
  136.  
  137.         LINE INPUT #fh1%,line1$
  138.         LINE INPUT #fh2%,line2$
  139.  
  140.         IF gfError THEN
  141.             XLogFailure "XFileCmp INPUT or EOF errors"
  142.             gErrorType = ET_NOTHING
  143.             gfError = FALSE
  144.             EXIT SUB
  145.         END IF
  146.  
  147.  
  148.         IF line1$ <> line2$ THEN
  149.             done = TRUE
  150.             diff = TRUE
  151.         END IF
  152.  
  153.         IF NOT done AND EOF(fh1%) AND EOF(fh2%) THEN
  154.             done = TRUE
  155.         END IF
  156.  
  157.         IF NOT done AND (EOF(fh1%) OR EOF(fh2%)) THEN
  158.             diff = TRUE
  159.             done = TRUE
  160.         END IF
  161.  
  162.     WEND
  163.  
  164.     CLOSE #fh1%
  165.     CLOSE #fh2%
  166.  
  167.     IF gfError THEN
  168.         XLogFailure "XFileCmp CLOSE errors"
  169.         gErrorType = ET_NOTHING
  170.         gfError = FALSE
  171.         EXIT SUB
  172.     END IF
  173.  
  174.     gErrorType = ET_NOTHING
  175.  
  176.     IF diff THEN
  177.         XLogFailure "Files " + stFileSpec1$ + "," + stFileSpec2$ + " don't compare"
  178.     END IF
  179.  
  180. END SUB
  181.  
  182. '
  183. ' XFileNotCmp(stFileSpec1$,stFileSpec2$)
  184. '
  185. ' Description:
  186. '       Compares two files, line by line
  187. '       Logs a Failure if the files don't exist or are same
  188. '
  189. ' Parameters:
  190. '       stFileSpec1$,stFileSpec2  - file specifications
  191. '
  192. ' Returns:
  193. '       nothing
  194. '
  195. ' Example:
  196. '       XFileNotCmp "Foo.dat","foo.bsl"
  197. '
  198. '
  199. '
  200. SUB XFileNotCmp(stFileSpec1$,stFileSpec2$) STATIC
  201.     DIM fh1%    ' file handle of first file
  202.     DIM fh2%    ' file handle of second file
  203.     DIM line1$  ' line from first file
  204.     DIM line2$  ' line from second file
  205.     DIM done    ' flag to stop looping
  206.     DIM diff    ' flag to indicate if files compare
  207.  
  208.     gErrorType = ET_NEXT
  209.  
  210.     fh1% = FREEFILE
  211.     OPEN stFileSpec1$ FOR INPUT AS #fh1%
  212.     fh2% = FREEFILE
  213.     OPEN stFileSpec2$ FOR INPUT AS #fh2%
  214.  
  215.     IF gfError THEN
  216.         XLogFailure "Could not open files for XFileNotCmp"
  217.         gErrorType = ET_NOTHING
  218.         gfError = FALSE
  219.         EXIT SUB
  220.     END IF
  221.  
  222.     done = FALSE
  223.     diff = FALSE
  224.  
  225.     IF EOF(fh1%) AND EOF(fh2%) THEN
  226.         done = TRUE
  227.     END IF
  228.  
  229.     IF NOT done AND (EOF(fh1%) OR EOF(fh2%)) THEN
  230.         diff = TRUE
  231.         done = TRUE
  232.     END IF
  233.  
  234.     WHILE NOT done
  235.  
  236.         LINE INPUT #fh1%,line1$
  237.         LINE INPUT #fh2%,line2$
  238.  
  239.         IF gfError THEN
  240.             XLogFailure "XFileNotCmp INPUT or EOF errors"
  241.             gErrorType = ET_NOTHING
  242.             gfError = FALSE
  243.             EXIT SUB
  244.         END IF
  245.  
  246.         IF line1$ <> line2$ THEN
  247.             done = TRUE
  248.             diff = TRUE
  249.         END IF
  250.  
  251.         IF NOT done AND EOF(fh1%) AND EOF(fh2%) THEN
  252.             done = TRUE
  253.         END IF
  254.  
  255.         IF NOT done AND (EOF(fh1%) OR EOF(fh2%)) THEN
  256.             diff = TRUE
  257.             done = TRUE
  258.         END IF
  259.  
  260.     WEND
  261.  
  262.     CLOSE #fh1%
  263.     CLOSE #fh2%
  264.  
  265.     IF gfError THEN
  266.         XLogFailure "XFileNotCmp CLOSE errors"
  267.         gErrorType = ET_NOTHING
  268.         gfError = FALSE
  269.         EXIT SUB
  270.     END IF
  271.  
  272.     gErrorType = ET_NOTHING
  273.  
  274.     IF NOT diff THEN
  275.         XLogFailure "Files " + stFileSpec1$ + "," + stFileSpec2$ + " do compare"
  276.     END IF
  277. END SUB
  278.  
  279. '
  280. ' BFileCmp%(stFileSpec1$,stFileSpec2$)
  281. '
  282. ' Description:
  283. '       Compares two files, line by line
  284. '       Logs a Failure if the files don't exist
  285. '
  286. ' Parameters:
  287. '       stFileSpec1$,stFileSpec2  - file specifications
  288. '
  289. ' Returns:
  290. '       FALSE IF XFileCmp would detect an error
  291. '
  292. ' Example:
  293. '       x% = BFileCmp "Foo.dat","foo.bsl"
  294. '
  295. '
  296. '
  297. FUNCTION BFileCmp%(stFileSpec1$,stFileSpec2$) STATIC
  298.     DIM fh1%
  299.     DIM fh2%
  300.     DIM line1$
  301.     DIM line2$
  302.     DIM done
  303.     DIM diff
  304.  
  305.     gErrorType = ET_NEXT
  306.     fh1% = FREEFILE
  307.     OPEN stFileSpec1$ FOR INPUT AS #fh1%
  308.     fh2% = FREEFILE
  309.     OPEN stFileSpec2$ FOR INPUT AS #fh2%
  310.  
  311.     IF gfError THEN
  312.         BFileCmp = FALSE
  313.         gErrorType = ET_NOTHING
  314.         gfError = FALSE
  315.         EXIT FUNCTION
  316.     END IF
  317.  
  318.     done = FALSE
  319.     diff = FALSE
  320.  
  321.     IF EOF(fh1%) AND EOF(fh2%) THEN
  322.         done = TRUE
  323.     END IF
  324.  
  325.     IF NOT done AND (EOF(fh1%) OR EOF(fh2%)) THEN
  326.         diff = TRUE
  327.         done = TRUE
  328.     END IF
  329.  
  330.     WHILE NOT done
  331.  
  332.         LINE INPUT #fh1%,line1$
  333.         LINE INPUT #fh2%,line2$
  334.  
  335.         IF gfError THEN
  336.             BFileCmp = FALSE
  337.             gErrorType = ET_NOTHING
  338.             gfError = FALSE
  339.             EXIT FUNCTION
  340.         END IF
  341.  
  342.         IF line1$ <> line2$ THEN
  343.             done = TRUE
  344.             diff = TRUE
  345.         END IF
  346.  
  347.         IF NOT done AND EOF(fh1%) AND EOF(fh2%) THEN
  348.             done = TRUE
  349.         END IF
  350.  
  351.         IF NOT done AND (EOF(fh1%) OR EOF(fh2%)) THEN
  352.             diff = TRUE
  353.             done = TRUE
  354.         END IF
  355.  
  356.     WEND
  357.  
  358.     CLOSE #fh1%
  359.     CLOSE #fh2%
  360.  
  361.     IF gfError THEN
  362.         BFileCmp = FALSE
  363.         gErrorType = ET_NOTHING
  364.         gfError = FALSE
  365.         EXIT FUNCTION
  366.     END IF
  367.  
  368.     BFileCmp = NOT diff    ' IF different a log failure would normally happen
  369.  
  370. END FUNCTION
  371.  
  372.  
  373. '
  374. ' XDeleteFile(stFileSpec$)
  375. '
  376. ' Description:
  377. '       Will delete stFileSpec$ if it, they, exists.
  378. '       logs a failure if it can't delete them or if the file(s)
  379. '       doesn't exist
  380. '
  381. ' Parameters:
  382. '       stFileSpec$  - file specification
  383. '
  384. ' Returns:
  385. '       nothing
  386. '
  387. ' Example:
  388. '       XDeleteFile "*.bak"
  389. '
  390. '
  391. SUB XDeleteFile(stFileSpec$) STATIC
  392.     IF EXISTS(stFileSpec$) THEN
  393.         gErrorType = ET_NEXT
  394.         KILL stFileSpec$
  395.         IF gfError THEN
  396.             XLogFailure "XDeleteFile " + stFileSpec$ + " could NOT be deleted"
  397.             gfError = FALSE
  398.         END IF
  399.         gErrorType = ET_NOTHING
  400.     ELSE
  401.         XLogFailure "XDeleteFile " + stFileSpec$ + " NOT deleted (doesn't exist)."
  402.     END IF
  403. END SUB
  404.  
  405. '
  406. ' XDeleteFileIfExists(stFileSpec$)
  407. '
  408. ' Description:
  409. '       Will delete stFileSpec$ if it, they, exists.
  410. '       logs a failure if it can't delete them but doesn't if the file(s)
  411. '       doesn't exist
  412. '
  413. ' Parameters:
  414. '       stFileSpec$  - file specification
  415. '
  416. ' Returns:
  417. '       nothing
  418. '
  419. ' Example:
  420. '       XDeleteFileIfExists "*.bak"
  421. '
  422. '
  423. SUB XDeleteFileIfExists(stFileSpec$) STATIC
  424.     IF EXISTS(stFileSpec$) THEN
  425.         gErrorType = ET_NEXT
  426.         KILL stFileSpec$
  427.         IF gfError THEN
  428.             XLogFailure "XDeleteFileIfExists " + stFileSpec$ + " could NOT be deleted"
  429.             gfError = FALSE
  430.         END IF
  431.         gErrorType = ET_NOTHING
  432.     END IF
  433. END SUB
  434.  
  435. '
  436. ' XCreateFile(stFileSpec$,s$)
  437. '
  438. ' Description:
  439. '       Will Create stFileSpec$ and put string in it
  440. '       logs a failure if it can't Create it
  441. '
  442. ' Parameters:
  443. '       stFileSpec$  - file specification
  444. '
  445. ' Returns:
  446. '       nothing
  447. '
  448. ' Example:
  449. '       XCreateFile "foo.dat","Hello world"
  450. '
  451. '
  452. '
  453.  
  454. SUB XCreateFile(stFileSpec$,s$) STATIC
  455.     DIM fh%
  456.     gErrorType = ET_NEXT
  457.     fh% = FREEFILE
  458.  
  459.     OPEN stFileSpec$ FOR OUTPUT AS #fh%
  460.  
  461.     PRINT #fh%,s$       ' put the string in the file
  462.  
  463.     CLOSE #fh%
  464.  
  465.     IF gfError THEN
  466.         XLogFailure "XCreateFile encountered runtime errors"
  467.         gfError = FALSE
  468.     END IF
  469.     gErrorType = ET_NOTHING
  470.  
  471. END SUB
  472.  
  473. '
  474. ' XAppendFile(stFileSpec$,s$)
  475. '
  476. ' Description:
  477. '       Will Append stFileSpec$ and put string in it
  478. '       logs a failure if it can't Append it
  479. '
  480. ' Parameters:
  481. '       stFileSpec$  - file specification
  482. '
  483. ' Returns:
  484. '       nothing
  485. '
  486. ' Example:
  487. '       XAppendFile "foo.dat","Hello world"
  488. '
  489. '
  490. '
  491.  
  492. SUB XAppendFile(stFileSpec$,s$) STATIC
  493.     DIM fh%
  494.  
  495.     gErrorType = ET_NEXT
  496.  
  497.     fh% = FREEFILE
  498.  
  499.     OPEN stFileSpec$ FOR APPEND AS #fh%
  500.  
  501.     PRINT #fh%,s$       ' put the string in the file
  502.  
  503.     CLOSE #fh%
  504.  
  505.     IF gfError THEN
  506.         XLogFailure "XAppendFile encountered runtime errors"
  507.         gfError = FALSE
  508.     END IF
  509.     gErrorType = ET_NOTHING
  510.  
  511. END SUB
  512.  
  513.  
  514. '
  515. ' XWaitMessageFile(s$,Message$,WaitTime%)
  516. '
  517. ' Description:
  518. '       Wait for file to exist, only wait up to given time,
  519. '       check if string is in file (if string is non-empty)
  520. '       logs a failure if the files doesn't exist, or when
  521. '       it does and the string isn't in it.
  522. '
  523. ' Parameters:
  524. '       s$    - file specification
  525. '       Message$  - the string to look for
  526. '       WaitTime% - the longest to wait
  527. '
  528. ' Returns:
  529. '       nothing
  530. '
  531. ' Example:
  532. '       XWaitMessageFile "foo.dat","Hello world",20
  533. '
  534. '
  535. '
  536.  
  537. SUB XWaitMessageFile(s$,Message$, WaitTime%) STATIC
  538.  
  539.     DIM fDone%      ' flag to stop looping
  540.     DIM fFound%     ' flag to indicate if file found
  541.     DIM lineIn$       ' line from file
  542.     DIM inret%      ' return from INSTR
  543.     DIM fh%         ' File handle
  544.  
  545.     fDone = FALSE
  546.     fFound = FALSE
  547.  
  548.     WHILE NOT fDone
  549.  
  550.         IF EXISTS(s$) THEN
  551.             fDone = TRUE
  552.             fFound = TRUE
  553.         ELSE
  554.             SLEEP 1
  555.  
  556.             WaitTime% = WaitTime% - 1
  557.             IF WaitTime% <= 0 THEN
  558.                 fDone = TRUE
  559.             END IF
  560.         END IF
  561.     WEND
  562.  
  563.     IF NOT fFound% THEN
  564.         XLogFailure "FAIL """ + s$ + """ Message File not found"
  565.     ELSE
  566.  
  567.         IF Message$ = "" THEN
  568.             ' don't bother searching if no string given
  569.             EXIT SUB
  570.         END IF
  571.  
  572.         fDone = FALSE
  573.         fFOUND = FALSE
  574.  
  575.         gErrorType = ET_NEXT
  576.  
  577.         fh% = FREEFILE
  578.  
  579.         OPEN s$ FOR INPUT AS # fh%
  580.  
  581.         IF EOF(fh%) THEN
  582.             fDone% = TRUE
  583.         END IF
  584.  
  585.         IF gfError THEN
  586.             XLogFailure "XWaitMessageFile encountered runtime error during OPEN"
  587.             gErrorType = ET_NOTHING
  588.             gfError = FALSE
  589.             EXIT SUB
  590.         END IF
  591.  
  592.         WHILE NOT fDone%
  593.  
  594.             LINE INPUT # fh%, lineIn$
  595.  
  596.             IF gfError THEN
  597.                 XLogFailure "XWaitMessageFile encountered runtime error during INPUT"
  598.                 gErrorType = ET_NOTHING
  599.                 gfError = FALSE
  600.                 EXIT SUB
  601.             END IF
  602.  
  603.             inret% = INSTR(lineIn$,Message$)
  604.  
  605.             IF inret% <> 0 THEN
  606.                 fFound% = TRUE
  607.                 fDone = TRUE
  608.             END IF
  609.  
  610.             IF EOF(fh%) THEN
  611.                 fDone% = TRUE
  612.             END IF
  613.         WEND
  614.  
  615.         CLOSE # fh%
  616.  
  617.         IF gfError THEN
  618.             XLogFailure "XWaitMessageFile encountered runtime error during CLOSE"
  619.             gErrorType = ET_NOTHING
  620.             gfError = FALSE
  621.             EXIT SUB
  622.         END IF
  623.         gErrorType = ET_NOTHING
  624.  
  625.         IF NOT fFound% THEN
  626.             XLogFailure "FAIL, found """ + s$ + """ Message File, """ + Message$ + """ not in it"
  627.         END IF
  628.     END IF
  629. END SUB
  630.  
  631. '**********************************************************
  632. '***************** Directory Subroutines ******************
  633. '**********************************************************
  634.  
  635. '
  636. ' XCWDCmp(s$)
  637. '
  638. ' Description:
  639. '       Compare the current working directory and log error if it
  640. '       doesn't match the expected value
  641. '
  642. ' Parameters:
  643. '       s$ - the expected value for the current directory
  644. '
  645. ' Returns:
  646. '       nothing
  647. '
  648. ' Example:
  649. '       XCWDCmp "c:\tests"
  650. '
  651.  
  652. SUB XCWDCmp(s$) STATIC
  653.  
  654.     IF BCWDCmp(s$) = 0 THEN
  655.         XLogFailure "Current working directory (" + UCASE$(CURDIR$) + ") doesn't match " + UCASE$(s$)
  656.     END IF
  657. END SUB
  658.  
  659. '
  660. ' XCWDNotCmp(s$)
  661. '
  662. ' Description:
  663. '       Compare the current working directory and log error if it
  664. '       does match the given value
  665. '
  666. ' Parameters:
  667. '       s$ - the value for the directory that isn't expected
  668. '
  669. ' Returns:
  670. '       nothing
  671. '
  672. ' Example:
  673. '       XCWDNotCmp "c:\tests"
  674. '
  675.  
  676. SUB XCWDNotCmp(s$) STATIC
  677.  
  678.     IF UCASE$(CURDIR$) = UCASE$(s$) THEN
  679.         XLogFailure "Current working directory (" + UCASE$(CURDIR$) + ") matches " + UCASE$(s$)
  680.     END IF
  681. END SUB
  682.  
  683. '
  684. ' BCWDCmp(s$)
  685. '
  686. ' Description:
  687. '       return compare of the current working directory and the expected value
  688. '
  689. ' Parameters:
  690. '       s$ - the expected value for the current directory
  691. '
  692. ' Returns:
  693. '       TRUE if matches, FALSE if doesn't
  694. '
  695. ' Example:
  696. '       flag% = BCWDCmp("c:\tests")
  697. '
  698.  
  699. FUNCTION BCWDCmp%(s$) STATIC
  700.  
  701.     BCWDCmp = UCASE$(CURDIR$) = UCASE$(s$)
  702.  
  703. END FUNCTION
  704.  
  705. '
  706. ' XDriveCmp(s$)
  707. '
  708. ' Description:
  709. '       Compare the current working drive and log error if it
  710. '       doesn't match the expected value
  711. '
  712. ' Parameters:
  713. '       s$ - the expected value for the current drive
  714. '
  715. ' Returns:
  716. '       nothing
  717. '
  718. ' Example:
  719. '       XDriveCmp "c:"
  720. '
  721.  
  722. SUB XDriveCmp(s$) STATIC
  723.  
  724.     IF BDriveCmp%(s$) = 0 THEN
  725.         XLogFailure "Current working Drive (" + MID$(UCASE$(CURDIR$),1,2) + ") doesn't match " + UCASE$(s$)
  726.     END IF
  727. END SUB
  728.  
  729. '
  730. ' XDriveNotCmp(s$)
  731. '
  732. ' Description:
  733. '       Compare the current working drive and log error if it
  734. '       does match the given value
  735. '
  736. ' Parameters:
  737. '       s$ - the expected value for the current drive
  738. '
  739. ' Returns:
  740. '       nothing
  741. '
  742. ' Example:
  743. '       XDriveNotCmp "c:"
  744. '
  745. SUB XDriveNotCmp(s$) STATIC
  746.  
  747.     IF MID$(UCASE$(CURDIR$),1,2) = UCASE$(s$) THEN
  748.         XLogFailure "Current working Drive (" + MID$(UCASE$(CURDIR$),1,2) + ") matches " + s$
  749.     END IF
  750. END SUB
  751.  
  752. '
  753. ' BDriveCmp(s$)
  754. '
  755. ' Description:
  756. '       return compare the current working drive and the expected value
  757. '
  758. ' Parameters:
  759. '       s$ - the expected value for the current drive
  760. '
  761. ' Returns:
  762. '       TRUE if matches, FALSE if doesn't
  763. '
  764. ' Example:
  765. '       flag% = BDriveCmp("c:")
  766. '
  767.  
  768. FUNCTION BDriveCmp%(s$) STATIC
  769.  
  770.     BDriveCmp = MID$(UCASE$(CURDIR$),1,2) = UCASE$(s$)
  771.  
  772. END FUNCTION
  773.  
  774. '
  775. ' XChangeCWD(s$)
  776. '
  777. ' Description:
  778. '       Change to given working directory, log failure if doesn't succeed
  779. '
  780. ' Parameters:
  781. '       s$ - directory to change to
  782. '
  783. ' Returns:
  784. '       nothing
  785. '
  786. ' Example:
  787. '       XChangeCWD "\tmp"
  788. '
  789. '
  790. SUB XChangeCWD(s$) STATIC
  791.     gErrorType = ET_NEXT
  792.     CHDIR s$
  793.     IF gfError THEN
  794.         XLogFailure "XChangeCWD could not change directory"
  795.         gfError = FALSE
  796.     END IF
  797.     gErrorType = ET_NOTHING
  798. END SUB
  799.  
  800. '
  801. ' XCreateDir(s$)
  802. '
  803. ' Description:
  804. '       Create the given directory, log failure if doesn't succeed
  805. '
  806. ' Parameters:
  807. '       s$ - directory to create
  808. '
  809. ' Returns:
  810. '       nothing
  811. '
  812. ' Example:
  813. '       XCreateDir "\tmpdir"
  814. '
  815. '
  816. SUB XCreateDir(s$) STATIC
  817.     gErrorType = ET_NEXT
  818.     MKDIR s$
  819.     IF gfError THEN
  820.         XLogFailure "XCreateDir could not create directory"
  821.         gfError = FALSE
  822.     END IF
  823.     gErrorType = ET_NOTHING
  824. END SUB
  825.  
  826. '
  827. ' XChangeDrive(s$)
  828. '
  829. ' Description:
  830. '       Change the current working drive, log failure if doesn't succeed
  831. '
  832. ' Parameters:
  833. '       s$ - drive to change to
  834. '
  835. ' Returns:
  836. '       nothing
  837. '
  838. ' Example:
  839. '       XChangeDrive "c:"
  840. '
  841. '
  842. SUB XChangeDrive(s$) STATIC
  843.     gErrorType = ET_NEXT
  844.     CHDRIVE s$
  845.     IF gfError THEN
  846.         XLogFailure "XChangeDrive could not change drive"
  847.         gfError = FALSE
  848.     END IF
  849.     gErrorType = ET_NOTHING
  850. END SUB
  851.  
  852. '**********************************************************
  853. '***************** Program Subroutines ********************
  854. '**********************************************************
  855.  
  856.  
  857.  
  858. '
  859. ' HStartApp%(stAppName$)
  860. '
  861. ' Description:
  862. '       Starts app AppName and returns the handle to the App
  863. '
  864. ' Parameters:
  865. '       stAppName$  - name of app to WinExec and get handle to
  866. '
  867. ' Returns:
  868. '       handle to application started
  869. '
  870. ' Example:
  871. '       hWinHelp% = HStartApp("winhelp.exe")
  872. '
  873. '
  874. FUNCTION HStartApp%(stAppName$) STATIC
  875.     DIM Bogus%
  876.     DIM lpszTemp$
  877.     Bogus% = WinExec (stAppName$, SW_SHOWNORMAL)
  878.     lpszTemp$ = "WinExec error with " + stAppName$ + " :"
  879.  
  880.     ' WinExec defines SOME of the values between 0 and 32
  881.     ' as errors... any return value greater than 32
  882.     ' should be considered a success!
  883.     SELECT CASE Bogus%
  884.         CASE 0
  885.             XLogFailure lpszTemp$ + "Out of memory - exiting"
  886.  
  887.         CASE 2
  888.             XLogFailure lpszTemp$ + "File not found"
  889.             End
  890.         CASE 3
  891.             XLogFailure lpszTemp$ + "Path not found"
  892.  
  893.         CASE 5
  894.             XLogFailure lpszTemp$ + "Attempt to dynamically link to a task"
  895.  
  896.         CASE 6
  897.             XLogFailure lpszTemp$ + "Library requires separate data segments"
  898.  
  899.         CASE 10
  900.             XLogFailure lpszTemp$ + "Incorrect Windows version"
  901.  
  902.         CASE 11
  903.             XLogFailure lpszTemp$ + "Invalid EXE file"
  904.  
  905.         CASE 12
  906.             XLogFailure lpszTemp$ + "OS/2 application"
  907.  
  908.         CASE 13
  909.             XLogFailure lpszTemp$ + "DOS 4.0 application"
  910.  
  911.         CASE 14
  912.             XLogFailure lpszTemp$ + "Unknown EXE type"
  913.  
  914.         CASE 15
  915.             XLogFailure lpszTemp$ + "Must run in real mode Windows"
  916.  
  917.         CASE 16
  918.             XLogFailure lpszTemp$ + "Cannot run more than one instance"
  919.  
  920.         CASE 17
  921.             XLogFailure lpszTemp$ + "Large-frame EMS allows only one instance"
  922.  
  923.         CASE 18
  924.             XLogFailure lpszTemp$ + "Must run in standard or enhanced mode Windows"
  925.  
  926.         CASE 0 TO 32
  927.             XLogFailure lpszTemp$ + "Unknown Error in WinExec"
  928.  
  929.      END SELECT
  930.  
  931.      HStartApp = GetActiveWindow ()
  932. END FUNCTION
  933.  
  934. '
  935. ' XStartApp(stAppName$)
  936. '
  937. ' Description:
  938. '       Starts app AppName and sets handle to ghAppHwnd.
  939. '       if we get a null handle, THEN we end the script here.
  940. '
  941. ' Parameters:
  942. '       stAppName$  - name of app to WinExec
  943. '
  944. ' Returns:
  945. '       nothing
  946. '
  947. ' Example:
  948. '       XStartApp "winhelp.exe"
  949. '
  950. '
  951. SUB XStartApp(stAppName$, stClassname$) STATIC
  952.     DIM logstr$
  953.     'ghAppHwnd is a global
  954.     ghAppHwnd = HStartApp(stAppName$)
  955.     IF (ghAppHwnd = 0) THEN
  956.         'we didn't get a handle
  957.         XLogFailure "Unable to start app " + stAppName$
  958.     ELSEIF stClassname$ <> "" THEN
  959.         gsAppClassname = stClassname$    ' remember it for later
  960.         IF FindWindow(stClassname$,NULL) = 0 THEN
  961.             ' The app isn't around
  962.             logstr$ = "The app " + stAppName$ + " started but didn't stay OR..."
  963.             logstr$ = logstr$ + CRLF$ + "the given class name ("
  964.             logstr$ = logstr$ +  stClassname$ + ") is incorrect"
  965.             XLogFailure logstr$
  966.         END IF
  967.     END IF
  968. END SUB
  969.  
  970. '
  971. ' XSetCleanup(sCleanup$)
  972. '
  973. ' Description:
  974. '       Stores a user defined DoKeys string to be used to exit the
  975. '       application automatically.  If set to an empty string,
  976. '       nothing will be sent with DoKeys but there will still be
  977. '       a log failure if the application is still running when the
  978. '       script ends (no check is done if there wasn't a classname
  979. '       supplied with XStartApp
  980. '
  981. ' Parameters:
  982. '       sCleanup$ - the string to use with DoKeys to end the app
  983. '
  984. ' Returns:
  985. '       nothing
  986. '
  987. ' Example:
  988. '       XSetCleanup "{esc 5}%vx"
  989. '
  990. '
  991. SUB XSetCleanup (sCleanup$) STATIC
  992.     gsCleanup$ = sCleanup$
  993. END SUB
  994.  
  995. ' This routine is not intended to be called in the user script.
  996. ' This routine is executed when the script finishes with an END
  997. ' statement.  Its purpose is to find the application started with
  998. ' XStartapp using the classname supplied there.  if it exists,
  999. ' and the gsCleanup string is nonempty, the gsCleanup string will
  1000. ' be played.  This may still not get rid of the app for various
  1001. ' reasons: maybe it is prompting to save a file, or it won't exit
  1002. ' a dialog...
  1003.  
  1004. SUB XDoCleanup STATIC
  1005.     DIM logstr$
  1006.     IF gsCleanup$ <> "" AND gsAppClassname$ <> "" AND FindWindow(gsAppClassname$,NULL) <> 0 THEN
  1007.         DoKeys gsCleanup$
  1008.     END IF
  1009.     IF gsAppClassname$ <> "" AND FindWindow(gsAppClassname$,NULL) <> 0 THEN
  1010.         logstr$ =  "The app with class name " + gsAppClassname$ + " was not"
  1011.         logstr$ = logstr$ + CRLF$ + "halted by the cleanup string " + gsCleanup$
  1012.         XLogFailure logstr$
  1013.     END IF
  1014.  
  1015. END SUB
  1016.  
  1017.  
  1018.  
  1019. '**********************************************************
  1020. '***************** Mouse Subroutines **********************
  1021. '**********************************************************
  1022.  
  1023. ' The mouse routines use the VK_LBUTTON, VK_RBUTTON, VK_MBUTTON
  1024. ' constants to determine which button to use (or LBUTTON, MBUTTON or RBUTTON
  1025. ' as defined in fasttest.inc
  1026.  
  1027.  
  1028. '
  1029. ' XMoveMouse(x%,y%)
  1030. '
  1031. ' Description:
  1032. '       Moves the mouse pointer to specified absolute screen coordinates
  1033. '
  1034. ' Parameters:
  1035. '       x%,y% - x and y coordinates to move to
  1036. '
  1037. ' Returns:
  1038. '       nothing
  1039. '
  1040. ' Example:
  1041. '       XMoveMouse 100,120
  1042. '
  1043. '
  1044.  
  1045. SUB XMoveMouse (x%, y%) STATIC
  1046.  
  1047.     QueMouseMove x%,y%
  1048.     QueFlush FALSE
  1049. END SUB
  1050.  
  1051.  
  1052. '
  1053. ' XClickMouse(button%,x%,y%)
  1054. '
  1055. ' Description:
  1056. '       Clicks the mouse pointer to specified absolute screen coordinates
  1057. '
  1058. ' Parameters:
  1059. '       button% - which button to click
  1060. '       x%,y% - x and y coordinates to move to
  1061. '
  1062. ' Returns:
  1063. '       nothing
  1064. '
  1065. ' Example:
  1066. '       XClickMouse LBUTTON,100,120
  1067. '
  1068. '
  1069.  
  1070. SUB XClickMouse(button%, x%, y%) STATIC
  1071.  
  1072.     QueMouseDn button%,x%,y%
  1073.     QueMouseUp button%,x%,y%
  1074.     QueFlush FALSE
  1075.  
  1076. END SUB
  1077.  
  1078. '
  1079. ' XDblClickMouse(button%,x%,y%)
  1080. '
  1081. ' Description:
  1082. '       Clicks the mouse pointer to specified absolute screen coordinates
  1083. '
  1084. ' Parameters:
  1085. '       button% - which button to double click
  1086. '       x%,y% - x and y coordinates to move to
  1087. '
  1088. ' Returns:
  1089. '       nothing
  1090. '
  1091. ' Example:
  1092. '       XDblClickMouse LBUTTON,100,120
  1093. '
  1094. '
  1095. SUB XDblClickMouse(button%, x%, y%) STATIC
  1096.  
  1097.     QueMouseDblClk button%,x%,y%
  1098.     QueFlush FALSE
  1099.  
  1100. END SUB
  1101.  
  1102. '
  1103. ' XDragMouse (button%, Begx%, Begy%, Endx%, Endy%)
  1104. '
  1105. ' Description:
  1106. '       Drags the mouse pointer to specified absolute screen coordinates
  1107. '
  1108. ' Parameters:
  1109. '       button% - which button to use for dragging
  1110. '       Begx%,Begy% - x and y coordinates to Drag from
  1111. '       Endx%,Endy% - x and y coordinates to Drag to
  1112. '
  1113. ' Returns:
  1114. '       nothing
  1115. '
  1116. ' Example:
  1117. '       XDragMouse LBUTTON,100,120, 200,220
  1118. '
  1119. '
  1120. SUB XDragMouse (button%, Begx%, Begy%, Endx%, Endy%) STATIC
  1121.  
  1122.     QueMouseDn button%,Begx%,Begy%
  1123.     QueMouseMove Endx%,Endy%
  1124.     QueMouseUp button%,Endx%,Endy%
  1125.     QueFlush FALSE
  1126. END SUB
  1127.  
  1128.  
  1129.  
  1130.  
  1131. '**********************************************************
  1132. '***************** ClipBoard Subroutines ******************
  1133. '**********************************************************
  1134.  
  1135.  
  1136. '
  1137. ' XClipBoardCmp(s$)
  1138. '
  1139. ' Description:
  1140. '       Compare given string to what is in the clipboard, log failure
  1141. '       if they don't match
  1142. '
  1143. ' Parameters:
  1144. '       s$ - string to compare
  1145. '
  1146. ' Returns:
  1147. '       nothing
  1148. '
  1149. ' Example:
  1150. '       XClipBoardCmp "07734"
  1151. '
  1152. '
  1153. SUB XClipBoardCmp (s$) STATIC
  1154.  
  1155.     IF s$ <> CLIPBOARD$ THEN
  1156.         XLogFailure "String does not match clipboard"
  1157.     END IF
  1158. END SUB
  1159.  
  1160. '
  1161. ' XClipBoardNotCmp(s$)
  1162. '
  1163. ' Description:
  1164. '       Compare given string to what is in the clipboard, log failure
  1165. '       if they match
  1166. '
  1167. ' Parameters:
  1168. '       s$ - string to compare
  1169. '
  1170. ' Returns:
  1171. '       nothing
  1172. '
  1173. ' Example:
  1174. '       XClipBoardNotCmp "07734"
  1175. '
  1176. '
  1177. SUB XClipBoardNotCmp (s$) STATIC
  1178.  
  1179.     IF s$ = CLIPBOARD$ THEN
  1180.         XLogFailure "String does match clipboard"
  1181.     END IF
  1182. END SUB
  1183.  
  1184. '
  1185. ' BClipBoardCmp(s$)
  1186. '
  1187. ' Description:
  1188. '       Compare given string to what is in the clipboard, log failure
  1189. '       if they don't match
  1190. '
  1191. ' Parameters:
  1192. '      s$ - string to compare
  1193. '
  1194. ' Returns:
  1195. '       TRUE if matches, FALSE if doesn't
  1196. '
  1197. ' Example:
  1198. '       flag% = BClipBoardCmp "07734"
  1199. '
  1200. '
  1201. FUNCTION BClipBoardCmp (s$) STATIC
  1202.  
  1203.     BClipBoardCmp = s$ = CLIPBOARD$
  1204. END FUNCTION
  1205.