ole32/tests: Fix two failures on NT4.
[wine/multimedia.git] / dlls / ole32 / tests / dragdrop.c
blobb7599814ba87e8554b9cf38fdc6fcf82d3c12116
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 /* functions that are not present on all versions of Windows */
35 HRESULT (WINAPI * pCoInitializeEx)(LPVOID lpReserved, DWORD dwCoInit);
37 static int droptarget_addref_called;
38 static int droptarget_release_called;
40 /* helper macros to make tests a bit leaner */
41 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
43 static HRESULT WINAPI DropTarget_QueryInterface(IDropTarget* iface, REFIID riid,
44 void** ppvObject)
46 trace("DropTarget_QueryInterface\n");
47 if (IsEqualIID(riid, &IID_IUnknown) ||
48 IsEqualIID(riid, &IID_IDropTarget))
50 IUnknown_AddRef(iface);
51 *ppvObject = iface;
52 return S_OK;
54 *ppvObject = NULL;
55 return E_NOINTERFACE;
58 static ULONG WINAPI DropTarget_AddRef(IDropTarget* iface)
60 droptarget_addref_called++;
61 return 2;
64 static ULONG WINAPI DropTarget_Release(IDropTarget* iface)
66 droptarget_release_called++;
67 return 1;
70 static HRESULT WINAPI DropTarget_DragEnter(IDropTarget* iface,
71 IDataObject* pDataObj,
72 DWORD grfKeyState, POINTL pt,
73 DWORD* pdwEffect)
75 return E_NOTIMPL;
78 static HRESULT WINAPI DropTarget_DragOver(IDropTarget* iface,
79 DWORD grfKeyState,
80 POINTL pt,
81 DWORD* pdwEffect)
83 return E_NOTIMPL;
86 static HRESULT WINAPI DropTarget_DragLeave(IDropTarget* iface)
88 return E_NOTIMPL;
91 static HRESULT WINAPI DropTarget_Drop(IDropTarget* iface,
92 IDataObject* pDataObj, DWORD grfKeyState,
93 POINTL pt, DWORD* pdwEffect)
95 return E_NOTIMPL;
98 static const IDropTargetVtbl DropTarget_VTbl =
100 DropTarget_QueryInterface,
101 DropTarget_AddRef,
102 DropTarget_Release,
103 DropTarget_DragEnter,
104 DropTarget_DragOver,
105 DropTarget_DragLeave,
106 DropTarget_Drop
109 static IDropTarget DropTarget = { &DropTarget_VTbl };
111 static ATOM register_dummy_class(void)
113 WNDCLASS wc =
116 DefWindowProc,
119 GetModuleHandle(NULL),
120 NULL,
121 LoadCursor(NULL, IDC_ARROW),
122 (HBRUSH)(COLOR_BTNFACE+1),
123 NULL,
124 TEXT("WineOleTestClass"),
127 return RegisterClass(&wc);
130 START_TEST(dragdrop)
132 HRESULT hr;
133 HWND hwnd;
135 hwnd = CreateWindow(MAKEINTATOM(register_dummy_class()), "Test", 0,
136 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
137 NULL, NULL, NULL);
139 hr = RegisterDragDrop(hwnd, &DropTarget);
140 ok(hr == E_OUTOFMEMORY ||
141 broken(hr == CO_E_NOTINITIALIZED), /* NT4 */
142 "RegisterDragDrop without OLE initialized should have returned E_OUTOFMEMORY instead of 0x%08x\n", hr);
144 OleInitialize(NULL);
146 hr = RegisterDragDrop(hwnd, NULL);
147 ok(hr == E_INVALIDARG, "RegisterDragDrop with NULL IDropTarget * should return E_INVALIDARG instead of 0x%08x\n", hr);
149 hr = RegisterDragDrop(NULL, &DropTarget);
150 ok(hr == DRAGDROP_E_INVALIDHWND, "RegisterDragDrop with NULL hwnd should return DRAGDROP_E_INVALIDHWND instead of 0x%08x\n", hr);
152 hr = RegisterDragDrop((HWND)0xdeadbeef, &DropTarget);
153 ok(hr == DRAGDROP_E_INVALIDHWND, "RegisterDragDrop with garbage hwnd should return DRAGDROP_E_INVALIDHWND instead of 0x%08x\n", hr);
155 ok(droptarget_addref_called == 0, "DropTarget_AddRef shouldn't have been called\n");
156 hr = RegisterDragDrop(hwnd, &DropTarget);
157 ok_ole_success(hr, "RegisterDragDrop");
158 ok(droptarget_addref_called == 1, "DropTarget_AddRef should have been called once, not %d times\n", droptarget_addref_called);
160 hr = RegisterDragDrop(hwnd, &DropTarget);
161 ok(hr == DRAGDROP_E_ALREADYREGISTERED, "RegisterDragDrop with already registered hwnd should return DRAGDROP_E_ALREADYREGISTERED instead of 0x%08x\n", hr);
163 ok(droptarget_release_called == 0, "DropTarget_Release shouldn't have been called\n");
164 OleUninitialize();
165 ok(droptarget_release_called == 0, "DropTarget_Release shouldn't have been called\n");
167 hr = RevokeDragDrop(hwnd);
168 ok_ole_success(hr, "RevokeDragDrop");
169 ok(droptarget_release_called == 1 ||
170 broken(droptarget_release_called == 0), /* NT4 */
171 "DropTarget_Release should have been called once, not %d times\n", droptarget_release_called);
173 hr = RevokeDragDrop(NULL);
174 ok(hr == DRAGDROP_E_INVALIDHWND, "RevokeDragDrop with NULL hwnd should return DRAGDROP_E_INVALIDHWND instead of 0x%08x\n", hr);
176 DestroyWindow(hwnd);