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.

417 lines
9.4 KiB

  1. //+------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993.
  5. //
  6. // File: bm_marsh.cxx
  7. //
  8. // Contents: Mashalling test
  9. //
  10. // Classes: COleMarshalTest
  11. //
  12. // History: 29-July-93 t-martig Created
  13. //
  14. //--------------------------------------------------------------------------
  15. #include <headers.cxx>
  16. #pragma hdrstop
  17. #include <bm_mrsh2.hxx>
  18. #include <oletest.hxx>
  19. #include <rpc.h>
  20. #include <rpcdce.h>
  21. // funciton prototype
  22. DWORD _stdcall FnThread2(void *param);
  23. ULARGE_INTEGER ulSeekStart[REPS]; // stream starts
  24. LARGE_INTEGER libMove[REPS];
  25. const IID *iid2[] = {&IID_IUnknown, &IID_IUnknown,
  26. &IID_IAdviseSink, &IID_IAdviseSink,
  27. &IID_IDataObject, &IID_IDataObject,
  28. &IID_IOleObject, &IID_IOleObject,
  29. &IID_IOleClientSite, &IID_IOleClientSite,
  30. &IID_IParseDisplayName, &IID_IParseDisplayName,
  31. &IID_IPersistStorage, &IID_IPersistStorage,
  32. &IID_IPersistFile, &IID_IPersistFile,
  33. &IID_IStorage, &IID_IStorage,
  34. &IID_IOleContainer, &IID_IOleContainer,
  35. &IID_IOleItemContainer, &IID_IOleItemContainer,
  36. &IID_IOleInPlaceSite, &IID_IOleInPlaceActiveObject,
  37. &IID_IOleInPlaceObject, &IID_IOleInPlaceUIWindow,
  38. &IID_IOleInPlaceFrame, &IID_IOleWindow};
  39. TCHAR *COleMarshalTest2::Name ()
  40. {
  41. return TEXT("Marshalling2");
  42. }
  43. SCODE COleMarshalTest2::Setup (CTestInput *pInput)
  44. {
  45. SCODE sc;
  46. m_hThrd = NULL;
  47. m_dwTID1 = GetCurrentThreadId();
  48. for (ULONG i=0; i<REPS; i++)
  49. m_pStm[i] = NULL;
  50. CTestBase::Setup(pInput);
  51. // Get number of iterations
  52. m_ulIterations = pInput->GetIterations(Name());
  53. // set NULL in case of error
  54. for (i=0; i<m_ulIterations; i++)
  55. m_punk[i] = NULL;
  56. // Get custom ClsID from .ini file
  57. pInput->GetClassID(&m_ClsID, Name());
  58. // Get class activation context from .ini file
  59. m_dwClsCtx = pInput->GetClassCtx(Name());
  60. for (i=0; i<REPS; i++)
  61. {
  62. INIT_RESULTS (m_ulMarshalTime[i]);
  63. INIT_RESULTS (m_ulUnmarshalTime[i]);
  64. INIT_RESULTS (m_ulReleaseTime[i]);
  65. INIT_RESULTS (m_ulMarshalTime2[i]);
  66. INIT_RESULTS (m_ulUnmarshalTime2[i]);
  67. INIT_RESULTS (m_ulReleaseTime2[i]);
  68. }
  69. sc = InitCOM();
  70. if (FAILED(sc))
  71. {
  72. Log (TEXT("Setup - CoInitialize failed."), sc);
  73. return sc;
  74. }
  75. for (i=0; i<m_ulIterations; i++)
  76. {
  77. // create an instance of the object to marshal
  78. sc = CoCreateInstance(m_ClsID, NULL, m_dwClsCtx,
  79. IID_IUnknown, (void **)&m_punk[i]);
  80. if (FAILED(sc))
  81. {
  82. Log (TEXT("Setup - CoCreateInstance failed"), sc);
  83. return sc;
  84. }
  85. }
  86. for (i=0; i<REPS; i++)
  87. {
  88. // create a stream to marshal the interface into
  89. SCODE sc = CreateStreamOnHGlobal(NULL, 0, &m_pStm[i]);
  90. if (FAILED(sc))
  91. {
  92. Log (TEXT("Setup - CreateStreamOnHGlobal failed"), sc);
  93. }
  94. else
  95. {
  96. // write some data to init the stream
  97. DWORD dwTemp;
  98. m_pStm[i]->Write(&dwTemp, sizeof(DWORD), NULL);
  99. }
  100. }
  101. m_hThrd = CreateThread(NULL, 0, FnThread2, (void *)this, 0, &m_dwTID2);
  102. if (m_hThrd == NULL)
  103. {
  104. Log (TEXT("Setup - CreateThread failed"), sc);
  105. }
  106. Sleep(50); // let the other thread initialize
  107. return S_OK;
  108. }
  109. SCODE COleMarshalTest2::Cleanup ()
  110. {
  111. // release objects
  112. for (ULONG i=0; i<m_ulIterations; i++)
  113. {
  114. if (m_punk[i])
  115. m_punk[i]->Release();
  116. }
  117. for (i=0; i<REPS; i++)
  118. {
  119. if (m_pStm[i])
  120. m_pStm[i]->Release();
  121. }
  122. UninitCOM();
  123. // close all the handles
  124. CloseHandle(m_hThrd);
  125. return S_OK;
  126. }
  127. DWORD _stdcall FnThread2(void *param)
  128. {
  129. COleMarshalTest2 *pMrshlTst = (COleMarshalTest2 *)param;
  130. return pMrshlTst->Run2();
  131. }
  132. SCODE COleMarshalTest2::Run ()
  133. {
  134. CStopWatch sw;
  135. LPVOID FAR pv[REPS];
  136. for (ULONG iIter=0; iIter<m_ulIterations; iIter++)
  137. {
  138. SCODE sc[REPS];
  139. // settle down before running
  140. Sleep(100);
  141. // first, marshal the interface REPS times.
  142. for (ULONG i=0; i<REPS; i++)
  143. {
  144. // save current stream seek pointer
  145. LISet32(libMove[i], 0x00000000);
  146. m_pStm[i]->Seek(libMove[i], STREAM_SEEK_CUR, &ulSeekStart[i]);
  147. // marshal the interface into the stream
  148. sw.Reset();
  149. sc[i] = CoMarshalInterface(m_pStm[i], *iid2[i], m_punk[iIter],
  150. 0, 0, MSHLFLAGS_NORMAL);
  151. m_ulMarshalTime[i][iIter] = sw.Read ();
  152. Log (TEXT("CoMarshalInterface"), sc[i]);
  153. if (FAILED(sc[i]))
  154. {
  155. m_ulMarshalTime[i][iIter] = NOTAVAIL;
  156. }
  157. }
  158. // reset the stream ptrs
  159. for (i=0; i<REPS; i++)
  160. {
  161. // set stream ptr back to the starting position
  162. LISet32(libMove[i], ulSeekStart[i].LowPart);
  163. m_pStm[i]->Seek(libMove[i], STREAM_SEEK_SET, &ulSeekStart[i]);
  164. }
  165. // kick the other thread alive
  166. PostThreadMessage(m_dwTID2, WM_QUIT, NULL, NULL);
  167. // enter modal loop to dispatch ORPC messages
  168. MSG msg;
  169. while (GetMessage(&msg, NULL, WM_NULL, WM_NULL))
  170. {
  171. DispatchMessage(&msg);
  172. }
  173. // reset the stream ptrs
  174. for (i=0; i<REPS; i++)
  175. {
  176. // set stream ptr back to the starting position
  177. LISet32(libMove[i], ulSeekStart[i].LowPart);
  178. m_pStm[i]->Seek(libMove[i], STREAM_SEEK_SET, &ulSeekStart[i]);
  179. }
  180. Sleep(100);
  181. // unmarshal the interface ptrs
  182. for (i=0; i<REPS; i++)
  183. {
  184. // unmarshal the interface from the stream
  185. sw.Reset ();
  186. sc[i] = CoUnmarshalInterface(m_pStm[i], *iid2[i], &pv[i]);
  187. m_ulUnmarshalTime2[i][iIter] = sw.Read ();
  188. Log (TEXT("CoUnmarshalInterface"), sc[i]);
  189. }
  190. Sleep(100);
  191. // release all the interface ptrs we got
  192. for (i=0; i<REPS; i++)
  193. {
  194. if (SUCCEEDED(sc[i]))
  195. {
  196. sw.Reset ();
  197. ((IUnknown *)pv[i])->Release ();
  198. m_ulReleaseTime2[i][iIter] = sw.Read ();
  199. Log (TEXT("Release"), sc[i]);
  200. }
  201. else
  202. {
  203. m_ulReleaseTime2[i][iIter] = NOTAVAIL;
  204. m_ulUnmarshalTime2[i][iIter] = NOTAVAIL;
  205. }
  206. }
  207. // reset the stream ptrs
  208. for (i=0; i<REPS; i++)
  209. {
  210. // set stream ptr back to the starting position
  211. LISet32(libMove[i], ulSeekStart[i].LowPart);
  212. m_pStm[i]->Seek(libMove[i], STREAM_SEEK_SET, &ulSeekStart[i]);
  213. }
  214. }
  215. return S_OK;
  216. }
  217. SCODE COleMarshalTest2::Run2 ()
  218. {
  219. SCODE sc = InitCOM();
  220. if (FAILED(sc))
  221. {
  222. Log (TEXT("Thread2 - CoInitialize failed."), sc);
  223. return sc;
  224. }
  225. CStopWatch sw;
  226. LPVOID FAR pv[REPS];
  227. for (ULONG iIter=0; iIter<m_ulIterations; iIter++)
  228. {
  229. SCODE sc[REPS];
  230. // enter modal loop to dispatch ORPC messages
  231. MSG msg;
  232. while (GetMessage(&msg, NULL, WM_NULL, WM_NULL))
  233. {
  234. DispatchMessage(&msg);
  235. }
  236. Sleep(100);
  237. // UnmarshalInterface the interfaces from the stream
  238. for (ULONG i=0; i<REPS; i++)
  239. {
  240. // unmarshal the interface from the stream
  241. sw.Reset ();
  242. sc[i] = CoUnmarshalInterface(m_pStm[i], *iid2[i], &pv[i]);
  243. m_ulUnmarshalTime[i][iIter] = sw.Read ();
  244. Log (TEXT("CoUnmarshalInterface"), sc[i]);
  245. }
  246. // now reset the stream ptrs
  247. for (i=0; i<REPS; i++)
  248. {
  249. // set stream ptr back to the starting position
  250. LISet32(libMove[i], ulSeekStart[i].LowPart);
  251. m_pStm[i]->Seek(libMove[i], STREAM_SEEK_SET, &ulSeekStart[i]);
  252. }
  253. Sleep(100);
  254. // remarshal the interface proxies
  255. for (i=0; i<REPS; i++)
  256. {
  257. sw.Reset();
  258. sc[i] = CoMarshalInterface(m_pStm[i], *iid2[i], (IUnknown *)pv[i],
  259. 0, 0, MSHLFLAGS_NORMAL);
  260. m_ulMarshalTime2[i][iIter] = sw.Read ();
  261. Log (TEXT("CoMarshalInterface"), sc[i]);
  262. if (FAILED(sc[i]))
  263. {
  264. m_ulMarshalTime2[i][iIter] = NOTAVAIL;
  265. }
  266. }
  267. Sleep(100);
  268. // release all the interface ptrs we got
  269. for (i=0; i<REPS; i++)
  270. {
  271. if (SUCCEEDED(sc[i]))
  272. {
  273. sw.Reset ();
  274. ((IUnknown *)pv[i])->Release ();
  275. m_ulReleaseTime[i][iIter] = sw.Read ();
  276. Log (TEXT("Release"), sc[i]);
  277. }
  278. else
  279. {
  280. m_ulReleaseTime[i][iIter] = NOTAVAIL;
  281. m_ulUnmarshalTime[i][iIter] = NOTAVAIL;
  282. }
  283. }
  284. // signal the other thread it is OK to go.
  285. PostThreadMessage(m_dwTID1, WM_QUIT, NULL, NULL);
  286. }
  287. UninitCOM();
  288. return S_OK;
  289. }
  290. SCODE COleMarshalTest2::Report (CTestOutput &output)
  291. {
  292. output.WriteSectionHeader (Name(),
  293. TEXT("Interface Marshalling2"),
  294. *m_pInput);
  295. for (ULONG iCtx=0; iCtx<1; iCtx++)
  296. {
  297. output.WriteString (TEXT("\n"));
  298. output.WriteClassID (&m_ClsID);
  299. output.WriteString (apszClsCtx[0]);
  300. output.WriteString (TEXT("\n"));
  301. for (ULONG i=0; i<REPS; i++)
  302. {
  303. output.WriteResults(TEXT("CoMarshalInterface "), m_ulIterations, m_ulMarshalTime[i]);
  304. }
  305. output.WriteString (TEXT("\n"));
  306. for (i=0; i<REPS; i++)
  307. {
  308. output.WriteResults(TEXT("CoUnmarshalInterface"), m_ulIterations, m_ulUnmarshalTime[i]);
  309. }
  310. output.WriteString (TEXT("\n"));
  311. for (i=0; i<REPS; i++)
  312. {
  313. output.WriteResults(TEXT("Release Interface "), m_ulIterations, m_ulReleaseTime[i]);
  314. }
  315. output.WriteString (TEXT("\n"));
  316. for (i=0; i<REPS; i++)
  317. {
  318. output.WriteResults(TEXT("CoMarshalInterface2 "), m_ulIterations, m_ulMarshalTime2[i]);
  319. }
  320. output.WriteString (TEXT("\n"));
  321. for (i=0; i<REPS; i++)
  322. {
  323. output.WriteResults(TEXT("CoUnmarshalInterface2"), m_ulIterations, m_ulUnmarshalTime2[i]);
  324. }
  325. output.WriteString (TEXT("\n"));
  326. for (i=0; i<REPS; i++)
  327. {
  328. output.WriteResults(TEXT("Release Interface2 "), m_ulIterations, m_ulReleaseTime2[i]);
  329. }
  330. output.WriteString (TEXT("\n"));
  331. }
  332. return S_OK;
  333. }