Source code of Windows XP (NT5)
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.

469 lines
17 KiB

  1. '******************************** TUTOR.MST **********************************
  2. 'Demonstrates: This will test the OLE 2.0 sample app: OLine.EXE
  3. '
  4. 'Required Files: MSTEST.INC, OUTLINE.EXE
  5. '
  6. 'Uses: TESTSCRN, TESTCTRL, TESTEVENT.
  7. '
  8. 'Notes: Assumes all exe's are in the PATH.
  9. '
  10. '******************************************************************************
  11. Declare Sub Init
  12. Declare Sub Windows
  13. Declare Sub AddLines
  14. Declare Sub NewDoc
  15. Declare Sub ClearAll
  16. Declare Sub TestNames
  17. Declare Sub TestClip
  18. Declare Sub EndTest
  19. Declare SUB LogPrint(szString$)
  20. Declare SUB CheckAppExists(szAppName$, szErrMessage$)
  21. Declare SUB CheckAppNotExists(szAppName$, szErrMessage$)
  22. Declare FUNCTION CheckWndIsActive(szAppName$, szErrMessage$) AS INTEGER
  23. Declare SUB IsDllLoaded(szDllName$)
  24. Declare FUNCTION GetDllUsage(szDllName$) AS INTEGER
  25. Declare SUB CheckDllUsage(szDllName$, nExpectedUsage%)
  26. '******************************************************************************
  27. ' CONST
  28. '******************************************************************************
  29. Const DefAppName$ = "outline"
  30. Const RootAppDir$ = "c:\ole2samp\outline\"
  31. Const SDemo1AppName$ = "sdemo1"
  32. Const SDemo1ClassName$ = "SDemo1"
  33. Const EllipseWTClassName$ = "EllipseWT"
  34. Const BELL = 7
  35. Global WinHandle%, DbWinHandle%, logfile%, ErrCount, fSlaveMode%, fAutoMode%, AppName$, AppWndName$, AppDir$
  36. Const nDll = 4
  37. GLOBAL DllList$(nDll)
  38. GLOBAL DllExpectedUsage%(nDll)
  39. DllList(0) = "OLE2.DLL"
  40. DllList(1) = "OLECLASS.DLL"
  41. DllList(2) = "OLEREM.DLL"
  42. DllList(3) = "OLEPROXY.DLL"
  43. DllList(4) = "DOCFILE.DLL"
  44. '******************************************************************************
  45. ' DEFINES
  46. '******************************************************************************
  47. '$DEFINE TESTSCRN
  48. '$DEFINE TESTCTRL
  49. '$DEFINE TESTEVNT
  50. '******************************************************************************
  51. ' INCLUDES
  52. '******************************************************************************
  53. '$INCLUDE 'mstest.inc'
  54. '$INCLUDE 'fasttest.inc'
  55. '$INCLUDE 'winkern.inc'
  56. '******************************************************************************
  57. ' Main program code
  58. '******************************************************************************
  59. ON ERROR GOTO ErrorTrap
  60. Init '*** Initialize logging, global constants.
  61. Windows '*** Test various windowing features of app.
  62. NewDoc '*** start a new document
  63. AddLines '*** Add some lines to document
  64. TestNames '*** Test naming functionality
  65. TestClip '*** Test clipboard functionality
  66. EndTest '*** Shut down.
  67. END
  68. '******************************************************************************
  69. ' TRAPS
  70. '******************************************************************************
  71. ErrorTrap:
  72. ErrCount = ErrCount + 1
  73. SELECT CASE Err
  74. CASE ERR_INVALID_PATH
  75. LogPrint "Path not found. Error number " + STR$(Err)
  76. LogPrint " on line " + STR$(ERL)
  77. LogPrint " in script " + ERF
  78. LogPrint ERROR$ ' The error message.
  79. END
  80. CASE ERR_CANT_OPEN_FILE
  81. LogPrint "Can't Open File. Error number " + STR$(Err)
  82. LogPrint " on line " + STR$(ERL)
  83. LogPrint " in script " + ERF
  84. LogPrint ERROR$ ' The error message.
  85. END
  86. CASE ERR_ILLEGAL_FUNCTION_CALL
  87. LogPrint "Illegal function call. Error number " + STR$(Err)
  88. LogPrint " on line " + STR$(ERL)
  89. LogPrint " in script " + ERF
  90. LogPrint ERROR$ ' The error message.
  91. LogPrint " (NOTE: Check if OLETEST.EXE & SDEMO1.EXE are on your PATH)"
  92. END
  93. CASE ELSE
  94. LogPrint "Unexpected error: Number " + STR$(Err)
  95. LogPrint " on line " + STR$(ERL)
  96. LogPrint " in script " +ERF
  97. LogPrint ERROR$ ' The error message.
  98. END
  99. END SELECT
  100. '*** trap UAE from an application
  101. 'TRAP UAETrap FROM "TESTDRVR.EXE"
  102. ' LogPrint "!!!!!! UNRECOVERERABLE APPLICATION ERROR ENCOUNTERED!"
  103. ' LogPrint " ABORT TESTING!"
  104. ' ErrCount = ErrCount + 1
  105. ' EndTest
  106. 'END TRAP
  107. '******************************************************************************
  108. ' SUBs and FUNCTIONs
  109. '******************************************************************************
  110. '******************************************************************************
  111. ' SUB Init sets up several variables that are used thoughout the test.
  112. '******************************************************************************
  113. SUB Init STATIC
  114. Viewport On
  115. Viewport Clear
  116. ErrCount = 0
  117. fSlaveMode = 0
  118. fAutoMode = 0
  119. IF TESTMODE$ = "auto" OR TESTMODE$ = "AUTO" THEN
  120. fAutoMode = 1
  121. ENDIF
  122. '*** Determine name of app to run. this can be given with "/C appname" cmd line opt.
  123. IF COMMAND$ = "" THEN
  124. AppName$ = DefAppName$
  125. ELSE
  126. AppName$ = COMMAND$
  127. ENDIF
  128. AppWndName$ = AppName$ + " -"
  129. logfile = FREEFILE
  130. OPEN "mstest.log" FOR OUTPUT AS # logfile
  131. 'Set log file and write header to file.
  132. LogPrint "**********************************************"
  133. LogPrint "STARTING TEST OF " + AppName$ + " APPLICATION"
  134. LogPrint " " + DATETIME$
  135. LogPrint "**********************************************"
  136. 'Record the initial usage counts for all OLE2 related DLLs
  137. FOR I = 0 TO nDll
  138. DllExpectedUsage(I) = GetDllUsage(DllLIst(I))
  139. NEXT I
  140. 'Run the program and get its window handle.
  141. WinHandle = WFndWnd(AppWndName$, FW_PART or FW_FOCUS or FW_ALL)
  142. IF WinHandle = 0 THEN
  143. LogPrint "Launching new instance of " + AppName$ + " app--running test in slave mode"
  144. LogPrint "NOTE: Running test in slave mode -- app will automatically shut down"
  145. RUN "dbwin", NOWAIT '*** start up debug messages window
  146. DbWinHandle = WGetActWnd(0)
  147. DoKeys "%(e)e" '*** Edit.Clear buffer
  148. RUN RootAppDir$ + AppName$ + "\" + AppName$, NOWAIT
  149. WinHandle = WGetActWnd(0)
  150. fSlaveMode = 1 '*** Test is run in slave mode, shut down afterwards
  151. ELSE
  152. LogPrint "Using existing instance of " + AppName$
  153. ENDIF
  154. IF CheckWndIsActive("Debug Messages", "") <> 0 THEN
  155. DoKeys "%(o)t" '*** Toggle off 'always on top' mode of debug window
  156. WSetActWnd WinHandle '*** activate app
  157. ENDIF
  158. x = CheckWndIsActive(AppWndName$, AppName$ + " Test not launched successfully")
  159. END SUB
  160. '******************************************************************************
  161. ' SUB Window will size app window and set it's position.
  162. '******************************************************************************
  163. SUB Windows STATIC
  164. DIM i%
  165. 'Position and size the form.
  166. WSetWndPos WinHandle, 200, 200
  167. WSetWndSiz WinHandle, 50, 60
  168. 'Adjust the window to several locations.
  169. For i = 1 to 10
  170. WAdjWndSiz WinHandle, 4*i, 4*i
  171. Next i
  172. END SUB
  173. '******************************************************************************
  174. ' SUB NewDoc -- start a new doc.
  175. '******************************************************************************
  176. SUB NewDoc STATIC
  177. LogPrint "--- BEGIN NewDoc"
  178. WSetActWnd WinHandle '*** activate app
  179. DoKeys "%(l)axxxx" '*** add a line so doc is dirty
  180. WButtonClick "OK" '*** Close input dialog box
  181. DoKeys "%(f)n" '*** New command
  182. WButtonClick "No" '*** Do not save
  183. x = CheckWndIsActive(AppWndName$, "Unknown Error")
  184. LogPrint "--- END"
  185. END SUB
  186. '******************************************************************************
  187. ' SUB ClearAll -- clear all lines.
  188. '******************************************************************************
  189. SUB ClearAll STATIC
  190. LogPrint "--- BEGIN ClearALL"
  191. WSetActWnd WinHandle '*** activate app
  192. DoKeys "%(e)l" '*** select all
  193. DoKeys "%(e)e" '*** clear selection
  194. x = CheckWndIsActive(AppWndName$, "Unknown Error")
  195. LogPrint "--- END"
  196. END SUB
  197. '******************************************************************************
  198. ' SUB AddLines -- add text lines.
  199. '******************************************************************************
  200. SUB AddLines STATIC
  201. LogPrint "--- BEGIN AddLines"
  202. WSetActWnd WinHandle '*** activate app
  203. DoKeys "%(l)aLine 1: This is a test" '*** add a line
  204. WButtonClick "OK" '*** Close input dialog box
  205. DoKeys "%(l)aLine 2: This is a test" '*** add a line
  206. WButtonClick "OK" '*** Close input dialog box
  207. DoKeys "%(l)aLine 3: This is a test" '*** add a line
  208. WButtonClick "OK" '*** Close input dialog box
  209. DoKeys "%(l)aLine 3.1: This is a sub point" '*** add a line
  210. WButtonClick "OK" '*** Close input dialog box
  211. DoKeys "%(l)i" '*** indent line
  212. DoKeys "%(l)aLine 3.2: This is a sub point" '*** add a line
  213. WButtonClick "OK" '*** Close input dialog box
  214. DoKeys "%(l)aLine 3.3: This is a sub point" '*** add a line
  215. WButtonClick "OK" '*** Close input dialog box
  216. DoKeys "%(l)i" '*** indent line
  217. DoKeys "%(l)i" '*** indent line
  218. DoKeys "%(l)i" '*** indent line
  219. DoKeys "%(l)i" '*** indent line
  220. DoKeys "%(l)i" '*** indent line
  221. DoKeys "%(l)i" '*** indent line
  222. DoKeys "%(l)n" '*** un-indent line
  223. DoKeys "%(l)n" '*** un-indent line
  224. DoKeys "%(l)n" '*** un-indent line
  225. DoKeys "%(l)n" '*** un-indent line
  226. DoKeys "%(l)n" '*** un-indent line
  227. DoKeys "%(l)n" '*** un-indent line
  228. x = CheckWndIsActive(AppWndName$, "Unknown Error")
  229. LogPrint "--- END"
  230. END SUB
  231. '******************************************************************************
  232. ' SUB TestNames -- test the naming functionality.
  233. '******************************************************************************
  234. SUB TestNames STATIC
  235. LogPrint "--- BEGIN TestNames"
  236. WSetActWnd WinHandle '*** activate app
  237. DoKeys "{UP}"
  238. DoKeys "{Down}"
  239. DoKeys "+({UP})+({UP})+({UP})" '*** select some lines
  240. DoKeys "%(n)dx" '*** define a name
  241. WButtonClick "Ok" '*** Close define name dialog box
  242. DoKeys "%(l)aLine 4: This should be part of name x" '*** add a line
  243. WButtonClick "OK" '*** Close input dialog box
  244. DoKeys "%(l)aLine 5: This should be part of name x" '*** add a line
  245. WButtonClick "OK" '*** Close input dialog box
  246. DoKeys "%(n)gx" '*** goto name
  247. WButtonClick "OK" '*** Close define name dialog box
  248. DoKeys "{Down}"
  249. DoKeys "+{Down}" '*** select the 2 lines that were added
  250. DoKeys "%(e)e" '*** delete the selection
  251. DoKeys "%(n)gx" '*** goto name
  252. WButtonClick "OK" '*** Close define name dialog box
  253. x = CheckWndIsActive(AppWndName$, "Unknown Error")
  254. LogPrint "--- END"
  255. END SUB
  256. '******************************************************************************
  257. ' SUB TestClip -- test the clipboard functionality.
  258. '******************************************************************************
  259. SUB TestClip STATIC
  260. LogPrint "--- BEGIN TestClip"
  261. WSetActWnd WinHandle '*** activate app
  262. DoKeys "%(e)t" '*** cut the selection
  263. DoKeys "%(e)p" '*** paste
  264. DoKeys "%(e)p" '*** paste
  265. x = CheckWndIsActive(AppWndName$, "Unknown Error")
  266. LogPrint "--- END"
  267. END SUB
  268. SUB EndTest STATIC
  269. IF fSlaveMode <> 0 THEN
  270. LogPrint "*** EndTest"
  271. IF CheckWndIsActive(AppWndName$, AppName$ + " can NOT be closed properly") THEN
  272. DoKeys "%FX" '*** shut down OLETEST
  273. WButtonClick "No" '*** Do not save
  274. ENDIF
  275. WMinWnd(DbWinHandle) '*** minimize debug messages window
  276. CheckAppNotExists AppWndName$, AppName$ + " NOT shut down properly"
  277. ENDIF
  278. 'Check that all OLE2 related DLLs have the expected usage counts
  279. FOR I = 0 TO nDll
  280. CheckDllUsage DllList(I), DllExpectedUsage(I)
  281. NEXT I
  282. LogPrint "**********************************************"
  283. LogPrint "SUCCESSFULLY COMPLETED " + AppName$ + "TEST"
  284. LogPrint " " + DATETIME$
  285. LogPrint "Total of " + STR$(ErrCount) + " errors detected"
  286. LogPrint "**********************************************"
  287. CLOSE # logfile
  288. IF fAutoMode = 0 THEN
  289. PRINT, CHR$(BELL) '*** sound a BEEP, we are done!
  290. IF ErrCount = 0 THEN
  291. PAUSE "Test seems successful"
  292. ELSE
  293. PAUSE "*** TEST FAILED -- (" + STR$(ErrCount) + " Errors). See mstest.log"
  294. ENDIF
  295. ENDIF
  296. END SUB
  297. '******************************************************************************
  298. ' SUB LogPrint prints a string to the logfile and to the Viewport.
  299. '******************************************************************************
  300. SUB LogPrint(szString$) STATIC
  301. PRINT #logfile, szString$
  302. PRINT, szString$
  303. END SUB
  304. SUB CheckAppExists(szAppName$, szErrMessage$) STATIC
  305. hWnd = WFndWnd(szAppName, FW_PART or FW_ALL or FW_NOCASE)
  306. IF hWnd = 0 THEN
  307. LogPrint "!!!!!! Operation FAILED..."
  308. LogPrint " " + szErrMessage$
  309. ErrCount = ErrCount + 1
  310. ENDIF
  311. END SUB
  312. SUB CheckAppNotExists(szAppName$, szErrMessage$) STATIC
  313. hWnd = WFndWnd(szAppName, FW_PART or FW_ALL or FW_NOCASE)
  314. IF hWnd <> 0 THEN
  315. LogPrint "!!!!!! Operation FAILED..."
  316. LogPrint " " + szErrMessage$
  317. ErrCount = ErrCount + 1
  318. ENDIF
  319. END SUB
  320. STATIC FUNCTION CheckWndIsActive(szAppName$, szErrMessage$) AS INTEGER
  321. hWnd = WFndWnd(szAppName, FW_PART or FW_ALL or FW_NOCASE)
  322. CheckWndIsActive = hWnd
  323. IF hWnd <> WGetActWnd(0) THEN
  324. CheckWndIsActive = 0
  325. '*** if no message is given, then it is not considered an error
  326. IF szErrMessage <> "" THEN
  327. LogPrint "!!!!!! Operation FAILED..."
  328. LogPrint " " + szErrMessage$
  329. LogPrint " <" + GetText(0) + "> Window is Active"
  330. IF fAutoMode = 0 THEN
  331. PAUSE "<" + szAppName + "> Window expected.... " + "<" + GetText(0) + "> Window is Active"
  332. ENDIF
  333. '*** if a dialog is active, then close it. it is probably an error message
  334. IF WButtonExists("Ignore") THEN
  335. WButtonClick "OK" '*** Close err message box
  336. ELSEIF WButtonExists("OK") THEN
  337. WButtonClick "OK" '*** Close err message box
  338. ELSEIF WButtonExists("Ok") THEN
  339. WButtonClick "Ok" '*** Close err message box
  340. ELSEIF WButtonExists("Cancel") THEN
  341. WButtonClick "Cancel" '*** Close err message box
  342. ELSEIF WButtonExists("CANCEL") THEN
  343. WButtonClick "CANCEL" '*** Close err message box
  344. ELSEIF WButtonExists("Close") THEN
  345. WButtonClick "Close" '*** Close err message box
  346. ENDIF
  347. ErrCount = ErrCount + 1
  348. ENDIF
  349. ENDIF
  350. END FUNCTION
  351. '******************************************************************************
  352. ' FUNCTION GetDllUsage gets the usage count of a DLL.
  353. '******************************************************************************
  354. STATIC FUNCTION GetDllUsage(szDllName$) AS INTEGER
  355. hDll% = GetModuleHandle(szDllName)
  356. GetDllUsage = GetModuleUsage(hDll)
  357. END FUNCTION
  358. '******************************************************************************
  359. ' SUB CheckDllUsage checks if a DLL is loaded the expected number of times.
  360. '******************************************************************************
  361. SUB CheckDllUsage(szDllName$, nExpectedUsage%) STATIC
  362. usage% = GetDllUsage(szDllName)
  363. LogPrint "DLL: " + szDllName + " loadded" + STR$(usage) + " times (expected" + STR$(nExpectedUsage) + " times)"
  364. '*** can only reliably report an error when expected usage is 0
  365. IF usage <> nExpectedUsage AND nExpectedUsage = 0 THEN
  366. LogPrint "!!!!!! " + szDllName + " NOT UNLOADED PROPERLY!"
  367. ErrCount = ErrCount + 1
  368. ENDIF
  369. END SUB