Source code of Windows XP (NT5)
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.

798 lines
21 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993 - 1993.
  5. //
  6. // File: tmoniker.cxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 12-31-93 ErikGav Chicago port
  15. //
  16. //----------------------------------------------------------------------------
  17. // moniker.cxx : various tests related to monikers...
  18. //
  19. #pragma optimize("",off)
  20. #include <stdio.h>
  21. #include <windows.h>
  22. #include <ole2.h>
  23. #include "olebind.hxx"
  24. #include "tmoniker.h"
  25. STDAPI_(LPSTREAM) CreateMemStm(DWORD cb, LPHANDLE phdl);
  26. // BUGBUG: Make this test more extensive -- all operations on a
  27. // bind context should be verified.
  28. BOOL TestBindCtx( void )
  29. {
  30. XBindCtx pbc;
  31. XUnknown punk;
  32. XUnknown punk2;
  33. HRESULT hr = CreateBindCtx(0, &pbc);
  34. TEST_FAILED_HR(FAILED(hr), "CreateBindCtx Failed")
  35. hr = pbc->RegisterObjectParam(L"Key1", pbc);
  36. TEST_FAILED_HR(FAILED(hr), "RegisterObjectParam Failed")
  37. hr = pbc->GetObjectParam(L"Key1", &punk2);
  38. TEST_FAILED_HR(FAILED(hr), "GetObjectParam Failed")
  39. TEST_FAILED((pbc != punk2),
  40. "Failure to get registered object parameter")
  41. // BUGBUG: What do we test for here?
  42. punk2.Set(NULL);
  43. hr = pbc->GetObjectParam(L"Key2", &punk2);
  44. TEST_FAILED_HR((hr != E_FAIL),
  45. "GetObjectParam with bad key did not return an error")
  46. TEST_FAILED((punk2 != NULL),
  47. "Bad GetObjectParam did not return NULL for object")
  48. hr = pbc->RegisterObjectParam(L"Key2", pbc);
  49. TEST_FAILED_HR(FAILED(hr), "Second RegisterObjectParam Failed")
  50. hr = pbc->GetObjectParam(L"Key2", &punk);
  51. TEST_FAILED_HR(FAILED(hr), "GetObjectParam on second Failed")
  52. TEST_FAILED((pbc != punk),
  53. "Failure on second to get registered object parameter")
  54. // BUGBUG: What do we check?
  55. punk.Set(NULL);
  56. hr = pbc->RevokeObjectParam(L"Key2");
  57. TEST_FAILED_HR(FAILED(hr),
  58. "RevokeObjectParam of Key2 Failed")
  59. hr = pbc->GetObjectParam(L"Key2", &punk);
  60. TEST_FAILED_HR((hr != E_FAIL),
  61. "Get of revoked Key2 returned success")
  62. TEST_FAILED((punk != NULL),
  63. "Value returned on get of revoked key2")
  64. hr = pbc->RevokeObjectParam(L"Key1");
  65. TEST_FAILED_HR(FAILED(hr),
  66. "RevokeObjectParam of Key1 Failed")
  67. return FALSE;
  68. }
  69. BOOL VerifyFileMoniker(LPWSTR wcsFile)
  70. {
  71. HRESULT hr;
  72. XMoniker pmk;
  73. XBindCtx pbc;
  74. LPWSTR wcsDisplayName = NULL;
  75. hr = CreateBindCtx(0,&pbc);
  76. TEST_FAILED_HR(FAILED(hr), "CreateBindCtx");
  77. hr = CreateFileMoniker(wcsFile,&pmk);
  78. TEST_FAILED_HR(FAILED(hr), "CreateFileMoniker failed");
  79. hr = pmk->GetDisplayName(pbc,NULL,&wcsDisplayName);
  80. TEST_FAILED_HR(FAILED(hr), "GetDisplayName failed");
  81. if (0 != wcscmp(wcsFile,wcsDisplayName))
  82. {
  83. wsprintfA(&wszErrBuf[0], "(%S) doesn't match displayname (%S)",wcsFile,wcsDisplayName);
  84. MessageBoxA(NULL, &wszErrBuf[0], szOleBindError, MB_OK);
  85. hr = E_FAIL;
  86. }
  87. CoTaskMemFree(wcsDisplayName);
  88. return(hr);
  89. }
  90. BOOL TestMoniker(LPWSTR pszPath1, LPWSTR pszPath2)
  91. {
  92. XUnknown pUnk;
  93. XUnknown pUnk1;
  94. XBindCtx pbc;
  95. XMoniker pmk1;
  96. XMoniker pmk2;
  97. XMoniker pmk3;
  98. XMoniker pmk4;
  99. XMoniker pmk5;
  100. XMoniker pmk6;
  101. XMoniker pmkItem1;
  102. XMoniker pmkItem2;
  103. XMoniker pmkAnti;
  104. XStream pStm;
  105. XOleObject pObj;
  106. XMalloc pIMalloc;
  107. XMoniker pmkLong1;
  108. XMoniker pmkLong2;
  109. XRunningObjectTable prot;
  110. ULONG chEaten;
  111. LPWSTR szName;
  112. LARGE_INTEGER large_int;
  113. HRESULT hr;
  114. //
  115. // Test the dotdot eating methods
  116. //
  117. VerifyFileMoniker(L".");
  118. VerifyFileMoniker(L"..\\");
  119. VerifyFileMoniker(L"foo.bar");
  120. VerifyFileMoniker(L".foo.bar");
  121. VerifyFileMoniker(L".foo..bar");
  122. VerifyFileMoniker(L"..foo.bar");
  123. VerifyFileMoniker(L"..foo..bar");
  124. VerifyFileMoniker(L"foo\\bar");
  125. VerifyFileMoniker(L"foo\\.bar");
  126. VerifyFileMoniker(L"foo\\..bar");
  127. VerifyFileMoniker(L".foo\\bar");
  128. VerifyFileMoniker(L".foo\\.bar");
  129. VerifyFileMoniker(L".foo\\..bar");
  130. VerifyFileMoniker(L"..foo\\bar");
  131. VerifyFileMoniker(L"..foo\\.bar");
  132. VerifyFileMoniker(L"..foo\\..bar");
  133. VerifyFileMoniker(L"...foo\\bar");
  134. VerifyFileMoniker(L"...foo\\.bar");
  135. VerifyFileMoniker(L"...foo\\..bar");
  136. VerifyFileMoniker(L"\\foo\\bar");
  137. VerifyFileMoniker(L"\\.foo\\bar");
  138. VerifyFileMoniker(L"\\..foo\\bar");
  139. VerifyFileMoniker(L"..\\foo\\bar");
  140. VerifyFileMoniker(L"..\\.foo\\bar");
  141. VerifyFileMoniker(L"..\\..foo\\bar");
  142. hr = CoGetMalloc(MEMCTX_TASK, &pIMalloc);
  143. TEST_FAILED_HR(FAILED(hr), "CoGetMalloc failed");
  144. hr = CreateFileMoniker(pszPath1, &pmk1);
  145. TEST_FAILED_HR(FAILED(hr), "CreateFileMoniker for path1 failed!")
  146. TEST_FAILED((pmk1 == NULL),
  147. "CreateFileMoniker returned a null moniker ptr")
  148. hr = CreateBindCtx(0, &pbc);
  149. TEST_FAILED_HR(FAILED(hr),
  150. "CreateBindCtx File Moniker GetDisplayName failed!")
  151. hr = pmk1->GetDisplayName(pbc, NULL, &szName);
  152. // release it
  153. pbc.Set(NULL, FALSE);
  154. TEST_FAILED_HR(FAILED(hr), "File Moniker GetDisplayName failed!");
  155. // BUGBUG: The following is an inappropriate test.
  156. // TEST_FAILED((lstrcmp(szName, pszPath1) != 0), "Wrong path from file mon");
  157. // Free the path
  158. pIMalloc->Free(szName);
  159. LAST_RELEASE(pmk1)
  160. CreateFileMoniker(pszPath1, &pmk1);
  161. hr = CreateFileMoniker(pszPath2, &pmk6);
  162. TEST_FAILED_HR(FAILED(hr), "CreateFileMoniker for path2 failed")
  163. //
  164. // Test Item Monikers
  165. //
  166. hr = CreateItemMoniker(L"\\", L"1", &pmk2);
  167. TEST_FAILED_HR(FAILED(hr), "CreateItemMoniker 1 failed")
  168. hr = CreateBindCtx(0, &pbc);
  169. TEST_FAILED_HR(FAILED(hr),
  170. "CreateBindCtx Item Moniker GetDisplayName failed!")
  171. hr = pmk2->GetDisplayName(pbc, NULL, &szName);
  172. pbc.Set(NULL);
  173. TEST_FAILED_HR(FAILED(hr), "Item Moniker GetDisplayName failed!");
  174. TEST_FAILED((wcscmp(szName, L"\\1") != 0), "Wrong path from item mon");
  175. // Free the path
  176. pIMalloc->Free(szName);
  177. hr = CreateItemMoniker(L"\\", L"2", &pmk3);
  178. TEST_FAILED_HR(FAILED(hr), "CreateItemMoniker 0 failed")
  179. hr = pmk3->Inverse(&pmk4);
  180. TEST_FAILED_HR(FAILED(hr), "Inverse of 0 failed")
  181. hr = CreateBindCtx(0, &pbc);
  182. TEST_FAILED_HR(FAILED(hr), "CreateBindCtx after inverse failed")
  183. hr = pmk4->GetDisplayName(pbc, NULL, &szName);
  184. TEST_FAILED_HR(FAILED(hr), "GetDisplayName on AntiMoniker failed")
  185. TEST_FAILED((memcmp(szName, L"\\..", sizeof(L"\\..")) != 0),
  186. "GetDisplayName on AntiMoniker name wrong\n")
  187. // Free memory API allocated.
  188. pIMalloc->Free(szName);
  189. // Release interfaces we are finished with
  190. LAST_RELEASE(pbc)
  191. LAST_RELEASE(pmk4)
  192. //
  193. // Test composition of file moniker & item moniker
  194. //
  195. hr = pmk1->ComposeWith(pmk2, FALSE, &pmk4);
  196. TEST_FAILED_HR(FAILED(hr), "ComposeWith failed")
  197. hr = CreateBindCtx(0, &pbc);
  198. TEST_FAILED_HR(FAILED(hr),
  199. "CreateBindCtx Composite Moniker GetDisplayName failed!")
  200. hr = pmk4->GetDisplayName(pbc, NULL, &szName);
  201. pbc.Set(NULL);
  202. TEST_FAILED_HR(FAILED(hr), "GetDisplayName on Composite moniker failed")
  203. // Free memory API allocated.
  204. pIMalloc->Free(szName);
  205. Sleep(10);
  206. hr = BindMoniker(pmk4, 0, IID_IUnknown, (LPVOID FAR*) &pUnk);
  207. TEST_FAILED_HR(FAILED(hr), "BindMoniker with composed moniker failed")
  208. TEST_FAILED((pUnk == NULL),
  209. "BindMoniker with composed moniker returned NULL punk\n")
  210. hr = pUnk->QueryInterface(IID_IOleObject, (LPVOID FAR*) &pObj);
  211. TEST_FAILED_HR(FAILED(hr), "QI to IID_IOleObject failed")
  212. TEST_FAILED((pObj == NULL),
  213. "pObj returned from QI invalid")
  214. hr = pmk6->ComposeWith(pmk3, FALSE, &pmk5);
  215. TEST_FAILED_HR(FAILED(hr), "ComposedWith of pmk6 failed")
  216. hr = BindMoniker(pmk5, 0, IID_IUnknown, (LPVOID FAR*) &pUnk1);
  217. TEST_FAILED_HR(FAILED(hr), "BindMoniker of pmk5 failed")
  218. hr = OleRun(pUnk1);
  219. TEST_FAILED_HR(FAILED(hr), "OleRun call failed")
  220. TEST_FAILED_HR(FAILED(hr), "GetObject Failed");
  221. // Clean up objects
  222. pObj.Set(NULL);
  223. LAST_RELEASE(pUnk1);
  224. LAST_RELEASE(pmk5);
  225. LAST_RELEASE(pUnk);
  226. LAST_RELEASE(pmk6);
  227. //
  228. // Test Marshal/Unmarshal Moniker
  229. //
  230. // Make a moniker to marshal
  231. hr = pmk4->ComposeWith(pmk3, FALSE, &pmk6);
  232. TEST_FAILED_HR(FAILED(hr), "Compose of moniker for marshal test failed");
  233. // Create a shared memory stream for the marshaled moniker
  234. hr = CreateStreamOnHGlobal(NULL, TRUE, &pStm);
  235. TEST_FAILED((FAILED(hr)), "CreateStreamOnHGlobal")
  236. // Marshal the interface into the stream
  237. hr = CoMarshalInterface(pStm, IID_IMoniker, pmk6, 0, NULL, MSHLFLAGS_NORMAL);
  238. TEST_FAILED_HR(FAILED(hr), "CoMarshalInterface failed")
  239. LISet32(large_int, 0);
  240. hr = pStm->Seek(large_int, STREAM_SEEK_SET, NULL);
  241. TEST_FAILED_HR(FAILED(hr), "Seek on shared stream failed")
  242. hr = CoUnmarshalInterface(pStm, IID_IMoniker, (LPVOID FAR*)&pmk5);
  243. TEST_FAILED_HR(FAILED(hr), "CoUnmarshalInterface failed")
  244. // Dump interfaces we are done with
  245. LAST_RELEASE(pmk6);
  246. LAST_RELEASE(pmk3);
  247. LAST_RELEASE(pmk4);
  248. LAST_RELEASE(pmk1);
  249. LAST_RELEASE(pmk2);
  250. LAST_RELEASE(pStm);
  251. LAST_RELEASE(pmk5);
  252. //
  253. // Test Moniker Composition
  254. //
  255. // BUGBUG: Check result
  256. hr = CreateFileMoniker(L"\\ole2\\test\\breadth\\servers\\ellipswt",
  257. &pmk1);
  258. TEST_FAILED_HR(FAILED(hr),
  259. "First CreateFileMoniker in composition test failed")
  260. hr = CreateFileMoniker(L"..\\..\\..\\dll\\sdemo1.exe",&pmk2);
  261. TEST_FAILED_HR(FAILED(hr),
  262. "Second CreateFileMoniker in composition test failed")
  263. hr = pmk1->ComposeWith(pmk2, FALSE, &pmk4);
  264. TEST_FAILED_HR(FAILED(hr), "ComposeWith of file monikers failed")
  265. // Dump interfaces we are done with
  266. LAST_RELEASE(pmk4);
  267. LAST_RELEASE(pmk1);
  268. LAST_RELEASE(pmk2);
  269. //
  270. // Testing file moniker CommonPrefixWith
  271. //
  272. // BUGBUG: Check result
  273. hr = CreateFileMoniker(L"\\Ole2\\Test\\Breadth\\Servers\\Ellipswt",
  274. &pmk1);
  275. TEST_FAILED_HR(FAILED(hr),
  276. "CommonPrefixWith First CreateFileMoniker failed")
  277. hr = CreateFileMoniker(
  278. L"\\ole2\\test\\breadth\\serverandthensome\\bar", &pmk2);
  279. TEST_FAILED_HR(FAILED(hr),
  280. "CommonPrefixWith second CreateFileMoniker failed")
  281. hr = pmk1->CommonPrefixWith(pmk2, &pmk4);
  282. TEST_FAILED_HR(FAILED(hr), "CommonPrefixWith failed")
  283. hr = CreateBindCtx(0, &pbc);
  284. TEST_FAILED_HR(FAILED(hr),
  285. "CreateBindCtx CommonPrefixWith GetDisplayName failed!")
  286. hr = pmk4->GetDisplayName(pbc, NULL, &szName);
  287. pbc.Set(NULL);
  288. TEST_FAILED_HR(FAILED(hr), "CommonPrefixWith: GetDisplayName failed!");
  289. TEST_FAILED((_wcsicmp(szName, L"\\ole2\\test\\breadth") != 0),
  290. "Common prefix with: Wrong Output Path\n");
  291. // Free the path
  292. pIMalloc->Free(szName);
  293. // Dump monikers we are done with
  294. LAST_RELEASE(pmk4);
  295. LAST_RELEASE(pmk2);
  296. LAST_RELEASE(pmk1);
  297. //
  298. // Testing file moniker RelativePathTo
  299. //
  300. // BUGBUG: Check result.
  301. hr = CreateFileMoniker(L"\\Ole2\\Test\\Breadth\\Servers\\Ellipswt",
  302. &pmk1);
  303. TEST_FAILED_HR(FAILED(hr), "RelativePathTo first CreateFileMoniker failed")
  304. hr = CreateFileMoniker(
  305. L"\\ole2\\test\\breadth\\serverandthensome\\bar", &pmk2);
  306. TEST_FAILED_HR(FAILED(hr),
  307. "RelativePathTo Second CreateFileMoniker failed")
  308. hr = pmk1->RelativePathTo(pmk2, &pmk4);
  309. TEST_FAILED_HR(FAILED(hr), "RelativePathTo failed")
  310. hr = CreateBindCtx(0, &pbc);
  311. TEST_FAILED_HR(FAILED(hr),
  312. "CreateBindCtx RelativePathTo GetDisplayName failed!")
  313. hr = pmk4->GetDisplayName(pbc, NULL, &szName);
  314. pbc.Set(NULL);
  315. TEST_FAILED_HR(FAILED(hr), "RelativePathTo: GetDisplayName failed!");
  316. TEST_FAILED((wcscmp(szName, L"..\\..\\serverandthensome\\bar") != 0),
  317. "RelativePathTo: Wrong Output Path");
  318. // Free the path
  319. pIMalloc->Free(szName);
  320. LAST_RELEASE(pmk2);
  321. LAST_RELEASE(pmk1);
  322. LAST_RELEASE(pmk4);
  323. //
  324. // Testing MkParseDisplayName
  325. //
  326. hr = CreateBindCtx(0, &pbc);
  327. TEST_FAILED_HR(FAILED(hr), "MkParseDisplayName CreatebindCtx failed")
  328. // make a path to the object
  329. WCHAR szBuf[256];
  330. int cPath1;
  331. cPath1 = wcslen(pszPath1);
  332. memcpy(szBuf, pszPath1, cPath1 * sizeof(WCHAR));
  333. memcpy(szBuf + cPath1, L"\\1", sizeof(L"\\1"));
  334. hr = MkParseDisplayName(pbc, szBuf, &chEaten, &pmk1);
  335. TEST_FAILED_HR(FAILED(hr), "MkParseDisplayName failed")
  336. LAST_RELEASE(pmk1);
  337. LAST_RELEASE(pbc);
  338. //
  339. // Test Moniker IsEqual function on equivalent paths
  340. // The moniker code should catch some forms of equivalent
  341. // paths, but doesn't handle all of them.
  342. //
  343. //
  344. hr = CreateFileMoniker(L"first",&pmk1);
  345. TEST_FAILED_HR(FAILED(hr),
  346. "First CreateFileMoniker in IsEqual test failed")
  347. hr = CreateFileMoniker(L".\\first",&pmk2);
  348. TEST_FAILED_HR(FAILED(hr),
  349. "Second CreateFileMoniker in IsEqual test failed")
  350. hr = CreateFileMoniker(L"..\\first",&pmk3);
  351. TEST_FAILED_HR(FAILED(hr),
  352. "Third CreateFileMoniker in IsEqual test failed")
  353. // This moniker variation has been disabled for Cairo
  354. // until the moniker code gets unified.
  355. #ifndef _CAIRO_
  356. hr = CreateFileMoniker(L"..\\.first",&pmk4);
  357. TEST_FAILED_HR(FAILED(hr),
  358. "Fourth CreateFileMoniker in IsEqual test failed")
  359. #endif
  360. hr = pmk1->IsEqual(pmk2);
  361. TEST_FAILED_HR((hr != S_OK), "pmk1->IsEqual(pmk2) failed")
  362. hr = pmk2->IsEqual(pmk3);
  363. TEST_FAILED_HR((hr != S_FALSE), "pmk2->IsEqual(pmk3) failed")
  364. #ifndef _CAIRO_
  365. hr = pmk3->IsEqual(pmk4);
  366. TEST_FAILED_HR((hr != S_FALSE), "pmk3->IsEqual(pmk4) failed")
  367. hr = pmk4->IsEqual(pmk4);
  368. TEST_FAILED_HR((hr != S_OK), "pmk4->IsEqual(pmk4) failed")
  369. #endif
  370. // Dump interfaces we are done with
  371. LAST_RELEASE(pmk1);
  372. LAST_RELEASE(pmk2);
  373. LAST_RELEASE(pmk3);
  374. #ifndef _CAIRO_
  375. LAST_RELEASE(pmk4);
  376. #endif
  377. //
  378. // Test IsRunning
  379. //
  380. // we make up a name based on the pid and an arbitrary string,
  381. // so that the name is unique to this process.
  382. WCHAR wszMkName[MAX_PATH];
  383. wcscpy(wszMkName, L"YourStockOptionsDependOnThis");
  384. wcscat(wszMkName, &wszPid[1]); // skip leading backslash
  385. hr = CreateFileMoniker(wszMkName, &pmk1);
  386. TEST_FAILED_HR(FAILED(hr),
  387. "First CreateFileMoniker in IsRunning failed")
  388. hr = CreateBindCtx(0, &pbc);
  389. TEST_FAILED_HR(FAILED(hr),
  390. "CreateBindCtx in IsRunning failed")
  391. //
  392. // We shouldn't find the moniker in the ROT
  393. //
  394. hr = pmk1->IsRunning(pbc,NULL,NULL);
  395. TEST_FAILED_HR((hr != S_FALSE),
  396. "IsRunning returns other than S_FALSE");
  397. //
  398. // The FileMoniker should ignore pmk1
  399. //
  400. hr = pmk1->IsRunning(pbc,pmk1,NULL);
  401. TEST_FAILED_HR((hr != S_FALSE),
  402. "IsRunning #2 returns other than S_FALSE");
  403. hr = GetRunningObjectTable(0, &prot);
  404. TEST_FAILED_HR(FAILED(hr),"IsRunning GetRunningObjectTable failed!");
  405. //
  406. // Just for kicks, we are going to register this moniker itself
  407. // as running. We needed an IUnknown pointer here, and the moniker
  408. // just happens to have one.
  409. //
  410. DWORD dwRegister;
  411. DWORD dwRegister2;
  412. hr = prot->Register(0,pmk1,pmk1,&dwRegister);
  413. TEST_FAILED_HR(FAILED(hr),
  414. "Register with ROT failed in IsRunning");
  415. //
  416. // We should find the moniker as running
  417. //
  418. hr = pmk1->IsRunning(pbc,NULL,NULL);
  419. TEST_FAILED_HR((hr != S_OK),
  420. "IsRunning returns other than S_OK");
  421. hr = prot->IsRunning(pmk1);
  422. TEST_FAILED_HR((hr != S_OK),
  423. "IsRunning returns other than S_OK");
  424. //
  425. // Register it again, and we should get notice that it is running
  426. //
  427. // This test the ROT, and also test the moniker comparision
  428. // functions
  429. //
  430. hr = prot->Register(0,pmk1,pmk1,&dwRegister2);
  431. TEST_FAILED_HR(hr != MK_S_MONIKERALREADYREGISTERED,
  432. "Register with ROT failed in IsRunning");
  433. hr = prot->IsRunning(pmk1);
  434. TEST_FAILED_HR((hr != S_OK),
  435. "IsRunning #1 has returned != S_OK");
  436. hr = prot->Revoke(dwRegister2);
  437. TEST_FAILED_HR(FAILED(hr),
  438. "Revoke dwRegister2 with ROT failed");
  439. hr = prot->Revoke(dwRegister2);
  440. TEST_FAILED_HR(hr == S_OK,
  441. "Revoke dwRegister2 with ROT should have failed");
  442. //
  443. // It is registered twice, it should still be there from the original
  444. // registration
  445. //
  446. hr = pmk1->IsRunning(pbc,NULL,NULL);
  447. TEST_FAILED_HR((hr != S_OK),
  448. "IsRunning #2 has returned != S_OK");
  449. //
  450. // Cram in a ItemMoniker to test its comparision stuff.
  451. //
  452. hr = CreateItemMoniker(L"!",L"KevinRo",&pmkItem1);
  453. TEST_FAILED_HR(FAILED(hr),
  454. "Creating Item Moniker KevinRo");
  455. hr = CreateItemMoniker(L"!",L"SueA",&pmkItem2);
  456. TEST_FAILED_HR(FAILED(hr),
  457. "Creating Item Moniker SueA");
  458. DWORD dwKevinRo;
  459. DWORD dwSueA;
  460. hr = prot->Register(0,pmkItem1,pmkItem1,&dwKevinRo);
  461. TEST_FAILED_HR(FAILED(hr),
  462. "Register KevinRo with ROT failed in IsRunning");
  463. hr = prot->Register(0,pmkItem2,pmkItem2,&dwSueA);
  464. TEST_FAILED_HR(FAILED(hr),
  465. "Register SueA with ROT failed in IsRunning");
  466. //
  467. // Now revoke monikers
  468. //
  469. hr = prot->Revoke(dwRegister);
  470. TEST_FAILED_HR(FAILED(hr),
  471. "Revoke with ROT failed in IsRunning");
  472. //
  473. // We shouldn't find the moniker in the ROT
  474. //
  475. hr = pmk1->IsRunning(pbc,NULL,NULL);
  476. TEST_FAILED_HR((hr != S_FALSE),
  477. "IsRunning returns other than S_FALSE");
  478. //
  479. // Now revoke the item monikers.
  480. //
  481. hr = prot->Revoke(dwKevinRo);
  482. TEST_FAILED_HR(FAILED(hr),
  483. "Revoke with ROT failed in for KevinRo");
  484. hr = prot->Revoke(dwSueA);
  485. TEST_FAILED_HR(FAILED(hr),
  486. "Revoke with ROT failed in for SueA");
  487. //
  488. // An AntiMoniker
  489. //
  490. hr = CreateAntiMoniker(&pmkAnti);
  491. TEST_FAILED_HR(FAILED(hr),
  492. "Failed creating AntiMoniker in Comparison Data Test");
  493. DWORD dwAnti;
  494. hr = prot->Register(0,pmkAnti,pmkAnti,&dwAnti);
  495. TEST_FAILED_HR(FAILED(hr),
  496. "Register Anti with ROT failed in IsRunning");
  497. hr = prot->IsRunning(pmkAnti);
  498. TEST_FAILED_HR((hr != S_OK),
  499. "IsRunning pmkAnti returns other than S_OK");
  500. //
  501. // Now revoke the 'other' monikers.
  502. //
  503. hr = prot->Revoke(dwAnti);
  504. TEST_FAILED_HR(FAILED(hr),
  505. "Revoke with ROT failed in for Anti");
  506. //
  507. // Test file monikers with long file names
  508. //
  509. // Creation
  510. hr = CreateFileMoniker(LongDirShort, &pmkLong1);
  511. TEST_FAILED_HR(FAILED(hr), "CreateFileMoniker for long short failed!")
  512. TEST_FAILED((pmkLong1 == NULL),
  513. "CreateFileMoniker returned a null moniker ptr\n")
  514. LAST_RELEASE(pmkLong1);
  515. // Equivalence with short name version
  516. hr = CreateFileMoniker(LongDirLong, &pmkLong1);
  517. TEST_FAILED_HR(FAILED(hr), "CreateFileMoniker for long long failed!")
  518. TEST_FAILED((pmkLong1 == NULL),
  519. "CreateFileMoniker returned a null moniker ptr\n")
  520. #if 0
  521. // Debug code to print out the display name to check that long
  522. // names are handled correctly
  523. hr = CreateBindCtx(0, &pbc);
  524. TEST_FAILED_HR(FAILED(hr),
  525. "CreateBindCtx File Moniker GetDisplayName failed!")
  526. hr = pmkLong1->GetDisplayName(pbc, NULL, &szName);
  527. // release it
  528. pbc.Set(NULL, FALSE);
  529. TEST_FAILED_HR(FAILED(hr), "File Moniker GetDisplayName failed!");
  530. wprintf(L"Display name: '%s', %d\n", szName, wcslen(szName));
  531. // Free the path
  532. pIMalloc->Free(szName);
  533. #endif
  534. hr = CreateFileMoniker(LongDirLongSe, &pmkLong2);
  535. TEST_FAILED_HR(FAILED(hr), "CreateFileMoniker for long long se failed!")
  536. TEST_FAILED((pmkLong2 == NULL),
  537. "CreateFileMoniker returned a null moniker ptr\n")
  538. TEST_FAILED(pmkLong1->IsEqual(pmkLong2) != S_OK,
  539. "Long file monikers not equal\n");
  540. #if 0
  541. // Debug code to print out the display name to check that long
  542. // names are handled correctly
  543. hr = CreateBindCtx(0, &pbc);
  544. TEST_FAILED_HR(FAILED(hr),
  545. "CreateBindCtx File Moniker GetDisplayName failed!")
  546. hr = pmkLong2->GetDisplayName(pbc, NULL, &szName);
  547. // release it
  548. pbc.Set(NULL, FALSE);
  549. TEST_FAILED_HR(FAILED(hr), "File Moniker GetDisplayName failed!");
  550. wprintf(L"Display name: '%s', %d\n", szName, wcslen(szName));
  551. // Free the path
  552. pIMalloc->Free(szName);
  553. #endif
  554. LAST_RELEASE(pmkLong1);
  555. LAST_RELEASE(pmkLong2);
  556. return FALSE;
  557. }