Release 1.6-rc2.
[wine/testsucceed.git] / dlls / ole32 / tests / dragdrop.c
blob10385bdac4e9c9db4cfccb9cdb48bf0585a14cf3
1 /*
2 * Drag and Drop Tests
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
21 #define _WIN32_DCOM
22 #define COBJMACROS
23 #define CONST_VTABLE
25 #include <stdarg.h>
26 #include <stdio.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "objbase.h"
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,
40 void** ppvObject)
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);
47 *ppvObject = iface;
48 return S_OK;
50 *ppvObject = NULL;
51 return E_NOINTERFACE;
54 static ULONG WINAPI DropTarget_AddRef(IDropTarget* iface)
56 droptarget_refs++;
57 return droptarget_refs;
60 static ULONG WINAPI DropTarget_Release(IDropTarget* iface)
62 droptarget_refs--;
63 return droptarget_refs;
66 static HRESULT WINAPI DropTarget_DragEnter(IDropTarget* iface,
67 IDataObject* pDataObj,
68 DWORD grfKeyState, POINTL pt,
69 DWORD* pdwEffect)
71 return E_NOTIMPL;
74 static HRESULT WINAPI DropTarget_DragOver(IDropTarget* iface,
75 DWORD grfKeyState,
76 POINTL pt,
77 DWORD* pdwEffect)
79 return E_NOTIMPL;
82 static HRESULT WINAPI DropTarget_DragLeave(IDropTarget* iface)
84 return E_NOTIMPL;
87 static HRESULT WINAPI DropTarget_Drop(IDropTarget* iface,
88 IDataObject* pDataObj, DWORD grfKeyState,
89 POINTL pt, DWORD* pdwEffect)
91 return E_NOTIMPL;
94 static const IDropTargetVtbl DropTarget_VTbl =
96 DropTarget_QueryInterface,
97 DropTarget_AddRef,
98 DropTarget_Release,
99 DropTarget_DragEnter,
100 DropTarget_DragOver,
101 DropTarget_DragLeave,
102 DropTarget_Drop
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))
113 *ppObj = iface;
114 IDropSource_AddRef(iface);
115 return S_OK;
117 return E_NOINTERFACE;
120 static ULONG WINAPI DropSource_AddRef(IDropSource *iface)
122 return 2;
125 static ULONG WINAPI DropSource_Release(IDropSource *iface)
127 return 1;
130 static HRESULT WINAPI DropSource_QueryContinueDrag(
131 IDropSource *iface,
132 BOOL fEscapePressed,
133 DWORD grfKeyState)
135 /* always drop */
136 return DRAGDROP_S_DROP;
139 static HRESULT WINAPI DropSource_GiveFeedback(
140 IDropSource *iface,
141 DWORD dwEffect)
143 return DRAGDROP_S_USEDEFAULTCURSORS;
146 static const IDropSourceVtbl dropsource_vtbl = {
147 DropSource_QueryInterface,
148 DropSource_AddRef,
149 DropSource_Release,
150 DropSource_QueryContinueDrag,
151 DropSource_GiveFeedback
154 static IDropSource DropSource = { &dropsource_vtbl };
156 /** IDataObject stub **/
157 static HRESULT WINAPI DataObject_QueryInterface(
158 IDataObject *iface,
159 REFIID riid,
160 void **pObj)
162 if (IsEqualIID(riid, &IID_IUnknown) ||
163 IsEqualIID(riid, &IID_IDataObject))
165 *pObj = iface;
166 IDataObject_AddRef(iface);
167 return S_OK;
169 return E_NOINTERFACE;
172 static ULONG WINAPI DataObject_AddRef(IDataObject *iface)
174 return 2;
177 static ULONG WINAPI DataObject_Release(IDataObject *iface)
179 return 1;
182 static HRESULT WINAPI DataObject_GetData(
183 IDataObject *iface,
184 FORMATETC *pformatetcIn,
185 STGMEDIUM *pmedium)
187 return E_NOTIMPL;
190 static HRESULT WINAPI DataObject_GetDataHere(
191 IDataObject *iface,
192 FORMATETC *pformatetc,
193 STGMEDIUM *pmedium)
195 return E_NOTIMPL;
198 static HRESULT WINAPI DataObject_QueryGetData(
199 IDataObject *iface,
200 FORMATETC *pformatetc)
202 return S_OK;
205 static HRESULT WINAPI DataObject_GetCanonicalFormatEtc(
206 IDataObject *iface,
207 FORMATETC *pformatectIn,
208 FORMATETC *pformatetcOut)
210 return E_NOTIMPL;
213 static HRESULT WINAPI DataObject_SetData(
214 IDataObject *iface,
215 FORMATETC *pformatetc,
216 STGMEDIUM *pmedium,
217 BOOL fRelease)
219 return E_NOTIMPL;
222 static HRESULT WINAPI DataObject_EnumFormatEtc(
223 IDataObject *iface,
224 DWORD dwDirection,
225 IEnumFORMATETC **ppenumFormatEtc)
227 return S_OK;
230 static HRESULT WINAPI DataObject_DAdvise(
231 IDataObject *iface,
232 FORMATETC *pformatetc,
233 DWORD advf,
234 IAdviseSink *pAdvSink,
235 DWORD *pdwConnection)
237 return E_NOTIMPL;
240 static HRESULT WINAPI DataObject_DUnadvise(
241 IDataObject *iface,
242 DWORD dwConnection)
244 return E_NOTIMPL;
247 static HRESULT WINAPI DataObject_EnumDAdvise(
248 IDataObject *iface,
249 IEnumSTATDATA **ppenumAdvise)
251 return E_NOTIMPL;
254 static const IDataObjectVtbl dataobject_vtbl = {
255 DataObject_QueryInterface,
256 DataObject_AddRef,
257 DataObject_Release,
258 DataObject_GetData,
259 DataObject_GetDataHere,
260 DataObject_QueryGetData,
261 DataObject_GetCanonicalFormatEtc,
262 DataObject_SetData,
263 DataObject_EnumFormatEtc,
264 DataObject_DAdvise,
265 DataObject_DUnadvise,
266 DataObject_EnumDAdvise
269 static IDataObject DataObject = { &dataobject_vtbl };
271 static ATOM register_dummy_class(void)
273 WNDCLASS wc =
276 DefWindowProc,
279 GetModuleHandle(NULL),
280 NULL,
281 LoadCursor(NULL, IDC_ARROW),
282 (HBRUSH)(COLOR_BTNFACE+1),
283 NULL,
284 TEXT("WineOleTestClass"),
287 return RegisterClass(&wc);
290 static void test_Register_Revoke(void)
292 HANDLE prop;
293 HRESULT hr;
294 HWND hwnd;
296 hwnd = CreateWindowA("WineOleTestClass", "Test", 0,
297 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
298 NULL, NULL, 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);
305 OleInitialize(NULL);
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");
328 OleUninitialize();
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);
340 DestroyWindow(hwnd);
342 /* try to revoke with already destroyed window */
343 OleInitialize(NULL);
345 hwnd = CreateWindowA("WineOleTestClass", "Test", 0,
346 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
347 NULL, NULL, NULL);
349 hr = RegisterDragDrop(hwnd, &DropTarget);
350 ok(hr == S_OK, "got 0x%08x\n", hr);
352 DestroyWindow(hwnd);
354 hr = RevokeDragDrop(hwnd);
355 ok(hr == DRAGDROP_E_INVALIDHWND, "got 0x%08x\n", hr);
357 OleUninitialize();
360 static void test_DoDragDrop(void)
362 DWORD effect;
363 HRESULT hr;
364 HWND hwnd;
366 hwnd = CreateWindowA("WineOleTestClass", "Test", 0,
367 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
368 NULL, NULL, 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);
399 OleUninitialize();
401 DestroyWindow(hwnd);
404 START_TEST(dragdrop)
406 register_dummy_class();
408 test_Register_Revoke();
409 test_DoDragDrop();