mssign32: Add a trailing '\n' to a few FIXME() messages.
[wine/multimedia.git] / dlls / ole32 / tests / ole2.c
blob6641683dede362e7861351113511f01b35b003cf
1 /*
2 * Object Linking and Embedding Tests
4 * Copyright 2005 Robert Shearman
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
22 #define CONST_VTABLE
23 #define WIN32_LEAN_AND_MEAN
25 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "objbase.h"
30 #include "shlguid.h"
32 #include "wine/test.h"
34 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
36 static IPersistStorage OleObjectPersistStg;
37 static IOleCache *cache;
38 static IRunnableObject *runnable;
40 static const CLSID CLSID_WineTest =
41 { /* 9474ba1a-258b-490b-bc13-516e9239ace0 */
42 0x9474ba1a,
43 0x258b,
44 0x490b,
45 {0xbc, 0x13, 0x51, 0x6e, 0x92, 0x39, 0xac, 0xe0}
48 static const IID IID_WineTest =
49 { /* 9474ba1a-258b-490b-bc13-516e9239ace1 */
50 0x9474ba1a,
51 0x258b,
52 0x490b,
53 {0xbc, 0x13, 0x51, 0x6e, 0x92, 0x39, 0xac, 0xe1}
56 #define TEST_OPTIONAL 0x1
57 #define TEST_TODO 0x2
59 struct expected_method
61 const char *method;
62 unsigned int flags;
65 static const struct expected_method *expected_method_list;
66 static FORMATETC *g_expected_fetc = NULL;
68 static BOOL g_showRunnable = TRUE;
69 static BOOL g_isRunning = TRUE;
70 static BOOL g_failGetMiscStatus;
71 static HRESULT g_QIFailsWith;
73 static UINT cf_test_1, cf_test_2, cf_test_3;
75 #define CHECK_EXPECTED_METHOD(method_name) \
76 do { \
77 trace("%s\n", method_name); \
78 ok(expected_method_list->method != NULL, "Extra method %s called\n", method_name); \
79 if (!strcmp(expected_method_list->method, "WINE_EXTRA")) \
80 { \
81 todo_wine ok(0, "Too many method calls.\n"); \
82 break; \
83 } \
84 if (expected_method_list->method) \
85 { \
86 while (expected_method_list->flags & TEST_OPTIONAL && \
87 strcmp(expected_method_list->method, method_name) != 0) \
88 expected_method_list++; \
89 if (expected_method_list->flags & TEST_TODO) \
90 todo_wine \
91 ok(!strcmp(expected_method_list->method, method_name), \
92 "Expected %s to be called instead of %s\n", \
93 expected_method_list->method, method_name); \
94 else \
95 ok(!strcmp(expected_method_list->method, method_name), \
96 "Expected %s to be called instead of %s\n", \
97 expected_method_list->method, method_name); \
98 expected_method_list++; \
99 } \
100 } while(0)
102 #define CHECK_NO_EXTRA_METHODS() \
103 do { \
104 while (expected_method_list->flags & TEST_OPTIONAL) \
105 expected_method_list++; \
106 ok(!expected_method_list->method, "Method sequence starting from %s not called\n", expected_method_list->method); \
107 } while (0)
109 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
111 CHECK_EXPECTED_METHOD("OleObject_QueryInterface");
113 *ppv = NULL;
115 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IOleObject))
116 *ppv = iface;
117 else if (IsEqualIID(riid, &IID_IPersistStorage))
118 *ppv = &OleObjectPersistStg;
119 else if (IsEqualIID(riid, &IID_IOleCache))
120 *ppv = cache;
121 else if (IsEqualIID(riid, &IID_IRunnableObject) && g_showRunnable)
122 *ppv = runnable;
123 else if (IsEqualIID(riid, &IID_WineTest))
124 return g_QIFailsWith;
126 if(*ppv) {
127 IUnknown_AddRef((IUnknown*)*ppv);
128 return S_OK;
131 trace("OleObject_QueryInterface: returning E_NOINTERFACE\n");
132 return E_NOINTERFACE;
135 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
137 CHECK_EXPECTED_METHOD("OleObject_AddRef");
138 return 2;
141 static ULONG WINAPI OleObject_Release(IOleObject *iface)
143 CHECK_EXPECTED_METHOD("OleObject_Release");
144 return 1;
147 static HRESULT WINAPI OleObject_SetClientSite
149 IOleObject *iface,
150 IOleClientSite *pClientSite
153 CHECK_EXPECTED_METHOD("OleObject_SetClientSite");
154 return S_OK;
157 static HRESULT WINAPI OleObject_GetClientSite
159 IOleObject *iface,
160 IOleClientSite **ppClientSite
163 CHECK_EXPECTED_METHOD("OleObject_GetClientSite");
164 return E_NOTIMPL;
167 static HRESULT WINAPI OleObject_SetHostNames
169 IOleObject *iface,
170 LPCOLESTR szContainerApp,
171 LPCOLESTR szContainerObj
174 CHECK_EXPECTED_METHOD("OleObject_SetHostNames");
175 return S_OK;
178 static HRESULT WINAPI OleObject_Close
180 IOleObject *iface,
181 DWORD dwSaveOption
184 CHECK_EXPECTED_METHOD("OleObject_Close");
185 return S_OK;
188 static HRESULT WINAPI OleObject_SetMoniker
190 IOleObject *iface,
191 DWORD dwWhichMoniker,
192 IMoniker *pmk
195 CHECK_EXPECTED_METHOD("OleObject_SetMoniker");
196 return S_OK;
199 static HRESULT WINAPI OleObject_GetMoniker
201 IOleObject *iface,
202 DWORD dwAssign,
203 DWORD dwWhichMoniker,
204 IMoniker **ppmk
207 CHECK_EXPECTED_METHOD("OleObject_GetMoniker");
208 return S_OK;
211 static HRESULT WINAPI OleObject_InitFromData
213 IOleObject *iface,
214 IDataObject *pDataObject,
215 BOOL fCreation,
216 DWORD dwReserved
219 CHECK_EXPECTED_METHOD("OleObject_InitFromData");
220 return S_OK;
223 static HRESULT WINAPI OleObject_GetClipboardData
225 IOleObject *iface,
226 DWORD dwReserved,
227 IDataObject **ppDataObject
230 CHECK_EXPECTED_METHOD("OleObject_GetClipboardData");
231 return E_NOTIMPL;
234 static HRESULT WINAPI OleObject_DoVerb
236 IOleObject *iface,
237 LONG iVerb,
238 LPMSG lpmsg,
239 IOleClientSite *pActiveSite,
240 LONG lindex,
241 HWND hwndParent,
242 LPCRECT lprcPosRect
245 CHECK_EXPECTED_METHOD("OleObject_DoVerb");
246 return S_OK;
249 static HRESULT WINAPI OleObject_EnumVerbs
251 IOleObject *iface,
252 IEnumOLEVERB **ppEnumOleVerb
255 CHECK_EXPECTED_METHOD("OleObject_EnumVerbs");
256 return E_NOTIMPL;
259 static HRESULT WINAPI OleObject_Update
261 IOleObject *iface
264 CHECK_EXPECTED_METHOD("OleObject_Update");
265 return S_OK;
268 static HRESULT WINAPI OleObject_IsUpToDate
270 IOleObject *iface
273 CHECK_EXPECTED_METHOD("OleObject_IsUpToDate");
274 return S_OK;
277 static HRESULT WINAPI OleObject_GetUserClassID
279 IOleObject *iface,
280 CLSID *pClsid
283 CHECK_EXPECTED_METHOD("OleObject_GetUserClassID");
284 return E_NOTIMPL;
287 static HRESULT WINAPI OleObject_GetUserType
289 IOleObject *iface,
290 DWORD dwFormOfType,
291 LPOLESTR *pszUserType
294 CHECK_EXPECTED_METHOD("OleObject_GetUserType");
295 return E_NOTIMPL;
298 static HRESULT WINAPI OleObject_SetExtent
300 IOleObject *iface,
301 DWORD dwDrawAspect,
302 SIZEL *psizel
305 CHECK_EXPECTED_METHOD("OleObject_SetExtent");
306 return S_OK;
309 static HRESULT WINAPI OleObject_GetExtent
311 IOleObject *iface,
312 DWORD dwDrawAspect,
313 SIZEL *psizel
316 CHECK_EXPECTED_METHOD("OleObject_GetExtent");
317 return E_NOTIMPL;
320 static HRESULT WINAPI OleObject_Advise
322 IOleObject *iface,
323 IAdviseSink *pAdvSink,
324 DWORD *pdwConnection
327 CHECK_EXPECTED_METHOD("OleObject_Advise");
328 return S_OK;
331 static HRESULT WINAPI OleObject_Unadvise
333 IOleObject *iface,
334 DWORD dwConnection
337 CHECK_EXPECTED_METHOD("OleObject_Unadvise");
338 return S_OK;
341 static HRESULT WINAPI OleObject_EnumAdvise
343 IOleObject *iface,
344 IEnumSTATDATA **ppenumAdvise
347 CHECK_EXPECTED_METHOD("OleObject_EnumAdvise");
348 return E_NOTIMPL;
351 static HRESULT WINAPI OleObject_GetMiscStatus
353 IOleObject *iface,
354 DWORD dwAspect,
355 DWORD *pdwStatus
358 CHECK_EXPECTED_METHOD("OleObject_GetMiscStatus");
359 if(!g_failGetMiscStatus)
361 *pdwStatus = OLEMISC_RECOMPOSEONRESIZE;
362 return S_OK;
364 else
366 *pdwStatus = 0x1234;
367 return E_FAIL;
371 static HRESULT WINAPI OleObject_SetColorScheme
373 IOleObject *iface,
374 LOGPALETTE *pLogpal
377 CHECK_EXPECTED_METHOD("OleObject_SetColorScheme");
378 return E_NOTIMPL;
381 static const IOleObjectVtbl OleObjectVtbl =
383 OleObject_QueryInterface,
384 OleObject_AddRef,
385 OleObject_Release,
386 OleObject_SetClientSite,
387 OleObject_GetClientSite,
388 OleObject_SetHostNames,
389 OleObject_Close,
390 OleObject_SetMoniker,
391 OleObject_GetMoniker,
392 OleObject_InitFromData,
393 OleObject_GetClipboardData,
394 OleObject_DoVerb,
395 OleObject_EnumVerbs,
396 OleObject_Update,
397 OleObject_IsUpToDate,
398 OleObject_GetUserClassID,
399 OleObject_GetUserType,
400 OleObject_SetExtent,
401 OleObject_GetExtent,
402 OleObject_Advise,
403 OleObject_Unadvise,
404 OleObject_EnumAdvise,
405 OleObject_GetMiscStatus,
406 OleObject_SetColorScheme
409 static IOleObject OleObject = { &OleObjectVtbl };
411 static HRESULT WINAPI OleObjectPersistStg_QueryInterface(IPersistStorage *iface, REFIID riid, void **ppv)
413 trace("OleObjectPersistStg_QueryInterface\n");
414 return IUnknown_QueryInterface((IUnknown *)&OleObject, riid, ppv);
417 static ULONG WINAPI OleObjectPersistStg_AddRef(IPersistStorage *iface)
419 CHECK_EXPECTED_METHOD("OleObjectPersistStg_AddRef");
420 return 2;
423 static ULONG WINAPI OleObjectPersistStg_Release(IPersistStorage *iface)
425 CHECK_EXPECTED_METHOD("OleObjectPersistStg_Release");
426 return 1;
429 static HRESULT WINAPI OleObjectPersistStg_GetClassId(IPersistStorage *iface, CLSID *clsid)
431 CHECK_EXPECTED_METHOD("OleObjectPersistStg_GetClassId");
432 return E_NOTIMPL;
435 static HRESULT WINAPI OleObjectPersistStg_IsDirty
437 IPersistStorage *iface
440 CHECK_EXPECTED_METHOD("OleObjectPersistStg_IsDirty");
441 return S_OK;
444 static HRESULT WINAPI OleObjectPersistStg_InitNew
446 IPersistStorage *iface,
447 IStorage *pStg
450 CHECK_EXPECTED_METHOD("OleObjectPersistStg_InitNew");
451 return S_OK;
454 static HRESULT WINAPI OleObjectPersistStg_Load
456 IPersistStorage *iface,
457 IStorage *pStg
460 CHECK_EXPECTED_METHOD("OleObjectPersistStg_Load");
461 return S_OK;
464 static HRESULT WINAPI OleObjectPersistStg_Save
466 IPersistStorage *iface,
467 IStorage *pStgSave,
468 BOOL fSameAsLoad
471 CHECK_EXPECTED_METHOD("OleObjectPersistStg_Save");
472 return S_OK;
475 static HRESULT WINAPI OleObjectPersistStg_SaveCompleted
477 IPersistStorage *iface,
478 IStorage *pStgNew
481 CHECK_EXPECTED_METHOD("OleObjectPersistStg_SaveCompleted");
482 return S_OK;
485 static HRESULT WINAPI OleObjectPersistStg_HandsOffStorage
487 IPersistStorage *iface
490 CHECK_EXPECTED_METHOD("OleObjectPersistStg_HandsOffStorage");
491 return S_OK;
494 static const IPersistStorageVtbl OleObjectPersistStgVtbl =
496 OleObjectPersistStg_QueryInterface,
497 OleObjectPersistStg_AddRef,
498 OleObjectPersistStg_Release,
499 OleObjectPersistStg_GetClassId,
500 OleObjectPersistStg_IsDirty,
501 OleObjectPersistStg_InitNew,
502 OleObjectPersistStg_Load,
503 OleObjectPersistStg_Save,
504 OleObjectPersistStg_SaveCompleted,
505 OleObjectPersistStg_HandsOffStorage
508 static IPersistStorage OleObjectPersistStg = { &OleObjectPersistStgVtbl };
510 static HRESULT WINAPI OleObjectCache_QueryInterface(IOleCache *iface, REFIID riid, void **ppv)
512 return IUnknown_QueryInterface((IUnknown *)&OleObject, riid, ppv);
515 static ULONG WINAPI OleObjectCache_AddRef(IOleCache *iface)
517 CHECK_EXPECTED_METHOD("OleObjectCache_AddRef");
518 return 2;
521 static ULONG WINAPI OleObjectCache_Release(IOleCache *iface)
523 CHECK_EXPECTED_METHOD("OleObjectCache_Release");
524 return 1;
527 static HRESULT WINAPI OleObjectCache_Cache
529 IOleCache *iface,
530 FORMATETC *pformatetc,
531 DWORD advf,
532 DWORD *pdwConnection
535 CHECK_EXPECTED_METHOD("OleObjectCache_Cache");
536 if (g_expected_fetc) {
537 ok(pformatetc != NULL, "pformatetc should not be NULL\n");
538 if (pformatetc) {
539 ok(pformatetc->cfFormat == g_expected_fetc->cfFormat,
540 "cfFormat: %x\n", pformatetc->cfFormat);
541 ok((pformatetc->ptd != NULL) == (g_expected_fetc->ptd != NULL),
542 "ptd: %p\n", pformatetc->ptd);
543 ok(pformatetc->dwAspect == g_expected_fetc->dwAspect,
544 "dwAspect: %x\n", pformatetc->dwAspect);
545 ok(pformatetc->lindex == g_expected_fetc->lindex,
546 "lindex: %x\n", pformatetc->lindex);
547 ok(pformatetc->tymed == g_expected_fetc->tymed,
548 "tymed: %x\n", pformatetc->tymed);
550 } else
551 ok(pformatetc == NULL, "pformatetc should be NULL\n");
552 return S_OK;
555 static HRESULT WINAPI OleObjectCache_Uncache
557 IOleCache *iface,
558 DWORD dwConnection
561 CHECK_EXPECTED_METHOD("OleObjectCache_Uncache");
562 return S_OK;
565 static HRESULT WINAPI OleObjectCache_EnumCache
567 IOleCache *iface,
568 IEnumSTATDATA **ppenumSTATDATA
571 CHECK_EXPECTED_METHOD("OleObjectCache_EnumCache");
572 return S_OK;
576 static HRESULT WINAPI OleObjectCache_InitCache
578 IOleCache *iface,
579 IDataObject *pDataObject
582 CHECK_EXPECTED_METHOD("OleObjectCache_InitCache");
583 return S_OK;
587 static HRESULT WINAPI OleObjectCache_SetData
589 IOleCache *iface,
590 FORMATETC *pformatetc,
591 STGMEDIUM *pmedium,
592 BOOL fRelease
595 CHECK_EXPECTED_METHOD("OleObjectCache_SetData");
596 return S_OK;
600 static const IOleCacheVtbl OleObjectCacheVtbl =
602 OleObjectCache_QueryInterface,
603 OleObjectCache_AddRef,
604 OleObjectCache_Release,
605 OleObjectCache_Cache,
606 OleObjectCache_Uncache,
607 OleObjectCache_EnumCache,
608 OleObjectCache_InitCache,
609 OleObjectCache_SetData
612 static IOleCache OleObjectCache = { &OleObjectCacheVtbl };
614 static HRESULT WINAPI OleObjectCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
616 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
618 *ppv = iface;
619 IUnknown_AddRef(iface);
620 return S_OK;
622 *ppv = NULL;
623 return E_NOINTERFACE;
626 static ULONG WINAPI OleObjectCF_AddRef(IClassFactory *iface)
628 return 2;
631 static ULONG WINAPI OleObjectCF_Release(IClassFactory *iface)
633 return 1;
636 static HRESULT WINAPI OleObjectCF_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID riid, void **ppv)
638 return IUnknown_QueryInterface((IUnknown *)&OleObject, riid, ppv);
641 static HRESULT WINAPI OleObjectCF_LockServer(IClassFactory *iface, BOOL lock)
643 return S_OK;
646 static const IClassFactoryVtbl OleObjectCFVtbl =
648 OleObjectCF_QueryInterface,
649 OleObjectCF_AddRef,
650 OleObjectCF_Release,
651 OleObjectCF_CreateInstance,
652 OleObjectCF_LockServer
655 static IClassFactory OleObjectCF = { &OleObjectCFVtbl };
657 static HRESULT WINAPI OleObjectRunnable_QueryInterface(IRunnableObject *iface, REFIID riid, void **ppv)
659 return IUnknown_QueryInterface((IUnknown *)&OleObject, riid, ppv);
662 static ULONG WINAPI OleObjectRunnable_AddRef(IRunnableObject *iface)
664 CHECK_EXPECTED_METHOD("OleObjectRunnable_AddRef");
665 return 2;
668 static ULONG WINAPI OleObjectRunnable_Release(IRunnableObject *iface)
670 CHECK_EXPECTED_METHOD("OleObjectRunnable_Release");
671 return 1;
674 static HRESULT WINAPI OleObjectRunnable_GetRunningClass(
675 IRunnableObject *iface,
676 LPCLSID lpClsid)
678 CHECK_EXPECTED_METHOD("OleObjectRunnable_GetRunningClass");
679 return E_NOTIMPL;
682 static HRESULT WINAPI OleObjectRunnable_Run(
683 IRunnableObject *iface,
684 LPBINDCTX pbc)
686 CHECK_EXPECTED_METHOD("OleObjectRunnable_Run");
687 return S_OK;
690 static BOOL WINAPI OleObjectRunnable_IsRunning(IRunnableObject *iface)
692 CHECK_EXPECTED_METHOD("OleObjectRunnable_IsRunning");
693 return g_isRunning;
696 static HRESULT WINAPI OleObjectRunnable_LockRunning(
697 IRunnableObject *iface,
698 BOOL fLock,
699 BOOL fLastUnlockCloses)
701 CHECK_EXPECTED_METHOD("OleObjectRunnable_LockRunning");
702 return S_OK;
705 static HRESULT WINAPI OleObjectRunnable_SetContainedObject(
706 IRunnableObject *iface,
707 BOOL fContained)
709 CHECK_EXPECTED_METHOD("OleObjectRunnable_SetContainedObject");
710 return S_OK;
713 static const IRunnableObjectVtbl OleObjectRunnableVtbl =
715 OleObjectRunnable_QueryInterface,
716 OleObjectRunnable_AddRef,
717 OleObjectRunnable_Release,
718 OleObjectRunnable_GetRunningClass,
719 OleObjectRunnable_Run,
720 OleObjectRunnable_IsRunning,
721 OleObjectRunnable_LockRunning,
722 OleObjectRunnable_SetContainedObject
725 static IRunnableObject OleObjectRunnable = { &OleObjectRunnableVtbl };
727 static const CLSID CLSID_Equation3 = {0x0002CE02, 0x0000, 0x0000, {0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46} };
729 static void test_OleCreate(IStorage *pStorage)
731 HRESULT hr;
732 IOleObject *pObject;
733 FORMATETC formatetc;
734 static const struct expected_method methods_olerender_none[] =
736 { "OleObject_QueryInterface", 0 },
737 { "OleObject_AddRef", 0 },
738 { "OleObject_QueryInterface", 0 },
739 { "OleObject_AddRef", TEST_OPTIONAL },
740 { "OleObject_Release", TEST_OPTIONAL },
741 { "OleObject_QueryInterface", TEST_OPTIONAL },
742 { "OleObjectPersistStg_AddRef", 0 },
743 { "OleObjectPersistStg_InitNew", 0 },
744 { "OleObjectPersistStg_Release", 0 },
745 { "OleObject_Release", 0 },
746 { "OleObject_Release", TEST_OPTIONAL },
747 { NULL, 0 }
749 static const struct expected_method methods_olerender_draw[] =
751 { "OleObject_QueryInterface", 0 },
752 { "OleObject_AddRef", 0 },
753 { "OleObject_QueryInterface", 0 },
754 { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
755 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
756 { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
757 { "OleObjectPersistStg_AddRef", 0 },
758 { "OleObjectPersistStg_InitNew", 0 },
759 { "OleObjectPersistStg_Release", 0 },
760 { "OleObject_QueryInterface", 0 },
761 { "OleObjectRunnable_AddRef", 0 },
762 { "OleObjectRunnable_Run", 0 },
763 { "OleObjectRunnable_Release", 0 },
764 { "OleObject_QueryInterface", 0 },
765 { "OleObjectCache_AddRef", 0 },
766 { "OleObjectCache_Cache", 0 },
767 { "OleObjectCache_Release", 0 },
768 { "OleObject_Release", 0 },
769 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
770 { NULL, 0 }
772 static const struct expected_method methods_olerender_format[] =
774 { "OleObject_QueryInterface", 0 },
775 { "OleObject_AddRef", 0 },
776 { "OleObject_QueryInterface", 0 },
777 { "OleObject_AddRef", 0 },
778 { "OleObject_GetMiscStatus", 0 },
779 { "OleObject_QueryInterface", 0 },
780 { "OleObjectPersistStg_AddRef", 0 },
781 { "OleObjectPersistStg_InitNew", 0 },
782 { "OleObjectPersistStg_Release", 0 },
783 { "OleObject_SetClientSite", 0 },
784 { "OleObject_Release", 0 },
785 { "OleObject_QueryInterface", 0 },
786 { "OleObjectRunnable_AddRef", 0 },
787 { "OleObjectRunnable_Run", 0 },
788 { "OleObjectRunnable_Release", 0 },
789 { "OleObject_QueryInterface", 0 },
790 { "OleObjectCache_AddRef", 0 },
791 { "OleObjectCache_Cache", 0 },
792 { "OleObjectCache_Release", 0 },
793 { "OleObject_Release", 0 },
794 { NULL, 0 }
796 static const struct expected_method methods_olerender_asis[] =
798 { "OleObject_QueryInterface", 0 },
799 { "OleObject_AddRef", 0 },
800 { "OleObject_QueryInterface", 0 },
801 { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
802 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
803 { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
804 { "OleObjectPersistStg_AddRef", 0 },
805 { "OleObjectPersistStg_InitNew", 0 },
806 { "OleObjectPersistStg_Release", 0 },
807 { "OleObject_Release", 0 },
808 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
809 { NULL, 0 }
811 static const struct expected_method methods_olerender_draw_no_runnable[] =
813 { "OleObject_QueryInterface", 0 },
814 { "OleObject_AddRef", 0 },
815 { "OleObject_QueryInterface", 0 },
816 { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
817 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
818 { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
819 { "OleObjectPersistStg_AddRef", 0 },
820 { "OleObjectPersistStg_InitNew", 0 },
821 { "OleObjectPersistStg_Release", 0 },
822 { "OleObject_QueryInterface", 0 },
823 { "OleObject_QueryInterface", 0 },
824 { "OleObjectCache_AddRef", 0 },
825 { "OleObjectCache_Cache", 0 },
826 { "OleObjectCache_Release", 0 },
827 { "OleObject_Release", 0 },
828 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
829 { NULL, 0 },
831 static const struct expected_method methods_olerender_draw_no_cache[] =
833 { "OleObject_QueryInterface", 0 },
834 { "OleObject_AddRef", 0 },
835 { "OleObject_QueryInterface", 0 },
836 { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
837 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
838 { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
839 { "OleObjectPersistStg_AddRef", 0 },
840 { "OleObjectPersistStg_InitNew", 0 },
841 { "OleObjectPersistStg_Release", 0 },
842 { "OleObject_QueryInterface", 0 },
843 { "OleObjectRunnable_AddRef", 0 },
844 { "OleObjectRunnable_Run", 0 },
845 { "OleObjectRunnable_Release", 0 },
846 { "OleObject_QueryInterface", 0 },
847 { "OleObject_Release", 0 },
848 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
849 { NULL, 0 }
852 g_expected_fetc = &formatetc;
853 formatetc.cfFormat = 0;
854 formatetc.ptd = NULL;
855 formatetc.dwAspect = DVASPECT_CONTENT;
856 formatetc.lindex = -1;
857 formatetc.tymed = TYMED_NULL;
858 runnable = &OleObjectRunnable;
859 cache = &OleObjectCache;
860 expected_method_list = methods_olerender_none;
861 trace("OleCreate with OLERENDER_NONE:\n");
862 hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_NONE, NULL, NULL, pStorage, (void **)&pObject);
863 ok_ole_success(hr, "OleCreate");
864 IOleObject_Release(pObject);
865 CHECK_NO_EXTRA_METHODS();
867 expected_method_list = methods_olerender_draw;
868 trace("OleCreate with OLERENDER_DRAW:\n");
869 hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject);
870 ok_ole_success(hr, "OleCreate");
871 IOleObject_Release(pObject);
872 CHECK_NO_EXTRA_METHODS();
874 formatetc.cfFormat = CF_TEXT;
875 formatetc.ptd = NULL;
876 formatetc.dwAspect = DVASPECT_CONTENT;
877 formatetc.lindex = -1;
878 formatetc.tymed = TYMED_HGLOBAL;
879 expected_method_list = methods_olerender_format;
880 trace("OleCreate with OLERENDER_FORMAT:\n");
881 hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_FORMAT, &formatetc, (IOleClientSite *)0xdeadbeef, pStorage, (void **)&pObject);
882 ok(hr == S_OK ||
883 broken(hr == E_INVALIDARG), /* win2k */
884 "OleCreate failed with error 0x%08x\n", hr);
885 if (pObject)
887 IOleObject_Release(pObject);
888 CHECK_NO_EXTRA_METHODS();
891 expected_method_list = methods_olerender_asis;
892 trace("OleCreate with OLERENDER_ASIS:\n");
893 hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_ASIS, NULL, NULL, pStorage, (void **)&pObject);
894 ok_ole_success(hr, "OleCreate");
895 IOleObject_Release(pObject);
896 CHECK_NO_EXTRA_METHODS();
898 formatetc.cfFormat = 0;
899 formatetc.tymed = TYMED_NULL;
900 runnable = NULL;
901 expected_method_list = methods_olerender_draw_no_runnable;
902 trace("OleCreate with OLERENDER_DRAW (no IRunnableObject):\n");
903 hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject);
904 ok_ole_success(hr, "OleCreate");
905 IOleObject_Release(pObject);
906 CHECK_NO_EXTRA_METHODS();
908 runnable = &OleObjectRunnable;
909 cache = NULL;
910 expected_method_list = methods_olerender_draw_no_cache;
911 trace("OleCreate with OLERENDER_DRAW (no IOleCache):\n");
912 hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject);
913 ok_ole_success(hr, "OleCreate");
914 IOleObject_Release(pObject);
915 CHECK_NO_EXTRA_METHODS();
916 trace("end\n");
919 static void test_OleLoad(IStorage *pStorage)
921 HRESULT hr;
922 IOleObject *pObject;
924 static const struct expected_method methods_oleload[] =
926 { "OleObject_QueryInterface", 0 },
927 { "OleObject_AddRef", 0 },
928 { "OleObject_QueryInterface", 0 },
929 { "OleObject_AddRef", 0 },
930 { "OleObject_GetMiscStatus", 0 },
931 { "OleObject_QueryInterface", 0 },
932 { "OleObjectPersistStg_AddRef", 0 },
933 { "OleObjectPersistStg_Load", 0 },
934 { "OleObjectPersistStg_Release", 0 },
935 { "OleObject_SetClientSite", 0 },
936 { "OleObject_Release", 0 },
937 { "OleObject_QueryInterface", 0 },
938 { "OleObject_GetMiscStatus", 0 },
939 { "OleObject_Release", 0 },
940 { NULL, 0 }
943 /* Test once with IOleObject_GetMiscStatus failing */
944 expected_method_list = methods_oleload;
945 g_failGetMiscStatus = TRUE;
946 trace("OleLoad:\n");
947 hr = OleLoad(pStorage, &IID_IOleObject, (IOleClientSite *)0xdeadbeef, (void **)&pObject);
948 ok(hr == S_OK ||
949 broken(hr == E_INVALIDARG), /* win98 and win2k */
950 "OleLoad failed with error 0x%08x\n", hr);
951 if(pObject)
953 DWORD dwStatus = 0xdeadbeef;
954 hr = IOleObject_GetMiscStatus(pObject, DVASPECT_CONTENT, &dwStatus);
955 ok(hr == E_FAIL, "Got 0x%08x\n", hr);
956 ok(dwStatus == 0x1234, "Got 0x%08x\n", dwStatus);
958 IOleObject_Release(pObject);
959 CHECK_NO_EXTRA_METHODS();
962 /* Test again, let IOleObject_GetMiscStatus succeed. */
963 g_failGetMiscStatus = FALSE;
964 expected_method_list = methods_oleload;
965 trace("OleLoad:\n");
966 hr = OleLoad(pStorage, &IID_IOleObject, (IOleClientSite *)0xdeadbeef, (void **)&pObject);
967 ok(hr == S_OK ||
968 broken(hr == E_INVALIDARG), /* win98 and win2k */
969 "OleLoad failed with error 0x%08x\n", hr);
970 if (pObject)
972 DWORD dwStatus = 0xdeadbeef;
973 hr = IOleObject_GetMiscStatus(pObject, DVASPECT_CONTENT, &dwStatus);
974 ok(hr == S_OK, "Got 0x%08x\n", hr);
975 ok(dwStatus == 1, "Got 0x%08x\n", dwStatus);
977 IOleObject_Release(pObject);
978 CHECK_NO_EXTRA_METHODS();
982 static BOOL STDMETHODCALLTYPE draw_continue(ULONG_PTR param)
984 CHECK_EXPECTED_METHOD("draw_continue");
985 return TRUE;
988 static BOOL STDMETHODCALLTYPE draw_continue_false(ULONG_PTR param)
990 CHECK_EXPECTED_METHOD("draw_continue_false");
991 return FALSE;
994 static HRESULT WINAPI AdviseSink_QueryInterface(IAdviseSink *iface, REFIID riid, void **ppv)
996 if (IsEqualIID(riid, &IID_IAdviseSink) || IsEqualIID(riid, &IID_IUnknown))
998 *ppv = iface;
999 IUnknown_AddRef(iface);
1000 return S_OK;
1002 *ppv = NULL;
1003 return E_NOINTERFACE;
1006 static ULONG WINAPI AdviseSink_AddRef(IAdviseSink *iface)
1008 return 2;
1011 static ULONG WINAPI AdviseSink_Release(IAdviseSink *iface)
1013 return 1;
1017 static void WINAPI AdviseSink_OnDataChange(
1018 IAdviseSink *iface,
1019 FORMATETC *pFormatetc,
1020 STGMEDIUM *pStgmed)
1022 CHECK_EXPECTED_METHOD("AdviseSink_OnDataChange");
1025 static void WINAPI AdviseSink_OnViewChange(
1026 IAdviseSink *iface,
1027 DWORD dwAspect,
1028 LONG lindex)
1030 CHECK_EXPECTED_METHOD("AdviseSink_OnViewChange");
1033 static void WINAPI AdviseSink_OnRename(
1034 IAdviseSink *iface,
1035 IMoniker *pmk)
1037 CHECK_EXPECTED_METHOD("AdviseSink_OnRename");
1040 static void WINAPI AdviseSink_OnSave(IAdviseSink *iface)
1042 CHECK_EXPECTED_METHOD("AdviseSink_OnSave");
1045 static void WINAPI AdviseSink_OnClose(IAdviseSink *iface)
1047 CHECK_EXPECTED_METHOD("AdviseSink_OnClose");
1050 static const IAdviseSinkVtbl AdviseSinkVtbl =
1052 AdviseSink_QueryInterface,
1053 AdviseSink_AddRef,
1054 AdviseSink_Release,
1055 AdviseSink_OnDataChange,
1056 AdviseSink_OnViewChange,
1057 AdviseSink_OnRename,
1058 AdviseSink_OnSave,
1059 AdviseSink_OnClose
1062 static IAdviseSink AdviseSink = { &AdviseSinkVtbl };
1064 static HRESULT WINAPI DataObject_QueryInterface(
1065 IDataObject* iface,
1066 REFIID riid,
1067 void** ppvObject)
1069 CHECK_EXPECTED_METHOD("DataObject_QueryInterface");
1071 if (IsEqualIID(riid, &IID_IDataObject) || IsEqualIID(riid, &IID_IUnknown))
1073 *ppvObject = iface;
1074 return S_OK;
1076 *ppvObject = NULL;
1077 return S_OK;
1080 static ULONG WINAPI DataObject_AddRef(
1081 IDataObject* iface)
1083 CHECK_EXPECTED_METHOD("DataObject_AddRef");
1084 return 2;
1087 static ULONG WINAPI DataObject_Release(
1088 IDataObject* iface)
1090 CHECK_EXPECTED_METHOD("DataObject_Release");
1091 return 1;
1094 static HRESULT WINAPI DataObject_GetData(
1095 IDataObject* iface,
1096 LPFORMATETC pformatetcIn,
1097 STGMEDIUM* pmedium)
1099 CHECK_EXPECTED_METHOD("DataObject_GetData");
1100 return E_NOTIMPL;
1103 static HRESULT WINAPI DataObject_GetDataHere(
1104 IDataObject* iface,
1105 LPFORMATETC pformatetc,
1106 STGMEDIUM* pmedium)
1108 CHECK_EXPECTED_METHOD("DataObject_GetDataHere");
1109 return E_NOTIMPL;
1112 static HRESULT WINAPI DataObject_QueryGetData(
1113 IDataObject* iface,
1114 LPFORMATETC pformatetc)
1116 CHECK_EXPECTED_METHOD("DataObject_QueryGetData");
1117 return S_OK;
1120 static HRESULT WINAPI DataObject_GetCanonicalFormatEtc(
1121 IDataObject* iface,
1122 LPFORMATETC pformatectIn,
1123 LPFORMATETC pformatetcOut)
1125 CHECK_EXPECTED_METHOD("DataObject_GetCanonicalFormatEtc");
1126 return E_NOTIMPL;
1129 static HRESULT WINAPI DataObject_SetData(
1130 IDataObject* iface,
1131 LPFORMATETC pformatetc,
1132 STGMEDIUM* pmedium,
1133 BOOL fRelease)
1135 CHECK_EXPECTED_METHOD("DataObject_SetData");
1136 return E_NOTIMPL;
1139 static HRESULT WINAPI DataObject_EnumFormatEtc(
1140 IDataObject* iface,
1141 DWORD dwDirection,
1142 IEnumFORMATETC** ppenumFormatEtc)
1144 CHECK_EXPECTED_METHOD("DataObject_EnumFormatEtc");
1145 return E_NOTIMPL;
1148 static HRESULT WINAPI DataObject_DAdvise(
1149 IDataObject* iface,
1150 FORMATETC* pformatetc,
1151 DWORD advf,
1152 IAdviseSink* pAdvSink,
1153 DWORD* pdwConnection)
1155 STGMEDIUM stgmedium;
1157 CHECK_EXPECTED_METHOD("DataObject_DAdvise");
1158 *pdwConnection = 1;
1160 if(advf & ADVF_PRIMEFIRST)
1162 ok(pformatetc->cfFormat == cf_test_2, "got %04x\n", pformatetc->cfFormat);
1163 stgmedium.tymed = TYMED_HGLOBAL;
1164 U(stgmedium).hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, 4);
1165 stgmedium.pUnkForRelease = NULL;
1166 IAdviseSink_OnDataChange(pAdvSink, pformatetc, &stgmedium);
1169 return S_OK;
1172 static HRESULT WINAPI DataObject_DUnadvise(
1173 IDataObject* iface,
1174 DWORD dwConnection)
1176 CHECK_EXPECTED_METHOD("DataObject_DUnadvise");
1177 return S_OK;
1180 static HRESULT WINAPI DataObject_EnumDAdvise(
1181 IDataObject* iface,
1182 IEnumSTATDATA** ppenumAdvise)
1184 CHECK_EXPECTED_METHOD("DataObject_EnumDAdvise");
1185 return OLE_E_ADVISENOTSUPPORTED;
1188 static IDataObjectVtbl DataObjectVtbl =
1190 DataObject_QueryInterface,
1191 DataObject_AddRef,
1192 DataObject_Release,
1193 DataObject_GetData,
1194 DataObject_GetDataHere,
1195 DataObject_QueryGetData,
1196 DataObject_GetCanonicalFormatEtc,
1197 DataObject_SetData,
1198 DataObject_EnumFormatEtc,
1199 DataObject_DAdvise,
1200 DataObject_DUnadvise,
1201 DataObject_EnumDAdvise
1204 static IDataObject DataObject = { &DataObjectVtbl };
1206 static void test_data_cache(void)
1208 HRESULT hr;
1209 IOleCache2 *pOleCache;
1210 IStorage *pStorage;
1211 IPersistStorage *pPS;
1212 IViewObject *pViewObject;
1213 IOleCacheControl *pOleCacheControl;
1214 IDataObject *pCacheDataObject;
1215 FORMATETC fmtetc;
1216 STGMEDIUM stgmedium;
1217 DWORD dwConnection;
1218 DWORD dwFreeze;
1219 RECTL rcBounds;
1220 HDC hdcMem;
1221 CLSID clsid;
1222 char szSystemDir[MAX_PATH];
1223 WCHAR wszPath[MAX_PATH];
1224 static const WCHAR wszShell32[] = {'\\','s','h','e','l','l','3','2','.','d','l','l',0};
1226 static const struct expected_method methods_cacheinitnew[] =
1228 { "AdviseSink_OnViewChange", 0 },
1229 { "AdviseSink_OnViewChange", 0 },
1230 { "draw_continue", 1 },
1231 { "draw_continue_false", 1 },
1232 { "DataObject_DAdvise", 0 },
1233 { "DataObject_DAdvise", 0 },
1234 { "DataObject_DUnadvise", 0 },
1235 { "DataObject_DUnadvise", 0 },
1236 { NULL, 0 }
1238 static const struct expected_method methods_cacheload[] =
1240 { "AdviseSink_OnViewChange", 0 },
1241 { "draw_continue", 1 },
1242 { "draw_continue", 1 },
1243 { "draw_continue", 1 },
1244 { "DataObject_GetData", 0 },
1245 { "DataObject_GetData", 0 },
1246 { "DataObject_GetData", 0 },
1247 { NULL, 0 }
1249 static const struct expected_method methods_cachethenrun[] =
1251 { "DataObject_DAdvise", 0 },
1252 { "DataObject_DAdvise", 0 },
1253 { "DataObject_DAdvise", 0 },
1254 { "DataObject_QueryGetData", 1 }, /* called by win9x and nt4 */
1255 { "DataObject_DAdvise", 0 },
1256 { "DataObject_DUnadvise", 0 },
1257 { "DataObject_DUnadvise", 0 },
1258 { "DataObject_DUnadvise", 0 },
1259 { "DataObject_DUnadvise", 0 },
1260 { NULL, 0 }
1263 GetSystemDirectory(szSystemDir, sizeof(szSystemDir)/sizeof(szSystemDir[0]));
1265 expected_method_list = methods_cacheinitnew;
1267 fmtetc.cfFormat = CF_METAFILEPICT;
1268 fmtetc.dwAspect = DVASPECT_ICON;
1269 fmtetc.lindex = -1;
1270 fmtetc.ptd = NULL;
1271 fmtetc.tymed = TYMED_MFPICT;
1273 hr = StgCreateDocfile(NULL, STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_DELETEONRELEASE, 0, &pStorage);
1274 ok_ole_success(hr, "StgCreateDocfile");
1276 /* Test with new data */
1278 hr = CreateDataCache(NULL, &CLSID_NULL, &IID_IOleCache2, (LPVOID *)&pOleCache);
1279 ok_ole_success(hr, "CreateDataCache");
1281 hr = IOleCache_QueryInterface(pOleCache, &IID_IPersistStorage, (LPVOID *)&pPS);
1282 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IPersistStorage)");
1283 hr = IOleCache_QueryInterface(pOleCache, &IID_IViewObject, (LPVOID *)&pViewObject);
1284 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IViewObject)");
1285 hr = IOleCache_QueryInterface(pOleCache, &IID_IOleCacheControl, (LPVOID *)&pOleCacheControl);
1286 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IOleCacheControl)");
1288 hr = IViewObject_SetAdvise(pViewObject, DVASPECT_ICON, ADVF_PRIMEFIRST, &AdviseSink);
1289 ok_ole_success(hr, "IViewObject_SetAdvise");
1291 hr = IPersistStorage_InitNew(pPS, pStorage);
1292 ok_ole_success(hr, "IPersistStorage_InitNew");
1294 hr = IPersistStorage_IsDirty(pPS);
1295 ok_ole_success(hr, "IPersistStorage_IsDirty");
1297 hr = IPersistStorage_GetClassID(pPS, &clsid);
1298 ok_ole_success(hr, "IPersistStorage_GetClassID");
1299 ok(IsEqualCLSID(&clsid, &IID_NULL), "clsid should be blank\n");
1301 hr = IOleCache_Uncache(pOleCache, 0xdeadbeef);
1302 ok(hr == OLE_E_NOCONNECTION, "IOleCache_Uncache with invalid value should return OLE_E_NOCONNECTION instead of 0x%x\n", hr);
1304 /* Both tests crash on NT4 and below. StgCreatePropSetStg is only available on w2k and above. */
1305 if (GetProcAddress(GetModuleHandleA("ole32.dll"), "StgCreatePropSetStg"))
1307 hr = IOleCache_Cache(pOleCache, NULL, 0, &dwConnection);
1308 ok(hr == E_INVALIDARG, "IOleCache_Cache with NULL fmtetc should have returned E_INVALIDARG instead of 0x%08x\n", hr);
1310 hr = IOleCache_Cache(pOleCache, NULL, 0, NULL);
1311 ok(hr == E_INVALIDARG, "IOleCache_Cache with NULL pdwConnection should have returned E_INVALIDARG instead of 0x%08x\n", hr);
1313 else
1315 skip("tests with NULL parameters will crash on NT4 and below\n");
1318 for (fmtetc.cfFormat = CF_TEXT; fmtetc.cfFormat < CF_MAX; fmtetc.cfFormat++)
1320 int i;
1321 fmtetc.dwAspect = DVASPECT_THUMBNAIL;
1322 for (i = 0; i < 7; i++)
1324 fmtetc.tymed = 1 << i;
1325 hr = IOleCache_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1326 if ((fmtetc.cfFormat == CF_METAFILEPICT && fmtetc.tymed == TYMED_MFPICT) ||
1327 (fmtetc.cfFormat == CF_BITMAP && fmtetc.tymed == TYMED_GDI) ||
1328 (fmtetc.cfFormat == CF_DIB && fmtetc.tymed == TYMED_HGLOBAL) ||
1329 (fmtetc.cfFormat == CF_ENHMETAFILE && fmtetc.tymed == TYMED_ENHMF))
1330 ok(hr == S_OK, "IOleCache_Cache cfFormat = %d, tymed = %d should have returned S_OK instead of 0x%08x\n",
1331 fmtetc.cfFormat, fmtetc.tymed, hr);
1332 else if (fmtetc.tymed == TYMED_HGLOBAL)
1333 ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED ||
1334 broken(hr == S_OK && fmtetc.cfFormat == CF_BITMAP) /* Win9x & NT4 */,
1335 "IOleCache_Cache cfFormat = %d, tymed = %d should have returned CACHE_S_FORMATETC_NOTSUPPORTED instead of 0x%08x\n",
1336 fmtetc.cfFormat, fmtetc.tymed, hr);
1337 else
1338 ok(hr == DV_E_TYMED, "IOleCache_Cache cfFormat = %d, tymed = %d should have returned DV_E_TYMED instead of 0x%08x\n",
1339 fmtetc.cfFormat, fmtetc.tymed, hr);
1340 if (SUCCEEDED(hr))
1342 hr = IOleCache_Uncache(pOleCache, dwConnection);
1343 ok_ole_success(hr, "IOleCache_Uncache");
1348 fmtetc.cfFormat = CF_BITMAP;
1349 fmtetc.dwAspect = DVASPECT_THUMBNAIL;
1350 fmtetc.tymed = TYMED_GDI;
1351 hr = IOleCache_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1352 ok_ole_success(hr, "IOleCache_Cache");
1354 fmtetc.cfFormat = 0;
1355 fmtetc.dwAspect = DVASPECT_ICON;
1356 fmtetc.tymed = TYMED_MFPICT;
1357 hr = IOleCache_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1358 ok_ole_success(hr, "IOleCache_Cache");
1360 MultiByteToWideChar(CP_ACP, 0, szSystemDir, -1, wszPath, sizeof(wszPath)/sizeof(wszPath[0]));
1361 memcpy(wszPath+lstrlenW(wszPath), wszShell32, sizeof(wszShell32));
1363 fmtetc.cfFormat = CF_METAFILEPICT;
1364 stgmedium.tymed = TYMED_MFPICT;
1365 U(stgmedium).hMetaFilePict = OleMetafilePictFromIconAndLabel(
1366 LoadIcon(NULL, IDI_APPLICATION), wszPath, wszPath, 0);
1367 stgmedium.pUnkForRelease = NULL;
1369 fmtetc.dwAspect = DVASPECT_CONTENT;
1370 hr = IOleCache_SetData(pOleCache, &fmtetc, &stgmedium, FALSE);
1371 ok(hr == OLE_E_BLANK, "IOleCache_SetData for aspect not in cache should have return OLE_E_BLANK instead of 0x%08x\n", hr);
1373 fmtetc.dwAspect = DVASPECT_ICON;
1374 hr = IOleCache_SetData(pOleCache, &fmtetc, &stgmedium, FALSE);
1375 ok_ole_success(hr, "IOleCache_SetData");
1376 ReleaseStgMedium(&stgmedium);
1378 hr = IViewObject_Freeze(pViewObject, DVASPECT_ICON, -1, NULL, &dwFreeze);
1379 todo_wine {
1380 ok_ole_success(hr, "IViewObject_Freeze");
1381 hr = IViewObject_Freeze(pViewObject, DVASPECT_CONTENT, -1, NULL, &dwFreeze);
1382 ok(hr == OLE_E_BLANK, "IViewObject_Freeze with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1385 rcBounds.left = 0;
1386 rcBounds.top = 0;
1387 rcBounds.right = 100;
1388 rcBounds.bottom = 100;
1389 hdcMem = CreateCompatibleDC(NULL);
1391 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1392 ok_ole_success(hr, "IViewObject_Draw");
1394 hr = IViewObject_Draw(pViewObject, DVASPECT_CONTENT, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1395 ok(hr == OLE_E_BLANK, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1397 /* a NULL draw_continue fn ptr */
1398 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, NULL, 0xdeadbeef);
1399 ok_ole_success(hr, "IViewObject_Draw");
1401 /* draw_continue that returns FALSE to abort drawing */
1402 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue_false, 0xdeadbeef);
1403 ok(hr == E_ABORT ||
1404 broken(hr == S_OK), /* win9x may skip the callbacks */
1405 "IViewObject_Draw with draw_continue_false returns 0x%08x\n", hr);
1407 DeleteDC(hdcMem);
1409 hr = IOleCacheControl_OnRun(pOleCacheControl, &DataObject);
1410 ok_ole_success(hr, "IOleCacheControl_OnRun");
1412 hr = IPersistStorage_Save(pPS, pStorage, TRUE);
1413 ok_ole_success(hr, "IPersistStorage_Save");
1415 hr = IPersistStorage_SaveCompleted(pPS, NULL);
1416 ok_ole_success(hr, "IPersistStorage_SaveCompleted");
1418 hr = IPersistStorage_IsDirty(pPS);
1419 ok(hr == S_FALSE, "IPersistStorage_IsDirty should have returned S_FALSE instead of 0x%x\n", hr);
1421 IPersistStorage_Release(pPS);
1422 IViewObject_Release(pViewObject);
1423 IOleCache_Release(pOleCache);
1424 IOleCacheControl_Release(pOleCacheControl);
1426 CHECK_NO_EXTRA_METHODS();
1428 /* Test with loaded data */
1429 trace("Testing loaded data with CreateDataCache:\n");
1430 expected_method_list = methods_cacheload;
1432 hr = CreateDataCache(NULL, &CLSID_NULL, &IID_IOleCache2, (LPVOID *)&pOleCache);
1433 ok_ole_success(hr, "CreateDataCache");
1435 hr = IOleCache_QueryInterface(pOleCache, &IID_IPersistStorage, (LPVOID *)&pPS);
1436 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IPersistStorage)");
1437 hr = IOleCache_QueryInterface(pOleCache, &IID_IViewObject, (LPVOID *)&pViewObject);
1438 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IViewObject)");
1440 hr = IViewObject_SetAdvise(pViewObject, DVASPECT_ICON, ADVF_PRIMEFIRST, &AdviseSink);
1441 ok_ole_success(hr, "IViewObject_SetAdvise");
1443 hr = IPersistStorage_Load(pPS, pStorage);
1444 ok_ole_success(hr, "IPersistStorage_Load");
1446 hr = IPersistStorage_IsDirty(pPS);
1447 ok(hr == S_FALSE, "IPersistStorage_IsDirty should have returned S_FALSE instead of 0x%x\n", hr);
1449 fmtetc.cfFormat = 0;
1450 fmtetc.dwAspect = DVASPECT_ICON;
1451 fmtetc.lindex = -1;
1452 fmtetc.ptd = NULL;
1453 fmtetc.tymed = TYMED_MFPICT;
1454 hr = IOleCache_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1455 ok(hr == CACHE_S_SAMECACHE, "IOleCache_Cache with already loaded data format type should return CACHE_S_SAMECACHE instead of 0x%x\n", hr);
1457 rcBounds.left = 0;
1458 rcBounds.top = 0;
1459 rcBounds.right = 100;
1460 rcBounds.bottom = 100;
1461 hdcMem = CreateCompatibleDC(NULL);
1463 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1464 ok_ole_success(hr, "IViewObject_Draw");
1466 hr = IViewObject_Draw(pViewObject, DVASPECT_CONTENT, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1467 ok(hr == OLE_E_BLANK, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1469 /* unload the cached storage object, causing it to be reloaded */
1470 hr = IOleCache2_DiscardCache(pOleCache, DISCARDCACHE_NOSAVE);
1471 ok_ole_success(hr, "IOleCache2_DiscardCache");
1472 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1473 ok_ole_success(hr, "IViewObject_Draw");
1475 /* unload the cached storage object, but don't allow it to be reloaded */
1476 hr = IPersistStorage_HandsOffStorage(pPS);
1477 ok_ole_success(hr, "IPersistStorage_HandsOffStorage");
1478 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1479 ok_ole_success(hr, "IViewObject_Draw");
1480 hr = IOleCache2_DiscardCache(pOleCache, DISCARDCACHE_NOSAVE);
1481 ok_ole_success(hr, "IOleCache2_DiscardCache");
1482 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1483 ok(hr == OLE_E_BLANK, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1485 DeleteDC(hdcMem);
1487 todo_wine {
1488 hr = IOleCache_InitCache(pOleCache, &DataObject);
1489 ok(hr == CACHE_E_NOCACHE_UPDATED, "IOleCache_InitCache should have returned CACHE_E_NOCACHE_UPDATED instead of 0x%08x\n", hr);
1492 IPersistStorage_Release(pPS);
1493 IViewObject_Release(pViewObject);
1494 IOleCache_Release(pOleCache);
1496 todo_wine {
1497 CHECK_NO_EXTRA_METHODS();
1500 hr = CreateDataCache(NULL, &CLSID_NULL, &IID_IOleCache2, (LPVOID *)&pOleCache);
1501 ok_ole_success(hr, "CreateDataCache");
1503 expected_method_list = methods_cachethenrun;
1505 hr = IOleCache_QueryInterface(pOleCache, &IID_IDataObject, (LPVOID *)&pCacheDataObject);
1506 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IDataObject)");
1507 hr = IOleCache_QueryInterface(pOleCache, &IID_IOleCacheControl, (LPVOID *)&pOleCacheControl);
1508 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IOleCacheControl)");
1510 fmtetc.cfFormat = CF_METAFILEPICT;
1511 fmtetc.dwAspect = DVASPECT_CONTENT;
1512 fmtetc.tymed = TYMED_MFPICT;
1514 hr = IOleCache_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1515 ok_ole_success(hr, "IOleCache_Cache");
1517 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1518 ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1520 fmtetc.cfFormat = cf_test_1;
1521 fmtetc.dwAspect = DVASPECT_CONTENT;
1522 fmtetc.tymed = TYMED_HGLOBAL;
1524 hr = IOleCache_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1525 ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED, "got %08x\n", hr);
1527 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1528 ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1530 fmtetc.cfFormat = cf_test_2;
1531 hr = IOleCache_Cache(pOleCache, &fmtetc, ADVF_PRIMEFIRST, &dwConnection);
1532 ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED, "got %08x\n", hr);
1534 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1535 ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1537 hr = IOleCacheControl_OnRun(pOleCacheControl, &DataObject);
1538 ok_ole_success(hr, "IOleCacheControl_OnRun");
1540 fmtetc.cfFormat = cf_test_3;
1541 hr = IOleCache_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1542 ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED, "got %08x\n", hr);
1544 fmtetc.cfFormat = cf_test_1;
1545 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1546 ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1548 fmtetc.cfFormat = cf_test_2;
1549 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1550 ok(hr == S_OK, "got %08x\n", hr);
1551 ReleaseStgMedium(&stgmedium);
1553 fmtetc.cfFormat = cf_test_3;
1554 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1555 ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1557 IOleCacheControl_Release(pOleCacheControl);
1558 IDataObject_Release(pCacheDataObject);
1559 IOleCache_Release(pOleCache);
1561 CHECK_NO_EXTRA_METHODS();
1563 IStorage_Release(pStorage);
1566 static void test_default_handler(void)
1568 HRESULT hr;
1569 IOleObject *pObject;
1570 IRunnableObject *pRunnableObject;
1571 IOleClientSite *pClientSite;
1572 IDataObject *pDataObject;
1573 SIZEL sizel;
1574 DWORD dwStatus;
1575 CLSID clsid;
1576 LPOLESTR pszUserType;
1577 LOGPALETTE palette;
1578 DWORD dwAdvConn;
1579 IMoniker *pMoniker;
1580 FORMATETC fmtetc;
1581 IOleInPlaceObject *pInPlaceObj;
1582 IEnumOLEVERB *pEnumVerbs;
1583 DWORD dwRegister;
1584 static const WCHAR wszUnknown[] = {'U','n','k','n','o','w','n',0};
1585 static const WCHAR wszHostName[] = {'W','i','n','e',' ','T','e','s','t',' ','P','r','o','g','r','a','m',0};
1586 static const WCHAR wszDelim[] = {'!',0};
1588 static const struct expected_method methods_embeddinghelper[] =
1590 { "OleObject_QueryInterface", 0 },
1591 { "OleObject_AddRef", 0 },
1592 { "OleObject_QueryInterface", 0 },
1593 { "OleObject_QueryInterface", TEST_TODO },
1594 { "OleObject_QueryInterface", 0 },
1595 { "OleObject_QueryInterface", 0 },
1596 { "OleObject_QueryInterface", TEST_OPTIONAL }, /* Win95/98/NT4 */
1597 { "OleObject_Release", TEST_TODO },
1598 { "WINE_EXTRA", TEST_OPTIONAL },
1599 { NULL, 0 }
1602 hr = CoCreateInstance(&CLSID_WineTest, NULL, CLSCTX_INPROC_HANDLER, &IID_IOleObject, (void **)&pObject);
1603 ok(hr == REGDB_E_CLASSNOTREG, "CoCreateInstance should have failed with REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1605 hr = OleCreateDefaultHandler(&CLSID_WineTest, NULL, &IID_IOleObject, (void **)&pObject);
1606 ok_ole_success(hr, "OleCreateDefaultHandler");
1608 hr = IOleObject_QueryInterface(pObject, &IID_IOleInPlaceObject, (void **)&pInPlaceObj);
1609 ok(hr == E_NOINTERFACE, "IOleObject_QueryInterface(&IID_IOleInPlaceObject) should return E_NOINTERFACE instead of 0x%08x\n", hr);
1611 hr = IOleObject_Advise(pObject, &AdviseSink, &dwAdvConn);
1612 ok_ole_success(hr, "IOleObject_Advise");
1614 hr = IOleObject_Close(pObject, OLECLOSE_NOSAVE);
1615 ok_ole_success(hr, "IOleObject_Close");
1617 /* FIXME: test IOleObject_EnumAdvise */
1619 hr = IOleObject_EnumVerbs(pObject, &pEnumVerbs);
1620 ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_EnumVerbs should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1622 hr = IOleObject_GetClientSite(pObject, &pClientSite);
1623 ok_ole_success(hr, "IOleObject_GetClientSite");
1625 hr = IOleObject_GetClipboardData(pObject, 0, &pDataObject);
1626 ok(hr == OLE_E_NOTRUNNING,
1627 "IOleObject_GetClipboardData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n",
1628 hr);
1630 hr = IOleObject_GetExtent(pObject, DVASPECT_CONTENT, &sizel);
1631 ok(hr == OLE_E_BLANK, "IOleObject_GetExtent should have returned OLE_E_BLANK instead of 0x%08x\n",
1632 hr);
1634 hr = IOleObject_GetMiscStatus(pObject, DVASPECT_CONTENT, &dwStatus);
1635 ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_GetMiscStatus should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1637 hr = IOleObject_GetUserClassID(pObject, &clsid);
1638 ok_ole_success(hr, "IOleObject_GetUserClassID");
1639 ok(IsEqualCLSID(&clsid, &CLSID_WineTest), "clsid != CLSID_WineTest\n");
1641 hr = IOleObject_GetUserType(pObject, USERCLASSTYPE_FULL, &pszUserType);
1642 todo_wine {
1643 ok_ole_success(hr, "IOleObject_GetUserType");
1644 ok(!lstrcmpW(pszUserType, wszUnknown), "Retrieved user type was wrong\n");
1647 hr = IOleObject_InitFromData(pObject, NULL, TRUE, 0);
1648 ok(hr == OLE_E_NOTRUNNING, "IOleObject_InitFromData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1650 hr = IOleObject_IsUpToDate(pObject);
1651 ok(hr == OLE_E_NOTRUNNING, "IOleObject_IsUpToDate should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1653 palette.palNumEntries = 1;
1654 palette.palVersion = 2;
1655 memset(&palette.palPalEntry[0], 0, sizeof(palette.palPalEntry[0]));
1656 hr = IOleObject_SetColorScheme(pObject, &palette);
1657 ok(hr == OLE_E_NOTRUNNING, "IOleObject_SetColorScheme should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1659 sizel.cx = sizel.cy = 0;
1660 hr = IOleObject_SetExtent(pObject, DVASPECT_CONTENT, &sizel);
1661 ok(hr == OLE_E_NOTRUNNING, "IOleObject_SetExtent should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1663 hr = IOleObject_SetHostNames(pObject, wszHostName, NULL);
1664 ok_ole_success(hr, "IOleObject_SetHostNames");
1666 hr = CreateItemMoniker(wszDelim, wszHostName, &pMoniker);
1667 ok_ole_success(hr, "CreateItemMoniker");
1668 hr = IOleObject_SetMoniker(pObject, OLEWHICHMK_CONTAINER, pMoniker);
1669 ok_ole_success(hr, "IOleObject_SetMoniker");
1670 IMoniker_Release(pMoniker);
1672 hr = IOleObject_GetMoniker(pObject, OLEGETMONIKER_ONLYIFTHERE, OLEWHICHMK_CONTAINER, &pMoniker);
1673 ok(hr == E_FAIL, "IOleObject_GetMoniker should have returned E_FAIL instead of 0x%08x\n", hr);
1675 hr = IOleObject_Update(pObject);
1676 todo_wine
1677 ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_Update should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1679 hr = IOleObject_QueryInterface(pObject, &IID_IDataObject, (void **)&pDataObject);
1680 ok_ole_success(hr, "IOleObject_QueryInterface");
1682 fmtetc.cfFormat = CF_TEXT;
1683 fmtetc.ptd = NULL;
1684 fmtetc.dwAspect = DVASPECT_CONTENT;
1685 fmtetc.lindex = -1;
1686 fmtetc.tymed = TYMED_NULL;
1687 hr = IDataObject_DAdvise(pDataObject, &fmtetc, 0, &AdviseSink, &dwAdvConn);
1688 ok_ole_success(hr, "IDataObject_DAdvise");
1690 fmtetc.cfFormat = CF_ENHMETAFILE;
1691 fmtetc.ptd = NULL;
1692 fmtetc.dwAspect = DVASPECT_CONTENT;
1693 fmtetc.lindex = -1;
1694 fmtetc.tymed = TYMED_ENHMF;
1695 hr = IDataObject_DAdvise(pDataObject, &fmtetc, 0, &AdviseSink, &dwAdvConn);
1696 ok_ole_success(hr, "IDataObject_DAdvise");
1698 fmtetc.cfFormat = CF_ENHMETAFILE;
1699 fmtetc.ptd = NULL;
1700 fmtetc.dwAspect = DVASPECT_CONTENT;
1701 fmtetc.lindex = -1;
1702 fmtetc.tymed = TYMED_ENHMF;
1703 hr = IDataObject_QueryGetData(pDataObject, &fmtetc);
1704 todo_wine
1705 ok(hr == OLE_E_NOTRUNNING, "IDataObject_QueryGetData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1707 fmtetc.cfFormat = CF_TEXT;
1708 fmtetc.ptd = NULL;
1709 fmtetc.dwAspect = DVASPECT_CONTENT;
1710 fmtetc.lindex = -1;
1711 fmtetc.tymed = TYMED_NULL;
1712 hr = IDataObject_QueryGetData(pDataObject, &fmtetc);
1713 todo_wine
1714 ok(hr == OLE_E_NOTRUNNING, "IDataObject_QueryGetData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1716 hr = IOleObject_QueryInterface(pObject, &IID_IRunnableObject, (void **)&pRunnableObject);
1717 ok_ole_success(hr, "IOleObject_QueryInterface");
1719 hr = IRunnableObject_SetContainedObject(pRunnableObject, TRUE);
1720 ok_ole_success(hr, "IRunnableObject_SetContainedObject");
1722 hr = IRunnableObject_Run(pRunnableObject, NULL);
1723 ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_Run should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1725 hr = IOleObject_Close(pObject, OLECLOSE_NOSAVE);
1726 ok_ole_success(hr, "IOleObject_Close");
1728 IRunnableObject_Release(pRunnableObject);
1729 IOleObject_Release(pObject);
1731 /* Test failure propagation from delegate ::QueryInterface */
1732 hr = CoRegisterClassObject(&CLSID_WineTest, (IUnknown*)&OleObjectCF,
1733 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &dwRegister);
1734 ok_ole_success(hr, "CoRegisterClassObject");
1735 if(SUCCEEDED(hr))
1737 expected_method_list = methods_embeddinghelper;
1738 hr = OleCreateEmbeddingHelper(&CLSID_WineTest, NULL, EMBDHLP_INPROC_SERVER,
1739 &OleObjectCF, &IID_IOleObject, (void**)&pObject);
1740 ok_ole_success(hr, "OleCreateEmbeddingHelper");
1741 if(SUCCEEDED(hr))
1743 IUnknown *punk;
1745 g_QIFailsWith = E_FAIL;
1746 hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1747 ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1749 g_QIFailsWith = E_NOINTERFACE;
1750 hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1751 ok(hr == E_NOINTERFACE, "Got 0x%08x\n", hr);
1753 g_QIFailsWith = CO_E_OBJNOTCONNECTED;
1754 hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1755 ok(hr == CO_E_OBJNOTCONNECTED, "Got 0x%08x\n", hr);
1757 g_QIFailsWith = 0x87654321;
1758 hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1759 ok(hr == 0x87654321, "Got 0x%08x\n", hr);
1761 IOleObject_Release(pObject);
1764 CHECK_NO_EXTRA_METHODS();
1766 hr = CoRevokeClassObject(dwRegister);
1767 ok_ole_success(hr, "CoRevokeClassObject");
1771 static void test_runnable(void)
1773 static const struct expected_method methods_query_runnable[] =
1775 { "OleObject_QueryInterface", 0 },
1776 { "OleObjectRunnable_AddRef", 0 },
1777 { "OleObjectRunnable_IsRunning", 0 },
1778 { "OleObjectRunnable_Release", 0 },
1779 { NULL, 0 }
1782 static const struct expected_method methods_no_runnable[] =
1784 { "OleObject_QueryInterface", 0 },
1785 { NULL, 0 }
1788 BOOL ret;
1789 IOleObject *object = &OleObject;
1791 /* null argument */
1792 ret = OleIsRunning(NULL);
1793 ok(ret == FALSE, "got %d\n", ret);
1795 expected_method_list = methods_query_runnable;
1796 ret = OleIsRunning(object);
1797 ok(ret == TRUE, "Object should be running\n");
1798 CHECK_NO_EXTRA_METHODS();
1800 g_isRunning = FALSE;
1801 expected_method_list = methods_query_runnable;
1802 ret = OleIsRunning(object);
1803 ok(ret == FALSE, "Object should not be running\n");
1804 CHECK_NO_EXTRA_METHODS();
1806 g_showRunnable = FALSE; /* QueryInterface(IID_IRunnableObject, ...) will fail */
1807 expected_method_list = methods_no_runnable;
1808 ret = OleIsRunning(object);
1809 ok(ret == TRUE, "Object without IRunnableObject should be running\n");
1810 CHECK_NO_EXTRA_METHODS();
1812 g_isRunning = TRUE;
1813 g_showRunnable = TRUE;
1816 static HRESULT WINAPI Unknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
1818 *ppv = NULL;
1819 if (IsEqualIID(riid, &IID_IUnknown)) *ppv = iface;
1820 if (*ppv)
1822 IUnknown_AddRef((IUnknown *)*ppv);
1823 return S_OK;
1825 return E_NOINTERFACE;
1828 static ULONG WINAPI Unknown_AddRef(IUnknown *iface)
1830 return 2;
1833 static ULONG WINAPI Unknown_Release(IUnknown *iface)
1835 return 1;
1838 static const IUnknownVtbl UnknownVtbl =
1840 Unknown_QueryInterface,
1841 Unknown_AddRef,
1842 Unknown_Release
1845 static IUnknown unknown = { &UnknownVtbl };
1847 static void test_OleLockRunning(void)
1849 HRESULT hr;
1851 hr = OleLockRunning((LPUNKNOWN)&unknown, TRUE, FALSE);
1852 ok(hr == S_OK, "OleLockRunning failed 0x%08x\n", hr);
1855 START_TEST(ole2)
1857 DWORD dwRegister;
1858 IStorage *pStorage;
1859 STATSTG statstg;
1860 HRESULT hr;
1862 cf_test_1 = RegisterClipboardFormatA("cf_winetest_1");
1863 cf_test_2 = RegisterClipboardFormatA("cf_winetest_2");
1864 cf_test_3 = RegisterClipboardFormatA("cf_winetest_3");
1866 CoInitialize(NULL);
1868 hr = CoRegisterClassObject(&CLSID_Equation3, (IUnknown *)&OleObjectCF, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &dwRegister);
1869 ok_ole_success(hr, "CoRegisterClassObject");
1871 hr = StgCreateDocfile(NULL, STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_DELETEONRELEASE, 0, &pStorage);
1872 ok_ole_success(hr, "StgCreateDocfile");
1874 test_OleCreate(pStorage);
1876 hr = IStorage_Stat(pStorage, &statstg, STATFLAG_NONAME);
1877 ok_ole_success(hr, "IStorage_Stat");
1878 ok(IsEqualCLSID(&CLSID_Equation3, &statstg.clsid), "Wrong CLSID in storage\n");
1880 test_OleLoad(pStorage);
1882 IStorage_Release(pStorage);
1884 hr = CoRevokeClassObject(dwRegister);
1885 ok_ole_success(hr, "CoRevokeClassObject");
1887 test_data_cache();
1888 test_default_handler();
1889 test_runnable();
1890 test_OleLockRunning();
1892 CoUninitialize();