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.

355 lines
10 KiB

  1. //+------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993.
  5. //
  6. // File: bm_crtl.cxx
  7. //
  8. // Contents: CreateLink apis
  9. //
  10. // Classes: CCreateLinkApi
  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_crtl.hxx"
  26. //**********************************************************************
  27. //
  28. // CCreateLinkTest::Name, SetUp, Run, CleanUp
  29. //
  30. // Purpose:
  31. //
  32. // These routines provide the implementation for the Name, Setup,
  33. // Run and CleanUp of the class CCreateLinkTest. For details see the doc
  34. // for driver what are these routines supposed to do.
  35. //
  36. // Parameters:
  37. //
  38. //
  39. // Return Value:
  40. //
  41. // None
  42. //
  43. //
  44. // Comments:
  45. // If STRESS is defined don't do anything with timer variable! We are
  46. // not interested in time values.
  47. //
  48. //********************************************************************
  49. TCHAR *CCreateLinkTest::Name ()
  50. {
  51. return TEXT("CreateLinkTest");
  52. }
  53. SCODE CCreateLinkTest::Setup (CTestInput *pInput)
  54. {
  55. CTestBase::Setup(pInput);
  56. HRESULT sc;
  57. HRESULT hres;
  58. #ifdef STRESS
  59. //If stress condition loop number of time = STRESSCOUNT
  60. m_ulIterations = STRESSCOUNT;
  61. #else
  62. // get iteration count
  63. m_ulIterations = pInput->GetIterations(Name());
  64. #endif
  65. #ifndef STRESS
  66. // initialize timing arrays
  67. INIT_RESULTS(m_ulOleCreateLinkSr32);
  68. INIT_RESULTS(m_ulOleCreateLinkOutl);
  69. INIT_RESULTS(m_ulOleCreateLinkRenderDrawSr32);
  70. INIT_RESULTS(m_ulOleCreateLinkRenderDrawOutl);
  71. #endif
  72. sc = OleInitialize(NULL);
  73. if (FAILED(sc))
  74. {
  75. Log (TEXT("Setup - OleInitialize failed."), sc);
  76. return sc;
  77. }
  78. hres = CLSIDFromString(L"Sr32test", &m_clsidSr32);
  79. Log (TEXT("CLSIDFromString returned ."), hres);
  80. if (hres != NOERROR)
  81. return E_FAIL;
  82. hres = CLSIDFromString(OutlineClassName, &m_clsidOutl);
  83. Log (TEXT("CLSIDFromString returned ."), hres);
  84. if (hres != NOERROR)
  85. return E_FAIL;
  86. //CreateLink Doc and Root Storage
  87. m_lpDoc = CSimpleDoc::Create();
  88. for (ULONG iIter=0; iIter<m_ulIterations; iIter++)
  89. {
  90. // CreateLink 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 CCreateLinkTest::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. // CCreateLinkTest::Run
  109. //
  110. // Purpose:
  111. // This is the work horse routine which calls OLE apis.
  112. // The profile is done by creating moniker then calling OleCreateLink on moniker.
  113. //
  114. //
  115. // Parameters:
  116. //
  117. //
  118. // Return Value:
  119. //
  120. // None
  121. //
  122. // Functions called:
  123. // CallOleCreateLink defined below
  124. //
  125. //
  126. // Comments:
  127. // Need to add more Server types including In-Proc servers.
  128. //
  129. //********************************************************************
  130. SCODE CCreateLinkTest::Run ()
  131. {
  132. CStopWatch sw;
  133. BOOL fRet;
  134. TCHAR szTemp[MAX_PATH];
  135. OLECHAR szSr2FileName[MAX_PATH];
  136. OLECHAR szOutlFileName[MAX_PATH];
  137. // Get file name of .ini file. if not specified in the command
  138. // line, use the default BM.INI in the local directory
  139. GetCurrentDirectory (MAX_PATH, szTemp);
  140. swprintf(szSr2FileName,
  141. #ifdef UNICODE
  142. L"%s\\foo.sr2",
  143. #else
  144. L"%S\\foo.sr2",
  145. #endif
  146. szTemp);
  147. swprintf(szOutlFileName,
  148. #ifdef UNICODE
  149. L"%s\\foo.oln",
  150. #else
  151. L"%S\\foo.oln",
  152. #endif
  153. szTemp);
  154. fRet = CallOleCreateLink(szSr2FileName, m_pSite, IID_IOleObject, NULL,
  155. NULL, m_ulIterations, m_ulOleCreateLinkSr32);
  156. fRet = CallOleCreateLink(szOutlFileName, m_pSite, IID_IOleObject, NULL,
  157. NULL, m_ulIterations, m_ulOleCreateLinkOutl);
  158. fRet = CallOleCreateLink(szSr2FileName, m_pSite, IID_IOleObject, OLERENDER_DRAW,
  159. NULL, m_ulIterations, m_ulOleCreateLinkRenderDrawSr32);
  160. fRet = CallOleCreateLink(szOutlFileName, m_pSite, IID_IOleObject, OLERENDER_DRAW,
  161. NULL, m_ulIterations, m_ulOleCreateLinkRenderDrawOutl);
  162. //Create the objects with RenderFormat = Metafile
  163. FORMATETC fmte = {CF_METAFILEPICT, NULL, DVASPECT_CONTENT, -1, TYMED_MFPICT};
  164. fRet = CallOleCreateLink(szSr2FileName, m_pSite, IID_IOleObject, OLERENDER_FORMAT,
  165. &fmte, m_ulIterations, m_ulOleCreateLinkRenderFormatMFSr32);
  166. fRet = CallOleCreateLink(szOutlFileName, m_pSite, IID_IOleObject, OLERENDER_FORMAT,
  167. &fmte, m_ulIterations, m_ulOleCreateLinkRenderFormatMFOutl);
  168. //Create the objects with RenderFormat = Bitmap
  169. fmte.cfFormat = CF_BITMAP;
  170. fmte.dwAspect = DVASPECT_CONTENT;
  171. fmte.tymed = TYMED_GDI;
  172. fRet = CallOleCreateLink(szSr2FileName, m_pSite, IID_IOleObject, OLERENDER_FORMAT,
  173. &fmte, m_ulIterations, m_ulOleCreateLinkRenderFormatBMSr32);
  174. //Create the objects with RenderFormat = Text
  175. fmte.cfFormat = CF_TEXT;
  176. fmte.dwAspect = DVASPECT_CONTENT;
  177. fmte.tymed = TYMED_HGLOBAL;
  178. fRet = CallOleCreateLink(szSr2FileName, m_pSite, IID_IOleObject, OLERENDER_FORMAT,
  179. &fmte, m_ulIterations, m_ulOleCreateLinkRenderFormatTextSr32);
  180. fRet = CallOleCreateLink(szOutlFileName, m_pSite, IID_IOleObject, OLERENDER_FORMAT,
  181. &fmte, m_ulIterations, m_ulOleCreateLinkRenderFormatTextOutl);
  182. return S_OK;
  183. }
  184. SCODE CCreateLinkTest::Report (CTestOutput &output)
  185. {
  186. //Bail out immediately on STRESS because none of the following variables
  187. //will have sane value
  188. #ifdef STRESS
  189. return S_OK;
  190. #endif
  191. output.WriteString (TEXT("*************************************************\n"));
  192. output.WriteSectionHeader (Name(), TEXT("CreateLink Apis"), *m_pInput);
  193. output.WriteString (TEXT("*************************************************\n"));
  194. output.WriteString (TEXT("\n"));
  195. output.WriteResults (TEXT("OleCreateLink Sr32test\t\t\t"), m_ulIterations, m_ulOleCreateLinkSr32);
  196. output.WriteString (TEXT("\n"));
  197. output.WriteString (TEXT("\n"));
  198. output.WriteResults (TEXT("OleCreateLink Outline \t\t\t"), m_ulIterations, m_ulOleCreateLinkOutl);
  199. output.WriteString (TEXT("\n"));
  200. output.WriteString (TEXT("\n"));
  201. output.WriteResults (TEXT("OleCreateLink with RenderDraw Sr32test\t"), m_ulIterations, m_ulOleCreateLinkRenderDrawSr32);
  202. output.WriteString (TEXT("\n"));
  203. output.WriteString (TEXT("\n"));
  204. output.WriteResults (TEXT("OleCreateLink with RenderDraw Outline\t"), m_ulIterations, m_ulOleCreateLinkRenderDrawOutl);
  205. output.WriteString (TEXT("\n"));
  206. output.WriteString (TEXT("\n"));
  207. output.WriteResults (TEXT("OleCreateLink with RenderFormatMF Sr32test\t"), m_ulIterations, m_ulOleCreateLinkRenderFormatMFSr32);
  208. output.WriteString (TEXT("\n"));
  209. output.WriteString (TEXT("\n"));
  210. output.WriteResults (TEXT("OleCreateLink with RenderFormatMF Outline\t"), m_ulIterations, m_ulOleCreateLinkRenderFormatMFOutl);
  211. output.WriteString (TEXT("\n"));
  212. output.WriteString (TEXT("\n"));
  213. output.WriteResults (TEXT("OleCreateLink with RenderFormatBM Sr32test\t "), m_ulIterations, m_ulOleCreateLinkRenderFormatBMSr32);
  214. output.WriteString (TEXT("\n"));
  215. #ifdef DOESNOTWORKFOROUTLINE
  216. output.WriteString (TEXT("\n"));
  217. output.WriteResults (TEXT("OleCreateLink with RenderFormatBM Outline\t"), m_ulIterations, m_ulOleCreateLinkRenderFormatBMOutl);
  218. output.WriteString (TEXT("\n"));
  219. #endif
  220. output.WriteString (TEXT("\n"));
  221. output.WriteResults (TEXT("OleCreateLink with RenderFormatTxt Sr32test\t"), m_ulIterations, m_ulOleCreateLinkRenderFormatTextSr32);
  222. output.WriteString (TEXT("\n"));
  223. output.WriteString (TEXT("\n"));
  224. output.WriteResults (TEXT("OleCreateLink with RenderFormatTxt Outline\t "), m_ulIterations, m_ulOleCreateLinkRenderFormatTextOutl);
  225. output.WriteString (TEXT("\n"));
  226. return S_OK;
  227. }
  228. //**********************************************************************
  229. //
  230. // CallOleCreateLink
  231. //
  232. // Purpose:
  233. // Calls OleCreateLink to create the link and then destroys them.
  234. //
  235. //
  236. // Parameters:
  237. //
  238. //
  239. // Return Value:
  240. //
  241. // None
  242. //
  243. // Functions called:
  244. // CreateFileMoniker OLE2 api
  245. // OleCreateLink OLE2 api - Is profiled here
  246. //
  247. //
  248. // Comments:
  249. // Need to add more Server types including In-Proc servers.
  250. //
  251. //********************************************************************
  252. BOOL CallOleCreateLink(LPCOLESTR lpFileName, CSimpleSite * pSite[], REFIID riid, DWORD renderopt,
  253. LPFORMATETC pFormatEtc, ULONG ulIterations, ULONG uOleCreateLinktime[])
  254. {
  255. CStopWatch sw;
  256. HRESULT hres;
  257. ULONG iIter;
  258. LPMONIKER pmk = NULL;
  259. BOOL retVal = FALSE;
  260. hres = CreateFileMoniker(lpFileName, &pmk);
  261. if (hres != NOERROR)
  262. goto error;
  263. for ( iIter=0; iIter<ulIterations; iIter++)
  264. {
  265. HEAPVALIDATE() ;
  266. sw.Reset();
  267. hres = OleCreateLink(pmk, riid, renderopt, pFormatEtc, &pSite[iIter]->m_OleClientSite,
  268. pSite[iIter]->m_lpObjStorage, (VOID FAR* FAR*)&pSite[iIter]->m_lpOleObject);
  269. GetTimerVal(uOleCreateLinktime[iIter]);
  270. LOGRESULTS (TEXT("OleCreateLink "), hres);
  271. if (hres != NOERROR)
  272. {
  273. goto error;
  274. }
  275. }
  276. //CleanUp before going to Next
  277. for (iIter=0; iIter<ulIterations; iIter++)
  278. {
  279. // Unload the object and release the Ole Object
  280. pSite[iIter]->UnloadOleObject();
  281. }
  282. retVal = TRUE;
  283. error:
  284. if (hres != NOERROR)
  285. Log (TEXT("Routine CallOleCreateLink failed with hres = "), hres);
  286. if (pmk)
  287. pmk->Release();
  288. return retVal;
  289. }