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
23 #define WIN32_LEAN_AND_MEAN
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 */
45 {0xbc, 0x13, 0x51, 0x6e, 0x92, 0x39, 0xac, 0xe0}
48 static const IID IID_WineTest =
49 { /* 9474ba1a-258b-490b-bc13-516e9239ace1 */
53 {0xbc, 0x13, 0x51, 0x6e, 0x92, 0x39, 0xac, 0xe1}
56 #define TEST_OPTIONAL 0x1
59 struct expected_method
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) \
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")) \
81 todo_wine ok(0, "Too many method calls.\n"); \
84 if (expected_method_list->method) \
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) \
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); \
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++; \
102 #define CHECK_NO_EXTRA_METHODS() \
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); \
109 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
111 CHECK_EXPECTED_METHOD("OleObject_QueryInterface");
115 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IOleObject))
117 else if (IsEqualIID(riid, &IID_IPersistStorage))
118 *ppv = &OleObjectPersistStg;
119 else if (IsEqualIID(riid, &IID_IOleCache))
121 else if (IsEqualIID(riid, &IID_IRunnableObject) && g_showRunnable)
123 else if (IsEqualIID(riid, &IID_WineTest))
124 return g_QIFailsWith;
127 IUnknown_AddRef((IUnknown*)*ppv);
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");
141 static ULONG WINAPI OleObject_Release(IOleObject *iface)
143 CHECK_EXPECTED_METHOD("OleObject_Release");
147 static HRESULT WINAPI OleObject_SetClientSite
150 IOleClientSite *pClientSite
153 CHECK_EXPECTED_METHOD("OleObject_SetClientSite");
157 static HRESULT WINAPI OleObject_GetClientSite
160 IOleClientSite **ppClientSite
163 CHECK_EXPECTED_METHOD("OleObject_GetClientSite");
167 static HRESULT WINAPI OleObject_SetHostNames
170 LPCOLESTR szContainerApp,
171 LPCOLESTR szContainerObj
174 CHECK_EXPECTED_METHOD("OleObject_SetHostNames");
178 static HRESULT WINAPI OleObject_Close
184 CHECK_EXPECTED_METHOD("OleObject_Close");
188 static HRESULT WINAPI OleObject_SetMoniker
191 DWORD dwWhichMoniker,
195 CHECK_EXPECTED_METHOD("OleObject_SetMoniker");
199 static HRESULT WINAPI OleObject_GetMoniker
203 DWORD dwWhichMoniker,
207 CHECK_EXPECTED_METHOD("OleObject_GetMoniker");
211 static HRESULT WINAPI OleObject_InitFromData
214 IDataObject *pDataObject,
219 CHECK_EXPECTED_METHOD("OleObject_InitFromData");
223 static HRESULT WINAPI OleObject_GetClipboardData
227 IDataObject **ppDataObject
230 CHECK_EXPECTED_METHOD("OleObject_GetClipboardData");
234 static HRESULT WINAPI OleObject_DoVerb
239 IOleClientSite *pActiveSite,
245 CHECK_EXPECTED_METHOD("OleObject_DoVerb");
249 static HRESULT WINAPI OleObject_EnumVerbs
252 IEnumOLEVERB **ppEnumOleVerb
255 CHECK_EXPECTED_METHOD("OleObject_EnumVerbs");
259 static HRESULT WINAPI OleObject_Update
264 CHECK_EXPECTED_METHOD("OleObject_Update");
268 static HRESULT WINAPI OleObject_IsUpToDate
273 CHECK_EXPECTED_METHOD("OleObject_IsUpToDate");
277 static HRESULT WINAPI OleObject_GetUserClassID
283 CHECK_EXPECTED_METHOD("OleObject_GetUserClassID");
287 static HRESULT WINAPI OleObject_GetUserType
291 LPOLESTR *pszUserType
294 CHECK_EXPECTED_METHOD("OleObject_GetUserType");
298 static HRESULT WINAPI OleObject_SetExtent
305 CHECK_EXPECTED_METHOD("OleObject_SetExtent");
309 static HRESULT WINAPI OleObject_GetExtent
316 CHECK_EXPECTED_METHOD("OleObject_GetExtent");
320 static HRESULT WINAPI OleObject_Advise
323 IAdviseSink *pAdvSink,
327 CHECK_EXPECTED_METHOD("OleObject_Advise");
331 static HRESULT WINAPI OleObject_Unadvise
337 CHECK_EXPECTED_METHOD("OleObject_Unadvise");
341 static HRESULT WINAPI OleObject_EnumAdvise
344 IEnumSTATDATA **ppenumAdvise
347 CHECK_EXPECTED_METHOD("OleObject_EnumAdvise");
351 static HRESULT WINAPI OleObject_GetMiscStatus
358 CHECK_EXPECTED_METHOD("OleObject_GetMiscStatus");
359 if(!g_failGetMiscStatus)
361 *pdwStatus = OLEMISC_RECOMPOSEONRESIZE;
371 static HRESULT WINAPI OleObject_SetColorScheme
377 CHECK_EXPECTED_METHOD("OleObject_SetColorScheme");
381 static const IOleObjectVtbl OleObjectVtbl =
383 OleObject_QueryInterface,
386 OleObject_SetClientSite,
387 OleObject_GetClientSite,
388 OleObject_SetHostNames,
390 OleObject_SetMoniker,
391 OleObject_GetMoniker,
392 OleObject_InitFromData,
393 OleObject_GetClipboardData,
397 OleObject_IsUpToDate,
398 OleObject_GetUserClassID,
399 OleObject_GetUserType,
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");
423 static ULONG WINAPI OleObjectPersistStg_Release(IPersistStorage *iface)
425 CHECK_EXPECTED_METHOD("OleObjectPersistStg_Release");
429 static HRESULT WINAPI OleObjectPersistStg_GetClassId(IPersistStorage *iface, CLSID *clsid)
431 CHECK_EXPECTED_METHOD("OleObjectPersistStg_GetClassId");
435 static HRESULT WINAPI OleObjectPersistStg_IsDirty
437 IPersistStorage *iface
440 CHECK_EXPECTED_METHOD("OleObjectPersistStg_IsDirty");
444 static HRESULT WINAPI OleObjectPersistStg_InitNew
446 IPersistStorage *iface,
450 CHECK_EXPECTED_METHOD("OleObjectPersistStg_InitNew");
454 static HRESULT WINAPI OleObjectPersistStg_Load
456 IPersistStorage *iface,
460 CHECK_EXPECTED_METHOD("OleObjectPersistStg_Load");
464 static HRESULT WINAPI OleObjectPersistStg_Save
466 IPersistStorage *iface,
471 CHECK_EXPECTED_METHOD("OleObjectPersistStg_Save");
475 static HRESULT WINAPI OleObjectPersistStg_SaveCompleted
477 IPersistStorage *iface,
481 CHECK_EXPECTED_METHOD("OleObjectPersistStg_SaveCompleted");
485 static HRESULT WINAPI OleObjectPersistStg_HandsOffStorage
487 IPersistStorage *iface
490 CHECK_EXPECTED_METHOD("OleObjectPersistStg_HandsOffStorage");
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");
521 static ULONG WINAPI OleObjectCache_Release(IOleCache *iface)
523 CHECK_EXPECTED_METHOD("OleObjectCache_Release");
527 static HRESULT WINAPI OleObjectCache_Cache
530 FORMATETC *pformatetc,
535 CHECK_EXPECTED_METHOD("OleObjectCache_Cache");
536 if (g_expected_fetc) {
537 ok(pformatetc != NULL, "pformatetc should not be NULL\n");
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);
551 ok(pformatetc == NULL, "pformatetc should be NULL\n");
555 static HRESULT WINAPI OleObjectCache_Uncache
561 CHECK_EXPECTED_METHOD("OleObjectCache_Uncache");
565 static HRESULT WINAPI OleObjectCache_EnumCache
568 IEnumSTATDATA **ppenumSTATDATA
571 CHECK_EXPECTED_METHOD("OleObjectCache_EnumCache");
576 static HRESULT WINAPI OleObjectCache_InitCache
579 IDataObject *pDataObject
582 CHECK_EXPECTED_METHOD("OleObjectCache_InitCache");
587 static HRESULT WINAPI OleObjectCache_SetData
590 FORMATETC *pformatetc,
595 CHECK_EXPECTED_METHOD("OleObjectCache_SetData");
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))
619 IClassFactory_AddRef(iface);
623 return E_NOINTERFACE;
626 static ULONG WINAPI OleObjectCF_AddRef(IClassFactory *iface)
631 static ULONG WINAPI OleObjectCF_Release(IClassFactory *iface)
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)
646 static const IClassFactoryVtbl OleObjectCFVtbl =
648 OleObjectCF_QueryInterface,
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");
668 static ULONG WINAPI OleObjectRunnable_Release(IRunnableObject *iface)
670 CHECK_EXPECTED_METHOD("OleObjectRunnable_Release");
674 static HRESULT WINAPI OleObjectRunnable_GetRunningClass(
675 IRunnableObject *iface,
678 CHECK_EXPECTED_METHOD("OleObjectRunnable_GetRunningClass");
682 static HRESULT WINAPI OleObjectRunnable_Run(
683 IRunnableObject *iface,
686 CHECK_EXPECTED_METHOD("OleObjectRunnable_Run");
690 static BOOL WINAPI OleObjectRunnable_IsRunning(IRunnableObject *iface)
692 CHECK_EXPECTED_METHOD("OleObjectRunnable_IsRunning");
696 static HRESULT WINAPI OleObjectRunnable_LockRunning(
697 IRunnableObject *iface,
699 BOOL fLastUnlockCloses)
701 CHECK_EXPECTED_METHOD("OleObjectRunnable_LockRunning");
705 static HRESULT WINAPI OleObjectRunnable_SetContainedObject(
706 IRunnableObject *iface,
709 CHECK_EXPECTED_METHOD("OleObjectRunnable_SetContainedObject");
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 HRESULT WINAPI viewobject_QueryInterface(IViewObject *iface, REFIID riid, void **obj)
731 if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IViewObject))
738 return E_NOINTERFACE;
741 static ULONG WINAPI viewobject_AddRef(IViewObject *iface)
746 static ULONG WINAPI viewobject_Release(IViewObject *iface)
751 static HRESULT WINAPI viewobject_Draw(IViewObject *iface, DWORD aspect, LONG index,
752 void *paspect, DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw,
753 LPCRECTL bounds, LPCRECTL wbounds, BOOL (STDMETHODCALLTYPE *pfnContinue)(ULONG_PTR dwContinue),
754 ULONG_PTR dwContinue)
756 ok(index == -1, "index=%d\n", index);
760 static HRESULT WINAPI viewobject_GetColorSet(IViewObject *iface, DWORD draw_aspect, LONG index,
761 void *aspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **colorset)
763 ok(0, "unexpected call GetColorSet\n");
767 static HRESULT WINAPI viewobject_Freeze(IViewObject *iface, DWORD draw_aspect, LONG index,
768 void *aspect, DWORD *freeze)
770 ok(0, "unexpected call Freeze\n");
774 static HRESULT WINAPI viewobject_Unfreeze(IViewObject *iface, DWORD freeze)
776 ok(0, "unexpected call Unfreeze\n");
780 static HRESULT WINAPI viewobject_SetAdvise(IViewObject *iface, DWORD aspects, DWORD advf, IAdviseSink *sink)
782 ok(0, "unexpected call SetAdvise\n");
786 static HRESULT WINAPI viewobject_GetAdvise(IViewObject *iface, DWORD *aspects, DWORD *advf,
789 ok(0, "unexpected call GetAdvise\n");
793 static const struct IViewObjectVtbl viewobjectvtbl = {
794 viewobject_QueryInterface,
798 viewobject_GetColorSet,
801 viewobject_SetAdvise,
805 static IViewObject viewobject = { &viewobjectvtbl };
807 static void test_OleCreate(IStorage *pStorage)
812 static const struct expected_method methods_olerender_none[] =
814 { "OleObject_QueryInterface", 0 },
815 { "OleObject_AddRef", 0 },
816 { "OleObject_QueryInterface", 0 },
817 { "OleObject_AddRef", TEST_OPTIONAL },
818 { "OleObject_Release", TEST_OPTIONAL },
819 { "OleObject_QueryInterface", TEST_OPTIONAL },
820 { "OleObjectPersistStg_AddRef", 0 },
821 { "OleObjectPersistStg_InitNew", 0 },
822 { "OleObjectPersistStg_Release", 0 },
823 { "OleObject_Release", 0 },
824 { "OleObject_Release", TEST_OPTIONAL },
827 static const struct expected_method methods_olerender_draw[] =
829 { "OleObject_QueryInterface", 0 },
830 { "OleObject_AddRef", 0 },
831 { "OleObject_QueryInterface", 0 },
832 { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
833 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
834 { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
835 { "OleObjectPersistStg_AddRef", 0 },
836 { "OleObjectPersistStg_InitNew", 0 },
837 { "OleObjectPersistStg_Release", 0 },
838 { "OleObject_QueryInterface", 0 },
839 { "OleObjectRunnable_AddRef", 0 },
840 { "OleObjectRunnable_Run", 0 },
841 { "OleObjectRunnable_Release", 0 },
842 { "OleObject_QueryInterface", 0 },
843 { "OleObjectCache_AddRef", 0 },
844 { "OleObjectCache_Cache", 0 },
845 { "OleObjectCache_Release", 0 },
846 { "OleObject_Release", 0 },
847 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
850 static const struct expected_method methods_olerender_format[] =
852 { "OleObject_QueryInterface", 0 },
853 { "OleObject_AddRef", 0 },
854 { "OleObject_QueryInterface", 0 },
855 { "OleObject_AddRef", 0 },
856 { "OleObject_GetMiscStatus", 0 },
857 { "OleObject_QueryInterface", 0 },
858 { "OleObjectPersistStg_AddRef", 0 },
859 { "OleObjectPersistStg_InitNew", 0 },
860 { "OleObjectPersistStg_Release", 0 },
861 { "OleObject_SetClientSite", 0 },
862 { "OleObject_Release", 0 },
863 { "OleObject_QueryInterface", 0 },
864 { "OleObjectRunnable_AddRef", 0 },
865 { "OleObjectRunnable_Run", 0 },
866 { "OleObjectRunnable_Release", 0 },
867 { "OleObject_QueryInterface", 0 },
868 { "OleObjectCache_AddRef", 0 },
869 { "OleObjectCache_Cache", 0 },
870 { "OleObjectCache_Release", 0 },
871 { "OleObject_Release", 0 },
874 static const struct expected_method methods_olerender_asis[] =
876 { "OleObject_QueryInterface", 0 },
877 { "OleObject_AddRef", 0 },
878 { "OleObject_QueryInterface", 0 },
879 { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
880 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
881 { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
882 { "OleObjectPersistStg_AddRef", 0 },
883 { "OleObjectPersistStg_InitNew", 0 },
884 { "OleObjectPersistStg_Release", 0 },
885 { "OleObject_Release", 0 },
886 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
889 static const struct expected_method methods_olerender_draw_no_runnable[] =
891 { "OleObject_QueryInterface", 0 },
892 { "OleObject_AddRef", 0 },
893 { "OleObject_QueryInterface", 0 },
894 { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
895 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
896 { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
897 { "OleObjectPersistStg_AddRef", 0 },
898 { "OleObjectPersistStg_InitNew", 0 },
899 { "OleObjectPersistStg_Release", 0 },
900 { "OleObject_QueryInterface", 0 },
901 { "OleObject_QueryInterface", 0 },
902 { "OleObjectCache_AddRef", 0 },
903 { "OleObjectCache_Cache", 0 },
904 { "OleObjectCache_Release", 0 },
905 { "OleObject_Release", 0 },
906 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
909 static const struct expected_method methods_olerender_draw_no_cache[] =
911 { "OleObject_QueryInterface", 0 },
912 { "OleObject_AddRef", 0 },
913 { "OleObject_QueryInterface", 0 },
914 { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
915 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
916 { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
917 { "OleObjectPersistStg_AddRef", 0 },
918 { "OleObjectPersistStg_InitNew", 0 },
919 { "OleObjectPersistStg_Release", 0 },
920 { "OleObject_QueryInterface", 0 },
921 { "OleObjectRunnable_AddRef", 0 },
922 { "OleObjectRunnable_Run", 0 },
923 { "OleObjectRunnable_Release", 0 },
924 { "OleObject_QueryInterface", 0 },
925 { "OleObject_Release", 0 },
926 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
930 g_expected_fetc = &formatetc;
931 formatetc.cfFormat = 0;
932 formatetc.ptd = NULL;
933 formatetc.dwAspect = DVASPECT_CONTENT;
934 formatetc.lindex = -1;
935 formatetc.tymed = TYMED_NULL;
936 runnable = &OleObjectRunnable;
937 cache = &OleObjectCache;
938 expected_method_list = methods_olerender_none;
939 trace("OleCreate with OLERENDER_NONE:\n");
940 hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_NONE, NULL, NULL, pStorage, (void **)&pObject);
941 ok_ole_success(hr, "OleCreate");
942 IOleObject_Release(pObject);
943 CHECK_NO_EXTRA_METHODS();
945 expected_method_list = methods_olerender_draw;
946 trace("OleCreate with OLERENDER_DRAW:\n");
947 hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject);
948 ok_ole_success(hr, "OleCreate");
949 IOleObject_Release(pObject);
950 CHECK_NO_EXTRA_METHODS();
952 formatetc.cfFormat = CF_TEXT;
953 formatetc.ptd = NULL;
954 formatetc.dwAspect = DVASPECT_CONTENT;
955 formatetc.lindex = -1;
956 formatetc.tymed = TYMED_HGLOBAL;
957 expected_method_list = methods_olerender_format;
958 trace("OleCreate with OLERENDER_FORMAT:\n");
959 hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_FORMAT, &formatetc, (IOleClientSite *)0xdeadbeef, pStorage, (void **)&pObject);
961 broken(hr == E_INVALIDARG), /* win2k */
962 "OleCreate failed with error 0x%08x\n", hr);
965 IOleObject_Release(pObject);
966 CHECK_NO_EXTRA_METHODS();
969 expected_method_list = methods_olerender_asis;
970 trace("OleCreate with OLERENDER_ASIS:\n");
971 hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_ASIS, NULL, NULL, pStorage, (void **)&pObject);
972 ok_ole_success(hr, "OleCreate");
973 IOleObject_Release(pObject);
974 CHECK_NO_EXTRA_METHODS();
976 formatetc.cfFormat = 0;
977 formatetc.tymed = TYMED_NULL;
979 expected_method_list = methods_olerender_draw_no_runnable;
980 trace("OleCreate with OLERENDER_DRAW (no IRunnableObject):\n");
981 hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject);
982 ok_ole_success(hr, "OleCreate");
983 IOleObject_Release(pObject);
984 CHECK_NO_EXTRA_METHODS();
986 runnable = &OleObjectRunnable;
988 expected_method_list = methods_olerender_draw_no_cache;
989 trace("OleCreate with OLERENDER_DRAW (no IOleCache):\n");
990 hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject);
991 ok_ole_success(hr, "OleCreate");
992 IOleObject_Release(pObject);
993 CHECK_NO_EXTRA_METHODS();
995 g_expected_fetc = NULL;
998 static void test_OleLoad(IStorage *pStorage)
1001 IOleObject *pObject;
1003 static const struct expected_method methods_oleload[] =
1005 { "OleObject_QueryInterface", 0 },
1006 { "OleObject_AddRef", 0 },
1007 { "OleObject_QueryInterface", 0 },
1008 { "OleObject_AddRef", 0 },
1009 { "OleObject_GetMiscStatus", 0 },
1010 { "OleObject_QueryInterface", 0 },
1011 { "OleObjectPersistStg_AddRef", 0 },
1012 { "OleObjectPersistStg_Load", 0 },
1013 { "OleObjectPersistStg_Release", 0 },
1014 { "OleObject_SetClientSite", 0 },
1015 { "OleObject_Release", 0 },
1016 { "OleObject_QueryInterface", 0 },
1017 { "OleObject_GetMiscStatus", 0 },
1018 { "OleObject_Release", 0 },
1022 /* Test once with IOleObject_GetMiscStatus failing */
1023 expected_method_list = methods_oleload;
1024 g_failGetMiscStatus = TRUE;
1025 trace("OleLoad:\n");
1026 hr = OleLoad(pStorage, &IID_IOleObject, (IOleClientSite *)0xdeadbeef, (void **)&pObject);
1028 broken(hr == E_INVALIDARG), /* win98 and win2k */
1029 "OleLoad failed with error 0x%08x\n", hr);
1032 DWORD dwStatus = 0xdeadbeef;
1033 hr = IOleObject_GetMiscStatus(pObject, DVASPECT_CONTENT, &dwStatus);
1034 ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1035 ok(dwStatus == 0x1234, "Got 0x%08x\n", dwStatus);
1037 IOleObject_Release(pObject);
1038 CHECK_NO_EXTRA_METHODS();
1041 /* Test again, let IOleObject_GetMiscStatus succeed. */
1042 g_failGetMiscStatus = FALSE;
1043 expected_method_list = methods_oleload;
1044 trace("OleLoad:\n");
1045 hr = OleLoad(pStorage, &IID_IOleObject, (IOleClientSite *)0xdeadbeef, (void **)&pObject);
1047 broken(hr == E_INVALIDARG), /* win98 and win2k */
1048 "OleLoad failed with error 0x%08x\n", hr);
1051 DWORD dwStatus = 0xdeadbeef;
1052 hr = IOleObject_GetMiscStatus(pObject, DVASPECT_CONTENT, &dwStatus);
1053 ok(hr == S_OK, "Got 0x%08x\n", hr);
1054 ok(dwStatus == 1, "Got 0x%08x\n", dwStatus);
1056 IOleObject_Release(pObject);
1057 CHECK_NO_EXTRA_METHODS();
1061 static BOOL STDMETHODCALLTYPE draw_continue(ULONG_PTR param)
1063 CHECK_EXPECTED_METHOD("draw_continue");
1067 static BOOL STDMETHODCALLTYPE draw_continue_false(ULONG_PTR param)
1069 CHECK_EXPECTED_METHOD("draw_continue_false");
1073 static HRESULT WINAPI AdviseSink_QueryInterface(IAdviseSink *iface, REFIID riid, void **ppv)
1075 if (IsEqualIID(riid, &IID_IAdviseSink) || IsEqualIID(riid, &IID_IUnknown))
1078 IAdviseSink_AddRef(iface);
1082 return E_NOINTERFACE;
1085 static ULONG WINAPI AdviseSink_AddRef(IAdviseSink *iface)
1090 static ULONG WINAPI AdviseSink_Release(IAdviseSink *iface)
1096 static void WINAPI AdviseSink_OnDataChange(
1098 FORMATETC *pFormatetc,
1101 CHECK_EXPECTED_METHOD("AdviseSink_OnDataChange");
1104 static void WINAPI AdviseSink_OnViewChange(
1109 CHECK_EXPECTED_METHOD("AdviseSink_OnViewChange");
1112 static void WINAPI AdviseSink_OnRename(
1116 CHECK_EXPECTED_METHOD("AdviseSink_OnRename");
1119 static void WINAPI AdviseSink_OnSave(IAdviseSink *iface)
1121 CHECK_EXPECTED_METHOD("AdviseSink_OnSave");
1124 static void WINAPI AdviseSink_OnClose(IAdviseSink *iface)
1126 CHECK_EXPECTED_METHOD("AdviseSink_OnClose");
1129 static const IAdviseSinkVtbl AdviseSinkVtbl =
1131 AdviseSink_QueryInterface,
1134 AdviseSink_OnDataChange,
1135 AdviseSink_OnViewChange,
1136 AdviseSink_OnRename,
1141 static IAdviseSink AdviseSink = { &AdviseSinkVtbl };
1143 static HRESULT WINAPI DataObject_QueryInterface(
1148 CHECK_EXPECTED_METHOD("DataObject_QueryInterface");
1150 if (IsEqualIID(riid, &IID_IDataObject) || IsEqualIID(riid, &IID_IUnknown))
1159 static ULONG WINAPI DataObject_AddRef(
1162 CHECK_EXPECTED_METHOD("DataObject_AddRef");
1166 static ULONG WINAPI DataObject_Release(
1169 CHECK_EXPECTED_METHOD("DataObject_Release");
1173 static HRESULT WINAPI DataObject_GetData(
1175 LPFORMATETC pformatetcIn,
1178 CHECK_EXPECTED_METHOD("DataObject_GetData");
1182 static HRESULT WINAPI DataObject_GetDataHere(
1184 LPFORMATETC pformatetc,
1187 CHECK_EXPECTED_METHOD("DataObject_GetDataHere");
1191 static HRESULT WINAPI DataObject_QueryGetData(
1193 LPFORMATETC pformatetc)
1195 CHECK_EXPECTED_METHOD("DataObject_QueryGetData");
1199 static HRESULT WINAPI DataObject_GetCanonicalFormatEtc(
1201 LPFORMATETC pformatectIn,
1202 LPFORMATETC pformatetcOut)
1204 CHECK_EXPECTED_METHOD("DataObject_GetCanonicalFormatEtc");
1208 static HRESULT WINAPI DataObject_SetData(
1210 LPFORMATETC pformatetc,
1214 CHECK_EXPECTED_METHOD("DataObject_SetData");
1218 static HRESULT WINAPI DataObject_EnumFormatEtc(
1221 IEnumFORMATETC** ppenumFormatEtc)
1223 CHECK_EXPECTED_METHOD("DataObject_EnumFormatEtc");
1227 static HRESULT WINAPI DataObject_DAdvise(
1229 FORMATETC* pformatetc,
1231 IAdviseSink* pAdvSink,
1232 DWORD* pdwConnection)
1234 STGMEDIUM stgmedium;
1236 CHECK_EXPECTED_METHOD("DataObject_DAdvise");
1239 if(advf & ADVF_PRIMEFIRST)
1241 ok(pformatetc->cfFormat == cf_test_2, "got %04x\n", pformatetc->cfFormat);
1242 stgmedium.tymed = TYMED_HGLOBAL;
1243 U(stgmedium).hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, 4);
1244 stgmedium.pUnkForRelease = NULL;
1245 IAdviseSink_OnDataChange(pAdvSink, pformatetc, &stgmedium);
1251 static HRESULT WINAPI DataObject_DUnadvise(
1255 CHECK_EXPECTED_METHOD("DataObject_DUnadvise");
1259 static HRESULT WINAPI DataObject_EnumDAdvise(
1261 IEnumSTATDATA** ppenumAdvise)
1263 CHECK_EXPECTED_METHOD("DataObject_EnumDAdvise");
1264 return OLE_E_ADVISENOTSUPPORTED;
1267 static IDataObjectVtbl DataObjectVtbl =
1269 DataObject_QueryInterface,
1273 DataObject_GetDataHere,
1274 DataObject_QueryGetData,
1275 DataObject_GetCanonicalFormatEtc,
1277 DataObject_EnumFormatEtc,
1279 DataObject_DUnadvise,
1280 DataObject_EnumDAdvise
1283 static IDataObject DataObject = { &DataObjectVtbl };
1285 static void test_data_cache(void)
1288 IOleCache2 *pOleCache;
1290 IPersistStorage *pPS;
1291 IViewObject *pViewObject;
1292 IOleCacheControl *pOleCacheControl;
1293 IDataObject *pCacheDataObject;
1295 STGMEDIUM stgmedium;
1301 char szSystemDir[MAX_PATH];
1302 WCHAR wszPath[MAX_PATH];
1303 static const WCHAR wszShell32[] = {'\\','s','h','e','l','l','3','2','.','d','l','l',0};
1305 static const struct expected_method methods_cacheinitnew[] =
1307 { "AdviseSink_OnViewChange", 0 },
1308 { "AdviseSink_OnViewChange", 0 },
1309 { "draw_continue", 1 },
1310 { "draw_continue_false", 1 },
1311 { "DataObject_DAdvise", 0 },
1312 { "DataObject_DAdvise", 0 },
1313 { "DataObject_DUnadvise", 0 },
1314 { "DataObject_DUnadvise", 0 },
1317 static const struct expected_method methods_cacheload[] =
1319 { "AdviseSink_OnViewChange", 0 },
1320 { "draw_continue", 1 },
1321 { "draw_continue", 1 },
1322 { "draw_continue", 1 },
1323 { "DataObject_GetData", 0 },
1324 { "DataObject_GetData", 0 },
1325 { "DataObject_GetData", 0 },
1328 static const struct expected_method methods_cachethenrun[] =
1330 { "DataObject_DAdvise", 0 },
1331 { "DataObject_DAdvise", 0 },
1332 { "DataObject_DAdvise", 0 },
1333 { "DataObject_QueryGetData", 1 }, /* called by win9x and nt4 */
1334 { "DataObject_DAdvise", 0 },
1335 { "DataObject_DUnadvise", 0 },
1336 { "DataObject_DUnadvise", 0 },
1337 { "DataObject_DUnadvise", 0 },
1338 { "DataObject_DUnadvise", 0 },
1342 GetSystemDirectory(szSystemDir, sizeof(szSystemDir)/sizeof(szSystemDir[0]));
1344 expected_method_list = methods_cacheinitnew;
1346 fmtetc.cfFormat = CF_METAFILEPICT;
1347 fmtetc.dwAspect = DVASPECT_ICON;
1350 fmtetc.tymed = TYMED_MFPICT;
1352 hr = StgCreateDocfile(NULL, STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_DELETEONRELEASE, 0, &pStorage);
1353 ok_ole_success(hr, "StgCreateDocfile");
1355 /* Test with new data */
1357 hr = CreateDataCache(NULL, &CLSID_NULL, &IID_IOleCache2, (LPVOID *)&pOleCache);
1358 ok_ole_success(hr, "CreateDataCache");
1360 hr = IOleCache2_QueryInterface(pOleCache, &IID_IPersistStorage, (LPVOID *)&pPS);
1361 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IPersistStorage)");
1362 hr = IOleCache2_QueryInterface(pOleCache, &IID_IViewObject, (LPVOID *)&pViewObject);
1363 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IViewObject)");
1364 hr = IOleCache2_QueryInterface(pOleCache, &IID_IOleCacheControl, (LPVOID *)&pOleCacheControl);
1365 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IOleCacheControl)");
1367 hr = IViewObject_SetAdvise(pViewObject, DVASPECT_ICON, ADVF_PRIMEFIRST, &AdviseSink);
1368 ok_ole_success(hr, "IViewObject_SetAdvise");
1370 hr = IPersistStorage_InitNew(pPS, pStorage);
1371 ok_ole_success(hr, "IPersistStorage_InitNew");
1373 hr = IPersistStorage_IsDirty(pPS);
1374 ok_ole_success(hr, "IPersistStorage_IsDirty");
1376 hr = IPersistStorage_GetClassID(pPS, &clsid);
1377 ok_ole_success(hr, "IPersistStorage_GetClassID");
1378 ok(IsEqualCLSID(&clsid, &IID_NULL), "clsid should be blank\n");
1380 hr = IOleCache2_Uncache(pOleCache, 0xdeadbeef);
1381 ok(hr == OLE_E_NOCONNECTION, "IOleCache_Uncache with invalid value should return OLE_E_NOCONNECTION instead of 0x%x\n", hr);
1383 /* Both tests crash on NT4 and below. StgCreatePropSetStg is only available on w2k and above. */
1384 if (GetProcAddress(GetModuleHandleA("ole32.dll"), "StgCreatePropSetStg"))
1386 hr = IOleCache2_Cache(pOleCache, NULL, 0, &dwConnection);
1387 ok(hr == E_INVALIDARG, "IOleCache_Cache with NULL fmtetc should have returned E_INVALIDARG instead of 0x%08x\n", hr);
1389 hr = IOleCache2_Cache(pOleCache, NULL, 0, NULL);
1390 ok(hr == E_INVALIDARG, "IOleCache_Cache with NULL pdwConnection should have returned E_INVALIDARG instead of 0x%08x\n", hr);
1394 skip("tests with NULL parameters will crash on NT4 and below\n");
1397 for (fmtetc.cfFormat = CF_TEXT; fmtetc.cfFormat < CF_MAX; fmtetc.cfFormat++)
1400 fmtetc.dwAspect = DVASPECT_THUMBNAIL;
1401 for (i = 0; i < 7; i++)
1403 fmtetc.tymed = 1 << i;
1404 hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1405 if ((fmtetc.cfFormat == CF_METAFILEPICT && fmtetc.tymed == TYMED_MFPICT) ||
1406 (fmtetc.cfFormat == CF_BITMAP && fmtetc.tymed == TYMED_GDI) ||
1407 (fmtetc.cfFormat == CF_DIB && fmtetc.tymed == TYMED_HGLOBAL) ||
1408 (fmtetc.cfFormat == CF_ENHMETAFILE && fmtetc.tymed == TYMED_ENHMF))
1409 ok(hr == S_OK, "IOleCache_Cache cfFormat = %d, tymed = %d should have returned S_OK instead of 0x%08x\n",
1410 fmtetc.cfFormat, fmtetc.tymed, hr);
1411 else if (fmtetc.tymed == TYMED_HGLOBAL)
1412 ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED ||
1413 broken(hr == S_OK && fmtetc.cfFormat == CF_BITMAP) /* Win9x & NT4 */,
1414 "IOleCache_Cache cfFormat = %d, tymed = %d should have returned CACHE_S_FORMATETC_NOTSUPPORTED instead of 0x%08x\n",
1415 fmtetc.cfFormat, fmtetc.tymed, hr);
1417 ok(hr == DV_E_TYMED, "IOleCache_Cache cfFormat = %d, tymed = %d should have returned DV_E_TYMED instead of 0x%08x\n",
1418 fmtetc.cfFormat, fmtetc.tymed, hr);
1421 hr = IOleCache2_Uncache(pOleCache, dwConnection);
1422 ok_ole_success(hr, "IOleCache_Uncache");
1427 fmtetc.cfFormat = CF_BITMAP;
1428 fmtetc.dwAspect = DVASPECT_THUMBNAIL;
1429 fmtetc.tymed = TYMED_GDI;
1430 hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1431 ok_ole_success(hr, "IOleCache_Cache");
1433 fmtetc.cfFormat = 0;
1434 fmtetc.dwAspect = DVASPECT_ICON;
1435 fmtetc.tymed = TYMED_MFPICT;
1436 hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1437 ok_ole_success(hr, "IOleCache_Cache");
1439 MultiByteToWideChar(CP_ACP, 0, szSystemDir, -1, wszPath, sizeof(wszPath)/sizeof(wszPath[0]));
1440 memcpy(wszPath+lstrlenW(wszPath), wszShell32, sizeof(wszShell32));
1442 fmtetc.cfFormat = CF_METAFILEPICT;
1443 stgmedium.tymed = TYMED_MFPICT;
1444 U(stgmedium).hMetaFilePict = OleMetafilePictFromIconAndLabel(
1445 LoadIcon(NULL, IDI_APPLICATION), wszPath, wszPath, 0);
1446 stgmedium.pUnkForRelease = NULL;
1448 fmtetc.dwAspect = DVASPECT_CONTENT;
1449 hr = IOleCache2_SetData(pOleCache, &fmtetc, &stgmedium, FALSE);
1450 ok(hr == OLE_E_BLANK, "IOleCache_SetData for aspect not in cache should have return OLE_E_BLANK instead of 0x%08x\n", hr);
1452 fmtetc.dwAspect = DVASPECT_ICON;
1453 hr = IOleCache2_SetData(pOleCache, &fmtetc, &stgmedium, FALSE);
1454 ok_ole_success(hr, "IOleCache_SetData");
1455 ReleaseStgMedium(&stgmedium);
1457 hr = IViewObject_Freeze(pViewObject, DVASPECT_ICON, -1, NULL, &dwFreeze);
1459 ok_ole_success(hr, "IViewObject_Freeze");
1460 hr = IViewObject_Freeze(pViewObject, DVASPECT_CONTENT, -1, NULL, &dwFreeze);
1461 ok(hr == OLE_E_BLANK, "IViewObject_Freeze with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1466 rcBounds.right = 100;
1467 rcBounds.bottom = 100;
1468 hdcMem = CreateCompatibleDC(NULL);
1470 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1471 ok_ole_success(hr, "IViewObject_Draw");
1473 hr = IViewObject_Draw(pViewObject, DVASPECT_CONTENT, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1474 ok(hr == OLE_E_BLANK, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1476 /* a NULL draw_continue fn ptr */
1477 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, NULL, 0xdeadbeef);
1478 ok_ole_success(hr, "IViewObject_Draw");
1480 /* draw_continue that returns FALSE to abort drawing */
1481 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue_false, 0xdeadbeef);
1483 broken(hr == S_OK), /* win9x may skip the callbacks */
1484 "IViewObject_Draw with draw_continue_false returns 0x%08x\n", hr);
1488 hr = IOleCacheControl_OnRun(pOleCacheControl, &DataObject);
1489 ok_ole_success(hr, "IOleCacheControl_OnRun");
1491 hr = IPersistStorage_Save(pPS, pStorage, TRUE);
1492 ok_ole_success(hr, "IPersistStorage_Save");
1494 hr = IPersistStorage_SaveCompleted(pPS, NULL);
1495 ok_ole_success(hr, "IPersistStorage_SaveCompleted");
1497 hr = IPersistStorage_IsDirty(pPS);
1498 ok(hr == S_FALSE, "IPersistStorage_IsDirty should have returned S_FALSE instead of 0x%x\n", hr);
1500 IPersistStorage_Release(pPS);
1501 IViewObject_Release(pViewObject);
1502 IOleCache2_Release(pOleCache);
1503 IOleCacheControl_Release(pOleCacheControl);
1505 CHECK_NO_EXTRA_METHODS();
1507 /* Test with loaded data */
1508 trace("Testing loaded data with CreateDataCache:\n");
1509 expected_method_list = methods_cacheload;
1511 hr = CreateDataCache(NULL, &CLSID_NULL, &IID_IOleCache2, (LPVOID *)&pOleCache);
1512 ok_ole_success(hr, "CreateDataCache");
1514 hr = IOleCache2_QueryInterface(pOleCache, &IID_IPersistStorage, (LPVOID *)&pPS);
1515 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IPersistStorage)");
1516 hr = IOleCache2_QueryInterface(pOleCache, &IID_IViewObject, (LPVOID *)&pViewObject);
1517 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IViewObject)");
1519 hr = IViewObject_SetAdvise(pViewObject, DVASPECT_ICON, ADVF_PRIMEFIRST, &AdviseSink);
1520 ok_ole_success(hr, "IViewObject_SetAdvise");
1522 hr = IPersistStorage_Load(pPS, pStorage);
1523 ok_ole_success(hr, "IPersistStorage_Load");
1525 hr = IPersistStorage_IsDirty(pPS);
1526 ok(hr == S_FALSE, "IPersistStorage_IsDirty should have returned S_FALSE instead of 0x%x\n", hr);
1528 fmtetc.cfFormat = 0;
1529 fmtetc.dwAspect = DVASPECT_ICON;
1532 fmtetc.tymed = TYMED_MFPICT;
1533 hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1534 ok(hr == CACHE_S_SAMECACHE, "IOleCache_Cache with already loaded data format type should return CACHE_S_SAMECACHE instead of 0x%x\n", hr);
1538 rcBounds.right = 100;
1539 rcBounds.bottom = 100;
1540 hdcMem = CreateCompatibleDC(NULL);
1542 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1543 ok_ole_success(hr, "IViewObject_Draw");
1545 hr = IViewObject_Draw(pViewObject, DVASPECT_CONTENT, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1546 ok(hr == OLE_E_BLANK, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1548 /* unload the cached storage object, causing it to be reloaded */
1549 hr = IOleCache2_DiscardCache(pOleCache, DISCARDCACHE_NOSAVE);
1550 ok_ole_success(hr, "IOleCache2_DiscardCache");
1551 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1552 ok_ole_success(hr, "IViewObject_Draw");
1554 /* unload the cached storage object, but don't allow it to be reloaded */
1555 hr = IPersistStorage_HandsOffStorage(pPS);
1556 ok_ole_success(hr, "IPersistStorage_HandsOffStorage");
1557 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1558 ok_ole_success(hr, "IViewObject_Draw");
1559 hr = IOleCache2_DiscardCache(pOleCache, DISCARDCACHE_NOSAVE);
1560 ok_ole_success(hr, "IOleCache2_DiscardCache");
1561 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1562 ok(hr == OLE_E_BLANK, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1567 hr = IOleCache2_InitCache(pOleCache, &DataObject);
1568 ok(hr == CACHE_E_NOCACHE_UPDATED, "IOleCache_InitCache should have returned CACHE_E_NOCACHE_UPDATED instead of 0x%08x\n", hr);
1571 IPersistStorage_Release(pPS);
1572 IViewObject_Release(pViewObject);
1573 IOleCache2_Release(pOleCache);
1576 CHECK_NO_EXTRA_METHODS();
1579 hr = CreateDataCache(NULL, &CLSID_NULL, &IID_IOleCache2, (LPVOID *)&pOleCache);
1580 ok_ole_success(hr, "CreateDataCache");
1582 expected_method_list = methods_cachethenrun;
1584 hr = IOleCache2_QueryInterface(pOleCache, &IID_IDataObject, (LPVOID *)&pCacheDataObject);
1585 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IDataObject)");
1586 hr = IOleCache2_QueryInterface(pOleCache, &IID_IOleCacheControl, (LPVOID *)&pOleCacheControl);
1587 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IOleCacheControl)");
1589 fmtetc.cfFormat = CF_METAFILEPICT;
1590 fmtetc.dwAspect = DVASPECT_CONTENT;
1591 fmtetc.tymed = TYMED_MFPICT;
1593 hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1594 ok_ole_success(hr, "IOleCache_Cache");
1596 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1597 ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1599 fmtetc.cfFormat = cf_test_1;
1600 fmtetc.dwAspect = DVASPECT_CONTENT;
1601 fmtetc.tymed = TYMED_HGLOBAL;
1603 hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1604 ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED, "got %08x\n", hr);
1606 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1607 ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1609 fmtetc.cfFormat = cf_test_2;
1610 hr = IOleCache2_Cache(pOleCache, &fmtetc, ADVF_PRIMEFIRST, &dwConnection);
1611 ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED, "got %08x\n", hr);
1613 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1614 ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1616 hr = IOleCacheControl_OnRun(pOleCacheControl, &DataObject);
1617 ok_ole_success(hr, "IOleCacheControl_OnRun");
1619 fmtetc.cfFormat = cf_test_3;
1620 hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1621 ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED, "got %08x\n", hr);
1623 fmtetc.cfFormat = cf_test_1;
1624 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1625 ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1627 fmtetc.cfFormat = cf_test_2;
1628 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1629 ok(hr == S_OK, "got %08x\n", hr);
1630 ReleaseStgMedium(&stgmedium);
1632 fmtetc.cfFormat = cf_test_3;
1633 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1634 ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1636 IOleCacheControl_Release(pOleCacheControl);
1637 IDataObject_Release(pCacheDataObject);
1638 IOleCache2_Release(pOleCache);
1640 CHECK_NO_EXTRA_METHODS();
1642 IStorage_Release(pStorage);
1645 static void test_default_handler(void)
1648 IOleObject *pObject;
1649 IRunnableObject *pRunnableObject;
1650 IOleClientSite *pClientSite;
1651 IDataObject *pDataObject;
1655 LPOLESTR pszUserType;
1660 IOleInPlaceObject *pInPlaceObj;
1661 IEnumOLEVERB *pEnumVerbs;
1663 static const WCHAR wszUnknown[] = {'U','n','k','n','o','w','n',0};
1664 static const WCHAR wszHostName[] = {'W','i','n','e',' ','T','e','s','t',' ','P','r','o','g','r','a','m',0};
1665 static const WCHAR wszDelim[] = {'!',0};
1667 static const struct expected_method methods_embeddinghelper[] =
1669 { "OleObject_QueryInterface", 0 },
1670 { "OleObject_AddRef", 0 },
1671 { "OleObject_QueryInterface", 0 },
1672 { "OleObject_QueryInterface", TEST_TODO },
1673 { "OleObject_QueryInterface", 0 },
1674 { "OleObject_QueryInterface", 0 },
1675 { "OleObject_QueryInterface", TEST_OPTIONAL }, /* Win95/98/NT4 */
1676 { "OleObject_Release", TEST_TODO },
1677 { "WINE_EXTRA", TEST_OPTIONAL },
1681 hr = CoCreateInstance(&CLSID_WineTest, NULL, CLSCTX_INPROC_HANDLER, &IID_IOleObject, (void **)&pObject);
1682 ok(hr == REGDB_E_CLASSNOTREG, "CoCreateInstance should have failed with REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1684 hr = OleCreateDefaultHandler(&CLSID_WineTest, NULL, &IID_IOleObject, (void **)&pObject);
1685 ok_ole_success(hr, "OleCreateDefaultHandler");
1687 hr = IOleObject_QueryInterface(pObject, &IID_IOleInPlaceObject, (void **)&pInPlaceObj);
1688 ok(hr == E_NOINTERFACE, "IOleObject_QueryInterface(&IID_IOleInPlaceObject) should return E_NOINTERFACE instead of 0x%08x\n", hr);
1690 hr = IOleObject_Advise(pObject, &AdviseSink, &dwAdvConn);
1691 ok_ole_success(hr, "IOleObject_Advise");
1693 hr = IOleObject_Close(pObject, OLECLOSE_NOSAVE);
1694 ok_ole_success(hr, "IOleObject_Close");
1696 /* FIXME: test IOleObject_EnumAdvise */
1698 hr = IOleObject_EnumVerbs(pObject, &pEnumVerbs);
1699 ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_EnumVerbs should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1701 hr = IOleObject_GetClientSite(pObject, &pClientSite);
1702 ok_ole_success(hr, "IOleObject_GetClientSite");
1704 hr = IOleObject_GetClipboardData(pObject, 0, &pDataObject);
1705 ok(hr == OLE_E_NOTRUNNING,
1706 "IOleObject_GetClipboardData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n",
1709 hr = IOleObject_GetExtent(pObject, DVASPECT_CONTENT, &sizel);
1710 ok(hr == OLE_E_BLANK, "IOleObject_GetExtent should have returned OLE_E_BLANK instead of 0x%08x\n",
1713 hr = IOleObject_GetMiscStatus(pObject, DVASPECT_CONTENT, &dwStatus);
1714 ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_GetMiscStatus should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1716 hr = IOleObject_GetUserClassID(pObject, &clsid);
1717 ok_ole_success(hr, "IOleObject_GetUserClassID");
1718 ok(IsEqualCLSID(&clsid, &CLSID_WineTest), "clsid != CLSID_WineTest\n");
1720 hr = IOleObject_GetUserType(pObject, USERCLASSTYPE_FULL, &pszUserType);
1722 ok_ole_success(hr, "IOleObject_GetUserType");
1723 ok(!lstrcmpW(pszUserType, wszUnknown), "Retrieved user type was wrong\n");
1726 hr = IOleObject_InitFromData(pObject, NULL, TRUE, 0);
1727 ok(hr == OLE_E_NOTRUNNING, "IOleObject_InitFromData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1729 hr = IOleObject_IsUpToDate(pObject);
1730 ok(hr == OLE_E_NOTRUNNING, "IOleObject_IsUpToDate should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1732 palette.palNumEntries = 1;
1733 palette.palVersion = 2;
1734 memset(&palette.palPalEntry[0], 0, sizeof(palette.palPalEntry[0]));
1735 hr = IOleObject_SetColorScheme(pObject, &palette);
1736 ok(hr == OLE_E_NOTRUNNING, "IOleObject_SetColorScheme should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1738 sizel.cx = sizel.cy = 0;
1739 hr = IOleObject_SetExtent(pObject, DVASPECT_CONTENT, &sizel);
1740 ok(hr == OLE_E_NOTRUNNING, "IOleObject_SetExtent should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1742 hr = IOleObject_SetHostNames(pObject, wszHostName, NULL);
1743 ok_ole_success(hr, "IOleObject_SetHostNames");
1745 hr = CreateItemMoniker(wszDelim, wszHostName, &pMoniker);
1746 ok_ole_success(hr, "CreateItemMoniker");
1747 hr = IOleObject_SetMoniker(pObject, OLEWHICHMK_CONTAINER, pMoniker);
1748 ok_ole_success(hr, "IOleObject_SetMoniker");
1749 IMoniker_Release(pMoniker);
1751 hr = IOleObject_GetMoniker(pObject, OLEGETMONIKER_ONLYIFTHERE, OLEWHICHMK_CONTAINER, &pMoniker);
1752 ok(hr == E_FAIL, "IOleObject_GetMoniker should have returned E_FAIL instead of 0x%08x\n", hr);
1754 hr = IOleObject_Update(pObject);
1756 ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_Update should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1758 hr = IOleObject_QueryInterface(pObject, &IID_IDataObject, (void **)&pDataObject);
1759 ok_ole_success(hr, "IOleObject_QueryInterface");
1761 fmtetc.cfFormat = CF_TEXT;
1763 fmtetc.dwAspect = DVASPECT_CONTENT;
1765 fmtetc.tymed = TYMED_NULL;
1766 hr = IDataObject_DAdvise(pDataObject, &fmtetc, 0, &AdviseSink, &dwAdvConn);
1767 ok_ole_success(hr, "IDataObject_DAdvise");
1769 fmtetc.cfFormat = CF_ENHMETAFILE;
1771 fmtetc.dwAspect = DVASPECT_CONTENT;
1773 fmtetc.tymed = TYMED_ENHMF;
1774 hr = IDataObject_DAdvise(pDataObject, &fmtetc, 0, &AdviseSink, &dwAdvConn);
1775 ok_ole_success(hr, "IDataObject_DAdvise");
1777 fmtetc.cfFormat = CF_ENHMETAFILE;
1779 fmtetc.dwAspect = DVASPECT_CONTENT;
1781 fmtetc.tymed = TYMED_ENHMF;
1782 hr = IDataObject_QueryGetData(pDataObject, &fmtetc);
1784 ok(hr == OLE_E_NOTRUNNING, "IDataObject_QueryGetData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1786 fmtetc.cfFormat = CF_TEXT;
1788 fmtetc.dwAspect = DVASPECT_CONTENT;
1790 fmtetc.tymed = TYMED_NULL;
1791 hr = IDataObject_QueryGetData(pDataObject, &fmtetc);
1793 ok(hr == OLE_E_NOTRUNNING, "IDataObject_QueryGetData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1795 hr = IOleObject_QueryInterface(pObject, &IID_IRunnableObject, (void **)&pRunnableObject);
1796 ok_ole_success(hr, "IOleObject_QueryInterface");
1798 hr = IRunnableObject_SetContainedObject(pRunnableObject, TRUE);
1799 ok_ole_success(hr, "IRunnableObject_SetContainedObject");
1801 hr = IRunnableObject_Run(pRunnableObject, NULL);
1802 ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_Run should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1804 hr = IOleObject_Close(pObject, OLECLOSE_NOSAVE);
1805 ok_ole_success(hr, "IOleObject_Close");
1807 IRunnableObject_Release(pRunnableObject);
1808 IOleObject_Release(pObject);
1810 /* Test failure propagation from delegate ::QueryInterface */
1811 hr = CoRegisterClassObject(&CLSID_WineTest, (IUnknown*)&OleObjectCF,
1812 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &dwRegister);
1813 ok_ole_success(hr, "CoRegisterClassObject");
1816 expected_method_list = methods_embeddinghelper;
1817 hr = OleCreateEmbeddingHelper(&CLSID_WineTest, NULL, EMBDHLP_INPROC_SERVER,
1818 &OleObjectCF, &IID_IOleObject, (void**)&pObject);
1819 ok_ole_success(hr, "OleCreateEmbeddingHelper");
1824 g_QIFailsWith = E_FAIL;
1825 hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1826 ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1828 g_QIFailsWith = E_NOINTERFACE;
1829 hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1830 ok(hr == E_NOINTERFACE, "Got 0x%08x\n", hr);
1832 g_QIFailsWith = CO_E_OBJNOTCONNECTED;
1833 hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1834 ok(hr == CO_E_OBJNOTCONNECTED, "Got 0x%08x\n", hr);
1836 g_QIFailsWith = 0x87654321;
1837 hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1838 ok(hr == 0x87654321, "Got 0x%08x\n", hr);
1840 IOleObject_Release(pObject);
1843 CHECK_NO_EXTRA_METHODS();
1845 hr = CoRevokeClassObject(dwRegister);
1846 ok_ole_success(hr, "CoRevokeClassObject");
1850 static void test_runnable(void)
1852 static const struct expected_method methods_query_runnable[] =
1854 { "OleObject_QueryInterface", 0 },
1855 { "OleObjectRunnable_AddRef", 0 },
1856 { "OleObjectRunnable_IsRunning", 0 },
1857 { "OleObjectRunnable_Release", 0 },
1861 static const struct expected_method methods_no_runnable[] =
1863 { "OleObject_QueryInterface", 0 },
1868 IOleObject *object = &OleObject;
1871 ret = OleIsRunning(NULL);
1872 ok(ret == FALSE, "got %d\n", ret);
1874 expected_method_list = methods_query_runnable;
1875 ret = OleIsRunning(object);
1876 ok(ret == TRUE, "Object should be running\n");
1877 CHECK_NO_EXTRA_METHODS();
1879 g_isRunning = FALSE;
1880 expected_method_list = methods_query_runnable;
1881 ret = OleIsRunning(object);
1882 ok(ret == FALSE, "Object should not be running\n");
1883 CHECK_NO_EXTRA_METHODS();
1885 g_showRunnable = FALSE; /* QueryInterface(IID_IRunnableObject, ...) will fail */
1886 expected_method_list = methods_no_runnable;
1887 ret = OleIsRunning(object);
1888 ok(ret == TRUE, "Object without IRunnableObject should be running\n");
1889 CHECK_NO_EXTRA_METHODS();
1892 g_showRunnable = TRUE;
1895 static HRESULT WINAPI Unknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
1898 if (IsEqualIID(riid, &IID_IUnknown)) *ppv = iface;
1901 IUnknown_AddRef((IUnknown *)*ppv);
1904 return E_NOINTERFACE;
1907 static ULONG WINAPI Unknown_AddRef(IUnknown *iface)
1912 static ULONG WINAPI Unknown_Release(IUnknown *iface)
1917 static const IUnknownVtbl UnknownVtbl =
1919 Unknown_QueryInterface,
1924 static IUnknown unknown = { &UnknownVtbl };
1926 static void test_OleLockRunning(void)
1930 hr = OleLockRunning((LPUNKNOWN)&unknown, TRUE, FALSE);
1931 ok(hr == S_OK, "OleLockRunning failed 0x%08x\n", hr);
1934 static void test_OleDraw(void)
1939 hr = OleDraw((IUnknown*)&viewobject, 0, (HDC)0x1, NULL);
1940 ok(hr == S_OK, "got 0x%08x\n", hr);
1942 hr = OleDraw(NULL, 0, (HDC)0x1, NULL);
1943 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
1945 hr = OleDraw(NULL, 0, (HDC)0x1, &rect);
1946 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
1956 cf_test_1 = RegisterClipboardFormatA("cf_winetest_1");
1957 cf_test_2 = RegisterClipboardFormatA("cf_winetest_2");
1958 cf_test_3 = RegisterClipboardFormatA("cf_winetest_3");
1962 hr = CoRegisterClassObject(&CLSID_Equation3, (IUnknown *)&OleObjectCF, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &dwRegister);
1963 ok_ole_success(hr, "CoRegisterClassObject");
1965 hr = StgCreateDocfile(NULL, STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_DELETEONRELEASE, 0, &pStorage);
1966 ok_ole_success(hr, "StgCreateDocfile");
1968 test_OleCreate(pStorage);
1970 hr = IStorage_Stat(pStorage, &statstg, STATFLAG_NONAME);
1971 ok_ole_success(hr, "IStorage_Stat");
1972 ok(IsEqualCLSID(&CLSID_Equation3, &statstg.clsid), "Wrong CLSID in storage\n");
1974 test_OleLoad(pStorage);
1976 IStorage_Release(pStorage);
1978 hr = CoRevokeClassObject(dwRegister);
1979 ok_ole_success(hr, "CoRevokeClassObject");
1982 test_default_handler();
1984 test_OleLockRunning();