ole32: Use the cached information in BlockChainStream_GetCount.
[wine/multimedia.git] / dlls / ole32 / tests / dragdrop.c
blobe098354913cab2c32909443f66b0aef593386f9f
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_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,
41 void** ppvObject)
43 trace("DropTarget_QueryInterface\n");
44 if (IsEqualIID(riid, &IID_IUnknown) ||
45 IsEqualIID(riid, &IID_IDropTarget))
47 IUnknown_AddRef(iface);
48 *ppvObject = iface;
49 return S_OK;
51 *ppvObject = NULL;
52 return E_NOINTERFACE;
55 static ULONG WINAPI DropTarget_AddRef(IDropTarget* iface)
57 droptarget_addref_called++;
58 return 2;
61 static ULONG WINAPI DropTarget_Release(IDropTarget* iface)
63 droptarget_release_called++;
64 return 1;
67 static HRESULT WINAPI DropTarget_DragEnter(IDropTarget* iface,
68 IDataObject* pDataObj,
69 DWORD grfKeyState, POINTL pt,
70 DWORD* pdwEffect)
72 return E_NOTIMPL;
75 static HRESULT WINAPI DropTarget_DragOver(IDropTarget* iface,
76 DWORD grfKeyState,
77 POINTL pt,
78 DWORD* pdwEffect)
80 return E_NOTIMPL;
83 static HRESULT WINAPI DropTarget_DragLeave(IDropTarget* iface)
85 return E_NOTIMPL;
88 static HRESULT WINAPI DropTarget_Drop(IDropTarget* iface,
89 IDataObject* pDataObj, DWORD grfKeyState,
90 POINTL pt, DWORD* pdwEffect)
92 return E_NOTIMPL;
95 static const IDropTargetVtbl DropTarget_VTbl =
97 DropTarget_QueryInterface,
98 DropTarget_AddRef,
99 DropTarget_Release,
100 DropTarget_DragEnter,
101 DropTarget_DragOver,
102 DropTarget_DragLeave,
103 DropTarget_Drop
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))
114 *ppObj = iface;
115 IDropSource_AddRef(iface);
116 return S_OK;
118 return E_NOINTERFACE;
121 static ULONG WINAPI DropSource_AddRef(IDropSource *iface)
123 return 2;
126 static ULONG WINAPI DropSource_Release(IDropSource *iface)
128 return 1;
131 static HRESULT WINAPI DropSource_QueryContinueDrag(
132 IDropSource *iface,
133 BOOL fEscapePressed,
134 DWORD grfKeyState)
136 /* always drop */
137 return DRAGDROP_S_DROP;
140 static HRESULT WINAPI DropSource_GiveFeedback(
141 IDropSource *iface,
142 DWORD dwEffect)
144 return DRAGDROP_S_USEDEFAULTCURSORS;
147 static const IDropSourceVtbl dropsource_vtbl = {
148 DropSource_QueryInterface,
149 DropSource_AddRef,
150 DropSource_Release,
151 DropSource_QueryContinueDrag,
152 DropSource_GiveFeedback
155 static IDropSource DropSource = { &dropsource_vtbl };
157 /** IDataObject stub **/
158 static HRESULT WINAPI DataObject_QueryInterface(
159 IDataObject *iface,
160 REFIID riid,
161 void **pObj)
163 if (IsEqualIID(riid, &IID_IUnknown) ||
164 IsEqualIID(riid, &IID_IDataObject))
166 *pObj = iface;
167 IDataObject_AddRef(iface);
168 return S_OK;
170 return E_NOINTERFACE;
173 static ULONG WINAPI DataObject_AddRef(IDataObject *iface)
175 return 2;
178 static ULONG WINAPI DataObject_Release(IDataObject *iface)
180 return 1;
183 static HRESULT WINAPI DataObject_GetData(
184 IDataObject *iface,
185 FORMATETC *pformatetcIn,
186 STGMEDIUM *pmedium)
188 return E_NOTIMPL;
191 static HRESULT WINAPI DataObject_GetDataHere(
192 IDataObject *iface,
193 FORMATETC *pformatetc,
194 STGMEDIUM *pmedium)
196 return E_NOTIMPL;
199 static HRESULT WINAPI DataObject_QueryGetData(
200 IDataObject *iface,
201 FORMATETC *pformatetc)
203 return S_OK;
206 static HRESULT WINAPI DataObject_GetCanonicalFormatEtc(
207 IDataObject *iface,
208 FORMATETC *pformatectIn,
209 FORMATETC *pformatetcOut)
211 return E_NOTIMPL;
214 static HRESULT WINAPI DataObject_SetData(
215 IDataObject *iface,
216 FORMATETC *pformatetc,
217 STGMEDIUM *pmedium,
218 BOOL fRelease)
220 return E_NOTIMPL;
223 static HRESULT WINAPI DataObject_EnumFormatEtc(
224 IDataObject *iface,
225 DWORD dwDirection,
226 IEnumFORMATETC **ppenumFormatEtc)
228 return S_OK;
231 static HRESULT WINAPI DataObject_DAdvise(
232 IDataObject *iface,
233 FORMATETC *pformatetc,
234 DWORD advf,
235 IAdviseSink *pAdvSink,
236 DWORD *pdwConnection)
238 return E_NOTIMPL;
241 static HRESULT WINAPI DataObject_DUnadvise(
242 IDataObject *iface,
243 DWORD dwConnection)
245 return E_NOTIMPL;
248 static HRESULT WINAPI DataObject_EnumDAdvise(
249 IDataObject *iface,
250 IEnumSTATDATA **ppenumAdvise)
252 return E_NOTIMPL;
255 static const IDataObjectVtbl dataobject_vtbl = {
256 DataObject_QueryInterface,
257 DataObject_AddRef,
258 DataObject_Release,
259 DataObject_GetData,
260 DataObject_GetDataHere,
261 DataObject_QueryGetData,
262 DataObject_GetCanonicalFormatEtc,
263 DataObject_SetData,
264 DataObject_EnumFormatEtc,
265 DataObject_DAdvise,
266 DataObject_DUnadvise,
267 DataObject_EnumDAdvise
270 static IDataObject DataObject = { &dataobject_vtbl };
272 static ATOM register_dummy_class(void)
274 WNDCLASS wc =
277 DefWindowProc,
280 GetModuleHandle(NULL),
281 NULL,
282 LoadCursor(NULL, IDC_ARROW),
283 (HBRUSH)(COLOR_BTNFACE+1),
284 NULL,
285 TEXT("WineOleTestClass"),
288 return RegisterClass(&wc);
291 static void test_Register_Revoke(void)
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_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");
325 OleUninitialize();
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);
337 DestroyWindow(hwnd);
339 /* try to revoke with already destroyed window */
340 OleInitialize(NULL);
342 hwnd = CreateWindowA("WineOleTestClass", "Test", 0,
343 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
344 NULL, NULL, NULL);
346 hr = RegisterDragDrop(hwnd, &DropTarget);
347 ok(hr == S_OK, "got 0x%08x\n", hr);
349 DestroyWindow(hwnd);
351 hr = RevokeDragDrop(hwnd);
352 ok(hr == DRAGDROP_E_INVALIDHWND, "got 0x%08x\n", hr);
354 OleUninitialize();
357 static void test_DoDragDrop(void)
359 DWORD effect;
360 HRESULT hr;
361 HWND hwnd;
363 hwnd = CreateWindowA("WineOleTestClass", "Test", 0,
364 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
365 NULL, NULL, 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);
396 OleUninitialize();
398 DestroyWindow(hwnd);
401 START_TEST(dragdrop)
403 register_dummy_class();
405 test_Register_Revoke();
406 test_DoDragDrop();