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.

503 lines
14 KiB

  1. //+------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993.
  5. //
  6. // File: bm_Cache.cxx
  7. //
  8. // Contents: Contains the impl of COleCacheTest which deals with Clipboard related
  9. // apis.
  10. //
  11. // Classes: COleCacheTest
  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_cache.hxx"
  27. #include <oleauto.h>
  28. //**********************************************************************
  29. //
  30. // CCacheTest::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 CCacheTest. 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 *COleCacheTest::Name ()
  52. {
  53. return TEXT("CacheTest");
  54. }
  55. SCODE COleCacheTest::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_CacheTimesOutl.ulCreateCache);
  70. for (int xx = 0; xx < TEST_MAX_ITERATIONS; xx++)
  71. {
  72. m_CacheTimesOutl[xx].ulCreateCache = NOTAVAIL;
  73. m_CacheTimesOutl[xx].ulCache = NOTAVAIL;
  74. m_CacheTimesOutl[xx].ulInitCache = NOTAVAIL;
  75. m_CacheTimesOutl[xx].ulLoadCache = NOTAVAIL;
  76. m_CacheTimesOutl[xx].ulSaveCache = NOTAVAIL;
  77. m_CacheTimesOutl[xx].ulUncache = NOTAVAIL;
  78. m_CacheTimesOutl[xx].ulUpdateCache = NOTAVAIL;
  79. m_CacheTimesOutl[xx].ulDiscardCache = NOTAVAIL;
  80. }
  81. #endif
  82. sc = OleInitialize(NULL);
  83. if (FAILED(sc))
  84. {
  85. Log (TEXT("Setup - OleInitialize failed."), sc);
  86. return sc;
  87. }
  88. hres = CLSIDFromString(OutlineClassName, &m_clsidOutl);
  89. Log (TEXT("CLSIDFromString returned ."), hres);
  90. assert (hres == NOERROR);
  91. //Create root Doc and STorage for Doc
  92. m_lpDoc = CSimpleDoc::Create();
  93. //Create Individual Objects and Init the table
  94. for (ULONG iIter=0; iIter<m_ulIterations; iIter++) {
  95. // Create an instance of Site
  96. CSimpleSite *pObj = CSimpleSite::Create(m_lpDoc, iIter);
  97. if (pObj)
  98. m_pSite[iIter] = pObj;
  99. }
  100. return sc;
  101. }
  102. SCODE COleCacheTest::Cleanup ()
  103. {
  104. for (ULONG iIter=0; iIter<m_ulIterations; iIter++)
  105. {
  106. delete m_pSite[iIter];
  107. }
  108. OleUninitialize();
  109. return S_OK;
  110. }
  111. SCODE COleCacheTest::Run ()
  112. {
  113. BOOL fRet;
  114. fRet = CallRunCache(m_clsidOutl, m_pSite, m_pOleCache2, m_ulIterations, m_CacheTimesOutl);
  115. return S_OK;
  116. }
  117. SCODE COleCacheTest::Report (CTestOutput &output)
  118. {
  119. //Bail out immediately on STRESS because none of the following variables
  120. //will have sane value
  121. #ifdef STRESS
  122. return S_OK;
  123. #endif
  124. output.WriteString (TEXT("*************************************************\n"));
  125. output.WriteSectionHeader (Name(), TEXT("Cache Apis"), *m_pInput);
  126. output.WriteString (TEXT("*************************************************\n"));
  127. output.WriteString (TEXT("\n"));
  128. WriteCacheOutput(output, TEXT("Outline"), m_CacheTimesOutl, m_ulIterations);
  129. output.WriteString (TEXT("\n"));
  130. return S_OK;
  131. }
  132. //**********************************************************************
  133. //
  134. // CallRunCache
  135. //
  136. // Purpose:
  137. // Creates an embedded object and calls routines to create cache
  138. // Initialize them and then Save and load them.
  139. //
  140. //
  141. // Parameters:
  142. //
  143. //
  144. // Return Value:
  145. //
  146. // None
  147. //
  148. // Functions called:
  149. // OleCreate OLE2 api
  150. // CreateCacheObjects Create Cache objects
  151. // FillCache To fill up the caches with pDO
  152. // SaveAndLoadCache Get the estimates for Save and Load Cache
  153. //
  154. //
  155. // Comments:
  156. //
  157. //
  158. //********************************************************************
  159. BOOL CallRunCache(REFCLSID rclsid, CSimpleSite *pSite[], LPOLECACHE2 pOleCache2[],
  160. ULONG ulIterations, CacheTimes Cachetimes[])
  161. {
  162. HRESULT hres;
  163. ULONG iIter;
  164. BOOL retVal = FALSE;
  165. LPDATAOBJECT pDO = NULL;
  166. CSimpleSite* pTempSite = CSimpleSite::Create(pSite[0]->m_lpDoc, -1); //Some temporary name
  167. if (!pTempSite)
  168. goto error;
  169. //If we have not had any problem then
  170. HEAPVALIDATE() ;
  171. hres = OleCreate(rclsid, IID_IOleObject, OLERENDER_DRAW, NULL,
  172. &pTempSite->m_OleClientSite, pTempSite->m_lpObjStorage,
  173. (VOID FAR* FAR*)&pTempSite->m_lpOleObject);
  174. LOGRESULTS (TEXT("OleCreate "), hres);
  175. if (hres != NOERROR)
  176. {
  177. goto error;
  178. }
  179. hres = pTempSite->m_lpOleObject->QueryInterface(IID_IDataObject, (LPVOID FAR*)&pDO);
  180. if (hres != NOERROR)
  181. goto error;
  182. //Now call Appropriate routines to Save and Cache the objects
  183. hres = CreateCacheObjects( pSite, pOleCache2, ulIterations, Cachetimes);
  184. if (hres != NOERROR)
  185. goto error; //there is no point in going if we had problem with creation
  186. FillCache(pDO, pOleCache2, ulIterations, Cachetimes);
  187. SaveAndLoadCache(pSite, pOleCache2, ulIterations, Cachetimes);
  188. retVal = TRUE;
  189. error:
  190. if (hres != NOERROR)
  191. Log (TEXT("Routine CallRunCache failed with hres = "), hres);
  192. if (pDO)
  193. pDO->Release();
  194. if (pTempSite)
  195. {
  196. pTempSite->UnloadOleObject();
  197. delete pTempSite;
  198. }
  199. for (iIter=0; iIter < ulIterations; iIter++)
  200. {
  201. if (pOleCache2[iIter])
  202. {
  203. pOleCache2[iIter]->Release();
  204. pOleCache2[iIter] = NULL;
  205. }
  206. }
  207. return retVal;
  208. }
  209. //**********************************************************************
  210. //
  211. // CreateCacheObjects
  212. //
  213. // Purpose:
  214. // Creates Cache objects and then initlaize them.
  215. //
  216. //
  217. //
  218. //
  219. // Parameters:
  220. //
  221. //
  222. // Return Value:
  223. //
  224. // HRESULT that came from IPS->InitNew
  225. //
  226. // Functions called:
  227. // CreateDataCache OLE2 api
  228. //
  229. //
  230. // Comments:
  231. //
  232. //
  233. //********************************************************************
  234. HRESULT CreateCacheObjects(CSimpleSite *pSite[], LPOLECACHE2 pOleCache2[],
  235. ULONG ulIterations, CacheTimes Cachetimes[])
  236. {
  237. CStopWatch sw;
  238. HRESULT hres;
  239. ULONG iIter;
  240. BOOL retVal = FALSE;
  241. for (iIter=0; iIter<ulIterations; iIter++)
  242. {
  243. sw.Reset();
  244. hres = CreateDataCache(NULL, CLSID_NULL, IID_IOleCache2, (LPVOID FAR*)&pOleCache2[iIter]);
  245. GetTimerVal(Cachetimes[iIter].ulCreateCache);
  246. LOGRESULTS (TEXT("CreateDataCache "), hres);
  247. if (hres != NOERROR)
  248. {
  249. goto error;
  250. }
  251. //
  252. //Initlaize the cache for use later
  253. //
  254. LPPERSISTSTORAGE lpStg = NULL;
  255. hres = pOleCache2[iIter]->QueryInterface(IID_IPersistStorage, (LPVOID FAR*) &lpStg);
  256. if (hres == NOERROR)
  257. {
  258. hres = lpStg->InitNew(pSite[iIter]->m_lpObjStorage);
  259. lpStg->Release();
  260. }
  261. }
  262. error:
  263. if (hres != NOERROR)
  264. Log (TEXT("Routine CreateCacheObject failed with hres = "), hres);
  265. return hres;
  266. }
  267. VOID FillCache(LPDATAOBJECT pDO, LPOLECACHE2 pOleCache2[], ULONG ulIterations,
  268. CacheTimes Cachetimes[])
  269. {
  270. CStopWatch sw;
  271. HRESULT hres;
  272. ULONG iIter;
  273. BOOL retVal = FALSE;
  274. //Initalize the cache
  275. //NOTE: What I am doing below is trying to Init the cache with format that
  276. //I think are very basic and common. So that we can profile the rest of the
  277. //Cache methods with these options
  278. //
  279. //Work On: Create more Cache nodes!!!
  280. //
  281. for (iIter=0; iIter<ulIterations; iIter++)
  282. {
  283. FORMATETC fmte;
  284. DWORD dwConnection = 0L;
  285. fmte.cfFormat = CF_METAFILEPICT;
  286. fmte.dwAspect = DVASPECT_CONTENT;
  287. fmte.ptd = NULL;
  288. fmte.tymed = TYMED_MFPICT;
  289. fmte.lindex = -1;
  290. sw.Reset();
  291. hres = pOleCache2[iIter]->Cache(&fmte, ADVF_PRIMEFIRST | ADVFCACHE_ONSAVE | ADVF_DATAONSTOP,
  292. &dwConnection);
  293. GetTimerVal(Cachetimes[iIter].ulCache);
  294. LOGRESULTS (TEXT("IOleCache:Cache "), hres);
  295. if (hres != NOERROR)
  296. {
  297. goto error;
  298. }
  299. }
  300. //Fill the Cache from Data object provided
  301. for (iIter=0; iIter<ulIterations; iIter++)
  302. {
  303. sw.Reset();
  304. hres = pOleCache2[iIter]->InitCache(pDO);
  305. GetTimerVal(Cachetimes[iIter].ulInitCache);
  306. LOGRESULTS (TEXT("IOleCache:InitCache "), hres);
  307. if (hres != NOERROR)
  308. {
  309. goto error;
  310. }
  311. }
  312. error:
  313. if (hres != NOERROR)
  314. Log (TEXT("Routine FillCache failed with hres = "), hres);
  315. }
  316. VOID SaveAndLoadCache(CSimpleSite *pSite[], LPOLECACHE2 pOleCache2[],
  317. ULONG ulIterations, CacheTimes Cachetimes[])
  318. {
  319. CStopWatch sw;
  320. HRESULT hres;
  321. ULONG iIter;
  322. // Save the Cache, i.e. save the formats Cached
  323. for (iIter=0; iIter<ulIterations; iIter++)
  324. {
  325. LPPERSISTSTORAGE lpStg = NULL;
  326. hres = pOleCache2[iIter]->QueryInterface(IID_IPersistStorage, (LPVOID FAR*)&lpStg);
  327. if (hres != NOERROR)
  328. continue; //TRy next Cache, it is unexpected condition though
  329. sw.Reset();
  330. hres = lpStg->Save(pSite[iIter]->m_lpObjStorage, TRUE);
  331. hres = lpStg->SaveCompleted(NULL);
  332. GetTimerVal(Cachetimes[iIter].ulSaveCache);
  333. if (lpStg)
  334. lpStg->Release();
  335. LOGRESULTS (TEXT("Cache- Save and SaveCompleted "), hres);
  336. }
  337. //
  338. //To test IOC:Load we need to destroy old cache nodes, create new
  339. //ones and ask them to laod themselves
  340. //
  341. for (iIter=0; iIter < ulIterations; iIter++)
  342. {
  343. if (pOleCache2[iIter])
  344. {
  345. pOleCache2[iIter]->Release();
  346. pOleCache2[iIter] = NULL;
  347. }
  348. }
  349. //Create new set of Cache
  350. for (iIter=0; iIter<ulIterations; iIter++)
  351. {
  352. sw.Reset();
  353. hres = CreateDataCache(NULL, CLSID_NULL, IID_IOleCache2, (LPVOID FAR*)&pOleCache2[iIter]);
  354. GetTimerVal(Cachetimes[iIter].ulCreateCache);
  355. LOGRESULTS (TEXT("CreateDataCache "), hres);
  356. if (hres != NOERROR)
  357. {
  358. goto error;
  359. }
  360. }
  361. //Load the Cache from the storage provided
  362. for (iIter=0; iIter<ulIterations; iIter++)
  363. {
  364. LPPERSISTSTORAGE lpStg = NULL;
  365. //Query for IPS to load the object
  366. hres = pOleCache2[iIter]->QueryInterface(IID_IPersistStorage, (LPVOID FAR*) &lpStg);
  367. if (hres != NOERROR)
  368. continue; //Try next Cache
  369. sw.Reset();
  370. hres = lpStg->Load(pSite[iIter]->m_lpObjStorage);
  371. GetTimerVal(Cachetimes[iIter].ulLoadCache);
  372. if (lpStg)
  373. lpStg->Release();
  374. LOGRESULTS (TEXT("Cache- Load "), hres);
  375. } //End For
  376. error:
  377. if (hres != NOERROR)
  378. Log (TEXT("Routine SaveAndLoadCache failed with hres = "), hres);
  379. }
  380. void WriteCacheOutput(CTestOutput &output, LPTSTR lpstr, CacheTimes *CTimes, ULONG ulIterations)
  381. {
  382. UINT iIter;
  383. output.WriteString (TEXT("Name"));
  384. output.WriteString (lpszTab);
  385. output.WriteString (TEXT("Create"));
  386. output.WriteString (lpszTab);
  387. output.WriteString (TEXT("IOC:Cache"));
  388. output.WriteString (lpszTab);
  389. output.WriteString (TEXT("IOC:InitCache"));
  390. output.WriteString (lpszTab);
  391. output.WriteString (TEXT("LoadCache"));
  392. output.WriteString (lpszTab);
  393. output.WriteString (TEXT("SaveCache"));
  394. output.WriteString (TEXT("\n"));
  395. for (iIter = 0; iIter < ulIterations; iIter++)
  396. {
  397. output.WriteString (lpstr);
  398. output.WriteString (lpszTab);
  399. output.WriteString (lpszTab);
  400. output.WriteLong (CTimes[iIter].ulCreateCache);
  401. output.WriteString (lpszTab);
  402. output.WriteLong (CTimes[iIter].ulCache);
  403. output.WriteString (lpszTab);
  404. output.WriteLong (CTimes[iIter].ulInitCache);
  405. output.WriteString (lpszTab);
  406. output.WriteLong (CTimes[iIter].ulLoadCache);
  407. output.WriteString (lpszTab);
  408. output.WriteLong (CTimes[iIter].ulSaveCache);
  409. output.WriteString (TEXT("\n"));
  410. }
  411. }