comdlg32: Indentation fix.
[wine] / dlls / ole32 / tests / ole2.c
1 /*
2  * Object Linking and Embedding Tests
3  *
4  * Copyright 2005 Robert Shearman
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #define COBJMACROS
22 #define CONST_VTABLE
23 #define WIN32_LEAN_AND_MEAN
24
25 #include <stdarg.h>
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "objbase.h"
30 #include "shlguid.h"
31
32 #include "wine/test.h"
33
34 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
35
36 static IPersistStorage OleObjectPersistStg;
37 static IOleCache *cache;
38 static IRunnableObject *runnable;
39
40 static const CLSID CLSID_WineTest =
41 { /* 9474ba1a-258b-490b-bc13-516e9239ace0 */
42     0x9474ba1a,
43     0x258b,
44     0x490b,
45     {0xbc, 0x13, 0x51, 0x6e, 0x92, 0x39, 0xac, 0xe0}
46 };
47
48 static const IID IID_WineTest =
49 { /* 9474ba1a-258b-490b-bc13-516e9239ace1 */
50     0x9474ba1a,
51     0x258b,
52     0x490b,
53     {0xbc, 0x13, 0x51, 0x6e, 0x92, 0x39, 0xac, 0xe1}
54 };
55
56 #define TEST_OPTIONAL 0x1
57 #define TEST_TODO     0x2
58
59 struct expected_method
60 {
61     const char *method;
62     unsigned int flags;
63 };
64
65 static const struct expected_method *expected_method_list;
66 static FORMATETC *g_expected_fetc = NULL;
67
68 static BOOL g_showRunnable = TRUE;
69 static BOOL g_isRunning = TRUE;
70 static BOOL g_failGetMiscStatus;
71 static HRESULT g_QIFailsWith;
72
73 static UINT cf_test_1, cf_test_2, cf_test_3;
74
75 #define CHECK_EXPECTED_METHOD(method_name) \
76     do { \
77         trace("%s\n", method_name); \
78         ok(expected_method_list->method != NULL, "Extra method %s called\n", method_name); \
79         if (!strcmp(expected_method_list->method, "WINE_EXTRA")) \
80         { \
81             todo_wine ok(0, "Too many method calls.\n"); \
82             break; \
83         } \
84         if (expected_method_list->method) \
85         { \
86             while (expected_method_list->flags & TEST_OPTIONAL && \
87                    strcmp(expected_method_list->method, method_name) != 0) \
88                 expected_method_list++; \
89             if (expected_method_list->flags & TEST_TODO) \
90                 todo_wine \
91                     ok(!strcmp(expected_method_list->method, method_name), \
92                        "Expected %s to be called instead of %s\n", \
93                        expected_method_list->method, method_name); \
94             else \
95                 ok(!strcmp(expected_method_list->method, method_name), \
96                    "Expected %s to be called instead of %s\n", \
97                    expected_method_list->method, method_name); \
98             expected_method_list++; \
99         } \
100     } while(0)
101
102 #define CHECK_NO_EXTRA_METHODS() \
103     do { \
104         while (expected_method_list->flags & TEST_OPTIONAL) \
105             expected_method_list++; \
106         ok(!expected_method_list->method, "Method sequence starting from %s not called\n", expected_method_list->method); \
107     } while (0)
108
109 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
110 {
111     CHECK_EXPECTED_METHOD("OleObject_QueryInterface");
112
113     *ppv = NULL;
114
115     if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IOleObject))
116         *ppv = iface;
117     else if (IsEqualIID(riid, &IID_IPersistStorage))
118         *ppv = &OleObjectPersistStg;
119     else if (IsEqualIID(riid, &IID_IOleCache))
120         *ppv = cache;
121     else if (IsEqualIID(riid, &IID_IRunnableObject) && g_showRunnable)
122         *ppv = runnable;
123     else if (IsEqualIID(riid, &IID_WineTest))
124         return g_QIFailsWith;
125
126     if(*ppv) {
127         IUnknown_AddRef((IUnknown*)*ppv);
128         return S_OK;
129     }
130
131     trace("OleObject_QueryInterface: returning E_NOINTERFACE\n");
132     return E_NOINTERFACE;
133 }
134
135 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
136 {
137     CHECK_EXPECTED_METHOD("OleObject_AddRef");
138     return 2;
139 }
140
141 static ULONG WINAPI OleObject_Release(IOleObject *iface)
142 {
143     CHECK_EXPECTED_METHOD("OleObject_Release");
144     return 1;
145 }
146
147 static HRESULT WINAPI OleObject_SetClientSite
148     (
149         IOleObject *iface,
150         IOleClientSite *pClientSite
151     )
152 {
153     CHECK_EXPECTED_METHOD("OleObject_SetClientSite");
154     return S_OK;
155 }
156
157 static HRESULT WINAPI OleObject_GetClientSite
158     (
159         IOleObject *iface,
160         IOleClientSite **ppClientSite
161     )
162 {
163     CHECK_EXPECTED_METHOD("OleObject_GetClientSite");
164     return E_NOTIMPL;
165 }
166
167 static HRESULT WINAPI OleObject_SetHostNames
168     (
169         IOleObject *iface,
170         LPCOLESTR szContainerApp,
171         LPCOLESTR szContainerObj
172     )
173 {
174     CHECK_EXPECTED_METHOD("OleObject_SetHostNames");
175     return S_OK;
176 }
177
178 static HRESULT WINAPI OleObject_Close
179     (
180         IOleObject *iface,
181         DWORD dwSaveOption
182     )
183 {
184     CHECK_EXPECTED_METHOD("OleObject_Close");
185     return S_OK;
186 }
187
188 static HRESULT WINAPI OleObject_SetMoniker
189     (
190         IOleObject *iface,
191         DWORD dwWhichMoniker,
192         IMoniker *pmk
193     )
194 {
195     CHECK_EXPECTED_METHOD("OleObject_SetMoniker");
196     return S_OK;
197 }
198
199 static HRESULT WINAPI OleObject_GetMoniker
200     (
201         IOleObject *iface,
202         DWORD dwAssign,
203         DWORD dwWhichMoniker,
204         IMoniker **ppmk
205     )
206 {
207     CHECK_EXPECTED_METHOD("OleObject_GetMoniker");
208     return S_OK;
209 }
210
211 static HRESULT WINAPI OleObject_InitFromData
212     (
213         IOleObject *iface,
214         IDataObject *pDataObject,
215         BOOL fCreation,
216         DWORD dwReserved
217     )
218 {
219     CHECK_EXPECTED_METHOD("OleObject_InitFromData");
220     return S_OK;
221 }
222
223 static HRESULT WINAPI OleObject_GetClipboardData
224     (
225         IOleObject *iface,
226         DWORD dwReserved,
227         IDataObject **ppDataObject
228     )
229 {
230     CHECK_EXPECTED_METHOD("OleObject_GetClipboardData");
231     return E_NOTIMPL;
232 }
233
234 static HRESULT WINAPI OleObject_DoVerb
235     (
236         IOleObject *iface,
237         LONG iVerb,
238         LPMSG lpmsg,
239         IOleClientSite *pActiveSite,
240         LONG lindex,
241         HWND hwndParent,
242         LPCRECT lprcPosRect
243     )
244 {
245     CHECK_EXPECTED_METHOD("OleObject_DoVerb");
246     return S_OK;
247 }
248
249 static HRESULT WINAPI OleObject_EnumVerbs
250     (
251         IOleObject *iface,
252         IEnumOLEVERB **ppEnumOleVerb
253     )
254 {
255     CHECK_EXPECTED_METHOD("OleObject_EnumVerbs");
256     return E_NOTIMPL;
257 }
258
259 static HRESULT WINAPI OleObject_Update
260     (
261         IOleObject *iface
262     )
263 {
264     CHECK_EXPECTED_METHOD("OleObject_Update");
265     return S_OK;
266 }
267
268 static HRESULT WINAPI OleObject_IsUpToDate
269     (
270         IOleObject *iface
271     )
272 {
273     CHECK_EXPECTED_METHOD("OleObject_IsUpToDate");
274     return S_OK;
275 }
276
277 static HRESULT WINAPI OleObject_GetUserClassID
278 (
279     IOleObject *iface,
280     CLSID *pClsid
281 )
282 {
283     CHECK_EXPECTED_METHOD("OleObject_GetUserClassID");
284     return E_NOTIMPL;
285 }
286
287 static HRESULT WINAPI OleObject_GetUserType
288 (
289     IOleObject *iface,
290     DWORD dwFormOfType,
291     LPOLESTR *pszUserType
292 )
293 {
294     CHECK_EXPECTED_METHOD("OleObject_GetUserType");
295     return E_NOTIMPL;
296 }
297
298 static HRESULT WINAPI OleObject_SetExtent
299 (
300     IOleObject *iface,
301     DWORD dwDrawAspect,
302     SIZEL *psizel
303 )
304 {
305     CHECK_EXPECTED_METHOD("OleObject_SetExtent");
306     return S_OK;
307 }
308
309 static HRESULT WINAPI OleObject_GetExtent
310 (
311     IOleObject *iface,
312     DWORD dwDrawAspect,
313     SIZEL *psizel
314 )
315 {
316     CHECK_EXPECTED_METHOD("OleObject_GetExtent");
317     return E_NOTIMPL;
318 }
319
320 static HRESULT WINAPI OleObject_Advise
321 (
322     IOleObject *iface,
323     IAdviseSink *pAdvSink,
324     DWORD *pdwConnection
325 )
326 {
327     CHECK_EXPECTED_METHOD("OleObject_Advise");
328     return S_OK;
329 }
330
331 static HRESULT WINAPI OleObject_Unadvise
332 (
333     IOleObject *iface,
334     DWORD dwConnection
335 )
336 {
337     CHECK_EXPECTED_METHOD("OleObject_Unadvise");
338     return S_OK;
339 }
340
341 static HRESULT WINAPI OleObject_EnumAdvise
342 (
343     IOleObject *iface,
344     IEnumSTATDATA **ppenumAdvise
345 )
346 {
347     CHECK_EXPECTED_METHOD("OleObject_EnumAdvise");
348     return E_NOTIMPL;
349 }
350
351 static HRESULT WINAPI OleObject_GetMiscStatus
352 (
353     IOleObject *iface,
354     DWORD dwAspect,
355     DWORD *pdwStatus
356 )
357 {
358     CHECK_EXPECTED_METHOD("OleObject_GetMiscStatus");
359     if(!g_failGetMiscStatus)
360     {
361         *pdwStatus = OLEMISC_RECOMPOSEONRESIZE;
362         return S_OK;
363     }
364     else
365     {
366         *pdwStatus = 0x1234;
367         return E_FAIL;
368     }
369 }
370
371 static HRESULT WINAPI OleObject_SetColorScheme
372 (
373     IOleObject *iface,
374     LOGPALETTE *pLogpal
375 )
376 {
377     CHECK_EXPECTED_METHOD("OleObject_SetColorScheme");
378     return E_NOTIMPL;
379 }
380
381 static const IOleObjectVtbl OleObjectVtbl =
382 {
383     OleObject_QueryInterface,
384     OleObject_AddRef,
385     OleObject_Release,
386     OleObject_SetClientSite,
387     OleObject_GetClientSite,
388     OleObject_SetHostNames,
389     OleObject_Close,
390     OleObject_SetMoniker,
391     OleObject_GetMoniker,
392     OleObject_InitFromData,
393     OleObject_GetClipboardData,
394     OleObject_DoVerb,
395     OleObject_EnumVerbs,
396     OleObject_Update,
397     OleObject_IsUpToDate,
398     OleObject_GetUserClassID,
399     OleObject_GetUserType,
400     OleObject_SetExtent,
401     OleObject_GetExtent,
402     OleObject_Advise,
403     OleObject_Unadvise,
404     OleObject_EnumAdvise,
405     OleObject_GetMiscStatus,
406     OleObject_SetColorScheme
407 };
408
409 static IOleObject OleObject = { &OleObjectVtbl };
410
411 static HRESULT WINAPI OleObjectPersistStg_QueryInterface(IPersistStorage *iface, REFIID riid, void **ppv)
412 {
413     trace("OleObjectPersistStg_QueryInterface\n");
414     return IUnknown_QueryInterface((IUnknown *)&OleObject, riid, ppv);
415 }
416
417 static ULONG WINAPI OleObjectPersistStg_AddRef(IPersistStorage *iface)
418 {
419     CHECK_EXPECTED_METHOD("OleObjectPersistStg_AddRef");
420     return 2;
421 }
422
423 static ULONG WINAPI OleObjectPersistStg_Release(IPersistStorage *iface)
424 {
425     CHECK_EXPECTED_METHOD("OleObjectPersistStg_Release");
426     return 1;
427 }
428
429 static HRESULT WINAPI OleObjectPersistStg_GetClassId(IPersistStorage *iface, CLSID *clsid)
430 {
431     CHECK_EXPECTED_METHOD("OleObjectPersistStg_GetClassId");
432     return E_NOTIMPL;
433 }
434
435 static HRESULT WINAPI OleObjectPersistStg_IsDirty
436 (
437     IPersistStorage *iface
438 )
439 {
440     CHECK_EXPECTED_METHOD("OleObjectPersistStg_IsDirty");
441     return S_OK;
442 }
443
444 static HRESULT WINAPI OleObjectPersistStg_InitNew
445 (
446     IPersistStorage *iface,
447     IStorage *pStg
448 )
449 {
450     CHECK_EXPECTED_METHOD("OleObjectPersistStg_InitNew");
451     return S_OK;
452 }
453
454 static HRESULT WINAPI OleObjectPersistStg_Load
455 (
456     IPersistStorage *iface,
457     IStorage *pStg
458 )
459 {
460     CHECK_EXPECTED_METHOD("OleObjectPersistStg_Load");
461     return S_OK;
462 }
463
464 static HRESULT WINAPI OleObjectPersistStg_Save
465 (
466     IPersistStorage *iface,
467     IStorage *pStgSave,
468     BOOL fSameAsLoad
469 )
470 {
471     CHECK_EXPECTED_METHOD("OleObjectPersistStg_Save");
472     return S_OK;
473 }
474
475 static HRESULT WINAPI OleObjectPersistStg_SaveCompleted
476 (
477     IPersistStorage *iface,
478     IStorage *pStgNew
479 )
480 {
481     CHECK_EXPECTED_METHOD("OleObjectPersistStg_SaveCompleted");
482     return S_OK;
483 }
484
485 static HRESULT WINAPI OleObjectPersistStg_HandsOffStorage
486 (
487     IPersistStorage *iface
488 )
489 {
490     CHECK_EXPECTED_METHOD("OleObjectPersistStg_HandsOffStorage");
491     return S_OK;
492 }
493
494 static const IPersistStorageVtbl OleObjectPersistStgVtbl =
495 {
496     OleObjectPersistStg_QueryInterface,
497     OleObjectPersistStg_AddRef,
498     OleObjectPersistStg_Release,
499     OleObjectPersistStg_GetClassId,
500     OleObjectPersistStg_IsDirty,
501     OleObjectPersistStg_InitNew,
502     OleObjectPersistStg_Load,
503     OleObjectPersistStg_Save,
504     OleObjectPersistStg_SaveCompleted,
505     OleObjectPersistStg_HandsOffStorage
506 };
507
508 static IPersistStorage OleObjectPersistStg = { &OleObjectPersistStgVtbl };
509
510 static HRESULT WINAPI OleObjectCache_QueryInterface(IOleCache *iface, REFIID riid, void **ppv)
511 {
512     return IUnknown_QueryInterface((IUnknown *)&OleObject, riid, ppv);
513 }
514
515 static ULONG WINAPI OleObjectCache_AddRef(IOleCache *iface)
516 {
517     CHECK_EXPECTED_METHOD("OleObjectCache_AddRef");
518     return 2;
519 }
520
521 static ULONG WINAPI OleObjectCache_Release(IOleCache *iface)
522 {
523     CHECK_EXPECTED_METHOD("OleObjectCache_Release");
524     return 1;
525 }
526
527 static HRESULT WINAPI OleObjectCache_Cache
528 (
529     IOleCache *iface,
530     FORMATETC *pformatetc,
531     DWORD advf,
532     DWORD *pdwConnection
533 )
534 {
535     CHECK_EXPECTED_METHOD("OleObjectCache_Cache");
536     if (g_expected_fetc) {
537         ok(pformatetc != NULL, "pformatetc should not be NULL\n");
538         if (pformatetc) {
539             ok(pformatetc->cfFormat == g_expected_fetc->cfFormat,
540                     "cfFormat: %x\n", pformatetc->cfFormat);
541             ok((pformatetc->ptd != NULL) == (g_expected_fetc->ptd != NULL),
542                     "ptd: %p\n", pformatetc->ptd);
543             ok(pformatetc->dwAspect == g_expected_fetc->dwAspect,
544                     "dwAspect: %x\n", pformatetc->dwAspect);
545             ok(pformatetc->lindex == g_expected_fetc->lindex,
546                     "lindex: %x\n", pformatetc->lindex);
547             ok(pformatetc->tymed == g_expected_fetc->tymed,
548                     "tymed: %x\n", pformatetc->tymed);
549         }
550     } else
551         ok(pformatetc == NULL, "pformatetc should be NULL\n");
552     return S_OK;
553 }
554
555 static HRESULT WINAPI OleObjectCache_Uncache
556 (
557     IOleCache *iface,
558     DWORD dwConnection
559 )
560 {
561     CHECK_EXPECTED_METHOD("OleObjectCache_Uncache");
562     return S_OK;
563 }
564
565 static HRESULT WINAPI OleObjectCache_EnumCache
566 (
567     IOleCache *iface,
568     IEnumSTATDATA **ppenumSTATDATA
569 )
570 {
571     CHECK_EXPECTED_METHOD("OleObjectCache_EnumCache");
572     return S_OK;
573 }
574
575
576 static HRESULT WINAPI OleObjectCache_InitCache
577 (
578     IOleCache *iface,
579     IDataObject *pDataObject
580 )
581 {
582     CHECK_EXPECTED_METHOD("OleObjectCache_InitCache");
583     return S_OK;
584 }
585
586
587 static HRESULT WINAPI OleObjectCache_SetData
588 (
589     IOleCache *iface,
590     FORMATETC *pformatetc,
591     STGMEDIUM *pmedium,
592     BOOL fRelease
593 )
594 {
595     CHECK_EXPECTED_METHOD("OleObjectCache_SetData");
596     return S_OK;
597 }
598
599
600 static const IOleCacheVtbl OleObjectCacheVtbl =
601 {
602     OleObjectCache_QueryInterface,
603     OleObjectCache_AddRef,
604     OleObjectCache_Release,
605     OleObjectCache_Cache,
606     OleObjectCache_Uncache,
607     OleObjectCache_EnumCache,
608     OleObjectCache_InitCache,
609     OleObjectCache_SetData
610 };
611
612 static IOleCache OleObjectCache = { &OleObjectCacheVtbl };
613
614 static HRESULT WINAPI OleObjectCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
615 {
616     if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
617     {
618         *ppv = iface;
619         IClassFactory_AddRef(iface);
620         return S_OK;
621     }
622     *ppv = NULL;
623     return E_NOINTERFACE;
624 }
625
626 static ULONG WINAPI OleObjectCF_AddRef(IClassFactory *iface)
627 {
628     return 2;
629 }
630
631 static ULONG WINAPI OleObjectCF_Release(IClassFactory *iface)
632 {
633     return 1;
634 }
635
636 static HRESULT WINAPI OleObjectCF_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID riid, void **ppv)
637 {
638     return IUnknown_QueryInterface((IUnknown *)&OleObject, riid, ppv);
639 }
640
641 static HRESULT WINAPI OleObjectCF_LockServer(IClassFactory *iface, BOOL lock)
642 {
643     return S_OK;
644 }
645
646 static const IClassFactoryVtbl OleObjectCFVtbl =
647 {
648     OleObjectCF_QueryInterface,
649     OleObjectCF_AddRef,
650     OleObjectCF_Release,
651     OleObjectCF_CreateInstance,
652     OleObjectCF_LockServer
653 };
654
655 static IClassFactory OleObjectCF = { &OleObjectCFVtbl };
656
657 static HRESULT WINAPI OleObjectRunnable_QueryInterface(IRunnableObject *iface, REFIID riid, void **ppv)
658 {
659     return IUnknown_QueryInterface((IUnknown *)&OleObject, riid, ppv);
660 }
661
662 static ULONG WINAPI OleObjectRunnable_AddRef(IRunnableObject *iface)
663 {
664     CHECK_EXPECTED_METHOD("OleObjectRunnable_AddRef");
665     return 2;
666 }
667
668 static ULONG WINAPI OleObjectRunnable_Release(IRunnableObject *iface)
669 {
670     CHECK_EXPECTED_METHOD("OleObjectRunnable_Release");
671     return 1;
672 }
673
674 static HRESULT WINAPI OleObjectRunnable_GetRunningClass(
675     IRunnableObject *iface,
676     LPCLSID lpClsid)
677 {
678     CHECK_EXPECTED_METHOD("OleObjectRunnable_GetRunningClass");
679     return E_NOTIMPL;
680 }
681
682 static HRESULT WINAPI OleObjectRunnable_Run(
683     IRunnableObject *iface,
684     LPBINDCTX pbc)
685 {
686     CHECK_EXPECTED_METHOD("OleObjectRunnable_Run");
687     return S_OK;
688 }
689
690 static BOOL WINAPI OleObjectRunnable_IsRunning(IRunnableObject *iface)
691 {
692     CHECK_EXPECTED_METHOD("OleObjectRunnable_IsRunning");
693     return g_isRunning;
694 }
695
696 static HRESULT WINAPI OleObjectRunnable_LockRunning(
697     IRunnableObject *iface,
698     BOOL fLock,
699     BOOL fLastUnlockCloses)
700 {
701     CHECK_EXPECTED_METHOD("OleObjectRunnable_LockRunning");
702     return S_OK;
703 }
704
705 static HRESULT WINAPI OleObjectRunnable_SetContainedObject(
706     IRunnableObject *iface,
707     BOOL fContained)
708 {
709     CHECK_EXPECTED_METHOD("OleObjectRunnable_SetContainedObject");
710     return S_OK;
711 }
712
713 static const IRunnableObjectVtbl OleObjectRunnableVtbl =
714 {
715     OleObjectRunnable_QueryInterface,
716     OleObjectRunnable_AddRef,
717     OleObjectRunnable_Release,
718     OleObjectRunnable_GetRunningClass,
719     OleObjectRunnable_Run,
720     OleObjectRunnable_IsRunning,
721     OleObjectRunnable_LockRunning,
722     OleObjectRunnable_SetContainedObject
723 };
724
725 static IRunnableObject OleObjectRunnable = { &OleObjectRunnableVtbl };
726
727 static const CLSID CLSID_Equation3 = {0x0002CE02, 0x0000, 0x0000, {0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46} };
728
729 static HRESULT WINAPI viewobject_QueryInterface(IViewObject *iface, REFIID riid, void **obj)
730 {
731     if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IViewObject))
732     {
733         *obj = iface;
734         return S_OK;
735     }
736
737     *obj = NULL;
738     return E_NOINTERFACE;
739 }
740
741 static ULONG WINAPI viewobject_AddRef(IViewObject *iface)
742 {
743     return 2;
744 }
745
746 static ULONG WINAPI viewobject_Release(IViewObject *iface)
747 {
748     return 1;
749 }
750
751 static HRESULT WINAPI viewobject_Draw(IViewObject *iface, DWORD aspect, LONG index,
752     void *paspect, DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw,
753     LPCRECTL bounds, LPCRECTL wbounds, BOOL (STDMETHODCALLTYPE *pfnContinue)(ULONG_PTR dwContinue),
754     ULONG_PTR dwContinue)
755 {
756     ok(index == -1, "index=%d\n", index);
757     return S_OK;
758 }
759
760 static HRESULT WINAPI viewobject_GetColorSet(IViewObject *iface, DWORD draw_aspect, LONG index,
761     void *aspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **colorset)
762 {
763     ok(0, "unexpected call GetColorSet\n");
764     return E_NOTIMPL;
765 }
766
767 static HRESULT WINAPI viewobject_Freeze(IViewObject *iface, DWORD draw_aspect, LONG index,
768     void *aspect, DWORD *freeze)
769 {
770     ok(0, "unexpected call Freeze\n");
771     return E_NOTIMPL;
772 }
773
774 static HRESULT WINAPI viewobject_Unfreeze(IViewObject *iface, DWORD freeze)
775 {
776     ok(0, "unexpected call Unfreeze\n");
777     return E_NOTIMPL;
778 }
779
780 static HRESULT WINAPI viewobject_SetAdvise(IViewObject *iface, DWORD aspects, DWORD advf, IAdviseSink *sink)
781 {
782     ok(0, "unexpected call SetAdvise\n");
783     return E_NOTIMPL;
784 }
785
786 static HRESULT WINAPI viewobject_GetAdvise(IViewObject *iface, DWORD *aspects, DWORD *advf,
787     IAdviseSink **sink)
788 {
789     ok(0, "unexpected call GetAdvise\n");
790     return E_NOTIMPL;
791 }
792
793 static const struct IViewObjectVtbl viewobjectvtbl = {
794     viewobject_QueryInterface,
795     viewobject_AddRef,
796     viewobject_Release,
797     viewobject_Draw,
798     viewobject_GetColorSet,
799     viewobject_Freeze,
800     viewobject_Unfreeze,
801     viewobject_SetAdvise,
802     viewobject_GetAdvise
803 };
804
805 static IViewObject viewobject = { &viewobjectvtbl };
806
807 static void test_OleCreate(IStorage *pStorage)
808 {
809     HRESULT hr;
810     IOleObject *pObject;
811     FORMATETC formatetc;
812     static const struct expected_method methods_olerender_none[] =
813     {
814         { "OleObject_QueryInterface", 0 },
815         { "OleObject_AddRef", 0 },
816         { "OleObject_QueryInterface", 0 },
817         { "OleObject_AddRef", TEST_OPTIONAL },
818         { "OleObject_Release", TEST_OPTIONAL },
819         { "OleObject_QueryInterface", TEST_OPTIONAL },
820         { "OleObjectPersistStg_AddRef", 0 },
821         { "OleObjectPersistStg_InitNew", 0 },
822         { "OleObjectPersistStg_Release", 0 },
823         { "OleObject_Release", 0 },
824         { "OleObject_Release", TEST_OPTIONAL },
825         { NULL, 0 }
826     };
827     static const struct expected_method methods_olerender_draw[] =
828     {
829         { "OleObject_QueryInterface", 0 },
830         { "OleObject_AddRef", 0 },
831         { "OleObject_QueryInterface", 0 },
832         { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
833         { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
834         { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
835         { "OleObjectPersistStg_AddRef", 0 },
836         { "OleObjectPersistStg_InitNew", 0 },
837         { "OleObjectPersistStg_Release", 0 },
838         { "OleObject_QueryInterface", 0 },
839         { "OleObjectRunnable_AddRef", 0 },
840         { "OleObjectRunnable_Run", 0 },
841         { "OleObjectRunnable_Release", 0 },
842         { "OleObject_QueryInterface", 0 },
843         { "OleObjectCache_AddRef", 0 },
844         { "OleObjectCache_Cache", 0 },
845         { "OleObjectCache_Release", 0 },
846         { "OleObject_Release", 0 },
847         { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
848         { NULL, 0 }
849     };
850     static const struct expected_method methods_olerender_format[] =
851     {
852         { "OleObject_QueryInterface", 0 },
853         { "OleObject_AddRef", 0 },
854         { "OleObject_QueryInterface", 0 },
855         { "OleObject_AddRef", 0 },
856         { "OleObject_GetMiscStatus", 0 },
857         { "OleObject_QueryInterface", 0 },
858         { "OleObjectPersistStg_AddRef", 0 },
859         { "OleObjectPersistStg_InitNew", 0 },
860         { "OleObjectPersistStg_Release", 0 },
861         { "OleObject_SetClientSite", 0 },
862         { "OleObject_Release", 0 },
863         { "OleObject_QueryInterface", 0 },
864         { "OleObjectRunnable_AddRef", 0 },
865         { "OleObjectRunnable_Run", 0 },
866         { "OleObjectRunnable_Release", 0 },
867         { "OleObject_QueryInterface", 0 },
868         { "OleObjectCache_AddRef", 0 },
869         { "OleObjectCache_Cache", 0 },
870         { "OleObjectCache_Release", 0 },
871         { "OleObject_Release", 0 },
872         { NULL, 0 }
873     };
874     static const struct expected_method methods_olerender_asis[] =
875     {
876         { "OleObject_QueryInterface", 0 },
877         { "OleObject_AddRef", 0 },
878         { "OleObject_QueryInterface", 0 },
879         { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
880         { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
881         { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
882         { "OleObjectPersistStg_AddRef", 0 },
883         { "OleObjectPersistStg_InitNew", 0 },
884         { "OleObjectPersistStg_Release", 0 },
885         { "OleObject_Release", 0 },
886         { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
887         { NULL, 0 }
888     };
889     static const struct expected_method methods_olerender_draw_no_runnable[] =
890     {
891         { "OleObject_QueryInterface", 0 },
892         { "OleObject_AddRef", 0 },
893         { "OleObject_QueryInterface", 0 },
894         { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
895         { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
896         { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
897         { "OleObjectPersistStg_AddRef", 0 },
898         { "OleObjectPersistStg_InitNew", 0 },
899         { "OleObjectPersistStg_Release", 0 },
900         { "OleObject_QueryInterface", 0 },
901         { "OleObject_QueryInterface", 0 },
902         { "OleObjectCache_AddRef", 0 },
903         { "OleObjectCache_Cache", 0 },
904         { "OleObjectCache_Release", 0 },
905         { "OleObject_Release", 0 },
906         { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
907         { NULL, 0 },
908     };
909     static const struct expected_method methods_olerender_draw_no_cache[] =
910     {
911         { "OleObject_QueryInterface", 0 },
912         { "OleObject_AddRef", 0 },
913         { "OleObject_QueryInterface", 0 },
914         { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
915         { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
916         { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
917         { "OleObjectPersistStg_AddRef", 0 },
918         { "OleObjectPersistStg_InitNew", 0 },
919         { "OleObjectPersistStg_Release", 0 },
920         { "OleObject_QueryInterface", 0 },
921         { "OleObjectRunnable_AddRef", 0 },
922         { "OleObjectRunnable_Run", 0 },
923         { "OleObjectRunnable_Release", 0 },
924         { "OleObject_QueryInterface", 0 },
925         { "OleObject_Release", 0 },
926         { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
927         { NULL, 0 }
928     };
929
930     g_expected_fetc = &formatetc;
931     formatetc.cfFormat = 0;
932     formatetc.ptd = NULL;
933     formatetc.dwAspect = DVASPECT_CONTENT;
934     formatetc.lindex = -1;
935     formatetc.tymed = TYMED_NULL;
936     runnable = &OleObjectRunnable;
937     cache = &OleObjectCache;
938     expected_method_list = methods_olerender_none;
939     trace("OleCreate with OLERENDER_NONE:\n");
940     hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_NONE, NULL, NULL, pStorage, (void **)&pObject);
941     ok_ole_success(hr, "OleCreate");
942     IOleObject_Release(pObject);
943     CHECK_NO_EXTRA_METHODS();
944
945     expected_method_list = methods_olerender_draw;
946     trace("OleCreate with OLERENDER_DRAW:\n");
947     hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject);
948     ok_ole_success(hr, "OleCreate");
949     IOleObject_Release(pObject);
950     CHECK_NO_EXTRA_METHODS();
951
952     formatetc.cfFormat = CF_TEXT;
953     formatetc.ptd = NULL;
954     formatetc.dwAspect = DVASPECT_CONTENT;
955     formatetc.lindex = -1;
956     formatetc.tymed = TYMED_HGLOBAL;
957     expected_method_list = methods_olerender_format;
958     trace("OleCreate with OLERENDER_FORMAT:\n");
959     hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_FORMAT, &formatetc, (IOleClientSite *)0xdeadbeef, pStorage, (void **)&pObject);
960     ok(hr == S_OK ||
961        broken(hr == E_INVALIDARG), /* win2k */
962        "OleCreate failed with error 0x%08x\n", hr);
963     if (pObject)
964     {
965         IOleObject_Release(pObject);
966         CHECK_NO_EXTRA_METHODS();
967     }
968
969     expected_method_list = methods_olerender_asis;
970     trace("OleCreate with OLERENDER_ASIS:\n");
971     hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_ASIS, NULL, NULL, pStorage, (void **)&pObject);
972     ok_ole_success(hr, "OleCreate");
973     IOleObject_Release(pObject);
974     CHECK_NO_EXTRA_METHODS();
975
976     formatetc.cfFormat = 0;
977     formatetc.tymed = TYMED_NULL;
978     runnable = NULL;
979     expected_method_list = methods_olerender_draw_no_runnable;
980     trace("OleCreate with OLERENDER_DRAW (no IRunnableObject):\n");
981     hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject);
982     ok_ole_success(hr, "OleCreate");
983     IOleObject_Release(pObject);
984     CHECK_NO_EXTRA_METHODS();
985
986     runnable = &OleObjectRunnable;
987     cache = NULL;
988     expected_method_list = methods_olerender_draw_no_cache;
989     trace("OleCreate with OLERENDER_DRAW (no IOleCache):\n");
990     hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject);
991     ok_ole_success(hr, "OleCreate");
992     IOleObject_Release(pObject);
993     CHECK_NO_EXTRA_METHODS();
994     trace("end\n");
995     g_expected_fetc = NULL;
996 }
997
998 static void test_OleLoad(IStorage *pStorage)
999 {
1000     HRESULT hr;
1001     IOleObject *pObject;
1002
1003     static const struct expected_method methods_oleload[] =
1004     {
1005         { "OleObject_QueryInterface", 0 },
1006         { "OleObject_AddRef", 0 },
1007         { "OleObject_QueryInterface", 0 },
1008         { "OleObject_AddRef", 0 },
1009         { "OleObject_GetMiscStatus", 0 },
1010         { "OleObject_QueryInterface", 0 },
1011         { "OleObjectPersistStg_AddRef", 0 },
1012         { "OleObjectPersistStg_Load", 0 },
1013         { "OleObjectPersistStg_Release", 0 },
1014         { "OleObject_SetClientSite", 0 },
1015         { "OleObject_Release", 0 },
1016         { "OleObject_QueryInterface", 0 },
1017         { "OleObject_GetMiscStatus", 0 },
1018         { "OleObject_Release", 0 },
1019         { NULL, 0 }
1020     };
1021
1022     /* Test once with IOleObject_GetMiscStatus failing */
1023     expected_method_list = methods_oleload;
1024     g_failGetMiscStatus = TRUE;
1025     trace("OleLoad:\n");
1026     hr = OleLoad(pStorage, &IID_IOleObject, (IOleClientSite *)0xdeadbeef, (void **)&pObject);
1027     ok(hr == S_OK ||
1028        broken(hr == E_INVALIDARG), /* win98 and win2k */
1029        "OleLoad failed with error 0x%08x\n", hr);
1030     if(pObject)
1031     {
1032         DWORD dwStatus = 0xdeadbeef;
1033         hr = IOleObject_GetMiscStatus(pObject, DVASPECT_CONTENT, &dwStatus);
1034         ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1035         ok(dwStatus == 0x1234, "Got 0x%08x\n", dwStatus);
1036
1037         IOleObject_Release(pObject);
1038         CHECK_NO_EXTRA_METHODS();
1039     }
1040
1041     /* Test again, let IOleObject_GetMiscStatus succeed. */
1042     g_failGetMiscStatus = FALSE;
1043     expected_method_list = methods_oleload;
1044     trace("OleLoad:\n");
1045     hr = OleLoad(pStorage, &IID_IOleObject, (IOleClientSite *)0xdeadbeef, (void **)&pObject);
1046     ok(hr == S_OK ||
1047        broken(hr == E_INVALIDARG), /* win98 and win2k */
1048        "OleLoad failed with error 0x%08x\n", hr);
1049     if (pObject)
1050     {
1051         DWORD dwStatus = 0xdeadbeef;
1052         hr = IOleObject_GetMiscStatus(pObject, DVASPECT_CONTENT, &dwStatus);
1053         ok(hr == S_OK, "Got 0x%08x\n", hr);
1054         ok(dwStatus == 1, "Got 0x%08x\n", dwStatus);
1055
1056         IOleObject_Release(pObject);
1057         CHECK_NO_EXTRA_METHODS();
1058     }
1059 }
1060
1061 static BOOL STDMETHODCALLTYPE draw_continue(ULONG_PTR param)
1062 {
1063     CHECK_EXPECTED_METHOD("draw_continue");
1064     return TRUE;
1065 }
1066
1067 static BOOL STDMETHODCALLTYPE draw_continue_false(ULONG_PTR param)
1068 {
1069     CHECK_EXPECTED_METHOD("draw_continue_false");
1070     return FALSE;
1071 }
1072
1073 static HRESULT WINAPI AdviseSink_QueryInterface(IAdviseSink *iface, REFIID riid, void **ppv)
1074 {
1075     if (IsEqualIID(riid, &IID_IAdviseSink) || IsEqualIID(riid, &IID_IUnknown))
1076     {
1077         *ppv = iface;
1078         IAdviseSink_AddRef(iface);
1079         return S_OK;
1080     }
1081     *ppv = NULL;
1082     return E_NOINTERFACE;
1083 }
1084
1085 static ULONG WINAPI AdviseSink_AddRef(IAdviseSink *iface)
1086 {
1087     return 2;
1088 }
1089
1090 static ULONG WINAPI AdviseSink_Release(IAdviseSink *iface)
1091 {
1092     return 1;
1093 }
1094
1095
1096 static void WINAPI AdviseSink_OnDataChange(
1097     IAdviseSink *iface,
1098     FORMATETC *pFormatetc,
1099     STGMEDIUM *pStgmed)
1100 {
1101     CHECK_EXPECTED_METHOD("AdviseSink_OnDataChange");
1102 }
1103
1104 static void WINAPI AdviseSink_OnViewChange(
1105     IAdviseSink *iface,
1106     DWORD dwAspect,
1107     LONG lindex)
1108 {
1109     CHECK_EXPECTED_METHOD("AdviseSink_OnViewChange");
1110 }
1111
1112 static void WINAPI AdviseSink_OnRename(
1113     IAdviseSink *iface,
1114     IMoniker *pmk)
1115 {
1116     CHECK_EXPECTED_METHOD("AdviseSink_OnRename");
1117 }
1118
1119 static void WINAPI AdviseSink_OnSave(IAdviseSink *iface)
1120 {
1121     CHECK_EXPECTED_METHOD("AdviseSink_OnSave");
1122 }
1123
1124 static void WINAPI AdviseSink_OnClose(IAdviseSink *iface)
1125 {
1126     CHECK_EXPECTED_METHOD("AdviseSink_OnClose");
1127 }
1128
1129 static const IAdviseSinkVtbl AdviseSinkVtbl =
1130 {
1131     AdviseSink_QueryInterface,
1132     AdviseSink_AddRef,
1133     AdviseSink_Release,
1134     AdviseSink_OnDataChange,
1135     AdviseSink_OnViewChange,
1136     AdviseSink_OnRename,
1137     AdviseSink_OnSave,
1138     AdviseSink_OnClose
1139 };
1140
1141 static IAdviseSink AdviseSink = { &AdviseSinkVtbl };
1142
1143 static HRESULT WINAPI DataObject_QueryInterface(
1144             IDataObject*     iface,
1145             REFIID           riid,
1146             void**           ppvObject)
1147 {
1148     CHECK_EXPECTED_METHOD("DataObject_QueryInterface");
1149
1150     if (IsEqualIID(riid, &IID_IDataObject) || IsEqualIID(riid, &IID_IUnknown))
1151     {
1152         *ppvObject = iface;
1153         return S_OK;
1154     }
1155     *ppvObject = NULL;
1156     return S_OK;
1157 }
1158
1159 static ULONG WINAPI DataObject_AddRef(
1160             IDataObject*     iface)
1161 {
1162     CHECK_EXPECTED_METHOD("DataObject_AddRef");
1163     return 2;
1164 }
1165
1166 static ULONG WINAPI DataObject_Release(
1167             IDataObject*     iface)
1168 {
1169     CHECK_EXPECTED_METHOD("DataObject_Release");
1170     return 1;
1171 }
1172
1173 static HRESULT WINAPI DataObject_GetData(
1174         IDataObject*     iface,
1175         LPFORMATETC      pformatetcIn,
1176         STGMEDIUM*       pmedium)
1177 {
1178     CHECK_EXPECTED_METHOD("DataObject_GetData");
1179     return E_NOTIMPL;
1180 }
1181
1182 static HRESULT WINAPI DataObject_GetDataHere(
1183         IDataObject*     iface,
1184         LPFORMATETC      pformatetc,
1185         STGMEDIUM*       pmedium)
1186 {
1187     CHECK_EXPECTED_METHOD("DataObject_GetDataHere");
1188     return E_NOTIMPL;
1189 }
1190
1191 static HRESULT WINAPI DataObject_QueryGetData(
1192         IDataObject*     iface,
1193         LPFORMATETC      pformatetc)
1194 {
1195     CHECK_EXPECTED_METHOD("DataObject_QueryGetData");
1196     return S_OK;
1197 }
1198
1199 static HRESULT WINAPI DataObject_GetCanonicalFormatEtc(
1200         IDataObject*     iface,
1201         LPFORMATETC      pformatectIn,
1202         LPFORMATETC      pformatetcOut)
1203 {
1204     CHECK_EXPECTED_METHOD("DataObject_GetCanonicalFormatEtc");
1205     return E_NOTIMPL;
1206 }
1207
1208 static HRESULT WINAPI DataObject_SetData(
1209         IDataObject*     iface,
1210         LPFORMATETC      pformatetc,
1211         STGMEDIUM*       pmedium,
1212         BOOL             fRelease)
1213 {
1214     CHECK_EXPECTED_METHOD("DataObject_SetData");
1215     return E_NOTIMPL;
1216 }
1217
1218 static HRESULT WINAPI DataObject_EnumFormatEtc(
1219         IDataObject*     iface,
1220         DWORD            dwDirection,
1221         IEnumFORMATETC** ppenumFormatEtc)
1222 {
1223     CHECK_EXPECTED_METHOD("DataObject_EnumFormatEtc");
1224     return E_NOTIMPL;
1225 }
1226
1227 static HRESULT WINAPI DataObject_DAdvise(
1228         IDataObject*     iface,
1229         FORMATETC*       pformatetc,
1230         DWORD            advf,
1231         IAdviseSink*     pAdvSink,
1232         DWORD*           pdwConnection)
1233 {
1234     STGMEDIUM stgmedium;
1235
1236     CHECK_EXPECTED_METHOD("DataObject_DAdvise");
1237     *pdwConnection = 1;
1238
1239     if(advf & ADVF_PRIMEFIRST)
1240     {
1241         ok(pformatetc->cfFormat == cf_test_2, "got %04x\n", pformatetc->cfFormat);
1242         stgmedium.tymed = TYMED_HGLOBAL;
1243         U(stgmedium).hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, 4);
1244         stgmedium.pUnkForRelease = NULL;
1245         IAdviseSink_OnDataChange(pAdvSink, pformatetc, &stgmedium);
1246     }
1247
1248     return S_OK;
1249 }
1250
1251 static HRESULT WINAPI DataObject_DUnadvise(
1252         IDataObject*     iface,
1253         DWORD            dwConnection)
1254 {
1255     CHECK_EXPECTED_METHOD("DataObject_DUnadvise");
1256     return S_OK;
1257 }
1258
1259 static HRESULT WINAPI DataObject_EnumDAdvise(
1260         IDataObject*     iface,
1261         IEnumSTATDATA**  ppenumAdvise)
1262 {
1263     CHECK_EXPECTED_METHOD("DataObject_EnumDAdvise");
1264     return OLE_E_ADVISENOTSUPPORTED;
1265 }
1266
1267 static IDataObjectVtbl DataObjectVtbl =
1268 {
1269     DataObject_QueryInterface,
1270     DataObject_AddRef,
1271     DataObject_Release,
1272     DataObject_GetData,
1273     DataObject_GetDataHere,
1274     DataObject_QueryGetData,
1275     DataObject_GetCanonicalFormatEtc,
1276     DataObject_SetData,
1277     DataObject_EnumFormatEtc,
1278     DataObject_DAdvise,
1279     DataObject_DUnadvise,
1280     DataObject_EnumDAdvise
1281 };
1282
1283 static IDataObject DataObject = { &DataObjectVtbl };
1284
1285 static void test_data_cache(void)
1286 {
1287     HRESULT hr;
1288     IOleCache2 *pOleCache;
1289     IStorage *pStorage;
1290     IPersistStorage *pPS;
1291     IViewObject *pViewObject;
1292     IOleCacheControl *pOleCacheControl;
1293     IDataObject *pCacheDataObject;
1294     FORMATETC fmtetc;
1295     STGMEDIUM stgmedium;
1296     DWORD dwConnection;
1297     DWORD dwFreeze;
1298     RECTL rcBounds;
1299     HDC hdcMem;
1300     CLSID clsid;
1301     char szSystemDir[MAX_PATH];
1302     WCHAR wszPath[MAX_PATH];
1303     static const WCHAR wszShell32[] = {'\\','s','h','e','l','l','3','2','.','d','l','l',0};
1304
1305     static const struct expected_method methods_cacheinitnew[] =
1306     {
1307         { "AdviseSink_OnViewChange", 0 },
1308         { "AdviseSink_OnViewChange", 0 },
1309         { "draw_continue", 1 },
1310         { "draw_continue_false", 1 },
1311         { "DataObject_DAdvise", 0 },
1312         { "DataObject_DAdvise", 0 },
1313         { "DataObject_DUnadvise", 0 },
1314         { "DataObject_DUnadvise", 0 },
1315         { NULL, 0 }
1316     };
1317     static const struct expected_method methods_cacheload[] =
1318     {
1319         { "AdviseSink_OnViewChange", 0 },
1320         { "draw_continue", 1 },
1321         { "draw_continue", 1 },
1322         { "draw_continue", 1 },
1323         { "DataObject_GetData", 0 },
1324         { "DataObject_GetData", 0 },
1325         { "DataObject_GetData", 0 },
1326         { NULL, 0 }
1327     };
1328     static const struct expected_method methods_cachethenrun[] =
1329     {
1330         { "DataObject_DAdvise", 0 },
1331         { "DataObject_DAdvise", 0 },
1332         { "DataObject_DAdvise", 0 },
1333         { "DataObject_QueryGetData", 1 }, /* called by win9x and nt4 */
1334         { "DataObject_DAdvise", 0 },
1335         { "DataObject_DUnadvise", 0 },
1336         { "DataObject_DUnadvise", 0 },
1337         { "DataObject_DUnadvise", 0 },
1338         { "DataObject_DUnadvise", 0 },
1339         { NULL, 0 }
1340     };
1341
1342     GetSystemDirectory(szSystemDir, sizeof(szSystemDir)/sizeof(szSystemDir[0]));
1343
1344     expected_method_list = methods_cacheinitnew;
1345
1346     fmtetc.cfFormat = CF_METAFILEPICT;
1347     fmtetc.dwAspect = DVASPECT_ICON;
1348     fmtetc.lindex = -1;
1349     fmtetc.ptd = NULL;
1350     fmtetc.tymed = TYMED_MFPICT;
1351
1352     hr = StgCreateDocfile(NULL, STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_DELETEONRELEASE, 0, &pStorage);
1353     ok_ole_success(hr, "StgCreateDocfile");
1354
1355     /* Test with new data */
1356
1357     hr = CreateDataCache(NULL, &CLSID_NULL, &IID_IOleCache2, (LPVOID *)&pOleCache);
1358     ok_ole_success(hr, "CreateDataCache");
1359
1360     hr = IOleCache2_QueryInterface(pOleCache, &IID_IPersistStorage, (LPVOID *)&pPS);
1361     ok_ole_success(hr, "IOleCache_QueryInterface(IID_IPersistStorage)");
1362     hr = IOleCache2_QueryInterface(pOleCache, &IID_IViewObject, (LPVOID *)&pViewObject);
1363     ok_ole_success(hr, "IOleCache_QueryInterface(IID_IViewObject)");
1364     hr = IOleCache2_QueryInterface(pOleCache, &IID_IOleCacheControl, (LPVOID *)&pOleCacheControl);
1365     ok_ole_success(hr, "IOleCache_QueryInterface(IID_IOleCacheControl)");
1366
1367     hr = IViewObject_SetAdvise(pViewObject, DVASPECT_ICON, ADVF_PRIMEFIRST, &AdviseSink);
1368     ok_ole_success(hr, "IViewObject_SetAdvise");
1369
1370     hr = IPersistStorage_InitNew(pPS, pStorage);
1371     ok_ole_success(hr, "IPersistStorage_InitNew");
1372
1373     hr = IPersistStorage_IsDirty(pPS);
1374     ok_ole_success(hr, "IPersistStorage_IsDirty");
1375
1376     hr = IPersistStorage_GetClassID(pPS, &clsid);
1377     ok_ole_success(hr, "IPersistStorage_GetClassID");
1378     ok(IsEqualCLSID(&clsid, &IID_NULL), "clsid should be blank\n");
1379
1380     hr = IOleCache2_Uncache(pOleCache, 0xdeadbeef);
1381     ok(hr == OLE_E_NOCONNECTION, "IOleCache_Uncache with invalid value should return OLE_E_NOCONNECTION instead of 0x%x\n", hr);
1382
1383     /* Both tests crash on NT4 and below. StgCreatePropSetStg is only available on w2k and above. */
1384     if (GetProcAddress(GetModuleHandleA("ole32.dll"), "StgCreatePropSetStg"))
1385     {
1386         hr = IOleCache2_Cache(pOleCache, NULL, 0, &dwConnection);
1387         ok(hr == E_INVALIDARG, "IOleCache_Cache with NULL fmtetc should have returned E_INVALIDARG instead of 0x%08x\n", hr);
1388
1389         hr = IOleCache2_Cache(pOleCache, NULL, 0, NULL);
1390         ok(hr == E_INVALIDARG, "IOleCache_Cache with NULL pdwConnection should have returned E_INVALIDARG instead of 0x%08x\n", hr);
1391     }
1392     else
1393     {
1394         skip("tests with NULL parameters will crash on NT4 and below\n");
1395     }
1396
1397     for (fmtetc.cfFormat = CF_TEXT; fmtetc.cfFormat < CF_MAX; fmtetc.cfFormat++)
1398     {
1399         int i;
1400         fmtetc.dwAspect = DVASPECT_THUMBNAIL;
1401         for (i = 0; i < 7; i++)
1402         {
1403             fmtetc.tymed = 1 << i;
1404             hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1405             if ((fmtetc.cfFormat == CF_METAFILEPICT && fmtetc.tymed == TYMED_MFPICT) ||
1406                 (fmtetc.cfFormat == CF_BITMAP && fmtetc.tymed == TYMED_GDI) ||
1407                 (fmtetc.cfFormat == CF_DIB && fmtetc.tymed == TYMED_HGLOBAL) ||
1408                 (fmtetc.cfFormat == CF_ENHMETAFILE && fmtetc.tymed == TYMED_ENHMF))
1409                 ok(hr == S_OK, "IOleCache_Cache cfFormat = %d, tymed = %d should have returned S_OK instead of 0x%08x\n",
1410                     fmtetc.cfFormat, fmtetc.tymed, hr);
1411             else if (fmtetc.tymed == TYMED_HGLOBAL)
1412                 ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED ||
1413                    broken(hr == S_OK && fmtetc.cfFormat == CF_BITMAP) /* Win9x & NT4 */,
1414                     "IOleCache_Cache cfFormat = %d, tymed = %d should have returned CACHE_S_FORMATETC_NOTSUPPORTED instead of 0x%08x\n",
1415                     fmtetc.cfFormat, fmtetc.tymed, hr);
1416             else
1417                 ok(hr == DV_E_TYMED, "IOleCache_Cache cfFormat = %d, tymed = %d should have returned DV_E_TYMED instead of 0x%08x\n",
1418                     fmtetc.cfFormat, fmtetc.tymed, hr);
1419             if (SUCCEEDED(hr))
1420             {
1421                 hr = IOleCache2_Uncache(pOleCache, dwConnection);
1422                 ok_ole_success(hr, "IOleCache_Uncache");
1423             }
1424         }
1425     }
1426
1427     fmtetc.cfFormat = CF_BITMAP;
1428     fmtetc.dwAspect = DVASPECT_THUMBNAIL;
1429     fmtetc.tymed = TYMED_GDI;
1430     hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1431     ok_ole_success(hr, "IOleCache_Cache");
1432
1433     fmtetc.cfFormat = 0;
1434     fmtetc.dwAspect = DVASPECT_ICON;
1435     fmtetc.tymed = TYMED_MFPICT;
1436     hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1437     ok_ole_success(hr, "IOleCache_Cache");
1438
1439     MultiByteToWideChar(CP_ACP, 0, szSystemDir, -1, wszPath, sizeof(wszPath)/sizeof(wszPath[0]));
1440     memcpy(wszPath+lstrlenW(wszPath), wszShell32, sizeof(wszShell32));
1441
1442     fmtetc.cfFormat = CF_METAFILEPICT;
1443     stgmedium.tymed = TYMED_MFPICT;
1444     U(stgmedium).hMetaFilePict = OleMetafilePictFromIconAndLabel(
1445         LoadIcon(NULL, IDI_APPLICATION), wszPath, wszPath, 0);
1446     stgmedium.pUnkForRelease = NULL;
1447
1448     fmtetc.dwAspect = DVASPECT_CONTENT;
1449     hr = IOleCache2_SetData(pOleCache, &fmtetc, &stgmedium, FALSE);
1450     ok(hr == OLE_E_BLANK, "IOleCache_SetData for aspect not in cache should have return OLE_E_BLANK instead of 0x%08x\n", hr);
1451
1452     fmtetc.dwAspect = DVASPECT_ICON;
1453     hr = IOleCache2_SetData(pOleCache, &fmtetc, &stgmedium, FALSE);
1454     ok_ole_success(hr, "IOleCache_SetData");
1455     ReleaseStgMedium(&stgmedium);
1456
1457     hr = IViewObject_Freeze(pViewObject, DVASPECT_ICON, -1, NULL, &dwFreeze);
1458     todo_wine {
1459     ok_ole_success(hr, "IViewObject_Freeze");
1460     hr = IViewObject_Freeze(pViewObject, DVASPECT_CONTENT, -1, NULL, &dwFreeze);
1461     ok(hr == OLE_E_BLANK, "IViewObject_Freeze with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1462     }
1463
1464     rcBounds.left = 0;
1465     rcBounds.top = 0;
1466     rcBounds.right = 100;
1467     rcBounds.bottom = 100;
1468     hdcMem = CreateCompatibleDC(NULL);
1469
1470     hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1471     ok_ole_success(hr, "IViewObject_Draw");
1472
1473     hr = IViewObject_Draw(pViewObject, DVASPECT_CONTENT, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1474     ok(hr == OLE_E_BLANK, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1475
1476     /* a NULL draw_continue fn ptr */
1477     hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, NULL, 0xdeadbeef);
1478     ok_ole_success(hr, "IViewObject_Draw");
1479
1480     /* draw_continue that returns FALSE to abort drawing */
1481     hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue_false, 0xdeadbeef);
1482     ok(hr == E_ABORT ||
1483        broken(hr == S_OK), /* win9x may skip the callbacks */
1484        "IViewObject_Draw with draw_continue_false returns 0x%08x\n", hr);
1485
1486     DeleteDC(hdcMem);
1487
1488     hr = IOleCacheControl_OnRun(pOleCacheControl, &DataObject);
1489     ok_ole_success(hr, "IOleCacheControl_OnRun");
1490
1491     hr = IPersistStorage_Save(pPS, pStorage, TRUE);
1492     ok_ole_success(hr, "IPersistStorage_Save");
1493
1494     hr = IPersistStorage_SaveCompleted(pPS, NULL);
1495     ok_ole_success(hr, "IPersistStorage_SaveCompleted");
1496
1497     hr = IPersistStorage_IsDirty(pPS);
1498     ok(hr == S_FALSE, "IPersistStorage_IsDirty should have returned S_FALSE instead of 0x%x\n", hr);
1499
1500     IPersistStorage_Release(pPS);
1501     IViewObject_Release(pViewObject);
1502     IOleCache2_Release(pOleCache);
1503     IOleCacheControl_Release(pOleCacheControl);
1504
1505     CHECK_NO_EXTRA_METHODS();
1506
1507     /* Test with loaded data */
1508     trace("Testing loaded data with CreateDataCache:\n");
1509     expected_method_list = methods_cacheload;
1510
1511     hr = CreateDataCache(NULL, &CLSID_NULL, &IID_IOleCache2, (LPVOID *)&pOleCache);
1512     ok_ole_success(hr, "CreateDataCache");
1513
1514     hr = IOleCache2_QueryInterface(pOleCache, &IID_IPersistStorage, (LPVOID *)&pPS);
1515     ok_ole_success(hr, "IOleCache_QueryInterface(IID_IPersistStorage)");
1516     hr = IOleCache2_QueryInterface(pOleCache, &IID_IViewObject, (LPVOID *)&pViewObject);
1517     ok_ole_success(hr, "IOleCache_QueryInterface(IID_IViewObject)");
1518
1519     hr = IViewObject_SetAdvise(pViewObject, DVASPECT_ICON, ADVF_PRIMEFIRST, &AdviseSink);
1520     ok_ole_success(hr, "IViewObject_SetAdvise");
1521
1522     hr = IPersistStorage_Load(pPS, pStorage);
1523     ok_ole_success(hr, "IPersistStorage_Load");
1524
1525     hr = IPersistStorage_IsDirty(pPS);
1526     ok(hr == S_FALSE, "IPersistStorage_IsDirty should have returned S_FALSE instead of 0x%x\n", hr);
1527
1528     fmtetc.cfFormat = 0;
1529     fmtetc.dwAspect = DVASPECT_ICON;
1530     fmtetc.lindex = -1;
1531     fmtetc.ptd = NULL;
1532     fmtetc.tymed = TYMED_MFPICT;
1533     hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1534     ok(hr == CACHE_S_SAMECACHE, "IOleCache_Cache with already loaded data format type should return CACHE_S_SAMECACHE instead of 0x%x\n", hr);
1535
1536     rcBounds.left = 0;
1537     rcBounds.top = 0;
1538     rcBounds.right = 100;
1539     rcBounds.bottom = 100;
1540     hdcMem = CreateCompatibleDC(NULL);
1541
1542     hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1543     ok_ole_success(hr, "IViewObject_Draw");
1544
1545     hr = IViewObject_Draw(pViewObject, DVASPECT_CONTENT, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1546     ok(hr == OLE_E_BLANK, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1547
1548     /* unload the cached storage object, causing it to be reloaded */
1549     hr = IOleCache2_DiscardCache(pOleCache, DISCARDCACHE_NOSAVE);
1550     ok_ole_success(hr, "IOleCache2_DiscardCache");
1551     hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1552     ok_ole_success(hr, "IViewObject_Draw");
1553
1554     /* unload the cached storage object, but don't allow it to be reloaded */
1555     hr = IPersistStorage_HandsOffStorage(pPS);
1556     ok_ole_success(hr, "IPersistStorage_HandsOffStorage");
1557     hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1558     ok_ole_success(hr, "IViewObject_Draw");
1559     hr = IOleCache2_DiscardCache(pOleCache, DISCARDCACHE_NOSAVE);
1560     ok_ole_success(hr, "IOleCache2_DiscardCache");
1561     hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1562     ok(hr == OLE_E_BLANK, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1563
1564     DeleteDC(hdcMem);
1565
1566     todo_wine {
1567     hr = IOleCache2_InitCache(pOleCache, &DataObject);
1568     ok(hr == CACHE_E_NOCACHE_UPDATED, "IOleCache_InitCache should have returned CACHE_E_NOCACHE_UPDATED instead of 0x%08x\n", hr);
1569     }
1570
1571     IPersistStorage_Release(pPS);
1572     IViewObject_Release(pViewObject);
1573     IOleCache2_Release(pOleCache);
1574
1575     todo_wine {
1576     CHECK_NO_EXTRA_METHODS();
1577     }
1578
1579     hr = CreateDataCache(NULL, &CLSID_NULL, &IID_IOleCache2, (LPVOID *)&pOleCache);
1580     ok_ole_success(hr, "CreateDataCache");
1581
1582     expected_method_list = methods_cachethenrun;
1583
1584     hr = IOleCache2_QueryInterface(pOleCache, &IID_IDataObject, (LPVOID *)&pCacheDataObject);
1585     ok_ole_success(hr, "IOleCache_QueryInterface(IID_IDataObject)");
1586     hr = IOleCache2_QueryInterface(pOleCache, &IID_IOleCacheControl, (LPVOID *)&pOleCacheControl);
1587     ok_ole_success(hr, "IOleCache_QueryInterface(IID_IOleCacheControl)");
1588
1589     fmtetc.cfFormat = CF_METAFILEPICT;
1590     fmtetc.dwAspect = DVASPECT_CONTENT;
1591     fmtetc.tymed = TYMED_MFPICT;
1592
1593     hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1594     ok_ole_success(hr, "IOleCache_Cache");
1595
1596     hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1597     ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1598
1599     fmtetc.cfFormat = cf_test_1;
1600     fmtetc.dwAspect = DVASPECT_CONTENT;
1601     fmtetc.tymed = TYMED_HGLOBAL;
1602
1603     hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1604     ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED, "got %08x\n", hr);
1605
1606     hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1607     ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1608
1609     fmtetc.cfFormat = cf_test_2;
1610     hr = IOleCache2_Cache(pOleCache, &fmtetc, ADVF_PRIMEFIRST, &dwConnection);
1611     ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED, "got %08x\n", hr);
1612
1613     hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1614     ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1615
1616     hr = IOleCacheControl_OnRun(pOleCacheControl, &DataObject);
1617     ok_ole_success(hr, "IOleCacheControl_OnRun");
1618
1619     fmtetc.cfFormat = cf_test_3;
1620     hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1621     ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED, "got %08x\n", hr);
1622
1623     fmtetc.cfFormat = cf_test_1;
1624     hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1625     ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1626
1627     fmtetc.cfFormat = cf_test_2;
1628     hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1629     ok(hr == S_OK, "got %08x\n", hr);
1630     ReleaseStgMedium(&stgmedium);
1631
1632     fmtetc.cfFormat = cf_test_3;
1633     hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1634     ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1635
1636     IOleCacheControl_Release(pOleCacheControl);
1637     IDataObject_Release(pCacheDataObject);
1638     IOleCache2_Release(pOleCache);
1639
1640     CHECK_NO_EXTRA_METHODS();
1641
1642     IStorage_Release(pStorage);
1643 }
1644
1645 static void test_default_handler(void)
1646 {
1647     HRESULT hr;
1648     IOleObject *pObject;
1649     IRunnableObject *pRunnableObject;
1650     IOleClientSite *pClientSite;
1651     IDataObject *pDataObject;
1652     SIZEL sizel;
1653     DWORD dwStatus;
1654     CLSID clsid;
1655     LPOLESTR pszUserType;
1656     LOGPALETTE palette;
1657     DWORD dwAdvConn;
1658     IMoniker *pMoniker;
1659     FORMATETC fmtetc;
1660     IOleInPlaceObject *pInPlaceObj;
1661     IEnumOLEVERB *pEnumVerbs;
1662     DWORD dwRegister;
1663     static const WCHAR wszUnknown[] = {'U','n','k','n','o','w','n',0};
1664     static const WCHAR wszHostName[] = {'W','i','n','e',' ','T','e','s','t',' ','P','r','o','g','r','a','m',0};
1665     static const WCHAR wszDelim[] = {'!',0};
1666
1667     static const struct expected_method methods_embeddinghelper[] =
1668     {
1669         { "OleObject_QueryInterface", 0 },
1670         { "OleObject_AddRef", 0 },
1671         { "OleObject_QueryInterface", 0 },
1672         { "OleObject_QueryInterface", TEST_TODO },
1673         { "OleObject_QueryInterface", 0 },
1674         { "OleObject_QueryInterface", 0 },
1675         { "OleObject_QueryInterface", TEST_OPTIONAL }, /* Win95/98/NT4 */
1676         { "OleObject_Release", TEST_TODO },
1677         { "WINE_EXTRA", TEST_OPTIONAL },
1678         { NULL, 0 }
1679     };
1680
1681     hr = CoCreateInstance(&CLSID_WineTest, NULL, CLSCTX_INPROC_HANDLER, &IID_IOleObject, (void **)&pObject);
1682     ok(hr == REGDB_E_CLASSNOTREG, "CoCreateInstance should have failed with REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1683
1684     hr = OleCreateDefaultHandler(&CLSID_WineTest, NULL, &IID_IOleObject, (void **)&pObject);
1685     ok_ole_success(hr, "OleCreateDefaultHandler");
1686
1687     hr = IOleObject_QueryInterface(pObject, &IID_IOleInPlaceObject, (void **)&pInPlaceObj);
1688     ok(hr == E_NOINTERFACE, "IOleObject_QueryInterface(&IID_IOleInPlaceObject) should return E_NOINTERFACE instead of 0x%08x\n", hr);
1689
1690     hr = IOleObject_Advise(pObject, &AdviseSink, &dwAdvConn);
1691     ok_ole_success(hr, "IOleObject_Advise");
1692
1693     hr = IOleObject_Close(pObject, OLECLOSE_NOSAVE);
1694     ok_ole_success(hr, "IOleObject_Close");
1695
1696     /* FIXME: test IOleObject_EnumAdvise */
1697
1698     hr = IOleObject_EnumVerbs(pObject, &pEnumVerbs);
1699     ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_EnumVerbs should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1700
1701     hr = IOleObject_GetClientSite(pObject, &pClientSite);
1702     ok_ole_success(hr, "IOleObject_GetClientSite");
1703
1704     hr = IOleObject_GetClipboardData(pObject, 0, &pDataObject);
1705     ok(hr == OLE_E_NOTRUNNING,
1706        "IOleObject_GetClipboardData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n",
1707        hr);
1708
1709     hr = IOleObject_GetExtent(pObject, DVASPECT_CONTENT, &sizel);
1710     ok(hr == OLE_E_BLANK, "IOleObject_GetExtent should have returned OLE_E_BLANK instead of 0x%08x\n",
1711        hr);
1712
1713     hr = IOleObject_GetMiscStatus(pObject, DVASPECT_CONTENT, &dwStatus);
1714     ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_GetMiscStatus should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1715
1716     hr = IOleObject_GetUserClassID(pObject, &clsid);
1717     ok_ole_success(hr, "IOleObject_GetUserClassID");
1718     ok(IsEqualCLSID(&clsid, &CLSID_WineTest), "clsid != CLSID_WineTest\n");
1719
1720     hr = IOleObject_GetUserType(pObject, USERCLASSTYPE_FULL, &pszUserType);
1721     todo_wine {
1722     ok_ole_success(hr, "IOleObject_GetUserType");
1723     ok(!lstrcmpW(pszUserType, wszUnknown), "Retrieved user type was wrong\n");
1724     }
1725
1726     hr = IOleObject_InitFromData(pObject, NULL, TRUE, 0);
1727     ok(hr == OLE_E_NOTRUNNING, "IOleObject_InitFromData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1728
1729     hr = IOleObject_IsUpToDate(pObject);
1730     ok(hr == OLE_E_NOTRUNNING, "IOleObject_IsUpToDate should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1731
1732     palette.palNumEntries = 1;
1733     palette.palVersion = 2;
1734     memset(&palette.palPalEntry[0], 0, sizeof(palette.palPalEntry[0]));
1735     hr = IOleObject_SetColorScheme(pObject, &palette);
1736     ok(hr == OLE_E_NOTRUNNING, "IOleObject_SetColorScheme should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1737
1738     sizel.cx = sizel.cy = 0;
1739     hr = IOleObject_SetExtent(pObject, DVASPECT_CONTENT, &sizel);
1740     ok(hr == OLE_E_NOTRUNNING, "IOleObject_SetExtent should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1741
1742     hr = IOleObject_SetHostNames(pObject, wszHostName, NULL);
1743     ok_ole_success(hr, "IOleObject_SetHostNames");
1744
1745     hr = CreateItemMoniker(wszDelim, wszHostName, &pMoniker);
1746     ok_ole_success(hr, "CreateItemMoniker");
1747     hr = IOleObject_SetMoniker(pObject, OLEWHICHMK_CONTAINER, pMoniker);
1748     ok_ole_success(hr, "IOleObject_SetMoniker");
1749     IMoniker_Release(pMoniker);
1750
1751     hr = IOleObject_GetMoniker(pObject, OLEGETMONIKER_ONLYIFTHERE, OLEWHICHMK_CONTAINER, &pMoniker);
1752     ok(hr == E_FAIL, "IOleObject_GetMoniker should have returned E_FAIL instead of 0x%08x\n", hr);
1753
1754     hr = IOleObject_Update(pObject);
1755     todo_wine
1756     ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_Update should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1757
1758     hr = IOleObject_QueryInterface(pObject, &IID_IDataObject, (void **)&pDataObject);
1759     ok_ole_success(hr, "IOleObject_QueryInterface");
1760
1761     fmtetc.cfFormat = CF_TEXT;
1762     fmtetc.ptd = NULL;
1763     fmtetc.dwAspect = DVASPECT_CONTENT;
1764     fmtetc.lindex = -1;
1765     fmtetc.tymed = TYMED_NULL;
1766     hr = IDataObject_DAdvise(pDataObject, &fmtetc, 0, &AdviseSink, &dwAdvConn);
1767     ok_ole_success(hr, "IDataObject_DAdvise");
1768
1769     fmtetc.cfFormat = CF_ENHMETAFILE;
1770     fmtetc.ptd = NULL;
1771     fmtetc.dwAspect = DVASPECT_CONTENT;
1772     fmtetc.lindex = -1;
1773     fmtetc.tymed = TYMED_ENHMF;
1774     hr = IDataObject_DAdvise(pDataObject, &fmtetc, 0, &AdviseSink, &dwAdvConn);
1775     ok_ole_success(hr, "IDataObject_DAdvise");
1776
1777     fmtetc.cfFormat = CF_ENHMETAFILE;
1778     fmtetc.ptd = NULL;
1779     fmtetc.dwAspect = DVASPECT_CONTENT;
1780     fmtetc.lindex = -1;
1781     fmtetc.tymed = TYMED_ENHMF;
1782     hr = IDataObject_QueryGetData(pDataObject, &fmtetc);
1783     todo_wine
1784     ok(hr == OLE_E_NOTRUNNING, "IDataObject_QueryGetData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1785
1786     fmtetc.cfFormat = CF_TEXT;
1787     fmtetc.ptd = NULL;
1788     fmtetc.dwAspect = DVASPECT_CONTENT;
1789     fmtetc.lindex = -1;
1790     fmtetc.tymed = TYMED_NULL;
1791     hr = IDataObject_QueryGetData(pDataObject, &fmtetc);
1792     todo_wine
1793     ok(hr == OLE_E_NOTRUNNING, "IDataObject_QueryGetData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1794
1795     hr = IOleObject_QueryInterface(pObject, &IID_IRunnableObject, (void **)&pRunnableObject);
1796     ok_ole_success(hr, "IOleObject_QueryInterface");
1797
1798     hr = IRunnableObject_SetContainedObject(pRunnableObject, TRUE);
1799     ok_ole_success(hr, "IRunnableObject_SetContainedObject");
1800
1801     hr = IRunnableObject_Run(pRunnableObject, NULL);
1802     ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_Run should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1803
1804     hr = IOleObject_Close(pObject, OLECLOSE_NOSAVE);
1805     ok_ole_success(hr, "IOleObject_Close");
1806
1807     IRunnableObject_Release(pRunnableObject);
1808     IOleObject_Release(pObject);
1809
1810     /* Test failure propagation from delegate ::QueryInterface */
1811     hr = CoRegisterClassObject(&CLSID_WineTest, (IUnknown*)&OleObjectCF,
1812                                CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &dwRegister);
1813     ok_ole_success(hr, "CoRegisterClassObject");
1814     if(SUCCEEDED(hr))
1815     {
1816         expected_method_list = methods_embeddinghelper;
1817         hr = OleCreateEmbeddingHelper(&CLSID_WineTest, NULL, EMBDHLP_INPROC_SERVER,
1818                                       &OleObjectCF, &IID_IOleObject, (void**)&pObject);
1819         ok_ole_success(hr, "OleCreateEmbeddingHelper");
1820         if(SUCCEEDED(hr))
1821         {
1822             IUnknown *punk;
1823
1824             g_QIFailsWith = E_FAIL;
1825             hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1826             ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1827
1828             g_QIFailsWith = E_NOINTERFACE;
1829             hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1830             ok(hr == E_NOINTERFACE, "Got 0x%08x\n", hr);
1831
1832             g_QIFailsWith = CO_E_OBJNOTCONNECTED;
1833             hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1834             ok(hr == CO_E_OBJNOTCONNECTED, "Got 0x%08x\n", hr);
1835
1836             g_QIFailsWith = 0x87654321;
1837             hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1838             ok(hr == 0x87654321, "Got 0x%08x\n", hr);
1839
1840             IOleObject_Release(pObject);
1841         }
1842
1843         CHECK_NO_EXTRA_METHODS();
1844
1845         hr = CoRevokeClassObject(dwRegister);
1846         ok_ole_success(hr, "CoRevokeClassObject");
1847     }
1848 }
1849
1850 static void test_runnable(void)
1851 {
1852     static const struct expected_method methods_query_runnable[] =
1853     {
1854         { "OleObject_QueryInterface", 0 },
1855         { "OleObjectRunnable_AddRef", 0 },
1856         { "OleObjectRunnable_IsRunning", 0 },
1857         { "OleObjectRunnable_Release", 0 },
1858         { NULL, 0 }
1859     };
1860
1861     static const struct expected_method methods_no_runnable[] =
1862     {
1863         { "OleObject_QueryInterface", 0 },
1864         { NULL, 0 }
1865     };
1866
1867     BOOL ret;
1868     IOleObject *object = &OleObject;
1869
1870     /* null argument */
1871     ret = OleIsRunning(NULL);
1872     ok(ret == FALSE, "got %d\n", ret);
1873
1874     expected_method_list = methods_query_runnable;
1875     ret = OleIsRunning(object);
1876     ok(ret == TRUE, "Object should be running\n");
1877     CHECK_NO_EXTRA_METHODS();
1878
1879     g_isRunning = FALSE;
1880     expected_method_list = methods_query_runnable;
1881     ret = OleIsRunning(object);
1882     ok(ret == FALSE, "Object should not be running\n");
1883     CHECK_NO_EXTRA_METHODS();
1884
1885     g_showRunnable = FALSE;  /* QueryInterface(IID_IRunnableObject, ...) will fail */
1886     expected_method_list = methods_no_runnable;
1887     ret = OleIsRunning(object);
1888     ok(ret == TRUE, "Object without IRunnableObject should be running\n");
1889     CHECK_NO_EXTRA_METHODS();
1890
1891     g_isRunning = TRUE;
1892     g_showRunnable = TRUE;
1893 }
1894
1895 static HRESULT WINAPI Unknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
1896 {
1897     *ppv = NULL;
1898     if (IsEqualIID(riid, &IID_IUnknown)) *ppv = iface;
1899     if (*ppv)
1900     {
1901         IUnknown_AddRef((IUnknown *)*ppv);
1902         return S_OK;
1903     }
1904     return E_NOINTERFACE;
1905 }
1906
1907 static ULONG WINAPI Unknown_AddRef(IUnknown *iface)
1908 {
1909     return 2;
1910 }
1911
1912 static ULONG WINAPI Unknown_Release(IUnknown *iface)
1913 {
1914     return 1;
1915 }
1916
1917 static const IUnknownVtbl UnknownVtbl =
1918 {
1919     Unknown_QueryInterface,
1920     Unknown_AddRef,
1921     Unknown_Release
1922 };
1923
1924 static IUnknown unknown = { &UnknownVtbl };
1925
1926 static void test_OleLockRunning(void)
1927 {
1928     HRESULT hr;
1929
1930     hr = OleLockRunning((LPUNKNOWN)&unknown, TRUE, FALSE);
1931     ok(hr == S_OK, "OleLockRunning failed 0x%08x\n", hr);
1932 }
1933
1934 static void test_OleDraw(void)
1935 {
1936     HRESULT hr;
1937     RECT rect;
1938
1939     hr = OleDraw((IUnknown*)&viewobject, 0, (HDC)0x1, NULL);
1940     ok(hr == S_OK, "got 0x%08x\n", hr);
1941
1942     hr = OleDraw(NULL, 0, (HDC)0x1, NULL);
1943     ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
1944
1945     hr = OleDraw(NULL, 0, (HDC)0x1, &rect);
1946     ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
1947 }
1948
1949 START_TEST(ole2)
1950 {
1951     DWORD dwRegister;
1952     IStorage *pStorage;
1953     STATSTG statstg;
1954     HRESULT hr;
1955
1956     cf_test_1 = RegisterClipboardFormatA("cf_winetest_1");
1957     cf_test_2 = RegisterClipboardFormatA("cf_winetest_2");
1958     cf_test_3 = RegisterClipboardFormatA("cf_winetest_3");
1959
1960     CoInitialize(NULL);
1961
1962     hr = CoRegisterClassObject(&CLSID_Equation3, (IUnknown *)&OleObjectCF, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &dwRegister);
1963     ok_ole_success(hr, "CoRegisterClassObject");
1964
1965     hr = StgCreateDocfile(NULL, STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_DELETEONRELEASE, 0, &pStorage);
1966     ok_ole_success(hr, "StgCreateDocfile");
1967
1968     test_OleCreate(pStorage);
1969
1970     hr = IStorage_Stat(pStorage, &statstg, STATFLAG_NONAME);
1971     ok_ole_success(hr, "IStorage_Stat");
1972     ok(IsEqualCLSID(&CLSID_Equation3, &statstg.clsid), "Wrong CLSID in storage\n");
1973
1974     test_OleLoad(pStorage);
1975
1976     IStorage_Release(pStorage);
1977
1978     hr = CoRevokeClassObject(dwRegister);
1979     ok_ole_success(hr, "CoRevokeClassObject");
1980
1981     test_data_cache();
1982     test_default_handler();
1983     test_runnable();
1984     test_OleLockRunning();
1985     test_OleDraw();
1986
1987     CoUninitialize();
1988 }