ole32/tests: Add tests for loading a dib 'CONTENTS' stream.
[wine.git] / dlls / ole32 / tests / ole2.c
blob0c27bd1e8abc8638bbb7b64cd0959c32b47702a9
1 /*
2 * Object Linking and Embedding Tests
4 * Copyright 2005 Robert Shearman
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
22 #define CONST_VTABLE
23 #define WIN32_LEAN_AND_MEAN
25 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "objbase.h"
30 #include "shlguid.h"
32 #include "wine/test.h"
34 #include "initguid.h"
36 DEFINE_GUID(CLSID_Picture_Metafile,0x315,0,0,0xc0,0,0,0,0,0,0,0x46);
37 DEFINE_GUID(CLSID_Picture_Dib,0x316,0,0,0xc0,0,0,0,0,0,0,0x46);
39 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
41 #define DEFINE_EXPECT(func) \
42 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
44 #define SET_EXPECT(func) \
45 expect_ ## func = TRUE
47 #define CHECK_EXPECT2(func) \
48 do { \
49 ok(expect_ ##func, "unexpected call " #func "\n"); \
50 called_ ## func = TRUE; \
51 }while(0)
53 #define CHECK_EXPECT(func) \
54 do { \
55 CHECK_EXPECT2(func); \
56 expect_ ## func = FALSE; \
57 }while(0)
59 #define CHECK_CALLED(func) \
60 do { \
61 ok(called_ ## func, "expected " #func "\n"); \
62 expect_ ## func = called_ ## func = FALSE; \
63 }while(0)
65 DEFINE_EXPECT(Storage_Stat);
66 DEFINE_EXPECT(Storage_OpenStream_CompObj);
67 DEFINE_EXPECT(Storage_SetClass);
68 DEFINE_EXPECT(Storage_CreateStream_CompObj);
69 DEFINE_EXPECT(Storage_OpenStream_Ole);
71 static IPersistStorage OleObjectPersistStg;
72 static IOleCache *cache;
73 static IRunnableObject *runnable;
75 static const CLSID CLSID_WineTestOld =
76 { /* 9474ba1a-258b-490b-bc13-516e9239acd0 */
77 0x9474ba1a,
78 0x258b,
79 0x490b,
80 {0xbc, 0x13, 0x51, 0x6e, 0x92, 0x39, 0xac, 0xd0}
83 static const CLSID CLSID_WineTest =
84 { /* 9474ba1a-258b-490b-bc13-516e9239ace0 */
85 0x9474ba1a,
86 0x258b,
87 0x490b,
88 {0xbc, 0x13, 0x51, 0x6e, 0x92, 0x39, 0xac, 0xe0}
91 static const IID IID_WineTest =
92 { /* 9474ba1a-258b-490b-bc13-516e9239ace1 */
93 0x9474ba1a,
94 0x258b,
95 0x490b,
96 {0xbc, 0x13, 0x51, 0x6e, 0x92, 0x39, 0xac, 0xe1}
99 #define TEST_OPTIONAL 0x1
100 #define TEST_TODO 0x2
102 struct expected_method
104 const char *method;
105 unsigned int flags;
108 static const struct expected_method *expected_method_list;
109 static FORMATETC *g_expected_fetc = NULL;
111 static BOOL g_showRunnable = TRUE;
112 static BOOL g_isRunning = TRUE;
113 static BOOL g_failGetMiscStatus;
114 static HRESULT g_QIFailsWith;
116 static UINT cf_test_1, cf_test_2, cf_test_3;
118 #define CHECK_EXPECTED_METHOD(method_name) \
119 do { \
120 trace("%s\n", method_name); \
121 ok(expected_method_list->method != NULL, "Extra method %s called\n", method_name); \
122 if (!strcmp(expected_method_list->method, "WINE_EXTRA")) \
124 todo_wine ok(0, "Too many method calls.\n"); \
125 break; \
127 if (expected_method_list->method) \
129 while (expected_method_list->flags & TEST_OPTIONAL && \
130 strcmp(expected_method_list->method, method_name) != 0) \
131 expected_method_list++; \
132 if (expected_method_list->flags & TEST_TODO) \
133 todo_wine \
134 ok(!strcmp(expected_method_list->method, method_name), \
135 "Expected %s to be called instead of %s\n", \
136 expected_method_list->method, method_name); \
137 else \
138 ok(!strcmp(expected_method_list->method, method_name), \
139 "Expected %s to be called instead of %s\n", \
140 expected_method_list->method, method_name); \
141 expected_method_list++; \
143 } while(0)
145 #define CHECK_NO_EXTRA_METHODS() \
146 do { \
147 while (expected_method_list->flags & TEST_OPTIONAL) \
148 expected_method_list++; \
149 ok(!expected_method_list->method, "Method sequence starting from %s not called\n", expected_method_list->method); \
150 } while (0)
152 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
154 CHECK_EXPECTED_METHOD("OleObject_QueryInterface");
156 *ppv = NULL;
158 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IOleObject))
159 *ppv = iface;
160 else if (IsEqualIID(riid, &IID_IPersistStorage))
161 *ppv = &OleObjectPersistStg;
162 else if (IsEqualIID(riid, &IID_IOleCache))
163 *ppv = cache;
164 else if (IsEqualIID(riid, &IID_IRunnableObject) && g_showRunnable)
165 *ppv = runnable;
166 else if (IsEqualIID(riid, &IID_WineTest))
167 return g_QIFailsWith;
169 if(*ppv) {
170 IUnknown_AddRef((IUnknown*)*ppv);
171 return S_OK;
174 trace("OleObject_QueryInterface: returning E_NOINTERFACE\n");
175 return E_NOINTERFACE;
178 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
180 CHECK_EXPECTED_METHOD("OleObject_AddRef");
181 return 2;
184 static ULONG WINAPI OleObject_Release(IOleObject *iface)
186 CHECK_EXPECTED_METHOD("OleObject_Release");
187 return 1;
190 static HRESULT WINAPI OleObject_SetClientSite
192 IOleObject *iface,
193 IOleClientSite *pClientSite
196 CHECK_EXPECTED_METHOD("OleObject_SetClientSite");
197 return S_OK;
200 static HRESULT WINAPI OleObject_GetClientSite
202 IOleObject *iface,
203 IOleClientSite **ppClientSite
206 CHECK_EXPECTED_METHOD("OleObject_GetClientSite");
207 return E_NOTIMPL;
210 static HRESULT WINAPI OleObject_SetHostNames
212 IOleObject *iface,
213 LPCOLESTR szContainerApp,
214 LPCOLESTR szContainerObj
217 CHECK_EXPECTED_METHOD("OleObject_SetHostNames");
218 return S_OK;
221 static HRESULT WINAPI OleObject_Close
223 IOleObject *iface,
224 DWORD dwSaveOption
227 CHECK_EXPECTED_METHOD("OleObject_Close");
228 return S_OK;
231 static HRESULT WINAPI OleObject_SetMoniker
233 IOleObject *iface,
234 DWORD dwWhichMoniker,
235 IMoniker *pmk
238 CHECK_EXPECTED_METHOD("OleObject_SetMoniker");
239 return S_OK;
242 static HRESULT WINAPI OleObject_GetMoniker
244 IOleObject *iface,
245 DWORD dwAssign,
246 DWORD dwWhichMoniker,
247 IMoniker **ppmk
250 CHECK_EXPECTED_METHOD("OleObject_GetMoniker");
251 return S_OK;
254 static HRESULT WINAPI OleObject_InitFromData
256 IOleObject *iface,
257 IDataObject *pDataObject,
258 BOOL fCreation,
259 DWORD dwReserved
262 CHECK_EXPECTED_METHOD("OleObject_InitFromData");
263 return S_OK;
266 static HRESULT WINAPI OleObject_GetClipboardData
268 IOleObject *iface,
269 DWORD dwReserved,
270 IDataObject **ppDataObject
273 CHECK_EXPECTED_METHOD("OleObject_GetClipboardData");
274 return E_NOTIMPL;
277 static HRESULT WINAPI OleObject_DoVerb
279 IOleObject *iface,
280 LONG iVerb,
281 LPMSG lpmsg,
282 IOleClientSite *pActiveSite,
283 LONG lindex,
284 HWND hwndParent,
285 LPCRECT lprcPosRect
288 CHECK_EXPECTED_METHOD("OleObject_DoVerb");
289 return S_OK;
292 static HRESULT WINAPI OleObject_EnumVerbs
294 IOleObject *iface,
295 IEnumOLEVERB **ppEnumOleVerb
298 CHECK_EXPECTED_METHOD("OleObject_EnumVerbs");
299 return E_NOTIMPL;
302 static HRESULT WINAPI OleObject_Update
304 IOleObject *iface
307 CHECK_EXPECTED_METHOD("OleObject_Update");
308 return S_OK;
311 static HRESULT WINAPI OleObject_IsUpToDate
313 IOleObject *iface
316 CHECK_EXPECTED_METHOD("OleObject_IsUpToDate");
317 return S_OK;
320 static HRESULT WINAPI OleObject_GetUserClassID
322 IOleObject *iface,
323 CLSID *pClsid
326 CHECK_EXPECTED_METHOD("OleObject_GetUserClassID");
327 return E_NOTIMPL;
330 static HRESULT WINAPI OleObject_GetUserType
332 IOleObject *iface,
333 DWORD dwFormOfType,
334 LPOLESTR *pszUserType
337 CHECK_EXPECTED_METHOD("OleObject_GetUserType");
338 return E_NOTIMPL;
341 static HRESULT WINAPI OleObject_SetExtent
343 IOleObject *iface,
344 DWORD dwDrawAspect,
345 SIZEL *psizel
348 CHECK_EXPECTED_METHOD("OleObject_SetExtent");
349 return S_OK;
352 static HRESULT WINAPI OleObject_GetExtent
354 IOleObject *iface,
355 DWORD dwDrawAspect,
356 SIZEL *psizel
359 CHECK_EXPECTED_METHOD("OleObject_GetExtent");
360 return E_NOTIMPL;
363 static HRESULT WINAPI OleObject_Advise
365 IOleObject *iface,
366 IAdviseSink *pAdvSink,
367 DWORD *pdwConnection
370 CHECK_EXPECTED_METHOD("OleObject_Advise");
371 return S_OK;
374 static HRESULT WINAPI OleObject_Unadvise
376 IOleObject *iface,
377 DWORD dwConnection
380 CHECK_EXPECTED_METHOD("OleObject_Unadvise");
381 return S_OK;
384 static HRESULT WINAPI OleObject_EnumAdvise
386 IOleObject *iface,
387 IEnumSTATDATA **ppenumAdvise
390 CHECK_EXPECTED_METHOD("OleObject_EnumAdvise");
391 return E_NOTIMPL;
394 static HRESULT WINAPI OleObject_GetMiscStatus
396 IOleObject *iface,
397 DWORD dwAspect,
398 DWORD *pdwStatus
401 CHECK_EXPECTED_METHOD("OleObject_GetMiscStatus");
402 if(!g_failGetMiscStatus)
404 *pdwStatus = OLEMISC_RECOMPOSEONRESIZE;
405 return S_OK;
407 else
409 *pdwStatus = 0x1234;
410 return E_FAIL;
414 static HRESULT WINAPI OleObject_SetColorScheme
416 IOleObject *iface,
417 LOGPALETTE *pLogpal
420 CHECK_EXPECTED_METHOD("OleObject_SetColorScheme");
421 return E_NOTIMPL;
424 static const IOleObjectVtbl OleObjectVtbl =
426 OleObject_QueryInterface,
427 OleObject_AddRef,
428 OleObject_Release,
429 OleObject_SetClientSite,
430 OleObject_GetClientSite,
431 OleObject_SetHostNames,
432 OleObject_Close,
433 OleObject_SetMoniker,
434 OleObject_GetMoniker,
435 OleObject_InitFromData,
436 OleObject_GetClipboardData,
437 OleObject_DoVerb,
438 OleObject_EnumVerbs,
439 OleObject_Update,
440 OleObject_IsUpToDate,
441 OleObject_GetUserClassID,
442 OleObject_GetUserType,
443 OleObject_SetExtent,
444 OleObject_GetExtent,
445 OleObject_Advise,
446 OleObject_Unadvise,
447 OleObject_EnumAdvise,
448 OleObject_GetMiscStatus,
449 OleObject_SetColorScheme
452 static IOleObject OleObject = { &OleObjectVtbl };
454 static HRESULT WINAPI OleObjectPersistStg_QueryInterface(IPersistStorage *iface, REFIID riid, void **ppv)
456 trace("OleObjectPersistStg_QueryInterface\n");
457 return IUnknown_QueryInterface((IUnknown *)&OleObject, riid, ppv);
460 static ULONG WINAPI OleObjectPersistStg_AddRef(IPersistStorage *iface)
462 CHECK_EXPECTED_METHOD("OleObjectPersistStg_AddRef");
463 return 2;
466 static ULONG WINAPI OleObjectPersistStg_Release(IPersistStorage *iface)
468 CHECK_EXPECTED_METHOD("OleObjectPersistStg_Release");
469 return 1;
472 static HRESULT WINAPI OleObjectPersistStg_GetClassId(IPersistStorage *iface, CLSID *clsid)
474 CHECK_EXPECTED_METHOD("OleObjectPersistStg_GetClassId");
475 return E_NOTIMPL;
478 static HRESULT WINAPI OleObjectPersistStg_IsDirty
480 IPersistStorage *iface
483 CHECK_EXPECTED_METHOD("OleObjectPersistStg_IsDirty");
484 return S_OK;
487 static HRESULT WINAPI OleObjectPersistStg_InitNew
489 IPersistStorage *iface,
490 IStorage *pStg
493 CHECK_EXPECTED_METHOD("OleObjectPersistStg_InitNew");
494 return S_OK;
497 static HRESULT WINAPI OleObjectPersistStg_Load
499 IPersistStorage *iface,
500 IStorage *pStg
503 CHECK_EXPECTED_METHOD("OleObjectPersistStg_Load");
504 return S_OK;
507 static HRESULT WINAPI OleObjectPersistStg_Save
509 IPersistStorage *iface,
510 IStorage *pStgSave,
511 BOOL fSameAsLoad
514 CHECK_EXPECTED_METHOD("OleObjectPersistStg_Save");
515 return S_OK;
518 static HRESULT WINAPI OleObjectPersistStg_SaveCompleted
520 IPersistStorage *iface,
521 IStorage *pStgNew
524 CHECK_EXPECTED_METHOD("OleObjectPersistStg_SaveCompleted");
525 return S_OK;
528 static HRESULT WINAPI OleObjectPersistStg_HandsOffStorage
530 IPersistStorage *iface
533 CHECK_EXPECTED_METHOD("OleObjectPersistStg_HandsOffStorage");
534 return S_OK;
537 static const IPersistStorageVtbl OleObjectPersistStgVtbl =
539 OleObjectPersistStg_QueryInterface,
540 OleObjectPersistStg_AddRef,
541 OleObjectPersistStg_Release,
542 OleObjectPersistStg_GetClassId,
543 OleObjectPersistStg_IsDirty,
544 OleObjectPersistStg_InitNew,
545 OleObjectPersistStg_Load,
546 OleObjectPersistStg_Save,
547 OleObjectPersistStg_SaveCompleted,
548 OleObjectPersistStg_HandsOffStorage
551 static IPersistStorage OleObjectPersistStg = { &OleObjectPersistStgVtbl };
553 static HRESULT WINAPI OleObjectCache_QueryInterface(IOleCache *iface, REFIID riid, void **ppv)
555 return IUnknown_QueryInterface((IUnknown *)&OleObject, riid, ppv);
558 static ULONG WINAPI OleObjectCache_AddRef(IOleCache *iface)
560 CHECK_EXPECTED_METHOD("OleObjectCache_AddRef");
561 return 2;
564 static ULONG WINAPI OleObjectCache_Release(IOleCache *iface)
566 CHECK_EXPECTED_METHOD("OleObjectCache_Release");
567 return 1;
570 static HRESULT WINAPI OleObjectCache_Cache
572 IOleCache *iface,
573 FORMATETC *pformatetc,
574 DWORD advf,
575 DWORD *pdwConnection
578 CHECK_EXPECTED_METHOD("OleObjectCache_Cache");
579 if (g_expected_fetc) {
580 ok(pformatetc != NULL, "pformatetc should not be NULL\n");
581 if (pformatetc) {
582 ok(pformatetc->cfFormat == g_expected_fetc->cfFormat,
583 "cfFormat: %x\n", pformatetc->cfFormat);
584 ok((pformatetc->ptd != NULL) == (g_expected_fetc->ptd != NULL),
585 "ptd: %p\n", pformatetc->ptd);
586 ok(pformatetc->dwAspect == g_expected_fetc->dwAspect,
587 "dwAspect: %x\n", pformatetc->dwAspect);
588 ok(pformatetc->lindex == g_expected_fetc->lindex,
589 "lindex: %x\n", pformatetc->lindex);
590 ok(pformatetc->tymed == g_expected_fetc->tymed,
591 "tymed: %x\n", pformatetc->tymed);
593 } else
594 ok(pformatetc == NULL, "pformatetc should be NULL\n");
595 return S_OK;
598 static HRESULT WINAPI OleObjectCache_Uncache
600 IOleCache *iface,
601 DWORD dwConnection
604 CHECK_EXPECTED_METHOD("OleObjectCache_Uncache");
605 return S_OK;
608 static HRESULT WINAPI OleObjectCache_EnumCache
610 IOleCache *iface,
611 IEnumSTATDATA **ppenumSTATDATA
614 CHECK_EXPECTED_METHOD("OleObjectCache_EnumCache");
615 return S_OK;
619 static HRESULT WINAPI OleObjectCache_InitCache
621 IOleCache *iface,
622 IDataObject *pDataObject
625 CHECK_EXPECTED_METHOD("OleObjectCache_InitCache");
626 return S_OK;
630 static HRESULT WINAPI OleObjectCache_SetData
632 IOleCache *iface,
633 FORMATETC *pformatetc,
634 STGMEDIUM *pmedium,
635 BOOL fRelease
638 CHECK_EXPECTED_METHOD("OleObjectCache_SetData");
639 return S_OK;
643 static const IOleCacheVtbl OleObjectCacheVtbl =
645 OleObjectCache_QueryInterface,
646 OleObjectCache_AddRef,
647 OleObjectCache_Release,
648 OleObjectCache_Cache,
649 OleObjectCache_Uncache,
650 OleObjectCache_EnumCache,
651 OleObjectCache_InitCache,
652 OleObjectCache_SetData
655 static IOleCache OleObjectCache = { &OleObjectCacheVtbl };
657 static HRESULT WINAPI OleObjectCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
659 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
661 *ppv = iface;
662 IClassFactory_AddRef(iface);
663 return S_OK;
665 *ppv = NULL;
666 return E_NOINTERFACE;
669 static ULONG WINAPI OleObjectCF_AddRef(IClassFactory *iface)
671 return 2;
674 static ULONG WINAPI OleObjectCF_Release(IClassFactory *iface)
676 return 1;
679 static HRESULT WINAPI OleObjectCF_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID riid, void **ppv)
681 return IUnknown_QueryInterface((IUnknown *)&OleObject, riid, ppv);
684 static HRESULT WINAPI OleObjectCF_LockServer(IClassFactory *iface, BOOL lock)
686 return S_OK;
689 static const IClassFactoryVtbl OleObjectCFVtbl =
691 OleObjectCF_QueryInterface,
692 OleObjectCF_AddRef,
693 OleObjectCF_Release,
694 OleObjectCF_CreateInstance,
695 OleObjectCF_LockServer
698 static IClassFactory OleObjectCF = { &OleObjectCFVtbl };
700 static HRESULT WINAPI OleObjectRunnable_QueryInterface(IRunnableObject *iface, REFIID riid, void **ppv)
702 return IUnknown_QueryInterface((IUnknown *)&OleObject, riid, ppv);
705 static ULONG WINAPI OleObjectRunnable_AddRef(IRunnableObject *iface)
707 CHECK_EXPECTED_METHOD("OleObjectRunnable_AddRef");
708 return 2;
711 static ULONG WINAPI OleObjectRunnable_Release(IRunnableObject *iface)
713 CHECK_EXPECTED_METHOD("OleObjectRunnable_Release");
714 return 1;
717 static HRESULT WINAPI OleObjectRunnable_GetRunningClass(
718 IRunnableObject *iface,
719 LPCLSID lpClsid)
721 CHECK_EXPECTED_METHOD("OleObjectRunnable_GetRunningClass");
722 return E_NOTIMPL;
725 static HRESULT WINAPI OleObjectRunnable_Run(
726 IRunnableObject *iface,
727 LPBINDCTX pbc)
729 CHECK_EXPECTED_METHOD("OleObjectRunnable_Run");
730 return S_OK;
733 static BOOL WINAPI OleObjectRunnable_IsRunning(IRunnableObject *iface)
735 CHECK_EXPECTED_METHOD("OleObjectRunnable_IsRunning");
736 return g_isRunning;
739 static HRESULT WINAPI OleObjectRunnable_LockRunning(
740 IRunnableObject *iface,
741 BOOL fLock,
742 BOOL fLastUnlockCloses)
744 CHECK_EXPECTED_METHOD("OleObjectRunnable_LockRunning");
745 return S_OK;
748 static HRESULT WINAPI OleObjectRunnable_SetContainedObject(
749 IRunnableObject *iface,
750 BOOL fContained)
752 CHECK_EXPECTED_METHOD("OleObjectRunnable_SetContainedObject");
753 return S_OK;
756 static const IRunnableObjectVtbl OleObjectRunnableVtbl =
758 OleObjectRunnable_QueryInterface,
759 OleObjectRunnable_AddRef,
760 OleObjectRunnable_Release,
761 OleObjectRunnable_GetRunningClass,
762 OleObjectRunnable_Run,
763 OleObjectRunnable_IsRunning,
764 OleObjectRunnable_LockRunning,
765 OleObjectRunnable_SetContainedObject
768 static IRunnableObject OleObjectRunnable = { &OleObjectRunnableVtbl };
770 static const CLSID CLSID_Equation3 = {0x0002CE02, 0x0000, 0x0000, {0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46} };
772 static HRESULT WINAPI viewobject_QueryInterface(IViewObject *iface, REFIID riid, void **obj)
774 if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IViewObject))
776 *obj = iface;
777 return S_OK;
780 *obj = NULL;
781 return E_NOINTERFACE;
784 static ULONG WINAPI viewobject_AddRef(IViewObject *iface)
786 return 2;
789 static ULONG WINAPI viewobject_Release(IViewObject *iface)
791 return 1;
794 static HRESULT WINAPI viewobject_Draw(IViewObject *iface, DWORD aspect, LONG index,
795 void *paspect, DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw,
796 LPCRECTL bounds, LPCRECTL wbounds, BOOL (STDMETHODCALLTYPE *pfnContinue)(ULONG_PTR dwContinue),
797 ULONG_PTR dwContinue)
799 ok(index == -1, "index=%d\n", index);
800 return S_OK;
803 static HRESULT WINAPI viewobject_GetColorSet(IViewObject *iface, DWORD draw_aspect, LONG index,
804 void *aspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **colorset)
806 ok(0, "unexpected call GetColorSet\n");
807 return E_NOTIMPL;
810 static HRESULT WINAPI viewobject_Freeze(IViewObject *iface, DWORD draw_aspect, LONG index,
811 void *aspect, DWORD *freeze)
813 ok(0, "unexpected call Freeze\n");
814 return E_NOTIMPL;
817 static HRESULT WINAPI viewobject_Unfreeze(IViewObject *iface, DWORD freeze)
819 ok(0, "unexpected call Unfreeze\n");
820 return E_NOTIMPL;
823 static HRESULT WINAPI viewobject_SetAdvise(IViewObject *iface, DWORD aspects, DWORD advf, IAdviseSink *sink)
825 ok(0, "unexpected call SetAdvise\n");
826 return E_NOTIMPL;
829 static HRESULT WINAPI viewobject_GetAdvise(IViewObject *iface, DWORD *aspects, DWORD *advf,
830 IAdviseSink **sink)
832 ok(0, "unexpected call GetAdvise\n");
833 return E_NOTIMPL;
836 static const struct IViewObjectVtbl viewobjectvtbl = {
837 viewobject_QueryInterface,
838 viewobject_AddRef,
839 viewobject_Release,
840 viewobject_Draw,
841 viewobject_GetColorSet,
842 viewobject_Freeze,
843 viewobject_Unfreeze,
844 viewobject_SetAdvise,
845 viewobject_GetAdvise
848 static IViewObject viewobject = { &viewobjectvtbl };
850 static void test_OleCreate(IStorage *pStorage)
852 HRESULT hr;
853 IOleObject *pObject;
854 FORMATETC formatetc;
855 static const struct expected_method methods_olerender_none[] =
857 { "OleObject_QueryInterface", 0 },
858 { "OleObject_AddRef", 0 },
859 { "OleObject_QueryInterface", 0 },
860 { "OleObject_AddRef", TEST_OPTIONAL },
861 { "OleObject_Release", TEST_OPTIONAL },
862 { "OleObject_QueryInterface", TEST_OPTIONAL },
863 { "OleObjectPersistStg_AddRef", 0 },
864 { "OleObjectPersistStg_InitNew", 0 },
865 { "OleObjectPersistStg_Release", 0 },
866 { "OleObject_Release", 0 },
867 { "OleObject_Release", TEST_OPTIONAL },
868 { NULL, 0 }
870 static const struct expected_method methods_olerender_draw[] =
872 { "OleObject_QueryInterface", 0 },
873 { "OleObject_AddRef", 0 },
874 { "OleObject_QueryInterface", 0 },
875 { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
876 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
877 { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
878 { "OleObjectPersistStg_AddRef", 0 },
879 { "OleObjectPersistStg_InitNew", 0 },
880 { "OleObjectPersistStg_Release", 0 },
881 { "OleObject_QueryInterface", 0 },
882 { "OleObjectRunnable_AddRef", 0 },
883 { "OleObjectRunnable_Run", 0 },
884 { "OleObjectRunnable_Release", 0 },
885 { "OleObject_QueryInterface", 0 },
886 { "OleObjectCache_AddRef", 0 },
887 { "OleObjectCache_Cache", 0 },
888 { "OleObjectCache_Release", 0 },
889 { "OleObject_Release", 0 },
890 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
891 { NULL, 0 }
893 static const struct expected_method methods_olerender_format[] =
895 { "OleObject_QueryInterface", 0 },
896 { "OleObject_AddRef", 0 },
897 { "OleObject_QueryInterface", 0 },
898 { "OleObject_AddRef", 0 },
899 { "OleObject_GetMiscStatus", 0 },
900 { "OleObject_QueryInterface", 0 },
901 { "OleObjectPersistStg_AddRef", 0 },
902 { "OleObjectPersistStg_InitNew", 0 },
903 { "OleObjectPersistStg_Release", 0 },
904 { "OleObject_SetClientSite", 0 },
905 { "OleObject_Release", 0 },
906 { "OleObject_QueryInterface", 0 },
907 { "OleObjectRunnable_AddRef", 0 },
908 { "OleObjectRunnable_Run", 0 },
909 { "OleObjectRunnable_Release", 0 },
910 { "OleObject_QueryInterface", 0 },
911 { "OleObjectCache_AddRef", 0 },
912 { "OleObjectCache_Cache", 0 },
913 { "OleObjectCache_Release", 0 },
914 { "OleObject_Release", 0 },
915 { NULL, 0 }
917 static const struct expected_method methods_olerender_asis[] =
919 { "OleObject_QueryInterface", 0 },
920 { "OleObject_AddRef", 0 },
921 { "OleObject_QueryInterface", 0 },
922 { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
923 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
924 { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
925 { "OleObjectPersistStg_AddRef", 0 },
926 { "OleObjectPersistStg_InitNew", 0 },
927 { "OleObjectPersistStg_Release", 0 },
928 { "OleObject_Release", 0 },
929 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
930 { NULL, 0 }
932 static const struct expected_method methods_olerender_draw_no_runnable[] =
934 { "OleObject_QueryInterface", 0 },
935 { "OleObject_AddRef", 0 },
936 { "OleObject_QueryInterface", 0 },
937 { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
938 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
939 { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
940 { "OleObjectPersistStg_AddRef", 0 },
941 { "OleObjectPersistStg_InitNew", 0 },
942 { "OleObjectPersistStg_Release", 0 },
943 { "OleObject_QueryInterface", 0 },
944 { "OleObject_QueryInterface", 0 },
945 { "OleObjectCache_AddRef", 0 },
946 { "OleObjectCache_Cache", 0 },
947 { "OleObjectCache_Release", 0 },
948 { "OleObject_Release", 0 },
949 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
950 { NULL, 0 },
952 static const struct expected_method methods_olerender_draw_no_cache[] =
954 { "OleObject_QueryInterface", 0 },
955 { "OleObject_AddRef", 0 },
956 { "OleObject_QueryInterface", 0 },
957 { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
958 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
959 { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
960 { "OleObjectPersistStg_AddRef", 0 },
961 { "OleObjectPersistStg_InitNew", 0 },
962 { "OleObjectPersistStg_Release", 0 },
963 { "OleObject_QueryInterface", 0 },
964 { "OleObjectRunnable_AddRef", 0 },
965 { "OleObjectRunnable_Run", 0 },
966 { "OleObjectRunnable_Release", 0 },
967 { "OleObject_QueryInterface", 0 },
968 { "OleObject_Release", 0 },
969 { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
970 { NULL, 0 }
973 g_expected_fetc = &formatetc;
974 formatetc.cfFormat = 0;
975 formatetc.ptd = NULL;
976 formatetc.dwAspect = DVASPECT_CONTENT;
977 formatetc.lindex = -1;
978 formatetc.tymed = TYMED_NULL;
979 runnable = &OleObjectRunnable;
980 cache = &OleObjectCache;
981 expected_method_list = methods_olerender_none;
982 trace("OleCreate with OLERENDER_NONE:\n");
983 hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_NONE, NULL, NULL, pStorage, (void **)&pObject);
984 ok_ole_success(hr, "OleCreate");
985 IOleObject_Release(pObject);
986 CHECK_NO_EXTRA_METHODS();
988 expected_method_list = methods_olerender_draw;
989 trace("OleCreate with OLERENDER_DRAW:\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 formatetc.cfFormat = CF_TEXT;
996 formatetc.ptd = NULL;
997 formatetc.dwAspect = DVASPECT_CONTENT;
998 formatetc.lindex = -1;
999 formatetc.tymed = TYMED_HGLOBAL;
1000 expected_method_list = methods_olerender_format;
1001 trace("OleCreate with OLERENDER_FORMAT:\n");
1002 hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_FORMAT, &formatetc, (IOleClientSite *)0xdeadbeef, pStorage, (void **)&pObject);
1003 ok(hr == S_OK ||
1004 broken(hr == E_INVALIDARG), /* win2k */
1005 "OleCreate failed with error 0x%08x\n", hr);
1006 if (pObject)
1008 IOleObject_Release(pObject);
1009 CHECK_NO_EXTRA_METHODS();
1012 expected_method_list = methods_olerender_asis;
1013 trace("OleCreate with OLERENDER_ASIS:\n");
1014 hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_ASIS, NULL, NULL, pStorage, (void **)&pObject);
1015 ok_ole_success(hr, "OleCreate");
1016 IOleObject_Release(pObject);
1017 CHECK_NO_EXTRA_METHODS();
1019 formatetc.cfFormat = 0;
1020 formatetc.tymed = TYMED_NULL;
1021 runnable = NULL;
1022 expected_method_list = methods_olerender_draw_no_runnable;
1023 trace("OleCreate with OLERENDER_DRAW (no IRunnableObject):\n");
1024 hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject);
1025 ok_ole_success(hr, "OleCreate");
1026 IOleObject_Release(pObject);
1027 CHECK_NO_EXTRA_METHODS();
1029 runnable = &OleObjectRunnable;
1030 cache = NULL;
1031 expected_method_list = methods_olerender_draw_no_cache;
1032 trace("OleCreate with OLERENDER_DRAW (no IOleCache):\n");
1033 hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject);
1034 ok_ole_success(hr, "OleCreate");
1035 IOleObject_Release(pObject);
1036 CHECK_NO_EXTRA_METHODS();
1037 trace("end\n");
1038 g_expected_fetc = NULL;
1041 static void test_OleLoad(IStorage *pStorage)
1043 HRESULT hr;
1044 IOleObject *pObject;
1046 static const struct expected_method methods_oleload[] =
1048 { "OleObject_QueryInterface", 0 },
1049 { "OleObject_AddRef", 0 },
1050 { "OleObject_QueryInterface", 0 },
1051 { "OleObject_AddRef", 0 },
1052 { "OleObject_GetMiscStatus", 0 },
1053 { "OleObject_QueryInterface", 0 },
1054 { "OleObjectPersistStg_AddRef", 0 },
1055 { "OleObjectPersistStg_Load", 0 },
1056 { "OleObjectPersistStg_Release", 0 },
1057 { "OleObject_SetClientSite", 0 },
1058 { "OleObject_Release", 0 },
1059 { "OleObject_QueryInterface", 0 },
1060 { "OleObject_GetMiscStatus", 0 },
1061 { "OleObject_Release", 0 },
1062 { NULL, 0 }
1065 /* Test once with IOleObject_GetMiscStatus failing */
1066 expected_method_list = methods_oleload;
1067 g_failGetMiscStatus = TRUE;
1068 trace("OleLoad:\n");
1069 hr = OleLoad(pStorage, &IID_IOleObject, (IOleClientSite *)0xdeadbeef, (void **)&pObject);
1070 ok(hr == S_OK ||
1071 broken(hr == E_INVALIDARG), /* win98 and win2k */
1072 "OleLoad failed with error 0x%08x\n", hr);
1073 if(pObject)
1075 DWORD dwStatus = 0xdeadbeef;
1076 hr = IOleObject_GetMiscStatus(pObject, DVASPECT_CONTENT, &dwStatus);
1077 ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1078 ok(dwStatus == 0x1234, "Got 0x%08x\n", dwStatus);
1080 IOleObject_Release(pObject);
1081 CHECK_NO_EXTRA_METHODS();
1084 /* Test again, let IOleObject_GetMiscStatus succeed. */
1085 g_failGetMiscStatus = FALSE;
1086 expected_method_list = methods_oleload;
1087 trace("OleLoad:\n");
1088 hr = OleLoad(pStorage, &IID_IOleObject, (IOleClientSite *)0xdeadbeef, (void **)&pObject);
1089 ok(hr == S_OK ||
1090 broken(hr == E_INVALIDARG), /* win98 and win2k */
1091 "OleLoad failed with error 0x%08x\n", hr);
1092 if (pObject)
1094 DWORD dwStatus = 0xdeadbeef;
1095 hr = IOleObject_GetMiscStatus(pObject, DVASPECT_CONTENT, &dwStatus);
1096 ok(hr == S_OK, "Got 0x%08x\n", hr);
1097 ok(dwStatus == 1, "Got 0x%08x\n", dwStatus);
1099 IOleObject_Release(pObject);
1100 CHECK_NO_EXTRA_METHODS();
1104 static BOOL STDMETHODCALLTYPE draw_continue(ULONG_PTR param)
1106 CHECK_EXPECTED_METHOD("draw_continue");
1107 return TRUE;
1110 static BOOL STDMETHODCALLTYPE draw_continue_false(ULONG_PTR param)
1112 CHECK_EXPECTED_METHOD("draw_continue_false");
1113 return FALSE;
1116 static HRESULT WINAPI AdviseSink_QueryInterface(IAdviseSink *iface, REFIID riid, void **ppv)
1118 if (IsEqualIID(riid, &IID_IAdviseSink) || IsEqualIID(riid, &IID_IUnknown))
1120 *ppv = iface;
1121 IAdviseSink_AddRef(iface);
1122 return S_OK;
1124 *ppv = NULL;
1125 return E_NOINTERFACE;
1128 static ULONG WINAPI AdviseSink_AddRef(IAdviseSink *iface)
1130 return 2;
1133 static ULONG WINAPI AdviseSink_Release(IAdviseSink *iface)
1135 return 1;
1139 static void WINAPI AdviseSink_OnDataChange(
1140 IAdviseSink *iface,
1141 FORMATETC *pFormatetc,
1142 STGMEDIUM *pStgmed)
1144 CHECK_EXPECTED_METHOD("AdviseSink_OnDataChange");
1147 static void WINAPI AdviseSink_OnViewChange(
1148 IAdviseSink *iface,
1149 DWORD dwAspect,
1150 LONG lindex)
1152 CHECK_EXPECTED_METHOD("AdviseSink_OnViewChange");
1155 static void WINAPI AdviseSink_OnRename(
1156 IAdviseSink *iface,
1157 IMoniker *pmk)
1159 CHECK_EXPECTED_METHOD("AdviseSink_OnRename");
1162 static void WINAPI AdviseSink_OnSave(IAdviseSink *iface)
1164 CHECK_EXPECTED_METHOD("AdviseSink_OnSave");
1167 static void WINAPI AdviseSink_OnClose(IAdviseSink *iface)
1169 CHECK_EXPECTED_METHOD("AdviseSink_OnClose");
1172 static const IAdviseSinkVtbl AdviseSinkVtbl =
1174 AdviseSink_QueryInterface,
1175 AdviseSink_AddRef,
1176 AdviseSink_Release,
1177 AdviseSink_OnDataChange,
1178 AdviseSink_OnViewChange,
1179 AdviseSink_OnRename,
1180 AdviseSink_OnSave,
1181 AdviseSink_OnClose
1184 static IAdviseSink AdviseSink = { &AdviseSinkVtbl };
1186 static HRESULT WINAPI DataObject_QueryInterface(
1187 IDataObject* iface,
1188 REFIID riid,
1189 void** ppvObject)
1191 CHECK_EXPECTED_METHOD("DataObject_QueryInterface");
1193 if (IsEqualIID(riid, &IID_IDataObject) || IsEqualIID(riid, &IID_IUnknown))
1195 *ppvObject = iface;
1196 return S_OK;
1198 *ppvObject = NULL;
1199 return S_OK;
1202 static ULONG WINAPI DataObject_AddRef(
1203 IDataObject* iface)
1205 CHECK_EXPECTED_METHOD("DataObject_AddRef");
1206 return 2;
1209 static ULONG WINAPI DataObject_Release(
1210 IDataObject* iface)
1212 CHECK_EXPECTED_METHOD("DataObject_Release");
1213 return 1;
1216 static HRESULT WINAPI DataObject_GetData(
1217 IDataObject* iface,
1218 LPFORMATETC pformatetcIn,
1219 STGMEDIUM* pmedium)
1221 CHECK_EXPECTED_METHOD("DataObject_GetData");
1222 return E_NOTIMPL;
1225 static HRESULT WINAPI DataObject_GetDataHere(
1226 IDataObject* iface,
1227 LPFORMATETC pformatetc,
1228 STGMEDIUM* pmedium)
1230 CHECK_EXPECTED_METHOD("DataObject_GetDataHere");
1231 return E_NOTIMPL;
1234 static HRESULT WINAPI DataObject_QueryGetData(
1235 IDataObject* iface,
1236 LPFORMATETC pformatetc)
1238 CHECK_EXPECTED_METHOD("DataObject_QueryGetData");
1239 return S_OK;
1242 static HRESULT WINAPI DataObject_GetCanonicalFormatEtc(
1243 IDataObject* iface,
1244 LPFORMATETC pformatectIn,
1245 LPFORMATETC pformatetcOut)
1247 CHECK_EXPECTED_METHOD("DataObject_GetCanonicalFormatEtc");
1248 return E_NOTIMPL;
1251 static HRESULT WINAPI DataObject_SetData(
1252 IDataObject* iface,
1253 LPFORMATETC pformatetc,
1254 STGMEDIUM* pmedium,
1255 BOOL fRelease)
1257 CHECK_EXPECTED_METHOD("DataObject_SetData");
1258 return E_NOTIMPL;
1261 static HRESULT WINAPI DataObject_EnumFormatEtc(
1262 IDataObject* iface,
1263 DWORD dwDirection,
1264 IEnumFORMATETC** ppenumFormatEtc)
1266 CHECK_EXPECTED_METHOD("DataObject_EnumFormatEtc");
1267 return E_NOTIMPL;
1270 static HRESULT WINAPI DataObject_DAdvise(
1271 IDataObject* iface,
1272 FORMATETC* pformatetc,
1273 DWORD advf,
1274 IAdviseSink* pAdvSink,
1275 DWORD* pdwConnection)
1277 STGMEDIUM stgmedium;
1279 CHECK_EXPECTED_METHOD("DataObject_DAdvise");
1280 *pdwConnection = 1;
1282 if(advf & ADVF_PRIMEFIRST)
1284 ok(pformatetc->cfFormat == cf_test_2, "got %04x\n", pformatetc->cfFormat);
1285 stgmedium.tymed = TYMED_HGLOBAL;
1286 U(stgmedium).hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, 4);
1287 stgmedium.pUnkForRelease = NULL;
1288 IAdviseSink_OnDataChange(pAdvSink, pformatetc, &stgmedium);
1291 return S_OK;
1294 static HRESULT WINAPI DataObject_DUnadvise(
1295 IDataObject* iface,
1296 DWORD dwConnection)
1298 CHECK_EXPECTED_METHOD("DataObject_DUnadvise");
1299 return S_OK;
1302 static HRESULT WINAPI DataObject_EnumDAdvise(
1303 IDataObject* iface,
1304 IEnumSTATDATA** ppenumAdvise)
1306 CHECK_EXPECTED_METHOD("DataObject_EnumDAdvise");
1307 return OLE_E_ADVISENOTSUPPORTED;
1310 static IDataObjectVtbl DataObjectVtbl =
1312 DataObject_QueryInterface,
1313 DataObject_AddRef,
1314 DataObject_Release,
1315 DataObject_GetData,
1316 DataObject_GetDataHere,
1317 DataObject_QueryGetData,
1318 DataObject_GetCanonicalFormatEtc,
1319 DataObject_SetData,
1320 DataObject_EnumFormatEtc,
1321 DataObject_DAdvise,
1322 DataObject_DUnadvise,
1323 DataObject_EnumDAdvise
1326 static IDataObject DataObject = { &DataObjectVtbl };
1328 static void test_data_cache(void)
1330 HRESULT hr;
1331 IOleCache2 *pOleCache;
1332 IStorage *pStorage;
1333 IPersistStorage *pPS;
1334 IViewObject *pViewObject;
1335 IOleCacheControl *pOleCacheControl;
1336 IDataObject *pCacheDataObject;
1337 FORMATETC fmtetc;
1338 STGMEDIUM stgmedium;
1339 DWORD dwConnection;
1340 DWORD dwFreeze;
1341 RECTL rcBounds;
1342 HDC hdcMem;
1343 CLSID clsid;
1344 char szSystemDir[MAX_PATH];
1345 WCHAR wszPath[MAX_PATH];
1346 static const WCHAR wszShell32[] = {'\\','s','h','e','l','l','3','2','.','d','l','l',0};
1348 static const struct expected_method methods_cacheinitnew[] =
1350 { "AdviseSink_OnViewChange", 0 },
1351 { "AdviseSink_OnViewChange", 0 },
1352 { "draw_continue", 1 },
1353 { "draw_continue_false", 1 },
1354 { "DataObject_DAdvise", 0 },
1355 { "DataObject_DAdvise", 0 },
1356 { "DataObject_DUnadvise", 0 },
1357 { "DataObject_DUnadvise", 0 },
1358 { NULL, 0 }
1360 static const struct expected_method methods_cacheload[] =
1362 { "AdviseSink_OnViewChange", 0 },
1363 { "draw_continue", 1 },
1364 { "draw_continue", 1 },
1365 { "draw_continue", 1 },
1366 { "DataObject_GetData", 0 },
1367 { "DataObject_GetData", 0 },
1368 { "DataObject_GetData", 0 },
1369 { NULL, 0 }
1371 static const struct expected_method methods_cachethenrun[] =
1373 { "DataObject_DAdvise", 0 },
1374 { "DataObject_DAdvise", 0 },
1375 { "DataObject_DAdvise", 0 },
1376 { "DataObject_QueryGetData", 1 }, /* called by win9x and nt4 */
1377 { "DataObject_DAdvise", 0 },
1378 { "DataObject_DUnadvise", 0 },
1379 { "DataObject_DUnadvise", 0 },
1380 { "DataObject_DUnadvise", 0 },
1381 { "DataObject_DUnadvise", 0 },
1382 { NULL, 0 }
1385 GetSystemDirectoryA(szSystemDir, sizeof(szSystemDir)/sizeof(szSystemDir[0]));
1387 expected_method_list = methods_cacheinitnew;
1389 fmtetc.cfFormat = CF_METAFILEPICT;
1390 fmtetc.dwAspect = DVASPECT_ICON;
1391 fmtetc.lindex = -1;
1392 fmtetc.ptd = NULL;
1393 fmtetc.tymed = TYMED_MFPICT;
1395 hr = StgCreateDocfile(NULL, STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_DELETEONRELEASE, 0, &pStorage);
1396 ok_ole_success(hr, "StgCreateDocfile");
1398 /* Test with new data */
1400 hr = CreateDataCache(NULL, &CLSID_NULL, &IID_IOleCache2, (LPVOID *)&pOleCache);
1401 ok_ole_success(hr, "CreateDataCache");
1403 hr = IOleCache2_QueryInterface(pOleCache, &IID_IPersistStorage, (LPVOID *)&pPS);
1404 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IPersistStorage)");
1405 hr = IOleCache2_QueryInterface(pOleCache, &IID_IViewObject, (LPVOID *)&pViewObject);
1406 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IViewObject)");
1407 hr = IOleCache2_QueryInterface(pOleCache, &IID_IOleCacheControl, (LPVOID *)&pOleCacheControl);
1408 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IOleCacheControl)");
1410 hr = IViewObject_SetAdvise(pViewObject, DVASPECT_ICON, ADVF_PRIMEFIRST, &AdviseSink);
1411 ok_ole_success(hr, "IViewObject_SetAdvise");
1413 hr = IPersistStorage_InitNew(pPS, pStorage);
1414 ok_ole_success(hr, "IPersistStorage_InitNew");
1416 hr = IPersistStorage_IsDirty(pPS);
1417 ok_ole_success(hr, "IPersistStorage_IsDirty");
1419 hr = IPersistStorage_GetClassID(pPS, &clsid);
1420 ok_ole_success(hr, "IPersistStorage_GetClassID");
1421 ok(IsEqualCLSID(&clsid, &IID_NULL), "clsid should be blank\n");
1423 hr = IOleCache2_Uncache(pOleCache, 0xdeadbeef);
1424 ok(hr == OLE_E_NOCONNECTION, "IOleCache_Uncache with invalid value should return OLE_E_NOCONNECTION instead of 0x%x\n", hr);
1426 /* Both tests crash on NT4 and below. StgCreatePropSetStg is only available on w2k and above. */
1427 if (GetProcAddress(GetModuleHandleA("ole32.dll"), "StgCreatePropSetStg"))
1429 hr = IOleCache2_Cache(pOleCache, NULL, 0, &dwConnection);
1430 ok(hr == E_INVALIDARG, "IOleCache_Cache with NULL fmtetc should have returned E_INVALIDARG instead of 0x%08x\n", hr);
1432 hr = IOleCache2_Cache(pOleCache, NULL, 0, NULL);
1433 ok(hr == E_INVALIDARG, "IOleCache_Cache with NULL pdwConnection should have returned E_INVALIDARG instead of 0x%08x\n", hr);
1435 else
1437 skip("tests with NULL parameters will crash on NT4 and below\n");
1440 for (fmtetc.cfFormat = CF_TEXT; fmtetc.cfFormat < CF_MAX; fmtetc.cfFormat++)
1442 int i;
1443 fmtetc.dwAspect = DVASPECT_THUMBNAIL;
1444 for (i = 0; i < 7; i++)
1446 fmtetc.tymed = 1 << i;
1447 hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1448 if ((fmtetc.cfFormat == CF_METAFILEPICT && fmtetc.tymed == TYMED_MFPICT) ||
1449 (fmtetc.cfFormat == CF_BITMAP && fmtetc.tymed == TYMED_GDI) ||
1450 (fmtetc.cfFormat == CF_DIB && fmtetc.tymed == TYMED_HGLOBAL) ||
1451 (fmtetc.cfFormat == CF_ENHMETAFILE && fmtetc.tymed == TYMED_ENHMF))
1452 ok(hr == S_OK, "IOleCache_Cache cfFormat = %d, tymed = %d should have returned S_OK instead of 0x%08x\n",
1453 fmtetc.cfFormat, fmtetc.tymed, hr);
1454 else if (fmtetc.tymed == TYMED_HGLOBAL)
1455 ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED ||
1456 broken(hr == S_OK && fmtetc.cfFormat == CF_BITMAP) /* Win9x & NT4 */,
1457 "IOleCache_Cache cfFormat = %d, tymed = %d should have returned CACHE_S_FORMATETC_NOTSUPPORTED instead of 0x%08x\n",
1458 fmtetc.cfFormat, fmtetc.tymed, hr);
1459 else
1460 ok(hr == DV_E_TYMED, "IOleCache_Cache cfFormat = %d, tymed = %d should have returned DV_E_TYMED instead of 0x%08x\n",
1461 fmtetc.cfFormat, fmtetc.tymed, hr);
1462 if (SUCCEEDED(hr))
1464 hr = IOleCache2_Uncache(pOleCache, dwConnection);
1465 ok_ole_success(hr, "IOleCache_Uncache");
1470 fmtetc.cfFormat = CF_BITMAP;
1471 fmtetc.dwAspect = DVASPECT_THUMBNAIL;
1472 fmtetc.tymed = TYMED_GDI;
1473 hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1474 ok_ole_success(hr, "IOleCache_Cache");
1476 fmtetc.cfFormat = 0;
1477 fmtetc.dwAspect = DVASPECT_ICON;
1478 fmtetc.tymed = TYMED_MFPICT;
1479 hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1480 ok_ole_success(hr, "IOleCache_Cache");
1482 MultiByteToWideChar(CP_ACP, 0, szSystemDir, -1, wszPath, sizeof(wszPath)/sizeof(wszPath[0]));
1483 memcpy(wszPath+lstrlenW(wszPath), wszShell32, sizeof(wszShell32));
1485 fmtetc.cfFormat = CF_METAFILEPICT;
1486 stgmedium.tymed = TYMED_MFPICT;
1487 U(stgmedium).hMetaFilePict = OleMetafilePictFromIconAndLabel(
1488 LoadIconA(NULL, (LPSTR)IDI_APPLICATION), wszPath, wszPath, 0);
1489 stgmedium.pUnkForRelease = NULL;
1491 fmtetc.dwAspect = DVASPECT_CONTENT;
1492 hr = IOleCache2_SetData(pOleCache, &fmtetc, &stgmedium, FALSE);
1493 ok(hr == OLE_E_BLANK, "IOleCache_SetData for aspect not in cache should have return OLE_E_BLANK instead of 0x%08x\n", hr);
1495 fmtetc.dwAspect = DVASPECT_ICON;
1496 hr = IOleCache2_SetData(pOleCache, &fmtetc, &stgmedium, FALSE);
1497 ok_ole_success(hr, "IOleCache_SetData");
1498 ReleaseStgMedium(&stgmedium);
1500 hr = IViewObject_Freeze(pViewObject, DVASPECT_ICON, -1, NULL, &dwFreeze);
1501 todo_wine {
1502 ok_ole_success(hr, "IViewObject_Freeze");
1503 hr = IViewObject_Freeze(pViewObject, DVASPECT_CONTENT, -1, NULL, &dwFreeze);
1504 ok(hr == OLE_E_BLANK, "IViewObject_Freeze with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1507 rcBounds.left = 0;
1508 rcBounds.top = 0;
1509 rcBounds.right = 100;
1510 rcBounds.bottom = 100;
1511 hdcMem = CreateCompatibleDC(NULL);
1513 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1514 ok_ole_success(hr, "IViewObject_Draw");
1516 hr = IViewObject_Draw(pViewObject, DVASPECT_CONTENT, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1517 ok(hr == OLE_E_BLANK, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1519 /* a NULL draw_continue fn ptr */
1520 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, NULL, 0xdeadbeef);
1521 ok_ole_success(hr, "IViewObject_Draw");
1523 /* draw_continue that returns FALSE to abort drawing */
1524 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue_false, 0xdeadbeef);
1525 ok(hr == E_ABORT ||
1526 broken(hr == S_OK), /* win9x may skip the callbacks */
1527 "IViewObject_Draw with draw_continue_false returns 0x%08x\n", hr);
1529 DeleteDC(hdcMem);
1531 hr = IOleCacheControl_OnRun(pOleCacheControl, &DataObject);
1532 ok_ole_success(hr, "IOleCacheControl_OnRun");
1534 hr = IPersistStorage_Save(pPS, pStorage, TRUE);
1535 ok_ole_success(hr, "IPersistStorage_Save");
1537 hr = IPersistStorage_SaveCompleted(pPS, NULL);
1538 ok_ole_success(hr, "IPersistStorage_SaveCompleted");
1540 hr = IPersistStorage_IsDirty(pPS);
1541 ok(hr == S_FALSE, "IPersistStorage_IsDirty should have returned S_FALSE instead of 0x%x\n", hr);
1543 IPersistStorage_Release(pPS);
1544 IViewObject_Release(pViewObject);
1545 IOleCache2_Release(pOleCache);
1546 IOleCacheControl_Release(pOleCacheControl);
1548 CHECK_NO_EXTRA_METHODS();
1550 /* Test with loaded data */
1551 trace("Testing loaded data with CreateDataCache:\n");
1552 expected_method_list = methods_cacheload;
1554 hr = CreateDataCache(NULL, &CLSID_NULL, &IID_IOleCache2, (LPVOID *)&pOleCache);
1555 ok_ole_success(hr, "CreateDataCache");
1557 hr = IOleCache2_QueryInterface(pOleCache, &IID_IPersistStorage, (LPVOID *)&pPS);
1558 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IPersistStorage)");
1559 hr = IOleCache2_QueryInterface(pOleCache, &IID_IViewObject, (LPVOID *)&pViewObject);
1560 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IViewObject)");
1562 hr = IViewObject_SetAdvise(pViewObject, DVASPECT_ICON, ADVF_PRIMEFIRST, &AdviseSink);
1563 ok_ole_success(hr, "IViewObject_SetAdvise");
1565 hr = IPersistStorage_Load(pPS, pStorage);
1566 ok_ole_success(hr, "IPersistStorage_Load");
1568 hr = IPersistStorage_IsDirty(pPS);
1569 ok(hr == S_FALSE, "IPersistStorage_IsDirty should have returned S_FALSE instead of 0x%x\n", hr);
1571 fmtetc.cfFormat = 0;
1572 fmtetc.dwAspect = DVASPECT_ICON;
1573 fmtetc.lindex = -1;
1574 fmtetc.ptd = NULL;
1575 fmtetc.tymed = TYMED_MFPICT;
1576 hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1577 ok(hr == CACHE_S_SAMECACHE, "IOleCache_Cache with already loaded data format type should return CACHE_S_SAMECACHE instead of 0x%x\n", hr);
1579 rcBounds.left = 0;
1580 rcBounds.top = 0;
1581 rcBounds.right = 100;
1582 rcBounds.bottom = 100;
1583 hdcMem = CreateCompatibleDC(NULL);
1585 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1586 ok_ole_success(hr, "IViewObject_Draw");
1588 hr = IViewObject_Draw(pViewObject, DVASPECT_CONTENT, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1589 ok(hr == OLE_E_BLANK, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1591 /* unload the cached storage object, causing it to be reloaded */
1592 hr = IOleCache2_DiscardCache(pOleCache, DISCARDCACHE_NOSAVE);
1593 ok_ole_success(hr, "IOleCache2_DiscardCache");
1594 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1595 ok_ole_success(hr, "IViewObject_Draw");
1597 /* unload the cached storage object, but don't allow it to be reloaded */
1598 hr = IPersistStorage_HandsOffStorage(pPS);
1599 ok_ole_success(hr, "IPersistStorage_HandsOffStorage");
1600 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1601 ok_ole_success(hr, "IViewObject_Draw");
1602 hr = IOleCache2_DiscardCache(pOleCache, DISCARDCACHE_NOSAVE);
1603 ok_ole_success(hr, "IOleCache2_DiscardCache");
1604 hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1605 ok(hr == OLE_E_BLANK, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1607 DeleteDC(hdcMem);
1609 todo_wine {
1610 hr = IOleCache2_InitCache(pOleCache, &DataObject);
1611 ok(hr == CACHE_E_NOCACHE_UPDATED, "IOleCache_InitCache should have returned CACHE_E_NOCACHE_UPDATED instead of 0x%08x\n", hr);
1614 IPersistStorage_Release(pPS);
1615 IViewObject_Release(pViewObject);
1616 IOleCache2_Release(pOleCache);
1618 todo_wine {
1619 CHECK_NO_EXTRA_METHODS();
1622 hr = CreateDataCache(NULL, &CLSID_NULL, &IID_IOleCache2, (LPVOID *)&pOleCache);
1623 ok_ole_success(hr, "CreateDataCache");
1625 expected_method_list = methods_cachethenrun;
1627 hr = IOleCache2_QueryInterface(pOleCache, &IID_IDataObject, (LPVOID *)&pCacheDataObject);
1628 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IDataObject)");
1629 hr = IOleCache2_QueryInterface(pOleCache, &IID_IOleCacheControl, (LPVOID *)&pOleCacheControl);
1630 ok_ole_success(hr, "IOleCache_QueryInterface(IID_IOleCacheControl)");
1632 fmtetc.cfFormat = CF_METAFILEPICT;
1633 fmtetc.dwAspect = DVASPECT_CONTENT;
1634 fmtetc.tymed = TYMED_MFPICT;
1636 hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1637 ok_ole_success(hr, "IOleCache_Cache");
1639 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1640 ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1642 fmtetc.cfFormat = cf_test_1;
1643 fmtetc.dwAspect = DVASPECT_CONTENT;
1644 fmtetc.tymed = TYMED_HGLOBAL;
1646 hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1647 ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED, "got %08x\n", hr);
1649 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1650 ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1652 fmtetc.cfFormat = cf_test_2;
1653 hr = IOleCache2_Cache(pOleCache, &fmtetc, ADVF_PRIMEFIRST, &dwConnection);
1654 ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED, "got %08x\n", hr);
1656 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1657 ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1659 hr = IOleCacheControl_OnRun(pOleCacheControl, &DataObject);
1660 ok_ole_success(hr, "IOleCacheControl_OnRun");
1662 fmtetc.cfFormat = cf_test_3;
1663 hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1664 ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED, "got %08x\n", hr);
1666 fmtetc.cfFormat = cf_test_1;
1667 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1668 ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1670 fmtetc.cfFormat = cf_test_2;
1671 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1672 ok(hr == S_OK, "got %08x\n", hr);
1673 ReleaseStgMedium(&stgmedium);
1675 fmtetc.cfFormat = cf_test_3;
1676 hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1677 ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1679 IOleCacheControl_Release(pOleCacheControl);
1680 IDataObject_Release(pCacheDataObject);
1681 IOleCache2_Release(pOleCache);
1683 CHECK_NO_EXTRA_METHODS();
1685 IStorage_Release(pStorage);
1689 static const WCHAR CONTENTS[] = {'C','O','N','T','E','N','T','S',0};
1691 /* 2 x 1 x 32 bpp dib. PelsPerMeter = 200x400 */
1692 static BYTE dib[] =
1694 0x42, 0x4d, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00,
1695 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00,
1697 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00,
1698 0x00, 0x00, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00,
1700 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x00,
1701 0x00, 0x00, 0x90, 0x01, 0x00, 0x00, 0x00, 0x00,
1703 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
1704 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
1707 static IStorage *create_storage( int num )
1709 IStorage *stg;
1710 IStream *stm;
1711 HRESULT hr;
1712 ULONG written;
1714 hr = StgCreateDocfile( NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE | STGM_DELETEONRELEASE, 0, &stg );
1715 ok( hr == S_OK, "got %08x\n", hr);
1716 hr = IStorage_SetClass( stg, &CLSID_Picture_Dib );
1717 ok( hr == S_OK, "got %08x\n", hr);
1718 hr = IStorage_CreateStream( stg, CONTENTS, STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, 0, &stm );
1719 ok( hr == S_OK, "got %08x\n", hr);
1720 if (num == 1) /* Set biXPelsPerMeter = 0 */
1722 dib[0x26] = 0;
1723 dib[0x27] = 0;
1725 hr = IStream_Write( stm, dib, sizeof(dib), &written );
1726 ok( hr == S_OK, "got %08x\n", hr);
1727 IStream_Release( stm );
1728 return stg;
1731 static void test_data_cache_dib_contents_stream(int num)
1733 HRESULT hr;
1734 IUnknown *unk;
1735 IPersistStorage *persist;
1736 IDataObject *data;
1737 IViewObject2 *view;
1738 IStorage *stg;
1739 FORMATETC fmt = {CF_DIB, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
1740 STGMEDIUM med;
1741 CLSID cls;
1742 SIZEL sz;
1744 hr = CreateDataCache( NULL, &CLSID_Picture_Metafile, &IID_IUnknown, (void *)&unk );
1745 ok( SUCCEEDED(hr), "got %08x\n", hr );
1746 hr = IUnknown_QueryInterface( unk, &IID_IPersistStorage, (void *)&persist );
1747 ok( SUCCEEDED(hr), "got %08x\n", hr );
1748 hr = IUnknown_QueryInterface( unk, &IID_IDataObject, (void *)&data );
1749 ok( SUCCEEDED(hr), "got %08x\n", hr );
1750 hr = IUnknown_QueryInterface( unk, &IID_IViewObject2, (void *)&view );
1751 ok( SUCCEEDED(hr), "got %08x\n", hr );
1753 stg = create_storage( num );
1755 hr = IPersistStorage_Load( persist, stg );
1756 ok( SUCCEEDED(hr), "got %08x\n", hr );
1757 IStorage_Release( stg );
1759 hr = IPersistStorage_GetClassID( persist, &cls );
1760 ok( SUCCEEDED(hr), "got %08x\n", hr );
1761 ok( IsEqualCLSID( &cls, &CLSID_Picture_Dib ), "class id mismatch\n" );
1763 hr = IDataObject_GetData( data, &fmt, &med );
1764 ok( SUCCEEDED(hr), "got %08x\n", hr );
1765 if (SUCCEEDED(hr))
1767 ok( med.tymed == TYMED_HGLOBAL, "got %x\n", med.tymed );
1768 ReleaseStgMedium( &med );
1771 hr = IViewObject2_GetExtent( view, DVASPECT_CONTENT, -1, NULL, &sz );
1772 ok( SUCCEEDED(hr), "got %08x\n", hr );
1773 if (num == 0)
1775 ok( sz.cx == 1000, "got %d\n", sz.cx );
1776 ok( sz.cy == 250, "got %d\n", sz.cy );
1778 else
1780 HDC hdc = GetDC( 0 );
1781 LONG x = 2 * 2540 / GetDeviceCaps( hdc, LOGPIXELSX );
1782 LONG y = 1 * 2540 / GetDeviceCaps( hdc, LOGPIXELSY );
1783 ok( sz.cx == x, "got %d %d\n", sz.cx, x );
1784 ok( sz.cy == y, "got %d %d\n", sz.cy, y );
1786 ReleaseDC( 0, hdc );
1789 IViewObject2_Release( view );
1790 IDataObject_Release( data );
1791 IPersistStorage_Release( persist );
1792 IUnknown_Release( unk );
1795 static void test_default_handler(void)
1797 HRESULT hr;
1798 IOleObject *pObject;
1799 IRunnableObject *pRunnableObject;
1800 IOleClientSite *pClientSite;
1801 IDataObject *pDataObject;
1802 SIZEL sizel;
1803 DWORD dwStatus;
1804 CLSID clsid;
1805 LPOLESTR pszUserType;
1806 LOGPALETTE palette;
1807 DWORD dwAdvConn;
1808 IMoniker *pMoniker;
1809 FORMATETC fmtetc;
1810 IOleInPlaceObject *pInPlaceObj;
1811 IEnumOLEVERB *pEnumVerbs;
1812 DWORD dwRegister;
1813 static const WCHAR wszUnknown[] = {'U','n','k','n','o','w','n',0};
1814 static const WCHAR wszHostName[] = {'W','i','n','e',' ','T','e','s','t',' ','P','r','o','g','r','a','m',0};
1815 static const WCHAR wszDelim[] = {'!',0};
1817 static const struct expected_method methods_embeddinghelper[] =
1819 { "OleObject_QueryInterface", 0 },
1820 { "OleObject_AddRef", 0 },
1821 { "OleObject_QueryInterface", 0 },
1822 { "OleObject_QueryInterface", TEST_TODO },
1823 { "OleObject_QueryInterface", 0 },
1824 { "OleObject_QueryInterface", 0 },
1825 { "OleObject_QueryInterface", TEST_OPTIONAL }, /* Win95/98/NT4 */
1826 { "OleObject_Release", TEST_TODO },
1827 { "WINE_EXTRA", TEST_OPTIONAL },
1828 { NULL, 0 }
1831 hr = CoCreateInstance(&CLSID_WineTest, NULL, CLSCTX_INPROC_HANDLER, &IID_IOleObject, (void **)&pObject);
1832 ok(hr == REGDB_E_CLASSNOTREG, "CoCreateInstance should have failed with REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1834 hr = OleCreateDefaultHandler(&CLSID_WineTest, NULL, &IID_IOleObject, (void **)&pObject);
1835 ok_ole_success(hr, "OleCreateDefaultHandler");
1837 hr = IOleObject_QueryInterface(pObject, &IID_IOleInPlaceObject, (void **)&pInPlaceObj);
1838 ok(hr == E_NOINTERFACE, "IOleObject_QueryInterface(&IID_IOleInPlaceObject) should return E_NOINTERFACE instead of 0x%08x\n", hr);
1840 hr = IOleObject_Advise(pObject, &AdviseSink, &dwAdvConn);
1841 ok_ole_success(hr, "IOleObject_Advise");
1843 hr = IOleObject_Close(pObject, OLECLOSE_NOSAVE);
1844 ok_ole_success(hr, "IOleObject_Close");
1846 /* FIXME: test IOleObject_EnumAdvise */
1848 hr = IOleObject_EnumVerbs(pObject, &pEnumVerbs);
1849 ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_EnumVerbs should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1851 hr = IOleObject_GetClientSite(pObject, &pClientSite);
1852 ok_ole_success(hr, "IOleObject_GetClientSite");
1854 hr = IOleObject_SetClientSite(pObject, pClientSite);
1855 ok_ole_success(hr, "IOleObject_SetClientSite");
1857 hr = IOleObject_GetClipboardData(pObject, 0, &pDataObject);
1858 ok(hr == OLE_E_NOTRUNNING,
1859 "IOleObject_GetClipboardData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n",
1860 hr);
1862 hr = IOleObject_GetExtent(pObject, DVASPECT_CONTENT, &sizel);
1863 ok(hr == OLE_E_BLANK, "IOleObject_GetExtent should have returned OLE_E_BLANK instead of 0x%08x\n",
1864 hr);
1866 hr = IOleObject_GetMiscStatus(pObject, DVASPECT_CONTENT, &dwStatus);
1867 ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_GetMiscStatus should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1869 hr = IOleObject_GetUserClassID(pObject, &clsid);
1870 ok_ole_success(hr, "IOleObject_GetUserClassID");
1871 ok(IsEqualCLSID(&clsid, &CLSID_WineTest), "clsid != CLSID_WineTest\n");
1873 hr = IOleObject_GetUserType(pObject, USERCLASSTYPE_FULL, &pszUserType);
1874 todo_wine {
1875 ok_ole_success(hr, "IOleObject_GetUserType");
1876 ok(!lstrcmpW(pszUserType, wszUnknown), "Retrieved user type was wrong\n");
1879 hr = IOleObject_InitFromData(pObject, NULL, TRUE, 0);
1880 ok(hr == OLE_E_NOTRUNNING, "IOleObject_InitFromData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1882 hr = IOleObject_IsUpToDate(pObject);
1883 ok(hr == OLE_E_NOTRUNNING, "IOleObject_IsUpToDate should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1885 palette.palNumEntries = 1;
1886 palette.palVersion = 2;
1887 memset(&palette.palPalEntry[0], 0, sizeof(palette.palPalEntry[0]));
1888 hr = IOleObject_SetColorScheme(pObject, &palette);
1889 ok(hr == OLE_E_NOTRUNNING, "IOleObject_SetColorScheme should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1891 sizel.cx = sizel.cy = 0;
1892 hr = IOleObject_SetExtent(pObject, DVASPECT_CONTENT, &sizel);
1893 ok(hr == OLE_E_NOTRUNNING, "IOleObject_SetExtent should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1895 hr = IOleObject_SetHostNames(pObject, wszHostName, NULL);
1896 ok_ole_success(hr, "IOleObject_SetHostNames");
1898 hr = CreateItemMoniker(wszDelim, wszHostName, &pMoniker);
1899 ok_ole_success(hr, "CreateItemMoniker");
1900 hr = IOleObject_SetMoniker(pObject, OLEWHICHMK_CONTAINER, pMoniker);
1901 ok_ole_success(hr, "IOleObject_SetMoniker");
1902 IMoniker_Release(pMoniker);
1904 hr = IOleObject_GetMoniker(pObject, OLEGETMONIKER_ONLYIFTHERE, OLEWHICHMK_CONTAINER, &pMoniker);
1905 ok(hr == E_FAIL, "IOleObject_GetMoniker should have returned E_FAIL instead of 0x%08x\n", hr);
1907 hr = IOleObject_Update(pObject);
1908 todo_wine
1909 ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_Update should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1911 hr = IOleObject_QueryInterface(pObject, &IID_IDataObject, (void **)&pDataObject);
1912 ok_ole_success(hr, "IOleObject_QueryInterface");
1914 fmtetc.cfFormat = CF_TEXT;
1915 fmtetc.ptd = NULL;
1916 fmtetc.dwAspect = DVASPECT_CONTENT;
1917 fmtetc.lindex = -1;
1918 fmtetc.tymed = TYMED_NULL;
1919 hr = IDataObject_DAdvise(pDataObject, &fmtetc, 0, &AdviseSink, &dwAdvConn);
1920 ok_ole_success(hr, "IDataObject_DAdvise");
1922 fmtetc.cfFormat = CF_ENHMETAFILE;
1923 fmtetc.ptd = NULL;
1924 fmtetc.dwAspect = DVASPECT_CONTENT;
1925 fmtetc.lindex = -1;
1926 fmtetc.tymed = TYMED_ENHMF;
1927 hr = IDataObject_DAdvise(pDataObject, &fmtetc, 0, &AdviseSink, &dwAdvConn);
1928 ok_ole_success(hr, "IDataObject_DAdvise");
1930 fmtetc.cfFormat = CF_ENHMETAFILE;
1931 fmtetc.ptd = NULL;
1932 fmtetc.dwAspect = DVASPECT_CONTENT;
1933 fmtetc.lindex = -1;
1934 fmtetc.tymed = TYMED_ENHMF;
1935 hr = IDataObject_QueryGetData(pDataObject, &fmtetc);
1936 todo_wine
1937 ok(hr == OLE_E_NOTRUNNING, "IDataObject_QueryGetData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1939 fmtetc.cfFormat = CF_TEXT;
1940 fmtetc.ptd = NULL;
1941 fmtetc.dwAspect = DVASPECT_CONTENT;
1942 fmtetc.lindex = -1;
1943 fmtetc.tymed = TYMED_NULL;
1944 hr = IDataObject_QueryGetData(pDataObject, &fmtetc);
1945 todo_wine
1946 ok(hr == OLE_E_NOTRUNNING, "IDataObject_QueryGetData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1948 hr = IOleObject_QueryInterface(pObject, &IID_IRunnableObject, (void **)&pRunnableObject);
1949 ok_ole_success(hr, "IOleObject_QueryInterface");
1951 hr = IRunnableObject_SetContainedObject(pRunnableObject, TRUE);
1952 ok_ole_success(hr, "IRunnableObject_SetContainedObject");
1954 hr = IRunnableObject_Run(pRunnableObject, NULL);
1955 ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_Run should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1957 hr = IOleObject_Close(pObject, OLECLOSE_NOSAVE);
1958 ok_ole_success(hr, "IOleObject_Close");
1960 IRunnableObject_Release(pRunnableObject);
1961 IOleObject_Release(pObject);
1963 /* Test failure propagation from delegate ::QueryInterface */
1964 hr = CoRegisterClassObject(&CLSID_WineTest, (IUnknown*)&OleObjectCF,
1965 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &dwRegister);
1966 ok_ole_success(hr, "CoRegisterClassObject");
1967 if(SUCCEEDED(hr))
1969 expected_method_list = methods_embeddinghelper;
1970 hr = OleCreateEmbeddingHelper(&CLSID_WineTest, NULL, EMBDHLP_INPROC_SERVER,
1971 &OleObjectCF, &IID_IOleObject, (void**)&pObject);
1972 ok_ole_success(hr, "OleCreateEmbeddingHelper");
1973 if(SUCCEEDED(hr))
1975 IUnknown *punk;
1977 g_QIFailsWith = E_FAIL;
1978 hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1979 ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1981 g_QIFailsWith = E_NOINTERFACE;
1982 hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1983 ok(hr == E_NOINTERFACE, "Got 0x%08x\n", hr);
1985 g_QIFailsWith = CO_E_OBJNOTCONNECTED;
1986 hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1987 ok(hr == CO_E_OBJNOTCONNECTED, "Got 0x%08x\n", hr);
1989 g_QIFailsWith = 0x87654321;
1990 hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1991 ok(hr == 0x87654321, "Got 0x%08x\n", hr);
1993 IOleObject_Release(pObject);
1996 CHECK_NO_EXTRA_METHODS();
1998 hr = CoRevokeClassObject(dwRegister);
1999 ok_ole_success(hr, "CoRevokeClassObject");
2003 static void test_runnable(void)
2005 static const struct expected_method methods_query_runnable[] =
2007 { "OleObject_QueryInterface", 0 },
2008 { "OleObjectRunnable_AddRef", 0 },
2009 { "OleObjectRunnable_IsRunning", 0 },
2010 { "OleObjectRunnable_Release", 0 },
2011 { NULL, 0 }
2014 static const struct expected_method methods_no_runnable[] =
2016 { "OleObject_QueryInterface", 0 },
2017 { NULL, 0 }
2020 BOOL ret;
2021 IOleObject *object = &OleObject;
2023 /* null argument */
2024 ret = OleIsRunning(NULL);
2025 ok(ret == FALSE, "got %d\n", ret);
2027 expected_method_list = methods_query_runnable;
2028 ret = OleIsRunning(object);
2029 ok(ret == TRUE, "Object should be running\n");
2030 CHECK_NO_EXTRA_METHODS();
2032 g_isRunning = FALSE;
2033 expected_method_list = methods_query_runnable;
2034 ret = OleIsRunning(object);
2035 ok(ret == FALSE, "Object should not be running\n");
2036 CHECK_NO_EXTRA_METHODS();
2038 g_showRunnable = FALSE; /* QueryInterface(IID_IRunnableObject, ...) will fail */
2039 expected_method_list = methods_no_runnable;
2040 ret = OleIsRunning(object);
2041 ok(ret == TRUE, "Object without IRunnableObject should be running\n");
2042 CHECK_NO_EXTRA_METHODS();
2044 g_isRunning = TRUE;
2045 g_showRunnable = TRUE;
2048 static HRESULT WINAPI Unknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
2050 *ppv = NULL;
2051 if (IsEqualIID(riid, &IID_IUnknown)) *ppv = iface;
2052 if (*ppv)
2054 IUnknown_AddRef((IUnknown *)*ppv);
2055 return S_OK;
2057 return E_NOINTERFACE;
2060 static ULONG WINAPI Unknown_AddRef(IUnknown *iface)
2062 return 2;
2065 static ULONG WINAPI Unknown_Release(IUnknown *iface)
2067 return 1;
2070 static const IUnknownVtbl UnknownVtbl =
2072 Unknown_QueryInterface,
2073 Unknown_AddRef,
2074 Unknown_Release
2077 static IUnknown unknown = { &UnknownVtbl };
2079 static void test_OleRun(void)
2081 HRESULT hr;
2083 hr = OleRun(&unknown);
2084 ok(hr == S_OK, "OleRun failed 0x%08x\n", hr);
2087 static void test_OleLockRunning(void)
2089 HRESULT hr;
2091 hr = OleLockRunning((LPUNKNOWN)&unknown, TRUE, FALSE);
2092 ok(hr == S_OK, "OleLockRunning failed 0x%08x\n", hr);
2095 static void test_OleDraw(void)
2097 HRESULT hr;
2098 RECT rect;
2100 hr = OleDraw((IUnknown*)&viewobject, 0, (HDC)0x1, NULL);
2101 ok(hr == S_OK, "got 0x%08x\n", hr);
2103 hr = OleDraw(NULL, 0, (HDC)0x1, NULL);
2104 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
2106 hr = OleDraw(NULL, 0, (HDC)0x1, &rect);
2107 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
2110 static const WCHAR comp_objW[] = {1,'C','o','m','p','O','b','j',0};
2111 static IStream *comp_obj_stream;
2112 static IStream *ole_stream;
2114 static HRESULT WINAPI Storage_QueryInterface(IStorage *iface, REFIID riid, void **ppvObject)
2116 ok(0, "unexpected call to QueryInterface\n");
2117 return E_NOTIMPL;
2120 static ULONG WINAPI Storage_AddRef(IStorage *iface)
2122 ok(0, "unexpected call to AddRef\n");
2123 return 2;
2126 static ULONG WINAPI Storage_Release(IStorage *iface)
2128 ok(0, "unexpected call to Release\n");
2129 return 1;
2132 static HRESULT WINAPI Storage_CreateStream(IStorage *iface, LPCOLESTR pwcsName, DWORD grfMode, DWORD reserved1, DWORD reserved2, IStream **ppstm)
2134 ULARGE_INTEGER size = {{0}};
2135 LARGE_INTEGER pos = {{0}};
2136 HRESULT hr;
2138 CHECK_EXPECT(Storage_CreateStream_CompObj);
2139 ok(!lstrcmpW(pwcsName, comp_objW), "pwcsName = %s\n", wine_dbgstr_w(pwcsName));
2140 todo_wine ok(grfMode == (STGM_CREATE|STGM_SHARE_EXCLUSIVE|STGM_READWRITE), "grfMode = %x\n", grfMode);
2141 ok(!reserved1, "reserved1 = %x\n", reserved1);
2142 ok(!reserved2, "reserved2 = %x\n", reserved2);
2143 ok(!!ppstm, "ppstm = NULL\n");
2145 *ppstm = comp_obj_stream;
2146 IStream_AddRef(comp_obj_stream);
2147 hr = IStream_Seek(comp_obj_stream, pos, STREAM_SEEK_SET, NULL);
2148 ok(hr == S_OK, "IStream_Seek returned %x\n", hr);
2149 hr = IStream_SetSize(comp_obj_stream, size);
2150 ok(hr == S_OK, "IStream_SetSize returned %x\n", hr);
2151 return S_OK;
2154 static HRESULT WINAPI Storage_OpenStream(IStorage *iface, LPCOLESTR pwcsName, void *reserved1, DWORD grfMode, DWORD reserved2, IStream **ppstm)
2156 static const WCHAR ole1W[] = {1,'O','l','e',0};
2158 LARGE_INTEGER pos = {{0}};
2159 HRESULT hr;
2161 ok(!reserved1, "reserved1 = %p\n", reserved1);
2162 ok(!reserved2, "reserved2 = %x\n", reserved2);
2163 ok(!!ppstm, "ppstm = NULL\n");
2165 if(!lstrcmpW(pwcsName, comp_objW)) {
2166 CHECK_EXPECT2(Storage_OpenStream_CompObj);
2167 ok(grfMode == STGM_SHARE_EXCLUSIVE, "grfMode = %x\n", grfMode);
2169 *ppstm = comp_obj_stream;
2170 IStream_AddRef(comp_obj_stream);
2171 hr = IStream_Seek(comp_obj_stream, pos, STREAM_SEEK_SET, NULL);
2172 ok(hr == S_OK, "IStream_Seek returned %x\n", hr);
2173 return S_OK;
2174 }else if(!lstrcmpW(pwcsName, ole1W)) {
2175 CHECK_EXPECT(Storage_OpenStream_Ole);
2176 ok(grfMode == (STGM_SHARE_EXCLUSIVE|STGM_READWRITE), "grfMode = %x\n", grfMode);
2178 *ppstm = ole_stream;
2179 IStream_AddRef(ole_stream);
2180 hr = IStream_Seek(ole_stream, pos, STREAM_SEEK_SET, NULL);
2181 ok(hr == S_OK, "IStream_Seek returned %x\n", hr);
2182 return S_OK;
2185 ok(0, "unexpected call to OpenStream: %s\n", wine_dbgstr_w(pwcsName));
2186 return E_NOTIMPL;
2189 static HRESULT WINAPI Storage_CreateStorage(IStorage *iface, LPCOLESTR pwcsName, DWORD grfMode, DWORD dwStgFmt, DWORD reserved2, IStorage **ppstg)
2191 ok(0, "unexpected call to CreateStorage\n");
2192 return E_NOTIMPL;
2195 static HRESULT WINAPI Storage_OpenStorage(IStorage *iface, LPCOLESTR pwcsName, IStorage *pstgPriority, DWORD grfMode, SNB snbExclude, DWORD reserved, IStorage **ppstg)
2197 ok(0, "unexpected call to OpenStorage\n");
2198 return E_NOTIMPL;
2201 static HRESULT WINAPI Storage_CopyTo(IStorage *iface, DWORD ciidExclude, const IID *rgiidExclude, SNB snbExclude, IStorage *pstgDest)
2203 ok(0, "unexpected call to CopyTo\n");
2204 return E_NOTIMPL;
2207 static HRESULT WINAPI Storage_MoveElementTo(IStorage *iface, LPCOLESTR pwcsName, IStorage *pstgDest, LPCOLESTR pwcsNewName, DWORD grfFlags)
2209 ok(0, "unexpected call to MoveElementTo\n");
2210 return E_NOTIMPL;
2213 static HRESULT WINAPI Storage_Commit(IStorage *iface, DWORD grfCommitFlags)
2215 ok(0, "unexpected call to Commit\n");
2216 return E_NOTIMPL;
2219 static HRESULT WINAPI Storage_Revert(IStorage *iface)
2221 ok(0, "unexpected call to Revert\n");
2222 return E_NOTIMPL;
2225 static HRESULT WINAPI Storage_EnumElements(IStorage *iface, DWORD reserved1, void *reserved2, DWORD reserved3, IEnumSTATSTG **ppenum)
2227 ok(0, "unexpected call to EnumElements\n");
2228 return E_NOTIMPL;
2231 static HRESULT WINAPI Storage_DestroyElement(IStorage *iface, LPCOLESTR pwcsName)
2233 ok(0, "unexpected call to DestroyElement\n");
2234 return E_NOTIMPL;
2237 static HRESULT WINAPI Storage_RenameElement(IStorage *iface, LPCOLESTR pwcsOldName, LPCOLESTR pwcsNewName)
2239 ok(0, "unexpected call to RenameElement\n");
2240 return E_NOTIMPL;
2243 static HRESULT WINAPI Storage_SetElementTimes(IStorage *iface, LPCOLESTR pwcsName, const FILETIME *pctime, const FILETIME *patime, const FILETIME *pmtime)
2245 ok(0, "unexpected call to SetElementTimes\n");
2246 return E_NOTIMPL;
2249 static HRESULT WINAPI Storage_SetClass(IStorage *iface, REFCLSID clsid)
2251 CHECK_EXPECT(Storage_SetClass);
2252 ok(IsEqualIID(clsid, &CLSID_WineTest), "clsid = %s\n", wine_dbgstr_guid(clsid));
2253 return S_OK;
2256 static HRESULT WINAPI Storage_SetStateBits(IStorage *iface, DWORD grfStateBits, DWORD grfMask)
2258 ok(0, "unexpected call to SetStateBits\n");
2259 return E_NOTIMPL;
2262 static HRESULT WINAPI Storage_Stat(IStorage *iface, STATSTG *pstatstg, DWORD grfStatFlag)
2264 CHECK_EXPECT2(Storage_Stat);
2265 ok(pstatstg != NULL, "pstatstg = NULL\n");
2266 ok(grfStatFlag == STATFLAG_NONAME, "grfStatFlag = %x\n", grfStatFlag);
2268 memset(pstatstg, 0, sizeof(STATSTG));
2269 pstatstg->type = STGTY_STORAGE;
2270 pstatstg->clsid = CLSID_WineTestOld;
2271 return S_OK;
2274 static IStorageVtbl StorageVtbl =
2276 Storage_QueryInterface,
2277 Storage_AddRef,
2278 Storage_Release,
2279 Storage_CreateStream,
2280 Storage_OpenStream,
2281 Storage_CreateStorage,
2282 Storage_OpenStorage,
2283 Storage_CopyTo,
2284 Storage_MoveElementTo,
2285 Storage_Commit,
2286 Storage_Revert,
2287 Storage_EnumElements,
2288 Storage_DestroyElement,
2289 Storage_RenameElement,
2290 Storage_SetElementTimes,
2291 Storage_SetClass,
2292 Storage_SetStateBits,
2293 Storage_Stat
2296 static IStorage Storage = { &StorageVtbl };
2298 static void test_OleDoAutoConvert(void)
2300 static const WCHAR clsidW[] = {'C','L','S','I','D','\\',0};
2301 static struct {
2302 DWORD reserved1;
2303 DWORD version;
2304 DWORD reserved2[5];
2305 DWORD ansi_user_type_len;
2306 DWORD ansi_clipboard_format_len;
2307 DWORD reserved3;
2308 DWORD unicode_marker;
2309 DWORD unicode_user_type_len;
2310 DWORD unicode_clipboard_format_len;
2311 DWORD reserved4;
2312 } comp_obj_data;
2313 static struct {
2314 DWORD version;
2315 DWORD flags;
2316 DWORD link_update_option;
2317 DWORD reserved1;
2318 DWORD reserved_moniker_stream_size;
2319 DWORD relative_source_moniker_stream_size;
2320 DWORD absolute_source_moniker_stream_size;
2321 DWORD clsid_indicator;
2322 CLSID clsid;
2323 DWORD reserved_display_name;
2324 DWORD reserved2;
2325 DWORD local_update_time;
2326 DWORD local_check_update_time;
2327 DWORD remote_update_time;
2328 } ole_data;
2330 LARGE_INTEGER pos = {{0}};
2331 WCHAR buf[39+6];
2332 DWORD i, ret;
2333 HKEY root;
2334 CLSID clsid;
2335 HRESULT hr;
2337 hr = CreateStreamOnHGlobal(NULL, TRUE, &comp_obj_stream);
2338 ok(hr == S_OK, "CreateStreamOnHGlobal returned %x\n", hr);
2339 hr = IStream_Write(comp_obj_stream, (char*)&comp_obj_data, sizeof(comp_obj_data), NULL);
2340 ok(hr == S_OK, "IStream_Write returned %x\n", hr);
2342 hr = CreateStreamOnHGlobal(NULL, TRUE, &ole_stream);
2343 ok(hr == S_OK, "CreateStreamOnHGlobal returned %x\n", hr);
2344 hr = IStream_Write(ole_stream, (char*)&ole_data, sizeof(ole_data), NULL);
2345 ok(hr == S_OK, "IStream_Write returned %x\n", hr);
2347 clsid = IID_WineTest;
2348 hr = OleDoAutoConvert(NULL, &clsid);
2349 ok(hr == E_INVALIDARG, "OleDoAutoConvert returned %x\n", hr);
2350 ok(IsEqualIID(&clsid, &IID_NULL), "clsid = %s\n", wine_dbgstr_guid(&clsid));
2352 if(0) /* crashes on Win7 */
2353 OleDoAutoConvert(&Storage, NULL);
2355 clsid = IID_WineTest;
2356 SET_EXPECT(Storage_Stat);
2357 hr = OleDoAutoConvert(&Storage, &clsid);
2358 ok(hr == REGDB_E_CLASSNOTREG, "OleDoAutoConvert returned %x\n", hr);
2359 CHECK_CALLED(Storage_Stat);
2360 ok(IsEqualIID(&clsid, &CLSID_WineTestOld), "clsid = %s\n", wine_dbgstr_guid(&clsid));
2362 lstrcpyW(buf, clsidW);
2363 StringFromGUID2(&CLSID_WineTestOld, buf+6, 39);
2365 ret = RegCreateKeyExW(HKEY_CLASSES_ROOT, buf, 0, NULL, 0,
2366 KEY_READ | KEY_WRITE | KEY_CREATE_SUB_KEY, NULL, &root, NULL);
2367 if(ret != ERROR_SUCCESS) {
2368 win_skip("not enough permissions to create CLSID key (%u)\n", ret);
2369 return;
2372 clsid = IID_WineTest;
2373 SET_EXPECT(Storage_Stat);
2374 hr = OleDoAutoConvert(&Storage, &clsid);
2375 ok(hr == REGDB_E_KEYMISSING, "OleDoAutoConvert returned %x\n", hr);
2376 CHECK_CALLED(Storage_Stat);
2377 ok(IsEqualIID(&clsid, &CLSID_WineTestOld), "clsid = %s\n", wine_dbgstr_guid(&clsid));
2379 hr = OleSetAutoConvert(&CLSID_WineTestOld, &CLSID_WineTest);
2380 ok_ole_success(hr, "OleSetAutoConvert");
2382 hr = OleGetAutoConvert(&CLSID_WineTestOld, &clsid);
2383 ok_ole_success(hr, "OleGetAutoConvert");
2384 ok(IsEqualIID(&clsid, &CLSID_WineTest), "incorrect clsid: %s\n", wine_dbgstr_guid(&clsid));
2386 clsid = IID_WineTest;
2387 SET_EXPECT(Storage_Stat);
2388 SET_EXPECT(Storage_OpenStream_CompObj);
2389 SET_EXPECT(Storage_SetClass);
2390 SET_EXPECT(Storage_CreateStream_CompObj);
2391 SET_EXPECT(Storage_OpenStream_Ole);
2392 hr = OleDoAutoConvert(&Storage, &clsid);
2393 ok(hr == S_OK, "OleDoAutoConvert returned %x\n", hr);
2394 CHECK_CALLED(Storage_Stat);
2395 CHECK_CALLED(Storage_OpenStream_CompObj);
2396 CHECK_CALLED(Storage_SetClass);
2397 CHECK_CALLED(Storage_CreateStream_CompObj);
2398 CHECK_CALLED(Storage_OpenStream_Ole);
2399 ok(IsEqualIID(&clsid, &CLSID_WineTest), "clsid = %s\n", wine_dbgstr_guid(&clsid));
2401 hr = IStream_Seek(comp_obj_stream, pos, STREAM_SEEK_SET, NULL);
2402 ok(hr == S_OK, "IStream_Seek returned %x\n", hr);
2403 hr = IStream_Read(comp_obj_stream, &comp_obj_data, sizeof(comp_obj_data), NULL);
2404 ok(hr == S_OK, "IStream_Read returned %x\n", hr);
2405 ok(comp_obj_data.reserved1 == 0xfffe0001, "reserved1 = %x\n", comp_obj_data.reserved1);
2406 ok(comp_obj_data.version == 0xa03, "version = %x\n", comp_obj_data.version);
2407 ok(comp_obj_data.reserved2[0] == -1, "reserved2[0] = %x\n", comp_obj_data.reserved2[0]);
2408 ok(IsEqualIID(comp_obj_data.reserved2+1, &CLSID_WineTestOld), "reserved2 = %s\n", wine_dbgstr_guid((CLSID*)(comp_obj_data.reserved2+1)));
2409 ok(!comp_obj_data.ansi_user_type_len, "ansi_user_type_len = %d\n", comp_obj_data.ansi_user_type_len);
2410 ok(!comp_obj_data.ansi_clipboard_format_len, "ansi_clipboard_format_len = %d\n", comp_obj_data.ansi_clipboard_format_len);
2411 ok(!comp_obj_data.reserved3, "reserved3 = %x\n", comp_obj_data.reserved3);
2412 ok(comp_obj_data.unicode_marker == 0x71b239f4, "unicode_marker = %x\n", comp_obj_data.unicode_marker);
2413 ok(!comp_obj_data.unicode_user_type_len, "unicode_user_type_len = %d\n", comp_obj_data.unicode_user_type_len);
2414 ok(!comp_obj_data.unicode_clipboard_format_len, "unicode_clipboard_format_len = %d\n", comp_obj_data.unicode_clipboard_format_len);
2415 ok(!comp_obj_data.reserved4, "reserved4 %d\n", comp_obj_data.reserved4);
2417 hr = IStream_Seek(ole_stream, pos, STREAM_SEEK_SET, NULL);
2418 ok(hr == S_OK, "IStream_Seek returned %x\n", hr);
2419 hr = IStream_Read(ole_stream, &ole_data, sizeof(ole_data), NULL);
2420 ok(hr == S_OK, "IStream_Read returned %x\n", hr);
2421 ok(ole_data.version == 0, "version = %x\n", ole_data.version);
2422 ok(ole_data.flags == 4, "flags = %x\n", ole_data.flags);
2423 for(i=2; i<sizeof(ole_data)/sizeof(DWORD); i++)
2424 ok(((DWORD*)&ole_data)[i] == 0, "ole_data[%d] = %x\n", i, ((DWORD*)&ole_data)[i]);
2426 SET_EXPECT(Storage_OpenStream_Ole);
2427 hr = SetConvertStg(&Storage, TRUE);
2428 ok(hr == S_OK, "SetConvertStg returned %x\n", hr);
2429 CHECK_CALLED(Storage_OpenStream_Ole);
2431 SET_EXPECT(Storage_OpenStream_CompObj);
2432 SET_EXPECT(Storage_Stat);
2433 SET_EXPECT(Storage_CreateStream_CompObj);
2434 hr = WriteFmtUserTypeStg(&Storage, 0, NULL);
2435 ok(hr == S_OK, "WriteFmtUserTypeStg returned %x\n", hr);
2436 todo_wine CHECK_CALLED(Storage_OpenStream_CompObj);
2437 CHECK_CALLED(Storage_Stat);
2438 CHECK_CALLED(Storage_CreateStream_CompObj);
2439 hr = IStream_Seek(comp_obj_stream, pos, STREAM_SEEK_SET, NULL);
2440 ok(hr == S_OK, "IStream_Seek returned %x\n", hr);
2441 hr = IStream_Read(comp_obj_stream, &comp_obj_data, sizeof(comp_obj_data), NULL);
2442 ok(hr == S_OK, "IStream_Read returned %x\n", hr);
2443 ok(comp_obj_data.reserved1 == 0xfffe0001, "reserved1 = %x\n", comp_obj_data.reserved1);
2444 ok(comp_obj_data.version == 0xa03, "version = %x\n", comp_obj_data.version);
2445 ok(comp_obj_data.reserved2[0] == -1, "reserved2[0] = %x\n", comp_obj_data.reserved2[0]);
2446 ok(IsEqualIID(comp_obj_data.reserved2+1, &CLSID_WineTestOld), "reserved2 = %s\n", wine_dbgstr_guid((CLSID*)(comp_obj_data.reserved2+1)));
2447 ok(!comp_obj_data.ansi_user_type_len, "ansi_user_type_len = %d\n", comp_obj_data.ansi_user_type_len);
2448 ok(!comp_obj_data.ansi_clipboard_format_len, "ansi_clipboard_format_len = %d\n", comp_obj_data.ansi_clipboard_format_len);
2449 ok(!comp_obj_data.reserved3, "reserved3 = %x\n", comp_obj_data.reserved3);
2450 ok(comp_obj_data.unicode_marker == 0x71b239f4, "unicode_marker = %x\n", comp_obj_data.unicode_marker);
2451 ok(!comp_obj_data.unicode_user_type_len, "unicode_user_type_len = %d\n", comp_obj_data.unicode_user_type_len);
2452 ok(!comp_obj_data.unicode_clipboard_format_len, "unicode_clipboard_format_len = %d\n", comp_obj_data.unicode_clipboard_format_len);
2453 ok(!comp_obj_data.reserved4, "reserved4 %d\n", comp_obj_data.reserved4);
2455 ret = IStream_Release(comp_obj_stream);
2456 ok(!ret, "comp_obj_stream was not freed\n");
2457 ret = IStream_Release(ole_stream);
2458 ok(!ret, "ole_stream was not freed\n");
2460 ret = RegDeleteKeyA(root, "AutoConvertTo");
2461 ok(ret == ERROR_SUCCESS, "RegDeleteKey error %u\n", ret);
2462 ret = RegDeleteKeyA(root, "");
2463 ok(ret == ERROR_SUCCESS, "RegDeleteKey error %u\n", ret);
2464 RegCloseKey(root);
2467 START_TEST(ole2)
2469 DWORD dwRegister;
2470 IStorage *pStorage;
2471 STATSTG statstg;
2472 HRESULT hr;
2474 cf_test_1 = RegisterClipboardFormatA("cf_winetest_1");
2475 cf_test_2 = RegisterClipboardFormatA("cf_winetest_2");
2476 cf_test_3 = RegisterClipboardFormatA("cf_winetest_3");
2478 CoInitialize(NULL);
2480 hr = CoRegisterClassObject(&CLSID_Equation3, (IUnknown *)&OleObjectCF, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &dwRegister);
2481 ok_ole_success(hr, "CoRegisterClassObject");
2483 hr = StgCreateDocfile(NULL, STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_DELETEONRELEASE, 0, &pStorage);
2484 ok_ole_success(hr, "StgCreateDocfile");
2486 test_OleCreate(pStorage);
2488 hr = IStorage_Stat(pStorage, &statstg, STATFLAG_NONAME);
2489 ok_ole_success(hr, "IStorage_Stat");
2490 ok(IsEqualCLSID(&CLSID_Equation3, &statstg.clsid), "Wrong CLSID in storage\n");
2492 test_OleLoad(pStorage);
2494 IStorage_Release(pStorage);
2496 hr = CoRevokeClassObject(dwRegister);
2497 ok_ole_success(hr, "CoRevokeClassObject");
2499 test_data_cache();
2500 test_data_cache_dib_contents_stream( 0 );
2501 test_data_cache_dib_contents_stream( 1 );
2502 test_default_handler();
2503 test_runnable();
2504 test_OleRun();
2505 test_OleLockRunning();
2506 test_OleDraw();
2507 test_OleDoAutoConvert();
2509 CoUninitialize();