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
31 #include "wine/test.h"
33 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
35 static IPersistStorage OleObjectPersistStg;
36 static IOleCache *cache;
37 static IRunnableObject *runnable;
39 static const CLSID CLSID_WineTest =
40 { /* 9474ba1a-258b-490b-bc13-516e9239ace0 */
44 {0xbc, 0x13, 0x51, 0x6e, 0x92, 0x39, 0xac, 0xe0}
47 static const IID IID_WineTest =
48 { /* 9474ba1a-258b-490b-bc13-516e9239ace1 */
52 {0xbc, 0x13, 0x51, 0x6e, 0x92, 0x39, 0xac, 0xe1}
55 #define TEST_OPTIONAL 0x1
58 struct expected_method
64 static const struct expected_method *expected_method_list;
65 static FORMATETC *g_expected_fetc = NULL;
67 static BOOL g_showRunnable = TRUE;
68 static BOOL g_isRunning = TRUE;
69 static BOOL g_failGetMiscStatus;
70 static HRESULT g_QIFailsWith;
72 static UINT cf_test_1, cf_test_2, cf_test_3;
74 #define CHECK_EXPECTED_METHOD(method_name) \
76 trace("%s\n", method_name); \
77 ok(expected_method_list->method != NULL, "Extra method %s called\n", method_name); \
78 if (!strcmp(expected_method_list->method, "WINE_EXTRA")) \
80 todo_wine ok(0, "Too many method calls.\n"); \
83 if (expected_method_list->method) \
85 while (expected_method_list->flags & TEST_OPTIONAL && \
86 strcmp(expected_method_list->method, method_name) != 0) \
87 expected_method_list++; \
88 if (expected_method_list->flags & TEST_TODO) \
90 ok(!strcmp(expected_method_list->method, method_name), \
91 "Expected %s to be called instead of %s\n", \
92 expected_method_list->method, method_name); \
94 ok(!strcmp(expected_method_list->method, method_name), \
95 "Expected %s to be called instead of %s\n", \
96 expected_method_list->method, method_name); \
97 expected_method_list++; \
101 #define CHECK_NO_EXTRA_METHODS() \
103 while (expected_method_list->flags & TEST_OPTIONAL) \
104 expected_method_list++; \
105 ok(!expected_method_list->method, "Method sequence starting from %s not called\n", expected_method_list->method); \
108 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
110 CHECK_EXPECTED_METHOD("OleObject_QueryInterface");
114 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IOleObject))
116 else if (IsEqualIID(riid, &IID_IPersistStorage))
117 *ppv = &OleObjectPersistStg;
118 else if (IsEqualIID(riid, &IID_IOleCache))
120 else if (IsEqualIID(riid, &IID_IRunnableObject) && g_showRunnable)
122 else if (IsEqualIID(riid, &IID_WineTest))
123 return g_QIFailsWith;
126 IUnknown_AddRef((IUnknown*)*ppv);
130 trace("OleObject_QueryInterface: returning E_NOINTERFACE\n");
131 return E_NOINTERFACE;
134 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
136 CHECK_EXPECTED_METHOD("OleObject_AddRef");
140 static ULONG WINAPI OleObject_Release(IOleObject *iface)
142 CHECK_EXPECTED_METHOD("OleObject_Release");
146 static HRESULT WINAPI OleObject_SetClientSite
149 IOleClientSite *pClientSite
152 CHECK_EXPECTED_METHOD("OleObject_SetClientSite");
156 static HRESULT WINAPI OleObject_GetClientSite
159 IOleClientSite **ppClientSite
162 CHECK_EXPECTED_METHOD("OleObject_GetClientSite");
166 static HRESULT WINAPI OleObject_SetHostNames
169 LPCOLESTR szContainerApp,
170 LPCOLESTR szContainerObj
173 CHECK_EXPECTED_METHOD("OleObject_SetHostNames");
177 static HRESULT WINAPI OleObject_Close
183 CHECK_EXPECTED_METHOD("OleObject_Close");
187 static HRESULT WINAPI OleObject_SetMoniker
190 DWORD dwWhichMoniker,
194 CHECK_EXPECTED_METHOD("OleObject_SetMoniker");
198 static HRESULT WINAPI OleObject_GetMoniker
202 DWORD dwWhichMoniker,
206 CHECK_EXPECTED_METHOD("OleObject_GetMoniker");
210 static HRESULT WINAPI OleObject_InitFromData
213 IDataObject *pDataObject,
218 CHECK_EXPECTED_METHOD("OleObject_InitFromData");
222 static HRESULT WINAPI OleObject_GetClipboardData
226 IDataObject **ppDataObject
229 CHECK_EXPECTED_METHOD("OleObject_GetClipboardData");
233 static HRESULT WINAPI OleObject_DoVerb
238 IOleClientSite *pActiveSite,
244 CHECK_EXPECTED_METHOD("OleObject_DoVerb");
248 static HRESULT WINAPI OleObject_EnumVerbs
251 IEnumOLEVERB **ppEnumOleVerb
254 CHECK_EXPECTED_METHOD("OleObject_EnumVerbs");
258 static HRESULT WINAPI OleObject_Update
263 CHECK_EXPECTED_METHOD("OleObject_Update");
267 static HRESULT WINAPI OleObject_IsUpToDate
272 CHECK_EXPECTED_METHOD("OleObject_IsUpToDate");
276 static HRESULT WINAPI OleObject_GetUserClassID
282 CHECK_EXPECTED_METHOD("OleObject_GetUserClassID");
286 static HRESULT WINAPI OleObject_GetUserType
290 LPOLESTR *pszUserType
293 CHECK_EXPECTED_METHOD("OleObject_GetUserType");
297 static HRESULT WINAPI OleObject_SetExtent
304 CHECK_EXPECTED_METHOD("OleObject_SetExtent");
308 static HRESULT WINAPI OleObject_GetExtent
315 CHECK_EXPECTED_METHOD("OleObject_GetExtent");
319 static HRESULT WINAPI OleObject_Advise
322 IAdviseSink *pAdvSink,
326 CHECK_EXPECTED_METHOD("OleObject_Advise");
330 static HRESULT WINAPI OleObject_Unadvise
336 CHECK_EXPECTED_METHOD("OleObject_Unadvise");
340 static HRESULT WINAPI OleObject_EnumAdvise
343 IEnumSTATDATA **ppenumAdvise
346 CHECK_EXPECTED_METHOD("OleObject_EnumAdvise");
350 static HRESULT WINAPI OleObject_GetMiscStatus
357 CHECK_EXPECTED_METHOD("OleObject_GetMiscStatus");
358 if(!g_failGetMiscStatus)
360 *pdwStatus = OLEMISC_RECOMPOSEONRESIZE;
370 static HRESULT WINAPI OleObject_SetColorScheme
376 CHECK_EXPECTED_METHOD("OleObject_SetColorScheme");
380 static const IOleObjectVtbl OleObjectVtbl =
382 OleObject_QueryInterface,
385 OleObject_SetClientSite,
386 OleObject_GetClientSite,
387 OleObject_SetHostNames,
389 OleObject_SetMoniker,
390 OleObject_GetMoniker,
391 OleObject_InitFromData,
392 OleObject_GetClipboardData,
396 OleObject_IsUpToDate,
397 OleObject_GetUserClassID,
398 OleObject_GetUserType,
403 OleObject_EnumAdvise,
404 OleObject_GetMiscStatus,
405 OleObject_SetColorScheme
408 static IOleObject OleObject = { &OleObjectVtbl };
410 static HRESULT WINAPI OleObjectPersistStg_QueryInterface(IPersistStorage *iface, REFIID riid, void **ppv)
412 trace("OleObjectPersistStg_QueryInterface\n");
413 return IUnknown_QueryInterface((IUnknown *)&OleObject, riid, ppv);
416 static ULONG WINAPI OleObjectPersistStg_AddRef(IPersistStorage *iface)
418 CHECK_EXPECTED_METHOD("OleObjectPersistStg_AddRef");
422 static ULONG WINAPI OleObjectPersistStg_Release(IPersistStorage *iface)
424 CHECK_EXPECTED_METHOD("OleObjectPersistStg_Release");
428 static HRESULT WINAPI OleObjectPersistStg_GetClassId(IPersistStorage *iface, CLSID *clsid)
430 CHECK_EXPECTED_METHOD("OleObjectPersistStg_GetClassId");
434 static HRESULT WINAPI OleObjectPersistStg_IsDirty
436 IPersistStorage *iface
439 CHECK_EXPECTED_METHOD("OleObjectPersistStg_IsDirty");
443 static HRESULT WINAPI OleObjectPersistStg_InitNew
445 IPersistStorage *iface,
449 CHECK_EXPECTED_METHOD("OleObjectPersistStg_InitNew");
453 static HRESULT WINAPI OleObjectPersistStg_Load
455 IPersistStorage *iface,
459 CHECK_EXPECTED_METHOD("OleObjectPersistStg_Load");
463 static HRESULT WINAPI OleObjectPersistStg_Save
465 IPersistStorage *iface,
470 CHECK_EXPECTED_METHOD("OleObjectPersistStg_Save");
474 static HRESULT WINAPI OleObjectPersistStg_SaveCompleted
476 IPersistStorage *iface,
480 CHECK_EXPECTED_METHOD("OleObjectPersistStg_SaveCompleted");
484 static HRESULT WINAPI OleObjectPersistStg_HandsOffStorage
486 IPersistStorage *iface
489 CHECK_EXPECTED_METHOD("OleObjectPersistStg_HandsOffStorage");
493 static const IPersistStorageVtbl OleObjectPersistStgVtbl =
495 OleObjectPersistStg_QueryInterface,
496 OleObjectPersistStg_AddRef,
497 OleObjectPersistStg_Release,
498 OleObjectPersistStg_GetClassId,
499 OleObjectPersistStg_IsDirty,
500 OleObjectPersistStg_InitNew,
501 OleObjectPersistStg_Load,
502 OleObjectPersistStg_Save,
503 OleObjectPersistStg_SaveCompleted,
504 OleObjectPersistStg_HandsOffStorage
507 static IPersistStorage OleObjectPersistStg = { &OleObjectPersistStgVtbl };
509 static HRESULT WINAPI OleObjectCache_QueryInterface(IOleCache *iface, REFIID riid, void **ppv)
511 return IUnknown_QueryInterface((IUnknown *)&OleObject, riid, ppv);
514 static ULONG WINAPI OleObjectCache_AddRef(IOleCache *iface)
516 CHECK_EXPECTED_METHOD("OleObjectCache_AddRef");
520 static ULONG WINAPI OleObjectCache_Release(IOleCache *iface)
522 CHECK_EXPECTED_METHOD("OleObjectCache_Release");
526 static HRESULT WINAPI OleObjectCache_Cache
529 FORMATETC *pformatetc,
534 CHECK_EXPECTED_METHOD("OleObjectCache_Cache");
535 if (g_expected_fetc) {
536 ok(pformatetc != NULL, "pformatetc should not be NULL\n");
538 ok(pformatetc->cfFormat == g_expected_fetc->cfFormat,
539 "cfFormat: %x\n", pformatetc->cfFormat);
540 ok((pformatetc->ptd != NULL) == (g_expected_fetc->ptd != NULL),
541 "ptd: %p\n", pformatetc->ptd);
542 ok(pformatetc->dwAspect == g_expected_fetc->dwAspect,
543 "dwAspect: %x\n", pformatetc->dwAspect);
544 ok(pformatetc->lindex == g_expected_fetc->lindex,
545 "lindex: %x\n", pformatetc->lindex);
546 ok(pformatetc->tymed == g_expected_fetc->tymed,
547 "tymed: %x\n", pformatetc->tymed);
550 ok(pformatetc == NULL, "pformatetc should be NULL\n");
554 static HRESULT WINAPI OleObjectCache_Uncache
560 CHECK_EXPECTED_METHOD("OleObjectCache_Uncache");
564 static HRESULT WINAPI OleObjectCache_EnumCache
567 IEnumSTATDATA **ppenumSTATDATA
570 CHECK_EXPECTED_METHOD("OleObjectCache_EnumCache");
575 static HRESULT WINAPI OleObjectCache_InitCache
578 IDataObject *pDataObject
581 CHECK_EXPECTED_METHOD("OleObjectCache_InitCache");
586 static HRESULT WINAPI OleObjectCache_SetData
589 FORMATETC *pformatetc,
594 CHECK_EXPECTED_METHOD("OleObjectCache_SetData");
599 static const IOleCacheVtbl OleObjectCacheVtbl =
601 OleObjectCache_QueryInterface,
602 OleObjectCache_AddRef,
603 OleObjectCache_Release,
604 OleObjectCache_Cache,
605 OleObjectCache_Uncache,
606 OleObjectCache_EnumCache,
607 OleObjectCache_InitCache,
608 OleObjectCache_SetData
611 static IOleCache OleObjectCache = { &OleObjectCacheVtbl };
613 static HRESULT WINAPI OleObjectCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
615 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
618 IUnknown_AddRef(iface);
622 return E_NOINTERFACE;
625 static ULONG WINAPI OleObjectCF_AddRef(IClassFactory *iface)
630 static ULONG WINAPI OleObjectCF_Release(IClassFactory *iface)
635 static HRESULT WINAPI OleObjectCF_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID riid, void **ppv)
637 return IUnknown_QueryInterface((IUnknown *)&OleObject, riid, ppv);
640 static HRESULT WINAPI OleObjectCF_LockServer(IClassFactory *iface, BOOL lock)
645 static const IClassFactoryVtbl OleObjectCFVtbl =
647 OleObjectCF_QueryInterface,
650 OleObjectCF_CreateInstance,
651 OleObjectCF_LockServer
654 static IClassFactory OleObjectCF = { &OleObjectCFVtbl };
656 static HRESULT WINAPI OleObjectRunnable_QueryInterface(IRunnableObject *iface, REFIID riid, void **ppv)
658 return IUnknown_QueryInterface((IUnknown *)&OleObject, riid, ppv);
661 static ULONG WINAPI OleObjectRunnable_AddRef(IRunnableObject *iface)
663 CHECK_EXPECTED_METHOD("OleObjectRunnable_AddRef");
667 static ULONG WINAPI OleObjectRunnable_Release(IRunnableObject *iface)
669 CHECK_EXPECTED_METHOD("OleObjectRunnable_Release");
673 static HRESULT WINAPI OleObjectRunnable_GetRunningClass(
674 IRunnableObject *iface,
677 CHECK_EXPECTED_METHOD("OleObjectRunnable_GetRunningClass");
681 static HRESULT WINAPI OleObjectRunnable_Run(
682 IRunnableObject *iface,
685 CHECK_EXPECTED_METHOD("OleObjectRunnable_Run");
689 static BOOL WINAPI OleObjectRunnable_IsRunning(IRunnableObject *iface)
691 CHECK_EXPECTED_METHOD("OleObjectRunnable_IsRunning");
695 static HRESULT WINAPI OleObjectRunnable_LockRunning(
696 IRunnableObject *iface,
698 BOOL fLastUnlockCloses)
700 CHECK_EXPECTED_METHOD("OleObjectRunnable_LockRunning");
704 static HRESULT WINAPI OleObjectRunnable_SetContainedObject(
705 IRunnableObject *iface,
708 CHECK_EXPECTED_METHOD("OleObjectRunnable_SetContainedObject");
712 static const IRunnableObjectVtbl OleObjectRunnableVtbl =
714 OleObjectRunnable_QueryInterface,
715 OleObjectRunnable_AddRef,
716 OleObjectRunnable_Release,
717 OleObjectRunnable_GetRunningClass,
718 OleObjectRunnable_Run,
719 OleObjectRunnable_IsRunning,
720 OleObjectRunnable_LockRunning,
721 OleObjectRunnable_SetContainedObject
724 static IRunnableObject OleObjectRunnable = { &OleObjectRunnableVtbl };
726 static const CLSID CLSID_Equation3 = {0x0002CE02, 0x0000, 0x0000, {0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46} };
728 static void test_OleCreate(IStorage *pStorage)
733 static const struct expected_method methods_olerender_none[] =
735 { "OleObject_QueryInterface", 0 },
736 { "OleObject_AddRef", 0 },
737 { "OleObject_QueryInterface", 0 },
738 { "OleObject_AddRef", TEST_OPTIONAL },
739 { "OleObject_Release", TEST_OPTIONAL },
740 { "OleObject_QueryInterface", TEST_OPTIONAL },
741 { "OleObjectPersistStg_AddRef", 0 },
742 { "OleObjectPersistStg_InitNew", 0 },
743 { "OleObjectPersistStg_Release", 0 },
744 { "OleObject_Release", 0 },
745 { "OleObject_Release", TEST_OPTIONAL },
748 static const struct expected_method methods_olerender_draw[] =
750 { "OleObject_QueryInterface", 0 },
751 { "OleObject_AddRef", 0 },
752 { "OleObject_QueryInterface", 0 },
753 { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
754 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
755 { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
756 { "OleObjectPersistStg_AddRef", 0 },
757 { "OleObjectPersistStg_InitNew", 0 },
758 { "OleObjectPersistStg_Release", 0 },
759 { "OleObject_QueryInterface", 0 },
760 { "OleObjectRunnable_AddRef", 0 },
761 { "OleObjectRunnable_Run", 0 },
762 { "OleObjectRunnable_Release", 0 },
763 { "OleObject_QueryInterface", 0 },
764 { "OleObjectCache_AddRef", 0 },
765 { "OleObjectCache_Cache", 0 },
766 { "OleObjectCache_Release", 0 },
767 { "OleObject_Release", 0 },
768 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
771 static const struct expected_method methods_olerender_format[] =
773 { "OleObject_QueryInterface", 0 },
774 { "OleObject_AddRef", 0 },
775 { "OleObject_QueryInterface", 0 },
776 { "OleObject_AddRef", 0 },
777 { "OleObject_GetMiscStatus", 0 },
778 { "OleObject_QueryInterface", 0 },
779 { "OleObjectPersistStg_AddRef", 0 },
780 { "OleObjectPersistStg_InitNew", 0 },
781 { "OleObjectPersistStg_Release", 0 },
782 { "OleObject_SetClientSite", 0 },
783 { "OleObject_Release", 0 },
784 { "OleObject_QueryInterface", 0 },
785 { "OleObjectRunnable_AddRef", 0 },
786 { "OleObjectRunnable_Run", 0 },
787 { "OleObjectRunnable_Release", 0 },
788 { "OleObject_QueryInterface", 0 },
789 { "OleObjectCache_AddRef", 0 },
790 { "OleObjectCache_Cache", 0 },
791 { "OleObjectCache_Release", 0 },
792 { "OleObject_Release", 0 },
795 static const struct expected_method methods_olerender_asis[] =
797 { "OleObject_QueryInterface", 0 },
798 { "OleObject_AddRef", 0 },
799 { "OleObject_QueryInterface", 0 },
800 { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
801 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
802 { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
803 { "OleObjectPersistStg_AddRef", 0 },
804 { "OleObjectPersistStg_InitNew", 0 },
805 { "OleObjectPersistStg_Release", 0 },
806 { "OleObject_Release", 0 },
807 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
810 static const struct expected_method methods_olerender_draw_no_runnable[] =
812 { "OleObject_QueryInterface", 0 },
813 { "OleObject_AddRef", 0 },
814 { "OleObject_QueryInterface", 0 },
815 { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
816 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
817 { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
818 { "OleObjectPersistStg_AddRef", 0 },
819 { "OleObjectPersistStg_InitNew", 0 },
820 { "OleObjectPersistStg_Release", 0 },
821 { "OleObject_QueryInterface", 0 },
822 { "OleObject_QueryInterface", 0 },
823 { "OleObjectCache_AddRef", 0 },
824 { "OleObjectCache_Cache", 0 },
825 { "OleObjectCache_Release", 0 },
826 { "OleObject_Release", 0 },
827 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
830 static const struct expected_method methods_olerender_draw_no_cache[] =
832 { "OleObject_QueryInterface", 0 },
833 { "OleObject_AddRef", 0 },
834 { "OleObject_QueryInterface", 0 },
835 { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
836 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
837 { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
838 { "OleObjectPersistStg_AddRef", 0 },
839 { "OleObjectPersistStg_InitNew", 0 },
840 { "OleObjectPersistStg_Release", 0 },
841 { "OleObject_QueryInterface", 0 },
842 { "OleObjectRunnable_AddRef", 0 },
843 { "OleObjectRunnable_Run", 0 },
844 { "OleObjectRunnable_Release", 0 },
845 { "OleObject_QueryInterface", 0 },
846 { "OleObject_Release", 0 },
847 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
851 g_expected_fetc = &formatetc;
852 formatetc.cfFormat = 0;
853 formatetc.ptd = NULL;
854 formatetc.dwAspect = DVASPECT_CONTENT;
855 formatetc.lindex = -1;
856 formatetc.tymed = TYMED_NULL;
857 runnable = &OleObjectRunnable;
858 cache = &OleObjectCache;
859 expected_method_list = methods_olerender_none;
860 trace("OleCreate with OLERENDER_NONE:\n");
861 hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_NONE, NULL, NULL, pStorage, (void **)&pObject);
862 ok_ole_success(hr, "OleCreate");
863 IOleObject_Release(pObject);
864 CHECK_NO_EXTRA_METHODS();
866 expected_method_list = methods_olerender_draw;
867 trace("OleCreate with OLERENDER_DRAW:\n");
868 hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject);
869 ok_ole_success(hr, "OleCreate");
870 IOleObject_Release(pObject);
871 CHECK_NO_EXTRA_METHODS();
873 formatetc.cfFormat = CF_TEXT;
874 formatetc.ptd = NULL;
875 formatetc.dwAspect = DVASPECT_CONTENT;
876 formatetc.lindex = -1;
877 formatetc.tymed = TYMED_HGLOBAL;
878 expected_method_list = methods_olerender_format;
879 trace("OleCreate with OLERENDER_FORMAT:\n");
880 hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_FORMAT, &formatetc, (IOleClientSite *)0xdeadbeef, pStorage, (void **)&pObject);
882 broken(hr == E_INVALIDARG), /* win2k */
883 "OleCreate failed with error 0x%08x\n", hr);
886 IOleObject_Release(pObject);
887 CHECK_NO_EXTRA_METHODS();
890 expected_method_list = methods_olerender_asis;
891 trace("OleCreate with OLERENDER_ASIS:\n");
892 hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_ASIS, NULL, NULL, pStorage, (void **)&pObject);
893 ok_ole_success(hr, "OleCreate");
894 IOleObject_Release(pObject);
895 CHECK_NO_EXTRA_METHODS();
897 formatetc.cfFormat = 0;
898 formatetc.tymed = TYMED_NULL;
900 expected_method_list = methods_olerender_draw_no_runnable;
901 trace("OleCreate with OLERENDER_DRAW (no IRunnableObject):\n");
902 hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject);
903 ok_ole_success(hr, "OleCreate");
904 IOleObject_Release(pObject);
905 CHECK_NO_EXTRA_METHODS();
907 runnable = &OleObjectRunnable;
909 expected_method_list = methods_olerender_draw_no_cache;
910 trace("OleCreate with OLERENDER_DRAW (no IOleCache):\n");
911 hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject);
912 ok_ole_success(hr, "OleCreate");
913 IOleObject_Release(pObject);
914 CHECK_NO_EXTRA_METHODS();
918 static void test_OleLoad(IStorage *pStorage)
923 static const struct expected_method methods_oleload[] =
925 { "OleObject_QueryInterface", 0 },
926 { "OleObject_AddRef", 0 },
927 { "OleObject_QueryInterface", 0 },
928 { "OleObject_AddRef", 0 },
929 { "OleObject_GetMiscStatus", 0 },
930 { "OleObject_QueryInterface", 0 },
931 { "OleObjectPersistStg_AddRef", 0 },
932 { "OleObjectPersistStg_Load", 0 },
933 { "OleObjectPersistStg_Release", 0 },
934 { "OleObject_SetClientSite", 0 },
935 { "OleObject_Release", 0 },
936 { "OleObject_QueryInterface", 0 },
937 { "OleObject_GetMiscStatus", 0 },
938 { "OleObject_Release", 0 },
942 /* Test once with IOleObject_GetMiscStatus failing */
943 expected_method_list = methods_oleload;
944 g_failGetMiscStatus = TRUE;
946 hr = OleLoad(pStorage, &IID_IOleObject, (IOleClientSite *)0xdeadbeef, (void **)&pObject);
948 broken(hr == E_INVALIDARG), /* win98 and win2k */
949 "OleLoad failed with error 0x%08x\n", hr);
952 DWORD dwStatus = 0xdeadbeef;
953 hr = IOleObject_GetMiscStatus(pObject, DVASPECT_CONTENT, &dwStatus);
954 ok(hr == E_FAIL, "Got 0x%08x\n", hr);
955 ok(dwStatus == 0x1234, "Got 0x%08x\n", dwStatus);
957 IOleObject_Release(pObject);
958 CHECK_NO_EXTRA_METHODS();
961 /* Test again, let IOleObject_GetMiscStatus succeed. */
962 g_failGetMiscStatus = FALSE;
963 expected_method_list = methods_oleload;
965 hr = OleLoad(pStorage, &IID_IOleObject, (IOleClientSite *)0xdeadbeef, (void **)&pObject);
967 broken(hr == E_INVALIDARG), /* win98 and win2k */
968 "OleLoad failed with error 0x%08x\n", hr);
971 DWORD dwStatus = 0xdeadbeef;
972 hr = IOleObject_GetMiscStatus(pObject, DVASPECT_CONTENT, &dwStatus);
973 ok(hr == S_OK, "Got 0x%08x\n", hr);
974 ok(dwStatus == 1, "Got 0x%08x\n", dwStatus);
976 IOleObject_Release(pObject);
977 CHECK_NO_EXTRA_METHODS();
981 static BOOL STDMETHODCALLTYPE draw_continue(ULONG_PTR param)
983 CHECK_EXPECTED_METHOD("draw_continue");
987 static BOOL STDMETHODCALLTYPE draw_continue_false(ULONG_PTR param)
989 CHECK_EXPECTED_METHOD("draw_continue_false");
993 static HRESULT WINAPI AdviseSink_QueryInterface(IAdviseSink *iface, REFIID riid, void **ppv)
995 if (IsEqualIID(riid, &IID_IAdviseSink) || IsEqualIID(riid, &IID_IUnknown))
998 IUnknown_AddRef(iface);
1002 return E_NOINTERFACE;
1005 static ULONG WINAPI AdviseSink_AddRef(IAdviseSink *iface)
1010 static ULONG WINAPI AdviseSink_Release(IAdviseSink *iface)
1016 static void WINAPI AdviseSink_OnDataChange(
1018 FORMATETC *pFormatetc,
1021 CHECK_EXPECTED_METHOD("AdviseSink_OnDataChange");
1024 static void WINAPI AdviseSink_OnViewChange(
1029 CHECK_EXPECTED_METHOD("AdviseSink_OnViewChange");
1032 static void WINAPI AdviseSink_OnRename(
1036 CHECK_EXPECTED_METHOD("AdviseSink_OnRename");
1039 static void WINAPI AdviseSink_OnSave(IAdviseSink *iface)
1041 CHECK_EXPECTED_METHOD("AdviseSink_OnSave");
1044 static void WINAPI AdviseSink_OnClose(IAdviseSink *iface)
1046 CHECK_EXPECTED_METHOD("AdviseSink_OnClose");
1049 static const IAdviseSinkVtbl AdviseSinkVtbl =
1051 AdviseSink_QueryInterface,
1054 AdviseSink_OnDataChange,
1055 AdviseSink_OnViewChange,
1056 AdviseSink_OnRename,
1061 static IAdviseSink AdviseSink = { &AdviseSinkVtbl };
1063 static HRESULT WINAPI DataObject_QueryInterface(
1068 CHECK_EXPECTED_METHOD("DataObject_QueryInterface");
1070 if (IsEqualIID(riid, &IID_IDataObject) || IsEqualIID(riid, &IID_IUnknown))
1079 static ULONG WINAPI DataObject_AddRef(
1082 CHECK_EXPECTED_METHOD("DataObject_AddRef");
1086 static ULONG WINAPI DataObject_Release(
1089 CHECK_EXPECTED_METHOD("DataObject_Release");
1093 static HRESULT WINAPI DataObject_GetData(
1095 LPFORMATETC pformatetcIn,
1098 CHECK_EXPECTED_METHOD("DataObject_GetData");
1102 static HRESULT WINAPI DataObject_GetDataHere(
1104 LPFORMATETC pformatetc,
1107 CHECK_EXPECTED_METHOD("DataObject_GetDataHere");
1111 static HRESULT WINAPI DataObject_QueryGetData(
1113 LPFORMATETC pformatetc)
1115 CHECK_EXPECTED_METHOD("DataObject_QueryGetData");
1119 static HRESULT WINAPI DataObject_GetCanonicalFormatEtc(
1121 LPFORMATETC pformatectIn,
1122 LPFORMATETC pformatetcOut)
1124 CHECK_EXPECTED_METHOD("DataObject_GetCanonicalFormatEtc");
1128 static HRESULT WINAPI DataObject_SetData(
1130 LPFORMATETC pformatetc,
1134 CHECK_EXPECTED_METHOD("DataObject_SetData");
1138 static HRESULT WINAPI DataObject_EnumFormatEtc(
1141 IEnumFORMATETC** ppenumFormatEtc)
1143 CHECK_EXPECTED_METHOD("DataObject_EnumFormatEtc");
1147 static HRESULT WINAPI DataObject_DAdvise(
1149 FORMATETC* pformatetc,
1151 IAdviseSink* pAdvSink,
1152 DWORD* pdwConnection)
1154 STGMEDIUM stgmedium;
1156 CHECK_EXPECTED_METHOD("DataObject_DAdvise");
1159 if(advf & ADVF_PRIMEFIRST)
1161 ok(pformatetc->cfFormat == cf_test_2, "got %04x\n", pformatetc->cfFormat);
1162 stgmedium.tymed = TYMED_HGLOBAL;
1163 U(stgmedium).hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, 4);
1164 stgmedium.pUnkForRelease = NULL;
1165 IAdviseSink_OnDataChange(pAdvSink, pformatetc, &stgmedium);
1171 static HRESULT WINAPI DataObject_DUnadvise(
1175 CHECK_EXPECTED_METHOD("DataObject_DUnadvise");
1179 static HRESULT WINAPI DataObject_EnumDAdvise(
1181 IEnumSTATDATA** ppenumAdvise)
1183 CHECK_EXPECTED_METHOD("DataObject_EnumDAdvise");
1184 return OLE_E_ADVISENOTSUPPORTED;
1187 static IDataObjectVtbl DataObjectVtbl =
1189 DataObject_QueryInterface,
1193 DataObject_GetDataHere,
1194 DataObject_QueryGetData,
1195 DataObject_GetCanonicalFormatEtc,
1197 DataObject_EnumFormatEtc,
1199 DataObject_DUnadvise,
1200 DataObject_EnumDAdvise
1203 static IDataObject DataObject = { &DataObjectVtbl };
1205 static void test_data_cache(void)
1208 IOleCache2 *pOleCache;
1210 IPersistStorage *pPS;
1211 IViewObject *pViewObject;
1212 IOleCacheControl *pOleCacheControl;
1213 IDataObject *pCacheDataObject;
1215 STGMEDIUM stgmedium;
1221 char szSystemDir[MAX_PATH];
1222 WCHAR wszPath[MAX_PATH];
1223 static const WCHAR wszShell32[] = {'\\','s','h','e','l','l','3','2','.','d','l','l',0};
1225 static const struct expected_method methods_cacheinitnew[] =
1227 { "AdviseSink_OnViewChange", 0 },
1228 { "AdviseSink_OnViewChange", 0 },
1229 { "draw_continue", 1 },
1230 { "draw_continue_false", 1 },
1231 { "DataObject_DAdvise", 0 },
1232 { "DataObject_DAdvise", 0 },
1233 { "DataObject_DUnadvise", 0 },
1234 { "DataObject_DUnadvise", 0 },
1237 static const struct expected_method methods_cacheload[] =
1239 { "AdviseSink_OnViewChange", 0 },
1240 { "draw_continue", 1 },
1241 { "draw_continue", 1 },
1242 { "draw_continue", 1 },
1243 { "DataObject_GetData", 0 },
1244 { "DataObject_GetData", 0 },
1245 { "DataObject_GetData", 0 },
1248 static const struct expected_method methods_cachethenrun[] =
1250 { "DataObject_DAdvise", 0 },
1251 { "DataObject_DAdvise", 0 },
1252 { "DataObject_DAdvise", 0 },
1253 { "DataObject_QueryGetData", 1 }, /* called by win9x and nt4 */
1254 { "DataObject_DAdvise", 0 },
1255 { "DataObject_DUnadvise", 0 },
1256 { "DataObject_DUnadvise", 0 },
1257 { "DataObject_DUnadvise", 0 },
1258 { "DataObject_DUnadvise", 0 },
1262 GetSystemDirectory(szSystemDir, sizeof(szSystemDir)/sizeof(szSystemDir[0]));
1264 expected_method_list = methods_cacheinitnew;
1266 fmtetc.cfFormat = CF_METAFILEPICT;
1267 fmtetc.dwAspect = DVASPECT_ICON;
1270 fmtetc.tymed = TYMED_MFPICT;
1272 hr = StgCreateDocfile(NULL, STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_DELETEONRELEASE, 0, &pStorage);
1273 ok_ole_success(hr, "StgCreateDocfile");
1275 /* Test with new data */
1277 hr = CreateDataCache(NULL, &CLSID_NULL, &IID_IOleCache2, (LPVOID *)&pOleCache);
1278 ok_ole_success(hr, "CreateDataCache");
1280 hr = IOleCache_QueryInterface(pOleCache, &IID_IPersistStorage, (LPVOID *)&pPS);
1281 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IPersistStorage)");
1282 hr = IOleCache_QueryInterface(pOleCache, &IID_IViewObject, (LPVOID *)&pViewObject);
1283 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IViewObject)");
1284 hr = IOleCache_QueryInterface(pOleCache, &IID_IOleCacheControl, (LPVOID *)&pOleCacheControl);
1285 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IOleCacheControl)");
1287 hr = IViewObject_SetAdvise(pViewObject, DVASPECT_ICON, ADVF_PRIMEFIRST, &AdviseSink);
1288 ok_ole_success(hr, "IViewObject_SetAdvise");
1290 hr = IPersistStorage_InitNew(pPS, pStorage);
1291 ok_ole_success(hr, "IPersistStorage_InitNew");
1293 hr = IPersistStorage_IsDirty(pPS);
1294 ok_ole_success(hr, "IPersistStorage_IsDirty");
1296 hr = IPersistStorage_GetClassID(pPS, &clsid);
1297 ok_ole_success(hr, "IPersistStorage_GetClassID");
1298 ok(IsEqualCLSID(&clsid, &IID_NULL), "clsid should be blank\n");
1300 hr = IOleCache_Uncache(pOleCache, 0xdeadbeef);
1301 ok(hr == OLE_E_NOCONNECTION, "IOleCache_Uncache with invalid value should return OLE_E_NOCONNECTION instead of 0x%x\n", hr);
1303 /* Both tests crash on NT4 and below. StgCreatePropSetStg is only available on w2k and above. */
1304 if (GetProcAddress(GetModuleHandleA("ole32.dll"), "StgCreatePropSetStg"))
1306 hr = IOleCache_Cache(pOleCache, NULL, 0, &dwConnection);
1307 ok(hr == E_INVALIDARG, "IOleCache_Cache with NULL fmtetc should have returned E_INVALIDARG instead of 0x%08x\n", hr);
1309 hr = IOleCache_Cache(pOleCache, NULL, 0, NULL);
1310 ok(hr == E_INVALIDARG, "IOleCache_Cache with NULL pdwConnection should have returned E_INVALIDARG instead of 0x%08x\n", hr);
1314 skip("tests with NULL parameters will crash on NT4 and below\n");
1317 for (fmtetc.cfFormat = CF_TEXT; fmtetc.cfFormat < CF_MAX; fmtetc.cfFormat++)
1320 fmtetc.dwAspect = DVASPECT_THUMBNAIL;
1321 for (i = 0; i < 7; i++)
1323 fmtetc.tymed = 1 << i;
1324 hr = IOleCache_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1325 if ((fmtetc.cfFormat == CF_METAFILEPICT && fmtetc.tymed == TYMED_MFPICT) ||
1326 (fmtetc.cfFormat == CF_BITMAP && fmtetc.tymed == TYMED_GDI) ||
1327 (fmtetc.cfFormat == CF_DIB && fmtetc.tymed == TYMED_HGLOBAL) ||
1328 (fmtetc.cfFormat == CF_ENHMETAFILE && fmtetc.tymed == TYMED_ENHMF))
1329 ok(hr == S_OK, "IOleCache_Cache cfFormat = %d, tymed = %d should have returned S_OK instead of 0x%08x\n",
1330 fmtetc.cfFormat, fmtetc.tymed, hr);
1331 else if (fmtetc.tymed == TYMED_HGLOBAL)
1332 ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED ||
1333 broken(hr == S_OK && fmtetc.cfFormat == CF_BITMAP) /* Win9x & NT4 */,
1334 "IOleCache_Cache cfFormat = %d, tymed = %d should have returned CACHE_S_FORMATETC_NOTSUPPORTED instead of 0x%08x\n",
1335 fmtetc.cfFormat, fmtetc.tymed, hr);
1337 ok(hr == DV_E_TYMED, "IOleCache_Cache cfFormat = %d, tymed = %d should have returned DV_E_TYMED instead of 0x%08x\n",
1338 fmtetc.cfFormat, fmtetc.tymed, hr);
1341 hr = IOleCache_Uncache(pOleCache, dwConnection);
1342 ok_ole_success(hr, "IOleCache_Uncache");
1347 fmtetc.cfFormat = CF_BITMAP;
1348 fmtetc.dwAspect = DVASPECT_THUMBNAIL;
1349 fmtetc.tymed = TYMED_GDI;
1350 hr = IOleCache_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1351 ok_ole_success(hr, "IOleCache_Cache");
1353 fmtetc.cfFormat = 0;
1354 fmtetc.dwAspect = DVASPECT_ICON;
1355 fmtetc.tymed = TYMED_MFPICT;
1356 hr = IOleCache_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1357 ok_ole_success(hr, "IOleCache_Cache");
1359 MultiByteToWideChar(CP_ACP, 0, szSystemDir, -1, wszPath, sizeof(wszPath)/sizeof(wszPath[0]));
1360 memcpy(wszPath+lstrlenW(wszPath), wszShell32, sizeof(wszShell32));
1362 fmtetc.cfFormat = CF_METAFILEPICT;
1363 stgmedium.tymed = TYMED_MFPICT;
1364 U(stgmedium).hMetaFilePict = OleMetafilePictFromIconAndLabel(
1365 LoadIcon(NULL, IDI_APPLICATION), wszPath, wszPath, 0);
1366 stgmedium.pUnkForRelease = NULL;
1368 fmtetc.dwAspect = DVASPECT_CONTENT;
1369 hr = IOleCache_SetData(pOleCache, &fmtetc, &stgmedium, FALSE);
1370 ok(hr == OLE_E_BLANK, "IOleCache_SetData for aspect not in cache should have return OLE_E_BLANK instead of 0x%08x\n", hr);
1372 fmtetc.dwAspect = DVASPECT_ICON;
1373 hr = IOleCache_SetData(pOleCache, &fmtetc, &stgmedium, FALSE);
1374 ok_ole_success(hr, "IOleCache_SetData");
1375 ReleaseStgMedium(&stgmedium);
1377 hr = IViewObject_Freeze(pViewObject, DVASPECT_ICON, -1, NULL, &dwFreeze);
1379 ok_ole_success(hr, "IViewObject_Freeze");
1380 hr = IViewObject_Freeze(pViewObject, DVASPECT_CONTENT, -1, NULL, &dwFreeze);
1381 ok(hr == OLE_E_BLANK, "IViewObject_Freeze with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1386 rcBounds.right = 100;
1387 rcBounds.bottom = 100;
1388 hdcMem = CreateCompatibleDC(NULL);
1390 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1391 ok_ole_success(hr, "IViewObject_Draw");
1393 hr = IViewObject_Draw(pViewObject, DVASPECT_CONTENT, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1394 ok(hr == OLE_E_BLANK, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1396 /* a NULL draw_continue fn ptr */
1397 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, NULL, 0xdeadbeef);
1398 ok_ole_success(hr, "IViewObject_Draw");
1400 /* draw_continue that returns FALSE to abort drawing */
1401 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue_false, 0xdeadbeef);
1403 broken(hr == S_OK), /* win9x may skip the callbacks */
1404 "IViewObject_Draw with draw_continue_false returns 0x%08x\n", hr);
1408 hr = IOleCacheControl_OnRun(pOleCacheControl, &DataObject);
1409 ok_ole_success(hr, "IOleCacheControl_OnRun");
1411 hr = IPersistStorage_Save(pPS, pStorage, TRUE);
1412 ok_ole_success(hr, "IPersistStorage_Save");
1414 hr = IPersistStorage_SaveCompleted(pPS, NULL);
1415 ok_ole_success(hr, "IPersistStorage_SaveCompleted");
1417 hr = IPersistStorage_IsDirty(pPS);
1418 ok(hr == S_FALSE, "IPersistStorage_IsDirty should have returned S_FALSE instead of 0x%x\n", hr);
1420 IPersistStorage_Release(pPS);
1421 IViewObject_Release(pViewObject);
1422 IOleCache_Release(pOleCache);
1423 IOleCacheControl_Release(pOleCacheControl);
1425 CHECK_NO_EXTRA_METHODS();
1427 /* Test with loaded data */
1428 trace("Testing loaded data with CreateDataCache:\n");
1429 expected_method_list = methods_cacheload;
1431 hr = CreateDataCache(NULL, &CLSID_NULL, &IID_IOleCache2, (LPVOID *)&pOleCache);
1432 ok_ole_success(hr, "CreateDataCache");
1434 hr = IOleCache_QueryInterface(pOleCache, &IID_IPersistStorage, (LPVOID *)&pPS);
1435 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IPersistStorage)");
1436 hr = IOleCache_QueryInterface(pOleCache, &IID_IViewObject, (LPVOID *)&pViewObject);
1437 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IViewObject)");
1439 hr = IViewObject_SetAdvise(pViewObject, DVASPECT_ICON, ADVF_PRIMEFIRST, &AdviseSink);
1440 ok_ole_success(hr, "IViewObject_SetAdvise");
1442 hr = IPersistStorage_Load(pPS, pStorage);
1443 ok_ole_success(hr, "IPersistStorage_Load");
1445 hr = IPersistStorage_IsDirty(pPS);
1446 ok(hr == S_FALSE, "IPersistStorage_IsDirty should have returned S_FALSE instead of 0x%x\n", hr);
1448 fmtetc.cfFormat = 0;
1449 fmtetc.dwAspect = DVASPECT_ICON;
1452 fmtetc.tymed = TYMED_MFPICT;
1453 hr = IOleCache_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1454 ok(hr == CACHE_S_SAMECACHE, "IOleCache_Cache with already loaded data format type should return CACHE_S_SAMECACHE instead of 0x%x\n", hr);
1458 rcBounds.right = 100;
1459 rcBounds.bottom = 100;
1460 hdcMem = CreateCompatibleDC(NULL);
1462 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1463 ok_ole_success(hr, "IViewObject_Draw");
1465 hr = IViewObject_Draw(pViewObject, DVASPECT_CONTENT, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1466 ok(hr == OLE_E_BLANK, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1468 /* unload the cached storage object, causing it to be reloaded */
1469 hr = IOleCache2_DiscardCache(pOleCache, DISCARDCACHE_NOSAVE);
1470 ok_ole_success(hr, "IOleCache2_DiscardCache");
1471 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1472 ok_ole_success(hr, "IViewObject_Draw");
1474 /* unload the cached storage object, but don't allow it to be reloaded */
1475 hr = IPersistStorage_HandsOffStorage(pPS);
1476 ok_ole_success(hr, "IPersistStorage_HandsOffStorage");
1477 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1478 ok_ole_success(hr, "IViewObject_Draw");
1479 hr = IOleCache2_DiscardCache(pOleCache, DISCARDCACHE_NOSAVE);
1480 ok_ole_success(hr, "IOleCache2_DiscardCache");
1481 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1482 ok(hr == OLE_E_BLANK, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1487 hr = IOleCache_InitCache(pOleCache, &DataObject);
1488 ok(hr == CACHE_E_NOCACHE_UPDATED, "IOleCache_InitCache should have returned CACHE_E_NOCACHE_UPDATED instead of 0x%08x\n", hr);
1491 IPersistStorage_Release(pPS);
1492 IViewObject_Release(pViewObject);
1493 IOleCache_Release(pOleCache);
1496 CHECK_NO_EXTRA_METHODS();
1499 hr = CreateDataCache(NULL, &CLSID_NULL, &IID_IOleCache2, (LPVOID *)&pOleCache);
1500 ok_ole_success(hr, "CreateDataCache");
1502 expected_method_list = methods_cachethenrun;
1504 hr = IOleCache_QueryInterface(pOleCache, &IID_IDataObject, (LPVOID *)&pCacheDataObject);
1505 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IDataObject)");
1506 hr = IOleCache_QueryInterface(pOleCache, &IID_IOleCacheControl, (LPVOID *)&pOleCacheControl);
1507 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IOleCacheControl)");
1509 fmtetc.cfFormat = CF_METAFILEPICT;
1510 fmtetc.dwAspect = DVASPECT_CONTENT;
1511 fmtetc.tymed = TYMED_MFPICT;
1513 hr = IOleCache_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1514 ok_ole_success(hr, "IOleCache_Cache");
1516 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1517 ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1519 fmtetc.cfFormat = cf_test_1;
1520 fmtetc.dwAspect = DVASPECT_CONTENT;
1521 fmtetc.tymed = TYMED_HGLOBAL;
1523 hr = IOleCache_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1524 ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED, "got %08x\n", hr);
1526 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1527 ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1529 fmtetc.cfFormat = cf_test_2;
1530 hr = IOleCache_Cache(pOleCache, &fmtetc, ADVF_PRIMEFIRST, &dwConnection);
1531 ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED, "got %08x\n", hr);
1533 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1534 ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1536 hr = IOleCacheControl_OnRun(pOleCacheControl, &DataObject);
1537 ok_ole_success(hr, "IOleCacheControl_OnRun");
1539 fmtetc.cfFormat = cf_test_3;
1540 hr = IOleCache_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1541 ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED, "got %08x\n", hr);
1543 fmtetc.cfFormat = cf_test_1;
1544 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1545 ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1547 fmtetc.cfFormat = cf_test_2;
1548 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1549 ok(hr == S_OK, "got %08x\n", hr);
1550 ReleaseStgMedium(&stgmedium);
1552 fmtetc.cfFormat = cf_test_3;
1553 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1554 ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1556 IOleCacheControl_Release(pOleCacheControl);
1557 IDataObject_Release(pCacheDataObject);
1558 IOleCache_Release(pOleCache);
1560 CHECK_NO_EXTRA_METHODS();
1562 IStorage_Release(pStorage);
1565 static void test_default_handler(void)
1568 IOleObject *pObject;
1569 IRunnableObject *pRunnableObject;
1570 IOleClientSite *pClientSite;
1571 IDataObject *pDataObject;
1575 LPOLESTR pszUserType;
1580 IOleInPlaceObject *pInPlaceObj;
1581 IEnumOLEVERB *pEnumVerbs;
1583 static const WCHAR wszUnknown[] = {'U','n','k','n','o','w','n',0};
1584 static const WCHAR wszHostName[] = {'W','i','n','e',' ','T','e','s','t',' ','P','r','o','g','r','a','m',0};
1585 static const WCHAR wszDelim[] = {'!',0};
1587 static const struct expected_method methods_embeddinghelper[] =
1589 { "OleObject_QueryInterface", 0 },
1590 { "OleObject_AddRef", 0 },
1591 { "OleObject_QueryInterface", 0 },
1592 { "OleObject_QueryInterface", TEST_TODO },
1593 { "OleObject_QueryInterface", 0 },
1594 { "OleObject_QueryInterface", 0 },
1595 { "OleObject_QueryInterface", TEST_OPTIONAL }, /* Win95/98/NT4 */
1596 { "OleObject_Release", TEST_TODO },
1597 { "WINE_EXTRA", TEST_OPTIONAL },
1601 hr = CoCreateInstance(&CLSID_WineTest, NULL, CLSCTX_INPROC_HANDLER, &IID_IOleObject, (void **)&pObject);
1602 ok(hr == REGDB_E_CLASSNOTREG, "CoCreateInstance should have failed with REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1604 hr = OleCreateDefaultHandler(&CLSID_WineTest, NULL, &IID_IOleObject, (void **)&pObject);
1605 ok_ole_success(hr, "OleCreateDefaultHandler");
1607 hr = IOleObject_QueryInterface(pObject, &IID_IOleInPlaceObject, (void **)&pInPlaceObj);
1608 ok(hr == E_NOINTERFACE, "IOleObject_QueryInterface(&IID_IOleInPlaceObject) should return E_NOINTERFACE instead of 0x%08x\n", hr);
1610 hr = IOleObject_Advise(pObject, &AdviseSink, &dwAdvConn);
1611 ok_ole_success(hr, "IOleObject_Advise");
1613 hr = IOleObject_Close(pObject, OLECLOSE_NOSAVE);
1614 ok_ole_success(hr, "IOleObject_Close");
1616 /* FIXME: test IOleObject_EnumAdvise */
1618 hr = IOleObject_EnumVerbs(pObject, &pEnumVerbs);
1619 ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_EnumVerbs should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1621 hr = IOleObject_GetClientSite(pObject, &pClientSite);
1622 ok_ole_success(hr, "IOleObject_GetClientSite");
1624 hr = IOleObject_GetClipboardData(pObject, 0, &pDataObject);
1625 ok(hr == OLE_E_NOTRUNNING,
1626 "IOleObject_GetClipboardData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n",
1629 hr = IOleObject_GetExtent(pObject, DVASPECT_CONTENT, &sizel);
1630 ok(hr == OLE_E_BLANK, "IOleObject_GetExtent should have returned OLE_E_BLANK instead of 0x%08x\n",
1633 hr = IOleObject_GetMiscStatus(pObject, DVASPECT_CONTENT, &dwStatus);
1634 ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_GetMiscStatus should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1636 hr = IOleObject_GetUserClassID(pObject, &clsid);
1637 ok_ole_success(hr, "IOleObject_GetUserClassID");
1638 ok(IsEqualCLSID(&clsid, &CLSID_WineTest), "clsid != CLSID_WineTest\n");
1640 hr = IOleObject_GetUserType(pObject, USERCLASSTYPE_FULL, &pszUserType);
1642 ok_ole_success(hr, "IOleObject_GetUserType");
1643 ok(!lstrcmpW(pszUserType, wszUnknown), "Retrieved user type was wrong\n");
1646 hr = IOleObject_InitFromData(pObject, NULL, TRUE, 0);
1647 ok(hr == OLE_E_NOTRUNNING, "IOleObject_InitFromData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1649 hr = IOleObject_IsUpToDate(pObject);
1650 ok(hr == OLE_E_NOTRUNNING, "IOleObject_IsUpToDate should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1652 palette.palNumEntries = 1;
1653 palette.palVersion = 2;
1654 memset(&palette.palPalEntry[0], 0, sizeof(palette.palPalEntry[0]));
1655 hr = IOleObject_SetColorScheme(pObject, &palette);
1656 ok(hr == OLE_E_NOTRUNNING, "IOleObject_SetColorScheme should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1658 sizel.cx = sizel.cy = 0;
1659 hr = IOleObject_SetExtent(pObject, DVASPECT_CONTENT, &sizel);
1660 ok(hr == OLE_E_NOTRUNNING, "IOleObject_SetExtent should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1662 hr = IOleObject_SetHostNames(pObject, wszHostName, NULL);
1663 ok_ole_success(hr, "IOleObject_SetHostNames");
1665 hr = CreateItemMoniker(wszDelim, wszHostName, &pMoniker);
1666 ok_ole_success(hr, "CreateItemMoniker");
1667 hr = IOleObject_SetMoniker(pObject, OLEWHICHMK_CONTAINER, pMoniker);
1668 ok_ole_success(hr, "IOleObject_SetMoniker");
1669 IMoniker_Release(pMoniker);
1671 hr = IOleObject_GetMoniker(pObject, OLEGETMONIKER_ONLYIFTHERE, OLEWHICHMK_CONTAINER, &pMoniker);
1672 ok(hr == E_FAIL, "IOleObject_GetMoniker should have returned E_FAIL instead of 0x%08x\n", hr);
1674 hr = IOleObject_Update(pObject);
1676 ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_Update should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1678 hr = IOleObject_QueryInterface(pObject, &IID_IDataObject, (void **)&pDataObject);
1679 ok_ole_success(hr, "IOleObject_QueryInterface");
1681 fmtetc.cfFormat = CF_TEXT;
1683 fmtetc.dwAspect = DVASPECT_CONTENT;
1685 fmtetc.tymed = TYMED_NULL;
1686 hr = IDataObject_DAdvise(pDataObject, &fmtetc, 0, &AdviseSink, &dwAdvConn);
1687 ok_ole_success(hr, "IDataObject_DAdvise");
1689 fmtetc.cfFormat = CF_ENHMETAFILE;
1691 fmtetc.dwAspect = DVASPECT_CONTENT;
1693 fmtetc.tymed = TYMED_ENHMF;
1694 hr = IDataObject_DAdvise(pDataObject, &fmtetc, 0, &AdviseSink, &dwAdvConn);
1695 ok_ole_success(hr, "IDataObject_DAdvise");
1697 fmtetc.cfFormat = CF_ENHMETAFILE;
1699 fmtetc.dwAspect = DVASPECT_CONTENT;
1701 fmtetc.tymed = TYMED_ENHMF;
1702 hr = IDataObject_QueryGetData(pDataObject, &fmtetc);
1704 ok(hr == OLE_E_NOTRUNNING, "IDataObject_QueryGetData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1706 fmtetc.cfFormat = CF_TEXT;
1708 fmtetc.dwAspect = DVASPECT_CONTENT;
1710 fmtetc.tymed = TYMED_NULL;
1711 hr = IDataObject_QueryGetData(pDataObject, &fmtetc);
1713 ok(hr == OLE_E_NOTRUNNING, "IDataObject_QueryGetData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1715 hr = IOleObject_QueryInterface(pObject, &IID_IRunnableObject, (void **)&pRunnableObject);
1716 ok_ole_success(hr, "IOleObject_QueryInterface");
1718 hr = IRunnableObject_SetContainedObject(pRunnableObject, TRUE);
1719 ok_ole_success(hr, "IRunnableObject_SetContainedObject");
1721 hr = IRunnableObject_Run(pRunnableObject, NULL);
1722 ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_Run should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1724 hr = IOleObject_Close(pObject, OLECLOSE_NOSAVE);
1725 ok_ole_success(hr, "IOleObject_Close");
1727 IRunnableObject_Release(pRunnableObject);
1728 IOleObject_Release(pObject);
1730 /* Test failure propagation from delegate ::QueryInterface */
1731 hr = CoRegisterClassObject(&CLSID_WineTest, (IUnknown*)&OleObjectCF,
1732 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &dwRegister);
1733 ok_ole_success(hr, "CoRegisterClassObject");
1736 expected_method_list = methods_embeddinghelper;
1737 hr = OleCreateEmbeddingHelper(&CLSID_WineTest, NULL, EMBDHLP_INPROC_SERVER,
1738 &OleObjectCF, &IID_IOleObject, (void**)&pObject);
1739 ok_ole_success(hr, "OleCreateEmbeddingHelper");
1744 g_QIFailsWith = E_FAIL;
1745 hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1746 ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1748 g_QIFailsWith = E_NOINTERFACE;
1749 hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1750 ok(hr == E_NOINTERFACE, "Got 0x%08x\n", hr);
1752 g_QIFailsWith = CO_E_OBJNOTCONNECTED;
1753 hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1754 ok(hr == CO_E_OBJNOTCONNECTED, "Got 0x%08x\n", hr);
1756 g_QIFailsWith = 0x87654321;
1757 hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1758 ok(hr == 0x87654321, "Got 0x%08x\n", hr);
1760 IOleObject_Release(pObject);
1763 CHECK_NO_EXTRA_METHODS();
1765 hr = CoRevokeClassObject(dwRegister);
1766 ok_ole_success(hr, "CoRevokeClassObject");
1770 static void test_runnable(void)
1772 static const struct expected_method methods_query_runnable[] =
1774 { "OleObject_QueryInterface", 0 },
1775 { "OleObjectRunnable_AddRef", 0 },
1776 { "OleObjectRunnable_IsRunning", 0 },
1777 { "OleObjectRunnable_Release", 0 },
1781 static const struct expected_method methods_no_runnable[] =
1783 { "OleObject_QueryInterface", 0 },
1787 IOleObject *object = &OleObject;
1789 expected_method_list = methods_query_runnable;
1790 ok(OleIsRunning(object), "Object should be running\n");
1791 CHECK_NO_EXTRA_METHODS();
1793 g_isRunning = FALSE;
1794 expected_method_list = methods_query_runnable;
1795 ok(OleIsRunning(object) == FALSE, "Object should not be running\n");
1796 CHECK_NO_EXTRA_METHODS();
1798 g_showRunnable = FALSE; /* QueryInterface(IID_IRunnableObject, ...) will fail */
1799 expected_method_list = methods_no_runnable;
1800 ok(OleIsRunning(object), "Object without IRunnableObject should be running\n");
1801 CHECK_NO_EXTRA_METHODS();
1804 g_showRunnable = TRUE;
1807 static HRESULT WINAPI Unknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
1810 if (IsEqualIID(riid, &IID_IUnknown)) *ppv = iface;
1813 IUnknown_AddRef((IUnknown *)*ppv);
1816 return E_NOINTERFACE;
1819 static ULONG WINAPI Unknown_AddRef(IUnknown *iface)
1824 static ULONG WINAPI Unknown_Release(IUnknown *iface)
1829 static const IUnknownVtbl UnknownVtbl =
1831 Unknown_QueryInterface,
1836 static IUnknown Unknown = { &UnknownVtbl };
1838 static void test_OleLockRunning(void)
1842 hr = OleLockRunning((LPUNKNOWN)&Unknown, TRUE, FALSE);
1843 ok(hr == S_OK, "OleLockRunning failed 0x%08x\n", hr);
1853 cf_test_1 = RegisterClipboardFormatA("cf_winetest_1");
1854 cf_test_2 = RegisterClipboardFormatA("cf_winetest_2");
1855 cf_test_3 = RegisterClipboardFormatA("cf_winetest_3");
1859 hr = CoRegisterClassObject(&CLSID_Equation3, (IUnknown *)&OleObjectCF, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &dwRegister);
1860 ok_ole_success(hr, "CoRegisterClassObject");
1862 hr = StgCreateDocfile(NULL, STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_DELETEONRELEASE, 0, &pStorage);
1863 ok_ole_success(hr, "StgCreateDocfile");
1865 test_OleCreate(pStorage);
1867 hr = IStorage_Stat(pStorage, &statstg, STATFLAG_NONAME);
1868 ok_ole_success(hr, "IStorage_Stat");
1869 ok(IsEqualCLSID(&CLSID_Equation3, &statstg.clsid), "Wrong CLSID in storage\n");
1871 test_OleLoad(pStorage);
1873 IStorage_Release(pStorage);
1875 hr = CoRevokeClassObject(dwRegister);
1876 ok_ole_success(hr, "CoRevokeClassObject");
1879 test_default_handler();
1881 test_OleLockRunning();