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)
297 hwnd = CreateWindowA("WineOleTestClass", "Test", 0,
298 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
301 hr = RegisterDragDrop(hwnd, &DropTarget);
302 ok(hr == E_OUTOFMEMORY ||
303 broken(hr == CO_E_NOTINITIALIZED), /* NT4 */
304 "RegisterDragDrop without OLE initialized should have returned E_OUTOFMEMORY instead of 0x%08x\n", hr);
308 hr = RegisterDragDrop(hwnd, NULL);
309 ok(hr == E_INVALIDARG, "RegisterDragDrop with NULL IDropTarget * should return E_INVALIDARG instead of 0x%08x\n", hr);
311 hr = RegisterDragDrop(NULL, &DropTarget);
312 ok(hr == DRAGDROP_E_INVALIDHWND, "RegisterDragDrop with NULL hwnd should return DRAGDROP_E_INVALIDHWND instead of 0x%08x\n", hr);
314 hr = RegisterDragDrop((HWND)0xdeadbeef, &DropTarget);
315 ok(hr == DRAGDROP_E_INVALIDHWND, "RegisterDragDrop with garbage hwnd should return DRAGDROP_E_INVALIDHWND instead of 0x%08x\n", hr);
317 ok(droptarget_addref_called == 0, "DropTarget_AddRef shouldn't have been called\n");
318 hr = RegisterDragDrop(hwnd, &DropTarget);
319 ok_ole_success(hr, "RegisterDragDrop");
320 ok(droptarget_addref_called == 1, "DropTarget_AddRef should have been called once, not %d times\n", droptarget_addref_called);
322 prop = GetPropA(hwnd, "OleDropTargetInterface");
323 ok(prop == &DropTarget, "expected IDropTarget pointer %p, got %p\n", &DropTarget, prop);
325 hr = RegisterDragDrop(hwnd, &DropTarget);
326 ok(hr == DRAGDROP_E_ALREADYREGISTERED, "RegisterDragDrop with already registered hwnd should return DRAGDROP_E_ALREADYREGISTERED instead of 0x%08x\n", hr);
328 ok(droptarget_release_called == 0, "DropTarget_Release shouldn't have been called\n");
330 ok(droptarget_release_called == 0, "DropTarget_Release shouldn't have been called\n");
332 hr = RevokeDragDrop(hwnd);
333 ok_ole_success(hr, "RevokeDragDrop");
334 ok(droptarget_release_called == 1 ||
335 broken(droptarget_release_called == 0), /* NT4 */
336 "DropTarget_Release should have been called once, not %d times\n", droptarget_release_called);
338 hr = RevokeDragDrop(NULL);
339 ok(hr == DRAGDROP_E_INVALIDHWND, "RevokeDragDrop with NULL hwnd should return DRAGDROP_E_INVALIDHWND instead of 0x%08x\n", hr);
343 /* try to revoke with already destroyed window */
346 hwnd = CreateWindowA("WineOleTestClass", "Test", 0,
347 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
350 hr = RegisterDragDrop(hwnd, &DropTarget);
351 ok(hr == S_OK, "got 0x%08x\n", hr);
355 hr = RevokeDragDrop(hwnd);
356 ok(hr == DRAGDROP_E_INVALIDHWND, "got 0x%08x\n", hr);
361 static void test_DoDragDrop(void)
367 hwnd = CreateWindowA("WineOleTestClass", "Test", 0,
368 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
370 ok(IsWindow(hwnd), "failed to create window\n");
372 hr = OleInitialize(NULL);
373 ok(hr == S_OK, "got 0x%08x\n", hr);
375 hr = RegisterDragDrop(hwnd, &DropTarget);
376 ok(hr == S_OK, "got 0x%08x\n", hr);
378 /* incomplete arguments set */
379 hr = DoDragDrop(NULL, NULL, 0, NULL);
380 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
382 hr = DoDragDrop(NULL, &DropSource, 0, NULL);
383 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
385 hr = DoDragDrop(&DataObject, NULL, 0, NULL);
386 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
388 hr = DoDragDrop(NULL, NULL, 0, &effect);
389 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
391 hr = DoDragDrop(&DataObject, &DropSource, 0, NULL);
392 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
394 hr = DoDragDrop(NULL, &DropSource, 0, &effect);
395 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
397 hr = DoDragDrop(&DataObject, NULL, 0, &effect);
398 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
407 register_dummy_class();
409 test_Register_Revoke();