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.

479 lines
13 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: task.cpp
  7. //
  8. // Contents: The global task list and helper function implementations
  9. //
  10. // Classes:
  11. //
  12. // Functions: HandleTestEnd
  13. // RunAllTests
  14. // RunApp
  15. // RunTestOnThread
  16. //
  17. // History: dd-mmm-yy Author Comment
  18. // 06-Jan-95 t-scotth added apartment thread test and RunTestOnThread
  19. // 06-Feb-94 alexgo author
  20. //
  21. // Notes:
  22. // Folks adding new tests will need to insert their test
  23. // into the global array.
  24. //
  25. //--------------------------------------------------------------------------
  26. #include "oletest.h"
  27. #include "cotest.h"
  28. #include "letest.h"
  29. #include "attest.h"
  30. // global, zero'ed task item
  31. TaskItem vzTaskItem;
  32. // the global task list array.
  33. // Multi-test entries go first, followed by individual tests.
  34. #ifdef WIN32
  35. const TaskItem vrgTaskList[] =
  36. {
  37. // the constant should be the index at which individual tests
  38. // begin. RunAllTests will run every test in this list after
  39. // that index.
  40. { "Run All Tests", RunAllTests, (void *)2},
  41. // the constant below should be the index at which individual
  42. // upper layer unit tests exist. All tests at that index and
  43. // beyond will be run
  44. { "Run All Upper Layer Tests", RunAllTests, (void *)5 },
  45. { "OleBind", RunApp, (void *)"olebind.exe"},
  46. { "Threads", RunApi, (void *) ThreadUnitTest },
  47. { "Storage DRT", RunApp, (void *)"stgdrt.exe"},
  48. { "LE: Insert Object Test 1", LETest1, &letiInsertObjectTest1 },
  49. { "LE: Clipboard Test 1", RunApi, (void *)LEClipTest1},
  50. { "LE: Clipboard Test 2 (clipboard data object)", RunApi,
  51. (void *)LEClipTest2 },
  52. { "LE: Inplace Test 1", LETest1, &letiInplaceTest1 },
  53. { "LE: Data Advise Holder Test", RunApi,
  54. (void *) LEDataAdviseHolderTest},
  55. { "LE: OLE Advise Holder Test", RunApi, (void *) LEOleAdviseHolderTest},
  56. { "LE: OLE1 Clipboard Test 1", RunApi, (void *)LEOle1ClipTest1},
  57. { "LE: Insert Object Test 2", LETest1, &letiInsertObjectTest2 },
  58. { "LE: OLE1 Clipboard Test 2", LEOle1ClipTest2, NULL },
  59. { "LE: OleQueryCreateFromData Test 1", RunApi,
  60. (void *)TestOleQueryCreateFromDataMFCHack },
  61. { "LE: Apartment Thread Test", RunTestOnThread, (void *)ATTest },
  62. { 0, 0, 0 }
  63. };
  64. #else
  65. // Win16 tests
  66. const TaskItem vrgTaskList[] =
  67. {
  68. // the constant should be the index at which individual tests
  69. // begin. RunAllTests will run every test in this list after
  70. // that index.
  71. { "Run All Tests", RunAllTests, (void *)1},
  72. { "LE: Clipboard Test 1", RunApi, (void *)LEClipTest1},
  73. { "LE: Clipboard Test 2 (clipboard data object)", RunApi,
  74. (void *)LEClipTest2 },
  75. { "LE: OLE1 Clipboard Test 1", RunApi, (void *)LEOle1ClipTest1},
  76. { 0, 0, 0 }
  77. };
  78. #endif
  79. //+-------------------------------------------------------------------------
  80. //
  81. // Function: HandleTestEnd
  82. //
  83. // Synopsis: Handles processing for the WM_TESTEND message.
  84. //
  85. // Effects:
  86. //
  87. // Arguments: void
  88. //
  89. // Requires:
  90. //
  91. // Returns: void
  92. //
  93. // Signals:
  94. //
  95. // Modifies:
  96. //
  97. // Algorithm: execute the next task in the task stack or sends
  98. // a TESTSCOMPLETED message back the message queue
  99. //
  100. // History: dd-mmm-yy Author Comment
  101. // 06-Feb-94 alexgo author
  102. // 13-Dec-94 MikeW Allow testing to continue after failures
  103. //
  104. // Notes: vApp must be initialized correctly for this function to
  105. // work properly.
  106. //
  107. // BUGBUG::Need to add output routines in here.
  108. //
  109. //--------------------------------------------------------------------------
  110. void HandleTestEnd( void )
  111. {
  112. assert(vApp.m_message == WM_TESTEND);
  113. switch( vApp.m_wparam )
  114. {
  115. case TEST_UNKNOWN:
  116. //we usually get this message from a test run
  117. //by RunApp (i.e. one that does not communicate
  118. //with us via windows messages). We'll check
  119. //the exit code and decide what to do.
  120. if( vApp.m_lparam != 0 )
  121. {
  122. //presumably an error
  123. OutputString("Test End, Status Unknown "
  124. "( %lx )\r\n\r\n", vApp.m_lparam);
  125. vApp.m_fGotErrors = TRUE;
  126. break;
  127. }
  128. // otherwise we fall through to the success case.
  129. case TEST_SUCCESS:
  130. OutputString("Test Success ( %lx )!\r\n\r\n",
  131. vApp.m_lparam);
  132. break;
  133. case TEST_FAILURE:
  134. OutputString("Test FAILED! ( %lx )\r\n\r\n", vApp.m_lparam);
  135. vApp.m_fGotErrors = TRUE;
  136. break;
  137. default:
  138. assert(0); //we should never get here
  139. break;
  140. }
  141. vApp.Reset();
  142. //
  143. // Now check to see if there are any more tests
  144. //
  145. while (!vApp.m_TaskStack.IsEmpty())
  146. {
  147. TaskItem ti;
  148. vApp.m_TaskStack.Pop(&ti);
  149. if (ti.szName != (LPSTR) 0)
  150. {
  151. vApp.m_TaskStack.Push(&ti);
  152. break;
  153. }
  154. }
  155. if (vApp.m_TaskStack.IsEmpty())
  156. {
  157. PostMessage(vApp.m_hwndMain,
  158. WM_TESTSCOMPLETED,
  159. vApp.m_wparam, vApp.m_lparam);
  160. }
  161. else
  162. {
  163. //if the stack is not empty, run
  164. //the next task
  165. PostMessage(vApp.m_hwndMain,
  166. WM_TESTSTART,
  167. 0, 0);
  168. }
  169. return;
  170. }
  171. //+-------------------------------------------------------------------------
  172. //
  173. // Function: HandleTestsCompleted
  174. //
  175. // Synopsis: Handles processing for the WM_TESTSCOMPLETED message.
  176. //
  177. // Effects:
  178. //
  179. // Arguments: void
  180. //
  181. // Requires:
  182. //
  183. // Returns: void
  184. //
  185. // Signals:
  186. //
  187. // Modifies:
  188. //
  189. // Algorithm:
  190. //
  191. // History: dd-mmm-yy Author Comment
  192. // 06-Feb-94 alexgo author
  193. //
  194. // Notes: vApp must be initialized correctly for this function to
  195. // work properly.
  196. //
  197. // BUGBUG::Need to add more output routines in here.
  198. //
  199. //--------------------------------------------------------------------------
  200. void HandleTestsCompleted( void )
  201. {
  202. char szBuf[128];
  203. assert(vApp.m_message == WM_TESTSCOMPLETED);
  204. //temporary output
  205. switch(vApp.m_fGotErrors)
  206. {
  207. case FALSE:
  208. OutputString("Tests PASSED!!\n");
  209. break;
  210. case TRUE:
  211. sprintf(szBuf, "Tests FAILED, code %lx",
  212. vApp.m_lparam);
  213. MessageBox(vApp.m_hwndMain, szBuf, "Ole Test Driver",
  214. MB_ICONEXCLAMATION | MB_OK);
  215. break;
  216. default:
  217. assert(0);
  218. }
  219. //
  220. // Reset the got error status
  221. //
  222. vApp.m_fGotErrors = FALSE;
  223. return;
  224. }
  225. //+-------------------------------------------------------------------------
  226. //
  227. // Function: RunAllTests
  228. //
  229. // Synopsis: Runs all the individual tests in the global list
  230. //
  231. // Effects:
  232. //
  233. // Arguments: pvArg -- the index at which individual tests
  234. // start in the global list.
  235. //
  236. // Requires:
  237. //
  238. // Returns: void
  239. //
  240. // Signals:
  241. //
  242. // Modifies:
  243. //
  244. // Algorithm:
  245. //
  246. // History: dd-mmm-yy Author Comment
  247. // 06-Feb-94 alexgo author
  248. //
  249. // Notes:
  250. // Tests will be run in the order they appear in the global
  251. // list.
  252. //
  253. //--------------------------------------------------------------------------
  254. void RunAllTests( void *pvArg )
  255. {
  256. ULONG index = (ULONG)pvArg;
  257. ULONG i;
  258. //find the number of tasks in the list (so we can push
  259. //them in reverse order).
  260. for (i = 0; vrgTaskList[i].szName != 0; i++ )
  261. {
  262. ;
  263. }
  264. assert( i > 1 );
  265. //now push the tasks onto the stack in reverse order.
  266. for (i--; i >= index; i-- )
  267. {
  268. vApp.m_TaskStack.Push(vrgTaskList + i);
  269. }
  270. //start the first one.
  271. vApp.m_TaskStack.PopAndExecute(NULL);
  272. return;
  273. }
  274. //+-------------------------------------------------------------------------
  275. //
  276. // Function: RunApi
  277. //
  278. // Synopsis: Runs the specified Api
  279. //
  280. // Effects:
  281. //
  282. // Arguments: [pvArg] -- the api to run
  283. //
  284. // Requires:
  285. //
  286. // Returns: void
  287. //
  288. // Signals:
  289. //
  290. // Modifies:
  291. //
  292. // Algorithm:
  293. //
  294. // History: dd-mmm-yy Author Comment
  295. // 23-Mar-94 alexgo author
  296. //
  297. // Notes:
  298. //
  299. //--------------------------------------------------------------------------
  300. void RunApi( void *pvArg )
  301. {
  302. HRESULT hresult;
  303. hresult = (*((HRESULT (*)(void))pvArg))();
  304. vApp.Reset();
  305. vApp.m_wparam = (hresult == NOERROR) ? TEST_SUCCESS : TEST_FAILURE;
  306. vApp.m_lparam = (LPARAM)hresult;
  307. vApp.m_message = WM_TESTEND;
  308. HandleTestEnd();
  309. }
  310. //+-------------------------------------------------------------------------
  311. //
  312. // Function: RunApp
  313. //
  314. // Synopsis: Runs the app specified in the argument
  315. //
  316. // Effects:
  317. //
  318. // Arguments: pvArg -- a string with the app to execute
  319. //
  320. // Requires:
  321. //
  322. // Returns: void
  323. //
  324. // Signals:
  325. //
  326. // Modifies:
  327. //
  328. // Algorithm: Create the process and wait for it to finish. The exit
  329. // status is then returned.
  330. //
  331. // History: dd-mmm-yy Author Comment
  332. // 06-Feb-94 alexgo author
  333. //
  334. // Notes:
  335. //
  336. //--------------------------------------------------------------------------
  337. void RunApp( void *pvArg )
  338. {
  339. WPARAM wparam = 0;
  340. DWORD error = 0;
  341. #ifdef WIN32
  342. PROCESS_INFORMATION procinfo;
  343. static STARTUPINFO startinfo; //to make it all zero
  344. assert(pvArg); //should be a valid ANSI string.
  345. startinfo.cb = sizeof(startinfo);
  346. if( CreateProcess(NULL, (LPTSTR)pvArg, NULL, NULL, NULL, NULL, NULL,
  347. NULL, &startinfo, &procinfo) )
  348. {
  349. //the process started, now wait for it to finish.
  350. WaitForSingleObject(procinfo.hProcess, INFINITE);
  351. //now get the return code of the process.
  352. GetExitCodeProcess(procinfo.hProcess, &error);
  353. wparam = TEST_UNKNOWN;
  354. }
  355. else
  356. {
  357. wparam = TEST_FAILURE;
  358. error = GetLastError();
  359. }
  360. #endif // WIN32
  361. // since there will be no WM_TESTEND message, we must do the
  362. // test end processing ourselves.
  363. vApp.Reset();
  364. vApp.m_wparam = wparam;
  365. vApp.m_lparam = error;
  366. vApp.m_message = WM_TESTEND;
  367. HandleTestEnd();
  368. return;
  369. }
  370. //+-------------------------------------------------------------------------
  371. //
  372. // Function: RunTestOnThread
  373. //
  374. // Synopsis: creates a thread to run a test function
  375. //
  376. // Effects: creates a new thread
  377. //
  378. // Arguments: [pvArg] -- a function pointer to the test function
  379. //
  380. // Requires:
  381. //
  382. // Returns: void
  383. //
  384. // Signals:
  385. //
  386. // Modifies:
  387. //
  388. // Algorithm:
  389. //
  390. // History: dd-mmm-yy Author Comment
  391. // 04-Jan-95 t-ScottH author
  392. //
  393. // Notes:
  394. //
  395. //--------------------------------------------------------------------------
  396. void RunTestOnThread(void *pvArg)
  397. {
  398. HANDLE hMainTestThread;
  399. DWORD dwThreadId = 0;
  400. hMainTestThread = CreateThread(
  401. NULL, // security attributes
  402. 0, // stack size (default)
  403. (LPTHREAD_START_ROUTINE)pvArg, // address of thread function
  404. NULL, // arguments of thread function
  405. 0, // creation flags
  406. &dwThreadId ); // address of new thread ID
  407. assert(hMainTestThread);
  408. CloseHandle(hMainTestThread);
  409. return;
  410. }
  411.