vcomp: No-op stubs for _vcomp_single_begin, _vcomp_single_end.
[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 void test_OleCreate(IStorage *pStorage)
730 {
731     HRESULT hr;
732     IOleObject *pObject;
733     FORMATETC formatetc;
734     static const struct expected_method methods_olerender_none[] =
735     {
736         { "OleObject_QueryInterface", 0 },
737         { "OleObject_AddRef", 0 },
738         { "OleObject_QueryInterface", 0 },
739         { "OleObject_AddRef", TEST_OPTIONAL },
740         { "OleObject_Release", TEST_OPTIONAL },
741         { "OleObject_QueryInterface", TEST_OPTIONAL },
742         { "OleObjectPersistStg_AddRef", 0 },
743         { "OleObjectPersistStg_InitNew", 0 },
744         { "OleObjectPersistStg_Release", 0 },
745         { "OleObject_Release", 0 },
746         { "OleObject_Release", TEST_OPTIONAL },
747         { NULL, 0 }
748     };
749     static const struct expected_method methods_olerender_draw[] =
750     {
751         { "OleObject_QueryInterface", 0 },
752         { "OleObject_AddRef", 0 },
753         { "OleObject_QueryInterface", 0 },
754         { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
755         { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
756         { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
757         { "OleObjectPersistStg_AddRef", 0 },
758         { "OleObjectPersistStg_InitNew", 0 },
759         { "OleObjectPersistStg_Release", 0 },
760         { "OleObject_QueryInterface", 0 },
761         { "OleObjectRunnable_AddRef", 0 },
762         { "OleObjectRunnable_Run", 0 },
763         { "OleObjectRunnable_Release", 0 },
764         { "OleObject_QueryInterface", 0 },
765         { "OleObjectCache_AddRef", 0 },
766         { "OleObjectCache_Cache", 0 },
767         { "OleObjectCache_Release", 0 },
768         { "OleObject_Release", 0 },
769         { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
770         { NULL, 0 }
771     };
772     static const struct expected_method methods_olerender_format[] =
773     {
774         { "OleObject_QueryInterface", 0 },
775         { "OleObject_AddRef", 0 },
776         { "OleObject_QueryInterface", 0 },
777         { "OleObject_AddRef", 0 },
778         { "OleObject_GetMiscStatus", 0 },
779         { "OleObject_QueryInterface", 0 },
780         { "OleObjectPersistStg_AddRef", 0 },
781         { "OleObjectPersistStg_InitNew", 0 },
782         { "OleObjectPersistStg_Release", 0 },
783         { "OleObject_SetClientSite", 0 },
784         { "OleObject_Release", 0 },
785         { "OleObject_QueryInterface", 0 },
786         { "OleObjectRunnable_AddRef", 0 },
787         { "OleObjectRunnable_Run", 0 },
788         { "OleObjectRunnable_Release", 0 },
789         { "OleObject_QueryInterface", 0 },
790         { "OleObjectCache_AddRef", 0 },
791         { "OleObjectCache_Cache", 0 },
792         { "OleObjectCache_Release", 0 },
793         { "OleObject_Release", 0 },
794         { NULL, 0 }
795     };
796     static const struct expected_method methods_olerender_asis[] =
797     {
798         { "OleObject_QueryInterface", 0 },
799         { "OleObject_AddRef", 0 },
800         { "OleObject_QueryInterface", 0 },
801         { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
802         { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
803         { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
804         { "OleObjectPersistStg_AddRef", 0 },
805         { "OleObjectPersistStg_InitNew", 0 },
806         { "OleObjectPersistStg_Release", 0 },
807         { "OleObject_Release", 0 },
808         { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
809         { NULL, 0 }
810     };
811     static const struct expected_method methods_olerender_draw_no_runnable[] =
812     {
813         { "OleObject_QueryInterface", 0 },
814         { "OleObject_AddRef", 0 },
815         { "OleObject_QueryInterface", 0 },
816         { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
817         { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
818         { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
819         { "OleObjectPersistStg_AddRef", 0 },
820         { "OleObjectPersistStg_InitNew", 0 },
821         { "OleObjectPersistStg_Release", 0 },
822         { "OleObject_QueryInterface", 0 },
823         { "OleObject_QueryInterface", 0 },
824         { "OleObjectCache_AddRef", 0 },
825         { "OleObjectCache_Cache", 0 },
826         { "OleObjectCache_Release", 0 },
827         { "OleObject_Release", 0 },
828         { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
829         { NULL, 0 },
830     };
831     static const struct expected_method methods_olerender_draw_no_cache[] =
832     {
833         { "OleObject_QueryInterface", 0 },
834         { "OleObject_AddRef", 0 },
835         { "OleObject_QueryInterface", 0 },
836         { "OleObject_AddRef", TEST_OPTIONAL /* NT4 only */ },
837         { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
838         { "OleObject_QueryInterface", TEST_OPTIONAL /* NT4 only */ },
839         { "OleObjectPersistStg_AddRef", 0 },
840         { "OleObjectPersistStg_InitNew", 0 },
841         { "OleObjectPersistStg_Release", 0 },
842         { "OleObject_QueryInterface", 0 },
843         { "OleObjectRunnable_AddRef", 0 },
844         { "OleObjectRunnable_Run", 0 },
845         { "OleObjectRunnable_Release", 0 },
846         { "OleObject_QueryInterface", 0 },
847         { "OleObject_Release", 0 },
848         { "OleObject_Release", TEST_OPTIONAL /* NT4 only */ },
849         { NULL, 0 }
850     };
851
852     g_expected_fetc = &formatetc;
853     formatetc.cfFormat = 0;
854     formatetc.ptd = NULL;
855     formatetc.dwAspect = DVASPECT_CONTENT;
856     formatetc.lindex = -1;
857     formatetc.tymed = TYMED_NULL;
858     runnable = &OleObjectRunnable;
859     cache = &OleObjectCache;
860     expected_method_list = methods_olerender_none;
861     trace("OleCreate with OLERENDER_NONE:\n");
862     hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_NONE, NULL, NULL, pStorage, (void **)&pObject);
863     ok_ole_success(hr, "OleCreate");
864     IOleObject_Release(pObject);
865     CHECK_NO_EXTRA_METHODS();
866
867     expected_method_list = methods_olerender_draw;
868     trace("OleCreate with OLERENDER_DRAW:\n");
869     hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject);
870     ok_ole_success(hr, "OleCreate");
871     IOleObject_Release(pObject);
872     CHECK_NO_EXTRA_METHODS();
873
874     formatetc.cfFormat = CF_TEXT;
875     formatetc.ptd = NULL;
876     formatetc.dwAspect = DVASPECT_CONTENT;
877     formatetc.lindex = -1;
878     formatetc.tymed = TYMED_HGLOBAL;
879     expected_method_list = methods_olerender_format;
880     trace("OleCreate with OLERENDER_FORMAT:\n");
881     hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_FORMAT, &formatetc, (IOleClientSite *)0xdeadbeef, pStorage, (void **)&pObject);
882     ok(hr == S_OK ||
883        broken(hr == E_INVALIDARG), /* win2k */
884        "OleCreate failed with error 0x%08x\n", hr);
885     if (pObject)
886     {
887         IOleObject_Release(pObject);
888         CHECK_NO_EXTRA_METHODS();
889     }
890
891     expected_method_list = methods_olerender_asis;
892     trace("OleCreate with OLERENDER_ASIS:\n");
893     hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_ASIS, NULL, NULL, pStorage, (void **)&pObject);
894     ok_ole_success(hr, "OleCreate");
895     IOleObject_Release(pObject);
896     CHECK_NO_EXTRA_METHODS();
897
898     formatetc.cfFormat = 0;
899     formatetc.tymed = TYMED_NULL;
900     runnable = NULL;
901     expected_method_list = methods_olerender_draw_no_runnable;
902     trace("OleCreate with OLERENDER_DRAW (no IRunnableObject):\n");
903     hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject);
904     ok_ole_success(hr, "OleCreate");
905     IOleObject_Release(pObject);
906     CHECK_NO_EXTRA_METHODS();
907
908     runnable = &OleObjectRunnable;
909     cache = NULL;
910     expected_method_list = methods_olerender_draw_no_cache;
911     trace("OleCreate with OLERENDER_DRAW (no IOleCache):\n");
912     hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject);
913     ok_ole_success(hr, "OleCreate");
914     IOleObject_Release(pObject);
915     CHECK_NO_EXTRA_METHODS();
916     trace("end\n");
917     g_expected_fetc = NULL;
918 }
919
920 static void test_OleLoad(IStorage *pStorage)
921 {
922     HRESULT hr;
923     IOleObject *pObject;
924
925     static const struct expected_method methods_oleload[] =
926     {
927         { "OleObject_QueryInterface", 0 },
928         { "OleObject_AddRef", 0 },
929         { "OleObject_QueryInterface", 0 },
930         { "OleObject_AddRef", 0 },
931         { "OleObject_GetMiscStatus", 0 },
932         { "OleObject_QueryInterface", 0 },
933         { "OleObjectPersistStg_AddRef", 0 },
934         { "OleObjectPersistStg_Load", 0 },
935         { "OleObjectPersistStg_Release", 0 },
936         { "OleObject_SetClientSite", 0 },
937         { "OleObject_Release", 0 },
938         { "OleObject_QueryInterface", 0 },
939         { "OleObject_GetMiscStatus", 0 },
940         { "OleObject_Release", 0 },
941         { NULL, 0 }
942     };
943
944     /* Test once with IOleObject_GetMiscStatus failing */
945     expected_method_list = methods_oleload;
946     g_failGetMiscStatus = TRUE;
947     trace("OleLoad:\n");
948     hr = OleLoad(pStorage, &IID_IOleObject, (IOleClientSite *)0xdeadbeef, (void **)&pObject);
949     ok(hr == S_OK ||
950        broken(hr == E_INVALIDARG), /* win98 and win2k */
951        "OleLoad failed with error 0x%08x\n", hr);
952     if(pObject)
953     {
954         DWORD dwStatus = 0xdeadbeef;
955         hr = IOleObject_GetMiscStatus(pObject, DVASPECT_CONTENT, &dwStatus);
956         ok(hr == E_FAIL, "Got 0x%08x\n", hr);
957         ok(dwStatus == 0x1234, "Got 0x%08x\n", dwStatus);
958
959         IOleObject_Release(pObject);
960         CHECK_NO_EXTRA_METHODS();
961     }
962
963     /* Test again, let IOleObject_GetMiscStatus succeed. */
964     g_failGetMiscStatus = FALSE;
965     expected_method_list = methods_oleload;
966     trace("OleLoad:\n");
967     hr = OleLoad(pStorage, &IID_IOleObject, (IOleClientSite *)0xdeadbeef, (void **)&pObject);
968     ok(hr == S_OK ||
969        broken(hr == E_INVALIDARG), /* win98 and win2k */
970        "OleLoad failed with error 0x%08x\n", hr);
971     if (pObject)
972     {
973         DWORD dwStatus = 0xdeadbeef;
974         hr = IOleObject_GetMiscStatus(pObject, DVASPECT_CONTENT, &dwStatus);
975         ok(hr == S_OK, "Got 0x%08x\n", hr);
976         ok(dwStatus == 1, "Got 0x%08x\n", dwStatus);
977
978         IOleObject_Release(pObject);
979         CHECK_NO_EXTRA_METHODS();
980     }
981 }
982
983 static BOOL STDMETHODCALLTYPE draw_continue(ULONG_PTR param)
984 {
985     CHECK_EXPECTED_METHOD("draw_continue");
986     return TRUE;
987 }
988
989 static BOOL STDMETHODCALLTYPE draw_continue_false(ULONG_PTR param)
990 {
991     CHECK_EXPECTED_METHOD("draw_continue_false");
992     return FALSE;
993 }
994
995 static HRESULT WINAPI AdviseSink_QueryInterface(IAdviseSink *iface, REFIID riid, void **ppv)
996 {
997     if (IsEqualIID(riid, &IID_IAdviseSink) || IsEqualIID(riid, &IID_IUnknown))
998     {
999         *ppv = iface;
1000         IAdviseSink_AddRef(iface);
1001         return S_OK;
1002     }
1003     *ppv = NULL;
1004     return E_NOINTERFACE;
1005 }
1006
1007 static ULONG WINAPI AdviseSink_AddRef(IAdviseSink *iface)
1008 {
1009     return 2;
1010 }
1011
1012 static ULONG WINAPI AdviseSink_Release(IAdviseSink *iface)
1013 {
1014     return 1;
1015 }
1016
1017
1018 static void WINAPI AdviseSink_OnDataChange(
1019     IAdviseSink *iface,
1020     FORMATETC *pFormatetc,
1021     STGMEDIUM *pStgmed)
1022 {
1023     CHECK_EXPECTED_METHOD("AdviseSink_OnDataChange");
1024 }
1025
1026 static void WINAPI AdviseSink_OnViewChange(
1027     IAdviseSink *iface,
1028     DWORD dwAspect,
1029     LONG lindex)
1030 {
1031     CHECK_EXPECTED_METHOD("AdviseSink_OnViewChange");
1032 }
1033
1034 static void WINAPI AdviseSink_OnRename(
1035     IAdviseSink *iface,
1036     IMoniker *pmk)
1037 {
1038     CHECK_EXPECTED_METHOD("AdviseSink_OnRename");
1039 }
1040
1041 static void WINAPI AdviseSink_OnSave(IAdviseSink *iface)
1042 {
1043     CHECK_EXPECTED_METHOD("AdviseSink_OnSave");
1044 }
1045
1046 static void WINAPI AdviseSink_OnClose(IAdviseSink *iface)
1047 {
1048     CHECK_EXPECTED_METHOD("AdviseSink_OnClose");
1049 }
1050
1051 static const IAdviseSinkVtbl AdviseSinkVtbl =
1052 {
1053     AdviseSink_QueryInterface,
1054     AdviseSink_AddRef,
1055     AdviseSink_Release,
1056     AdviseSink_OnDataChange,
1057     AdviseSink_OnViewChange,
1058     AdviseSink_OnRename,
1059     AdviseSink_OnSave,
1060     AdviseSink_OnClose
1061 };
1062
1063 static IAdviseSink AdviseSink = { &AdviseSinkVtbl };
1064
1065 static HRESULT WINAPI DataObject_QueryInterface(
1066             IDataObject*     iface,
1067             REFIID           riid,
1068             void**           ppvObject)
1069 {
1070     CHECK_EXPECTED_METHOD("DataObject_QueryInterface");
1071
1072     if (IsEqualIID(riid, &IID_IDataObject) || IsEqualIID(riid, &IID_IUnknown))
1073     {
1074         *ppvObject = iface;
1075         return S_OK;
1076     }
1077     *ppvObject = NULL;
1078     return S_OK;
1079 }
1080
1081 static ULONG WINAPI DataObject_AddRef(
1082             IDataObject*     iface)
1083 {
1084     CHECK_EXPECTED_METHOD("DataObject_AddRef");
1085     return 2;
1086 }
1087
1088 static ULONG WINAPI DataObject_Release(
1089             IDataObject*     iface)
1090 {
1091     CHECK_EXPECTED_METHOD("DataObject_Release");
1092     return 1;
1093 }
1094
1095 static HRESULT WINAPI DataObject_GetData(
1096         IDataObject*     iface,
1097         LPFORMATETC      pformatetcIn,
1098         STGMEDIUM*       pmedium)
1099 {
1100     CHECK_EXPECTED_METHOD("DataObject_GetData");
1101     return E_NOTIMPL;
1102 }
1103
1104 static HRESULT WINAPI DataObject_GetDataHere(
1105         IDataObject*     iface,
1106         LPFORMATETC      pformatetc,
1107         STGMEDIUM*       pmedium)
1108 {
1109     CHECK_EXPECTED_METHOD("DataObject_GetDataHere");
1110     return E_NOTIMPL;
1111 }
1112
1113 static HRESULT WINAPI DataObject_QueryGetData(
1114         IDataObject*     iface,
1115         LPFORMATETC      pformatetc)
1116 {
1117     CHECK_EXPECTED_METHOD("DataObject_QueryGetData");
1118     return S_OK;
1119 }
1120
1121 static HRESULT WINAPI DataObject_GetCanonicalFormatEtc(
1122         IDataObject*     iface,
1123         LPFORMATETC      pformatectIn,
1124         LPFORMATETC      pformatetcOut)
1125 {
1126     CHECK_EXPECTED_METHOD("DataObject_GetCanonicalFormatEtc");
1127     return E_NOTIMPL;
1128 }
1129
1130 static HRESULT WINAPI DataObject_SetData(
1131         IDataObject*     iface,
1132         LPFORMATETC      pformatetc,
1133         STGMEDIUM*       pmedium,
1134         BOOL             fRelease)
1135 {
1136     CHECK_EXPECTED_METHOD("DataObject_SetData");
1137     return E_NOTIMPL;
1138 }
1139
1140 static HRESULT WINAPI DataObject_EnumFormatEtc(
1141         IDataObject*     iface,
1142         DWORD            dwDirection,
1143         IEnumFORMATETC** ppenumFormatEtc)
1144 {
1145     CHECK_EXPECTED_METHOD("DataObject_EnumFormatEtc");
1146     return E_NOTIMPL;
1147 }
1148
1149 static HRESULT WINAPI DataObject_DAdvise(
1150         IDataObject*     iface,
1151         FORMATETC*       pformatetc,
1152         DWORD            advf,
1153         IAdviseSink*     pAdvSink,
1154         DWORD*           pdwConnection)
1155 {
1156     STGMEDIUM stgmedium;
1157
1158     CHECK_EXPECTED_METHOD("DataObject_DAdvise");
1159     *pdwConnection = 1;
1160
1161     if(advf & ADVF_PRIMEFIRST)
1162     {
1163         ok(pformatetc->cfFormat == cf_test_2, "got %04x\n", pformatetc->cfFormat);
1164         stgmedium.tymed = TYMED_HGLOBAL;
1165         U(stgmedium).hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, 4);
1166         stgmedium.pUnkForRelease = NULL;
1167         IAdviseSink_OnDataChange(pAdvSink, pformatetc, &stgmedium);
1168     }
1169
1170     return S_OK;
1171 }
1172
1173 static HRESULT WINAPI DataObject_DUnadvise(
1174         IDataObject*     iface,
1175         DWORD            dwConnection)
1176 {
1177     CHECK_EXPECTED_METHOD("DataObject_DUnadvise");
1178     return S_OK;
1179 }
1180
1181 static HRESULT WINAPI DataObject_EnumDAdvise(
1182         IDataObject*     iface,
1183         IEnumSTATDATA**  ppenumAdvise)
1184 {
1185     CHECK_EXPECTED_METHOD("DataObject_EnumDAdvise");
1186     return OLE_E_ADVISENOTSUPPORTED;
1187 }
1188
1189 static IDataObjectVtbl DataObjectVtbl =
1190 {
1191     DataObject_QueryInterface,
1192     DataObject_AddRef,
1193     DataObject_Release,
1194     DataObject_GetData,
1195     DataObject_GetDataHere,
1196     DataObject_QueryGetData,
1197     DataObject_GetCanonicalFormatEtc,
1198     DataObject_SetData,
1199     DataObject_EnumFormatEtc,
1200     DataObject_DAdvise,
1201     DataObject_DUnadvise,
1202     DataObject_EnumDAdvise
1203 };
1204
1205 static IDataObject DataObject = { &DataObjectVtbl };
1206
1207 static void test_data_cache(void)
1208 {
1209     HRESULT hr;
1210     IOleCache2 *pOleCache;
1211     IStorage *pStorage;
1212     IPersistStorage *pPS;
1213     IViewObject *pViewObject;
1214     IOleCacheControl *pOleCacheControl;
1215     IDataObject *pCacheDataObject;
1216     FORMATETC fmtetc;
1217     STGMEDIUM stgmedium;
1218     DWORD dwConnection;
1219     DWORD dwFreeze;
1220     RECTL rcBounds;
1221     HDC hdcMem;
1222     CLSID clsid;
1223     char szSystemDir[MAX_PATH];
1224     WCHAR wszPath[MAX_PATH];
1225     static const WCHAR wszShell32[] = {'\\','s','h','e','l','l','3','2','.','d','l','l',0};
1226
1227     static const struct expected_method methods_cacheinitnew[] =
1228     {
1229         { "AdviseSink_OnViewChange", 0 },
1230         { "AdviseSink_OnViewChange", 0 },
1231         { "draw_continue", 1 },
1232         { "draw_continue_false", 1 },
1233         { "DataObject_DAdvise", 0 },
1234         { "DataObject_DAdvise", 0 },
1235         { "DataObject_DUnadvise", 0 },
1236         { "DataObject_DUnadvise", 0 },
1237         { NULL, 0 }
1238     };
1239     static const struct expected_method methods_cacheload[] =
1240     {
1241         { "AdviseSink_OnViewChange", 0 },
1242         { "draw_continue", 1 },
1243         { "draw_continue", 1 },
1244         { "draw_continue", 1 },
1245         { "DataObject_GetData", 0 },
1246         { "DataObject_GetData", 0 },
1247         { "DataObject_GetData", 0 },
1248         { NULL, 0 }
1249     };
1250     static const struct expected_method methods_cachethenrun[] =
1251     {
1252         { "DataObject_DAdvise", 0 },
1253         { "DataObject_DAdvise", 0 },
1254         { "DataObject_DAdvise", 0 },
1255         { "DataObject_QueryGetData", 1 }, /* called by win9x and nt4 */
1256         { "DataObject_DAdvise", 0 },
1257         { "DataObject_DUnadvise", 0 },
1258         { "DataObject_DUnadvise", 0 },
1259         { "DataObject_DUnadvise", 0 },
1260         { "DataObject_DUnadvise", 0 },
1261         { NULL, 0 }
1262     };
1263
1264     GetSystemDirectory(szSystemDir, sizeof(szSystemDir)/sizeof(szSystemDir[0]));
1265
1266     expected_method_list = methods_cacheinitnew;
1267
1268     fmtetc.cfFormat = CF_METAFILEPICT;
1269     fmtetc.dwAspect = DVASPECT_ICON;
1270     fmtetc.lindex = -1;
1271     fmtetc.ptd = NULL;
1272     fmtetc.tymed = TYMED_MFPICT;
1273
1274     hr = StgCreateDocfile(NULL, STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_DELETEONRELEASE, 0, &pStorage);
1275     ok_ole_success(hr, "StgCreateDocfile");
1276
1277     /* Test with new data */
1278
1279     hr = CreateDataCache(NULL, &CLSID_NULL, &IID_IOleCache2, (LPVOID *)&pOleCache);
1280     ok_ole_success(hr, "CreateDataCache");
1281
1282     hr = IOleCache2_QueryInterface(pOleCache, &IID_IPersistStorage, (LPVOID *)&pPS);
1283     ok_ole_success(hr, "IOleCache_QueryInterface(IID_IPersistStorage)");
1284     hr = IOleCache2_QueryInterface(pOleCache, &IID_IViewObject, (LPVOID *)&pViewObject);
1285     ok_ole_success(hr, "IOleCache_QueryInterface(IID_IViewObject)");
1286     hr = IOleCache2_QueryInterface(pOleCache, &IID_IOleCacheControl, (LPVOID *)&pOleCacheControl);
1287     ok_ole_success(hr, "IOleCache_QueryInterface(IID_IOleCacheControl)");
1288
1289     hr = IViewObject_SetAdvise(pViewObject, DVASPECT_ICON, ADVF_PRIMEFIRST, &AdviseSink);
1290     ok_ole_success(hr, "IViewObject_SetAdvise");
1291
1292     hr = IPersistStorage_InitNew(pPS, pStorage);
1293     ok_ole_success(hr, "IPersistStorage_InitNew");
1294
1295     hr = IPersistStorage_IsDirty(pPS);
1296     ok_ole_success(hr, "IPersistStorage_IsDirty");
1297
1298     hr = IPersistStorage_GetClassID(pPS, &clsid);
1299     ok_ole_success(hr, "IPersistStorage_GetClassID");
1300     ok(IsEqualCLSID(&clsid, &IID_NULL), "clsid should be blank\n");
1301
1302     hr = IOleCache2_Uncache(pOleCache, 0xdeadbeef);
1303     ok(hr == OLE_E_NOCONNECTION, "IOleCache_Uncache with invalid value should return OLE_E_NOCONNECTION instead of 0x%x\n", hr);
1304
1305     /* Both tests crash on NT4 and below. StgCreatePropSetStg is only available on w2k and above. */
1306     if (GetProcAddress(GetModuleHandleA("ole32.dll"), "StgCreatePropSetStg"))
1307     {
1308         hr = IOleCache2_Cache(pOleCache, NULL, 0, &dwConnection);
1309         ok(hr == E_INVALIDARG, "IOleCache_Cache with NULL fmtetc should have returned E_INVALIDARG instead of 0x%08x\n", hr);
1310
1311         hr = IOleCache2_Cache(pOleCache, NULL, 0, NULL);
1312         ok(hr == E_INVALIDARG, "IOleCache_Cache with NULL pdwConnection should have returned E_INVALIDARG instead of 0x%08x\n", hr);
1313     }
1314     else
1315     {
1316         skip("tests with NULL parameters will crash on NT4 and below\n");
1317     }
1318
1319     for (fmtetc.cfFormat = CF_TEXT; fmtetc.cfFormat < CF_MAX; fmtetc.cfFormat++)
1320     {
1321         int i;
1322         fmtetc.dwAspect = DVASPECT_THUMBNAIL;
1323         for (i = 0; i < 7; i++)
1324         {
1325             fmtetc.tymed = 1 << i;
1326             hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1327             if ((fmtetc.cfFormat == CF_METAFILEPICT && fmtetc.tymed == TYMED_MFPICT) ||
1328                 (fmtetc.cfFormat == CF_BITMAP && fmtetc.tymed == TYMED_GDI) ||
1329                 (fmtetc.cfFormat == CF_DIB && fmtetc.tymed == TYMED_HGLOBAL) ||
1330                 (fmtetc.cfFormat == CF_ENHMETAFILE && fmtetc.tymed == TYMED_ENHMF))
1331                 ok(hr == S_OK, "IOleCache_Cache cfFormat = %d, tymed = %d should have returned S_OK instead of 0x%08x\n",
1332                     fmtetc.cfFormat, fmtetc.tymed, hr);
1333             else if (fmtetc.tymed == TYMED_HGLOBAL)
1334                 ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED ||
1335                    broken(hr == S_OK && fmtetc.cfFormat == CF_BITMAP) /* Win9x & NT4 */,
1336                     "IOleCache_Cache cfFormat = %d, tymed = %d should have returned CACHE_S_FORMATETC_NOTSUPPORTED instead of 0x%08x\n",
1337                     fmtetc.cfFormat, fmtetc.tymed, hr);
1338             else
1339                 ok(hr == DV_E_TYMED, "IOleCache_Cache cfFormat = %d, tymed = %d should have returned DV_E_TYMED instead of 0x%08x\n",
1340                     fmtetc.cfFormat, fmtetc.tymed, hr);
1341             if (SUCCEEDED(hr))
1342             {
1343                 hr = IOleCache2_Uncache(pOleCache, dwConnection);
1344                 ok_ole_success(hr, "IOleCache_Uncache");
1345             }
1346         }
1347     }
1348
1349     fmtetc.cfFormat = CF_BITMAP;
1350     fmtetc.dwAspect = DVASPECT_THUMBNAIL;
1351     fmtetc.tymed = TYMED_GDI;
1352     hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1353     ok_ole_success(hr, "IOleCache_Cache");
1354
1355     fmtetc.cfFormat = 0;
1356     fmtetc.dwAspect = DVASPECT_ICON;
1357     fmtetc.tymed = TYMED_MFPICT;
1358     hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1359     ok_ole_success(hr, "IOleCache_Cache");
1360
1361     MultiByteToWideChar(CP_ACP, 0, szSystemDir, -1, wszPath, sizeof(wszPath)/sizeof(wszPath[0]));
1362     memcpy(wszPath+lstrlenW(wszPath), wszShell32, sizeof(wszShell32));
1363
1364     fmtetc.cfFormat = CF_METAFILEPICT;
1365     stgmedium.tymed = TYMED_MFPICT;
1366     U(stgmedium).hMetaFilePict = OleMetafilePictFromIconAndLabel(
1367         LoadIcon(NULL, IDI_APPLICATION), wszPath, wszPath, 0);
1368     stgmedium.pUnkForRelease = NULL;
1369
1370     fmtetc.dwAspect = DVASPECT_CONTENT;
1371     hr = IOleCache2_SetData(pOleCache, &fmtetc, &stgmedium, FALSE);
1372     ok(hr == OLE_E_BLANK, "IOleCache_SetData for aspect not in cache should have return OLE_E_BLANK instead of 0x%08x\n", hr);
1373
1374     fmtetc.dwAspect = DVASPECT_ICON;
1375     hr = IOleCache2_SetData(pOleCache, &fmtetc, &stgmedium, FALSE);
1376     ok_ole_success(hr, "IOleCache_SetData");
1377     ReleaseStgMedium(&stgmedium);
1378
1379     hr = IViewObject_Freeze(pViewObject, DVASPECT_ICON, -1, NULL, &dwFreeze);
1380     todo_wine {
1381     ok_ole_success(hr, "IViewObject_Freeze");
1382     hr = IViewObject_Freeze(pViewObject, DVASPECT_CONTENT, -1, NULL, &dwFreeze);
1383     ok(hr == OLE_E_BLANK, "IViewObject_Freeze with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1384     }
1385
1386     rcBounds.left = 0;
1387     rcBounds.top = 0;
1388     rcBounds.right = 100;
1389     rcBounds.bottom = 100;
1390     hdcMem = CreateCompatibleDC(NULL);
1391
1392     hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1393     ok_ole_success(hr, "IViewObject_Draw");
1394
1395     hr = IViewObject_Draw(pViewObject, DVASPECT_CONTENT, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1396     ok(hr == OLE_E_BLANK, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1397
1398     /* a NULL draw_continue fn ptr */
1399     hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, NULL, 0xdeadbeef);
1400     ok_ole_success(hr, "IViewObject_Draw");
1401
1402     /* draw_continue that returns FALSE to abort drawing */
1403     hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue_false, 0xdeadbeef);
1404     ok(hr == E_ABORT ||
1405        broken(hr == S_OK), /* win9x may skip the callbacks */
1406        "IViewObject_Draw with draw_continue_false returns 0x%08x\n", hr);
1407
1408     DeleteDC(hdcMem);
1409
1410     hr = IOleCacheControl_OnRun(pOleCacheControl, &DataObject);
1411     ok_ole_success(hr, "IOleCacheControl_OnRun");
1412
1413     hr = IPersistStorage_Save(pPS, pStorage, TRUE);
1414     ok_ole_success(hr, "IPersistStorage_Save");
1415
1416     hr = IPersistStorage_SaveCompleted(pPS, NULL);
1417     ok_ole_success(hr, "IPersistStorage_SaveCompleted");
1418
1419     hr = IPersistStorage_IsDirty(pPS);
1420     ok(hr == S_FALSE, "IPersistStorage_IsDirty should have returned S_FALSE instead of 0x%x\n", hr);
1421
1422     IPersistStorage_Release(pPS);
1423     IViewObject_Release(pViewObject);
1424     IOleCache2_Release(pOleCache);
1425     IOleCacheControl_Release(pOleCacheControl);
1426
1427     CHECK_NO_EXTRA_METHODS();
1428
1429     /* Test with loaded data */
1430     trace("Testing loaded data with CreateDataCache:\n");
1431     expected_method_list = methods_cacheload;
1432
1433     hr = CreateDataCache(NULL, &CLSID_NULL, &IID_IOleCache2, (LPVOID *)&pOleCache);
1434     ok_ole_success(hr, "CreateDataCache");
1435
1436     hr = IOleCache2_QueryInterface(pOleCache, &IID_IPersistStorage, (LPVOID *)&pPS);
1437     ok_ole_success(hr, "IOleCache_QueryInterface(IID_IPersistStorage)");
1438     hr = IOleCache2_QueryInterface(pOleCache, &IID_IViewObject, (LPVOID *)&pViewObject);
1439     ok_ole_success(hr, "IOleCache_QueryInterface(IID_IViewObject)");
1440
1441     hr = IViewObject_SetAdvise(pViewObject, DVASPECT_ICON, ADVF_PRIMEFIRST, &AdviseSink);
1442     ok_ole_success(hr, "IViewObject_SetAdvise");
1443
1444     hr = IPersistStorage_Load(pPS, pStorage);
1445     ok_ole_success(hr, "IPersistStorage_Load");
1446
1447     hr = IPersistStorage_IsDirty(pPS);
1448     ok(hr == S_FALSE, "IPersistStorage_IsDirty should have returned S_FALSE instead of 0x%x\n", hr);
1449
1450     fmtetc.cfFormat = 0;
1451     fmtetc.dwAspect = DVASPECT_ICON;
1452     fmtetc.lindex = -1;
1453     fmtetc.ptd = NULL;
1454     fmtetc.tymed = TYMED_MFPICT;
1455     hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1456     ok(hr == CACHE_S_SAMECACHE, "IOleCache_Cache with already loaded data format type should return CACHE_S_SAMECACHE instead of 0x%x\n", hr);
1457
1458     rcBounds.left = 0;
1459     rcBounds.top = 0;
1460     rcBounds.right = 100;
1461     rcBounds.bottom = 100;
1462     hdcMem = CreateCompatibleDC(NULL);
1463
1464     hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1465     ok_ole_success(hr, "IViewObject_Draw");
1466
1467     hr = IViewObject_Draw(pViewObject, DVASPECT_CONTENT, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1468     ok(hr == OLE_E_BLANK, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1469
1470     /* unload the cached storage object, causing it to be reloaded */
1471     hr = IOleCache2_DiscardCache(pOleCache, DISCARDCACHE_NOSAVE);
1472     ok_ole_success(hr, "IOleCache2_DiscardCache");
1473     hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1474     ok_ole_success(hr, "IViewObject_Draw");
1475
1476     /* unload the cached storage object, but don't allow it to be reloaded */
1477     hr = IPersistStorage_HandsOffStorage(pPS);
1478     ok_ole_success(hr, "IPersistStorage_HandsOffStorage");
1479     hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1480     ok_ole_success(hr, "IViewObject_Draw");
1481     hr = IOleCache2_DiscardCache(pOleCache, DISCARDCACHE_NOSAVE);
1482     ok_ole_success(hr, "IOleCache2_DiscardCache");
1483     hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1484     ok(hr == OLE_E_BLANK, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1485
1486     DeleteDC(hdcMem);
1487
1488     todo_wine {
1489     hr = IOleCache2_InitCache(pOleCache, &DataObject);
1490     ok(hr == CACHE_E_NOCACHE_UPDATED, "IOleCache_InitCache should have returned CACHE_E_NOCACHE_UPDATED instead of 0x%08x\n", hr);
1491     }
1492
1493     IPersistStorage_Release(pPS);
1494     IViewObject_Release(pViewObject);
1495     IOleCache2_Release(pOleCache);
1496
1497     todo_wine {
1498     CHECK_NO_EXTRA_METHODS();
1499     }
1500
1501     hr = CreateDataCache(NULL, &CLSID_NULL, &IID_IOleCache2, (LPVOID *)&pOleCache);
1502     ok_ole_success(hr, "CreateDataCache");
1503
1504     expected_method_list = methods_cachethenrun;
1505
1506     hr = IOleCache2_QueryInterface(pOleCache, &IID_IDataObject, (LPVOID *)&pCacheDataObject);
1507     ok_ole_success(hr, "IOleCache_QueryInterface(IID_IDataObject)");
1508     hr = IOleCache2_QueryInterface(pOleCache, &IID_IOleCacheControl, (LPVOID *)&pOleCacheControl);
1509     ok_ole_success(hr, "IOleCache_QueryInterface(IID_IOleCacheControl)");
1510
1511     fmtetc.cfFormat = CF_METAFILEPICT;
1512     fmtetc.dwAspect = DVASPECT_CONTENT;
1513     fmtetc.tymed = TYMED_MFPICT;
1514
1515     hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1516     ok_ole_success(hr, "IOleCache_Cache");
1517
1518     hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1519     ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1520
1521     fmtetc.cfFormat = cf_test_1;
1522     fmtetc.dwAspect = DVASPECT_CONTENT;
1523     fmtetc.tymed = TYMED_HGLOBAL;
1524
1525     hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1526     ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED, "got %08x\n", hr);
1527
1528     hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1529     ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1530
1531     fmtetc.cfFormat = cf_test_2;
1532     hr = IOleCache2_Cache(pOleCache, &fmtetc, ADVF_PRIMEFIRST, &dwConnection);
1533     ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED, "got %08x\n", hr);
1534
1535     hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1536     ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1537
1538     hr = IOleCacheControl_OnRun(pOleCacheControl, &DataObject);
1539     ok_ole_success(hr, "IOleCacheControl_OnRun");
1540
1541     fmtetc.cfFormat = cf_test_3;
1542     hr = IOleCache2_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1543     ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED, "got %08x\n", hr);
1544
1545     fmtetc.cfFormat = cf_test_1;
1546     hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1547     ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1548
1549     fmtetc.cfFormat = cf_test_2;
1550     hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1551     ok(hr == S_OK, "got %08x\n", hr);
1552     ReleaseStgMedium(&stgmedium);
1553
1554     fmtetc.cfFormat = cf_test_3;
1555     hr = IDataObject_GetData(pCacheDataObject, &fmtetc, &stgmedium);
1556     ok(hr == OLE_E_BLANK, "got %08x\n", hr);
1557
1558     IOleCacheControl_Release(pOleCacheControl);
1559     IDataObject_Release(pCacheDataObject);
1560     IOleCache2_Release(pOleCache);
1561
1562     CHECK_NO_EXTRA_METHODS();
1563
1564     IStorage_Release(pStorage);
1565 }
1566
1567 static void test_default_handler(void)
1568 {
1569     HRESULT hr;
1570     IOleObject *pObject;
1571     IRunnableObject *pRunnableObject;
1572     IOleClientSite *pClientSite;
1573     IDataObject *pDataObject;
1574     SIZEL sizel;
1575     DWORD dwStatus;
1576     CLSID clsid;
1577     LPOLESTR pszUserType;
1578     LOGPALETTE palette;
1579     DWORD dwAdvConn;
1580     IMoniker *pMoniker;
1581     FORMATETC fmtetc;
1582     IOleInPlaceObject *pInPlaceObj;
1583     IEnumOLEVERB *pEnumVerbs;
1584     DWORD dwRegister;
1585     static const WCHAR wszUnknown[] = {'U','n','k','n','o','w','n',0};
1586     static const WCHAR wszHostName[] = {'W','i','n','e',' ','T','e','s','t',' ','P','r','o','g','r','a','m',0};
1587     static const WCHAR wszDelim[] = {'!',0};
1588
1589     static const struct expected_method methods_embeddinghelper[] =
1590     {
1591         { "OleObject_QueryInterface", 0 },
1592         { "OleObject_AddRef", 0 },
1593         { "OleObject_QueryInterface", 0 },
1594         { "OleObject_QueryInterface", TEST_TODO },
1595         { "OleObject_QueryInterface", 0 },
1596         { "OleObject_QueryInterface", 0 },
1597         { "OleObject_QueryInterface", TEST_OPTIONAL }, /* Win95/98/NT4 */
1598         { "OleObject_Release", TEST_TODO },
1599         { "WINE_EXTRA", TEST_OPTIONAL },
1600         { NULL, 0 }
1601     };
1602
1603     hr = CoCreateInstance(&CLSID_WineTest, NULL, CLSCTX_INPROC_HANDLER, &IID_IOleObject, (void **)&pObject);
1604     ok(hr == REGDB_E_CLASSNOTREG, "CoCreateInstance should have failed with REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1605
1606     hr = OleCreateDefaultHandler(&CLSID_WineTest, NULL, &IID_IOleObject, (void **)&pObject);
1607     ok_ole_success(hr, "OleCreateDefaultHandler");
1608
1609     hr = IOleObject_QueryInterface(pObject, &IID_IOleInPlaceObject, (void **)&pInPlaceObj);
1610     ok(hr == E_NOINTERFACE, "IOleObject_QueryInterface(&IID_IOleInPlaceObject) should return E_NOINTERFACE instead of 0x%08x\n", hr);
1611
1612     hr = IOleObject_Advise(pObject, &AdviseSink, &dwAdvConn);
1613     ok_ole_success(hr, "IOleObject_Advise");
1614
1615     hr = IOleObject_Close(pObject, OLECLOSE_NOSAVE);
1616     ok_ole_success(hr, "IOleObject_Close");
1617
1618     /* FIXME: test IOleObject_EnumAdvise */
1619
1620     hr = IOleObject_EnumVerbs(pObject, &pEnumVerbs);
1621     ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_EnumVerbs should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1622
1623     hr = IOleObject_GetClientSite(pObject, &pClientSite);
1624     ok_ole_success(hr, "IOleObject_GetClientSite");
1625
1626     hr = IOleObject_GetClipboardData(pObject, 0, &pDataObject);
1627     ok(hr == OLE_E_NOTRUNNING,
1628        "IOleObject_GetClipboardData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n",
1629        hr);
1630
1631     hr = IOleObject_GetExtent(pObject, DVASPECT_CONTENT, &sizel);
1632     ok(hr == OLE_E_BLANK, "IOleObject_GetExtent should have returned OLE_E_BLANK instead of 0x%08x\n",
1633        hr);
1634
1635     hr = IOleObject_GetMiscStatus(pObject, DVASPECT_CONTENT, &dwStatus);
1636     ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_GetMiscStatus should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1637
1638     hr = IOleObject_GetUserClassID(pObject, &clsid);
1639     ok_ole_success(hr, "IOleObject_GetUserClassID");
1640     ok(IsEqualCLSID(&clsid, &CLSID_WineTest), "clsid != CLSID_WineTest\n");
1641
1642     hr = IOleObject_GetUserType(pObject, USERCLASSTYPE_FULL, &pszUserType);
1643     todo_wine {
1644     ok_ole_success(hr, "IOleObject_GetUserType");
1645     ok(!lstrcmpW(pszUserType, wszUnknown), "Retrieved user type was wrong\n");
1646     }
1647
1648     hr = IOleObject_InitFromData(pObject, NULL, TRUE, 0);
1649     ok(hr == OLE_E_NOTRUNNING, "IOleObject_InitFromData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1650
1651     hr = IOleObject_IsUpToDate(pObject);
1652     ok(hr == OLE_E_NOTRUNNING, "IOleObject_IsUpToDate should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1653
1654     palette.palNumEntries = 1;
1655     palette.palVersion = 2;
1656     memset(&palette.palPalEntry[0], 0, sizeof(palette.palPalEntry[0]));
1657     hr = IOleObject_SetColorScheme(pObject, &palette);
1658     ok(hr == OLE_E_NOTRUNNING, "IOleObject_SetColorScheme should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1659
1660     sizel.cx = sizel.cy = 0;
1661     hr = IOleObject_SetExtent(pObject, DVASPECT_CONTENT, &sizel);
1662     ok(hr == OLE_E_NOTRUNNING, "IOleObject_SetExtent should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1663
1664     hr = IOleObject_SetHostNames(pObject, wszHostName, NULL);
1665     ok_ole_success(hr, "IOleObject_SetHostNames");
1666
1667     hr = CreateItemMoniker(wszDelim, wszHostName, &pMoniker);
1668     ok_ole_success(hr, "CreateItemMoniker");
1669     hr = IOleObject_SetMoniker(pObject, OLEWHICHMK_CONTAINER, pMoniker);
1670     ok_ole_success(hr, "IOleObject_SetMoniker");
1671     IMoniker_Release(pMoniker);
1672
1673     hr = IOleObject_GetMoniker(pObject, OLEGETMONIKER_ONLYIFTHERE, OLEWHICHMK_CONTAINER, &pMoniker);
1674     ok(hr == E_FAIL, "IOleObject_GetMoniker should have returned E_FAIL instead of 0x%08x\n", hr);
1675
1676     hr = IOleObject_Update(pObject);
1677     todo_wine
1678     ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_Update should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1679
1680     hr = IOleObject_QueryInterface(pObject, &IID_IDataObject, (void **)&pDataObject);
1681     ok_ole_success(hr, "IOleObject_QueryInterface");
1682
1683     fmtetc.cfFormat = CF_TEXT;
1684     fmtetc.ptd = NULL;
1685     fmtetc.dwAspect = DVASPECT_CONTENT;
1686     fmtetc.lindex = -1;
1687     fmtetc.tymed = TYMED_NULL;
1688     hr = IDataObject_DAdvise(pDataObject, &fmtetc, 0, &AdviseSink, &dwAdvConn);
1689     ok_ole_success(hr, "IDataObject_DAdvise");
1690
1691     fmtetc.cfFormat = CF_ENHMETAFILE;
1692     fmtetc.ptd = NULL;
1693     fmtetc.dwAspect = DVASPECT_CONTENT;
1694     fmtetc.lindex = -1;
1695     fmtetc.tymed = TYMED_ENHMF;
1696     hr = IDataObject_DAdvise(pDataObject, &fmtetc, 0, &AdviseSink, &dwAdvConn);
1697     ok_ole_success(hr, "IDataObject_DAdvise");
1698
1699     fmtetc.cfFormat = CF_ENHMETAFILE;
1700     fmtetc.ptd = NULL;
1701     fmtetc.dwAspect = DVASPECT_CONTENT;
1702     fmtetc.lindex = -1;
1703     fmtetc.tymed = TYMED_ENHMF;
1704     hr = IDataObject_QueryGetData(pDataObject, &fmtetc);
1705     todo_wine
1706     ok(hr == OLE_E_NOTRUNNING, "IDataObject_QueryGetData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1707
1708     fmtetc.cfFormat = CF_TEXT;
1709     fmtetc.ptd = NULL;
1710     fmtetc.dwAspect = DVASPECT_CONTENT;
1711     fmtetc.lindex = -1;
1712     fmtetc.tymed = TYMED_NULL;
1713     hr = IDataObject_QueryGetData(pDataObject, &fmtetc);
1714     todo_wine
1715     ok(hr == OLE_E_NOTRUNNING, "IDataObject_QueryGetData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1716
1717     hr = IOleObject_QueryInterface(pObject, &IID_IRunnableObject, (void **)&pRunnableObject);
1718     ok_ole_success(hr, "IOleObject_QueryInterface");
1719
1720     hr = IRunnableObject_SetContainedObject(pRunnableObject, TRUE);
1721     ok_ole_success(hr, "IRunnableObject_SetContainedObject");
1722
1723     hr = IRunnableObject_Run(pRunnableObject, NULL);
1724     ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_Run should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1725
1726     hr = IOleObject_Close(pObject, OLECLOSE_NOSAVE);
1727     ok_ole_success(hr, "IOleObject_Close");
1728
1729     IRunnableObject_Release(pRunnableObject);
1730     IOleObject_Release(pObject);
1731
1732     /* Test failure propagation from delegate ::QueryInterface */
1733     hr = CoRegisterClassObject(&CLSID_WineTest, (IUnknown*)&OleObjectCF,
1734                                CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &dwRegister);
1735     ok_ole_success(hr, "CoRegisterClassObject");
1736     if(SUCCEEDED(hr))
1737     {
1738         expected_method_list = methods_embeddinghelper;
1739         hr = OleCreateEmbeddingHelper(&CLSID_WineTest, NULL, EMBDHLP_INPROC_SERVER,
1740                                       &OleObjectCF, &IID_IOleObject, (void**)&pObject);
1741         ok_ole_success(hr, "OleCreateEmbeddingHelper");
1742         if(SUCCEEDED(hr))
1743         {
1744             IUnknown *punk;
1745
1746             g_QIFailsWith = E_FAIL;
1747             hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1748             ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1749
1750             g_QIFailsWith = E_NOINTERFACE;
1751             hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1752             ok(hr == E_NOINTERFACE, "Got 0x%08x\n", hr);
1753
1754             g_QIFailsWith = CO_E_OBJNOTCONNECTED;
1755             hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1756             ok(hr == CO_E_OBJNOTCONNECTED, "Got 0x%08x\n", hr);
1757
1758             g_QIFailsWith = 0x87654321;
1759             hr = IOleObject_QueryInterface(pObject, &IID_WineTest, (void**)&punk);
1760             ok(hr == 0x87654321, "Got 0x%08x\n", hr);
1761
1762             IOleObject_Release(pObject);
1763         }
1764
1765         CHECK_NO_EXTRA_METHODS();
1766
1767         hr = CoRevokeClassObject(dwRegister);
1768         ok_ole_success(hr, "CoRevokeClassObject");
1769     }
1770 }
1771
1772 static void test_runnable(void)
1773 {
1774     static const struct expected_method methods_query_runnable[] =
1775     {
1776         { "OleObject_QueryInterface", 0 },
1777         { "OleObjectRunnable_AddRef", 0 },
1778         { "OleObjectRunnable_IsRunning", 0 },
1779         { "OleObjectRunnable_Release", 0 },
1780         { NULL, 0 }
1781     };
1782
1783     static const struct expected_method methods_no_runnable[] =
1784     {
1785         { "OleObject_QueryInterface", 0 },
1786         { NULL, 0 }
1787     };
1788
1789     BOOL ret;
1790     IOleObject *object = &OleObject;
1791
1792     /* null argument */
1793     ret = OleIsRunning(NULL);
1794     ok(ret == FALSE, "got %d\n", ret);
1795
1796     expected_method_list = methods_query_runnable;
1797     ret = OleIsRunning(object);
1798     ok(ret == TRUE, "Object should be running\n");
1799     CHECK_NO_EXTRA_METHODS();
1800
1801     g_isRunning = FALSE;
1802     expected_method_list = methods_query_runnable;
1803     ret = OleIsRunning(object);
1804     ok(ret == FALSE, "Object should not be running\n");
1805     CHECK_NO_EXTRA_METHODS();
1806
1807     g_showRunnable = FALSE;  /* QueryInterface(IID_IRunnableObject, ...) will fail */
1808     expected_method_list = methods_no_runnable;
1809     ret = OleIsRunning(object);
1810     ok(ret == TRUE, "Object without IRunnableObject should be running\n");
1811     CHECK_NO_EXTRA_METHODS();
1812
1813     g_isRunning = TRUE;
1814     g_showRunnable = TRUE;
1815 }
1816
1817 static HRESULT WINAPI Unknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
1818 {
1819     *ppv = NULL;
1820     if (IsEqualIID(riid, &IID_IUnknown)) *ppv = iface;
1821     if (*ppv)
1822     {
1823         IUnknown_AddRef((IUnknown *)*ppv);
1824         return S_OK;
1825     }
1826     return E_NOINTERFACE;
1827 }
1828
1829 static ULONG WINAPI Unknown_AddRef(IUnknown *iface)
1830 {
1831     return 2;
1832 }
1833
1834 static ULONG WINAPI Unknown_Release(IUnknown *iface)
1835 {
1836     return 1;
1837 }
1838
1839 static const IUnknownVtbl UnknownVtbl =
1840 {
1841     Unknown_QueryInterface,
1842     Unknown_AddRef,
1843     Unknown_Release
1844 };
1845
1846 static IUnknown unknown = { &UnknownVtbl };
1847
1848 static void test_OleLockRunning(void)
1849 {
1850     HRESULT hr;
1851
1852     hr = OleLockRunning((LPUNKNOWN)&unknown, TRUE, FALSE);
1853     ok(hr == S_OK, "OleLockRunning failed 0x%08x\n", hr);
1854 }
1855
1856 START_TEST(ole2)
1857 {
1858     DWORD dwRegister;
1859     IStorage *pStorage;
1860     STATSTG statstg;
1861     HRESULT hr;
1862
1863     cf_test_1 = RegisterClipboardFormatA("cf_winetest_1");
1864     cf_test_2 = RegisterClipboardFormatA("cf_winetest_2");
1865     cf_test_3 = RegisterClipboardFormatA("cf_winetest_3");
1866
1867     CoInitialize(NULL);
1868
1869     hr = CoRegisterClassObject(&CLSID_Equation3, (IUnknown *)&OleObjectCF, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &dwRegister);
1870     ok_ole_success(hr, "CoRegisterClassObject");
1871
1872     hr = StgCreateDocfile(NULL, STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_DELETEONRELEASE, 0, &pStorage);
1873     ok_ole_success(hr, "StgCreateDocfile");
1874
1875     test_OleCreate(pStorage);
1876
1877     hr = IStorage_Stat(pStorage, &statstg, STATFLAG_NONAME);
1878     ok_ole_success(hr, "IStorage_Stat");
1879     ok(IsEqualCLSID(&CLSID_Equation3, &statstg.clsid), "Wrong CLSID in storage\n");
1880
1881     test_OleLoad(pStorage);
1882
1883     IStorage_Release(pStorage);
1884
1885     hr = CoRevokeClassObject(dwRegister);
1886     ok_ole_success(hr, "CoRevokeClassObject");
1887
1888     test_data_cache();
1889     test_default_handler();
1890     test_runnable();
1891     test_OleLockRunning();
1892
1893     CoUninitialize();
1894 }