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.

311 lines
6.2 KiB

  1. //+------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993.
  5. //
  6. // File: bm_rpc2.cxx
  7. //
  8. // Contents: ORPC Method Invocation tests
  9. //
  10. // Classes: CRpcTest22
  11. //
  12. // History: 08-08-95 Rickhi Created
  13. //
  14. //--------------------------------------------------------------------------
  15. #include <headers.cxx>
  16. #pragma hdrstop
  17. #include <bm_rpc2.hxx>
  18. #include <stream.hxx>
  19. #include <oletest.hxx>
  20. #include <tracelog.hxx>
  21. #include <cqi.hxx>
  22. TCHAR *CRpcTest2::Name ()
  23. {
  24. return TEXT("RpcTest2");
  25. }
  26. SCODE CRpcTest2::Setup (CTestInput *pInput)
  27. {
  28. CTestBase::Setup(pInput);
  29. SCODE sc = pInput->GetGUID(&m_ClsID, Name(), TEXT("Clsid_Local"));
  30. if (FAILED(sc))
  31. {
  32. Log (TEXT("Setup - GetClassID failed."), sc);
  33. return sc;
  34. }
  35. // get iteration count
  36. m_ulIterations = pInput->GetIterations(Name());
  37. // initialize timing arrays
  38. INIT_RESULTS(m_ulNULLTime);
  39. INIT_RESULTS(m_ulIUnknownBestInTime);
  40. INIT_RESULTS(m_ulIUnknownWorstInTime);
  41. INIT_RESULTS(m_ulIUnknownBestOutTime);
  42. INIT_RESULTS(m_ulIUnknownWorstOutTime);
  43. m_pRPC = NULL;
  44. m_pStm = NULL;
  45. // get the stream of data to unmarshal from the file.
  46. TCHAR szFile[MAX_PATH];
  47. pInput->GetConfigString(Name(), TEXT("File"), TEXT(" "),
  48. szFile, sizeof(szFile)/sizeof(TCHAR));
  49. if (!wcscmp(szFile,L" "))
  50. {
  51. sc = E_INVALIDARG;
  52. Log (TEXT("Setup - Get FileName failed."), sc);
  53. return sc;
  54. }
  55. // now make a stream on file
  56. m_pStm = (IStream *) new CStreamOnFile(szFile, sc, TRUE);
  57. if (FAILED(sc))
  58. {
  59. Log (TEXT("Setup - new CStreamOnFile failed."), sc);
  60. return sc;
  61. }
  62. m_punkInproc = (IUnknown *) new CQI(CLSID_QI);
  63. return S_OK;
  64. }
  65. SCODE CRpcTest2::Cleanup ()
  66. {
  67. if (m_pRPC)
  68. m_pRPC->Release();
  69. if (m_punkInproc)
  70. m_punkInproc->Release();
  71. return S_OK;
  72. }
  73. SCODE CRpcTest2::PrepareForRun()
  74. {
  75. SCODE sc = InitCOM();
  76. if (FAILED(sc))
  77. {
  78. Log (TEXT("Setup - CoInitialize failed."), sc);
  79. return sc;
  80. }
  81. // get the interface to call on
  82. // reset the stream to the beginning
  83. LARGE_INTEGER libMove;
  84. LISet32(libMove, 0x00000000);
  85. m_pStm->Seek(libMove, STREAM_SEEK_SET, NULL);
  86. // unmarshal the interface
  87. sc = CoUnmarshalInterface(m_pStm, IID_IRpcTest, (void **)&m_pRPC);
  88. if (FAILED(sc))
  89. {
  90. Log (TEXT("PrepareForRun - CoUnmarshalInteface failed."), sc);
  91. UninitCOM();
  92. }
  93. Sleep(500);
  94. return sc;
  95. }
  96. void CRpcTest2::CleanupFromRun()
  97. {
  98. if (m_pRPC)
  99. {
  100. m_pRPC->Release();
  101. m_pRPC = NULL;
  102. }
  103. UninitCOM();
  104. Sleep(500);
  105. }
  106. SCODE CRpcTest2::Run ()
  107. {
  108. CStopWatch sw;
  109. SCODE sc;
  110. ULONG iIter;
  111. //
  112. // NULL call tests
  113. //
  114. if (FAILED(sc = PrepareForRun()))
  115. {
  116. return sc;
  117. }
  118. Sleep(2000);
  119. for (iIter=0; iIter<TEST_MAX_ITERATIONS_PRIVATE; iIter++)
  120. {
  121. sw.Reset();
  122. m_pRPC->Void();
  123. m_ulNULLTime[iIter] = sw.Read();
  124. }
  125. CleanupFromRun();
  126. //
  127. // IUnknown [in] Best Case - The other side already has
  128. // the interface we are passing in.
  129. //
  130. if (FAILED(sc = PrepareForRun()))
  131. {
  132. return sc;
  133. }
  134. // give the other side the interface to keep
  135. sc = m_pRPC->IUnknownInKeep(m_punkInproc);
  136. for (iIter=0; iIter<m_ulIterations; iIter++)
  137. {
  138. sw.Reset();
  139. sc = m_pRPC->IUnknownIn(m_punkInproc);
  140. m_ulIUnknownBestInTime[iIter] = sw.Read();
  141. }
  142. sc = m_pRPC->IUnknownInRelease();
  143. CleanupFromRun();
  144. //
  145. // IUnknown [out] Best Case - We already have the interface being
  146. // passed back to us.
  147. //
  148. if (FAILED(sc = PrepareForRun()))
  149. {
  150. return sc;
  151. }
  152. // get the interface from the other side, and hang onto it.
  153. IUnknown *punkOut = NULL;
  154. sc = m_pRPC->IUnknownOut(&punkOut);
  155. for (iIter=0; iIter<m_ulIterations; iIter++)
  156. {
  157. IUnknown *punkOut2 = NULL;
  158. sw.Reset();
  159. sc = m_pRPC->IUnknownOut(&punkOut2);
  160. m_ulIUnknownBestOutTime[iIter] = sw.Read();
  161. if (SUCCEEDED(sc))
  162. {
  163. // release 1 reference
  164. punkOut2->Release();
  165. }
  166. }
  167. // release the ptr we are holding, should be final release.
  168. punkOut->Release();
  169. CleanupFromRun();
  170. //
  171. // IUnknown [in] Worst Case - the other side does not have
  172. // the interface we are passing in, nor have we ever marshaled
  173. // an interface before in this process. The other side does not
  174. // keep the interface we hand it. We loop several times, each time
  175. // we do OleInit, OleUninit.
  176. //
  177. for (iIter=0; iIter<m_ulIterations; iIter++)
  178. {
  179. if (FAILED(sc = PrepareForRun()))
  180. {
  181. return sc;
  182. }
  183. sw.Reset();
  184. sc = m_pRPC->IUnknownIn(m_punkInproc);
  185. m_ulIUnknownWorstInTime[iIter] = sw.Read();
  186. CleanupFromRun();
  187. }
  188. //
  189. // IUnknown [out] Worst Case - the other side is giving us a brand
  190. // new object, that it has never marshaled before. We do not hold onto
  191. // the interface. We loop several times, each time
  192. // we do OleInit, OleUninit.
  193. //
  194. for (iIter=0; iIter<m_ulIterations; iIter++)
  195. {
  196. if (FAILED(sc = PrepareForRun()))
  197. {
  198. return sc;
  199. }
  200. sw.Reset();
  201. // BUGBUG sc = m_pRPC->IUnknownNewOut(&punkOut);
  202. sc = m_pRPC->IUnknownOut(&punkOut);
  203. m_ulIUnknownWorstOutTime[iIter] = sw.Read();
  204. if (SUCCEEDED(sc))
  205. {
  206. punkOut->Release();
  207. }
  208. CleanupFromRun();
  209. }
  210. return S_OK;
  211. }
  212. SCODE CRpcTest2::Report (CTestOutput &output)
  213. {
  214. output.WriteSectionHeader (Name(), TEXT("Object Rpc2"), *m_pInput);
  215. output.WriteString(TEXT("\n"));
  216. output.WriteResults(TEXT("NULL "), TEST_MAX_ITERATIONS_PRIVATE, m_ulNULLTime);
  217. output.WriteResults(TEXT("IUnknown In Best "), m_ulIterations, m_ulIUnknownBestInTime);
  218. output.WriteResults(TEXT("IUnknown In Worst"), m_ulIterations, m_ulIUnknownWorstInTime);
  219. output.WriteResults(TEXT("IUnknown Out Best "), m_ulIterations, m_ulIUnknownBestOutTime);
  220. output.WriteResults(TEXT("IUnknown Out Worst"), m_ulIterations, m_ulIUnknownWorstOutTime);
  221. return S_OK;
  222. }
  223.