ReactOS 0.4.16-dev-197-g92996da
main.c
Go to the documentation of this file.
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
29static const WCHAR *strstrW( const WCHAR *str, const WCHAR *sub )
30{
31 while (*str)
32 {
33 const WCHAR *p1 = str, *p2 = sub;
34 while (*p1 && *p2 && *p1 == *p2) { p1++; p2++; }
35 if (!*p2) return str;
36 str++;
37 }
38 return NULL;
39}
40
42{
44 *ppv = iface;
45 IEnumOLEVERB_AddRef(iface);
46 return S_OK;
47 }
48
49 *ppv = NULL;
50 return E_NOINTERFACE;
51}
52
54{
55 return 2;
56}
57
59{
60 return 1;
61}
62
63static int g_enumpos;
64static const WCHAR verbW[] = {'v','e','r','b',0};
65static HRESULT WINAPI enumverbs_Next(IEnumOLEVERB *iface, ULONG count, OLEVERB *verbs, ULONG *fetched)
66{
67 ok(count == 1, "got %u\n", count);
68 ok(fetched == NULL, "got %p\n", fetched);
69 ok(g_enumpos == 0 || g_enumpos == 1, "got pos %d\n", g_enumpos);
70
71 if (g_enumpos++ == 0) {
72 verbs->lVerb = 123;
73 verbs->lpszVerbName = CoTaskMemAlloc(sizeof(verbW));
74 lstrcpyW(verbs->lpszVerbName, verbW);
75 verbs->fuFlags = MF_ENABLED;
76 verbs->grfAttribs = OLEVERBATTRIB_ONCONTAINERMENU;
77 if (fetched) *fetched = 1;
78 return S_OK;
79 }
80
81 return S_FALSE;
82}
83
85{
86 ok(0, "unexpected call\n");
87 return E_NOTIMPL;
88}
89
91{
92 ok(0, "unexpected call\n");
93 return E_NOTIMPL;
94}
95
97{
98 ok(0, "unexpected call\n");
99 return E_NOTIMPL;
100}
101
102static IEnumOLEVERBVtbl enumverbsvtbl = {
110};
111
113
115{
117 *ppv = iface;
118 IOleObject_AddRef(iface);
119 return S_OK;
120 }
121
122 *ppv = NULL;
123 return E_NOINTERFACE;
124}
125
127{
128 return 2;
129}
130
132{
133 return 1;
134}
135
137{
138 ok(0, "unexpected call\n");
139 return E_NOTIMPL;
140}
141
143{
144 ok(0, "unexpected call\n");
145 return E_NOTIMPL;
146}
147
148static HRESULT WINAPI oleobject_SetHostNames(IOleObject *iface, LPCOLESTR containerapp,
149 LPCOLESTR containerObj)
150{
151 ok(0, "unexpected call\n");
152 return E_NOTIMPL;
153}
154
156{
157 ok(0, "unexpected call\n");
158 return E_NOTIMPL;
159}
160
162{
163 ok(0, "unexpected call\n");
164 return E_NOTIMPL;
165}
166
167static HRESULT WINAPI oleobject_GetMoniker(IOleObject *iface, DWORD assign, DWORD whichmoniker,
168 IMoniker **mk)
169{
170 ok(0, "unexpected call\n");
171 return E_NOTIMPL;
172}
173
175 BOOL creation, DWORD reserved)
176{
177 ok(0, "unexpected call\n");
178 return E_NOTIMPL;
179}
180
182{
183 ok(0, "unexpected call\n");
184 return E_NOTIMPL;
185}
186
189{
190 ok(0, "unexpected call\n");
191 return E_NOTIMPL;
192}
193
196{
197 if (g_enumverbsfail) {
198 *enumverb = NULL;
199 return E_FAIL;
200 }
201 *enumverb = &enumverbs;
202 return S_OK;
203}
204
206{
207 ok(0, "unexpected call\n");
208 return E_NOTIMPL;
209}
210
212{
213 ok(0, "unexpected call\n");
214 return E_NOTIMPL;
215}
216
218{
219 ok(0, "unexpected call\n");
220 return E_NOTIMPL;
221}
222
223static const WCHAR testW[] = {'t','e','s','t',0};
225 LPOLESTR *usertype)
226{
227 ok(formoftype == USERCLASSTYPE_SHORT, "got %d\n", formoftype);
228 *usertype = CoTaskMemAlloc(sizeof(testW));
229 lstrcpyW(*usertype, testW);
230 return S_OK;
231}
232
234{
235 ok(0, "unexpected call\n");
236 return E_NOTIMPL;
237}
238
240{
241 ok(0, "unexpected call\n");
242 return E_NOTIMPL;
243}
244
246{
247 ok(0, "unexpected call\n");
248 return E_NOTIMPL;
249}
250
252{
253 ok(0, "unexpected call\n");
254 return E_NOTIMPL;
255}
256
258{
259 ok(0, "unexpected call\n");
260 return E_NOTIMPL;
261}
262
264{
265 ok(0, "unexpected call\n");
266 return E_NOTIMPL;
267}
268
270{
271 ok(0, "unexpected call\n");
272 return E_NOTIMPL;
273}
274
275static IOleObjectVtbl oleobjectvtbl = {
300};
301
303
304static void test_OleUIAddVerbMenu(void)
305{
306 static const WCHAR cadabraW[] = {'c','a','d','a','b','r','a',0};
307 HMENU hMenu, verbmenu;
309 WCHAR buffW[50];
310 int count;
311 BOOL ret;
312
313 ret = OleUIAddVerbMenuW(NULL, NULL, NULL, 0, 0, 0, FALSE, 0, NULL);
314 ok(!ret, "got %d\n", ret);
315
316 verbmenu = (HMENU)0xdeadbeef;
317 ret = OleUIAddVerbMenuW(NULL, NULL, NULL, 0, 0, 0, FALSE, 0, &verbmenu);
318 ok(!ret, "got %d\n", ret);
319 ok(verbmenu == NULL, "got %p\n", verbmenu);
320
321 g_enumpos = 0;
322 ret = OleUIAddVerbMenuW(&oleobject, NULL, NULL, 0, 0, 0, FALSE, 0, NULL);
323 ok(!ret, "got %d\n", ret);
324
325 hMenu = CreatePopupMenu();
326
327 memset(&info, 0, sizeof(info));
328 info.cbSize = sizeof(info);
329 ret = InsertMenuItemW(hMenu, 0, TRUE, &info);
330 ok(ret, "got %d\n", ret);
331
332 count = GetMenuItemCount(hMenu);
333 ok(count == 1, "got %d\n", count);
334
335 g_enumpos = 0;
336 ret = OleUIAddVerbMenuW(&oleobject, NULL, hMenu, 0, 0, 0, FALSE, 0, NULL);
337 ok(!ret, "got %d\n", ret);
338
339 count = GetMenuItemCount(hMenu);
340 ok(count == 1, "got %d\n", count);
341
342 ret = InsertMenuItemW(hMenu, 0, TRUE, &info);
343 ok(ret, "got %d\n", ret);
344
345 count = GetMenuItemCount(hMenu);
346 ok(count == 2, "got %d\n", count);
347
348 verbmenu = (HMENU)0xdeadbeef;
349 g_enumpos = 0;
350 ret = OleUIAddVerbMenuW(&oleobject, NULL, hMenu, 1, 0, 0, FALSE, 0, &verbmenu);
351 ok(ret, "got %d\n", ret);
352 ok(verbmenu == NULL, "got %p\n", verbmenu);
353
354 count = GetMenuItemCount(hMenu);
355 ok(count == 2, "got %d\n", count);
356
357 /* object doesn't support EnumVerbs() */
359 g_enumpos = 0;
360 verbmenu = (HMENU)0xdeadbeef;
361 ret = OleUIAddVerbMenuW(&oleobject, NULL, hMenu, 2, 0, 0, FALSE, 0, &verbmenu);
362 ok(!ret, "got %d\n", ret);
363 ok(verbmenu == NULL, "got %p\n", verbmenu);
365
366 /* added disabled item */
367 memset(&info, 0, sizeof(info));
368 info.cbSize = sizeof(info);
370 ret = GetMenuItemInfoW(hMenu, 2, TRUE, &info);
371 ok(ret, "got %d\n", ret);
372 ok(info.fState & MFS_DISABLED, "got state 0x%08x\n", info.fState);
373 ok(info.hSubMenu == NULL, "got submenu %p\n", info.hSubMenu);
374
375 count = GetMenuItemCount(hMenu);
376 ok(count == 3, "got %d\n", count);
377
378 /* now without object */
379 verbmenu = (HMENU)0xdeadbeef;
380 ret = OleUIAddVerbMenuW(NULL, testW, hMenu, 3, 42, 0, FALSE, 0, &verbmenu);
381 ok(!ret, "got %d\n", ret);
382 ok(verbmenu == NULL, "got %p\n", verbmenu);
383
384 memset(&info, 0, sizeof(info));
385 info.cbSize = sizeof(info);
387 info.dwTypeData = buffW;
388 info.cch = ARRAY_SIZE(buffW);
389 ret = GetMenuItemInfoW(hMenu, 3, TRUE, &info);
390 ok(ret, "got %d\n", ret);
391 ok(info.fState == MF_GRAYED, "got state 0x%08x\n", info.fState);
392 ok(info.wID == 42, "got id %d\n", info.wID);
393 ok(info.hSubMenu == NULL, "got submenu %p\n", info.hSubMenu);
394
395 count = GetMenuItemCount(hMenu);
396 ok(count == 4, "got %d\n", count);
397
398 verbmenu = (HMENU)0xdeadbeef;
399 g_enumpos = 0;
400 ret = OleUIAddVerbMenuW(&oleobject, NULL, hMenu, 4, 0, 0, FALSE, 0, &verbmenu);
401 ok(ret, "got %d\n", ret);
402 ok(verbmenu == NULL, "got %p\n", verbmenu);
403
404 /* check newly added item */
405 memset(&info, 0, sizeof(info));
406 info.cbSize = sizeof(info);
408 info.dwTypeData = buffW;
409 info.cch = ARRAY_SIZE(buffW);
410 ret = GetMenuItemInfoW(hMenu, 4, TRUE, &info);
411 ok(ret, "got %d\n", ret);
412 /* Item string contains verb, usertype and localized string for 'Object' word,
413 exact format depends on localization. */
414 ok(strstrW(buffW, verbW) != NULL, "str %s\n", wine_dbgstr_w(buffW));
415 ok(info.fState == 0, "got state 0x%08x\n", info.fState);
416 ok(info.hSubMenu == NULL, "got submenu %p\n", info.hSubMenu);
417
418 count = GetMenuItemCount(hMenu);
419 ok(count == 5, "got %d\n", count);
420
421 DestroyMenu(hMenu);
422
423 /* try to add verb menu repeatedly, with same id */
424 hMenu = CreatePopupMenu();
425
426 count = GetMenuItemCount(hMenu);
427 ok(count == 0, "got %d\n", count);
428
429 verbmenu = NULL;
430 ret = OleUIAddVerbMenuW(NULL, NULL, hMenu, 0, 5, 10, TRUE, 3, &verbmenu);
431 ok(!ret, "got %d\n", ret);
432 ok(verbmenu == NULL, "got %p\n", verbmenu);
433
434 count = GetMenuItemCount(hMenu);
435 ok(count == 1, "got %d\n", count);
436
437 verbmenu = NULL;
438 ret = OleUIAddVerbMenuW(NULL, NULL, hMenu, 0, 5, 10, TRUE, 3, &verbmenu);
439 ok(!ret, "got %d\n", ret);
440 ok(verbmenu == NULL, "got %p\n", verbmenu);
441
442 count = GetMenuItemCount(hMenu);
443 ok(count == 1, "got %d\n", count);
444
445 /* same position, different id */
446 verbmenu = NULL;
447 ret = OleUIAddVerbMenuW(NULL, NULL, hMenu, 0, 6, 10, TRUE, 3, &verbmenu);
448 ok(!ret, "got %d\n", ret);
449 ok(verbmenu == NULL, "got %p\n", verbmenu);
450
451 count = GetMenuItemCount(hMenu);
452 ok(count == 1, "got %d\n", count);
453
454 /* change added item string and state */
455 memset(&info, 0, sizeof(info));
456 info.cbSize = sizeof(info);
458 info.fState = MFS_ENABLED;
459 info.dwTypeData = buffW;
460 lstrcpyW(buffW, cadabraW);
461 ret = SetMenuItemInfoW(hMenu, 0, TRUE, &info);
462 ok(ret, "got %d\n", ret);
463
464 buffW[0] = 0;
465 GetMenuStringW(hMenu, 0, buffW, ARRAY_SIZE(buffW), MF_BYPOSITION);
466 ok(!lstrcmpW(buffW, cadabraW), "got %s\n", wine_dbgstr_w(buffW));
467
468 verbmenu = NULL;
469 ret = OleUIAddVerbMenuW(NULL, NULL, hMenu, 0, 5, 10, TRUE, 3, &verbmenu);
470 ok(!ret, "got %d\n", ret);
471 ok(verbmenu == NULL, "got %p\n", verbmenu);
472
473 memset(&info, 0, sizeof(info));
474 info.cbSize = sizeof(info);
476 buffW[0] = 0;
477 info.dwTypeData = buffW;
478 info.cch = ARRAY_SIZE(buffW);
479 ret = GetMenuItemInfoW(hMenu, 0, TRUE, &info);
480 ok(ret, "got %d\n", ret);
481 ok(lstrcmpW(buffW, cadabraW), "got %s\n", wine_dbgstr_w(buffW));
482 ok(info.fState == MF_GRAYED, "got state 0x%08x\n", info.fState);
483
484 count = GetMenuItemCount(hMenu);
485 ok(count == 1, "got %d\n", count);
486
487 DestroyMenu(hMenu);
488}
489
491{
493}
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define msg(x)
Definition: auth_time.c:54
#define ARRAY_SIZE(A)
Definition: main.h:20
const GUID IID_IUnknown
static HWND hwndParent
Definition: cryptui.c:300
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define lstrcpyW
Definition: compat.h:749
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4243
r reserved
Definition: btrfs.c:3006
int main()
Definition: test.c:6
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
GLuint index
Definition: glext.h:6031
GLsizei GLenum GLboolean sink
Definition: glext.h:5672
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:426
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
static const WCHAR testW[]
Definition: jsregexp.c:44
#define wine_dbgstr_w
Definition: kernel32.h:34
static IActiveScriptSite * site
Definition: script.c:149
static LPOLESTR
Definition: stg_prop.c:27
static HRESULT WINAPI oleobject_SetMoniker(IOleObject *iface, DWORD whichmoniker, IMoniker *mk)
Definition: main.c:161
static HRESULT WINAPI oleobject_GetUserClassID(IOleObject *iface, CLSID *clsid)
Definition: main.c:217
static HRESULT WINAPI oleobject_DoVerb(IOleObject *iface, LONG verb, MSG *msg, IOleClientSite *activesite, LONG index, HWND hwndParent, LPCRECT rect)
Definition: main.c:187
static HRESULT WINAPI oleobject_GetExtent(IOleObject *iface, DWORD aspect, SIZEL *size)
Definition: main.c:239
static HRESULT WINAPI oleobject_Close(IOleObject *iface, DWORD saveopt)
Definition: main.c:155
static HRESULT WINAPI oleobject_Advise(IOleObject *iface, IAdviseSink *sink, DWORD *connection)
Definition: main.c:245
static HRESULT WINAPI oleobject_GetUserType(IOleObject *iface, DWORD formoftype, LPOLESTR *usertype)
Definition: main.c:224
static HRESULT WINAPI oleobject_Unadvise(IOleObject *iface, DWORD connection)
Definition: main.c:251
static ULONG WINAPI oleobject_AddRef(IOleObject *iface)
Definition: main.c:126
static BOOL g_enumverbsfail
Definition: main.c:194
static ULONG WINAPI enumverbs_AddRef(IEnumOLEVERB *iface)
Definition: main.c:53
static IOleObjectVtbl oleobjectvtbl
Definition: main.c:275
static ULONG WINAPI oleobject_Release(IOleObject *iface)
Definition: main.c:131
static HRESULT WINAPI oleobject_SetHostNames(IOleObject *iface, LPCOLESTR containerapp, LPCOLESTR containerObj)
Definition: main.c:148
static int g_enumpos
Definition: main.c:63
static HRESULT WINAPI oleobject_SetClientSite(IOleObject *iface, IOleClientSite *site)
Definition: main.c:136
static HRESULT WINAPI oleobject_GetClientSite(IOleObject *iface, IOleClientSite **site)
Definition: main.c:142
static HRESULT WINAPI oleobject_GetMoniker(IOleObject *iface, DWORD assign, DWORD whichmoniker, IMoniker **mk)
Definition: main.c:167
static void test_OleUIAddVerbMenu(void)
Definition: main.c:304
static HRESULT WINAPI oleobject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
Definition: main.c:114
static ULONG WINAPI enumverbs_Release(IEnumOLEVERB *iface)
Definition: main.c:58
static HRESULT WINAPI enumverbs_Reset(IEnumOLEVERB *iface)
Definition: main.c:90
static HRESULT WINAPI oleobject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **enumadvise)
Definition: main.c:257
static IEnumOLEVERB enumverbs
Definition: main.c:112
static HRESULT WINAPI enumverbs_Next(IEnumOLEVERB *iface, ULONG count, OLEVERB *verbs, ULONG *fetched)
Definition: main.c:65
static HRESULT WINAPI oleobject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **enumverb)
Definition: main.c:195
static const WCHAR verbW[]
Definition: main.c:64
static HRESULT WINAPI oleobject_GetMiscStatus(IOleObject *iface, DWORD aspect, DWORD *status)
Definition: main.c:263
static HRESULT WINAPI oleobject_GetClipboardData(IOleObject *iface, DWORD reserved, IDataObject **dataobject)
Definition: main.c:181
static HRESULT WINAPI enumverbs_QueryInterface(IEnumOLEVERB *iface, REFIID riid, void **ppv)
Definition: main.c:41
static HRESULT WINAPI oleobject_SetColorScheme(IOleObject *iface, LOGPALETTE *pal)
Definition: main.c:269
static HRESULT WINAPI enumverbs_Skip(IEnumOLEVERB *iface, ULONG count)
Definition: main.c:84
static HRESULT WINAPI oleobject_Update(IOleObject *iface)
Definition: main.c:205
static HRESULT WINAPI oleobject_SetExtent(IOleObject *iface, DWORD aspect, SIZEL *size)
Definition: main.c:233
static HRESULT WINAPI enumverbs_Clone(IEnumOLEVERB *iface, IEnumOLEVERB **ppenum)
Definition: main.c:96
static IEnumOLEVERBVtbl enumverbsvtbl
Definition: main.c:102
static HRESULT WINAPI oleobject_InitFromData(IOleObject *iface, IDataObject *dataobject, BOOL creation, DWORD reserved)
Definition: main.c:174
static HRESULT WINAPI oleobject_IsUpToDate(IOleObject *iface)
Definition: main.c:211
static IOleObject oleobject
Definition: main.c:302
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:63
REFCLSID clsid
Definition: msctf.c:82
const GUID IID_IOleObject
const GUID IID_IEnumOLEVERB
BOOL WINAPI OleUIAddVerbMenuW(IOleObject *object, LPCWSTR shorttype, HMENU hMenu, UINT uPos, UINT idmin, UINT idmax, BOOL addConvert, UINT idConvert, HMENU *ret_submenu)
Definition: oledlg_main.c:157
long LONG
Definition: pedump.c:60
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
#define REFIID
Definition: guiddef.h:118
#define strstrW(d, s)
Definition: unicode.h:38
const WCHAR * str
#define memset(x, y, z)
Definition: compat.h:39
& rect
Definition: startmenu.cpp:1413
Definition: ps.c:97
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
uint32_t ULONG
Definition: typedefs.h:59
int ret
#define WINAPI
Definition: msvc.h:6
#define S_FALSE
Definition: winerror.h:2357
#define E_NOINTERFACE
Definition: winerror.h:2364
HMENU WINAPI CreatePopupMenu(void)
Definition: menu.c:838
#define MIIM_STRING
Definition: winuser.h:730
#define MIIM_ID
Definition: winuser.h:725
int WINAPI GetMenuItemCount(_In_opt_ HMENU)
int WINAPI GetMenuStringW(_In_ HMENU hMenu, _In_ UINT uIDItem, _Out_writes_opt_(cchMax) LPWSTR lpString, _In_ int cchMax, _In_ UINT flags)
BOOL WINAPI SetMenuItemInfoW(_In_ HMENU, _In_ UINT, _In_ BOOL, _In_ LPCMENUITEMINFOW)
#define MFS_DISABLED
Definition: winuser.h:752
#define MIIM_STATE
Definition: winuser.h:724
#define MIIM_SUBMENU
Definition: winuser.h:726
#define MF_ENABLED
Definition: winuser.h:128
#define MF_BYPOSITION
Definition: winuser.h:203
#define MFS_ENABLED
Definition: winuser.h:753
BOOL WINAPI DestroyMenu(_In_ HMENU)
BOOL WINAPI GetMenuItemInfoW(_In_ HMENU, _In_ UINT, _In_ BOOL, _Inout_ LPMENUITEMINFOW)
BOOL WINAPI InsertMenuItemW(_In_ HMENU, _In_ UINT, _In_ BOOL, _In_ LPCMENUITEMINFOW)
#define MF_GRAYED
Definition: winuser.h:129
__wchar_t WCHAR
Definition: xmlstorage.h:180