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.

296 lines
7.8 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_marsh.hxx>
  18. #include <oletest.hxx>
  19. #include <rpc.h>
  20. #include <rpcdce.h>
  21. // extern "C" RPC_STATUS UuidCreate(GUID *pguid);
  22. TCHAR *COleMarshalTest::Name ()
  23. {
  24. return TEXT("Marshalling");
  25. }
  26. SCODE COleMarshalTest::Setup (CTestInput *pInput)
  27. {
  28. SCODE sc;
  29. for (ULONG i=0; i<REPS; i++)
  30. m_pStm[i] = NULL;
  31. CTestBase::Setup(pInput);
  32. // Get number of iterations
  33. m_ulIterations = pInput->GetIterations(Name());
  34. // set NULL in case of error
  35. for (i=0; i<m_ulIterations; i++)
  36. m_punk[i] = NULL;
  37. // Get custom ClsID from .ini file
  38. pInput->GetClassID(&m_ClsID, Name());
  39. // Get class activation context from .ini file
  40. m_dwClsCtx = pInput->GetClassCtx(Name());
  41. INIT_RESULTS (m_ulUuidCreateTime);
  42. for (i=0; i<REPS; i++)
  43. {
  44. INIT_RESULTS (m_ulMarshalTime[i]);
  45. INIT_RESULTS (m_ulUnmarshalTime[i]);
  46. INIT_RESULTS (m_ulLockObjectTime[i]);
  47. INIT_RESULTS (m_ulGetStdMarshalTime[i]);
  48. INIT_RESULTS (m_ulGetMarshalSizeTime[i]);
  49. INIT_RESULTS (m_ulDisconnectTime[i]);
  50. }
  51. sc = InitCOM();
  52. if (FAILED(sc))
  53. {
  54. Log (TEXT("Setup - CoInitialize failed."), sc);
  55. return sc;
  56. }
  57. for (i=0; i<m_ulIterations; i++)
  58. {
  59. // create an instance of the object to marshal
  60. sc = CoCreateInstance(m_ClsID, NULL, m_dwClsCtx,
  61. IID_IUnknown, (void **)&m_punk[i]);
  62. if (FAILED(sc))
  63. {
  64. Log (TEXT("Setup - CoCreateInstance failed"), sc);
  65. return sc;
  66. }
  67. }
  68. for (i=0; i<REPS; i++)
  69. {
  70. // create a stream to marshal the interface into
  71. SCODE sc = CreateStreamOnHGlobal(NULL, 0, &m_pStm[i]);
  72. if (FAILED(sc))
  73. {
  74. Log (TEXT("Setup - CreateStreamOnHGlobal failed"), sc);
  75. }
  76. else
  77. {
  78. // write some data to init the stream
  79. DWORD dwTemp;
  80. m_pStm[i]->Write(&dwTemp, sizeof(DWORD), NULL);
  81. }
  82. }
  83. return S_OK;
  84. }
  85. SCODE COleMarshalTest::Cleanup ()
  86. {
  87. // release objects
  88. for (ULONG i=0; i<m_ulIterations; i++)
  89. {
  90. if (m_punk[i])
  91. m_punk[i]->Release();
  92. }
  93. for (i=0; i<REPS; i++)
  94. {
  95. if (m_pStm[i])
  96. m_pStm[i]->Release();
  97. }
  98. UninitCOM();
  99. return S_OK;
  100. }
  101. SCODE COleMarshalTest::Run ()
  102. {
  103. CStopWatch sw;
  104. LPVOID FAR pv;
  105. for (ULONG iIter=0; iIter<m_ulIterations; iIter++)
  106. {
  107. SCODE sc[REPS];
  108. ULARGE_INTEGER ulSeekStart[REPS];
  109. LARGE_INTEGER libMove[REPS];
  110. // create Uuid's
  111. GUID guid;
  112. sw.Reset();
  113. sc[0] = UuidCreate(&guid);
  114. m_ulUuidCreateTime[iIter] = sw.Read();
  115. Log (TEXT("UuidCreate"), sc[0]);
  116. // first, marshal the interface REPS times.
  117. for (ULONG i=0; i<REPS; i++)
  118. {
  119. // save current stream seek pointer
  120. LISet32(libMove[i], 0x00000000);
  121. m_pStm[i]->Seek(libMove[i], STREAM_SEEK_CUR, &ulSeekStart[i]);
  122. // marshal the interface into the stream
  123. sw.Reset();
  124. sc[i] = CoMarshalInterface(m_pStm[i], IID_IUnknown, m_punk[iIter],
  125. 0, 0, MSHLFLAGS_NORMAL);
  126. m_ulMarshalTime[i][iIter] = sw.Read ();
  127. Log (TEXT("CoMarshalInterface"), sc[i]);
  128. if (FAILED(sc[i]))
  129. {
  130. m_ulMarshalTime[i][iIter] = NOTAVAIL;
  131. }
  132. }
  133. // now ReleaseMarshalData once
  134. i = 0;
  135. {
  136. // set stream ptr back to the starting position
  137. LISet32(libMove[i], ulSeekStart[i].LowPart);
  138. m_pStm[i]->Seek(libMove[i], STREAM_SEEK_SET, &ulSeekStart[i]);
  139. // unmarshal the interface from the stream
  140. sw.Reset ();
  141. sc[i] = CoReleaseMarshalData(m_pStm[i]);
  142. m_ulUnmarshalTime[i][iIter] = sw.Read ();
  143. Log (TEXT("CoReleaseMarshalData"), sc[i]);
  144. }
  145. // now UnmarshalInterface the remaining times
  146. for (i=1; i<REPS; i++)
  147. {
  148. if (FAILED(sc[i]))
  149. continue;
  150. // set stream ptr back to the starting position
  151. LISet32(libMove[i], ulSeekStart[i].LowPart);
  152. m_pStm[i]->Seek(libMove[i], STREAM_SEEK_SET, &ulSeekStart[i]);
  153. // unmarshal the interface from the stream
  154. sw.Reset ();
  155. sc[i] = CoUnmarshalInterface(m_pStm[i], IID_IUnknown, &pv);
  156. m_ulUnmarshalTime[i][iIter] = sw.Read ();
  157. Log (TEXT("CoUnmarshalInterface"), sc[i]);
  158. if (SUCCEEDED(sc[i]))
  159. {
  160. ((IUnknown *)pv)->Release (); // Unmarshal called AddRef
  161. }
  162. else
  163. {
  164. m_ulUnmarshalTime[i][iIter] = NOTAVAIL;
  165. }
  166. }
  167. // call CoLockObjectExternal
  168. sw.Reset();
  169. sc[0] = CoLockObjectExternal(m_punk[iIter], TRUE, FALSE);
  170. m_ulLockObjectTime[0][iIter] = sw.Read();
  171. Log (TEXT("CoLockObjectExternal"), sc[0]);
  172. sw.Reset();
  173. sc[1] = CoLockObjectExternal(m_punk[iIter], FALSE, FALSE);
  174. m_ulLockObjectTime[1][iIter] = sw.Read();
  175. Log (TEXT("CoLockObjectExternal"), sc[1]);
  176. // call CoGetStdMarshal
  177. IMarshal *pIM = NULL;
  178. sw.Reset();
  179. sc[0] = CoGetStandardMarshal(IID_IUnknown, m_punk[iIter], 0, NULL,
  180. MSHLFLAGS_NORMAL, &pIM);
  181. m_ulGetStdMarshalTime[0][iIter] = sw.Read();
  182. Log (TEXT("CoGetStandardMarshal"), sc[0]);
  183. sw.Reset();
  184. pIM->Release();
  185. m_ulGetStdMarshalTime[1][iIter] = sw.Read();
  186. Log (TEXT("Release StdMarshal"), sc[1]);
  187. // call CoGetMarshalSizeMax
  188. ULONG ulSize = 0;
  189. sw.Reset();
  190. sc[0] = CoGetMarshalSizeMax(&ulSize, IID_IUnknown, m_punk[iIter],
  191. 0, NULL,MSHLFLAGS_NORMAL);
  192. m_ulGetMarshalSizeTime[0][iIter] = sw.Read();
  193. Log (TEXT("CoGetMarshalSizeMax"), sc[0]);
  194. // call CoDisconnectObject
  195. sc[0] = CoLockObjectExternal(m_punk[iIter], TRUE, FALSE);
  196. sw.Reset();
  197. sc[0] = CoDisconnectObject(m_punk[iIter], 0);
  198. m_ulDisconnectTime[0][iIter] = sw.Read();
  199. Log (TEXT("CoDisconnectObject"), sc[0]);
  200. sc[0] = CoLockObjectExternal(m_punk[iIter], FALSE, FALSE);
  201. }
  202. return S_OK;
  203. }
  204. SCODE COleMarshalTest::Report (CTestOutput &output)
  205. {
  206. output.WriteSectionHeader (Name(),
  207. TEXT("Interface Marshalling"),
  208. *m_pInput);
  209. for (ULONG iCtx=0; iCtx<1; iCtx++)
  210. {
  211. output.WriteString (TEXT("\n"));
  212. output.WriteClassID (&m_ClsID);
  213. output.WriteString (apszClsCtx[0]);
  214. output.WriteString (TEXT("\n"));
  215. output.WriteResults (TEXT("UuidCreate "), m_ulIterations, m_ulUuidCreateTime);
  216. output.WriteString (TEXT("\n"));
  217. output.WriteResults (TEXT("CoMarshalInterface 1"), m_ulIterations, m_ulMarshalTime[0]);
  218. output.WriteResults (TEXT("CoMarshalInterface 2"), m_ulIterations, m_ulMarshalTime[1]);
  219. output.WriteResults (TEXT("CoMarshalInterface 3"), m_ulIterations, m_ulMarshalTime[2]);
  220. output.WriteString (TEXT("\n"));
  221. output.WriteResults (TEXT("CoReleaseMarshalData 3"), m_ulIterations, m_ulUnmarshalTime[0]);
  222. output.WriteResults (TEXT("CoUnmarshalInterface 2"), m_ulIterations, m_ulUnmarshalTime[1]);
  223. output.WriteResults (TEXT("CoUnmarshalInterface 1"), m_ulIterations, m_ulUnmarshalTime[2]);
  224. output.WriteString (TEXT("\n"));
  225. output.WriteResults (TEXT("CoLockObjectExternal L"), m_ulIterations, m_ulLockObjectTime[0]);
  226. output.WriteResults (TEXT("CoLockObjectExternal U"), m_ulIterations, m_ulLockObjectTime[1]);
  227. output.WriteString (TEXT("\n"));
  228. output.WriteResults (TEXT("CoGetStandardMarshal "), m_ulIterations, m_ulGetStdMarshalTime[0]);
  229. output.WriteResults (TEXT("pIMarshal->Release "), m_ulIterations, m_ulGetStdMarshalTime[1]);
  230. output.WriteString (TEXT("\n"));
  231. output.WriteResults (TEXT("CoDisconnectObject "), m_ulIterations, m_ulDisconnectTime[0]);
  232. }
  233. return S_OK;
  234. }