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.

332 lines
9.8 KiB

  1. //+------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993.
  5. //
  6. // File: bm_Crt.cxx
  7. //
  8. // Contents: Create apis
  9. //
  10. // Classes: CCreateApi
  11. //
  12. // Functions:
  13. //
  14. // History:
  15. //
  16. //--------------------------------------------------------------------------
  17. #include <headers.cxx>
  18. #pragma hdrstop
  19. #include "hlp_util.hxx"
  20. #include "hlp_iocs.hxx"
  21. #include "hlp_ias.hxx"
  22. #include "hlp_app.hxx"
  23. #include "hlp_site.hxx"
  24. #include "hlp_doc.hxx"
  25. #include "bm_Crt.hxx"
  26. TCHAR vlpScratchBuf[256];
  27. //**********************************************************************
  28. //
  29. // CCreate::Name, SetUp, Run, CleanUp
  30. //
  31. // Purpose:
  32. //
  33. // These routines provide the implementation for the Name, Setup,
  34. // Run and CleanUp of the class CCreateTest. For details see the doc
  35. // for driver what are these routines supposed to do.
  36. //
  37. // Parameters:
  38. //
  39. //
  40. // Return Value:
  41. //
  42. // None
  43. //
  44. //
  45. // Comments:
  46. // If STRESS is defined don't do anything with timer variable! We are
  47. // not interested in time values.
  48. //
  49. //********************************************************************
  50. TCHAR *CCreateTest::Name ()
  51. {
  52. return TEXT("CreateTest");
  53. }
  54. SCODE CCreateTest::Setup (CTestInput *pInput)
  55. {
  56. CTestBase::Setup(pInput);
  57. HRESULT sc;
  58. HRESULT hres;
  59. #ifdef STRESS
  60. //If stress condition loop number of time = STRESSCOUNT
  61. m_ulIterations = STRESSCOUNT;
  62. #else
  63. // get iteration count
  64. m_ulIterations = pInput->GetIterations(Name());
  65. #endif
  66. #ifndef STRESS
  67. // initialize timing arrays
  68. INIT_RESULTS(m_ulOleCreateSr32);
  69. INIT_RESULTS(m_ulOleCreateOutl);
  70. INIT_RESULTS(m_ulOleCreateRenderDrawSr32);
  71. INIT_RESULTS(m_ulOleCreateRenderDrawOutl);
  72. #endif
  73. sc = OleInitialize(NULL);
  74. if (FAILED(sc))
  75. {
  76. Log (TEXT("Setup - OleInitialize failed."), sc);
  77. return sc;
  78. }
  79. hres = CLSIDFromString(L"Sr32test", &m_clsidSr32);
  80. Log (TEXT("CLSIDFromString returned ."), hres);
  81. if (hres != NOERROR)
  82. return E_FAIL;
  83. hres = CLSIDFromString(OutlineClassName, &m_clsidOutl);
  84. Log (TEXT("CLSIDFromString returned ."), hres);
  85. if (hres != NOERROR)
  86. return E_FAIL;
  87. //Create Doc and Root storage
  88. m_lpDoc = CSimpleDoc::Create();
  89. for (ULONG iIter=0; iIter<m_ulIterations; iIter++) {
  90. // Create an instance of Site
  91. CSimpleSite *pObj = CSimpleSite::Create(m_lpDoc, iIter);
  92. if (pObj)
  93. m_pSite[iIter] = pObj;
  94. }
  95. return sc;
  96. }
  97. SCODE CCreateTest::Cleanup ()
  98. {
  99. for (ULONG iIter=0; iIter<m_ulIterations; iIter++)
  100. {
  101. delete m_pSite[iIter];
  102. }
  103. OleUninitialize();
  104. return S_OK;
  105. }
  106. //**********************************************************************
  107. //
  108. // CCreateTest::Run
  109. //
  110. // Purpose:
  111. // This is the work horse routine which calls OLE apis.
  112. // The profile is done by calling OleCreate on Sr32test and SvrOutl.
  113. // We get results for different FormatEtc types.
  114. //
  115. //
  116. // Parameters:
  117. //
  118. //
  119. // Return Value:
  120. //
  121. // None
  122. //
  123. // Functions called:
  124. // CallOleCreate defined below
  125. //
  126. //
  127. // Comments:
  128. // Need to add more Server types including In-Proc servers.
  129. //
  130. //********************************************************************
  131. SCODE CCreateTest::Run ()
  132. {
  133. CStopWatch sw;
  134. BOOL fRet;
  135. fRet = CallOleCreate(m_clsidSr32, m_pSite, IID_IOleObject,
  136. NULL, NULL, m_ulIterations, m_ulOleCreateSr32);
  137. fRet = CallOleCreate(m_clsidOutl, m_pSite, IID_IOleObject, NULL, NULL,
  138. m_ulIterations, m_ulOleCreateOutl);
  139. fRet = CallOleCreate(m_clsidSr32, m_pSite, IID_IOleObject, OLERENDER_DRAW,
  140. NULL, m_ulIterations, m_ulOleCreateRenderDrawSr32);
  141. fRet = CallOleCreate(m_clsidOutl, m_pSite, IID_IOleObject, OLERENDER_DRAW,
  142. NULL, m_ulIterations, m_ulOleCreateRenderDrawOutl);
  143. //Create the objects with RenderFormat = Metafile
  144. FORMATETC fmte = {CF_METAFILEPICT, NULL, DVASPECT_CONTENT, -1, TYMED_MFPICT};
  145. fRet = CallOleCreate(m_clsidSr32, m_pSite, IID_IOleObject, OLERENDER_FORMAT,
  146. &fmte, m_ulIterations, m_ulOleCreateRenderFormatMFSr32);
  147. fRet = CallOleCreate(m_clsidOutl, m_pSite, IID_IOleObject, OLERENDER_FORMAT,
  148. &fmte, m_ulIterations, m_ulOleCreateRenderFormatMFOutl);
  149. //Create the objects with RenderFormat = Bitmap
  150. fmte.cfFormat = CF_BITMAP;
  151. fmte.dwAspect = DVASPECT_CONTENT;
  152. fmte.tymed = TYMED_GDI;
  153. fRet = CallOleCreate(m_clsidSr32, m_pSite, IID_IOleObject, OLERENDER_FORMAT,
  154. &fmte, m_ulIterations, m_ulOleCreateRenderFormatBMSr32);
  155. fRet = CallOleCreate(m_clsidOutl, m_pSite, IID_IOleObject, OLERENDER_FORMAT,
  156. &fmte, m_ulIterations, m_ulOleCreateRenderFormatBMOutl);
  157. //Create the objects with RenderFormat = Text
  158. fmte.cfFormat = CF_TEXT;
  159. fmte.dwAspect = DVASPECT_CONTENT;
  160. fmte.tymed = TYMED_HGLOBAL;
  161. fRet = CallOleCreate(m_clsidSr32, m_pSite, IID_IOleObject, OLERENDER_FORMAT,
  162. &fmte, m_ulIterations, m_ulOleCreateRenderFormatTextSr32);
  163. fRet = CallOleCreate(m_clsidOutl, m_pSite, IID_IOleObject, OLERENDER_FORMAT,
  164. &fmte, m_ulIterations, m_ulOleCreateRenderFormatTextOutl);
  165. return S_OK;
  166. }
  167. SCODE CCreateTest::Report (CTestOutput &output)
  168. {
  169. //Bail out immediately on STRESS because none of the following variables
  170. //will have sane value
  171. #ifdef STRESS
  172. return S_OK;
  173. #endif
  174. output.WriteString (TEXT("*************************************************\n"));
  175. output.WriteSectionHeader (Name(), TEXT("Create Apis\t\t"), *m_pInput);
  176. output.WriteString (TEXT("*************************************************\n"));
  177. output.WriteString (TEXT("\n"));
  178. output.WriteResults (TEXT("OleCreate Sr32test \t\t\t"), m_ulIterations, m_ulOleCreateSr32);
  179. output.WriteString (TEXT("\n"));
  180. output.WriteString (TEXT("\n"));
  181. output.WriteResults (TEXT("OleCreate Outline\t\t\t "), m_ulIterations, m_ulOleCreateOutl);
  182. output.WriteString (TEXT("\n"));
  183. output.WriteString (TEXT("\n"));
  184. output.WriteResults (TEXT("OleCreate with RenderDraw Sr32test \t"), m_ulIterations, m_ulOleCreateRenderDrawSr32);
  185. output.WriteString (TEXT("\n"));
  186. output.WriteString (TEXT("\n"));
  187. output.WriteResults (TEXT("OleCreate with RenderDraw Outline \t "), m_ulIterations, m_ulOleCreateRenderDrawOutl);
  188. output.WriteString (TEXT("\n"));
  189. output.WriteString (TEXT("\n"));
  190. output.WriteResults (TEXT("OleCreate with RenderFormatMF Sr32test \t"), m_ulIterations, m_ulOleCreateRenderFormatMFSr32);
  191. output.WriteString (TEXT("\n"));
  192. output.WriteString (TEXT("\n"));
  193. output.WriteResults (TEXT("OleCreate with RenderFormatMF Outline \t "), m_ulIterations, m_ulOleCreateRenderFormatMFOutl);
  194. output.WriteString (TEXT("\n"));
  195. output.WriteString (TEXT("\n"));
  196. output.WriteResults (TEXT("OleCreate with RenderFormatBM Sr32test \t"), m_ulIterations, m_ulOleCreateRenderFormatBMSr32);
  197. output.WriteString (TEXT("\n"));
  198. output.WriteString (TEXT("\n"));
  199. output.WriteResults (TEXT("OleCreate with RenderFormatBM Outline \t "), m_ulIterations, m_ulOleCreateRenderFormatBMOutl);
  200. output.WriteString (TEXT("\n"));
  201. output.WriteString (TEXT("\n"));
  202. output.WriteResults (TEXT("OleCreate with RenderFormatTxt Sr32test\t "), m_ulIterations, m_ulOleCreateRenderFormatTextSr32);
  203. output.WriteString (TEXT("\n"));
  204. output.WriteString (TEXT("\n"));
  205. output.WriteResults (TEXT("OleCreate with RenderFormatTxt Outline\t "), m_ulIterations, m_ulOleCreateRenderFormatTextOutl);
  206. output.WriteString (TEXT("\n"));
  207. return S_OK;
  208. }
  209. //**********************************************************************
  210. //
  211. // CallOleCreate
  212. //
  213. // Purpose:
  214. // Calls OleCreate to create the object and then destroys them.
  215. //
  216. //
  217. // Parameters:
  218. //
  219. //
  220. // Return Value:
  221. //
  222. // None
  223. //
  224. // Functions called:
  225. // OleCreate OLE2 api - Is profiled here
  226. //
  227. //
  228. // Comments:
  229. // Need to add more Server types including In-Proc servers.
  230. //
  231. //********************************************************************
  232. BOOL CallOleCreate(REFCLSID rclsid, CSimpleSite * pSite[], REFIID riid, DWORD renderopt,
  233. LPFORMATETC pFormatEtc, ULONG ulIterations, ULONG uOleCreatetime[])
  234. {
  235. CStopWatch sw;
  236. HRESULT hres;
  237. ULONG iIter;
  238. for ( iIter=0; iIter<ulIterations; iIter++)
  239. {
  240. HEAPVALIDATE();
  241. sw.Reset();
  242. hres = OleCreate(rclsid, riid, renderopt, pFormatEtc,
  243. &pSite[iIter]->m_OleClientSite,
  244. pSite[iIter]->m_lpObjStorage, (VOID FAR* FAR*)&pSite[iIter]->m_lpOleObject);
  245. GetTimerVal(uOleCreatetime[iIter]);
  246. LOGRESULTS (TEXT("OleCreate "), hres);
  247. if (hres != NOERROR)
  248. {
  249. goto error;
  250. }
  251. }
  252. //CleanUp before going to Next
  253. for (iIter=0; iIter<ulIterations; iIter++)
  254. {
  255. // Unload the object and release the Ole Object
  256. pSite[iIter]->UnloadOleObject();
  257. #ifdef REVIEW //BIG REVIEW I am keeping same ClientSIte and Reusing
  258. //delete pSite[iIter];
  259. #endif
  260. }
  261. return TRUE;
  262. error:
  263. if (hres != NOERROR)
  264. Log (TEXT("Routine CallOleCreate failed with hres = "), hres);
  265. return FALSE;
  266. }