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.

557 lines
17 KiB

  1. //+------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993.
  5. //
  6. // File: bm_Load.cxx
  7. //
  8. // Contents: Contains the impl of COleLoadTest which deals with Clipboard related
  9. // apis.
  10. //
  11. // Classes: COleLoadTest
  12. //
  13. // Functions:
  14. //
  15. // History:
  16. //
  17. //--------------------------------------------------------------------------
  18. #include <headers.cxx>
  19. #pragma hdrstop
  20. #include "hlp_util.hxx"
  21. #include "hlp_iocs.hxx"
  22. #include "hlp_ias.hxx"
  23. #include "hlp_app.hxx"
  24. #include "hlp_site.hxx"
  25. #include "hlp_doc.hxx"
  26. #include "bm_Load.hxx"
  27. #include <oleauto.h>
  28. //**********************************************************************
  29. //
  30. // CLoadTest::Name, SetUp, Run, CleanUp
  31. //
  32. // Purpose:
  33. //
  34. // These routines provide the implementation for the Name, Setup,
  35. // Run and CleanUp of the class CLoadTest. For details see the doc
  36. // for driver what are these routines supposed to do.
  37. //
  38. // Parameters:
  39. //
  40. //
  41. // Return Value:
  42. //
  43. // None
  44. //
  45. //
  46. // Comments:
  47. // If STRESS is defined don't do anything with timer variable! We are
  48. // not interested in time values.
  49. //
  50. //********************************************************************
  51. TCHAR *COleLoadTest::Name ()
  52. {
  53. return TEXT("LoadTest");
  54. }
  55. SCODE COleLoadTest::Setup (CTestInput *pInput)
  56. {
  57. CTestBase::Setup(pInput);
  58. HRESULT sc;
  59. HRESULT hres;
  60. #ifdef STRESS
  61. //If stress condition loop number of time = STRESSCOUNT
  62. m_ulIterations = STRESSCOUNT;
  63. #else
  64. // get iteration count
  65. m_ulIterations = pInput->GetIterations(Name());
  66. #endif
  67. // initialize timing arrays
  68. #ifndef STRESS
  69. INIT_RESULTS(m_ulEmbedLoadOutl);
  70. INIT_RESULTS(m_ulEmbedSaveOutl);
  71. INIT_RESULTS(m_ulEmbedLoadRenderDrawOutl);
  72. INIT_RESULTS(m_ulEmbedSaveRenderDrawOutl);
  73. INIT_RESULTS(m_ulEmbedLoadRenderAsisOutl);
  74. INIT_RESULTS(m_ulEmbedSaveRenderAsisOutl);
  75. INIT_RESULTS(m_ulLinkLoadOutl);
  76. INIT_RESULTS(m_ulLinkAndSaveOutl);
  77. INIT_RESULTS(m_ulLinkLoadRenderDrawOutl);
  78. INIT_RESULTS(m_ulLinkAndSaveRenderDrawOutl);
  79. INIT_RESULTS(m_ulStaticAndLoadRenderDrawOutl);
  80. INIT_RESULTS(m_ulStaticAndSaveRenderDrawOutl);
  81. INIT_RESULTS(m_ulStaticAndLoadRenderBMOutl);
  82. INIT_RESULTS(m_ulStaticAndSaveRenderBMOutl);
  83. #endif
  84. sc = OleInitialize(NULL);
  85. if (FAILED(sc))
  86. {
  87. Log (TEXT("Setup - OleInitialize failed."), sc);
  88. return sc;
  89. }
  90. hres = CLSIDFromString(OutlineClassName, &m_clsidOutl);
  91. Log (TEXT("CLSIDFromString returned ."), hres);
  92. if (hres != NOERROR)
  93. return E_FAIL;
  94. //Create root Doc and STorage for Doc
  95. m_lpDoc = CSimpleDoc::Create();
  96. //Create Individual Objects and Init the table
  97. for (ULONG iIter=0; iIter<m_ulIterations; iIter++) {
  98. // CreateLink an instance of Site
  99. CSimpleSite *pObj = CSimpleSite::Create(m_lpDoc, iIter);
  100. if (pObj)
  101. m_pSite[iIter] = pObj;
  102. }
  103. return sc;
  104. }
  105. SCODE COleLoadTest::Cleanup ()
  106. {
  107. for (ULONG iIter=0; iIter<m_ulIterations; iIter++)
  108. {
  109. delete m_pSite[iIter];
  110. }
  111. OleUninitialize();
  112. return S_OK;
  113. }
  114. SCODE COleLoadTest::Run ()
  115. {
  116. CStopWatch sw;
  117. BOOL fRet;
  118. TCHAR szTemp[MAX_PATH];
  119. OLECHAR szOutlFileName[MAX_PATH];
  120. // Get file name of .ini file. if not specified in the command
  121. // line, use the default BM.INI in the local directory
  122. GetCurrentDirectory (MAX_PATH, szTemp);
  123. swprintf(szOutlFileName,
  124. #ifdef UNICODE
  125. L"%s\\foo.oln",
  126. #else
  127. L"%S\\foo.oln",
  128. #endif
  129. szTemp);
  130. //
  131. //Test cases for OleSave and OleLoad on Embedding
  132. //
  133. fRet = CallCreateLoadAndSave(m_clsidOutl, m_pSite, IID_IOleObject, OLERENDER_NONE,
  134. NULL, m_ulIterations, m_ulEmbedLoadOutl, m_ulEmbedSaveOutl );
  135. fRet = CallCreateLoadAndSave(m_clsidOutl, m_pSite, IID_IOleObject, OLERENDER_DRAW,
  136. NULL, m_ulIterations, m_ulEmbedLoadRenderDrawOutl, m_ulEmbedSaveRenderDrawOutl);
  137. fRet = CallCreateLoadAndSave(m_clsidOutl, m_pSite, IID_IOleObject, OLERENDER_ASIS,
  138. NULL, m_ulIterations, m_ulEmbedLoadRenderAsisOutl, m_ulEmbedSaveRenderAsisOutl );
  139. FORMATETC fmte = {CF_BITMAP, NULL, DVASPECT_CONTENT, -1, TYMED_GDI};
  140. fRet = CallCreateLoadAndSave(m_clsidOutl, m_pSite, IID_IOleObject, OLERENDER_FORMAT,
  141. &fmte, m_ulIterations, m_ulEmbedLoadRenderBMOutl, m_ulEmbedSaveRenderBMOutl );
  142. //
  143. //Test cases for OleSave and OleLoad on Links
  144. //
  145. fRet = CallLinkLoadAndSave(szOutlFileName, m_pSite, IID_IOleObject, OLERENDER_NONE,
  146. NULL, m_ulIterations, m_ulLinkLoadOutl, m_ulLinkAndSaveOutl);
  147. fRet = CallLinkLoadAndSave(szOutlFileName, m_pSite, IID_IOleObject, OLERENDER_DRAW,
  148. NULL, m_ulIterations, m_ulLinkLoadRenderDrawOutl, m_ulLinkAndSaveRenderDrawOutl);
  149. //
  150. //Test cases for OleSave and OleLoad on Static objects
  151. //
  152. fRet = CallStaticLoadAndSave(m_clsidOutl, m_lpDoc, m_pSite, IID_IOleObject, OLERENDER_DRAW,
  153. NULL, m_ulIterations, m_ulStaticAndLoadRenderDrawOutl, m_ulLinkAndSaveRenderDrawOutl);
  154. //fRet = CallStaticLoadAndSave(m_clsidOutl, m_lpDoc, m_pSite, IID_IOleObject, OLERENDER_FORMAT,
  155. // &fmte, m_ulIterations, m_ulStaticAndLoadRenderBMOutl, m_ulStaticAndSaveRenderBMOutl);
  156. return S_OK;
  157. }
  158. SCODE COleLoadTest::Report (CTestOutput &output)
  159. {
  160. //Bail out immediately on STRESS because none of the following variables
  161. //will have sane value
  162. #ifdef STRESS
  163. return S_OK;
  164. #endif
  165. output.WriteString (TEXT("*************************************************\n"));
  166. output.WriteSectionHeader (Name(), TEXT("Load Apis"), *m_pInput);
  167. output.WriteString (TEXT("*************************************************\n"));
  168. output.WriteString (TEXT("\n"));
  169. output.WriteResults (TEXT("OleLoad Embedding \t\t "), m_ulIterations, m_ulEmbedLoadOutl);
  170. output.WriteString (TEXT("\n"));
  171. output.WriteString (TEXT("\n"));
  172. output.WriteResults (TEXT("OleSave Embedding \t\t"), m_ulIterations, m_ulEmbedSaveOutl);
  173. output.WriteString (TEXT("\n"));
  174. output.WriteString (TEXT("\n"));
  175. output.WriteResults (TEXT("OleLoad Embedding with RenderDraw \t"), m_ulIterations, m_ulEmbedLoadRenderDrawOutl);
  176. output.WriteString (TEXT("\n"));
  177. output.WriteString (TEXT("\n"));
  178. output.WriteResults (TEXT("OleSave Embedding with RenderDraw \t"), m_ulIterations, m_ulEmbedSaveRenderDrawOutl);
  179. output.WriteString (TEXT("\n"));
  180. output.WriteString (TEXT("\n"));
  181. output.WriteResults (TEXT("OleLoad Embedding with RenderFormatBM Outline \t"), m_ulIterations, m_ulEmbedLoadRenderBMOutl);
  182. output.WriteString (TEXT("\n"));
  183. output.WriteString (TEXT("\n"));
  184. output.WriteResults (TEXT("OleSave with RenderFormatBM \t\t "), m_ulIterations, m_ulEmbedLoadRenderBMOutl);
  185. output.WriteString (TEXT("\n"));
  186. output.WriteString (TEXT("\n"));
  187. output.WriteResults (TEXT("OleLoad Embedding with RenderAsIs \t "), m_ulIterations, m_ulEmbedLoadRenderAsisOutl);
  188. output.WriteString (TEXT("\n"));
  189. output.WriteString (TEXT("\n"));
  190. output.WriteResults (TEXT("OleSave Embedding with RenderAsIs \t"), m_ulIterations, m_ulEmbedLoadRenderAsisOutl);
  191. output.WriteString (TEXT("\n"));
  192. output.WriteString (TEXT("\n"));
  193. output.WriteString (TEXT("***************************************\n"));
  194. output.WriteResults (TEXT("OleLoad Link Outline \t\t "), m_ulIterations, m_ulLinkLoadOutl);
  195. output.WriteString (TEXT("\n"));
  196. output.WriteString (TEXT("\n"));
  197. output.WriteResults (TEXT("OleSave Link Outline \t\t "), m_ulIterations, m_ulLinkAndSaveOutl);
  198. output.WriteString (TEXT("\n"));
  199. output.WriteString (TEXT("\n"));
  200. output.WriteResults (TEXT("OleLoad Link with RenderDraw \t\t"), m_ulIterations, m_ulLinkLoadRenderDrawOutl);
  201. output.WriteString (TEXT("\n"));
  202. output.WriteString (TEXT("\n"));
  203. output.WriteResults (TEXT("OleSave Link with RenderDraw Outline \t"), m_ulIterations, m_ulLinkAndSaveRenderDrawOutl);
  204. output.WriteString (TEXT("\n"));
  205. output.WriteString (TEXT("***************************************\n"));
  206. output.WriteResults (TEXT("OleCreateStaticAndLoad Outline \t "), m_ulIterations, m_ulStaticAndLoadRenderDrawOutl);
  207. output.WriteString (TEXT("\n"));
  208. output.WriteString (TEXT("\n"));
  209. output.WriteResults (TEXT("OleCreateStaticAndLoad with RenderDraw Outline \t"), m_ulIterations, m_ulStaticAndLoadRenderBMOutl);
  210. output.WriteString (TEXT("\n"));
  211. return S_OK;
  212. }
  213. //**********************************************************************
  214. //
  215. // CallCreateLoadAndSave
  216. //
  217. // Purpose:
  218. // Calls OleCreate to create the object and then
  219. // call OleLoad and OleSave to get the performance results on them.
  220. //
  221. //
  222. // Parameters:
  223. //
  224. //
  225. // Return Value:
  226. //
  227. // None
  228. //
  229. // Functions called:
  230. // OleCreate OLE2 api
  231. // LoadAndSave routine defined in this file
  232. //
  233. //
  234. // Comments:
  235. //
  236. //
  237. //********************************************************************
  238. BOOL CallCreateLoadAndSave(REFCLSID rclsid, CSimpleSite * pSite[], REFIID riid, DWORD renderopt,
  239. LPFORMATETC pFormatEtc, ULONG ulIterations,
  240. ULONG uOleLoadtime[], ULONG uOleSavetime[])
  241. {
  242. HRESULT hres;
  243. ULONG iIter;
  244. BOOL retVal = FALSE;
  245. //Create the objects
  246. for ( iIter=0; iIter<ulIterations; iIter++) {
  247. //If we have not had any problem then
  248. HEAPVALIDATE() ;
  249. hres = OleCreate(rclsid, riid, renderopt, pFormatEtc,
  250. &pSite[iIter]->m_OleClientSite,
  251. pSite[iIter]->m_lpObjStorage, (VOID FAR* FAR*)&pSite[iIter]->m_lpOleObject);
  252. if (hres != NOERROR)
  253. goto error;
  254. }
  255. //Now call Appropriate routines to Save and Load the objects
  256. LoadAndSave( pSite, ulIterations, uOleLoadtime, uOleSavetime);
  257. retVal = TRUE;
  258. error:
  259. if (hres != NOERROR)
  260. Log (TEXT("Routine CallCreateLoadAndSave failed with hres = "), hres);
  261. for (iIter=0; iIter<ulIterations; iIter++)
  262. {
  263. // Unload the object and release the Ole Object
  264. pSite[iIter]->UnloadOleObject();
  265. }
  266. return retVal;
  267. }
  268. BOOL CallLinkLoadAndSave(LPCOLESTR lpFileName, CSimpleSite * pSite[], REFIID riid, DWORD renderopt,
  269. LPFORMATETC pFormatEtc, ULONG ulIterations,
  270. ULONG uOleLoadtime[], ULONG uOleSavetime[])
  271. {
  272. HRESULT hres;
  273. ULONG iIter;
  274. BOOL retVal = FALSE;
  275. //Create the objects
  276. for ( iIter=0; iIter<ulIterations; iIter++) {
  277. //If we have not had any problem then
  278. HEAPVALIDATE() ;
  279. hres = OleCreateLinkToFile(lpFileName, riid, renderopt, pFormatEtc,
  280. &pSite[iIter]->m_OleClientSite,
  281. pSite[iIter]->m_lpObjStorage, (VOID FAR* FAR*)&pSite[iIter]->m_lpOleObject);
  282. if (hres != NOERROR)
  283. goto error;
  284. }
  285. //Now call Appropriate routines to Save and Load the objects
  286. LoadAndSave( pSite, ulIterations, uOleLoadtime, uOleSavetime);
  287. retVal = TRUE;
  288. error:
  289. if (hres != NOERROR)
  290. Log (TEXT("Routine CallCreateLoadAndSave failed with hres = "), hres);
  291. for (iIter=0; iIter<ulIterations; iIter++)
  292. {
  293. // Unload the object and release the Ole Object
  294. pSite[iIter]->UnloadOleObject();
  295. }
  296. return retVal;
  297. }
  298. //**********************************************************************
  299. //
  300. // LoadAndSave
  301. //
  302. // Purpose:
  303. // Calls OleLoad and OleSave on the object and timing results.
  304. //
  305. //
  306. // Parameters:
  307. //
  308. //
  309. // Return Value:
  310. //
  311. // None
  312. //
  313. // Functions called:
  314. // OleLoad OLE2 api
  315. // OleSave OLE2 api
  316. //
  317. //
  318. // Comments:
  319. //
  320. //
  321. //********************************************************************
  322. BOOL LoadAndSave(CSimpleSite * pSite[], ULONG ulIterations,
  323. ULONG uOleLoadtime[], ULONG uOleSavetime[])
  324. {
  325. LPPERSISTSTORAGE pStg = NULL;
  326. CStopWatch sw;
  327. HRESULT hres;
  328. ULONG iIter;
  329. BOOL retVal = FALSE;
  330. //Save the objects
  331. for (iIter=0; iIter<ulIterations; iIter++)
  332. {
  333. hres = pSite[iIter]->m_lpOleObject->QueryInterface(IID_IPersistStorage,
  334. (LPVOID FAR*)&pStg);
  335. if (hres != NOERROR)
  336. goto error;
  337. sw.Reset();
  338. hres = OleSave(pStg, pSite[iIter]->m_lpObjStorage, TRUE);
  339. GetTimerVal(uOleSavetime[iIter]);
  340. LOGRESULTS (TEXT("OleSave "), hres);
  341. if (hres != NOERROR)
  342. {
  343. goto error;
  344. }
  345. pStg->Release();
  346. pStg = NULL;
  347. }
  348. for (iIter=0; iIter<ulIterations; iIter++)
  349. {
  350. // Unload the object and release the Ole Object
  351. pSite[iIter]->UnloadOleObject();
  352. }
  353. //Load the objects
  354. for (iIter=0; iIter<ulIterations; iIter++)
  355. {
  356. sw.Reset();
  357. hres = OleLoad( pSite[iIter]->m_lpObjStorage, IID_IOleObject,
  358. &pSite[iIter]->m_OleClientSite, (VOID FAR* FAR*)&pSite[iIter]->m_lpOleObject);
  359. GetTimerVal(uOleLoadtime[iIter]);
  360. LOGRESULTS (TEXT("OleLoad "), hres);
  361. }
  362. retVal = TRUE;
  363. error:
  364. if (hres != NOERROR)
  365. Log (TEXT("Routine LoadAndSave failed with hres = "), hres);
  366. if (pStg)
  367. pStg->Release();
  368. return retVal;
  369. }
  370. //**********************************************************************
  371. //
  372. // CallStaticLoadAndSave
  373. //
  374. // Purpose:
  375. // Calls OleCreateStaticFromDara to create the object and then
  376. // call OleLoad and OleSave to get the performance results on them.
  377. //
  378. //
  379. // Parameters:
  380. //
  381. //
  382. // Return Value:
  383. //
  384. // None
  385. //
  386. // Functions called:
  387. // OleCreate OLE2 api
  388. // OleCreateStaticFromData OLE2 api
  389. // LoadAndSave routine defined in this file
  390. //
  391. //
  392. // Comments:
  393. // In this case we call OleCreateStaticFromData from data object
  394. // given by application.
  395. //
  396. //********************************************************************
  397. BOOL CallStaticLoadAndSave(REFCLSID rclsid, CSimpleDoc FAR * m_lpDoc, CSimpleSite * pSite[],
  398. REFIID riid, DWORD renderopt, LPFORMATETC pFormatEtc, ULONG ulIterations,
  399. ULONG uOleLoadtime[], ULONG uOleSavetime[])
  400. {
  401. HRESULT hres;
  402. ULONG iIter;
  403. BOOL retVal = FALSE;
  404. LPDATAOBJECT pDO = NULL;
  405. CSimpleSite* pTempSite = CSimpleSite::Create(m_lpDoc, -1); //-1 is unique in this case
  406. //Create the ole object and ask for IID_IDataObject interface
  407. hres = OleCreate(rclsid, IID_IOleObject, renderopt, pFormatEtc,
  408. &pTempSite->m_OleClientSite,
  409. pTempSite->m_lpObjStorage, (VOID FAR* FAR*)&pTempSite->m_lpOleObject);
  410. if (hres != NOERROR)
  411. goto error;
  412. hres = pTempSite->m_lpOleObject->QueryInterface(IID_IDataObject, (LPVOID FAR*)&pDO);
  413. if (hres != NOERROR)
  414. goto error;
  415. //Create the static objects from pDO
  416. for ( iIter=0; iIter<ulIterations; iIter++) {
  417. hres = OleCreateStaticFromData(pDO, riid, renderopt, pFormatEtc,
  418. &pSite[iIter]->m_OleClientSite, pSite[iIter]->m_lpObjStorage,
  419. (VOID FAR* FAR*)&pSite[iIter]->m_lpOleObject);
  420. if (hres != NOERROR)
  421. goto error;
  422. HEAPVALIDATE() ;
  423. }
  424. //Now call Appropriate routines to Save and Load the objects
  425. LoadAndSave( pSite, ulIterations, uOleLoadtime, uOleSavetime);
  426. retVal = TRUE;
  427. error:
  428. if (hres != NOERROR)
  429. Log (TEXT("Routine CallCreateLoadAndSave failed with hres = "), hres);
  430. if (pDO)
  431. pDO->Release();
  432. for (iIter=0; iIter<ulIterations; iIter++)
  433. {
  434. // Unload the object and release the Ole Object
  435. pSite[iIter]->UnloadOleObject();
  436. }
  437. if (pTempSite) //this should also release the object
  438. {
  439. pTempSite->UnloadOleObject();
  440. //delete pTempSite;
  441. }
  442. return retVal;
  443. }