0a75fd28e56226e46f0a3a8cba93f274cdebf5fe
[reactos.git] / rostests / winetests / oledlg / main.c
1 /*
2 * oledlg tests
3 *
4 * Copyright 2015 Nikolay Sivov for CodeWeavers
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #define COBJMACROS
22
23 #include <wine/test.h>
24 #include <stdio.h>
25
26 #include <initguid.h>
27 #include <oledlg.h>
28
29 static HRESULT WINAPI enumverbs_QueryInterface(IEnumOLEVERB *iface, REFIID riid, void **ppv)
30 {
31 if (IsEqualIID(riid, &IID_IEnumOLEVERB) || IsEqualIID(riid, &IID_IUnknown)) {
32 *ppv = iface;
33 IEnumOLEVERB_AddRef(iface);
34 return S_OK;
35 }
36
37 *ppv = NULL;
38 return E_NOINTERFACE;
39 }
40
41 static ULONG WINAPI enumverbs_AddRef(IEnumOLEVERB *iface)
42 {
43 return 2;
44 }
45
46 static ULONG WINAPI enumverbs_Release(IEnumOLEVERB *iface)
47 {
48 return 1;
49 }
50
51 static int g_enumpos;
52 static const WCHAR verbW[] = {'v','e','r','b',0};
53 static HRESULT WINAPI enumverbs_Next(IEnumOLEVERB *iface, ULONG count, OLEVERB *verbs, ULONG *fetched)
54 {
55 ok(count == 1, "got %u\n", count);
56 ok(fetched == NULL, "got %p\n", fetched);
57 ok(g_enumpos == 0 || g_enumpos == 1, "got pos %d\n", g_enumpos);
58
59 if (g_enumpos++ == 0) {
60 verbs->lVerb = 123;
61 verbs->lpszVerbName = CoTaskMemAlloc(sizeof(verbW));
62 lstrcpyW(verbs->lpszVerbName, verbW);
63 verbs->fuFlags = MF_ENABLED;
64 verbs->grfAttribs = OLEVERBATTRIB_ONCONTAINERMENU;
65 if (fetched) *fetched = 1;
66 return S_OK;
67 }
68
69 return S_FALSE;
70 }
71
72 static HRESULT WINAPI enumverbs_Skip(IEnumOLEVERB *iface, ULONG count)
73 {
74 ok(0, "unexpected call\n");
75 return E_NOTIMPL;
76 }
77
78 static HRESULT WINAPI enumverbs_Reset(IEnumOLEVERB *iface)
79 {
80 ok(0, "unexpected call\n");
81 return E_NOTIMPL;
82 }
83
84 static HRESULT WINAPI enumverbs_Clone(IEnumOLEVERB *iface, IEnumOLEVERB **ppenum)
85 {
86 ok(0, "unexpected call\n");
87 return E_NOTIMPL;
88 }
89
90 static IEnumOLEVERBVtbl enumverbsvtbl = {
91 enumverbs_QueryInterface,
92 enumverbs_AddRef,
93 enumverbs_Release,
94 enumverbs_Next,
95 enumverbs_Skip,
96 enumverbs_Reset,
97 enumverbs_Clone
98 };
99
100 static IEnumOLEVERB enumverbs = { &enumverbsvtbl };
101
102 static HRESULT WINAPI oleobject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
103 {
104 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IOleObject)) {
105 *ppv = iface;
106 IOleObject_AddRef(iface);
107 return S_OK;
108 }
109
110 *ppv = NULL;
111 return E_NOINTERFACE;
112 }
113
114 static ULONG WINAPI oleobject_AddRef(IOleObject *iface)
115 {
116 return 2;
117 }
118
119 static ULONG WINAPI oleobject_Release(IOleObject *iface)
120 {
121 return 1;
122 }
123
124 static HRESULT WINAPI oleobject_SetClientSite(IOleObject *iface, IOleClientSite *site)
125 {
126 ok(0, "unexpected call\n");
127 return E_NOTIMPL;
128 }
129
130 static HRESULT WINAPI oleobject_GetClientSite(IOleObject *iface, IOleClientSite **site)
131 {
132 ok(0, "unexpected call\n");
133 return E_NOTIMPL;
134 }
135
136 static HRESULT WINAPI oleobject_SetHostNames(IOleObject *iface, LPCOLESTR containerapp,
137 LPCOLESTR containerObj)
138 {
139 ok(0, "unexpected call\n");
140 return E_NOTIMPL;
141 }
142
143 static HRESULT WINAPI oleobject_Close(IOleObject *iface, DWORD saveopt)
144 {
145 ok(0, "unexpected call\n");
146 return E_NOTIMPL;
147 }
148
149 static HRESULT WINAPI oleobject_SetMoniker(IOleObject *iface, DWORD whichmoniker, IMoniker *mk)
150 {
151 ok(0, "unexpected call\n");
152 return E_NOTIMPL;
153 }
154
155 static HRESULT WINAPI oleobject_GetMoniker(IOleObject *iface, DWORD assign, DWORD whichmoniker,
156 IMoniker **mk)
157 {
158 ok(0, "unexpected call\n");
159 return E_NOTIMPL;
160 }
161
162 static HRESULT WINAPI oleobject_InitFromData(IOleObject *iface, IDataObject *dataobject,
163 BOOL creation, DWORD reserved)
164 {
165 ok(0, "unexpected call\n");
166 return E_NOTIMPL;
167 }
168
169 static HRESULT WINAPI oleobject_GetClipboardData(IOleObject *iface, DWORD reserved, IDataObject **dataobject)
170 {
171 ok(0, "unexpected call\n");
172 return E_NOTIMPL;
173 }
174
175 static HRESULT WINAPI oleobject_DoVerb(IOleObject *iface, LONG verb, MSG *msg, IOleClientSite *activesite,
176 LONG index, HWND hwndParent, LPCRECT rect)
177 {
178 ok(0, "unexpected call\n");
179 return E_NOTIMPL;
180 }
181
182 static BOOL g_enumverbsfail;
183 static HRESULT WINAPI oleobject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **enumverb)
184 {
185 if (g_enumverbsfail) {
186 *enumverb = NULL;
187 return E_FAIL;
188 }
189 *enumverb = &enumverbs;
190 return S_OK;
191 }
192
193 static HRESULT WINAPI oleobject_Update(IOleObject *iface)
194 {
195 ok(0, "unexpected call\n");
196 return E_NOTIMPL;
197 }
198
199 static HRESULT WINAPI oleobject_IsUpToDate(IOleObject *iface)
200 {
201 ok(0, "unexpected call\n");
202 return E_NOTIMPL;
203 }
204
205 static HRESULT WINAPI oleobject_GetUserClassID(IOleObject *iface, CLSID *clsid)
206 {
207 ok(0, "unexpected call\n");
208 return E_NOTIMPL;
209 }
210
211 static const WCHAR testW[] = {'t','e','s','t',0};
212 static HRESULT WINAPI oleobject_GetUserType(IOleObject *iface, DWORD formoftype,
213 LPOLESTR *usertype)
214 {
215 ok(formoftype == USERCLASSTYPE_SHORT, "got %d\n", formoftype);
216 *usertype = CoTaskMemAlloc(sizeof(testW));
217 lstrcpyW(*usertype, testW);
218 return S_OK;
219 }
220
221 static HRESULT WINAPI oleobject_SetExtent(IOleObject *iface, DWORD aspect, SIZEL *size)
222 {
223 ok(0, "unexpected call\n");
224 return E_NOTIMPL;
225 }
226
227 static HRESULT WINAPI oleobject_GetExtent(IOleObject *iface, DWORD aspect, SIZEL *size)
228 {
229 ok(0, "unexpected call\n");
230 return E_NOTIMPL;
231 }
232
233 static HRESULT WINAPI oleobject_Advise(IOleObject *iface, IAdviseSink *sink, DWORD *connection)
234 {
235 ok(0, "unexpected call\n");
236 return E_NOTIMPL;
237 }
238
239 static HRESULT WINAPI oleobject_Unadvise(IOleObject *iface, DWORD connection)
240 {
241 ok(0, "unexpected call\n");
242 return E_NOTIMPL;
243 }
244
245 static HRESULT WINAPI oleobject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **enumadvise)
246 {
247 ok(0, "unexpected call\n");
248 return E_NOTIMPL;
249 }
250
251 static HRESULT WINAPI oleobject_GetMiscStatus(IOleObject *iface, DWORD aspect, DWORD *status)
252 {
253 ok(0, "unexpected call\n");
254 return E_NOTIMPL;
255 }
256
257 static HRESULT WINAPI oleobject_SetColorScheme(IOleObject *iface, LOGPALETTE *pal)
258 {
259 ok(0, "unexpected call\n");
260 return E_NOTIMPL;
261 }
262
263 static IOleObjectVtbl oleobjectvtbl = {
264 oleobject_QueryInterface,
265 oleobject_AddRef,
266 oleobject_Release,
267 oleobject_SetClientSite,
268 oleobject_GetClientSite,
269 oleobject_SetHostNames,
270 oleobject_Close,
271 oleobject_SetMoniker,
272 oleobject_GetMoniker,
273 oleobject_InitFromData,
274 oleobject_GetClipboardData,
275 oleobject_DoVerb,
276 oleobject_EnumVerbs,
277 oleobject_Update,
278 oleobject_IsUpToDate,
279 oleobject_GetUserClassID,
280 oleobject_GetUserType,
281 oleobject_SetExtent,
282 oleobject_GetExtent,
283 oleobject_Advise,
284 oleobject_Unadvise,
285 oleobject_EnumAdvise,
286 oleobject_GetMiscStatus,
287 oleobject_SetColorScheme
288 };
289
290 static IOleObject oleobject = { &oleobjectvtbl };
291
292 static void test_OleUIAddVerbMenu(void)
293 {
294 HMENU hMenu, verbmenu;
295 MENUITEMINFOW info;
296 WCHAR buffW[50];
297 int count;
298 BOOL ret;
299
300 ret = OleUIAddVerbMenuW(NULL, NULL, NULL, 0, 0, 0, FALSE, 0, NULL);
301 ok(!ret, "got %d\n", ret);
302
303 verbmenu = (HMENU)0xdeadbeef;
304 ret = OleUIAddVerbMenuW(NULL, NULL, NULL, 0, 0, 0, FALSE, 0, &verbmenu);
305 ok(!ret, "got %d\n", ret);
306 ok(verbmenu == NULL, "got %p\n", verbmenu);
307
308 g_enumpos = 0;
309 ret = OleUIAddVerbMenuW(&oleobject, NULL, NULL, 0, 0, 0, FALSE, 0, NULL);
310 ok(!ret, "got %d\n", ret);
311
312 hMenu = CreatePopupMenu();
313
314 memset(&info, 0, sizeof(info));
315 info.cbSize = sizeof(info);
316 ret = InsertMenuItemW(hMenu, 0, TRUE, &info);
317 ok(ret, "got %d\n", ret);
318
319 count = GetMenuItemCount(hMenu);
320 ok(count == 1, "got %d\n", count);
321
322 g_enumpos = 0;
323 ret = OleUIAddVerbMenuW(&oleobject, NULL, hMenu, 0, 0, 0, FALSE, 0, NULL);
324 ok(!ret, "got %d\n", ret);
325
326 count = GetMenuItemCount(hMenu);
327 ok(count == 1, "got %d\n", count);
328
329 ret = InsertMenuItemW(hMenu, 0, TRUE, &info);
330 ok(ret, "got %d\n", ret);
331
332 count = GetMenuItemCount(hMenu);
333 ok(count == 2, "got %d\n", count);
334
335 verbmenu = (HMENU)0xdeadbeef;
336 g_enumpos = 0;
337 ret = OleUIAddVerbMenuW(&oleobject, NULL, hMenu, 1, 0, 0, FALSE, 0, &verbmenu);
338 ok(ret, "got %d\n", ret);
339 ok(verbmenu == NULL, "got %p\n", verbmenu);
340
341 count = GetMenuItemCount(hMenu);
342 ok(count == 2, "got %d\n", count);
343
344 /* object doesn't support EnumVerbs() */
345 g_enumverbsfail = TRUE;
346 g_enumpos = 0;
347 verbmenu = (HMENU)0xdeadbeef;
348 ret = OleUIAddVerbMenuW(&oleobject, NULL, hMenu, 2, 0, 0, FALSE, 0, &verbmenu);
349 ok(!ret, "got %d\n", ret);
350 ok(verbmenu == NULL, "got %p\n", verbmenu);
351 g_enumverbsfail = FALSE;
352
353 /* added disabled item */
354 memset(&info, 0, sizeof(info));
355 info.cbSize = sizeof(info);
356 info.fMask = MIIM_STATE|MIIM_SUBMENU;
357 ret = GetMenuItemInfoW(hMenu, 2, TRUE, &info);
358 ok(ret, "got %d\n", ret);
359 ok(info.fState & MFS_DISABLED, "got state 0x%08x\n", info.fState);
360 ok(info.hSubMenu == NULL, "got submenu %p\n", info.hSubMenu);
361
362 count = GetMenuItemCount(hMenu);
363 ok(count == 3, "got %d\n", count);
364
365 /* now without object */
366 verbmenu = (HMENU)0xdeadbeef;
367 ret = OleUIAddVerbMenuW(NULL, testW, hMenu, 3, 42, 0, FALSE, 0, &verbmenu);
368 ok(!ret, "got %d\n", ret);
369 ok(verbmenu == NULL, "got %p\n", verbmenu);
370
371 memset(&info, 0, sizeof(info));
372 info.cbSize = sizeof(info);
373 info.fMask = MIIM_STATE|MIIM_ID|MIIM_STRING|MIIM_SUBMENU;
374 info.dwTypeData = buffW;
375 info.cch = sizeof(buffW)/sizeof(WCHAR);
376 ret = GetMenuItemInfoW(hMenu, 3, TRUE, &info);
377 ok(ret, "got %d\n", ret);
378 ok(info.fState == MF_GRAYED, "got state 0x%08x\n", info.fState);
379 ok(info.wID == 42, "got id %d\n", info.wID);
380 ok(info.hSubMenu == NULL, "got submenu %p\n", info.hSubMenu);
381
382 count = GetMenuItemCount(hMenu);
383 ok(count == 4, "got %d\n", count);
384
385 verbmenu = (HMENU)0xdeadbeef;
386 g_enumpos = 0;
387 ret = OleUIAddVerbMenuW(&oleobject, NULL, hMenu, 4, 0, 0, FALSE, 0, &verbmenu);
388 ok(ret, "got %d\n", ret);
389 ok(verbmenu == NULL, "got %p\n", verbmenu);
390
391 /* check newly added item */
392 memset(&info, 0, sizeof(info));
393 info.cbSize = sizeof(info);
394 info.fMask = MIIM_STRING|MIIM_STATE|MIIM_SUBMENU;
395 info.dwTypeData = buffW;
396 info.cch = sizeof(buffW)/sizeof(WCHAR);
397 ret = GetMenuItemInfoW(hMenu, 4, TRUE, &info);
398 ok(ret, "got %d\n", ret);
399 /* item string has a form of '<verb> <usertype> <Object>', where Object is localized */
400 ok(!memcmp(buffW, verbW, sizeof(verbW) - sizeof(WCHAR)), "str %s\n", wine_dbgstr_w(buffW));
401 ok(info.fState == 0, "got state 0x%08x\n", info.fState);
402 ok(info.hSubMenu == NULL, "got submenu %p\n", info.hSubMenu);
403
404 count = GetMenuItemCount(hMenu);
405 ok(count == 5, "got %d\n", count);
406
407 DestroyMenu(hMenu);
408 }
409
410 START_TEST(main)
411 {
412 test_OleUIAddVerbMenu();
413 }