Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1214 lines
26 KiB

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