4 * Copyright 2015 Nikolay Sivov for CodeWeavers
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
23 #include "wine/test.h"
29 static HRESULT WINAPI
enumverbs_QueryInterface(IEnumOLEVERB
*iface
, REFIID riid
, void **ppv
)
31 if (IsEqualIID(riid
, &IID_IEnumOLEVERB
) || IsEqualIID(riid
, &IID_IUnknown
)) {
33 IEnumOLEVERB_AddRef(iface
);
41 static ULONG WINAPI
enumverbs_AddRef(IEnumOLEVERB
*iface
)
46 static ULONG WINAPI
enumverbs_Release(IEnumOLEVERB
*iface
)
52 static HRESULT WINAPI
enumverbs_Next(IEnumOLEVERB
*iface
, ULONG count
, OLEVERB
*verbs
, ULONG
*fetched
)
54 ok(count
== 1, "got %u\n", count
);
55 ok(fetched
== NULL
, "got %p\n", fetched
);
56 ok(g_enumpos
== 0 || g_enumpos
== 1, "got pos %d\n", g_enumpos
);
58 if (g_enumpos
++ == 0) {
60 verbs
->lpszVerbName
= CoTaskMemAlloc(sizeof(L
"verb"));
61 lstrcpyW(verbs
->lpszVerbName
, L
"verb");
62 verbs
->fuFlags
= MF_ENABLED
;
63 verbs
->grfAttribs
= OLEVERBATTRIB_ONCONTAINERMENU
;
64 if (fetched
) *fetched
= 1;
71 static HRESULT WINAPI
enumverbs_Skip(IEnumOLEVERB
*iface
, ULONG count
)
73 ok(0, "unexpected call\n");
77 static HRESULT WINAPI
enumverbs_Reset(IEnumOLEVERB
*iface
)
79 ok(0, "unexpected call\n");
83 static HRESULT WINAPI
enumverbs_Clone(IEnumOLEVERB
*iface
, IEnumOLEVERB
**ppenum
)
85 ok(0, "unexpected call\n");
89 static IEnumOLEVERBVtbl enumverbsvtbl
= {
90 enumverbs_QueryInterface
,
99 static IEnumOLEVERB enumverbs
= { &enumverbsvtbl
};
101 static HRESULT WINAPI
oleobject_QueryInterface(IOleObject
*iface
, REFIID riid
, void **ppv
)
103 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IOleObject
)) {
105 IOleObject_AddRef(iface
);
110 return E_NOINTERFACE
;
113 static ULONG WINAPI
oleobject_AddRef(IOleObject
*iface
)
118 static ULONG WINAPI
oleobject_Release(IOleObject
*iface
)
123 static HRESULT WINAPI
oleobject_SetClientSite(IOleObject
*iface
, IOleClientSite
*site
)
125 ok(0, "unexpected call\n");
129 static HRESULT WINAPI
oleobject_GetClientSite(IOleObject
*iface
, IOleClientSite
**site
)
131 ok(0, "unexpected call\n");
135 static HRESULT WINAPI
oleobject_SetHostNames(IOleObject
*iface
, LPCOLESTR containerapp
,
136 LPCOLESTR containerObj
)
138 ok(0, "unexpected call\n");
142 static HRESULT WINAPI
oleobject_Close(IOleObject
*iface
, DWORD saveopt
)
144 ok(0, "unexpected call\n");
148 static HRESULT WINAPI
oleobject_SetMoniker(IOleObject
*iface
, DWORD whichmoniker
, IMoniker
*mk
)
150 ok(0, "unexpected call\n");
154 static HRESULT WINAPI
oleobject_GetMoniker(IOleObject
*iface
, DWORD assign
, DWORD whichmoniker
,
157 ok(0, "unexpected call\n");
161 static HRESULT WINAPI
oleobject_InitFromData(IOleObject
*iface
, IDataObject
*dataobject
,
162 BOOL creation
, DWORD reserved
)
164 ok(0, "unexpected call\n");
168 static HRESULT WINAPI
oleobject_GetClipboardData(IOleObject
*iface
, DWORD reserved
, IDataObject
**dataobject
)
170 ok(0, "unexpected call\n");
174 static HRESULT WINAPI
oleobject_DoVerb(IOleObject
*iface
, LONG verb
, MSG
*msg
, IOleClientSite
*activesite
,
175 LONG index
, HWND hwndParent
, LPCRECT rect
)
177 ok(0, "unexpected call\n");
181 static BOOL g_enumverbsfail
;
182 static HRESULT WINAPI
oleobject_EnumVerbs(IOleObject
*iface
, IEnumOLEVERB
**enumverb
)
184 if (g_enumverbsfail
) {
188 *enumverb
= &enumverbs
;
192 static HRESULT WINAPI
oleobject_Update(IOleObject
*iface
)
194 ok(0, "unexpected call\n");
198 static HRESULT WINAPI
oleobject_IsUpToDate(IOleObject
*iface
)
200 ok(0, "unexpected call\n");
204 static HRESULT WINAPI
oleobject_GetUserClassID(IOleObject
*iface
, CLSID
*clsid
)
206 ok(0, "unexpected call\n");
209 static HRESULT WINAPI
oleobject_GetUserType(IOleObject
*iface
, DWORD formoftype
,
212 ok(formoftype
== USERCLASSTYPE_SHORT
, "got %d\n", formoftype
);
213 *usertype
= CoTaskMemAlloc(sizeof(L
"test"));
214 lstrcpyW(*usertype
, L
"test");
218 static HRESULT WINAPI
oleobject_SetExtent(IOleObject
*iface
, DWORD aspect
, SIZEL
*size
)
220 ok(0, "unexpected call\n");
224 static HRESULT WINAPI
oleobject_GetExtent(IOleObject
*iface
, DWORD aspect
, SIZEL
*size
)
226 ok(0, "unexpected call\n");
230 static HRESULT WINAPI
oleobject_Advise(IOleObject
*iface
, IAdviseSink
*sink
, DWORD
*connection
)
232 ok(0, "unexpected call\n");
236 static HRESULT WINAPI
oleobject_Unadvise(IOleObject
*iface
, DWORD connection
)
238 ok(0, "unexpected call\n");
242 static HRESULT WINAPI
oleobject_EnumAdvise(IOleObject
*iface
, IEnumSTATDATA
**enumadvise
)
244 ok(0, "unexpected call\n");
248 static HRESULT WINAPI
oleobject_GetMiscStatus(IOleObject
*iface
, DWORD aspect
, DWORD
*status
)
250 ok(0, "unexpected call\n");
254 static HRESULT WINAPI
oleobject_SetColorScheme(IOleObject
*iface
, LOGPALETTE
*pal
)
256 ok(0, "unexpected call\n");
260 static IOleObjectVtbl oleobjectvtbl
= {
261 oleobject_QueryInterface
,
264 oleobject_SetClientSite
,
265 oleobject_GetClientSite
,
266 oleobject_SetHostNames
,
268 oleobject_SetMoniker
,
269 oleobject_GetMoniker
,
270 oleobject_InitFromData
,
271 oleobject_GetClipboardData
,
275 oleobject_IsUpToDate
,
276 oleobject_GetUserClassID
,
277 oleobject_GetUserType
,
282 oleobject_EnumAdvise
,
283 oleobject_GetMiscStatus
,
284 oleobject_SetColorScheme
287 static IOleObject oleobject
= { &oleobjectvtbl
};
289 static void test_OleUIAddVerbMenu(void)
291 HMENU hMenu
, verbmenu
;
297 ret
= OleUIAddVerbMenuW(NULL
, NULL
, NULL
, 0, 0, 0, FALSE
, 0, NULL
);
298 ok(!ret
, "got %d\n", ret
);
300 verbmenu
= (HMENU
)0xdeadbeef;
301 ret
= OleUIAddVerbMenuW(NULL
, NULL
, NULL
, 0, 0, 0, FALSE
, 0, &verbmenu
);
302 ok(!ret
, "got %d\n", ret
);
303 ok(verbmenu
== NULL
, "got %p\n", verbmenu
);
306 ret
= OleUIAddVerbMenuW(&oleobject
, NULL
, NULL
, 0, 0, 0, FALSE
, 0, NULL
);
307 ok(!ret
, "got %d\n", ret
);
309 hMenu
= CreatePopupMenu();
311 memset(&info
, 0, sizeof(info
));
312 info
.cbSize
= sizeof(info
);
313 ret
= InsertMenuItemW(hMenu
, 0, TRUE
, &info
);
314 ok(ret
, "got %d\n", ret
);
316 count
= GetMenuItemCount(hMenu
);
317 ok(count
== 1, "got %d\n", count
);
320 ret
= OleUIAddVerbMenuW(&oleobject
, NULL
, hMenu
, 0, 0, 0, FALSE
, 0, NULL
);
321 ok(!ret
, "got %d\n", ret
);
323 count
= GetMenuItemCount(hMenu
);
324 ok(count
== 1, "got %d\n", count
);
326 ret
= InsertMenuItemW(hMenu
, 0, TRUE
, &info
);
327 ok(ret
, "got %d\n", ret
);
329 count
= GetMenuItemCount(hMenu
);
330 ok(count
== 2, "got %d\n", count
);
332 verbmenu
= (HMENU
)0xdeadbeef;
334 ret
= OleUIAddVerbMenuW(&oleobject
, NULL
, hMenu
, 1, 0, 0, FALSE
, 0, &verbmenu
);
335 ok(ret
, "got %d\n", ret
);
336 ok(verbmenu
== NULL
, "got %p\n", verbmenu
);
338 count
= GetMenuItemCount(hMenu
);
339 ok(count
== 2, "got %d\n", count
);
341 /* object doesn't support EnumVerbs() */
342 g_enumverbsfail
= TRUE
;
344 verbmenu
= (HMENU
)0xdeadbeef;
345 ret
= OleUIAddVerbMenuW(&oleobject
, NULL
, hMenu
, 2, 0, 0, FALSE
, 0, &verbmenu
);
346 ok(!ret
, "got %d\n", ret
);
347 ok(verbmenu
== NULL
, "got %p\n", verbmenu
);
348 g_enumverbsfail
= FALSE
;
350 /* added disabled item */
351 memset(&info
, 0, sizeof(info
));
352 info
.cbSize
= sizeof(info
);
353 info
.fMask
= MIIM_STATE
|MIIM_SUBMENU
;
354 ret
= GetMenuItemInfoW(hMenu
, 2, TRUE
, &info
);
355 ok(ret
, "got %d\n", ret
);
356 ok(info
.fState
& MFS_DISABLED
, "got state 0x%08x\n", info
.fState
);
357 ok(info
.hSubMenu
== NULL
, "got submenu %p\n", info
.hSubMenu
);
359 count
= GetMenuItemCount(hMenu
);
360 ok(count
== 3, "got %d\n", count
);
362 /* now without object */
363 verbmenu
= (HMENU
)0xdeadbeef;
364 ret
= OleUIAddVerbMenuW(NULL
, L
"test", hMenu
, 3, 42, 0, FALSE
, 0, &verbmenu
);
365 ok(!ret
, "got %d\n", ret
);
366 ok(verbmenu
== NULL
, "got %p\n", verbmenu
);
368 memset(&info
, 0, sizeof(info
));
369 info
.cbSize
= sizeof(info
);
370 info
.fMask
= MIIM_STATE
|MIIM_ID
|MIIM_STRING
|MIIM_SUBMENU
;
371 info
.dwTypeData
= buffW
;
372 info
.cch
= ARRAY_SIZE(buffW
);
373 ret
= GetMenuItemInfoW(hMenu
, 3, TRUE
, &info
);
374 ok(ret
, "got %d\n", ret
);
375 ok(info
.fState
== MF_GRAYED
, "got state 0x%08x\n", info
.fState
);
376 ok(info
.wID
== 42, "got id %d\n", info
.wID
);
377 ok(info
.hSubMenu
== NULL
, "got submenu %p\n", info
.hSubMenu
);
379 count
= GetMenuItemCount(hMenu
);
380 ok(count
== 4, "got %d\n", count
);
382 verbmenu
= (HMENU
)0xdeadbeef;
384 ret
= OleUIAddVerbMenuW(&oleobject
, NULL
, hMenu
, 4, 0, 0, FALSE
, 0, &verbmenu
);
385 ok(ret
, "got %d\n", ret
);
386 ok(verbmenu
== NULL
, "got %p\n", verbmenu
);
388 /* check newly added item */
389 memset(&info
, 0, sizeof(info
));
390 info
.cbSize
= sizeof(info
);
391 info
.fMask
= MIIM_STRING
|MIIM_STATE
|MIIM_SUBMENU
;
392 info
.dwTypeData
= buffW
;
393 info
.cch
= ARRAY_SIZE(buffW
);
394 ret
= GetMenuItemInfoW(hMenu
, 4, TRUE
, &info
);
395 ok(ret
, "got %d\n", ret
);
396 /* Item string contains verb, usertype and localized string for 'Object' word,
397 exact format depends on localization. */
398 ok(wcsstr(buffW
, L
"verb") != NULL
, "str %s\n", wine_dbgstr_w(buffW
));
399 ok(info
.fState
== 0, "got state 0x%08x\n", info
.fState
);
400 ok(info
.hSubMenu
== NULL
, "got submenu %p\n", info
.hSubMenu
);
402 count
= GetMenuItemCount(hMenu
);
403 ok(count
== 5, "got %d\n", count
);
407 /* try to add verb menu repeatedly, with same id */
408 hMenu
= CreatePopupMenu();
410 count
= GetMenuItemCount(hMenu
);
411 ok(count
== 0, "got %d\n", count
);
414 ret
= OleUIAddVerbMenuW(NULL
, NULL
, hMenu
, 0, 5, 10, TRUE
, 3, &verbmenu
);
415 ok(!ret
, "got %d\n", ret
);
416 ok(verbmenu
== NULL
, "got %p\n", verbmenu
);
418 count
= GetMenuItemCount(hMenu
);
419 ok(count
== 1, "got %d\n", count
);
422 ret
= OleUIAddVerbMenuW(NULL
, NULL
, hMenu
, 0, 5, 10, TRUE
, 3, &verbmenu
);
423 ok(!ret
, "got %d\n", ret
);
424 ok(verbmenu
== NULL
, "got %p\n", verbmenu
);
426 count
= GetMenuItemCount(hMenu
);
427 ok(count
== 1, "got %d\n", count
);
429 /* same position, different id */
431 ret
= OleUIAddVerbMenuW(NULL
, NULL
, hMenu
, 0, 6, 10, TRUE
, 3, &verbmenu
);
432 ok(!ret
, "got %d\n", ret
);
433 ok(verbmenu
== NULL
, "got %p\n", verbmenu
);
435 count
= GetMenuItemCount(hMenu
);
436 ok(count
== 1, "got %d\n", count
);
438 /* change added item string and state */
439 memset(&info
, 0, sizeof(info
));
440 info
.cbSize
= sizeof(info
);
441 info
.fMask
= MIIM_STRING
|MIIM_STATE
;
442 info
.fState
= MFS_ENABLED
;
443 info
.dwTypeData
= buffW
;
444 lstrcpyW(buffW
, L
"cadabra");
445 ret
= SetMenuItemInfoW(hMenu
, 0, TRUE
, &info
);
446 ok(ret
, "got %d\n", ret
);
449 GetMenuStringW(hMenu
, 0, buffW
, ARRAY_SIZE(buffW
), MF_BYPOSITION
);
450 ok(!lstrcmpW(buffW
, L
"cadabra"), "got %s\n", wine_dbgstr_w(buffW
));
453 ret
= OleUIAddVerbMenuW(NULL
, NULL
, hMenu
, 0, 5, 10, TRUE
, 3, &verbmenu
);
454 ok(!ret
, "got %d\n", ret
);
455 ok(verbmenu
== NULL
, "got %p\n", verbmenu
);
457 memset(&info
, 0, sizeof(info
));
458 info
.cbSize
= sizeof(info
);
459 info
.fMask
= MIIM_STRING
|MIIM_STATE
;
461 info
.dwTypeData
= buffW
;
462 info
.cch
= ARRAY_SIZE(buffW
);
463 ret
= GetMenuItemInfoW(hMenu
, 0, TRUE
, &info
);
464 ok(ret
, "got %d\n", ret
);
465 ok(lstrcmpW(buffW
, L
"cadabra"), "got %s\n", wine_dbgstr_w(buffW
));
466 ok(info
.fState
== MF_GRAYED
, "got state 0x%08x\n", info
.fState
);
468 count
= GetMenuItemCount(hMenu
);
469 ok(count
== 1, "got %d\n", count
);
476 test_OleUIAddVerbMenu();