ReactOS 0.4.15-dev-8207-gd73a838
defaulthandler.c File Reference
#include <stdarg.h>
#include <stdio.h>
#include "windef.h"
#include "winbase.h"
#include "objbase.h"
#include "wine/test.h"
Include dependency graph for defaulthandler.c:

Go to the source code of this file.

Classes

struct  ole_stream_header_t
 

Macros

#define COBJMACROS
 
#define CONST_VTABLE
 
#define DEFINE_EXPECT(func)    static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
 
#define SET_EXPECT(func)    expect_ ## func = TRUE
 
#define CHECK_EXPECT2(func)
 
#define CHECK_EXPECT(func)
 
#define CHECK_CALLED(func)
 
#define CHECK_NOT_CALLED(func)
 

Functions

 DEFINE_EXPECT (CF_QueryInterface_ClassFactory)
 
 DEFINE_EXPECT (CF_CreateInstance)
 
 DEFINE_EXPECT (CF_QueryInterface_IMarshal)
 
static HRESULT create_storage (IStorage **stg)
 
static void test_olestream (void)
 
static HRESULT WINAPI test_class_QueryInterface (IUnknown *iface, REFIID riid, void **ppv)
 
static ULONG WINAPI test_class_AddRef (IUnknown *iface)
 
static ULONG WINAPI test_class_Release (IUnknown *iface)
 
static HRESULT WINAPI ClassFactory_QueryInterface (IClassFactory *iface, REFIID riid, void **ppv)
 
static ULONG WINAPI ClassFactory_AddRef (IClassFactory *iface)
 
static ULONG WINAPI ClassFactory_Release (IClassFactory *iface)
 
static HRESULT WINAPI ClassFactory_CreateInstance (IClassFactory *iface, IUnknown *pUnkOuter, REFIID riid, void **ppv)
 
static HRESULT WINAPI ClassFactory_LockServer (IClassFactory *iface, BOOL fLock)
 
static void test_default_handler_run (void)
 
 START_TEST (defaulthandler)
 

Variables

static const IUnknownVtbl test_class_vtbl
 
static IUnknown test_class = { &test_class_vtbl }
 
static const IClassFactoryVtbl ClassFactoryVtbl
 
static IClassFactory ClassFactory = { &ClassFactoryVtbl }
 

Macro Definition Documentation

◆ CHECK_CALLED

#define CHECK_CALLED (   func)
Value:
do { \
ok(called_ ## func, "expected " #func "\n"); \
expect_ ## func = called_ ## func = FALSE; \
}while(0)
#define FALSE
Definition: types.h:117
GLenum func
Definition: glext.h:6028
#define expect_(expected, got, precision)
Definition: font.c:29

Definition at line 51 of file defaulthandler.c.

◆ CHECK_EXPECT

#define CHECK_EXPECT (   func)
Value:
do { \
CHECK_EXPECT2(func); \
expect_ ## func = FALSE; \
}while(0)

Definition at line 45 of file defaulthandler.c.

◆ CHECK_EXPECT2

#define CHECK_EXPECT2 (   func)
Value:
do { \
ok(expect_ ##func, "unexpected call " #func "\n"); \
called_ ## func = TRUE; \
}while(0)
#define TRUE
Definition: types.h:120

Definition at line 39 of file defaulthandler.c.

◆ CHECK_NOT_CALLED

#define CHECK_NOT_CALLED (   func)
Value:
do { \
ok(!called_ ## func, "unexpected " #func "\n"); \
expect_ ## func = called_ ## func = FALSE; \
}while(0)

Definition at line 57 of file defaulthandler.c.

◆ COBJMACROS

#define COBJMACROS

Definition at line 21 of file defaulthandler.c.

◆ CONST_VTABLE

#define CONST_VTABLE

Definition at line 22 of file defaulthandler.c.

◆ DEFINE_EXPECT

#define DEFINE_EXPECT (   func)     static BOOL expect_ ## func = FALSE, called_ ## func = FALSE

Definition at line 33 of file defaulthandler.c.

◆ SET_EXPECT

#define SET_EXPECT (   func)     expect_ ## func = TRUE

Definition at line 36 of file defaulthandler.c.

Function Documentation

◆ ClassFactory_AddRef()

static ULONG WINAPI ClassFactory_AddRef ( IClassFactory iface)
static

Definition at line 190 of file defaulthandler.c.

191{
192 return 2;
193}

◆ ClassFactory_CreateInstance()

static HRESULT WINAPI ClassFactory_CreateInstance ( IClassFactory iface,
IUnknown pUnkOuter,
REFIID  riid,
void **  ppv 
)
static

Definition at line 200 of file defaulthandler.c.

202{
204
205 ok(pUnkOuter == NULL, "pUnkOuter != NULL\n");
208 *ppv = NULL;
209 return E_NOINTERFACE;
210 }
211
212 *ppv = &test_class;
213 return S_OK;
214}
#define ok(value,...)
Definition: atltest.h:57
const GUID IID_IUnknown
#define NULL
Definition: types.h:112
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define todo_wine
Definition: custom.c:79
static IUnknown test_class
#define CHECK_EXPECT(func)
const GUID IID_IOleObject
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
static __inline const char * wine_dbgstr_guid(const GUID *id)
Definition: debug.h:197
static HRESULT WINAPI CF_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
Definition: urlmon_main.c:306
#define E_NOINTERFACE
Definition: winerror.h:2364

◆ ClassFactory_LockServer()

static HRESULT WINAPI ClassFactory_LockServer ( IClassFactory iface,
BOOL  fLock 
)
static

Definition at line 216 of file defaulthandler.c.

217{
218 ok(0, "unexpected call\n");
219 return E_NOTIMPL;
220}
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ ClassFactory_QueryInterface()

static HRESULT WINAPI ClassFactory_QueryInterface ( IClassFactory iface,
REFIID  riid,
void **  ppv 
)
static

Definition at line 170 of file defaulthandler.c.

171{
173 *ppv = iface;
174 return S_OK;
175 }else if(IsEqualGUID(riid, &IID_IMarshal)) {
176 CHECK_EXPECT(CF_QueryInterface_IMarshal);
177 *ppv = NULL;
178 return E_NOINTERFACE;
179 }else if(IsEqualGUID(riid, &IID_IClassFactory)) {
180 CHECK_EXPECT(CF_QueryInterface_ClassFactory);
181 *ppv = iface;
182 return S_OK;
183 }
184
185 ok(0, "unexpected interface: %s\n", wine_dbgstr_guid(riid));
186 *ppv = NULL;
187 return E_NOINTERFACE;
188}
const GUID IID_IClassFactory

◆ ClassFactory_Release()

static ULONG WINAPI ClassFactory_Release ( IClassFactory iface)
static

Definition at line 195 of file defaulthandler.c.

196{
197 return 1;
198}

◆ create_storage()

static HRESULT create_storage ( IStorage **  stg)
static

Definition at line 67 of file defaulthandler.c.

68{
69 HRESULT hr;
70 ILockBytes *lock_bytes;
71
72 hr = CreateILockBytesOnHGlobal(NULL, TRUE, &lock_bytes);
73 if(SUCCEEDED(hr))
74 {
77 ILockBytes_Release(lock_bytes);
78 }
79 return hr;
80}
HRESULT WINAPI StgCreateDocfileOnILockBytes(ILockBytes *plkbyt, DWORD grfMode, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8946
#define SUCCEEDED(hr)
Definition: intsafe.h:50
HRESULT WINAPI CreateILockBytesOnHGlobal(HGLOBAL global, BOOL delete_on_release, ILockBytes **ret)
Definition: memlockbytes.c:98
#define STGM_CREATE
Definition: objbase.h:926
#define STGM_READWRITE
Definition: objbase.h:919
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:923
HRESULT hr
Definition: shlfolder.c:183

◆ DEFINE_EXPECT() [1/3]

DEFINE_EXPECT ( CF_CreateInstance  )

◆ DEFINE_EXPECT() [2/3]

DEFINE_EXPECT ( CF_QueryInterface_ClassFactory  )

◆ DEFINE_EXPECT() [3/3]

DEFINE_EXPECT ( CF_QueryInterface_IMarshal  )

◆ START_TEST()

START_TEST ( defaulthandler  )

Definition at line 311 of file defaulthandler.c.

312{
314
317
319}
HRESULT WINAPI DECLSPEC_HOTPATCH OleInitialize(LPVOID reserved)
Definition: ole2.c:169
void WINAPI DECLSPEC_HOTPATCH OleUninitialize(void)
Definition: ole2.c:230
static void test_olestream(void)
static void test_default_handler_run(void)

◆ test_class_AddRef()

static ULONG WINAPI test_class_AddRef ( IUnknown iface)
static

Definition at line 152 of file defaulthandler.c.

153{
154 return 2;
155}

◆ test_class_QueryInterface()

static HRESULT WINAPI test_class_QueryInterface ( IUnknown iface,
REFIID  riid,
void **  ppv 
)
static

Definition at line 137 of file defaulthandler.c.

138{
140 *ppv = iface;
141 return S_OK;
142 }else if(IsEqualGUID(riid, &IID_IOleObject)) {
143 ok(0, "unexpected query for IOleObject interface\n");
144 *ppv = NULL;
145 return E_NOINTERFACE;
146 }
147
148 *ppv = NULL;
149 return E_NOINTERFACE;
150}

◆ test_class_Release()

static ULONG WINAPI test_class_Release ( IUnknown iface)
static

Definition at line 157 of file defaulthandler.c.

158{
159 return 1;
160}

◆ test_default_handler_run()

static void test_default_handler_run ( void  )
static

Definition at line 232 of file defaulthandler.c.

233{
234 const CLSID test_server_clsid = {0x0f77e570,0x80c3,0x11e2,{0x9e,0x96,0x08,0x00,0x20,0x0c,0x9a,0x66}};
235
236 IUnknown *unk;
237 IRunnableObject *ro;
238 IOleObject *oleobj;
239 IPersistStorage *persist;
240 DWORD class_reg;
242
243 if(!GetProcAddress(GetModuleHandleA("ole32"), "CoRegisterSurrogateEx")) {
244 win_skip("skipping OleCreateDefaultHandler tests\n");
245 return;
246 }
247
248 hres = CoRegisterClassObject(&test_server_clsid, (IUnknown*)&ClassFactory,
249 CLSCTX_INPROC_SERVER, 0, &class_reg);
250 ok(hres == S_OK, "CoRegisterClassObject failed: %x\n", hres);
251
252 hres = OleCreateDefaultHandler(&test_server_clsid, NULL, &IID_IUnknown, (void**)&unk);
253 ok(hres == S_OK, "OleCreateDefaultHandler failed: %x\n", hres);
254
255 hres = IUnknown_QueryInterface(unk, &IID_IRunnableObject, (void**)&ro);
256 ok(hres == S_OK, "QueryInterface(IRunnableObject) failed: %x\n", hres);
257 IUnknown_Release(unk);
258
259 hres = IRunnableObject_Run(ro, NULL);
260 ok(hres == REGDB_E_CLASSNOTREG, "Run returned: %x, expected REGDB_E_CLASSNOTREG\n", hres);
261 IRunnableObject_Release(ro);
262
263 SET_EXPECT(CF_QueryInterface_IMarshal);
264 CoRevokeClassObject(class_reg);
265 todo_wine CHECK_CALLED(CF_QueryInterface_IMarshal);
266
267 hres = CoRegisterClassObject(&test_server_clsid, (IUnknown*)&ClassFactory,
268 CLSCTX_LOCAL_SERVER, 0, &class_reg);
269 ok(hres == S_OK, "CoRegisterClassObject failed: %x\n", hres);
270
271 hres = OleCreateDefaultHandler(&test_server_clsid, NULL, &IID_IUnknown, (void**)&unk);
272 ok(hres == S_OK, "OleCreateDefaultHandler failed: %x\n", hres);
273
274 hres = IUnknown_QueryInterface(unk, &IID_IOleObject, (void**)&oleobj);
275 ok(hres == S_OK, "QueryInterface(IID_IOleObject) failed: %x\n", hres);
276
277 hres = IOleObject_QueryInterface(oleobj, &IID_IPersistStorage, (void**)&persist);
278 ok(hres == S_OK, "QueryInterface(IID_IPersistStorage) failed: %x\n", hres);
279 IPersistStorage_Release(persist);
280 IOleObject_Release(oleobj);
281
282 hres = IUnknown_QueryInterface(unk, &IID_IRunnableObject, (void**)&ro);
283 ok(hres == S_OK, "QueryInterface(IRunnableObject) failed: %x\n", hres);
284 IUnknown_Release(unk);
285
286 SET_EXPECT(CF_QueryInterface_ClassFactory);
288 hres = IRunnableObject_Run(ro, NULL);
290 ok(hres == S_OK, "Run failed: %x\n", hres);
291 CHECK_CALLED(CF_QueryInterface_ClassFactory);
293 IRunnableObject_Release(ro);
294
295 SET_EXPECT(CF_QueryInterface_ClassFactory);
297 hres = CoCreateInstance(&test_server_clsid, NULL, CLSCTX_LOCAL_SERVER,
298 &IID_IOleObject, (void**)&oleobj);
300 ok(hres == REGDB_E_CLASSNOTREG, "expected REGDB_E_CLASSNOTREG, got %x\n", hres);
302 CHECK_NOT_CALLED(CF_QueryInterface_ClassFactory);
305
306 SET_EXPECT(CF_QueryInterface_IMarshal);
307 CoRevokeClassObject(class_reg);
308 todo_wine CHECK_CALLED(CF_QueryInterface_IMarshal);
309}
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
HRESULT WINAPI CoRegisterClassObject(REFCLSID rclsid, LPUNKNOWN pUnk, DWORD dwClsContext, DWORD flags, LPDWORD lpdwRegister)
Definition: compobj.c:2897
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
HRESULT WINAPI DECLSPEC_HOTPATCH CoRevokeClassObject(DWORD dwRegister)
Definition: compobj.c:1086
HRESULT WINAPI OleCreateDefaultHandler(REFCLSID clsid, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObj)
unsigned long DWORD
Definition: ntddk_ex.h:95
HRESULT hres
Definition: protocol.c:465
#define SET_EXPECT(func)
#define CHECK_CALLED(func)
#define CHECK_NOT_CALLED(func)
const GUID IID_IRunnableObject
const GUID IID_IPersistStorage
#define win_skip
Definition: test.h:163
#define REGDB_E_CLASSNOTREG
Definition: winerror.h:2696

Referenced by START_TEST().

◆ test_olestream()

static void test_olestream ( void  )
static

Definition at line 91 of file defaulthandler.c.

92{
93 HRESULT hr;
94 const CLSID non_existent_class = {0xa5f1772f, 0x3772, 0x490f, {0x9e, 0xc6, 0x77, 0x13, 0xe8, 0xb3, 0x4b, 0x5d}};
95 IOleObject *ole_obj;
96 IPersistStorage *persist;
97 IStorage *stg;
98 IStream *stm;
99 static const WCHAR olestream[] = {1,'O','l','e',0};
100 ULONG read;
102
103 hr = create_storage(&stg);
104 ok(hr == S_OK, "got %08x\n", hr);
105
106 hr = IStorage_OpenStream(stg, olestream, NULL, STGM_SHARE_EXCLUSIVE | STGM_READ, 0, &stm);
107 ok(hr == STG_E_FILENOTFOUND, "got %08x\n", hr);
108
109 hr = OleCreateDefaultHandler(&non_existent_class, 0, &IID_IOleObject, (void**)&ole_obj);
110 ok(hr == S_OK, "got %08x\n", hr);
111
112 hr = IOleObject_QueryInterface(ole_obj, &IID_IPersistStorage, (void**)&persist);
113 ok(hr == S_OK, "got %08x\n", hr);
114
115 hr = IPersistStorage_InitNew(persist, stg);
116 ok(hr == S_OK, "got %08x\n", hr);
117
118 hr = IStorage_OpenStream(stg, olestream, NULL, STGM_SHARE_EXCLUSIVE | STGM_READ, 0, &stm);
119 ok(hr == S_OK, "got %08x\n", hr);
120 hr = IStream_Read(stm, &header, sizeof(header), &read);
121 ok(hr == S_OK, "got %08x\n", hr);
122 ok(read == sizeof(header), "read %d\n", read);
123 ok(header.version == 0x02000001, "got version %08x\n", header.version);
124 ok(header.flags == 0x0, "got flags %08x\n", header.flags);
125 ok(header.link_update_opt == 0x0, "got link update option %08x\n", header.link_update_opt);
126 ok(header.res == 0x0, "got reserved %08x\n", header.res);
127 ok(header.moniker_size == 0x0, "got moniker size %08x\n", header.moniker_size);
128
129 IStream_Release(stm);
130
131 IPersistStorage_Release(persist);
132 IOleObject_Release(ole_obj);
133
134 IStorage_Release(stg);
135}
#define read
Definition: acwin.h:96
static HGLOBAL create_storage(void)
Definition: clipboard.c:1289
#define STGM_READ
Definition: objbase.h:917
uint32_t ULONG
Definition: typedefs.h:59
#define STG_E_FILENOTFOUND
Definition: winerror.h:2565
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

Variable Documentation

◆ ClassFactory

Definition at line 230 of file defaulthandler.c.

◆ ClassFactoryVtbl

const IClassFactoryVtbl ClassFactoryVtbl
static
Initial value:
= {
}
static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter, REFIID riid, void **ppv)
static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)

Definition at line 222 of file defaulthandler.c.

◆ test_class

IUnknown test_class = { &test_class_vtbl }
static

Definition at line 168 of file defaulthandler.c.

Referenced by ClassFactory_CreateInstance().

◆ test_class_vtbl

const IUnknownVtbl test_class_vtbl
static
Initial value:
= {
}
static ULONG WINAPI test_class_Release(IUnknown *iface)
static HRESULT WINAPI test_class_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
static ULONG WINAPI test_class_AddRef(IUnknown *iface)

Definition at line 162 of file defaulthandler.c.