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.

943 lines
24 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: oleadv.cpp
  7. //
  8. // Contents: implementation of unit test for Ole Advise Holder
  9. //
  10. // Classes: CTestPretendMoniker
  11. // COaTestAdviseSink
  12. // COaTestObj
  13. //
  14. // Functions: NotifyOfChanges
  15. // TestSingleOleAdvise
  16. // TestMassOleAdvise
  17. // TestOleAdviseHolderEnumerator
  18. // LEOleAdviseHolderTest
  19. //
  20. // History: dd-mmm-yy Author Comment
  21. // 27-May-94 ricksa author
  22. //
  23. //--------------------------------------------------------------------------
  24. #include "oletest.h"
  25. #define MAX_OA_TO_REGISTER 100
  26. //+-------------------------------------------------------------------------
  27. //
  28. // Class: CTestPretendMoniker
  29. //
  30. // Purpose: Use where we need a moniker to confirm reciept of OnRename
  31. //
  32. // Interface: QueryInterface - get a new interface
  33. // AddRef - add a reference
  34. // Release - remove a reference
  35. // VerifySig - verify signiture is correct
  36. //
  37. // History: dd-mmm-yy Author Comment
  38. // 01-Jun-94 Ricksa Created
  39. //
  40. // Notes: This only supports IUnknown
  41. //
  42. //--------------------------------------------------------------------------
  43. class CTestPretendMoniker : public IUnknown
  44. {
  45. public:
  46. CTestPretendMoniker(void);
  47. // IUnknown methods
  48. HRESULT __stdcall QueryInterface(REFIID riid, LPVOID FAR* ppvObj);
  49. ULONG __stdcall AddRef(void);
  50. ULONG __stdcall Release(void);
  51. BOOL VerifySig(void);
  52. private:
  53. enum Sigs { SIG1 = 0x01020304, SIG2 = 0x04030201 };
  54. LONG _lRefs;
  55. Sigs _sig1;
  56. Sigs _sig2;
  57. };
  58. //+-------------------------------------------------------------------------
  59. //
  60. // Member: CTestPretendMoniker::CTestPretendMoniker
  61. //
  62. // Synopsis: Initialize object
  63. //
  64. // History: dd-mmm-yy Author Comment
  65. // 01-Jun-94 Ricksa Created
  66. //
  67. //--------------------------------------------------------------------------
  68. CTestPretendMoniker::CTestPretendMoniker(void)
  69. : _lRefs(0), _sig1(SIG1), _sig2(SIG2)
  70. {
  71. // Header does all the work
  72. }
  73. //+-------------------------------------------------------------------------
  74. //
  75. // Member: CTestPretendMoniker::VerifySig
  76. //
  77. // Synopsis: Verify signiture is as expected
  78. //
  79. // History: dd-mmm-yy Author Comment
  80. // 01-Jun-94 Ricksa Created
  81. //
  82. //--------------------------------------------------------------------------
  83. BOOL CTestPretendMoniker::VerifySig(void)
  84. {
  85. return (_sig1 == SIG1 && _sig2 == SIG2);
  86. }
  87. //+-------------------------------------------------------------------------
  88. //
  89. // Member: CTestPretendMoniker::QueryInterface
  90. //
  91. // Synopsis: Return a supported interface
  92. //
  93. // Arguments: [riid] - interface id requested
  94. // [ppvObj] - where to put the interface
  95. //
  96. // Returns: S_OK - we are returning an interface
  97. // E_NOINTERFACE - we do not support the requested interface
  98. //
  99. // History: dd-mmm-yy Author Comment
  100. // 01-Jun-94 Ricksa Created
  101. //
  102. //--------------------------------------------------------------------------
  103. HRESULT __stdcall CTestPretendMoniker::QueryInterface(
  104. REFIID riid,
  105. LPVOID *ppvObj)
  106. {
  107. if (IsEqualGUID(IID_IUnknown, riid) || IsEqualGUID(IID_IMoniker, riid))
  108. {
  109. AddRef();
  110. *ppvObj = this;
  111. return NOERROR;
  112. }
  113. *ppvObj = NULL;
  114. return E_NOINTERFACE;
  115. }
  116. //+-------------------------------------------------------------------------
  117. //
  118. // Member: CTestPretendMoniker::AddRef
  119. //
  120. // Synopsis: Bump reference count
  121. //
  122. // History: dd-mmm-yy Author Comment
  123. // 01-Jun-94 Ricksa Created
  124. //
  125. //--------------------------------------------------------------------------
  126. ULONG __stdcall CTestPretendMoniker::AddRef(void)
  127. {
  128. return _lRefs++;
  129. }
  130. //+-------------------------------------------------------------------------
  131. //
  132. // Member: CTestPretendMoniker::Release
  133. //
  134. // Synopsis: Decrement the reference count
  135. //
  136. // History: dd-mmm-yy Author Comment
  137. // 01-Jun-94 Ricksa Created
  138. //
  139. //--------------------------------------------------------------------------
  140. ULONG __stdcall CTestPretendMoniker::Release(void)
  141. {
  142. assert(_lRefs >= 1);
  143. return --_lRefs;
  144. }
  145. //+-------------------------------------------------------------------------
  146. //
  147. // Class: COaTestAdviseSink
  148. //
  149. // Purpose: Advise sink for use in testing the Ole Advise Holder
  150. //
  151. // Interface: QueryInterface - get supported interface pointer
  152. // AddRef - bump reference count
  153. // Release - decrement reference count
  154. // OnDataChange - not implemented
  155. // OnViewChange - not implemented
  156. // OnRename - rename notification
  157. // OnSave - save notification
  158. // OnClose - close notification
  159. // VerifyNotifications - verify all expected notifications arrived
  160. //
  161. // History: dd-mmm-yy Author Comment
  162. // 01-Jun-94 Ricksa Created
  163. //
  164. // Notes: We only support parts of advise sink we need to test the
  165. // advise holder.
  166. //
  167. //--------------------------------------------------------------------------
  168. class COaTestAdviseSink : public IAdviseSink
  169. {
  170. public:
  171. COaTestAdviseSink(void);
  172. // IUnknown methods
  173. HRESULT __stdcall QueryInterface(REFIID riid, LPVOID FAR* ppvObj);
  174. ULONG __stdcall AddRef(void);
  175. ULONG __stdcall Release(void);
  176. // IAdviseSink methods
  177. void __stdcall OnDataChange(FORMATETC *pFormatetc, STGMEDIUM *pStgmed);
  178. void __stdcall OnViewChange(
  179. DWORD dwAspect,
  180. LONG lindex);
  181. void __stdcall OnRename(IMoniker *pmk);
  182. void __stdcall OnSave(void);
  183. void __stdcall OnClose(void);
  184. // Test methods used for verification
  185. BOOL VerifyNotifications(void);
  186. private:
  187. LONG _lRefs;
  188. BOOL _fOnCloseNotify;
  189. BOOL _fOnSaveNotify;
  190. BOOL _fOnRenameNotify;
  191. };
  192. //+-------------------------------------------------------------------------
  193. //
  194. // Member: COaTestAdviseSink::COaTestAdviseSink
  195. //
  196. // Synopsis: Initialize advise sink
  197. //
  198. // History: dd-mmm-yy Author Comment
  199. // 01-Jun-94 Ricksa Created
  200. //
  201. //--------------------------------------------------------------------------
  202. COaTestAdviseSink::COaTestAdviseSink(void)
  203. : _lRefs(1), _fOnCloseNotify(FALSE), _fOnSaveNotify(FALSE),
  204. _fOnRenameNotify(FALSE)
  205. {
  206. // Header does all the work
  207. }
  208. //+-------------------------------------------------------------------------
  209. //
  210. // Member: COaTestAdviseSink::QueryInterface
  211. //
  212. // Synopsis: Return requested interface pointer
  213. //
  214. // Arguments: [riid] - interface id requested
  215. // [ppvObj] - where to put the interface
  216. //
  217. // Returns: S_OK - we are returning an interface
  218. // E_NOINTERFACE - we do not support the requested interface
  219. //
  220. // History: dd-mmm-yy Author Comment
  221. // 01-Jun-94 Ricksa Created
  222. //
  223. //--------------------------------------------------------------------------
  224. HRESULT __stdcall COaTestAdviseSink::QueryInterface(
  225. REFIID riid,
  226. LPVOID *ppvObj)
  227. {
  228. if (IsEqualGUID(IID_IUnknown, riid) || IsEqualGUID(IID_IAdviseSink, riid))
  229. {
  230. AddRef();
  231. *ppvObj = this;
  232. return NOERROR;
  233. }
  234. *ppvObj = NULL;
  235. return E_NOINTERFACE;
  236. }
  237. //+-------------------------------------------------------------------------
  238. //
  239. // Member: COaTestAdviseSink::AddRef
  240. //
  241. // Synopsis: Bump reference count
  242. //
  243. // History: dd-mmm-yy Author Comment
  244. // 01-Jun-94 Ricksa Created
  245. //
  246. //--------------------------------------------------------------------------
  247. ULONG __stdcall COaTestAdviseSink::AddRef(void)
  248. {
  249. return _lRefs++;
  250. }
  251. //+-------------------------------------------------------------------------
  252. //
  253. // Member: COaTestAdviseSink::Release
  254. //
  255. // Synopsis: Decrement reference count
  256. //
  257. // History: dd-mmm-yy Author Comment
  258. // 01-Jun-94 Ricksa Created
  259. //
  260. //--------------------------------------------------------------------------
  261. ULONG __stdcall COaTestAdviseSink::Release(void)
  262. {
  263. assert(_lRefs >= 1);
  264. return --_lRefs;
  265. }
  266. //+-------------------------------------------------------------------------
  267. //
  268. // Member: COaTestAdviseSink::OnDataChange
  269. //
  270. // Synopsis: Notify of change in data
  271. //
  272. // Arguments: [pFormatetc] - FORMATETC of data
  273. // [pStgmed] - storage medium for data
  274. //
  275. // History: dd-mmm-yy Author Comment
  276. // 01-Jun-94 Ricksa Created
  277. //
  278. // Notes: Not supported for this object
  279. //
  280. //--------------------------------------------------------------------------
  281. void __stdcall COaTestAdviseSink::OnDataChange(
  282. FORMATETC *pFormatetc,
  283. STGMEDIUM *pStgmed)
  284. {
  285. OutputString("COaTestAdviseSink::OnDataChange Unexpectedly Called!\r\n");
  286. }
  287. //+-------------------------------------------------------------------------
  288. //
  289. // Member: COaTestAdviseSink::OnViewChange
  290. //
  291. // Synopsis: Notify that view should change
  292. //
  293. // Arguments: [dwAspect] - specifies view of the object
  294. // [lindex] - which piece of view changed
  295. //
  296. // History: dd-mmm-yy Author Comment
  297. // 01-Jun-94 Ricksa Created
  298. //
  299. // Notes: Not supported for this object
  300. //
  301. //--------------------------------------------------------------------------
  302. void __stdcall COaTestAdviseSink::OnViewChange(
  303. DWORD dwAspect,
  304. LONG lindex)
  305. {
  306. OutputString("COaTestAdviseSink::OnViewChange Unexpectedly Called!\r\n");
  307. }
  308. //+-------------------------------------------------------------------------
  309. //
  310. // Member: COaTestAdviseSink::OnRename
  311. //
  312. // Synopsis: Notifies of rename operation
  313. //
  314. // Arguments: [pmk] - new full name of the object
  315. //
  316. // History: dd-mmm-yy Author Comment
  317. // 01-Jun-94 Ricksa Created
  318. //
  319. //--------------------------------------------------------------------------
  320. void __stdcall COaTestAdviseSink::OnRename(IMoniker *pmk)
  321. {
  322. // Verify that we get the pretend moniker
  323. CTestPretendMoniker *ptpm = (CTestPretendMoniker *) pmk;
  324. if (ptpm->VerifySig())
  325. {
  326. _fOnCloseNotify = TRUE;
  327. }
  328. else
  329. {
  330. OutputString("OnRename got a bad moniker\r\n");
  331. }
  332. }
  333. //+-------------------------------------------------------------------------
  334. //
  335. // Member: COaTestAdviseSink::OnSave
  336. //
  337. // Synopsis: Notifies that object has been saved
  338. //
  339. // History: dd-mmm-yy Author Comment
  340. // 01-Jun-94 Ricksa Created
  341. //
  342. //--------------------------------------------------------------------------
  343. void __stdcall COaTestAdviseSink::OnSave(void)
  344. {
  345. _fOnSaveNotify = TRUE;
  346. }
  347. //+-------------------------------------------------------------------------
  348. //
  349. // Member: COaTestAdviseSink::OnClose
  350. //
  351. // Synopsis: Notifies that object has been closed
  352. //
  353. // History: dd-mmm-yy Author Comment
  354. // 01-Jun-94 Ricksa Created
  355. //
  356. //--------------------------------------------------------------------------
  357. void __stdcall COaTestAdviseSink::OnClose(void)
  358. {
  359. _fOnRenameNotify = TRUE;
  360. }
  361. //+-------------------------------------------------------------------------
  362. //
  363. // Member: COaTestAdviseSink::VerifyNotifications
  364. //
  365. // Synopsis: Verify that we recieved expected notifications
  366. //
  367. // Returns: TRUE - we recieved expected notification
  368. // FALSE - we didn't receive expected notifications
  369. //
  370. // History: dd-mmm-yy Author Comment
  371. // 01-Jun-94 Ricksa Created
  372. //
  373. // Notes: This resets the values after returning the result
  374. //
  375. //--------------------------------------------------------------------------
  376. BOOL COaTestAdviseSink::VerifyNotifications(void)
  377. {
  378. // Save the result of all the notifications
  379. BOOL fResult = _fOnCloseNotify && _fOnSaveNotify && _fOnRenameNotify;
  380. // Reset the notifications
  381. _fOnCloseNotify = FALSE;
  382. _fOnSaveNotify = FALSE;
  383. _fOnRenameNotify = FALSE;
  384. // Let caller know the result of the notifications
  385. return fResult;
  386. }
  387. //+-------------------------------------------------------------------------
  388. //
  389. // Class: COaTestObj
  390. //
  391. // Purpose: Provides place to keep information related to an advise
  392. //
  393. // Interface: Register - register advise with holder
  394. // VerifyNotified - verify that object was notified by holder
  395. // Revoke - revoke registration with holder
  396. //
  397. // History: dd-mmm-yy Author Comment
  398. // 01-Jun-94 Ricksa Created
  399. //
  400. // Notes:
  401. //
  402. //--------------------------------------------------------------------------
  403. class COaTestObj
  404. {
  405. public:
  406. COaTestObj(void);
  407. HRESULT Register(IOleAdviseHolder *poah, char *pszCaller);
  408. HRESULT VerifyNotified(void);
  409. HRESULT Revoke(void);
  410. private:
  411. COaTestAdviseSink _otas;
  412. DWORD _dwConnection;
  413. IOleAdviseHolder * _poah;
  414. char * _pszTest;
  415. };
  416. //+-------------------------------------------------------------------------
  417. //
  418. // Member: COaTestObj::COaTestObj
  419. //
  420. // Synopsis: Initialize object
  421. //
  422. // History: dd-mmm-yy Author Comment
  423. // 01-Jun-94 Ricksa Created
  424. //
  425. //--------------------------------------------------------------------------
  426. COaTestObj::COaTestObj(void) : _dwConnection(0)
  427. {
  428. // Header does all the work
  429. }
  430. //+-------------------------------------------------------------------------
  431. //
  432. // Member: COaTestObj::Register
  433. //
  434. // Synopsis: Register advise with the holder
  435. //
  436. // Arguments: [poah] - pointer to the advise holder
  437. // [pszTest] - name of the test
  438. //
  439. // Returns: S_OK - registration was successful
  440. // E_FAIL - registration failed
  441. //
  442. // History: dd-mmm-yy Author Comment
  443. // 01-Jun-94 Ricksa Created
  444. //
  445. //--------------------------------------------------------------------------
  446. HRESULT COaTestObj::Register(IOleAdviseHolder *poah, char *pszTest)
  447. {
  448. // Register the advise
  449. HRESULT hr = poah->Advise(&_otas, &_dwConnection);
  450. // Make sure results are sensible
  451. if (hr != NOERROR)
  452. {
  453. OutputString("%s Registration failed hr = %lx\r\n", pszTest, hr);
  454. return E_FAIL;
  455. }
  456. if (_dwConnection == 0)
  457. {
  458. OutputString("%s Connection not updated\r\n", pszTest);
  459. return E_FAIL;
  460. }
  461. // Save these for the revoke
  462. _pszTest = pszTest;
  463. _poah = poah;
  464. return NOERROR;
  465. }
  466. //+-------------------------------------------------------------------------
  467. //
  468. // Member: COaTestObj::VerifyNotified
  469. //
  470. // Synopsis: Verify that our advise was notified of changes
  471. //
  472. // Returns: S_OK - advise was notified of changes
  473. // E_FAIL - object was not notified.
  474. //
  475. // History: dd-mmm-yy Author Comment
  476. // 01-Jun-94 Ricksa Created
  477. //
  478. //--------------------------------------------------------------------------
  479. HRESULT COaTestObj::VerifyNotified(void)
  480. {
  481. if (!_otas.VerifyNotifications())
  482. {
  483. OutputString("%s Object not correctly notified\r\n", _pszTest);
  484. return E_FAIL;
  485. }
  486. return NOERROR;
  487. }
  488. //+-------------------------------------------------------------------------
  489. //
  490. // Member: COaTestObj::Revoke
  491. //
  492. // Synopsis: Revoke our advise registration with advise holder
  493. //
  494. // Returns: S_OK - advise was successfully deregistered
  495. // E_FAIL - revokation experience unexpected result
  496. //
  497. // History: dd-mmm-yy Author Comment
  498. // 01-Jun-94 Ricksa Created
  499. //
  500. //--------------------------------------------------------------------------
  501. HRESULT COaTestObj::Revoke(void)
  502. {
  503. // Remove the advise registration
  504. HRESULT hr = _poah->Unadvise(_dwConnection);
  505. if (hr != NOERROR)
  506. {
  507. OutputString("%s Revoke failed hr = %lx\r\n", _pszTest, hr);
  508. return E_FAIL;
  509. }
  510. // Try the unadvise one more time to make sure it took
  511. hr = _poah->Unadvise(_dwConnection);
  512. if (hr != OLE_E_NOCONNECTION)
  513. {
  514. OutputString("%s Second revoke bad hr = %lx\r\n", _pszTest, hr);
  515. return E_FAIL;
  516. }
  517. return NOERROR;
  518. }
  519. //+-------------------------------------------------------------------------
  520. //
  521. // Function: NotifyOfChanges
  522. //
  523. // Synopsis: Run through list of possible notifications for advise
  524. //
  525. // Arguments: [poahForTest] - advise holder we are testing
  526. // [pszTest] - test description
  527. //
  528. // Returns: NOERROR - all notifications reported success
  529. // Any Other - error occurred during notification
  530. //
  531. // History: dd-mmm-yy Author Comment
  532. // 01-Jun-94 Ricksa Created
  533. //
  534. // Notes: We currently only do the public notifications
  535. //
  536. //--------------------------------------------------------------------------
  537. HRESULT NotifyOfChanges(IOleAdviseHolder *poahForTest, char *pszTest)
  538. {
  539. // Notify Renamed
  540. CTestPretendMoniker tpm;
  541. HRESULT hr = poahForTest->SendOnRename((IMoniker *) &tpm);
  542. if (hr != NOERROR)
  543. {
  544. OutputString("%s SendOnRename failed hr = %lx\r\n", pszTest);
  545. return hr;
  546. }
  547. // Notify of save
  548. hr = poahForTest->SendOnSave();
  549. if (hr != NOERROR)
  550. {
  551. OutputString("%s SendOnSave failed hr = %lx\r\n", pszTest);
  552. return hr;
  553. }
  554. // Notify of close
  555. hr = poahForTest->SendOnClose();
  556. if (hr != NOERROR)
  557. {
  558. OutputString("%s SendOnClose failed hr = %lx\r\n", pszTest);
  559. return hr;
  560. }
  561. return NOERROR;
  562. }
  563. //+-------------------------------------------------------------------------
  564. //
  565. // Function: TestSingleOleAdvise
  566. //
  567. // Synopsis: Test advise holder with only a single advise
  568. //
  569. // Arguments: [poahForTest] - advise holder we are testing
  570. //
  571. // Returns: NOERROR - test was successfully passed
  572. // Any Other - test failed
  573. //
  574. // Algorithm: Create a test object. Register that test object with the
  575. // advise holder. Tell adviser holder to notify all its objects
  576. // of changes. Verify that test object was notified. Revoke
  577. // the registration of the test object with the advise holder.
  578. //
  579. // History: dd-mmm-yy Author Comment
  580. // 01-Jun-94 Ricksa Created
  581. //
  582. //--------------------------------------------------------------------------
  583. HRESULT TestSingleOleAdvise(IOleAdviseHolder *poahForTest)
  584. {
  585. char *pszTest = "TestSingleOleAdvise";
  586. COaTestObj oto;
  587. // Register a single advise
  588. HRESULT hr = oto.Register(poahForTest, pszTest);
  589. if (hr != NOERROR)
  590. {
  591. return hr;
  592. }
  593. // Notifiy it of changes
  594. hr = NotifyOfChanges(poahForTest, pszTest);
  595. if (hr != NOERROR)
  596. {
  597. return hr;
  598. }
  599. // Verify that notifications occurred
  600. hr = oto.VerifyNotified();
  601. if (hr != NOERROR)
  602. {
  603. return hr;
  604. }
  605. // Revoke all advises
  606. return oto.Revoke();
  607. }
  608. //+-------------------------------------------------------------------------
  609. //
  610. // Function: TestMassOleAdvise
  611. //
  612. // Synopsis: Test registering a very large number of advises
  613. //
  614. // Arguments: [poahForTest] - advise holder we are testing
  615. //
  616. // Returns: NOERROR - test was successfully passed
  617. // Any Other - test failed
  618. //
  619. // Algorithm: Create a large number of test objects. Then register all
  620. // those with the advise holder for changes. Tell advise holder
  621. // to notify all its registered objects of changes. Verify that
  622. // each of the test objects recieved a notification. Finally,
  623. // revoke all the test object registrations.
  624. //
  625. // History: dd-mmm-yy Author Comment
  626. // 01-Jun-94 Ricksa Created
  627. //
  628. //--------------------------------------------------------------------------
  629. HRESULT TestMassOleAdvise(IOleAdviseHolder *poahForTest)
  630. {
  631. char *pszTest = "TestMassOleAdviseHolder";
  632. // Create a large number of advises
  633. COaTestObj aoto[MAX_OA_TO_REGISTER];
  634. HRESULT hr;
  635. // Register all the advises
  636. for (int i = 0; i < MAX_OA_TO_REGISTER; i++)
  637. {
  638. hr = aoto[i].Register(poahForTest, pszTest);
  639. if (hr != NOERROR)
  640. {
  641. OutputString("%s Failed on Loop %d\r\n", pszTest, i);
  642. return hr;
  643. }
  644. }
  645. // Notify all the advises of changes
  646. hr = NotifyOfChanges(poahForTest, pszTest);
  647. if (hr != NOERROR)
  648. {
  649. return hr;
  650. }
  651. // Verify all objects were notified
  652. for (i = 0; i < MAX_OA_TO_REGISTER; i++)
  653. {
  654. hr = aoto[i].VerifyNotified();
  655. if (hr != NOERROR)
  656. {
  657. OutputString("%s Failed on Loop %d\r\n", pszTest, i);
  658. return hr;
  659. }
  660. }
  661. // Revoke all registrations
  662. for (i = 0; i < MAX_OA_TO_REGISTER; i++)
  663. {
  664. hr = aoto[i].Revoke();
  665. if (hr != NOERROR)
  666. {
  667. OutputString("%s Failed on Loop %d\r\n", pszTest, i);
  668. return hr;
  669. }
  670. }
  671. return NOERROR;
  672. }
  673. //+-------------------------------------------------------------------------
  674. //
  675. // Function: TestOleAdviseHolderEnumerator
  676. //
  677. // Synopsis: Test the OLE Advise Holder enumerator
  678. //
  679. // Arguments: [poahForTest] - OLE advise holder we are testing
  680. //
  681. // Returns: NOERROR - test passed
  682. // Any Other - test failed
  683. //
  684. // History: dd-mmm-yy Author Comment
  685. // 01-Jun-94 Ricksa Created
  686. //
  687. // Notes: We currently just verify that the enumerator is not implemented
  688. //
  689. //--------------------------------------------------------------------------
  690. HRESULT TestOleAdviseHolderEnumerator(IOleAdviseHolder *poahForTest)
  691. {
  692. char *pszCaller = "TestOleAdviseHolderEnumerator";
  693. // Confirm no enumerator
  694. IEnumSTATDATA *penumAdvise;
  695. HRESULT hr = poahForTest->EnumAdvise(&penumAdvise);
  696. if (hr != E_NOTIMPL)
  697. {
  698. OutputString("%s EnumAdvise Hresult = %lx\r\n", pszCaller, hr);
  699. return E_FAIL;
  700. }
  701. if (penumAdvise != NULL)
  702. {
  703. OutputString("%s EnumAdvise returned advise not NULL\r\n", pszCaller);
  704. return E_FAIL;
  705. }
  706. return NOERROR;
  707. }
  708. //+-------------------------------------------------------------------------
  709. //
  710. // Function: LEOleAdviseHolderTest
  711. //
  712. // Synopsis: Unit test for advise holders
  713. //
  714. // Returns: NOERROR - test passed
  715. // Any Other - test failed
  716. //
  717. // Algorithm: First we verify that a large number of verification work. Then
  718. // we verify that a large number of registrations work. Finally,
  719. // we verify that the enumerator for the OLE advise holder
  720. // behaves as expected.
  721. //
  722. // History: dd-mmm-yy Author Comment
  723. // 01-Jun-94 Ricksa Created
  724. //
  725. //--------------------------------------------------------------------------
  726. HRESULT LEOleAdviseHolderTest(void)
  727. {
  728. IOleAdviseHolder *poahForTest;
  729. HRESULT hr = CreateOleAdviseHolder(&poahForTest);
  730. // Test a single registration
  731. if ((hr = TestSingleOleAdvise(poahForTest)) != NOERROR)
  732. {
  733. return hr;
  734. }
  735. // Test a large number of registrations
  736. if ((hr = TestMassOleAdvise(poahForTest)) != NOERROR)
  737. {
  738. return hr;
  739. }
  740. // Test Enumerator
  741. if ((hr = TestOleAdviseHolderEnumerator(poahForTest)) != NOERROR)
  742. {
  743. return hr;
  744. }
  745. // Release the advise holder
  746. DWORD dwFinalRefs = poahForTest->Release();
  747. if (dwFinalRefs != 0)
  748. {
  749. OutputString(
  750. "LEOleAdviseHolderTest Final Release is = %d", dwFinalRefs);
  751. return E_FAIL;
  752. }
  753. return NOERROR;
  754. }