4 * Copyright 2007 Robert Shearman
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "wine/test.h"
34 static int droptarget_refs
;
36 /* helper macros to make tests a bit leaner */
37 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
39 static HRESULT WINAPI
DropTarget_QueryInterface(IDropTarget
* iface
, REFIID riid
,
42 ok(0, "DropTarget_QueryInterface() shouldn't be called\n");
43 if (IsEqualIID(riid
, &IID_IUnknown
) ||
44 IsEqualIID(riid
, &IID_IDropTarget
))
46 IDropTarget_AddRef(iface
);
54 static ULONG WINAPI
DropTarget_AddRef(IDropTarget
* iface
)
57 return droptarget_refs
;
60 static ULONG WINAPI
DropTarget_Release(IDropTarget
* iface
)
63 return droptarget_refs
;
66 static HRESULT WINAPI
DropTarget_DragEnter(IDropTarget
* iface
,
67 IDataObject
* pDataObj
,
68 DWORD grfKeyState
, POINTL pt
,
74 static HRESULT WINAPI
DropTarget_DragOver(IDropTarget
* iface
,
82 static HRESULT WINAPI
DropTarget_DragLeave(IDropTarget
* iface
)
87 static HRESULT WINAPI
DropTarget_Drop(IDropTarget
* iface
,
88 IDataObject
* pDataObj
, DWORD grfKeyState
,
89 POINTL pt
, DWORD
* pdwEffect
)
94 static const IDropTargetVtbl DropTarget_VTbl
=
96 DropTarget_QueryInterface
,
101 DropTarget_DragLeave
,
105 static IDropTarget DropTarget
= { &DropTarget_VTbl
};
107 /** stub IDropSource **/
108 static HRESULT WINAPI
DropSource_QueryInterface(IDropSource
*iface
, REFIID riid
, void **ppObj
)
110 if (IsEqualIID(riid
, &IID_IUnknown
) ||
111 IsEqualIID(riid
, &IID_IDropSource
))
114 IDropSource_AddRef(iface
);
117 return E_NOINTERFACE
;
120 static ULONG WINAPI
DropSource_AddRef(IDropSource
*iface
)
125 static ULONG WINAPI
DropSource_Release(IDropSource
*iface
)
130 static HRESULT WINAPI
DropSource_QueryContinueDrag(
136 return DRAGDROP_S_DROP
;
139 static HRESULT WINAPI
DropSource_GiveFeedback(
143 return DRAGDROP_S_USEDEFAULTCURSORS
;
146 static const IDropSourceVtbl dropsource_vtbl
= {
147 DropSource_QueryInterface
,
150 DropSource_QueryContinueDrag
,
151 DropSource_GiveFeedback
154 static IDropSource DropSource
= { &dropsource_vtbl
};
156 /** IDataObject stub **/
157 static HRESULT WINAPI
DataObject_QueryInterface(
162 if (IsEqualIID(riid
, &IID_IUnknown
) ||
163 IsEqualIID(riid
, &IID_IDataObject
))
166 IDataObject_AddRef(iface
);
169 return E_NOINTERFACE
;
172 static ULONG WINAPI
DataObject_AddRef(IDataObject
*iface
)
177 static ULONG WINAPI
DataObject_Release(IDataObject
*iface
)
182 static HRESULT WINAPI
DataObject_GetData(
184 FORMATETC
*pformatetcIn
,
190 static HRESULT WINAPI
DataObject_GetDataHere(
192 FORMATETC
*pformatetc
,
198 static HRESULT WINAPI
DataObject_QueryGetData(
200 FORMATETC
*pformatetc
)
205 static HRESULT WINAPI
DataObject_GetCanonicalFormatEtc(
207 FORMATETC
*pformatectIn
,
208 FORMATETC
*pformatetcOut
)
213 static HRESULT WINAPI
DataObject_SetData(
215 FORMATETC
*pformatetc
,
222 static HRESULT WINAPI
DataObject_EnumFormatEtc(
225 IEnumFORMATETC
**ppenumFormatEtc
)
230 static HRESULT WINAPI
DataObject_DAdvise(
232 FORMATETC
*pformatetc
,
234 IAdviseSink
*pAdvSink
,
235 DWORD
*pdwConnection
)
240 static HRESULT WINAPI
DataObject_DUnadvise(
247 static HRESULT WINAPI
DataObject_EnumDAdvise(
249 IEnumSTATDATA
**ppenumAdvise
)
254 static const IDataObjectVtbl dataobject_vtbl
= {
255 DataObject_QueryInterface
,
259 DataObject_GetDataHere
,
260 DataObject_QueryGetData
,
261 DataObject_GetCanonicalFormatEtc
,
263 DataObject_EnumFormatEtc
,
265 DataObject_DUnadvise
,
266 DataObject_EnumDAdvise
269 static IDataObject DataObject
= { &dataobject_vtbl
};
271 static ATOM
register_dummy_class(void)
279 GetModuleHandle(NULL
),
281 LoadCursor(NULL
, IDC_ARROW
),
282 (HBRUSH
)(COLOR_BTNFACE
+1),
284 TEXT("WineOleTestClass"),
287 return RegisterClass(&wc
);
290 static void test_Register_Revoke(void)
296 hwnd
= CreateWindowA("WineOleTestClass", "Test", 0,
297 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, NULL
,
300 hr
= RegisterDragDrop(hwnd
, &DropTarget
);
301 ok(hr
== E_OUTOFMEMORY
||
302 broken(hr
== CO_E_NOTINITIALIZED
), /* NT4 */
303 "RegisterDragDrop without OLE initialized should have returned E_OUTOFMEMORY instead of 0x%08x\n", hr
);
307 hr
= RegisterDragDrop(hwnd
, NULL
);
308 ok(hr
== E_INVALIDARG
, "RegisterDragDrop with NULL IDropTarget * should return E_INVALIDARG instead of 0x%08x\n", hr
);
310 hr
= RegisterDragDrop(NULL
, &DropTarget
);
311 ok(hr
== DRAGDROP_E_INVALIDHWND
, "RegisterDragDrop with NULL hwnd should return DRAGDROP_E_INVALIDHWND instead of 0x%08x\n", hr
);
313 hr
= RegisterDragDrop((HWND
)0xdeadbeef, &DropTarget
);
314 ok(hr
== DRAGDROP_E_INVALIDHWND
, "RegisterDragDrop with garbage hwnd should return DRAGDROP_E_INVALIDHWND instead of 0x%08x\n", hr
);
316 ok(droptarget_refs
== 0, "DropTarget refs should be zero not %d\n", droptarget_refs
);
317 hr
= RegisterDragDrop(hwnd
, &DropTarget
);
318 ok_ole_success(hr
, "RegisterDragDrop");
319 ok(droptarget_refs
>= 1, "DropTarget refs should be at least one\n");
321 prop
= GetPropA(hwnd
, "OleDropTargetInterface");
322 ok(prop
== &DropTarget
, "expected IDropTarget pointer %p, got %p\n", &DropTarget
, prop
);
324 hr
= RegisterDragDrop(hwnd
, &DropTarget
);
325 ok(hr
== DRAGDROP_E_ALREADYREGISTERED
, "RegisterDragDrop with already registered hwnd should return DRAGDROP_E_ALREADYREGISTERED instead of 0x%08x\n", hr
);
327 ok(droptarget_refs
>= 1, "DropTarget refs should be at least one\n");
329 ok(droptarget_refs
>= 1, "DropTarget refs should be at least one\n");
331 hr
= RevokeDragDrop(hwnd
);
332 ok_ole_success(hr
, "RevokeDragDrop");
333 ok(droptarget_refs
== 0 ||
334 broken(droptarget_refs
== 1), /* NT4 */
335 "DropTarget refs should be zero not %d\n", droptarget_refs
);
337 hr
= RevokeDragDrop(NULL
);
338 ok(hr
== DRAGDROP_E_INVALIDHWND
, "RevokeDragDrop with NULL hwnd should return DRAGDROP_E_INVALIDHWND instead of 0x%08x\n", hr
);
342 /* try to revoke with already destroyed window */
345 hwnd
= CreateWindowA("WineOleTestClass", "Test", 0,
346 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, NULL
,
349 hr
= RegisterDragDrop(hwnd
, &DropTarget
);
350 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
354 hr
= RevokeDragDrop(hwnd
);
355 ok(hr
== DRAGDROP_E_INVALIDHWND
, "got 0x%08x\n", hr
);
360 static void test_DoDragDrop(void)
366 hwnd
= CreateWindowA("WineOleTestClass", "Test", 0,
367 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, NULL
,
369 ok(IsWindow(hwnd
), "failed to create window\n");
371 hr
= OleInitialize(NULL
);
372 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
374 hr
= RegisterDragDrop(hwnd
, &DropTarget
);
375 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
377 /* incomplete arguments set */
378 hr
= DoDragDrop(NULL
, NULL
, 0, NULL
);
379 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
381 hr
= DoDragDrop(NULL
, &DropSource
, 0, NULL
);
382 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
384 hr
= DoDragDrop(&DataObject
, NULL
, 0, NULL
);
385 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
387 hr
= DoDragDrop(NULL
, NULL
, 0, &effect
);
388 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
390 hr
= DoDragDrop(&DataObject
, &DropSource
, 0, NULL
);
391 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
393 hr
= DoDragDrop(NULL
, &DropSource
, 0, &effect
);
394 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
396 hr
= DoDragDrop(&DataObject
, NULL
, 0, &effect
);
397 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
406 register_dummy_class();
408 test_Register_Revoke();