ole32/tests: Fix crash on NT4 and below.
[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
24 #include <stdarg.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "objbase.h"
29 #include "shlguid.h"
30
31 #include "wine/test.h"
32
33 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
34
35 static IPersistStorage OleObjectPersistStg;
36 static IOleCache *cache;
37 static IRunnableObject *runnable;
38
39 static const CLSID CLSID_WineTest =
40 { /* 9474ba1a-258b-490b-bc13-516e9239ace0 */
41     0x9474ba1a,
42     0x258b,
43     0x490b,
44     {0xbc, 0x13, 0x51, 0x6e, 0x92, 0x39, 0xac, 0xe0}
45 };
46
47 static char const * const *expected_method_list;
48
49 BOOL g_showRunnable = TRUE;
50 BOOL g_isRunning = TRUE;
51
52 #define CHECK_EXPECTED_METHOD(method_name) \
53     do { \
54         trace("%s\n", method_name); \
55         ok(*expected_method_list != NULL, "Extra method %s called\n", method_name); \
56         if (*expected_method_list) \
57         { \
58             ok(!strcmp(*expected_method_list, method_name), "Expected %s to be called instead of %s\n", \
59                 *expected_method_list, method_name); \
60             expected_method_list++; \
61         } \
62     } while(0)
63
64 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
65 {
66     CHECK_EXPECTED_METHOD("OleObject_QueryInterface");
67
68     *ppv = NULL;
69
70     if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IOleObject))
71         *ppv = (void *)iface;
72     else if (IsEqualIID(riid, &IID_IPersistStorage))
73         *ppv = &OleObjectPersistStg;
74     else if (IsEqualIID(riid, &IID_IOleCache))
75         *ppv = cache;
76     else if (IsEqualIID(riid, &IID_IRunnableObject) && g_showRunnable)
77         *ppv = runnable;
78
79     if(*ppv) {
80         IUnknown_AddRef((IUnknown*)*ppv);
81         return S_OK;
82     }
83
84     trace("OleObject_QueryInterface: returning E_NOINTERFACE\n");
85     return E_NOINTERFACE;
86 }
87
88 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
89 {
90     CHECK_EXPECTED_METHOD("OleObject_AddRef");
91     return 2;
92 }
93
94 static ULONG WINAPI OleObject_Release(IOleObject *iface)
95 {
96     CHECK_EXPECTED_METHOD("OleObject_Release");
97     return 1;
98 }
99
100 static HRESULT WINAPI OleObject_SetClientSite
101     (
102         IOleObject *iface,
103         IOleClientSite *pClientSite
104     )
105 {
106     CHECK_EXPECTED_METHOD("OleObject_SetClientSite");
107     return S_OK;
108 }
109
110 static HRESULT WINAPI OleObject_GetClientSite
111     (
112         IOleObject *iface,
113         IOleClientSite **ppClientSite
114     )
115 {
116     CHECK_EXPECTED_METHOD("OleObject_GetClientSite");
117     return E_NOTIMPL;
118 }
119
120 static HRESULT WINAPI OleObject_SetHostNames
121     (
122         IOleObject *iface,
123         LPCOLESTR szContainerApp,
124         LPCOLESTR szContainerObj
125     )
126 {
127     CHECK_EXPECTED_METHOD("OleObject_SetHostNames");
128     return S_OK;
129 }
130
131 static HRESULT WINAPI OleObject_Close
132     (
133         IOleObject *iface,
134         DWORD dwSaveOption
135     )
136 {
137     CHECK_EXPECTED_METHOD("OleObject_Close");
138     return S_OK;
139 }
140
141 static HRESULT WINAPI OleObject_SetMoniker
142     (
143         IOleObject *iface,
144         DWORD dwWhichMoniker,
145         IMoniker *pmk
146     )
147 {
148     CHECK_EXPECTED_METHOD("OleObject_SetMoniker");
149     return S_OK;
150 }
151
152 static HRESULT WINAPI OleObject_GetMoniker
153     (
154         IOleObject *iface,
155         DWORD dwAssign,
156         DWORD dwWhichMoniker,
157         IMoniker **ppmk
158     )
159 {
160     CHECK_EXPECTED_METHOD("OleObject_GetMoniker");
161     return S_OK;
162 }
163
164 static HRESULT WINAPI OleObject_InitFromData
165     (
166         IOleObject *iface,
167         IDataObject *pDataObject,
168         BOOL fCreation,
169         DWORD dwReserved
170     )
171 {
172     CHECK_EXPECTED_METHOD("OleObject_InitFromData");
173     return S_OK;
174 }
175
176 static HRESULT WINAPI OleObject_GetClipboardData
177     (
178         IOleObject *iface,
179         DWORD dwReserved,
180         IDataObject **ppDataObject
181     )
182 {
183     CHECK_EXPECTED_METHOD("OleObject_GetClipboardData");
184     return E_NOTIMPL;
185 }
186
187 static HRESULT WINAPI OleObject_DoVerb
188     (
189         IOleObject *iface,
190         LONG iVerb,
191         LPMSG lpmsg,
192         IOleClientSite *pActiveSite,
193         LONG lindex,
194         HWND hwndParent,
195         LPCRECT lprcPosRect
196     )
197 {
198     CHECK_EXPECTED_METHOD("OleObject_DoVerb");
199     return S_OK;
200 }
201
202 static HRESULT WINAPI OleObject_EnumVerbs
203     (
204         IOleObject *iface,
205         IEnumOLEVERB **ppEnumOleVerb
206     )
207 {
208     CHECK_EXPECTED_METHOD("OleObject_EnumVerbs");
209     return E_NOTIMPL;
210 }
211
212 static HRESULT WINAPI OleObject_Update
213     (
214         IOleObject *iface
215     )
216 {
217     CHECK_EXPECTED_METHOD("OleObject_Update");
218     return S_OK;
219 }
220
221 static HRESULT WINAPI OleObject_IsUpToDate
222     (
223         IOleObject *iface
224     )
225 {
226     CHECK_EXPECTED_METHOD("OleObject_IsUpToDate");
227     return S_OK;
228 }
229
230 static HRESULT WINAPI OleObject_GetUserClassID
231 (
232     IOleObject *iface,
233     CLSID *pClsid
234 )
235 {
236     CHECK_EXPECTED_METHOD("OleObject_GetUserClassID");
237     return E_NOTIMPL;
238 }
239
240 static HRESULT WINAPI OleObject_GetUserType
241 (
242     IOleObject *iface,
243     DWORD dwFormOfType,
244     LPOLESTR *pszUserType
245 )
246 {
247     CHECK_EXPECTED_METHOD("OleObject_GetUserType");
248     return E_NOTIMPL;
249 }
250
251 static HRESULT WINAPI OleObject_SetExtent
252 (
253     IOleObject *iface,
254     DWORD dwDrawAspect,
255     SIZEL *psizel
256 )
257 {
258     CHECK_EXPECTED_METHOD("OleObject_SetExtent");
259     return S_OK;
260 }
261
262 static HRESULT WINAPI OleObject_GetExtent
263 (
264     IOleObject *iface,
265     DWORD dwDrawAspect,
266     SIZEL *psizel
267 )
268 {
269     CHECK_EXPECTED_METHOD("OleObject_GetExtent");
270     return E_NOTIMPL;
271 }
272
273 static HRESULT WINAPI OleObject_Advise
274 (
275     IOleObject *iface,
276     IAdviseSink *pAdvSink,
277     DWORD *pdwConnection
278 )
279 {
280     CHECK_EXPECTED_METHOD("OleObject_Advise");
281     return S_OK;
282 }
283
284 static HRESULT WINAPI OleObject_Unadvise
285 (
286     IOleObject *iface,
287     DWORD dwConnection
288 )
289 {
290     CHECK_EXPECTED_METHOD("OleObject_Unadvise");
291     return S_OK;
292 }
293
294 static HRESULT WINAPI OleObject_EnumAdvise
295 (
296     IOleObject *iface,
297     IEnumSTATDATA **ppenumAdvise
298 )
299 {
300     CHECK_EXPECTED_METHOD("OleObject_EnumAdvise");
301     return E_NOTIMPL;
302 }
303
304 static HRESULT WINAPI OleObject_GetMiscStatus
305 (
306     IOleObject *iface,
307     DWORD dwAspect,
308     DWORD *pdwStatus
309 )
310 {
311     CHECK_EXPECTED_METHOD("OleObject_GetMiscStatus");
312     *pdwStatus = DVASPECT_CONTENT;
313     return S_OK;
314 }
315
316 static HRESULT WINAPI OleObject_SetColorScheme
317 (
318     IOleObject *iface,
319     LOGPALETTE *pLogpal
320 )
321 {
322     CHECK_EXPECTED_METHOD("OleObject_SetColorScheme");
323     return E_NOTIMPL;
324 }
325
326 static const IOleObjectVtbl OleObjectVtbl =
327 {
328     OleObject_QueryInterface,
329     OleObject_AddRef,
330     OleObject_Release,
331     OleObject_SetClientSite,
332     OleObject_GetClientSite,
333     OleObject_SetHostNames,
334     OleObject_Close,
335     OleObject_SetMoniker,
336     OleObject_GetMoniker,
337     OleObject_InitFromData,
338     OleObject_GetClipboardData,
339     OleObject_DoVerb,
340     OleObject_EnumVerbs,
341     OleObject_Update,
342     OleObject_IsUpToDate,
343     OleObject_GetUserClassID,
344     OleObject_GetUserType,
345     OleObject_SetExtent,
346     OleObject_GetExtent,
347     OleObject_Advise,
348     OleObject_Unadvise,
349     OleObject_EnumAdvise,
350     OleObject_GetMiscStatus,
351     OleObject_SetColorScheme
352 };
353
354 static IOleObject OleObject = { &OleObjectVtbl };
355
356 static HRESULT WINAPI OleObjectPersistStg_QueryInterface(IPersistStorage *iface, REFIID riid, void **ppv)
357 {
358     trace("OleObjectPersistStg_QueryInterface\n");
359     return IUnknown_QueryInterface((IUnknown *)&OleObject, riid, ppv);
360 }
361
362 static ULONG WINAPI OleObjectPersistStg_AddRef(IPersistStorage *iface)
363 {
364     CHECK_EXPECTED_METHOD("OleObjectPersistStg_AddRef");
365     return 2;
366 }
367
368 static ULONG WINAPI OleObjectPersistStg_Release(IPersistStorage *iface)
369 {
370     CHECK_EXPECTED_METHOD("OleObjectPersistStg_Release");
371     return 1;
372 }
373
374 static HRESULT WINAPI OleObjectPersistStg_GetClassId(IPersistStorage *iface, CLSID *clsid)
375 {
376     CHECK_EXPECTED_METHOD("OleObjectPersistStg_GetClassId");
377     return E_NOTIMPL;
378 }
379
380 static HRESULT WINAPI OleObjectPersistStg_IsDirty
381 (
382     IPersistStorage *iface
383 )
384 {
385     CHECK_EXPECTED_METHOD("OleObjectPersistStg_IsDirty");
386     return S_OK;
387 }
388
389 static HRESULT WINAPI OleObjectPersistStg_InitNew
390 (
391     IPersistStorage *iface,
392     IStorage *pStg
393 )
394 {
395     CHECK_EXPECTED_METHOD("OleObjectPersistStg_InitNew");
396     return S_OK;
397 }
398
399 static HRESULT WINAPI OleObjectPersistStg_Load
400 (
401     IPersistStorage *iface,
402     IStorage *pStg
403 )
404 {
405     CHECK_EXPECTED_METHOD("OleObjectPersistStg_Load");
406     return S_OK;
407 }
408
409 static HRESULT WINAPI OleObjectPersistStg_Save
410 (
411     IPersistStorage *iface,
412     IStorage *pStgSave,
413     BOOL fSameAsLoad
414 )
415 {
416     CHECK_EXPECTED_METHOD("OleObjectPersistStg_Save");
417     return S_OK;
418 }
419
420 static HRESULT WINAPI OleObjectPersistStg_SaveCompleted
421 (
422     IPersistStorage *iface,
423     IStorage *pStgNew
424 )
425 {
426     CHECK_EXPECTED_METHOD("OleObjectPersistStg_SaveCompleted");
427     return S_OK;
428 }
429
430 static HRESULT WINAPI OleObjectPersistStg_HandsOffStorage
431 (
432     IPersistStorage *iface
433 )
434 {
435     CHECK_EXPECTED_METHOD("OleObjectPersistStg_HandsOffStorage");
436     return S_OK;
437 }
438
439 static const IPersistStorageVtbl OleObjectPersistStgVtbl =
440 {
441     OleObjectPersistStg_QueryInterface,
442     OleObjectPersistStg_AddRef,
443     OleObjectPersistStg_Release,
444     OleObjectPersistStg_GetClassId,
445     OleObjectPersistStg_IsDirty,
446     OleObjectPersistStg_InitNew,
447     OleObjectPersistStg_Load,
448     OleObjectPersistStg_Save,
449     OleObjectPersistStg_SaveCompleted,
450     OleObjectPersistStg_HandsOffStorage
451 };
452
453 static IPersistStorage OleObjectPersistStg = { &OleObjectPersistStgVtbl };
454
455 static HRESULT WINAPI OleObjectCache_QueryInterface(IOleCache *iface, REFIID riid, void **ppv)
456 {
457     return IUnknown_QueryInterface((IUnknown *)&OleObject, riid, ppv);
458 }
459
460 static ULONG WINAPI OleObjectCache_AddRef(IOleCache *iface)
461 {
462     CHECK_EXPECTED_METHOD("OleObjectCache_AddRef");
463     return 2;
464 }
465
466 static ULONG WINAPI OleObjectCache_Release(IOleCache *iface)
467 {
468     CHECK_EXPECTED_METHOD("OleObjectCache_Release");
469     return 1;
470 }
471
472 static HRESULT WINAPI OleObjectCache_Cache
473 (
474     IOleCache *iface,
475     FORMATETC *pformatetc,
476     DWORD advf,
477     DWORD *pdwConnection
478 )
479 {
480     CHECK_EXPECTED_METHOD("OleObjectCache_Cache");
481     return S_OK;
482 }
483
484 static HRESULT WINAPI OleObjectCache_Uncache
485 (
486     IOleCache *iface,
487     DWORD dwConnection
488 )
489 {
490     CHECK_EXPECTED_METHOD("OleObjectCache_Uncache");
491     return S_OK;
492 }
493
494 static HRESULT WINAPI OleObjectCache_EnumCache
495 (
496     IOleCache *iface,
497     IEnumSTATDATA **ppenumSTATDATA
498 )
499 {
500     CHECK_EXPECTED_METHOD("OleObjectCache_EnumCache");
501     return S_OK;
502 }
503
504
505 static HRESULT WINAPI OleObjectCache_InitCache
506 (
507     IOleCache *iface,
508     IDataObject *pDataObject
509 )
510 {
511     CHECK_EXPECTED_METHOD("OleObjectCache_InitCache");
512     return S_OK;
513 }
514
515
516 static HRESULT WINAPI OleObjectCache_SetData
517 (
518     IOleCache *iface,
519     FORMATETC *pformatetc,
520     STGMEDIUM *pmedium,
521     BOOL fRelease
522 )
523 {
524     CHECK_EXPECTED_METHOD("OleObjectCache_SetData");
525     return S_OK;
526 }
527
528
529 static const IOleCacheVtbl OleObjectCacheVtbl =
530 {
531     OleObjectCache_QueryInterface,
532     OleObjectCache_AddRef,
533     OleObjectCache_Release,
534     OleObjectCache_Cache,
535     OleObjectCache_Uncache,
536     OleObjectCache_EnumCache,
537     OleObjectCache_InitCache,
538     OleObjectCache_SetData
539 };
540
541 static IOleCache OleObjectCache = { &OleObjectCacheVtbl };
542
543 static HRESULT WINAPI OleObjectCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
544 {
545     if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
546     {
547         *ppv = iface;
548         IUnknown_AddRef(iface);
549         return S_OK;
550     }
551     *ppv = NULL;
552     return E_NOINTERFACE;
553 }
554
555 static ULONG WINAPI OleObjectCF_AddRef(IClassFactory *iface)
556 {
557     return 2;
558 }
559
560 static ULONG WINAPI OleObjectCF_Release(IClassFactory *iface)
561 {
562     return 1;
563 }
564
565 static HRESULT WINAPI OleObjectCF_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID riid, void **ppv)
566 {
567     return IUnknown_QueryInterface((IUnknown *)&OleObject, riid, ppv);
568 }
569
570 static HRESULT WINAPI OleObjectCF_LockServer(IClassFactory *iface, BOOL lock)
571 {
572     return S_OK;
573 }
574
575 static const IClassFactoryVtbl OleObjectCFVtbl =
576 {
577     OleObjectCF_QueryInterface,
578     OleObjectCF_AddRef,
579     OleObjectCF_Release,
580     OleObjectCF_CreateInstance,
581     OleObjectCF_LockServer
582 };
583
584 static IClassFactory OleObjectCF = { &OleObjectCFVtbl };
585
586 static HRESULT WINAPI OleObjectRunnable_QueryInterface(IRunnableObject *iface, REFIID riid, void **ppv)
587 {
588     return IUnknown_QueryInterface((IUnknown *)&OleObject, riid, ppv);
589 }
590
591 static ULONG WINAPI OleObjectRunnable_AddRef(IRunnableObject *iface)
592 {
593     CHECK_EXPECTED_METHOD("OleObjectRunnable_AddRef");
594     return 2;
595 }
596
597 static ULONG WINAPI OleObjectRunnable_Release(IRunnableObject *iface)
598 {
599     CHECK_EXPECTED_METHOD("OleObjectRunnable_Release");
600     return 1;
601 }
602
603 static HRESULT WINAPI OleObjectRunnable_GetRunningClass(
604     IRunnableObject *iface,
605     LPCLSID lpClsid)
606 {
607     CHECK_EXPECTED_METHOD("OleObjectRunnable_GetRunningClass");
608     return E_NOTIMPL;
609 }
610
611 static HRESULT WINAPI OleObjectRunnable_Run(
612     IRunnableObject *iface,
613     LPBINDCTX pbc)
614 {
615     CHECK_EXPECTED_METHOD("OleObjectRunnable_Run");
616     return S_OK;
617 }
618
619 static BOOL WINAPI OleObjectRunnable_IsRunning(IRunnableObject *iface)
620 {
621     CHECK_EXPECTED_METHOD("OleObjectRunnable_IsRunning");
622     return g_isRunning;
623 }
624
625 static HRESULT WINAPI OleObjectRunnable_LockRunning(
626     IRunnableObject *iface,
627     BOOL fLock,
628     BOOL fLastUnlockCloses)
629 {
630     CHECK_EXPECTED_METHOD("OleObjectRunnable_LockRunning");
631     return S_OK;
632 }
633
634 static HRESULT WINAPI OleObjectRunnable_SetContainedObject(
635     IRunnableObject *iface,
636     BOOL fContained)
637 {
638     CHECK_EXPECTED_METHOD("OleObjectRunnable_SetContainedObject");
639     return S_OK;
640 }
641
642 static const IRunnableObjectVtbl OleObjectRunnableVtbl =
643 {
644     OleObjectRunnable_QueryInterface,
645     OleObjectRunnable_AddRef,
646     OleObjectRunnable_Release,
647     OleObjectRunnable_GetRunningClass,
648     OleObjectRunnable_Run,
649     OleObjectRunnable_IsRunning,
650     OleObjectRunnable_LockRunning,
651     OleObjectRunnable_SetContainedObject
652 };
653
654 static IRunnableObject OleObjectRunnable = { &OleObjectRunnableVtbl };
655
656 static const CLSID CLSID_Equation3 = {0x0002CE02, 0x0000, 0x0000, {0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46} };
657
658 static void test_OleCreate(IStorage *pStorage)
659 {
660     HRESULT hr;
661     IOleObject *pObject;
662     FORMATETC formatetc;
663     static const char *methods_olerender_none[] =
664     {
665         "OleObject_QueryInterface",
666         "OleObject_AddRef",
667         "OleObject_QueryInterface",
668         "OleObjectPersistStg_AddRef",
669         "OleObjectPersistStg_InitNew",
670         "OleObjectPersistStg_Release",
671         "OleObject_Release",
672         NULL
673     };
674     static const char *methods_olerender_draw[] =
675     {
676         "OleObject_QueryInterface",
677         "OleObject_AddRef",
678         "OleObject_QueryInterface",
679         "OleObjectPersistStg_AddRef",
680         "OleObjectPersistStg_InitNew",
681         "OleObjectPersistStg_Release",
682         "OleObject_QueryInterface",
683         "OleObjectRunnable_AddRef",
684         "OleObjectRunnable_Run",
685         "OleObjectRunnable_Release",
686         "OleObject_QueryInterface",
687         "OleObjectCache_AddRef",
688         "OleObjectCache_Cache",
689         "OleObjectCache_Release",
690         "OleObject_Release",
691         NULL
692     };
693     static const char *methods_olerender_format[] =
694     {
695         "OleObject_QueryInterface",
696         "OleObject_AddRef",
697         "OleObject_QueryInterface",
698         "OleObject_AddRef",
699         "OleObject_GetMiscStatus",
700         "OleObject_QueryInterface",
701         "OleObjectPersistStg_AddRef",
702         "OleObjectPersistStg_InitNew",
703         "OleObjectPersistStg_Release",
704         "OleObject_SetClientSite",
705         "OleObject_Release",
706         "OleObject_QueryInterface",
707         "OleObjectRunnable_AddRef",
708         "OleObjectRunnable_Run",
709         "OleObjectRunnable_Release",
710         "OleObject_QueryInterface",
711         "OleObjectCache_AddRef",
712         "OleObjectCache_Cache",
713         "OleObjectCache_Release",
714         "OleObject_Release",
715         NULL
716     };
717     static const char *methods_olerender_asis[] =
718     {
719         "OleObject_QueryInterface",
720         "OleObject_AddRef",
721         "OleObject_QueryInterface",
722         "OleObjectPersistStg_AddRef",
723         "OleObjectPersistStg_InitNew",
724         "OleObjectPersistStg_Release",
725         "OleObject_Release",
726         NULL
727     };
728     static const char *methods_olerender_draw_no_runnable[] =
729     {
730         "OleObject_QueryInterface",
731         "OleObject_AddRef",
732         "OleObject_QueryInterface",
733         "OleObjectPersistStg_AddRef",
734         "OleObjectPersistStg_InitNew",
735         "OleObjectPersistStg_Release",
736         "OleObject_QueryInterface",
737         "OleObject_QueryInterface",
738         "OleObjectCache_AddRef",
739         "OleObjectCache_Cache",
740         "OleObjectCache_Release",
741         "OleObject_Release",
742         NULL
743     };
744     static const char *methods_olerender_draw_no_cache[] =
745     {
746         "OleObject_QueryInterface",
747         "OleObject_AddRef",
748         "OleObject_QueryInterface",
749         "OleObjectPersistStg_AddRef",
750         "OleObjectPersistStg_InitNew",
751         "OleObjectPersistStg_Release",
752         "OleObject_QueryInterface",
753         "OleObjectRunnable_AddRef",
754         "OleObjectRunnable_Run",
755         "OleObjectRunnable_Release",
756         "OleObject_QueryInterface",
757         "OleObject_Release",
758         NULL
759     };
760
761     runnable = &OleObjectRunnable;
762     cache = &OleObjectCache;
763     expected_method_list = methods_olerender_none;
764     trace("OleCreate with OLERENDER_NONE:\n");
765     hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_NONE, NULL, NULL, pStorage, (void **)&pObject);
766     ok_ole_success(hr, "OleCreate");
767     IOleObject_Release(pObject);
768     ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list);
769
770     expected_method_list = methods_olerender_draw;
771     trace("OleCreate with OLERENDER_DRAW:\n");
772     hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject);
773     ok_ole_success(hr, "OleCreate");
774     IOleObject_Release(pObject);
775     ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list);
776
777     formatetc.cfFormat = CF_TEXT;
778     formatetc.ptd = NULL;
779     formatetc.dwAspect = DVASPECT_CONTENT;
780     formatetc.lindex = -1;
781     formatetc.tymed = TYMED_HGLOBAL;
782     expected_method_list = methods_olerender_format;
783     trace("OleCreate with OLERENDER_FORMAT:\n");
784     hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_FORMAT, &formatetc, (IOleClientSite *)0xdeadbeef, pStorage, (void **)&pObject);
785     ok_ole_success(hr, "OleCreate");
786     if (pObject)
787         IOleObject_Release(pObject);
788     ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list);
789
790     expected_method_list = methods_olerender_asis;
791     trace("OleCreate with OLERENDER_ASIS:\n");
792     hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_ASIS, NULL, NULL, pStorage, (void **)&pObject);
793     ok_ole_success(hr, "OleCreate");
794     IOleObject_Release(pObject);
795     ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list);
796
797     runnable = NULL;
798     expected_method_list = methods_olerender_draw_no_runnable;
799     trace("OleCreate with OLERENDER_DRAW (no IOlObjectRunnable):\n");
800     hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject);
801     ok_ole_success(hr, "OleCreate");
802     IOleObject_Release(pObject);
803     ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list);
804
805     runnable = &OleObjectRunnable;
806     cache = NULL;
807     expected_method_list = methods_olerender_draw_no_cache;
808     trace("OleCreate with OLERENDER_DRAW (no IOlObjectRunnable):\n");
809     hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject);
810     ok_ole_success(hr, "OleCreate");
811     IOleObject_Release(pObject);
812     ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list);
813     trace("end\n");
814 }
815
816 static void test_OleLoad(IStorage *pStorage)
817 {
818     HRESULT hr;
819     IOleObject *pObject;
820
821     static const char *methods_oleload[] =
822     {
823         "OleObject_QueryInterface",
824         "OleObject_AddRef",
825         "OleObject_QueryInterface",
826         "OleObject_AddRef",
827         "OleObject_GetMiscStatus",
828         "OleObject_QueryInterface",
829         "OleObjectPersistStg_AddRef",
830         "OleObjectPersistStg_Load",
831         "OleObjectPersistStg_Release",
832         "OleObject_SetClientSite",
833         "OleObject_Release",
834         "OleObject_QueryInterface",
835         "OleObject_Release",
836         NULL
837     };
838
839     expected_method_list = methods_oleload;
840     trace("OleLoad:\n");
841     hr = OleLoad(pStorage, &IID_IOleObject, (IOleClientSite *)0xdeadbeef, (void **)&pObject);
842     ok_ole_success(hr, "OleLoad");
843     if (pObject)
844         IOleObject_Release(pObject);
845     ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list);
846 }
847
848 static BOOL STDMETHODCALLTYPE draw_continue(ULONG_PTR param)
849 {
850     CHECK_EXPECTED_METHOD("draw_continue");
851     return TRUE;
852 }
853
854 static HRESULT WINAPI AdviseSink_QueryInterface(IAdviseSink *iface, REFIID riid, void **ppv)
855 {
856     if (IsEqualIID(riid, &IID_IAdviseSink) || IsEqualIID(riid, &IID_IUnknown))
857     {
858         *ppv = iface;
859         IUnknown_AddRef(iface);
860         return S_OK;
861     }
862     *ppv = NULL;
863     return E_NOINTERFACE;
864 }
865
866 static ULONG WINAPI AdviseSink_AddRef(IAdviseSink *iface)
867 {
868     return 2;
869 }
870
871 static ULONG WINAPI AdviseSink_Release(IAdviseSink *iface)
872 {
873     return 1;
874 }
875
876
877 static void WINAPI AdviseSink_OnDataChange(
878     IAdviseSink *iface,
879     FORMATETC *pFormatetc,
880     STGMEDIUM *pStgmed)
881 {
882     CHECK_EXPECTED_METHOD("AdviseSink_OnDataChange");
883 }
884
885 static void WINAPI AdviseSink_OnViewChange(
886     IAdviseSink *iface,
887     DWORD dwAspect,
888     LONG lindex)
889 {
890     CHECK_EXPECTED_METHOD("AdviseSink_OnViewChange");
891 }
892
893 static void WINAPI AdviseSink_OnRename(
894     IAdviseSink *iface,
895     IMoniker *pmk)
896 {
897     CHECK_EXPECTED_METHOD("AdviseSink_OnRename");
898 }
899
900 static void WINAPI AdviseSink_OnSave(IAdviseSink *iface)
901 {
902     CHECK_EXPECTED_METHOD("AdviseSink_OnSave");
903 }
904
905 static void WINAPI AdviseSink_OnClose(IAdviseSink *iface)
906 {
907     CHECK_EXPECTED_METHOD("AdviseSink_OnClose");
908 }
909
910 static const IAdviseSinkVtbl AdviseSinkVtbl =
911 {
912     AdviseSink_QueryInterface,
913     AdviseSink_AddRef,
914     AdviseSink_Release,
915     AdviseSink_OnDataChange,
916     AdviseSink_OnViewChange,
917     AdviseSink_OnRename,
918     AdviseSink_OnSave,
919     AdviseSink_OnClose
920 };
921
922 static IAdviseSink AdviseSink = { &AdviseSinkVtbl };
923
924 static HRESULT WINAPI DataObject_QueryInterface(
925             IDataObject*     iface,
926             REFIID           riid,
927             void**           ppvObject)
928 {
929     if (IsEqualIID(riid, &IID_IDataObject) || IsEqualIID(riid, &IID_IUnknown))
930     {
931         *ppvObject = iface;
932         return S_OK;
933     }
934     *ppvObject = NULL;
935     return S_OK;
936 }
937
938 static ULONG WINAPI DataObject_AddRef(
939             IDataObject*     iface)
940 {
941     return 2;
942 }
943
944 static ULONG WINAPI DataObject_Release(
945             IDataObject*     iface)
946 {
947     return 1;
948 }
949
950 static HRESULT WINAPI DataObject_GetData(
951         IDataObject*     iface,
952         LPFORMATETC      pformatetcIn,
953         STGMEDIUM*       pmedium)
954 {
955     CHECK_EXPECTED_METHOD("DataObject_GetData");
956     return E_NOTIMPL;
957 }
958
959 static HRESULT WINAPI DataObject_GetDataHere(
960         IDataObject*     iface,
961         LPFORMATETC      pformatetc,
962         STGMEDIUM*       pmedium)
963 {
964     CHECK_EXPECTED_METHOD("DataObject_GetDataHere");
965     return E_NOTIMPL;
966 }
967
968 static HRESULT WINAPI DataObject_QueryGetData(
969         IDataObject*     iface,
970         LPFORMATETC      pformatetc)
971 {
972     CHECK_EXPECTED_METHOD("DataObject_QueryGetData");
973     return S_OK;
974 }
975
976 static HRESULT WINAPI DataObject_GetCanonicalFormatEtc(
977         IDataObject*     iface,
978         LPFORMATETC      pformatectIn,
979         LPFORMATETC      pformatetcOut)
980 {
981     CHECK_EXPECTED_METHOD("DataObject_GetCanonicalFormatEtc");
982     return E_NOTIMPL;
983 }
984
985 static HRESULT WINAPI DataObject_SetData(
986         IDataObject*     iface,
987         LPFORMATETC      pformatetc,
988         STGMEDIUM*       pmedium,
989         BOOL             fRelease)
990 {
991     CHECK_EXPECTED_METHOD("DataObject_SetData");
992     return E_NOTIMPL;
993 }
994
995 static HRESULT WINAPI DataObject_EnumFormatEtc(
996         IDataObject*     iface,
997         DWORD            dwDirection,
998         IEnumFORMATETC** ppenumFormatEtc)
999 {
1000     CHECK_EXPECTED_METHOD("DataObject_EnumFormatEtc");
1001     return E_NOTIMPL;
1002 }
1003
1004 static HRESULT WINAPI DataObject_DAdvise(
1005         IDataObject*     iface,
1006         FORMATETC*       pformatetc,
1007         DWORD            advf,
1008         IAdviseSink*     pAdvSink,
1009         DWORD*           pdwConnection)
1010 {
1011     CHECK_EXPECTED_METHOD("DataObject_DAdvise");
1012     *pdwConnection = 1;
1013     return S_OK;
1014 }
1015
1016 static HRESULT WINAPI DataObject_DUnadvise(
1017         IDataObject*     iface,
1018         DWORD            dwConnection)
1019 {
1020     CHECK_EXPECTED_METHOD("DataObject_DUnadvise");
1021     return S_OK;
1022 }
1023
1024 static HRESULT WINAPI DataObject_EnumDAdvise(
1025         IDataObject*     iface,
1026         IEnumSTATDATA**  ppenumAdvise)
1027 {
1028     CHECK_EXPECTED_METHOD("DataObject_EnumDAdvise");
1029     return OLE_E_ADVISENOTSUPPORTED;
1030 }
1031
1032 static IDataObjectVtbl DataObjectVtbl =
1033 {
1034     DataObject_QueryInterface,
1035     DataObject_AddRef,
1036     DataObject_Release,
1037     DataObject_GetData,
1038     DataObject_GetDataHere,
1039     DataObject_QueryGetData,
1040     DataObject_GetCanonicalFormatEtc,
1041     DataObject_SetData,
1042     DataObject_EnumFormatEtc,
1043     DataObject_DAdvise,
1044     DataObject_DUnadvise,
1045     DataObject_EnumDAdvise
1046 };
1047
1048 static IDataObject DataObject = { &DataObjectVtbl };
1049
1050 static void test_data_cache(void)
1051 {
1052     HRESULT hr;
1053     IOleCache2 *pOleCache;
1054     IStorage *pStorage;
1055     IPersistStorage *pPS;
1056     IViewObject *pViewObject;
1057     IOleCacheControl *pOleCacheControl;
1058     FORMATETC fmtetc;
1059     STGMEDIUM stgmedium;
1060     DWORD dwConnection;
1061     DWORD dwFreeze;
1062     RECTL rcBounds;
1063     HDC hdcMem;
1064     CLSID clsid;
1065     char szSystemDir[MAX_PATH];
1066     WCHAR wszPath[MAX_PATH];
1067     static const WCHAR wszShell32[] = {'\\','s','h','e','l','l','3','2','.','d','l','l',0};
1068
1069     static const char *methods_cacheinitnew[] =
1070     {
1071         "AdviseSink_OnViewChange",
1072         "AdviseSink_OnViewChange",
1073         "draw_continue",
1074         "DataObject_DAdvise",
1075         "DataObject_DAdvise",
1076         "DataObject_DUnadvise",
1077         "DataObject_DUnadvise",
1078         NULL
1079     };
1080     static const char *methods_cacheload[] =
1081     {
1082         "AdviseSink_OnViewChange",
1083         "draw_continue",
1084         "draw_continue",
1085         "draw_continue",
1086         "DataObject_GetData",
1087         "DataObject_GetData",
1088         "DataObject_GetData",
1089         NULL
1090     };
1091
1092     GetSystemDirectory(szSystemDir, sizeof(szSystemDir)/sizeof(szSystemDir[0]));
1093
1094     expected_method_list = methods_cacheinitnew;
1095
1096     fmtetc.cfFormat = CF_METAFILEPICT;
1097     fmtetc.dwAspect = DVASPECT_ICON;
1098     fmtetc.lindex = -1;
1099     fmtetc.ptd = NULL;
1100     fmtetc.tymed = TYMED_MFPICT;
1101
1102     hr = StgCreateDocfile(NULL, STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_DELETEONRELEASE, 0, &pStorage);
1103     ok_ole_success(hr, "StgCreateDocfile");
1104
1105     /* Test with new data */
1106
1107     hr = CreateDataCache(NULL, &CLSID_NULL, &IID_IOleCache2, (LPVOID *)&pOleCache);
1108     ok_ole_success(hr, "CreateDataCache");
1109
1110     hr = IOleCache_QueryInterface(pOleCache, &IID_IPersistStorage, (LPVOID *)&pPS);
1111     ok_ole_success(hr, "IOleCache_QueryInterface(IID_IPersistStorage)");
1112     hr = IOleCache_QueryInterface(pOleCache, &IID_IViewObject, (LPVOID *)&pViewObject);
1113     ok_ole_success(hr, "IOleCache_QueryInterface(IID_IViewObject)");
1114     hr = IOleCache_QueryInterface(pOleCache, &IID_IOleCacheControl, (LPVOID *)&pOleCacheControl);
1115     ok_ole_success(hr, "IOleCache_QueryInterface(IID_IOleCacheControl)");
1116
1117     hr = IViewObject_SetAdvise(pViewObject, DVASPECT_ICON, ADVF_PRIMEFIRST, &AdviseSink);
1118     ok_ole_success(hr, "IViewObject_SetAdvise");
1119
1120     hr = IPersistStorage_InitNew(pPS, pStorage);
1121     ok_ole_success(hr, "IPersistStorage_InitNew");
1122
1123     hr = IPersistStorage_IsDirty(pPS);
1124     ok_ole_success(hr, "IPersistStorage_IsDirty");
1125
1126     hr = IPersistStorage_GetClassID(pPS, &clsid);
1127     ok_ole_success(hr, "IPersistStorage_GetClassID");
1128     ok(IsEqualCLSID(&clsid, &IID_NULL), "clsid should be blank\n");
1129
1130     hr = IOleCache_Uncache(pOleCache, 0xdeadbeef);
1131     ok(hr == OLE_E_NOCONNECTION, "IOleCache_Uncache with invalid value should return OLE_E_NOCONNECTION instead of 0x%x\n", hr);
1132
1133     /* Both tests crash on NT4 and below */
1134     if (0)
1135     {
1136         hr = IOleCache_Cache(pOleCache, NULL, 0, &dwConnection);
1137         ok(hr == E_INVALIDARG, "IOleCache_Cache with NULL fmtetc should have returned E_INVALIDARG instead of 0x%08x\n", hr);
1138
1139         hr = IOleCache_Cache(pOleCache, NULL, 0, NULL);
1140         ok(hr == E_INVALIDARG, "IOleCache_Cache with NULL pdwConnection should have returned E_INVALIDARG instead of 0x%08x\n", hr);
1141     }
1142
1143     for (fmtetc.cfFormat = CF_TEXT; fmtetc.cfFormat < CF_MAX; fmtetc.cfFormat++)
1144     {
1145         int i;
1146         fmtetc.dwAspect = DVASPECT_THUMBNAIL;
1147         for (i = 0; i < 7; i++)
1148         {
1149             fmtetc.tymed = 1 << i;
1150             hr = IOleCache_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1151             if ((fmtetc.cfFormat == CF_METAFILEPICT && fmtetc.tymed == TYMED_MFPICT) ||
1152                 (fmtetc.cfFormat == CF_BITMAP && fmtetc.tymed == TYMED_GDI) ||
1153                 (fmtetc.cfFormat == CF_DIB && fmtetc.tymed == TYMED_HGLOBAL) ||
1154                 (fmtetc.cfFormat == CF_ENHMETAFILE && fmtetc.tymed == TYMED_ENHMF))
1155                 ok(hr == S_OK, "IOleCache_Cache cfFormat = %d, tymed = %d should have returned S_OK instead of 0x%08x\n",
1156                     fmtetc.cfFormat, fmtetc.tymed, hr);
1157             else if (fmtetc.tymed == TYMED_HGLOBAL)
1158                 ok(hr == CACHE_S_FORMATETC_NOTSUPPORTED,
1159                     "IOleCache_Cache cfFormat = %d, tymed = %d should have returned CACHE_S_FORMATETC_NOTSUPPORTED instead of 0x%08x\n",
1160                     fmtetc.cfFormat, fmtetc.tymed, hr);
1161             else
1162                 ok(hr == DV_E_TYMED, "IOleCache_Cache cfFormat = %d, tymed = %d should have returned DV_E_TYMED instead of 0x%08x\n",
1163                     fmtetc.cfFormat, fmtetc.tymed, hr);
1164             if (SUCCEEDED(hr))
1165             {
1166                 hr = IOleCache_Uncache(pOleCache, dwConnection);
1167                 ok_ole_success(hr, "IOleCache_Uncache");
1168             }
1169         }
1170     }
1171
1172     fmtetc.cfFormat = CF_BITMAP;
1173     fmtetc.dwAspect = DVASPECT_THUMBNAIL;
1174     fmtetc.tymed = TYMED_GDI;
1175     hr = IOleCache_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1176     ok_ole_success(hr, "IOleCache_Cache");
1177
1178     fmtetc.cfFormat = 0;
1179     fmtetc.dwAspect = DVASPECT_ICON;
1180     fmtetc.tymed = TYMED_MFPICT;
1181     hr = IOleCache_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1182     ok_ole_success(hr, "IOleCache_Cache");
1183
1184     MultiByteToWideChar(CP_ACP, 0, szSystemDir, -1, wszPath, sizeof(wszPath)/sizeof(wszPath[0]));
1185     memcpy(wszPath+lstrlenW(wszPath), wszShell32, sizeof(wszShell32));
1186
1187     fmtetc.cfFormat = CF_METAFILEPICT;
1188     stgmedium.tymed = TYMED_MFPICT;
1189     U(stgmedium).hMetaFilePict = OleMetafilePictFromIconAndLabel(
1190         LoadIcon(NULL, IDI_APPLICATION), wszPath, wszPath, 0);
1191     stgmedium.pUnkForRelease = NULL;
1192
1193     fmtetc.dwAspect = DVASPECT_CONTENT;
1194     hr = IOleCache_SetData(pOleCache, &fmtetc, &stgmedium, FALSE);
1195     ok(hr == OLE_E_BLANK, "IOleCache_SetData for aspect not in cache should have return OLE_E_BLANK instead of 0x%08x\n", hr);
1196
1197     fmtetc.dwAspect = DVASPECT_ICON;
1198     hr = IOleCache_SetData(pOleCache, &fmtetc, &stgmedium, FALSE);
1199     ok_ole_success(hr, "IOleCache_SetData");
1200
1201     hr = IViewObject_Freeze(pViewObject, DVASPECT_ICON, -1, NULL, &dwFreeze);
1202     todo_wine {
1203     ok_ole_success(hr, "IViewObject_Freeze");
1204     hr = IViewObject_Freeze(pViewObject, DVASPECT_CONTENT, -1, NULL, &dwFreeze);
1205     ok(hr == OLE_E_BLANK, "IViewObject_Freeze with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1206     }
1207
1208     rcBounds.left = 0;
1209     rcBounds.top = 0;
1210     rcBounds.right = 100;
1211     rcBounds.bottom = 100;
1212     hdcMem = CreateCompatibleDC(NULL);
1213
1214     hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1215     ok_ole_success(hr, "IViewObject_Draw");
1216
1217     hr = IViewObject_Draw(pViewObject, DVASPECT_CONTENT, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1218     ok(hr == OLE_E_BLANK, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1219
1220     DeleteDC(hdcMem);
1221
1222     hr = IOleCacheControl_OnRun(pOleCacheControl, &DataObject);
1223     todo_wine {
1224     ok_ole_success(hr, "IOleCacheControl_OnRun");
1225     }
1226
1227     hr = IPersistStorage_Save(pPS, pStorage, TRUE);
1228     ok_ole_success(hr, "IPersistStorage_Save");
1229
1230     hr = IPersistStorage_SaveCompleted(pPS, NULL);
1231     ok_ole_success(hr, "IPersistStorage_SaveCompleted");
1232
1233     hr = IPersistStorage_IsDirty(pPS);
1234     ok(hr == S_FALSE, "IPersistStorage_IsDirty should have returned S_FALSE instead of 0x%x\n", hr);
1235
1236     IPersistStorage_Release(pPS);
1237     IViewObject_Release(pViewObject);
1238     IOleCache_Release(pOleCache);
1239     IOleCacheControl_Release(pOleCacheControl);
1240
1241     todo_wine {
1242     ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list);
1243     }
1244
1245     /* Test with loaded data */
1246     trace("Testing loaded data with CreateDataCache:\n");
1247     expected_method_list = methods_cacheload;
1248
1249     hr = CreateDataCache(NULL, &CLSID_NULL, &IID_IOleCache2, (LPVOID *)&pOleCache);
1250     ok_ole_success(hr, "CreateDataCache");
1251
1252     hr = IOleCache_QueryInterface(pOleCache, &IID_IPersistStorage, (LPVOID *)&pPS);
1253     ok_ole_success(hr, "IOleCache_QueryInterface(IID_IPersistStorage)");
1254     hr = IOleCache_QueryInterface(pOleCache, &IID_IViewObject, (LPVOID *)&pViewObject);
1255     ok_ole_success(hr, "IOleCache_QueryInterface(IID_IViewObject)");
1256
1257     hr = IViewObject_SetAdvise(pViewObject, DVASPECT_ICON, ADVF_PRIMEFIRST, &AdviseSink);
1258     ok_ole_success(hr, "IViewObject_SetAdvise");
1259
1260     hr = IPersistStorage_Load(pPS, pStorage);
1261     ok_ole_success(hr, "IPersistStorage_Load");
1262
1263     hr = IPersistStorage_IsDirty(pPS);
1264     ok(hr == S_FALSE, "IPersistStorage_IsDirty should have returned S_FALSE instead of 0x%x\n", hr);
1265
1266     fmtetc.cfFormat = 0;
1267     fmtetc.dwAspect = DVASPECT_ICON;
1268     fmtetc.lindex = -1;
1269     fmtetc.ptd = NULL;
1270     fmtetc.tymed = TYMED_MFPICT;
1271     hr = IOleCache_Cache(pOleCache, &fmtetc, 0, &dwConnection);
1272     ok(hr == CACHE_S_SAMECACHE, "IOleCache_Cache with already loaded data format type should return CACHE_S_SAMECACHE instead of 0x%x\n", hr);
1273
1274     rcBounds.left = 0;
1275     rcBounds.top = 0;
1276     rcBounds.right = 100;
1277     rcBounds.bottom = 100;
1278     hdcMem = CreateCompatibleDC(NULL);
1279
1280     hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1281     ok_ole_success(hr, "IViewObject_Draw");
1282
1283     hr = IViewObject_Draw(pViewObject, DVASPECT_CONTENT, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1284     ok(hr == OLE_E_BLANK, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1285
1286     /* unload the cached storage object, causing it to be reloaded */
1287     hr = IOleCache2_DiscardCache(pOleCache, DISCARDCACHE_NOSAVE);
1288     ok_ole_success(hr, "IOleCache2_DiscardCache");
1289     hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1290     ok_ole_success(hr, "IViewObject_Draw");
1291
1292     /* unload the cached storage object, but don't allow it to be reloaded */
1293     hr = IPersistStorage_HandsOffStorage(pPS);
1294     ok_ole_success(hr, "IPersistStorage_HandsOffStorage");
1295     hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1296     ok_ole_success(hr, "IViewObject_Draw");
1297     hr = IOleCache2_DiscardCache(pOleCache, DISCARDCACHE_NOSAVE);
1298     ok_ole_success(hr, "IOleCache2_DiscardCache");
1299     hr = IViewObject_Draw(pViewObject, DVASPECT_ICON, -1, NULL, NULL, NULL, hdcMem, &rcBounds, NULL, draw_continue, 0xdeadbeef);
1300     ok(hr == OLE_E_BLANK, "IViewObject_Draw with uncached aspect should have returned OLE_E_BLANK instead of 0x%08x\n", hr);
1301
1302     DeleteDC(hdcMem);
1303
1304     todo_wine {
1305     hr = IOleCache_InitCache(pOleCache, &DataObject);
1306     ok(hr == CACHE_E_NOCACHE_UPDATED, "IOleCache_InitCache should have returned CACHE_E_NOCACHE_UPDATED instead of 0x%08x\n", hr);
1307     }
1308
1309     IPersistStorage_Release(pPS);
1310     IViewObject_Release(pViewObject);
1311     IOleCache_Release(pOleCache);
1312
1313     todo_wine {
1314     ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list);
1315     }
1316
1317     IStorage_Release(pStorage);
1318     ReleaseStgMedium(&stgmedium);
1319 }
1320
1321 static void test_default_handler(void)
1322 {
1323     HRESULT hr;
1324     IOleObject *pObject;
1325     IRunnableObject *pRunnableObject;
1326     IOleClientSite *pClientSite;
1327     IDataObject *pDataObject;
1328     SIZEL sizel;
1329     DWORD dwStatus;
1330     CLSID clsid;
1331     LPOLESTR pszUserType;
1332     LOGPALETTE palette;
1333     DWORD dwAdvConn;
1334     IMoniker *pMoniker;
1335     FORMATETC fmtetc;
1336     IOleInPlaceObject *pInPlaceObj;
1337     IEnumOLEVERB *pEnumVerbs;
1338     static const WCHAR wszUnknown[] = {'U','n','k','n','o','w','n',0};
1339     static const WCHAR wszHostName[] = {'W','i','n','e',' ','T','e','s','t',' ','P','r','o','g','r','a','m',0};
1340     static const WCHAR wszDelim[] = {'!',0};
1341
1342     hr = CoCreateInstance(&CLSID_WineTest, NULL, CLSCTX_INPROC_HANDLER, &IID_IOleObject, (void **)&pObject);
1343     ok(hr == REGDB_E_CLASSNOTREG, "CoCreateInstance should have failed with REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1344
1345     hr = OleCreateDefaultHandler(&CLSID_WineTest, NULL, &IID_IOleObject, (void **)&pObject);
1346     ok_ole_success(hr, "OleCreateDefaultHandler");
1347
1348     hr = IOleObject_QueryInterface(pObject, &IID_IOleInPlaceObject, (void **)&pInPlaceObj);
1349     ok(hr == E_NOINTERFACE, "IOleObject_QueryInterface(&IID_IOleInPlaceObject) should return E_NOINTERFACE instead of 0x%08x\n", hr);
1350
1351     hr = IOleObject_Advise(pObject, &AdviseSink, &dwAdvConn);
1352     ok_ole_success(hr, "IOleObject_Advise");
1353
1354     hr = IOleObject_Close(pObject, OLECLOSE_NOSAVE);
1355     ok_ole_success(hr, "IOleObject_Close");
1356
1357     /* FIXME: test IOleObject_EnumAdvise */
1358
1359     hr = IOleObject_EnumVerbs(pObject, &pEnumVerbs);
1360     ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_EnumVerbs should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1361
1362     hr = IOleObject_GetClientSite(pObject, &pClientSite);
1363     ok_ole_success(hr, "IOleObject_GetClientSite");
1364
1365     hr = IOleObject_GetClipboardData(pObject, 0, &pDataObject);
1366     ok(hr == OLE_E_NOTRUNNING,
1367        "IOleObject_GetClipboardData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n",
1368        hr);
1369
1370     hr = IOleObject_GetExtent(pObject, DVASPECT_CONTENT, &sizel);
1371     ok(hr == OLE_E_BLANK, "IOleObject_GetExtent should have returned OLE_E_BLANK instead of 0x%08x\n",
1372        hr);
1373
1374     hr = IOleObject_GetMiscStatus(pObject, DVASPECT_CONTENT, &dwStatus);
1375     todo_wine
1376     ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_GetMiscStatus should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1377
1378     hr = IOleObject_GetUserClassID(pObject, &clsid);
1379     ok_ole_success(hr, "IOleObject_GetUserClassID");
1380     ok(IsEqualCLSID(&clsid, &CLSID_WineTest), "clsid != CLSID_WineTest\n");
1381
1382     hr = IOleObject_GetUserType(pObject, USERCLASSTYPE_FULL, &pszUserType);
1383     todo_wine {
1384     ok_ole_success(hr, "IOleObject_GetUserType");
1385     ok(!lstrcmpW(pszUserType, wszUnknown), "Retrieved user type was wrong\n");
1386     }
1387
1388     hr = IOleObject_InitFromData(pObject, NULL, TRUE, 0);
1389     ok(hr == OLE_E_NOTRUNNING, "IOleObject_InitFromData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1390
1391     hr = IOleObject_IsUpToDate(pObject);
1392     ok(hr == OLE_E_NOTRUNNING, "IOleObject_IsUpToDate should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1393
1394     palette.palNumEntries = 1;
1395     palette.palVersion = 2;
1396     memset(&palette.palPalEntry[0], 0, sizeof(palette.palPalEntry[0]));
1397     hr = IOleObject_SetColorScheme(pObject, &palette);
1398     ok(hr == OLE_E_NOTRUNNING, "IOleObject_SetColorScheme should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1399
1400     sizel.cx = sizel.cy = 0;
1401     hr = IOleObject_SetExtent(pObject, DVASPECT_CONTENT, &sizel);
1402
1403     hr = IOleObject_SetHostNames(pObject, wszHostName, NULL);
1404     ok_ole_success(hr, "IOleObject_SetHostNames");
1405
1406     hr = CreateItemMoniker(wszDelim, wszHostName, &pMoniker);
1407     ok_ole_success(hr, "CreateItemMoniker");
1408     hr = IOleObject_SetMoniker(pObject, OLEWHICHMK_CONTAINER, pMoniker);
1409     ok_ole_success(hr, "IOleObject_SetMoniker");
1410     IMoniker_Release(pMoniker);
1411
1412     hr = IOleObject_GetMoniker(pObject, OLEGETMONIKER_ONLYIFTHERE, OLEWHICHMK_CONTAINER, &pMoniker);
1413     ok(hr == E_FAIL, "IOleObject_GetMoniker should have returned E_FAIL instead of 0x%08x\n", hr);
1414
1415     hr = IOleObject_Update(pObject);
1416     todo_wine
1417     ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_Update should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1418
1419     hr = IOleObject_QueryInterface(pObject, &IID_IDataObject, (void **)&pDataObject);
1420     ok_ole_success(hr, "IOleObject_QueryInterface");
1421
1422     fmtetc.cfFormat = CF_TEXT;
1423     fmtetc.ptd = NULL;
1424     fmtetc.dwAspect = DVASPECT_CONTENT;
1425     fmtetc.lindex = -1;
1426     fmtetc.tymed = TYMED_NULL;
1427     hr = IDataObject_DAdvise(pDataObject, &fmtetc, 0, &AdviseSink, &dwAdvConn);
1428     ok_ole_success(hr, "IDataObject_DAdvise");
1429
1430     fmtetc.cfFormat = CF_ENHMETAFILE;
1431     fmtetc.ptd = NULL;
1432     fmtetc.dwAspect = DVASPECT_CONTENT;
1433     fmtetc.lindex = -1;
1434     fmtetc.tymed = TYMED_ENHMF;
1435     hr = IDataObject_DAdvise(pDataObject, &fmtetc, 0, &AdviseSink, &dwAdvConn);
1436     ok_ole_success(hr, "IDataObject_DAdvise");
1437
1438     fmtetc.cfFormat = CF_ENHMETAFILE;
1439     fmtetc.ptd = NULL;
1440     fmtetc.dwAspect = DVASPECT_CONTENT;
1441     fmtetc.lindex = -1;
1442     fmtetc.tymed = TYMED_ENHMF;
1443     hr = IDataObject_QueryGetData(pDataObject, &fmtetc);
1444     todo_wine
1445     ok(hr == OLE_E_NOTRUNNING, "IDataObject_QueryGetData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1446
1447     fmtetc.cfFormat = CF_TEXT;
1448     fmtetc.ptd = NULL;
1449     fmtetc.dwAspect = DVASPECT_CONTENT;
1450     fmtetc.lindex = -1;
1451     fmtetc.tymed = TYMED_NULL;
1452     hr = IDataObject_QueryGetData(pDataObject, &fmtetc);
1453     todo_wine
1454     ok(hr == OLE_E_NOTRUNNING, "IDataObject_QueryGetData should have returned OLE_E_NOTRUNNING instead of 0x%08x\n", hr);
1455
1456     hr = IOleObject_QueryInterface(pObject, &IID_IRunnableObject, (void **)&pRunnableObject);
1457     ok_ole_success(hr, "IOleObject_QueryInterface");
1458
1459     hr = IRunnableObject_SetContainedObject(pRunnableObject, TRUE);
1460     ok_ole_success(hr, "IRunnableObject_SetContainedObject");
1461
1462     hr = IRunnableObject_Run(pRunnableObject, NULL);
1463     ok(hr == REGDB_E_CLASSNOTREG, "IOleObject_Run should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
1464
1465     hr = IOleObject_Close(pObject, OLECLOSE_NOSAVE);
1466     ok_ole_success(hr, "IOleObject_Close");
1467
1468     IRunnableObject_Release(pRunnableObject);
1469     IOleObject_Release(pObject);
1470 }
1471
1472 void test_runnable(void)
1473 {
1474     static const char *methods_query_runnable[] =
1475     {
1476         "OleObject_QueryInterface",
1477         "OleObjectRunnable_AddRef",
1478         "OleObjectRunnable_IsRunning",
1479         "OleObjectRunnable_Release",
1480         NULL
1481     };
1482
1483     static const char *methods_no_runnable[] =
1484     {
1485         "OleObject_QueryInterface",
1486         NULL
1487     };
1488
1489     IOleObject *object = (IOleObject *)&OleObject;
1490
1491     expected_method_list = methods_query_runnable;
1492     ok(OleIsRunning(object), "Object should be running\n");
1493     ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list);
1494
1495     g_isRunning = FALSE;
1496     expected_method_list = methods_query_runnable;
1497     ok(OleIsRunning(object) == FALSE, "Object should not be running\n");
1498     ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list);
1499
1500     g_showRunnable = FALSE;  /* QueryInterface(IID_IRunnableObject, ...) will fail */
1501     expected_method_list = methods_no_runnable;
1502     ok(OleIsRunning(object), "Object without IRunnableObject should be running\n");
1503     ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list);
1504
1505     g_isRunning = TRUE;
1506     g_showRunnable = TRUE;
1507 }
1508
1509 START_TEST(ole2)
1510 {
1511     DWORD dwRegister;
1512     IStorage *pStorage;
1513     STATSTG statstg;
1514     HRESULT hr;
1515
1516     CoInitialize(NULL);
1517
1518     hr = CoRegisterClassObject(&CLSID_Equation3, (IUnknown *)&OleObjectCF, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &dwRegister);
1519     ok_ole_success(hr, "CoRegisterClassObject");
1520
1521     hr = StgCreateDocfile(NULL, STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_DELETEONRELEASE, 0, &pStorage);
1522     ok_ole_success(hr, "StgCreateDocfile");
1523
1524     test_OleCreate(pStorage);
1525
1526     hr = IStorage_Stat(pStorage, &statstg, STATFLAG_NONAME);
1527     ok_ole_success(hr, "IStorage_Stat");
1528     ok(IsEqualCLSID(&CLSID_Equation3, &statstg.clsid), "Wrong CLSID in storage\n");
1529
1530     test_OleLoad(pStorage);
1531
1532     IStorage_Release(pStorage);
1533
1534     hr = CoRevokeClassObject(dwRegister);
1535     ok_ole_success(hr, "CoRevokeClassObject");
1536
1537     test_data_cache();
1538     test_default_handler();
1539     test_runnable();
1540
1541     CoUninitialize();
1542 }