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
30 #include "wine/test.h"
32 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
34 static IPersistStorage OleObjectPersistStg
;
35 static IOleCache
*cache
;
36 static IRunnableObject
*runnable
;
38 static char const * const *expected_method_list
;
40 #define CHECK_EXPECTED_METHOD(method_name) \
42 trace("%s\n", method_name); \
43 ok(*expected_method_list != NULL, "Extra method %s called\n", method_name); \
44 if (*expected_method_list) \
46 ok(!strcmp(*expected_method_list, method_name), "Expected %s to be called instead of %s\n", \
47 *expected_method_list, method_name); \
48 expected_method_list++; \
52 static HRESULT WINAPI
OleObject_QueryInterface(IOleObject
*iface
, REFIID riid
, void **ppv
)
54 CHECK_EXPECTED_METHOD("OleObject_QueryInterface");
58 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IOleObject
))
60 else if (IsEqualIID(riid
, &IID_IPersistStorage
))
61 *ppv
= &OleObjectPersistStg
;
62 else if (IsEqualIID(riid
, &IID_IOleCache
))
64 else if (IsEqualIID(riid
, &IID_IRunnableObject
))
68 IUnknown_AddRef((IUnknown
*)*ppv
);
72 trace("OleObject_QueryInterface: returning E_NOINTERFACE\n");
76 static ULONG WINAPI
OleObject_AddRef(IOleObject
*iface
)
78 CHECK_EXPECTED_METHOD("OleObject_AddRef");
82 static ULONG WINAPI
OleObject_Release(IOleObject
*iface
)
84 CHECK_EXPECTED_METHOD("OleObject_Release");
88 static HRESULT WINAPI OleObject_SetClientSite
91 IOleClientSite
*pClientSite
94 CHECK_EXPECTED_METHOD("OleObject_SetClientSite");
98 static HRESULT WINAPI OleObject_GetClientSite
101 IOleClientSite
**ppClientSite
104 CHECK_EXPECTED_METHOD("OleObject_GetClientSite");
108 static HRESULT WINAPI OleObject_SetHostNames
111 LPCOLESTR szContainerApp
,
112 LPCOLESTR szContainerObj
115 CHECK_EXPECTED_METHOD("OleObject_SetHostNames");
119 static HRESULT WINAPI OleObject_Close
125 CHECK_EXPECTED_METHOD("OleObject_Close");
129 static HRESULT WINAPI OleObject_SetMoniker
132 DWORD dwWhichMoniker
,
136 CHECK_EXPECTED_METHOD("OleObject_SetMoniker");
140 static HRESULT WINAPI OleObject_GetMoniker
144 DWORD dwWhichMoniker
,
148 CHECK_EXPECTED_METHOD("OleObject_GetMoniker");
152 static HRESULT WINAPI OleObject_InitFromData
155 IDataObject
*pDataObject
,
160 CHECK_EXPECTED_METHOD("OleObject_InitFromData");
164 static HRESULT WINAPI OleObject_GetClipboardData
168 IDataObject
**ppDataObject
171 CHECK_EXPECTED_METHOD("OleObject_GetClipboardData");
175 static HRESULT WINAPI OleObject_DoVerb
180 IOleClientSite
*pActiveSite
,
186 CHECK_EXPECTED_METHOD("OleObject_DoVerb");
190 static HRESULT WINAPI OleObject_EnumVerbs
193 IEnumOLEVERB
**ppEnumOleVerb
196 CHECK_EXPECTED_METHOD("OleObject_EnumVerbs");
200 static HRESULT WINAPI OleObject_Update
205 CHECK_EXPECTED_METHOD("OleObject_Update");
209 static HRESULT WINAPI OleObject_IsUpToDate
214 CHECK_EXPECTED_METHOD("OleObject_IsUpToDate");
218 static HRESULT WINAPI OleObject_GetUserClassID
224 CHECK_EXPECTED_METHOD("OleObject_GetUserClassID");
228 static HRESULT WINAPI OleObject_GetUserType
232 LPOLESTR
*pszUserType
235 CHECK_EXPECTED_METHOD("OleObject_GetUserType");
239 static HRESULT WINAPI OleObject_SetExtent
246 CHECK_EXPECTED_METHOD("OleObject_SetExtent");
250 static HRESULT WINAPI OleObject_GetExtent
257 CHECK_EXPECTED_METHOD("OleObject_GetExtent");
261 static HRESULT WINAPI OleObject_Advise
264 IAdviseSink
*pAdvSink
,
268 CHECK_EXPECTED_METHOD("OleObject_Advise");
272 static HRESULT WINAPI OleObject_Unadvise
278 CHECK_EXPECTED_METHOD("OleObject_Unadvise");
282 static HRESULT WINAPI OleObject_EnumAdvise
285 IEnumSTATDATA
**ppenumAdvise
288 CHECK_EXPECTED_METHOD("OleObject_EnumAdvise");
292 static HRESULT WINAPI OleObject_GetMiscStatus
299 CHECK_EXPECTED_METHOD("OleObject_GetMiscStatus");
300 *pdwStatus
= DVASPECT_CONTENT
;
304 static HRESULT WINAPI OleObject_SetColorScheme
310 CHECK_EXPECTED_METHOD("OleObject_SetColorScheme");
314 static IOleObjectVtbl OleObjectVtbl
=
316 OleObject_QueryInterface
,
319 OleObject_SetClientSite
,
320 OleObject_GetClientSite
,
321 OleObject_SetHostNames
,
323 OleObject_SetMoniker
,
324 OleObject_GetMoniker
,
325 OleObject_InitFromData
,
326 OleObject_GetClipboardData
,
330 OleObject_IsUpToDate
,
331 OleObject_GetUserClassID
,
332 OleObject_GetUserType
,
337 OleObject_EnumAdvise
,
338 OleObject_GetMiscStatus
,
339 OleObject_SetColorScheme
342 static IOleObject OleObject
= { &OleObjectVtbl
};
344 static HRESULT WINAPI
OleObjectPersistStg_QueryInterface(IPersistStorage
*iface
, REFIID riid
, void **ppv
)
346 trace("OleObjectPersistStg_QueryInterface\n");
347 return IUnknown_QueryInterface((IUnknown
*)&OleObject
, riid
, ppv
);
350 static ULONG WINAPI
OleObjectPersistStg_AddRef(IPersistStorage
*iface
)
352 CHECK_EXPECTED_METHOD("OleObjectPersistStg_AddRef");
356 static ULONG WINAPI
OleObjectPersistStg_Release(IPersistStorage
*iface
)
358 CHECK_EXPECTED_METHOD("OleObjectPersistStg_Release");
362 static HRESULT WINAPI
OleObjectPersistStg_GetClassId(IPersistStorage
*iface
, CLSID
*clsid
)
364 CHECK_EXPECTED_METHOD("OleObjectPersistStg_GetClassId");
368 static HRESULT WINAPI OleObjectPersistStg_IsDirty
370 IPersistStorage
*iface
373 CHECK_EXPECTED_METHOD("OleObjectPersistStg_IsDirty");
377 static HRESULT WINAPI OleObjectPersistStg_InitNew
379 IPersistStorage
*iface
,
383 CHECK_EXPECTED_METHOD("OleObjectPersistStg_InitNew");
387 static HRESULT WINAPI OleObjectPersistStg_Load
389 IPersistStorage
*iface
,
393 CHECK_EXPECTED_METHOD("OleObjectPersistStg_Load");
397 static HRESULT WINAPI OleObjectPersistStg_Save
399 IPersistStorage
*iface
,
404 CHECK_EXPECTED_METHOD("OleObjectPersistStg_Save");
408 static HRESULT WINAPI OleObjectPersistStg_SaveCompleted
410 IPersistStorage
*iface
,
414 CHECK_EXPECTED_METHOD("OleObjectPersistStg_SaveCompleted");
418 static HRESULT WINAPI OleObjectPersistStg_HandsOffStorage
420 IPersistStorage
*iface
423 CHECK_EXPECTED_METHOD("OleObjectPersistStg_HandsOffStorage");
427 static IPersistStorageVtbl OleObjectPersistStgVtbl
=
429 OleObjectPersistStg_QueryInterface
,
430 OleObjectPersistStg_AddRef
,
431 OleObjectPersistStg_Release
,
432 OleObjectPersistStg_GetClassId
,
433 OleObjectPersistStg_IsDirty
,
434 OleObjectPersistStg_InitNew
,
435 OleObjectPersistStg_Load
,
436 OleObjectPersistStg_Save
,
437 OleObjectPersistStg_SaveCompleted
,
438 OleObjectPersistStg_HandsOffStorage
441 static IPersistStorage OleObjectPersistStg
= { &OleObjectPersistStgVtbl
};
443 static HRESULT WINAPI
OleObjectCache_QueryInterface(IOleCache
*iface
, REFIID riid
, void **ppv
)
445 return IUnknown_QueryInterface((IUnknown
*)&OleObject
, riid
, ppv
);
448 static ULONG WINAPI
OleObjectCache_AddRef(IOleCache
*iface
)
450 CHECK_EXPECTED_METHOD("OleObjectCache_AddRef");
454 static ULONG WINAPI
OleObjectCache_Release(IOleCache
*iface
)
456 CHECK_EXPECTED_METHOD("OleObjectCache_Release");
460 static HRESULT WINAPI OleObjectCache_Cache
463 FORMATETC
*pformatetc
,
468 CHECK_EXPECTED_METHOD("OleObjectCache_Cache");
472 static HRESULT WINAPI OleObjectCache_Uncache
478 CHECK_EXPECTED_METHOD("OleObjectCache_Uncache");
482 static HRESULT WINAPI OleObjectCache_EnumCache
485 IEnumSTATDATA
**ppenumSTATDATA
488 CHECK_EXPECTED_METHOD("OleObjectCache_EnumCache");
493 static HRESULT WINAPI OleObjectCache_InitCache
496 IDataObject
*pDataObject
499 CHECK_EXPECTED_METHOD("OleObjectCache_InitCache");
504 static HRESULT WINAPI OleObjectCache_SetData
507 FORMATETC
*pformatetc
,
512 CHECK_EXPECTED_METHOD("OleObjectCache_SetData");
517 static IOleCacheVtbl OleObjectCacheVtbl
=
519 OleObjectCache_QueryInterface
,
520 OleObjectCache_AddRef
,
521 OleObjectCache_Release
,
522 OleObjectCache_Cache
,
523 OleObjectCache_Uncache
,
524 OleObjectCache_EnumCache
,
525 OleObjectCache_InitCache
,
526 OleObjectCache_SetData
529 static IOleCache OleObjectCache
= { &OleObjectCacheVtbl
};
531 static HRESULT WINAPI
OleObjectCF_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppv
)
533 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IClassFactory
))
536 IUnknown_AddRef(iface
);
540 return E_NOINTERFACE
;
543 static ULONG WINAPI
OleObjectCF_AddRef(IClassFactory
*iface
)
548 static ULONG WINAPI
OleObjectCF_Release(IClassFactory
*iface
)
553 static HRESULT WINAPI
OleObjectCF_CreateInstance(IClassFactory
*iface
, IUnknown
*punkOuter
, REFIID riid
, void **ppv
)
555 return IUnknown_QueryInterface((IUnknown
*)&OleObject
, riid
, ppv
);
558 static HRESULT WINAPI
OleObjectCF_LockServer(IClassFactory
*iface
, BOOL lock
)
563 static IClassFactoryVtbl OleObjectCFVtbl
=
565 OleObjectCF_QueryInterface
,
568 OleObjectCF_CreateInstance
,
569 OleObjectCF_LockServer
572 static IClassFactory OleObjectCF
= { &OleObjectCFVtbl
};
574 static HRESULT WINAPI
OleObjectRunnable_QueryInterface(IRunnableObject
*iface
, REFIID riid
, void **ppv
)
576 return IUnknown_QueryInterface((IUnknown
*)&OleObject
, riid
, ppv
);
579 static ULONG WINAPI
OleObjectRunnable_AddRef(IRunnableObject
*iface
)
581 CHECK_EXPECTED_METHOD("OleObjectRunnable_AddRef");
585 static ULONG WINAPI
OleObjectRunnable_Release(IRunnableObject
*iface
)
587 CHECK_EXPECTED_METHOD("OleObjectRunnable_Release");
591 static HRESULT WINAPI
OleObjectRunnable_GetRunningClass(
592 IRunnableObject
*iface
,
595 CHECK_EXPECTED_METHOD("OleObjectRunnable_GetRunningClass");
599 static HRESULT WINAPI
OleObjectRunnable_Run(
600 IRunnableObject
*iface
,
603 CHECK_EXPECTED_METHOD("OleObjectRunnable_Run");
607 static BOOL WINAPI
OleObjectRunnable_IsRunning(IRunnableObject
*iface
)
609 CHECK_EXPECTED_METHOD("OleObjectRunnable_IsRunning");
613 static HRESULT WINAPI
OleObjectRunnable_LockRunning(
614 IRunnableObject
*iface
,
616 BOOL fLastUnlockCloses
)
618 CHECK_EXPECTED_METHOD("OleObjectRunnable_LockRunning");
622 static HRESULT WINAPI
OleObjectRunnable_SetContainedObject(
623 IRunnableObject
*iface
,
626 CHECK_EXPECTED_METHOD("OleObjectRunnable_SetContainedObject");
630 static IRunnableObjectVtbl OleObjectRunnableVtbl
=
632 OleObjectRunnable_QueryInterface
,
633 OleObjectRunnable_AddRef
,
634 OleObjectRunnable_Release
,
635 OleObjectRunnable_GetRunningClass
,
636 OleObjectRunnable_Run
,
637 OleObjectRunnable_IsRunning
,
638 OleObjectRunnable_LockRunning
,
639 OleObjectRunnable_SetContainedObject
642 static IRunnableObject OleObjectRunnable
= { &OleObjectRunnableVtbl
};
644 static const CLSID CLSID_Equation3
= {0x0002CE02, 0x0000, 0x0000, {0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46} };
646 static void test_OleCreate(IStorage
*pStorage
)
651 static const char *methods_olerender_none
[] =
653 "OleObject_QueryInterface",
655 "OleObject_QueryInterface",
656 "OleObjectPersistStg_AddRef",
657 "OleObjectPersistStg_InitNew",
658 "OleObjectPersistStg_Release",
662 static const char *methods_olerender_draw
[] =
664 "OleObject_QueryInterface",
666 "OleObject_QueryInterface",
667 "OleObjectPersistStg_AddRef",
668 "OleObjectPersistStg_InitNew",
669 "OleObjectPersistStg_Release",
670 "OleObject_QueryInterface",
671 "OleObjectRunnable_AddRef",
672 "OleObjectRunnable_Run",
673 "OleObjectRunnable_Release",
674 "OleObject_QueryInterface",
675 "OleObjectCache_AddRef",
676 "OleObjectCache_Cache",
677 "OleObjectCache_Release",
681 static const char *methods_olerender_format
[] =
683 "OleObject_QueryInterface",
685 "OleObject_QueryInterface",
687 "OleObject_GetMiscStatus",
688 "OleObject_QueryInterface",
689 "OleObjectPersistStg_AddRef",
690 "OleObjectPersistStg_InitNew",
691 "OleObjectPersistStg_Release",
692 "OleObject_SetClientSite",
694 "OleObject_QueryInterface",
695 "OleObjectRunnable_AddRef",
696 "OleObjectRunnable_Run",
697 "OleObjectRunnable_Release",
698 "OleObject_QueryInterface",
699 "OleObjectCache_AddRef",
700 "OleObjectCache_Cache",
701 "OleObjectCache_Release",
705 static const char *methods_olerender_asis
[] =
707 "OleObject_QueryInterface",
709 "OleObject_QueryInterface",
710 "OleObjectPersistStg_AddRef",
711 "OleObjectPersistStg_InitNew",
712 "OleObjectPersistStg_Release",
716 static const char *methods_olerender_draw_no_runnable
[] =
718 "OleObject_QueryInterface",
720 "OleObject_QueryInterface",
721 "OleObjectPersistStg_AddRef",
722 "OleObjectPersistStg_InitNew",
723 "OleObjectPersistStg_Release",
724 "OleObject_QueryInterface",
725 "OleObject_QueryInterface",
726 "OleObjectCache_AddRef",
727 "OleObjectCache_Cache",
728 "OleObjectCache_Release",
732 static const char *methods_olerender_draw_no_cache
[] =
734 "OleObject_QueryInterface",
736 "OleObject_QueryInterface",
737 "OleObjectPersistStg_AddRef",
738 "OleObjectPersistStg_InitNew",
739 "OleObjectPersistStg_Release",
740 "OleObject_QueryInterface",
741 "OleObjectRunnable_AddRef",
742 "OleObjectRunnable_Run",
743 "OleObjectRunnable_Release",
744 "OleObject_QueryInterface",
749 runnable
= &OleObjectRunnable
;
750 cache
= &OleObjectCache
;
751 expected_method_list
= methods_olerender_none
;
752 trace("OleCreate with OLERENDER_NONE:\n");
753 hr
= OleCreate(&CLSID_Equation3
, &IID_IOleObject
, OLERENDER_NONE
, NULL
, NULL
, pStorage
, (void **)&pObject
);
754 ok_ole_success(hr
, "OleCreate");
755 IOleObject_Release(pObject
);
756 ok(!*expected_method_list
, "Method sequence starting from %s not called\n", *expected_method_list
);
758 expected_method_list
= methods_olerender_draw
;
759 trace("OleCreate with OLERENDER_DRAW:\n");
760 hr
= OleCreate(&CLSID_Equation3
, &IID_IOleObject
, OLERENDER_DRAW
, NULL
, NULL
, pStorage
, (void **)&pObject
);
761 ok_ole_success(hr
, "OleCreate");
762 IOleObject_Release(pObject
);
763 ok(!*expected_method_list
, "Method sequence starting from %s not called\n", *expected_method_list
);
765 formatetc
.cfFormat
= CF_TEXT
;
766 formatetc
.ptd
= NULL
;
767 formatetc
.dwAspect
= DVASPECT_CONTENT
;
768 formatetc
.lindex
= -1;
769 formatetc
.tymed
= TYMED_HGLOBAL
;
770 expected_method_list
= methods_olerender_format
;
771 trace("OleCreate with OLERENDER_FORMAT:\n");
772 hr
= OleCreate(&CLSID_Equation3
, &IID_IOleObject
, OLERENDER_FORMAT
, &formatetc
, (IOleClientSite
*)0xdeadbeef, pStorage
, (void **)&pObject
);
773 ok_ole_success(hr
, "OleCreate");
774 IOleObject_Release(pObject
);
775 ok(!*expected_method_list
, "Method sequence starting from %s not called\n", *expected_method_list
);
777 expected_method_list
= methods_olerender_asis
;
778 trace("OleCreate with OLERENDER_ASIS:\n");
779 hr
= OleCreate(&CLSID_Equation3
, &IID_IOleObject
, OLERENDER_ASIS
, NULL
, NULL
, pStorage
, (void **)&pObject
);
780 ok_ole_success(hr
, "OleCreate");
781 IOleObject_Release(pObject
);
782 ok(!*expected_method_list
, "Method sequence starting from %s not called\n", *expected_method_list
);
785 expected_method_list
= methods_olerender_draw_no_runnable
;
786 trace("OleCreate with OLERENDER_DRAW (no IOlObjectRunnable):\n");
787 hr
= OleCreate(&CLSID_Equation3
, &IID_IOleObject
, OLERENDER_DRAW
, NULL
, NULL
, pStorage
, (void **)&pObject
);
788 ok_ole_success(hr
, "OleCreate");
789 IOleObject_Release(pObject
);
790 ok(!*expected_method_list
, "Method sequence starting from %s not called\n", *expected_method_list
);
792 runnable
= &OleObjectRunnable
;
794 expected_method_list
= methods_olerender_draw_no_cache
;
795 trace("OleCreate with OLERENDER_DRAW (no IOlObjectRunnable):\n");
796 hr
= OleCreate(&CLSID_Equation3
, &IID_IOleObject
, OLERENDER_DRAW
, NULL
, NULL
, pStorage
, (void **)&pObject
);
797 ok_ole_success(hr
, "OleCreate");
798 IOleObject_Release(pObject
);
799 ok(!*expected_method_list
, "Method sequence starting from %s not called\n", *expected_method_list
);
803 static void test_OleLoad(IStorage
*pStorage
)
808 static const char *methods_oleload
[] =
810 "OleObject_QueryInterface",
812 "OleObject_QueryInterface",
814 "OleObject_GetMiscStatus",
815 "OleObject_QueryInterface",
816 "OleObjectPersistStg_AddRef",
817 "OleObjectPersistStg_Load",
818 "OleObjectPersistStg_Release",
819 "OleObject_SetClientSite",
821 "OleObject_QueryInterface",
826 expected_method_list
= methods_oleload
;
828 hr
= OleLoad(pStorage
, &IID_IOleObject
, (IOleClientSite
*)0xdeadbeef, (void **)&pObject
);
829 ok_ole_success(hr
, "OleLoad");
830 IOleObject_Release(pObject
);
831 ok(!*expected_method_list
, "Method sequence starting from %s not called\n", *expected_method_list
);
834 static BOOL STDMETHODCALLTYPE
draw_continue(ULONG_PTR param
)
836 CHECK_EXPECTED_METHOD("draw_continue");
840 static HRESULT WINAPI
AdviseSink_QueryInterface(IAdviseSink
*iface
, REFIID riid
, void **ppv
)
842 if (IsEqualIID(riid
, &IID_IAdviseSink
) || IsEqualIID(riid
, &IID_IUnknown
))
845 IUnknown_AddRef(iface
);
849 return E_NOINTERFACE
;
852 static ULONG WINAPI
AdviseSink_AddRef(IAdviseSink
*iface
)
857 static ULONG WINAPI
AdviseSink_Release(IAdviseSink
*iface
)
863 static void WINAPI
AdviseSink_OnDataChange(
865 FORMATETC
*pFormatetc
,
868 CHECK_EXPECTED_METHOD("AdviseSink_OnDataChange");
871 static void WINAPI
AdviseSink_OnViewChange(
876 CHECK_EXPECTED_METHOD("AdviseSink_OnViewChange");
879 static void WINAPI
AdviseSink_OnRename(
883 CHECK_EXPECTED_METHOD("AdviseSink_OnRename");
886 static void WINAPI
AdviseSink_OnSave(IAdviseSink
*iface
)
888 CHECK_EXPECTED_METHOD("AdviseSink_OnSave");
891 static void WINAPI
AdviseSink_OnClose(IAdviseSink
*iface
)
893 CHECK_EXPECTED_METHOD("AdviseSink_OnClose");
896 static IAdviseSinkVtbl AdviseSinkVtbl
=
898 AdviseSink_QueryInterface
,
901 AdviseSink_OnDataChange
,
902 AdviseSink_OnViewChange
,
908 static IAdviseSink AdviseSink
= { &AdviseSinkVtbl
};
910 static HRESULT WINAPI
DataObject_QueryInterface(
915 if (IsEqualIID(riid
, &IID_IDataObject
) || IsEqualIID(riid
, &IID_IUnknown
))
924 static ULONG WINAPI
DataObject_AddRef(
930 static ULONG WINAPI
DataObject_Release(
936 static HRESULT WINAPI
DataObject_GetData(
938 LPFORMATETC pformatetcIn
,
941 CHECK_EXPECTED_METHOD("DataObject_GetData");
945 static HRESULT WINAPI
DataObject_GetDataHere(
947 LPFORMATETC pformatetc
,
950 CHECK_EXPECTED_METHOD("DataObject_GetDataHere");
954 static HRESULT WINAPI
DataObject_QueryGetData(
956 LPFORMATETC pformatetc
)
958 CHECK_EXPECTED_METHOD("DataObject_QueryGetData");
962 static HRESULT WINAPI
DataObject_GetCanonicalFormatEtc(
964 LPFORMATETC pformatectIn
,
965 LPFORMATETC pformatetcOut
)
967 CHECK_EXPECTED_METHOD("DataObject_GetCanonicalFormatEtc");
971 static HRESULT WINAPI
DataObject_SetData(
973 LPFORMATETC pformatetc
,
977 CHECK_EXPECTED_METHOD("DataObject_SetData");
981 static HRESULT WINAPI
DataObject_EnumFormatEtc(
984 IEnumFORMATETC
** ppenumFormatEtc
)
986 CHECK_EXPECTED_METHOD("DataObject_EnumFormatEtc");
990 static HRESULT WINAPI
DataObject_DAdvise(
992 FORMATETC
* pformatetc
,
994 IAdviseSink
* pAdvSink
,
995 DWORD
* pdwConnection
)
997 CHECK_EXPECTED_METHOD("DataObject_DAdvise");
1002 static HRESULT WINAPI
DataObject_DUnadvise(
1006 CHECK_EXPECTED_METHOD("DataObject_DUnadvise");
1010 static HRESULT WINAPI
DataObject_EnumDAdvise(
1012 IEnumSTATDATA
** ppenumAdvise
)
1014 CHECK_EXPECTED_METHOD("DataObject_EnumDAdvise");
1015 return OLE_E_ADVISENOTSUPPORTED
;
1018 static IDataObjectVtbl DataObjectVtbl
=
1020 DataObject_QueryInterface
,
1024 DataObject_GetDataHere
,
1025 DataObject_QueryGetData
,
1026 DataObject_GetCanonicalFormatEtc
,
1028 DataObject_EnumFormatEtc
,
1030 DataObject_DUnadvise
,
1031 DataObject_EnumDAdvise
1034 static IDataObject DataObject
= { &DataObjectVtbl
};
1036 static void test_data_cache(void)
1039 IOleCache2
*pOleCache
;
1041 IPersistStorage
*pPS
;
1042 IViewObject
*pViewObject
;
1043 IOleCacheControl
*pOleCacheControl
;
1045 STGMEDIUM stgmedium
;
1051 char szSystemDir
[MAX_PATH
];
1052 WCHAR wszPath
[MAX_PATH
];
1053 static const WCHAR wszShell32
[] = {'\\','s','h','e','l','l','3','2','.','d','l','l',0};
1055 static const char *methods_cacheinitnew
[] =
1057 "AdviseSink_OnViewChange",
1058 "AdviseSink_OnViewChange",
1060 "DataObject_DAdvise",
1061 "DataObject_DAdvise",
1062 "DataObject_DUnadvise",
1063 "DataObject_DUnadvise",
1066 static const char *methods_cacheload
[] =
1068 "AdviseSink_OnViewChange",
1072 "DataObject_GetData",
1073 "DataObject_GetData",
1074 "DataObject_GetData",
1078 GetSystemDirectory(szSystemDir
, sizeof(szSystemDir
)/sizeof(szSystemDir
[0]));
1080 expected_method_list
= methods_cacheinitnew
;
1082 fmtetc
.cfFormat
= CF_METAFILEPICT
;
1083 fmtetc
.dwAspect
= DVASPECT_ICON
;
1086 fmtetc
.tymed
= TYMED_MFPICT
;
1088 hr
= StgCreateDocfile(NULL
, STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_DELETEONRELEASE
, 0, &pStorage
);
1089 ok_ole_success(hr
, "StgCreateDocfile");
1091 /* Test with new data */
1093 hr
= CreateDataCache(NULL
, &CLSID_NULL
, &IID_IOleCache2
, (LPVOID
*)&pOleCache
);
1094 ok_ole_success(hr
, "CreateDataCache");
1096 hr
= IOleCache_QueryInterface(pOleCache
, &IID_IPersistStorage
, (LPVOID
*)&pPS
);
1097 ok_ole_success(hr
, "IOleCache_QueryInterface(IID_IPersistStorage)");
1098 hr
= IOleCache_QueryInterface(pOleCache
, &IID_IViewObject
, (LPVOID
*)&pViewObject
);
1099 ok_ole_success(hr
, "IOleCache_QueryInterface(IID_IViewObject)");
1100 hr
= IOleCache_QueryInterface(pOleCache
, &IID_IOleCacheControl
, (LPVOID
*)&pOleCacheControl
);
1101 ok_ole_success(hr
, "IOleCache_QueryInterface(IID_IOleCacheControl)");
1103 hr
= IViewObject_SetAdvise(pViewObject
, DVASPECT_ICON
, ADVF_PRIMEFIRST
, &AdviseSink
);
1104 ok_ole_success(hr
, "IViewObject_SetAdvise");
1106 hr
= IPersistStorage_InitNew(pPS
, pStorage
);
1107 ok_ole_success(hr
, "IPersistStorage_InitNew");
1109 hr
= IPersistStorage_IsDirty(pPS
);
1110 ok_ole_success(hr
, "IPersistStorage_IsDirty");
1112 hr
= IPersistStorage_GetClassID(pPS
, &clsid
);
1113 ok_ole_success(hr
, "IPersistStorage_GetClassID");
1114 ok(IsEqualCLSID(&clsid
, &IID_NULL
), "clsid should be blank\n");
1116 hr
= IOleCache_Uncache(pOleCache
, 0xdeadbeef);
1117 ok(hr
== OLE_E_NOCONNECTION
, "IOleCache_Uncache with invalid value should return OLE_E_NOCONNECTION instead of 0x%x\n", hr
);
1119 for (fmtetc
.cfFormat
= CF_TEXT
; fmtetc
.cfFormat
< CF_MAX
; fmtetc
.cfFormat
++)
1122 fmtetc
.dwAspect
= DVASPECT_THUMBNAIL
;
1123 for (i
= 0; i
< 7; i
++)
1125 fmtetc
.tymed
= 1 << i
;
1126 hr
= IOleCache_Cache(pOleCache
, &fmtetc
, 0, &dwConnection
);
1127 if ((fmtetc
.cfFormat
== CF_METAFILEPICT
&& fmtetc
.tymed
== TYMED_MFPICT
) ||
1128 (fmtetc
.cfFormat
== CF_BITMAP
&& fmtetc
.tymed
== TYMED_GDI
) ||
1129 (fmtetc
.cfFormat
== CF_DIB
&& fmtetc
.tymed
== TYMED_HGLOBAL
) ||
1130 (fmtetc
.cfFormat
== CF_ENHMETAFILE
&& fmtetc
.tymed
== TYMED_ENHMF
))
1131 ok(hr
== S_OK
, "IOleCache_Cache cfFormat = %d, tymed = %d should have returned S_OK instead of 0x%08x\n",
1132 fmtetc
.cfFormat
, fmtetc
.tymed
, hr
);
1133 else if (fmtetc
.tymed
== TYMED_HGLOBAL
)
1134 ok(hr
== CACHE_S_FORMATETC_NOTSUPPORTED
,
1135 "IOleCache_Cache cfFormat = %d, tymed = %d should have returned CACHE_S_FORMATETC_NOTSUPPORTED instead of 0x%08x\n",
1136 fmtetc
.cfFormat
, fmtetc
.tymed
, hr
);
1138 ok(hr
== DV_E_TYMED
, "IOleCache_Cache cfFormat = %d, tymed = %d should have returned DV_E_TYMED instead of 0x%08x\n",
1139 fmtetc
.cfFormat
, fmtetc
.tymed
, hr
);
1142 hr
= IOleCache_Uncache(pOleCache
, dwConnection
);
1143 ok_ole_success(hr
, "IOleCache_Uncache");
1148 fmtetc
.cfFormat
= CF_BITMAP
;
1149 fmtetc
.dwAspect
= DVASPECT_THUMBNAIL
;
1150 fmtetc
.tymed
= TYMED_GDI
;
1151 hr
= IOleCache_Cache(pOleCache
, &fmtetc
, 0, &dwConnection
);
1152 ok_ole_success(hr
, "IOleCache_Cache");
1154 fmtetc
.cfFormat
= 0;
1155 fmtetc
.dwAspect
= DVASPECT_ICON
;
1156 fmtetc
.tymed
= TYMED_MFPICT
;
1157 hr
= IOleCache_Cache(pOleCache
, &fmtetc
, 0, &dwConnection
);
1158 ok_ole_success(hr
, "IOleCache_Cache");
1160 MultiByteToWideChar(CP_ACP
, 0, szSystemDir
, -1, wszPath
, sizeof(wszPath
)/sizeof(wszPath
[0]));
1161 memcpy(wszPath
+lstrlenW(wszPath
), wszShell32
, sizeof(wszShell32
));
1163 fmtetc
.cfFormat
= CF_METAFILEPICT
;
1164 stgmedium
.tymed
= TYMED_MFPICT
;
1165 U(stgmedium
).hMetaFilePict
= OleMetafilePictFromIconAndLabel(
1166 LoadIcon(NULL
, MAKEINTRESOURCE(IDI_APPLICATION
)), wszPath
, wszPath
, 0);
1167 stgmedium
.pUnkForRelease
= NULL
;
1169 fmtetc
.dwAspect
= DVASPECT_CONTENT
;
1170 hr
= IOleCache_SetData(pOleCache
, &fmtetc
, &stgmedium
, FALSE
);
1171 ok(hr
== OLE_E_BLANK
, "IOleCache_SetData for aspect not in cache should have return OLE_E_BLANK instead of 0x%08x\n", hr
);
1173 fmtetc
.dwAspect
= DVASPECT_ICON
;
1174 hr
= IOleCache_SetData(pOleCache
, &fmtetc
, &stgmedium
, FALSE
);
1175 ok_ole_success(hr
, "IOleCache_SetData");
1177 hr
= IViewObject_Freeze(pViewObject
, DVASPECT_ICON
, -1, NULL
, &dwFreeze
);
1179 ok_ole_success(hr
, "IViewObject_Freeze");
1180 hr
= IViewObject_Freeze(pViewObject
, DVASPECT_CONTENT
, -1, NULL
, &dwFreeze
);
1181 ok(hr
== OLE_E_BLANK
, "IViewObject_Freeze with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr
);
1186 rcBounds
.right
= 100;
1187 rcBounds
.bottom
= 100;
1188 hdcMem
= CreateCompatibleDC(NULL
);
1190 hr
= IViewObject_Draw(pViewObject
, DVASPECT_ICON
, -1, NULL
, NULL
, NULL
, hdcMem
, &rcBounds
, NULL
, draw_continue
, 0xdeadbeef);
1191 ok_ole_success(hr
, "IViewObject_Draw");
1193 hr
= IViewObject_Draw(pViewObject
, DVASPECT_CONTENT
, -1, NULL
, NULL
, NULL
, hdcMem
, &rcBounds
, NULL
, draw_continue
, 0xdeadbeef);
1194 ok(hr
== OLE_E_BLANK
, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr
);
1198 hr
= IOleCacheControl_OnRun(pOleCacheControl
, &DataObject
);
1200 ok_ole_success(hr
, "IOleCacheControl_OnRun");
1203 hr
= IPersistStorage_Save(pPS
, pStorage
, TRUE
);
1204 ok_ole_success(hr
, "IPersistStorage_Save");
1206 hr
= IPersistStorage_SaveCompleted(pPS
, NULL
);
1207 ok_ole_success(hr
, "IPersistStorage_SaveCompleted");
1209 hr
= IPersistStorage_IsDirty(pPS
);
1210 ok(hr
== S_FALSE
, "IPersistStorage_IsDirty should have returned S_FALSE instead of 0x%x\n", hr
);
1212 IPersistStorage_Release(pPS
);
1213 IViewObject_Release(pViewObject
);
1214 IOleCache_Release(pOleCache
);
1215 IOleCacheControl_Release(pOleCacheControl
);
1218 ok(!*expected_method_list
, "Method sequence starting from %s not called\n", *expected_method_list
);
1221 /* Test with loaded data */
1222 trace("Testing loaded data with CreateDataCache:\n");
1223 expected_method_list
= methods_cacheload
;
1225 hr
= CreateDataCache(NULL
, &CLSID_NULL
, &IID_IOleCache2
, (LPVOID
*)&pOleCache
);
1226 ok_ole_success(hr
, "CreateDataCache");
1228 hr
= IOleCache_QueryInterface(pOleCache
, &IID_IPersistStorage
, (LPVOID
*)&pPS
);
1229 ok_ole_success(hr
, "IOleCache_QueryInterface(IID_IPersistStorage)");
1230 hr
= IOleCache_QueryInterface(pOleCache
, &IID_IViewObject
, (LPVOID
*)&pViewObject
);
1231 ok_ole_success(hr
, "IOleCache_QueryInterface(IID_IViewObject)");
1233 hr
= IViewObject_SetAdvise(pViewObject
, DVASPECT_ICON
, ADVF_PRIMEFIRST
, &AdviseSink
);
1234 ok_ole_success(hr
, "IViewObject_SetAdvise");
1236 hr
= IPersistStorage_Load(pPS
, pStorage
);
1237 ok_ole_success(hr
, "IPersistStorage_Load");
1239 hr
= IPersistStorage_IsDirty(pPS
);
1240 ok(hr
== S_FALSE
, "IPersistStorage_IsDirty should have returned S_FALSE instead of 0x%x\n", hr
);
1242 fmtetc
.cfFormat
= 0;
1243 fmtetc
.dwAspect
= DVASPECT_ICON
;
1246 fmtetc
.tymed
= TYMED_MFPICT
;
1247 hr
= IOleCache_Cache(pOleCache
, &fmtetc
, 0, &dwConnection
);
1248 ok(hr
== CACHE_S_SAMECACHE
, "IOleCache_Cache with already loaded data format type should return CACHE_S_SAMECACHE instead of 0x%x\n", hr
);
1252 rcBounds
.right
= 100;
1253 rcBounds
.bottom
= 100;
1254 hdcMem
= CreateCompatibleDC(NULL
);
1256 hr
= IViewObject_Draw(pViewObject
, DVASPECT_ICON
, -1, NULL
, NULL
, NULL
, hdcMem
, &rcBounds
, NULL
, draw_continue
, 0xdeadbeef);
1257 ok_ole_success(hr
, "IViewObject_Draw");
1259 hr
= IViewObject_Draw(pViewObject
, DVASPECT_CONTENT
, -1, NULL
, NULL
, NULL
, hdcMem
, &rcBounds
, NULL
, draw_continue
, 0xdeadbeef);
1260 ok(hr
== OLE_E_BLANK
, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr
);
1262 /* unload the cached storage object, causing it to be reloaded */
1263 hr
= IOleCache2_DiscardCache(pOleCache
, DISCARDCACHE_NOSAVE
);
1264 ok_ole_success(hr
, "IOleCache2_DiscardCache");
1265 hr
= IViewObject_Draw(pViewObject
, DVASPECT_ICON
, -1, NULL
, NULL
, NULL
, hdcMem
, &rcBounds
, NULL
, draw_continue
, 0xdeadbeef);
1266 ok_ole_success(hr
, "IViewObject_Draw");
1268 /* unload the cached storage object, but don't allow it to be reloaded */
1269 hr
= IPersistStorage_HandsOffStorage(pPS
);
1270 ok_ole_success(hr
, "IPersistStorage_HandsOffStorage");
1271 hr
= IViewObject_Draw(pViewObject
, DVASPECT_ICON
, -1, NULL
, NULL
, NULL
, hdcMem
, &rcBounds
, NULL
, draw_continue
, 0xdeadbeef);
1272 ok_ole_success(hr
, "IViewObject_Draw");
1273 hr
= IOleCache2_DiscardCache(pOleCache
, DISCARDCACHE_NOSAVE
);
1274 ok_ole_success(hr
, "IOleCache2_DiscardCache");
1275 hr
= IViewObject_Draw(pViewObject
, DVASPECT_ICON
, -1, NULL
, NULL
, NULL
, hdcMem
, &rcBounds
, NULL
, draw_continue
, 0xdeadbeef);
1276 ok(hr
== OLE_E_BLANK
, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr
);
1281 hr
= IOleCache_InitCache(pOleCache
, &DataObject
);
1282 ok(hr
== CACHE_E_NOCACHE_UPDATED
, "IOleCache_InitCache should have returned CACHE_E_NOCACHE_UPDATED instead of 0x%08x\n", hr
);
1285 IPersistStorage_Release(pPS
);
1286 IViewObject_Release(pViewObject
);
1287 IOleCache_Release(pOleCache
);
1290 ok(!*expected_method_list
, "Method sequence starting from %s not called\n", *expected_method_list
);
1293 IStorage_Release(pStorage
);
1294 ReleaseStgMedium(&stgmedium
);
1306 hr
= CoRegisterClassObject(&CLSID_Equation3
, (IUnknown
*)&OleObjectCF
, CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, &dwRegister
);
1307 ok_ole_success(hr
, "CoRegisterClassObject");
1309 hr
= StgCreateDocfile(NULL
, STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
| STGM_DELETEONRELEASE
, 0, &pStorage
);
1310 ok_ole_success(hr
, "StgCreateDocfile");
1312 test_OleCreate(pStorage
);
1314 hr
= IStorage_Stat(pStorage
, &statstg
, STATFLAG_NONAME
);
1315 ok_ole_success(hr
, "IStorage_Stat");
1316 ok(IsEqualCLSID(&CLSID_Equation3
, &statstg
.clsid
), "Wrong CLSID in storage\n");
1318 test_OleLoad(pStorage
);
1320 IStorage_Release(pStorage
);
1322 hr
= CoRevokeClassObject(dwRegister
);
1323 ok_ole_success(hr
, "CoRevokeClassObject");