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_addref_called
;
35 static int droptarget_release_called
;
37 /* helper macros to make tests a bit leaner */
38 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
40 static HRESULT WINAPI
DropTarget_QueryInterface(IDropTarget
* iface
, REFIID riid
,
43 trace("DropTarget_QueryInterface\n");
44 if (IsEqualIID(riid
, &IID_IUnknown
) ||
45 IsEqualIID(riid
, &IID_IDropTarget
))
47 IUnknown_AddRef(iface
);
55 static ULONG WINAPI
DropTarget_AddRef(IDropTarget
* iface
)
57 droptarget_addref_called
++;
61 static ULONG WINAPI
DropTarget_Release(IDropTarget
* iface
)
63 droptarget_release_called
++;
67 static HRESULT WINAPI
DropTarget_DragEnter(IDropTarget
* iface
,
68 IDataObject
* pDataObj
,
69 DWORD grfKeyState
, POINTL pt
,
75 static HRESULT WINAPI
DropTarget_DragOver(IDropTarget
* iface
,
83 static HRESULT WINAPI
DropTarget_DragLeave(IDropTarget
* iface
)
88 static HRESULT WINAPI
DropTarget_Drop(IDropTarget
* iface
,
89 IDataObject
* pDataObj
, DWORD grfKeyState
,
90 POINTL pt
, DWORD
* pdwEffect
)
95 static const IDropTargetVtbl DropTarget_VTbl
=
97 DropTarget_QueryInterface
,
100 DropTarget_DragEnter
,
102 DropTarget_DragLeave
,
106 static IDropTarget DropTarget
= { &DropTarget_VTbl
};
108 /** stub IDropSource **/
109 static HRESULT WINAPI
DropSource_QueryInterface(IDropSource
*iface
, REFIID riid
, void **ppObj
)
111 if (IsEqualIID(riid
, &IID_IUnknown
) ||
112 IsEqualIID(riid
, &IID_IDropSource
))
115 IDropSource_AddRef(iface
);
118 return E_NOINTERFACE
;
121 static ULONG WINAPI
DropSource_AddRef(IDropSource
*iface
)
126 static ULONG WINAPI
DropSource_Release(IDropSource
*iface
)
131 static HRESULT WINAPI
DropSource_QueryContinueDrag(
137 return DRAGDROP_S_DROP
;
140 static HRESULT WINAPI
DropSource_GiveFeedback(
144 return DRAGDROP_S_USEDEFAULTCURSORS
;
147 static const IDropSourceVtbl dropsource_vtbl
= {
148 DropSource_QueryInterface
,
151 DropSource_QueryContinueDrag
,
152 DropSource_GiveFeedback
155 static IDropSource DropSource
= { &dropsource_vtbl
};
157 /** IDataObject stub **/
158 static HRESULT WINAPI
DataObject_QueryInterface(
163 if (IsEqualIID(riid
, &IID_IUnknown
) ||
164 IsEqualIID(riid
, &IID_IDataObject
))
167 IDataObject_AddRef(iface
);
170 return E_NOINTERFACE
;
173 static ULONG WINAPI
DataObject_AddRef(IDataObject
*iface
)
178 static ULONG WINAPI
DataObject_Release(IDataObject
*iface
)
183 static HRESULT WINAPI
DataObject_GetData(
185 FORMATETC
*pformatetcIn
,
191 static HRESULT WINAPI
DataObject_GetDataHere(
193 FORMATETC
*pformatetc
,
199 static HRESULT WINAPI
DataObject_QueryGetData(
201 FORMATETC
*pformatetc
)
206 static HRESULT WINAPI
DataObject_GetCanonicalFormatEtc(
208 FORMATETC
*pformatectIn
,
209 FORMATETC
*pformatetcOut
)
214 static HRESULT WINAPI
DataObject_SetData(
216 FORMATETC
*pformatetc
,
223 static HRESULT WINAPI
DataObject_EnumFormatEtc(
226 IEnumFORMATETC
**ppenumFormatEtc
)
231 static HRESULT WINAPI
DataObject_DAdvise(
233 FORMATETC
*pformatetc
,
235 IAdviseSink
*pAdvSink
,
236 DWORD
*pdwConnection
)
241 static HRESULT WINAPI
DataObject_DUnadvise(
248 static HRESULT WINAPI
DataObject_EnumDAdvise(
250 IEnumSTATDATA
**ppenumAdvise
)
255 static const IDataObjectVtbl dataobject_vtbl
= {
256 DataObject_QueryInterface
,
260 DataObject_GetDataHere
,
261 DataObject_QueryGetData
,
262 DataObject_GetCanonicalFormatEtc
,
264 DataObject_EnumFormatEtc
,
266 DataObject_DUnadvise
,
267 DataObject_EnumDAdvise
270 static IDataObject DataObject
= { &dataobject_vtbl
};
272 static ATOM
register_dummy_class(void)
280 GetModuleHandle(NULL
),
282 LoadCursor(NULL
, IDC_ARROW
),
283 (HBRUSH
)(COLOR_BTNFACE
+1),
285 TEXT("WineOleTestClass"),
288 return RegisterClass(&wc
);
291 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_addref_called
== 0, "DropTarget_AddRef shouldn't have been called\n");
317 hr
= RegisterDragDrop(hwnd
, &DropTarget
);
318 ok_ole_success(hr
, "RegisterDragDrop");
319 ok(droptarget_addref_called
== 1, "DropTarget_AddRef should have been called once, not %d times\n", droptarget_addref_called
);
321 hr
= RegisterDragDrop(hwnd
, &DropTarget
);
322 ok(hr
== DRAGDROP_E_ALREADYREGISTERED
, "RegisterDragDrop with already registered hwnd should return DRAGDROP_E_ALREADYREGISTERED instead of 0x%08x\n", hr
);
324 ok(droptarget_release_called
== 0, "DropTarget_Release shouldn't have been called\n");
326 ok(droptarget_release_called
== 0, "DropTarget_Release shouldn't have been called\n");
328 hr
= RevokeDragDrop(hwnd
);
329 ok_ole_success(hr
, "RevokeDragDrop");
330 ok(droptarget_release_called
== 1 ||
331 broken(droptarget_release_called
== 0), /* NT4 */
332 "DropTarget_Release should have been called once, not %d times\n", droptarget_release_called
);
334 hr
= RevokeDragDrop(NULL
);
335 ok(hr
== DRAGDROP_E_INVALIDHWND
, "RevokeDragDrop with NULL hwnd should return DRAGDROP_E_INVALIDHWND instead of 0x%08x\n", hr
);
339 /* try to revoke with already destroyed window */
342 hwnd
= CreateWindowA("WineOleTestClass", "Test", 0,
343 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, NULL
,
346 hr
= RegisterDragDrop(hwnd
, &DropTarget
);
347 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
351 hr
= RevokeDragDrop(hwnd
);
352 ok(hr
== DRAGDROP_E_INVALIDHWND
, "got 0x%08x\n", hr
);
357 static void test_DoDragDrop(void)
363 hwnd
= CreateWindowA("WineOleTestClass", "Test", 0,
364 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, NULL
,
366 ok(IsWindow(hwnd
), "failed to create window\n");
368 hr
= OleInitialize(NULL
);
369 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
371 hr
= RegisterDragDrop(hwnd
, &DropTarget
);
372 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
374 /* incomplete arguments set */
375 hr
= DoDragDrop(NULL
, NULL
, 0, NULL
);
376 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
378 hr
= DoDragDrop(NULL
, &DropSource
, 0, NULL
);
379 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
381 hr
= DoDragDrop(&DataObject
, NULL
, 0, NULL
);
382 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
384 hr
= DoDragDrop(NULL
, NULL
, 0, &effect
);
385 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
387 hr
= DoDragDrop(&DataObject
, &DropSource
, 0, NULL
);
388 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
390 hr
= DoDragDrop(NULL
, &DropSource
, 0, &effect
);
391 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
393 hr
= DoDragDrop(&DataObject
, NULL
, 0, &effect
);
394 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
403 register_dummy_class();
405 test_Register_Revoke();