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.

366 lines
8.5 KiB

  1. //+------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993.
  5. //
  6. // File: bm_rot.cxx
  7. //
  8. // Contents: Ole running object table test (ROT)
  9. //
  10. // Classes: CROTTest
  11. //
  12. // History: 9-July-93 t-martig Created
  13. //
  14. //--------------------------------------------------------------------------
  15. #include <headers.cxx>
  16. #pragma hdrstop
  17. #include <bm_rot.hxx>
  18. #include <cact.hxx> // CTestAct
  19. // function used by CTestAct. need not do anything for our usage.
  20. void GlobalRefs(BOOL fAdd)
  21. {
  22. }
  23. TCHAR *CROTTest::Name ()
  24. {
  25. return TEXT("ROT");
  26. }
  27. SCODE CROTTest::Setup (CTestInput *pInput)
  28. {
  29. IClassFactory *pICF = NULL;
  30. IPersistFile *pIPF = NULL;
  31. SCODE sc = S_OK, scRet = S_OK;
  32. CTestBase::Setup(pInput);
  33. // get the iteration count from the ini file
  34. m_ulIterations = pInput->GetIterations(Name());
  35. m_ulEntries = 1;
  36. // for each class ctx, get the classid, and init internal state
  37. for (ULONG iCtx=0; iCtx<CNT_CLSCTX; iCtx++)
  38. {
  39. // Get ClsID for this Ctx from the .ini file
  40. sc = pInput->GetGUID(&m_ClsID[iCtx], Name(), apszClsIDName[iCtx]);
  41. if (FAILED(sc))
  42. {
  43. Log (TEXT("Setup - GetClassID failed."), sc);
  44. return sc;
  45. }
  46. INIT_RESULTS(m_ulGetROTTime[iCtx]);
  47. INIT_RESULTS(m_ulReleaseTime[iCtx]);
  48. INIT_RESULTS(m_ulRegisterTime[iCtx]);
  49. INIT_RESULTS(m_ulRevokeTime[iCtx]);
  50. INIT_RESULTS(m_ulNoteChangeTime[iCtx]);
  51. INIT_RESULTS(m_ulGetChangeTime[iCtx]);
  52. INIT_RESULTS(m_ulIsRunningTime[iCtx]);
  53. INIT_RESULTS(m_ulGetObjectTime[iCtx]);
  54. INIT_RESULTS(m_ulEnumRunningTime[iCtx]);
  55. }
  56. sc = InitCOM();
  57. if (FAILED(sc))
  58. {
  59. Log (TEXT("Setup - CoInitialize failed."), sc);
  60. return sc;
  61. }
  62. // for each class ctx, create a persistent instance on disk
  63. for (iCtx=0; iCtx<CNT_CLSCTX; iCtx++)
  64. {
  65. m_punkObj[iCtx] = NULL;
  66. m_pmkObj[iCtx] = NULL;
  67. if (dwaClsCtx[iCtx] == CLSCTX_INPROC_SERVER)
  68. {
  69. // create an inprocess instance
  70. m_punkObj[iCtx] = (IPersistFile *) new CTestAct(m_ClsID[iCtx]);
  71. sc = (m_punkObj[iCtx] != NULL) ? S_OK : E_OUTOFMEMORY;
  72. }
  73. else
  74. {
  75. // Create an instance
  76. sc = CoCreateInstance(m_ClsID[iCtx], NULL, dwaClsCtx[iCtx],
  77. IID_IUnknown, (void **)&m_punkObj[iCtx]);
  78. }
  79. if (SUCCEEDED(sc))
  80. {
  81. // Create a moniker
  82. sc = CreateFileMoniker(apszPerstName[iCtx], &m_pmkObj[iCtx]);
  83. if (SUCCEEDED(sc))
  84. {
  85. // get the IPersistFile interface
  86. IPersistFile *pIPF = NULL;
  87. sc = m_punkObj[iCtx]->QueryInterface(IID_IPersistFile,
  88. (void **)&pIPF);
  89. if (SUCCEEDED(sc))
  90. {
  91. // save the class instance in the file.
  92. // NOTE: we assume the server's implementation of
  93. // this method does not do any ROT operations. We
  94. // know this to be true of CTestAct.
  95. sc = pIPF->Save(apszPerstName[iCtx], FALSE);
  96. pIPF->Release();
  97. if (FAILED(sc))
  98. {
  99. Log (TEXT("Setup - pIPF->Save failed."), sc);
  100. scRet = sc;
  101. }
  102. }
  103. else
  104. {
  105. Log (TEXT("Setup - QueryInterface failed"), sc);
  106. scRet = sc;
  107. }
  108. }
  109. else
  110. {
  111. Log (TEXT("Setup - CreateFileMoniker failed"), sc);
  112. scRet = sc;
  113. }
  114. }
  115. else
  116. {
  117. Log (TEXT("Setup - CreateInstance failed"), sc);
  118. scRet = sc;
  119. }
  120. }
  121. if (FAILED(scRet))
  122. {
  123. Cleanup();
  124. }
  125. return scRet;
  126. }
  127. SCODE CROTTest::Cleanup ()
  128. {
  129. CHAR szPerstName[80];
  130. // delete the persistent instances
  131. for (ULONG iCtx=0; iCtx<CNT_CLSCTX; iCtx++)
  132. {
  133. // delete files
  134. wcstombs(szPerstName, apszPerstName[iCtx],
  135. wcslen(apszPerstName[iCtx])+1);
  136. _unlink (szPerstName);
  137. if (m_punkObj[iCtx])
  138. m_punkObj[iCtx]->Release();
  139. if (m_pmkObj[iCtx])
  140. m_pmkObj[iCtx]->Release();
  141. }
  142. UninitCOM();
  143. return S_OK;
  144. }
  145. SCODE CROTTest::Run ()
  146. {
  147. IRunningObjectTable *pROT = NULL;
  148. CStopWatch sw;
  149. SCODE sc;
  150. // do the server side ROT operations.
  151. // this makes sense only for inprocess objects.
  152. ULONG iCtx=0;
  153. {
  154. // for each iteration
  155. for (ULONG iIter=0; iIter<m_ulIterations; iIter++)
  156. {
  157. sw.Reset();
  158. sc = GetRunningObjectTable(NULL, &pROT);
  159. m_ulGetROTTime[iCtx][iIter] = sw.Read();
  160. if (Log (TEXT("GetRunningObjectTable"), sc))
  161. {
  162. m_ulGetROTTime[iCtx][iIter] = NOTAVAIL;
  163. }
  164. DWORD dwRegister = 0;
  165. sw.Reset();
  166. sc = pROT->Register(0, m_punkObj[iCtx], m_pmkObj[iCtx], &dwRegister);
  167. m_ulRegisterTime[iCtx][iIter] = sw.Read();
  168. if (Log (TEXT("pROT->Register"), sc))
  169. {
  170. m_ulRegisterTime[iCtx][iIter] = NOTAVAIL;
  171. }
  172. FILETIME ft;
  173. SYSTEMTIME st;
  174. GetSystemTime(&st);
  175. SystemTimeToFileTime(&st, &ft);
  176. sw.Reset();
  177. sc = pROT->NoteChangeTime(dwRegister, &ft);
  178. m_ulNoteChangeTime[iCtx][iIter]=sw.Read ();
  179. if (Log (TEXT("pROT->NoteChangeTime"), sc))
  180. {
  181. m_ulNoteChangeTime[iCtx][iIter] = NOTAVAIL;
  182. }
  183. sw.Reset();
  184. sc = pROT->Revoke(dwRegister);
  185. m_ulRevokeTime[iCtx][iIter] = sw.Read();
  186. if (Log (TEXT("pROT->Revoke"), sc))
  187. {
  188. m_ulRevokeTime[iCtx][iIter] = NOTAVAIL;
  189. }
  190. sw.Reset();
  191. pROT->Release();
  192. m_ulReleaseTime[iCtx][iIter]=sw.Read ();
  193. pROT = NULL;
  194. if (Log (TEXT("pROT->Release"), sc))
  195. {
  196. m_ulReleaseTime[iCtx][iIter] = NOTAVAIL;
  197. }
  198. }
  199. }
  200. // do the client side ROT operations
  201. // this makes sense for both class contexts
  202. pROT = NULL;
  203. sc = GetRunningObjectTable(NULL, &pROT);
  204. if (Log (TEXT("GetRunningObjectTable"), sc))
  205. {
  206. return sc;
  207. }
  208. for (iCtx=0; iCtx<CNT_CLSCTX; iCtx++)
  209. {
  210. // put the object into the loaded state. this will cause it to
  211. // register itself in the ROT.
  212. IPersistFile *pIPF = NULL;
  213. sc = m_punkObj[iCtx]->QueryInterface(IID_IPersistFile, (void **)&pIPF);
  214. if (SUCCEEDED(sc))
  215. {
  216. pIPF->Load(apszPerstName[iCtx], STGM_READ | STGM_SHARE_DENY_NONE);
  217. pIPF->Release();
  218. }
  219. // for each iteration
  220. for (ULONG iIter=0; iIter<m_ulIterations; iIter++)
  221. {
  222. IEnumMoniker *pEnumMk = NULL;
  223. sw.Reset();
  224. sc = pROT->EnumRunning(&pEnumMk);
  225. m_ulEnumRunningTime[iCtx][iIter] = sw.Read();
  226. if (Log (TEXT("pROT->EnumRunning"), sc))
  227. {
  228. m_ulEnumRunningTime[iCtx][iIter] = NOTAVAIL;
  229. }
  230. if (pEnumMk)
  231. {
  232. pEnumMk->Release();
  233. }
  234. sw.Reset();
  235. sc = pROT->IsRunning(m_pmkObj[iCtx]);
  236. m_ulIsRunningTime[iCtx][iIter] = sw.Read();
  237. if (Log (TEXT("pROT->IsRunning"), sc))
  238. {
  239. m_ulIsRunningTime[iCtx][iIter] = NOTAVAIL;
  240. }
  241. FILETIME ft;
  242. sw.Reset();
  243. sc = pROT->GetTimeOfLastChange(m_pmkObj[iCtx], &ft);
  244. m_ulGetChangeTime[iCtx][iIter]=sw.Read ();
  245. if (Log (TEXT("pROT->GetTimeOfLastChange"), sc))
  246. {
  247. m_ulGetChangeTime[iCtx][iIter] = NOTAVAIL;
  248. }
  249. IUnknown *pUnk = NULL;
  250. sw.Reset();
  251. sc = pROT->GetObject(m_pmkObj[iCtx], &pUnk);
  252. m_ulGetObjectTime[iCtx][iIter]=sw.Read ();
  253. if (Log (TEXT("pROT->GetObject"), sc))
  254. {
  255. m_ulGetObjectTime[iCtx][iIter] = NOTAVAIL;
  256. }
  257. if (pUnk)
  258. {
  259. pUnk->Release();
  260. }
  261. }
  262. }
  263. return S_OK;
  264. }
  265. SCODE CROTTest::Report (CTestOutput &output)
  266. {
  267. output.WriteSectionHeader (Name(), TEXT("RunningObjectTable"), *m_pInput);
  268. // write out the server side results
  269. ULONG iCtx=0;
  270. output.WriteString(TEXT("\nServer Side\n\n"));
  271. output.WriteResults(TEXT("GetRunningObjTbl"), m_ulIterations, m_ulGetROTTime[iCtx]);
  272. output.WriteResults(TEXT("Register "), m_ulIterations, m_ulRegisterTime[iCtx]);
  273. output.WriteResults(TEXT("NoteChangeTime "), m_ulIterations, m_ulNoteChangeTime[iCtx]);
  274. output.WriteResults(TEXT("Revoke "), m_ulIterations, m_ulRevokeTime[iCtx]);
  275. output.WriteResults(TEXT("pROT->Release "), m_ulIterations, m_ulReleaseTime[iCtx]);
  276. // write out the client side results
  277. output.WriteString(TEXT("\nClient Side\n"));
  278. // for each clsctx, write the results
  279. for (iCtx=0; iCtx<CNT_CLSCTX; iCtx++)
  280. {
  281. output.WriteString(TEXT("\n"));
  282. output.WriteClassID(&m_ClsID[iCtx]);
  283. output.WriteString(apszClsCtx[iCtx]);
  284. output.WriteString(TEXT("\n"));
  285. output.WriteResults(TEXT("EnumRunning "), m_ulIterations, m_ulEnumRunningTime[iCtx]);
  286. output.WriteResults(TEXT("IsRunning "), m_ulIterations, m_ulIsRunningTime[iCtx]);
  287. output.WriteResults(TEXT("GetChangeTime "), m_ulIterations, m_ulGetChangeTime[iCtx]);
  288. output.WriteResults(TEXT("GetObject "), m_ulIterations, m_ulGetObjectTime[iCtx]);
  289. }
  290. return S_OK;
  291. }
  292.