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.

608 lines
19 KiB

  1. //+------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993.
  5. //
  6. // File: bm_Clip.cxx
  7. //
  8. // Contents: Contains the impl of CClipbrdTest which deals with
  9. // Clipboard related apis.
  10. //
  11. // Classes: CClipbrdTest
  12. //
  13. // Functions:
  14. //
  15. // History: Doesn't work yet. The code to place data on the clipboard
  16. // uses autoamation which isn't supported in the server.
  17. //
  18. //--------------------------------------------------------------------------
  19. #include <headers.cxx>
  20. #pragma hdrstop
  21. #include "hlp_util.hxx"
  22. #include "hlp_iocs.hxx"
  23. #include "hlp_ias.hxx"
  24. #include "hlp_app.hxx"
  25. #include "hlp_site.hxx"
  26. #include "hlp_doc.hxx"
  27. #include "bm_Clip.hxx"
  28. #include <oleauto.h>
  29. //**********************************************************************
  30. //
  31. // CClipbrd::Name, SetUp, Run, CleanUp
  32. //
  33. // Purpose:
  34. //
  35. // These routines provide the implementation for the Name, Setup,
  36. // Run and CleanUp of the class CClipbrd. For details see the doc
  37. // for driver what are these routines supposed to do.
  38. //
  39. // Parameters:
  40. //
  41. //
  42. // Return Value:
  43. //
  44. // None
  45. //
  46. //
  47. // Comments:
  48. // If STRESS is defined don't do anything with timer variable! We are
  49. // not interested in time values.
  50. //
  51. //********************************************************************
  52. TCHAR *CClipbrdTest::Name ()
  53. {
  54. return TEXT("ClipbrdTest");
  55. }
  56. SCODE CClipbrdTest::Setup (CTestInput *pInput)
  57. {
  58. CTestBase::Setup(pInput);
  59. HRESULT sc;
  60. HRESULT hres;
  61. #ifdef STRESS
  62. //If stress condition loop number of time = STRESSCOUNT
  63. m_ulIterations = STRESSCOUNT;
  64. #else
  65. // get iteration count
  66. m_ulIterations = pInput->GetIterations(Name());
  67. #endif
  68. // initialize timing arrays
  69. #ifndef STRESS
  70. INIT_RESULTS(m_ulOleGetClipbrd);
  71. INIT_RESULTS(m_ulOleQueryCreate);
  72. INIT_RESULTS(m_ulOleQueryLink);
  73. INIT_RESULTS(m_ulCreateFromClipOutl);
  74. INIT_RESULTS(m_ulCreateFromClipRenderDrawOutl);
  75. INIT_RESULTS(m_ulCreateFromClipRenderAsisOutl);
  76. INIT_RESULTS(m_ulCreateLinkFromClipOutl);
  77. INIT_RESULTS(m_ulCreateLinkFromClipRenderDrawOutl);
  78. INIT_RESULTS(m_ulCreateStaticFromClipRenderDrawOutl);
  79. INIT_RESULTS(m_ulCreateStaticFromClipRenderDrawBMOutl);
  80. #endif //STRESS
  81. sc = OleInitialize(NULL);
  82. if (FAILED(sc))
  83. {
  84. Log (TEXT("Setup - OleInitialize failed."), sc);
  85. return sc;
  86. }
  87. hres = CLSIDFromString(OutlineClassName, &m_clsidOutl);
  88. Log (TEXT("CLSIDFromString returned ."), hres);
  89. assert (hres == NOERROR);
  90. //Create root Doc and STorage for Doc
  91. m_lpDoc = CSimpleDoc::Create();
  92. //Create Individual Objects and Init the table
  93. for (ULONG iIter=0; iIter<m_ulIterations; iIter++) {
  94. // CreateLink an instance of Site
  95. CSimpleSite *pObj = CSimpleSite::Create(m_lpDoc, iIter);
  96. if (pObj)
  97. m_pSite[iIter] = pObj;
  98. }
  99. return sc;
  100. }
  101. SCODE CClipbrdTest::Cleanup ()
  102. {
  103. for (ULONG iIter=0; iIter<m_ulIterations; iIter++)
  104. {
  105. delete m_pSite[iIter];
  106. }
  107. OleUninitialize();
  108. return S_OK;
  109. }
  110. //**********************************************************************
  111. //
  112. // CClipbrd::Run
  113. //
  114. // Purpose:
  115. // This is the work horse routine which calls OLE apis.
  116. //
  117. //
  118. // Parameters:
  119. //
  120. //
  121. // Return Value:
  122. //
  123. // None
  124. //
  125. // Functions called:
  126. // OleSetClipboard OLE - Is profiled here
  127. // OleGetClipboard OLE - Is profiled here
  128. // OleCreateFromClip defined below
  129. //
  130. //
  131. // Comments:
  132. //
  133. //********************************************************************
  134. SCODE CClipbrdTest::Run ()
  135. {
  136. CStopWatch sw;
  137. HRESULT hres;
  138. BOOL fRet;
  139. TCHAR szTemp[MAX_PATH];
  140. OLECHAR szOutlFileName[MAX_PATH];
  141. // Get file name of .ini file. if not specified in the command
  142. // line, use the default BM.INI in the local directory
  143. GetCurrentDirectory (MAX_PATH, szTemp);
  144. swprintf(szOutlFileName,
  145. #ifdef UNICODE
  146. L"%s\\foo.oln",
  147. #else
  148. L"%S\\foo.oln",
  149. #endif
  150. szTemp);
  151. //Empty clipboard and get the estimate on empty clipboard
  152. hres = OleSetClipboard(NULL);
  153. sw.Reset();
  154. hres = OleSetClipboard(NULL);
  155. GetTimerVal(m_ulSetClipEmpty);
  156. fRet = CallOleGetClipbrd(szOutlFileName, m_ulIterations, m_ulOleGetClipbrd,
  157. m_ulOleQueryCreate, m_ulOleQueryLink);
  158. //Now Empty clipboard again. This time Data on clipboard from SvrOutl
  159. sw.Reset();
  160. hres = OleSetClipboard(NULL);
  161. GetTimerVal(m_ulSetClipOutl);
  162. //
  163. //Test cases for OleCreateFromData
  164. //
  165. fRet = CallCreateFromClip(szOutlFileName, m_pSite, IID_IOleObject, OLERENDER_NONE,
  166. NULL, m_ulIterations, m_ulCreateFromClipOutl, OLECREATE);
  167. //Empty clipboard for next test case
  168. hres = OleSetClipboard(NULL);
  169. fRet = CallCreateFromClip(szOutlFileName, m_pSite, IID_IOleObject, OLERENDER_DRAW,
  170. NULL, m_ulIterations, m_ulCreateFromClipRenderDrawOutl, OLECREATE);
  171. //Empty clipboard for next test case
  172. hres = OleSetClipboard(NULL);
  173. fRet = CallCreateFromClip(szOutlFileName, m_pSite, IID_IOleObject, OLERENDER_ASIS,
  174. NULL, m_ulIterations, m_ulCreateFromClipRenderAsisOutl, OLECREATE);
  175. //
  176. //Test cases for OleCreateLinkFromData
  177. //
  178. hres = OleSetClipboard(NULL);
  179. fRet = CallCreateFromClip(szOutlFileName, m_pSite, IID_IOleObject, OLERENDER_NONE,
  180. NULL, m_ulIterations, m_ulCreateLinkFromClipOutl, OLECREATELINK);
  181. //Empty clipboard for next test case
  182. hres = OleSetClipboard(NULL);
  183. fRet = CallCreateFromClip(szOutlFileName, m_pSite, IID_IOleObject, OLERENDER_DRAW,
  184. NULL, m_ulIterations, m_ulCreateLinkFromClipRenderDrawOutl, OLECREATELINK);
  185. //
  186. //Test cases for OleCreateLinkFromData
  187. //
  188. //I would have liked Bitmap but SvrOutl only supports Metafile
  189. FORMATETC fmte = {CF_ENHMETAFILE, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  190. hres = OleSetClipboard(NULL);
  191. fRet = CallCreateFromClip(szOutlFileName, m_pSite, IID_IOleObject, OLERENDER_FORMAT,
  192. &fmte, m_ulIterations, m_ulCreateStaticFromClipRenderDrawBMOutl, OLECREATESTATIC);
  193. //Empty clipboard for next test case
  194. hres = OleSetClipboard(NULL);
  195. fRet = CallCreateFromClip(szOutlFileName, m_pSite, IID_IOleObject, OLERENDER_DRAW,
  196. NULL, m_ulIterations, m_ulCreateStaticFromClipRenderDrawOutl, OLECREATESTATIC);
  197. return S_OK;
  198. }
  199. SCODE CClipbrdTest::Report (CTestOutput &output)
  200. {
  201. //Bail out immediately on STRESS because none of the following variables
  202. //will have sane value
  203. #ifdef STRESS
  204. return S_OK;
  205. #endif
  206. output.WriteString (TEXT("*************************************************\n"));
  207. output.WriteSectionHeader (Name(), TEXT("Clipbrd Apis"), *m_pInput);
  208. output.WriteString (TEXT("*************************************************\n"));
  209. output.WriteString (TEXT("\n"));
  210. output.WriteResults (TEXT("OleGetClipbrd \t\t\t"), m_ulIterations, m_ulOleGetClipbrd);
  211. output.WriteString (TEXT("\n"));
  212. output.WriteString (TEXT("\n"));
  213. output.WriteResults (TEXT("OleSetClipbrd Empty\t\t"), 1, &m_ulSetClipEmpty);
  214. output.WriteString (TEXT("\n"));
  215. output.WriteResults (TEXT("OleSetClipbrd Data\t\t"), 1, &m_ulSetClipOutl);
  216. output.WriteString (TEXT("\n"));
  217. output.WriteString (TEXT("\n"));
  218. output.WriteString (TEXT("***************************************\n"));
  219. output.WriteResults (TEXT("OleCreateFromClip Outline \t\t\t"), m_ulIterations, m_ulCreateFromClipOutl);
  220. output.WriteString (TEXT("\n"));
  221. output.WriteString (TEXT("\n"));
  222. output.WriteResults (TEXT("OleCreateFromClip with RenderDraw Outline\t"), m_ulIterations, m_ulCreateFromClipRenderDrawOutl);
  223. output.WriteString (TEXT("\n"));
  224. output.WriteString (TEXT("\n"));
  225. output.WriteResults (TEXT("OleCreateFromClip with RenderFormatMF Outline\t "), m_ulIterations, m_ulCreateFromClipRenderFormatMFOutl);
  226. output.WriteString (TEXT("\n"));
  227. output.WriteString (TEXT("\n"));
  228. output.WriteResults (TEXT("OleCreateFromClip with RenderAsIs Outline \t"), m_ulIterations, m_ulCreateFromClipRenderAsisOutl);
  229. output.WriteString (TEXT("\n"));
  230. output.WriteString (TEXT("\n"));
  231. output.WriteString (TEXT("***************************************\n"));
  232. output.WriteResults (TEXT("OleCreateLinkFromClip Outline \t\t"), m_ulIterations, m_ulCreateLinkFromClipOutl);
  233. output.WriteString (TEXT("\n"));
  234. output.WriteString (TEXT("\n"));
  235. output.WriteResults (TEXT("OleCreateLinkFromClip with RenderDraw Outline \t"), m_ulIterations, m_ulCreateLinkFromClipRenderDrawOutl);
  236. output.WriteString (TEXT("\n"));
  237. output.WriteString (TEXT("***************************************\n"));
  238. output.WriteResults (TEXT("OleCreateStaticFromClip Outline\t"), m_ulIterations, m_ulCreateStaticFromClipRenderDrawOutl);
  239. output.WriteString (TEXT("\n"));
  240. #if VERIFYSTATICBEHAVIOR
  241. output.WriteString (TEXT("\n"));
  242. output.WriteResults (TEXT("OleCreateStaticFromClip with RenderDraw Outline \t"), m_ulIterations, m_ulCreateStaticFromClipRenderDrawBMOutl);
  243. output.WriteString (TEXT("\n"));
  244. #endif
  245. return S_OK;
  246. }
  247. //**********************************************************************
  248. //
  249. // OleGetClipboard
  250. //
  251. // Purpose:
  252. // This routine is called CallOleGetClipboard but it also instruments
  253. // OLeQueryXX apis! (This was the best place to do that otherwise what
  254. // to do with Clipboard data).
  255. //
  256. //
  257. // Parameters:
  258. //
  259. //
  260. // Return Value:
  261. //
  262. // None
  263. //
  264. // Functions called:
  265. // CreateFileMoniker OLE - creates file moniker
  266. // CreateBindCtx OLE
  267. // IDispatch::GetIDsOfNames Dispatch routine which makes call into SvrOutl (yet another version!)
  268. // OleGetClipboard OLE - Is profiled here
  269. // OleQueryCreateFromData OLE - Is profiled here
  270. // OleLinkFromData OLE - Is profiled here
  271. //
  272. //
  273. // Comments:
  274. //
  275. //********************************************************************
  276. BOOL CallOleGetClipbrd(LPCOLESTR lpFileName, ULONG ulIterations, ULONG uOleClipbrdtime[],
  277. ULONG uOleQCreatetime[], ULONG uOleQLinktime[])
  278. {
  279. CStopWatch sw;
  280. HRESULT hres;
  281. ULONG iIter;
  282. BOOL retVal = FALSE;
  283. LPDATAOBJECT pDO = NULL;
  284. LPMONIKER pmk = NULL;
  285. LPBC pbc = NULL;
  286. IDispatch FAR* pDisp = NULL;
  287. hres = CreateFileMoniker(lpFileName, &pmk);
  288. if (hres != NOERROR)
  289. goto error;
  290. else {
  291. //Bind to moniker object and ask for IID_IDispatch
  292. hres = CreateBindCtx(NULL, &pbc);
  293. if (hres != NOERROR)
  294. goto error;
  295. hres = pmk->BindToObject(pbc, NULL, IID_IDispatch, (LPVOID FAR*) &pDisp);
  296. if (hres != NOERROR)
  297. goto error;
  298. //Now Make outline copy object to clipboard
  299. OLECHAR FAR* pCopy = L"COPY";
  300. DISPID dispid;
  301. EXCEPINFO expinfo;
  302. DISPPARAMS vNullDisp = {NULL, 0, 0, NULL};
  303. hres = pDisp->GetIDsOfNames(
  304. IID_NULL,
  305. &pCopy,
  306. 1, LOCALE_USER_DEFAULT,
  307. &dispid);
  308. if (hres == NOERROR) {
  309. //Invoke Method Copy so that SvrOutl copies data to clipboard
  310. hres = pDisp->Invoke( dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD,
  311. &vNullDisp, NULL, &expinfo, NULL);
  312. if (hres != NOERROR)
  313. goto error;
  314. }
  315. pDisp->Release();
  316. pDisp = NULL;
  317. }
  318. for ( iIter=0; iIter<ulIterations; iIter++) {
  319. //If we have not had any problem then
  320. sw.Reset();
  321. //Get the Clipboard data
  322. hres = OleGetClipboard(&pDO);
  323. GetTimerVal(uOleClipbrdtime[iIter]);
  324. LOGRESULTS (TEXT("OleGetClipboard "), hres);
  325. if (hres != NOERROR)
  326. {
  327. goto error;
  328. }
  329. //Now call QueryCreate and QueryLinkFromCLip Apis
  330. sw.Reset();
  331. hres = OleQueryCreateFromData(pDO);
  332. GetTimerVal(uOleQCreatetime[iIter]);
  333. LOGRESULTS (TEXT("OleQueryCreateFromData "), hres);
  334. sw.Reset();
  335. hres = OleQueryLinkFromData(pDO);
  336. GetTimerVal(uOleQLinktime[iIter]);
  337. LOGRESULTS (TEXT("OleQueryCreateLinkFromData "), hres);
  338. if (pDO) {
  339. pDO->Release();
  340. pDO = NULL;
  341. }
  342. }
  343. retVal = TRUE;
  344. error:
  345. if (hres != NOERROR)
  346. Log (TEXT("Routine OleGetClipbrd failed with hres = "), hres);
  347. if (pmk)
  348. pmk->Release();
  349. if (pDO)
  350. pDO->Release();
  351. if (pbc)
  352. pbc->Release();
  353. if (pDisp)
  354. pDisp->Release();
  355. return retVal;
  356. }
  357. //**********************************************************************
  358. //
  359. // CallCreateFromClip
  360. //
  361. // Purpose:
  362. // This routine creates the OLE object from Clipboard data. It creates
  363. // both embedded and linked object.
  364. //
  365. //
  366. // Parameters:
  367. //
  368. //
  369. // Return Value:
  370. //
  371. // None
  372. //
  373. // Functions called:
  374. // CreateFileMoniker OLE - creates file moniker
  375. // CreateBindCtx OLE
  376. // IDispatch::GetIDsOfNames Dispatch routine which makes call into SvrOutl (yet another version!)
  377. // IDispatch::Invoke Dispatch routine asking Svroutl to copy to clipboard
  378. // OleGetClipboard OLE - called to get Data object on Clip
  379. // OleCreateFromData OLE - Is profiled here
  380. // OleCreateLinkFromData OLE - Is profiled here
  381. // OleCreateStaticFromData OLE - Is profiled here
  382. //
  383. //
  384. // Comments:
  385. //
  386. //********************************************************************
  387. BOOL CallCreateFromClip(LPCOLESTR lpFileName, CSimpleSite * pSite[], REFIID riid, DWORD renderopt,
  388. LPFORMATETC pFormatEtc, ULONG ulIterations, ULONG uOleClipbrdtime[], CREATE_METHOD MethodID)
  389. {
  390. CStopWatch sw;
  391. HRESULT hres;
  392. ULONG iIter;
  393. BOOL retVal = FALSE;
  394. LPDATAOBJECT pDO = NULL;
  395. LPMONIKER pmk = NULL;
  396. LPBC pbc = NULL;
  397. IDispatch FAR* pDisp = NULL;
  398. hres = CreateFileMoniker(lpFileName, &pmk);
  399. if (hres != NOERROR)
  400. goto error;
  401. else {
  402. //Bind to moniker object and ask for IID_IDispatch
  403. hres = CreateBindCtx(NULL, &pbc);
  404. if (hres != NOERROR)
  405. goto error;
  406. hres = pmk->BindToObject(pbc, NULL, IID_IDispatch, (LPVOID FAR*)&pDisp);
  407. if (hres != NOERROR)
  408. goto error;
  409. //Now Make outline copy object to clipboard
  410. OLECHAR FAR* pCopy = L"COPY";
  411. DISPID dispid;
  412. EXCEPINFO expinfo;
  413. DISPPARAMS vNullDisp = {NULL, 0, 0, NULL};
  414. hres = pDisp->GetIDsOfNames(
  415. IID_NULL,
  416. &pCopy,
  417. 1, LOCALE_USER_DEFAULT,
  418. &dispid);
  419. if (hres == NOERROR) {
  420. hres = pDisp->Invoke( dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD,
  421. &vNullDisp, NULL, &expinfo, NULL);
  422. if (hres != NOERROR)
  423. goto error;
  424. }
  425. pDisp->Release();
  426. pDisp = NULL;
  427. }
  428. //Get the Clipboard data
  429. hres = OleGetClipboard(&pDO);
  430. if (hres != NOERROR)
  431. goto error;
  432. for ( iIter=0; iIter<ulIterations; iIter++) {
  433. //If we have not had any problem then
  434. HEAPVALIDATE() ;
  435. switch(MethodID) {
  436. case OLECREATE:
  437. {
  438. sw.Reset();
  439. hres = OleCreateFromData(pDO, riid, renderopt,
  440. pFormatEtc, &pSite[iIter]->m_OleClientSite,
  441. pSite[iIter]->m_lpObjStorage, (VOID FAR* FAR*)&pSite[iIter]->m_lpOleObject);
  442. break;
  443. }
  444. case OLECREATELINK:
  445. {
  446. sw.Reset();
  447. hres = OleCreateLinkFromData(pDO, riid, renderopt,
  448. pFormatEtc, &pSite[iIter]->m_OleClientSite,
  449. pSite[iIter]->m_lpObjStorage, (VOID FAR* FAR*)&pSite[iIter]->m_lpOleObject);
  450. break;
  451. }
  452. case OLECREATESTATIC:
  453. {
  454. sw.Reset();
  455. hres = OleCreateStaticFromData(pDO, riid, renderopt,
  456. pFormatEtc, &pSite[iIter]->m_OleClientSite,
  457. pSite[iIter]->m_lpObjStorage, (VOID FAR* FAR*)&pSite[iIter]->m_lpOleObject);
  458. break;
  459. }
  460. default:
  461. assert(FALSE);
  462. }
  463. GetTimerVal(uOleClipbrdtime[iIter]);
  464. LOGRESULTS (TEXT("OleCreate/Link/Static "), hres);
  465. if (hres != NOERROR)
  466. {
  467. goto error;
  468. }
  469. }
  470. for (iIter=0; iIter<ulIterations; iIter++)
  471. {
  472. // Unload the object and release the Ole Object
  473. pSite[iIter]->UnloadOleObject();
  474. }
  475. retVal = TRUE;
  476. error:
  477. if (hres != NOERROR)
  478. Log (TEXT("Routine CallCreateFromClip failed with hres = "), hres);
  479. if (pmk)
  480. pmk->Release();
  481. if (pDO)
  482. pDO->Release();
  483. if (pbc)
  484. pbc->Release();
  485. if (pDisp)
  486. pDisp->Release();
  487. return retVal;
  488. }