ReactOS 0.4.15-dev-7897-g78dc504
menu.cpp File Reference
#include "shelltest.h"
#include <shlwapi.h>
#include <unknownbase.h>
#include <shlguid_undoc.h>
Include dependency graph for menu.cpp:

Go to the source code of this file.

Classes

class  CDummyWindow
 
struct  _test_info
 
class  CMenuCallback
 

Macros

#define test_S_OK(hres, message)   ok(hres == S_OK, "%s (0x%lx instead of S_OK)\n",message, hResult);
 
#define test_HRES(hres, hresExpected, message)   ok(hres == hresExpected, "%s (0x%lx instead of 0x%lx)\n",message, hResult,hresExpected);
 

Functions

BOOL CheckWindowClass (HWND hwnd, PCWSTR className)
 
BOOL CreateCShellMenu (IShellMenu **shellMenu, IDockingWindow **dockingMenu, IObjectWithSite **menuWithSite)
 
void test_CShellMenu_params ()
 
void test_CShellMenu ()
 
void test_CShellMenu_callbacks (IShellFolder *shellFolder, HMENU hmenu)
 
void test_CShellMenu_with_DeskBar (IShellFolder *shellFolder, HMENU hmenu)
 
 START_TEST (menu)
 

Macro Definition Documentation

◆ test_HRES

#define test_HRES (   hres,
  hresExpected,
  message 
)    ok(hres == hresExpected, "%s (0x%lx instead of 0x%lx)\n",message, hResult,hresExpected);

Definition at line 15 of file menu.cpp.

◆ test_S_OK

#define test_S_OK (   hres,
  message 
)    ok(hres == S_OK, "%s (0x%lx instead of S_OK)\n",message, hResult);

Definition at line 14 of file menu.cpp.

Function Documentation

◆ CheckWindowClass()

BOOL CheckWindowClass ( HWND  hwnd,
PCWSTR  className 
)

Definition at line 17 of file menu.cpp.

18{
19 ULONG size = (lstrlenW(className) + 1)* sizeof(WCHAR);
21 if (GetClassNameW(hwnd, buffer, size ) == 0)
22 {
23 free(buffer);
24 return FALSE;
25 }
26 int res = wcscmp(buffer, className);
27 free(buffer);
28 return res == 0;
29}
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define FALSE
Definition: types.h:117
#define lstrlenW
Definition: compat.h:750
GLsizeiptr size
Definition: glext.h:5919
GLuint res
Definition: glext.h:9613
GLuint buffer
Definition: glext.h:5915
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
uint16_t * PWCHAR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
int WINAPI GetClassNameW(_In_ HWND hWnd, _Out_writes_to_(nMaxCount, return) LPWSTR lpClassName, _In_ int nMaxCount)
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by test_CShellMenu(), and test_CShellMenu_with_DeskBar().

◆ CreateCShellMenu()

BOOL CreateCShellMenu ( IShellMenu **  shellMenu,
IDockingWindow **  dockingMenu,
IObjectWithSite **  menuWithSite 
)

Definition at line 61 of file menu.cpp.

62{
63 HRESULT hResult;
64 hResult = CoCreateInstance(CLSID_MenuBand, NULL, CLSCTX_INPROC_SERVER, IID_IShellMenu, reinterpret_cast<void **>(shellMenu));
65 test_S_OK(hResult, "Failed to instantiate CLSID_MenuBand");
66 if (!shellMenu) return FALSE;
67
68 hResult = (*shellMenu)->QueryInterface(IID_IDockingWindow, reinterpret_cast<void **>(dockingMenu));
69 test_S_OK(hResult, "Failed to query IID_IDockingWindow");
70 hResult = (*shellMenu)->QueryInterface(IID_IObjectWithSite, reinterpret_cast<void **>(menuWithSite));
71 test_S_OK(hResult, "Failed to query IID_IObjectWithSite");
72 if (!dockingMenu || !menuWithSite) return FALSE;
73 return TRUE;
74}
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
#define test_S_OK(hres, message)
Definition: menu.cpp:14
const IID IID_IObjectWithSite

Referenced by test_CShellMenu(), test_CShellMenu_callbacks(), test_CShellMenu_params(), and test_CShellMenu_with_DeskBar().

◆ START_TEST()

START_TEST ( menu  )

Definition at line 405 of file menu.cpp.

406{
408
409 IShellFolder *shellFolder;
410 HRESULT hResult;
411 hResult = SHGetDesktopFolder(&shellFolder);
412 test_S_OK(hResult, "SHGetDesktopFolder failed");
413
414 HMENU hSubMenu = CreatePopupMenu();
415 AppendMenuW(hSubMenu, 0,0, L"Submenu item1");
416 AppendMenuW(hSubMenu, 0,0, L"Submenu item2");
418 AppendMenuW(hmenu, 0,0, L"test");
419 AppendMenuW(hmenu, 0,1, L"test1");
420 MENUITEMINFOW iteminfo = {0};
421 iteminfo.cbSize = sizeof(iteminfo);
422 iteminfo.hSubMenu = hSubMenu;
423 iteminfo.fMask = MIIM_STRING | MIIM_SUBMENU;
424 iteminfo.dwTypeData = const_cast<LPWSTR>(L"submenu");
425 iteminfo.cch = 7;
426 InsertMenuItemW(hmenu, 0, TRUE, &iteminfo);
427
430 test_CShellMenu_callbacks(shellFolder, hmenu);
432}
HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:2002
void test_CShellMenu_params()
Definition: menu.cpp:77
void test_CShellMenu()
Definition: menu.cpp:160
void test_CShellMenu_callbacks(IShellFolder *shellFolder, HMENU hmenu)
Definition: menu.cpp:289
void test_CShellMenu_with_DeskBar(IShellFolder *shellFolder, HMENU hmenu)
Definition: menu.cpp:349
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:63
#define L(x)
Definition: ntvdm.h:50
@ COINIT_APARTMENTTHREADED
Definition: objbase.h:278
LPWSTR dwTypeData
Definition: winuser.h:3269
static HMENU hmenu
Definition: win.c:66
HMENU WINAPI CreatePopupMenu(void)
Definition: menu.c:838
#define MIIM_STRING
Definition: winuser.h:727
#define MIIM_SUBMENU
Definition: winuser.h:723
BOOL WINAPI InsertMenuItemW(_In_ HMENU, _In_ UINT, _In_ BOOL, _In_ LPCMENUITEMINFOW)
BOOL WINAPI AppendMenuW(_In_ HMENU, _In_ UINT, _In_ UINT_PTR, _In_opt_ LPCWSTR)
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ test_CShellMenu()

void test_CShellMenu ( )

Definition at line 160 of file menu.cpp.

161{
162 HRESULT hResult;
163 IShellMenu* shellMenu;
164 IDockingWindow* dockingMenu;
165 IShellFolder *shellFolder;
166 IObjectWithSite *menuWithSite;
167 HWND hwndToolbar;
168
171 CDummyWindow* dummyWindow = new CDummyWindow(hWndParent);
172
173 if (!CreateCShellMenu(&shellMenu, &dockingMenu, &menuWithSite))
174 {
175 skip("failed to create CShellMenuObject\n");
176 delete dummyWindow;
177 return;
178 }
179
180 hResult = SHGetDesktopFolder(&shellFolder);
181 test_S_OK(hResult, "SHGetDesktopFolder failed");
182
183 hResult = shellMenu->Initialize(NULL, 0, ANCESTORDEFAULT, SMINIT_TOPLEVEL|SMINIT_VERTICAL);
184 test_S_OK(hResult, "Initialize failed");
185
186 hResult = shellMenu->SetShellFolder(shellFolder, NULL, NULL, 0);
187 test_S_OK(hResult, "SetShellFolder failed");
188
189 hResult = menuWithSite->SetSite(dummyWindow);
190 test_S_OK(hResult, "SetSite failed");
191
192 hResult = dockingMenu->GetWindow(&hwndToolbar);
193 test_S_OK(hResult, "GetWindow failed");
194 ok(hwndToolbar != NULL, "GetWindow should return a window\n");
195
196 HWND hwndRealParent = GetParent(hwndToolbar);
197 ok(GetParent(hwndRealParent) == hWndParent, "Wrong parent\n");
198 ok(CheckWindowClass(hwndToolbar, L"ToolbarWindow32"), "Wrong class\n");
199 ok(CheckWindowClass(hwndRealParent, L"SysPager"), "Wrong class\n");
200
201 menuWithSite->Release();
202 dockingMenu->Release();
203 shellMenu->Release();
204 ok(!IsWindow(hwndToolbar), "The toolbar window should not exist\n");
205
207}
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
HRESULT SetSite([in] IUnknown *pUnkSite)
HRESULT GetWindow([out] HWND *phwnd)
HRESULT SetShellFolder([in] IShellFolder *psf, [in] PCIDLIST_ABSOLUTE pidlFolder, [in] HKEY hKey, [in] DWORD dwFlags)
HRESULT Initialize([in] IShellMenuCallback *psmc, [in] UINT uId, [in] UINT uIdAncestor, [in] DWORD dwFlags)
ULONG Release()
BOOL CreateCShellMenu(IShellMenu **shellMenu, IDockingWindow **dockingMenu, IObjectWithSite **menuWithSite)
Definition: menu.cpp:61
BOOL CheckWindowClass(HWND hwnd, PCWSTR className)
Definition: menu.cpp:17
#define GetModuleHandle
Definition: winbase.h:3827
BOOL WINAPI IsWindow(_In_opt_ HWND)
HWND WINAPI CreateWindowExW(_In_ DWORD dwExStyle, _In_opt_ LPCWSTR lpClassName, _In_opt_ LPCWSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
#define CW_USEDEFAULT
Definition: winuser.h:225
HWND WINAPI GetParent(_In_ HWND)
BOOL WINAPI DestroyWindow(_In_ HWND)

Referenced by START_TEST().

◆ test_CShellMenu_callbacks()

void test_CShellMenu_callbacks ( IShellFolder shellFolder,
HMENU  hmenu 
)

Definition at line 289 of file menu.cpp.

290{
291 HRESULT hResult;
292 IShellMenu* shellMenu;
293 IDockingWindow* dockingMenu;
294 IObjectWithSite *menuWithSite;
296
299 CDummyWindow* dummyWindow = new CDummyWindow(hWndParent);
301
302 if (!CreateCShellMenu(&shellMenu, &dockingMenu, &menuWithSite))
303 {
304 skip("failed to create CShellMenuObject\n");
305 delete dummyWindow;
306 return;
307 }
308
309 struct _test_info cbtest_info[] = { {1, SMC_CREATE},
310 {2, SMC_GETSFOBJECT},
311 {3, 0x31},
312 {4, SMC_INITMENU},
313 {4, 53},
314 {4, 19},
315 {4, 0x10000000},
316 {4, SMC_NEWITEM},
317 {4, 20},
318 {4, 19},
319 {4, 6},
320 {4, 20},
321 {4, 8},
322 {4, 24},
323 {4, 5},
324 {4, 5},
325 {4, 5}};
326
327 callback = new CMenuCallback(cbtest_info,18);
328
329 callback->SetTest(1);
330 hResult = shellMenu->Initialize(callback, 0,ANCESTORDEFAULT, SMINIT_TOPLEVEL|SMINIT_VERTICAL);
331 test_S_OK(hResult, "Initialize failed");
332
333 callback->SetTest(2);
334 hResult = shellMenu->SetShellFolder(shellFolder, NULL, NULL, 0);
335 test_S_OK(hResult, "SetShellFolder failed");
336
337 callback->SetTest(3);
338 hResult = shellMenu->SetMenu(hmenu, hWndParent, SMSET_TOP);
339 test_S_OK(hResult, "SetMenu failed");
340
341 hResult = menuWithSite->SetSite(dummyWindow);
342 test_S_OK(hResult, "SetSite failed");
343
344 callback->SetTest(4);
345 hResult = dockingMenu->ShowDW(TRUE);
346 test_HRES(hResult, S_FALSE, "ShowDW failed");
347}
HRESULT ShowDW([in] BOOL fShow)
HRESULT SetMenu([in] HMENU hmenu, [in] HWND hwnd, [in] DWORD dwFlags)
#define test_HRES(hres, hresExpected, message)
Definition: menu.cpp:15
static IPrintDialogCallback callback
Definition: printdlg.c:326
#define S_FALSE
Definition: winerror.h:2357
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define SW_SHOW
Definition: winuser.h:775

Referenced by START_TEST().

◆ test_CShellMenu_params()

void test_CShellMenu_params ( )

Definition at line 77 of file menu.cpp.

78{
79 HRESULT hResult;
80 IShellMenu* shellMenu;
81 IDockingWindow* dockingMenu;
82 IObjectWithSite* menuWithSite;
83
85 UINT uId;
86 UINT uIdAncestor;
88 HWND hwndToolbar;
90 HWND hwndOwner;
91 DWORD menuFlagss;
92 IShellFolder *shellFolder;
93
94 if (!CreateCShellMenu(&shellMenu, &dockingMenu, &menuWithSite))
95 {
96 skip("failed to create CShellMenuObject\n");
97 return;
98 }
99
100 hResult = shellMenu->Initialize(NULL, 11, 22, 0xdeadbeef);
101 test_S_OK(hResult, "Initialize failed");
102
103 hResult = shellMenu->GetMenuInfo(&psmc, &uId, &uIdAncestor, &dwFlags);
104 test_S_OK(hResult, "GetMenuInfo failed");
105 ok (psmc == NULL, "wrong psmc\n");
106 ok (uId == 11, "wrong uid\n");
107 ok (uIdAncestor == 22, "wrong uIdAncestor\n");
108 ok (dwFlags == 0xdeadbeef, "wrong dwFlags\n");
109
110 hResult = shellMenu->Initialize(NULL, 0, ANCESTORDEFAULT, SMINIT_TOPLEVEL|SMINIT_VERTICAL);
111 test_S_OK(hResult, "Initialize failed");
112
113 hResult = dockingMenu->GetWindow(&hwndToolbar);
114 test_HRES(hResult, E_FAIL, "GetWindow should fail");
115
116 hResult = shellMenu->GetMenu(&hmenu, &hwndOwner, &menuFlagss);
117 test_HRES(hResult, E_FAIL, "GetMenu should fail");
118
120 hResult = shellMenu->SetMenu(hmenu, NULL, 0);
121 test_S_OK(hResult, "SetMenu failed");
122
123 hwndToolbar = (HWND)UlongToPtr(0xdeadbeef);
124 hResult = dockingMenu->GetWindow(&hwndToolbar);
125 test_S_OK(hResult, "GetWindow failed");
126 ok (hwndToolbar == NULL, "Expected NULL window\n");
127
128 hResult = shellMenu->SetMenu(NULL, NULL, 0);
129 test_S_OK(hResult, "SetMenu failed");
130
131 hResult = shellMenu->GetMenu(&hmenu, &hwndOwner, &menuFlagss);
132 test_S_OK(hResult, "GetMenu failed");
133 ok (hmenu == NULL, "Got a menu\n");
134
135 hResult = dockingMenu->GetWindow(&hwndToolbar);
136 test_S_OK(hResult, "GetWindow failed");
137
138 hResult = SHGetDesktopFolder(&shellFolder);
139 test_S_OK(hResult, "SHGetDesktopFolder failed");
140
141 hResult = shellMenu->SetShellFolder(shellFolder, NULL, 0, 0);
142 test_S_OK(hResult, "SetShellFolder failed");
143
144 hResult = shellMenu->SetShellFolder(NULL, NULL, 0, 0);
145 test_HRES(hResult, E_INVALIDARG, "SetShellFolder should fail");
146
147 hwndToolbar = (HWND)UlongToHandle(0xdeadbeef);
148 hResult = dockingMenu->GetWindow(&hwndToolbar);
149 test_S_OK(hResult, "GetWindow failed");
150 ok (hwndToolbar == NULL, "Expected NULL window\n");
151
152 hResult = dockingMenu->ShowDW(TRUE);
153 test_HRES(hResult, S_FALSE, "ShowDW should fail");
154
155 menuWithSite->Release();
156 dockingMenu->Release();
157 shellMenu->Release();
158}
#define UlongToHandle(ul)
Definition: basetsd.h:97
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_FAIL
Definition: ddrawi.h:102
HANDLE HWND
Definition: compat.h:19
#define UlongToPtr(u)
Definition: config.h:106
unsigned long DWORD
Definition: ntddk_ex.h:95
HRESULT GetMenuInfo([out] IShellMenuCallback **ppsmc, [out] UINT *puId, [out] UINT *puIdAncestor, [out] DWORD *pdwFlags)
HRESULT GetMenu([out] HMENU *phmenu, [out] HWND *phwnd, [out] DWORD *pdwFlags)
unsigned int UINT
Definition: ndis.h:50
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176

Referenced by START_TEST().

◆ test_CShellMenu_with_DeskBar()

void test_CShellMenu_with_DeskBar ( IShellFolder shellFolder,
HMENU  hmenu 
)

Definition at line 349 of file menu.cpp.

350{
351 HRESULT hResult;
352 IShellMenu* shellMenu;
353 IDockingWindow* dockingMenu;
354 IObjectWithSite *menuWithSite;
355 IMenuPopup* menuPopup;
356 IBandSite* bandSite;
357
358 /* Create the tree objects and query the nescesary interfaces */
359 BOOL bCreated = CreateCShellMenu(&shellMenu, &dockingMenu, &menuWithSite);
360 hResult = CoCreateInstance(CLSID_MenuDeskBar, NULL, CLSCTX_INPROC_SERVER, IID_IMenuPopup, reinterpret_cast<void **>(&menuPopup));
361 test_S_OK(hResult, "Failed to instantiate CLSID_MenuDeskBar");
362 hResult = CoCreateInstance(CLSID_MenuBandSite, NULL, CLSCTX_INPROC_SERVER, IID_IBandSite, reinterpret_cast<void **>(&bandSite));
363 test_S_OK(hResult, "Failed to instantiate CLSID_MenuBandSite");
364 if (!bCreated || !menuPopup || !bandSite)
365 {
366 skip("failed to create MenuBandSite object\n");
367 return;
368 }
369
370 /* Create the popup menu */
371 hResult = shellMenu->Initialize(NULL, 0, ANCESTORDEFAULT, SMINIT_TOPLEVEL|SMINIT_VERTICAL);
372 test_S_OK(hResult, "Initialize failed");
373 hResult = shellMenu->SetMenu( hmenu, NULL, SMSET_TOP);
374 test_S_OK(hResult, "SetMenu failed");
375 hResult = menuPopup->SetClient(bandSite);
376 test_S_OK(hResult, "SetClient failed");
377 hResult = bandSite->AddBand(shellMenu);
378 test_S_OK(hResult, "AddBand failed");
379
380 /* Show the popum menu */
381 POINTL p = {10,10};
382 hResult = menuPopup->Popup(&p, NULL, 0);
383 test_HRES(hResult, S_FALSE, "Popup failed");
384
385 HWND hWndToolbar, hWndToplevel;
386
387 /* Ensure that the created windows are correct */
388 hResult = dockingMenu->GetWindow(&hWndToolbar);
389 test_S_OK(hResult, "GetWindow failed");
390 ok(hWndToolbar != NULL, "GetWindow should return a window\n");
391
392 hResult = menuPopup->GetWindow(&hWndToplevel);
393 test_S_OK(hResult, "GetWindow failed");
394 ok(hWndToolbar != NULL, "GetWindow should return a window\n");
395
396 HWND hwndRealParent = GetParent(hWndToolbar);
397 ok(GetParent(hwndRealParent) == hWndToplevel, "Wrong parent\n");
398 ok(CheckWindowClass(hWndToolbar, L"ToolbarWindow32"), "Wrong class\n");
399 ok(CheckWindowClass(hwndRealParent, L"MenuSite"), "Wrong class\n");
400 ok(CheckWindowClass(hWndToplevel, L"BaseBar"), "Wrong class\n");
401
402 ok(GetAncestor (hWndToplevel, GA_PARENT) == GetDesktopWindow(), "Expected the BaseBar window to be top level\n");
403}
const GUID CLSID_MenuBandSite
unsigned int BOOL
Definition: ntddk_ex.h:94
GLfloat GLfloat p
Definition: glext.h:8902
HRESULT AddBand([in] IUnknown *punk)
HRESULT SetClient([in] IUnknown *punkClient)
HRESULT Popup([in] POINTL *ppt, [in] RECTL *prcExclude, [in] MP_POPUPFLAGS dwFlags)
#define GA_PARENT
Definition: winuser.h:2788
HWND WINAPI GetDesktopWindow(void)
Definition: window.c:656
HWND WINAPI GetAncestor(_In_ HWND, _In_ UINT)

Referenced by START_TEST().