1c2c66affSColin Finck /* Unit tests for systray
2c2c66affSColin Finck *
3c2c66affSColin Finck * Copyright 2007 Mikolaj Zalewski
4c2c66affSColin Finck *
5c2c66affSColin Finck * This library is free software; you can redistribute it and/or
6c2c66affSColin Finck * modify it under the terms of the GNU Lesser General Public
7c2c66affSColin Finck * License as published by the Free Software Foundation; either
8c2c66affSColin Finck * version 2.1 of the License, or (at your option) any later version.
9c2c66affSColin Finck *
10c2c66affSColin Finck * This library is distributed in the hope that it will be useful,
11c2c66affSColin Finck * but WITHOUT ANY WARRANTY; without even the implied warranty of
12c2c66affSColin Finck * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13c2c66affSColin Finck * Lesser General Public License for more details.
14c2c66affSColin Finck *
15c2c66affSColin Finck * You should have received a copy of the GNU Lesser General Public
16c2c66affSColin Finck * License along with this library; if not, write to the Free Software
17c2c66affSColin Finck * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18c2c66affSColin Finck */
19c2c66affSColin Finck
20*0be033feSAmine Khaldi #include <stdarg.h>
21*0be033feSAmine Khaldi
22*0be033feSAmine Khaldi #include <windows.h>
23*0be033feSAmine Khaldi #include "shellapi.h"
24*0be033feSAmine Khaldi
25*0be033feSAmine Khaldi #include "wine/test.h"
26*0be033feSAmine Khaldi
27c2c66affSColin Finck
28c2c66affSColin Finck static HWND hMainWnd;
29c2c66affSColin Finck static BOOL (WINAPI *pShell_NotifyIconW)(DWORD,PNOTIFYICONDATAW);
30c2c66affSColin Finck
test_cbsize(void)31c2c66affSColin Finck static void test_cbsize(void)
32c2c66affSColin Finck {
33c2c66affSColin Finck NOTIFYICONDATAA nidA;
34c2c66affSColin Finck BOOL ret;
35c2c66affSColin Finck
36c2c66affSColin Finck if (pShell_NotifyIconW)
37c2c66affSColin Finck {
38c2c66affSColin Finck NOTIFYICONDATAW nidW;
39c2c66affSColin Finck
40c2c66affSColin Finck ZeroMemory(&nidW, sizeof(nidW));
41c2c66affSColin Finck nidW.cbSize = NOTIFYICONDATAW_V1_SIZE;
42c2c66affSColin Finck nidW.hWnd = hMainWnd;
43c2c66affSColin Finck nidW.uID = 1;
44c2c66affSColin Finck nidW.uFlags = NIF_ICON|NIF_MESSAGE;
45c2c66affSColin Finck nidW.hIcon = LoadIconA(NULL, (LPSTR)IDI_APPLICATION);
46c2c66affSColin Finck nidW.uCallbackMessage = WM_USER+17;
47c2c66affSColin Finck ret = pShell_NotifyIconW(NIM_ADD, &nidW);
48c2c66affSColin Finck ok(ret, "NIM_ADD failed!\n");
49c2c66affSColin Finck /* using an invalid cbSize does work */
50c2c66affSColin Finck nidW.cbSize = 3;
51c2c66affSColin Finck nidW.hWnd = hMainWnd;
52c2c66affSColin Finck nidW.uID = 1;
53c2c66affSColin Finck ret = pShell_NotifyIconW(NIM_DELETE, &nidW);
54c2c66affSColin Finck ok( ret || broken(!ret), /* nt4 */ "NIM_DELETE failed!\n");
55c2c66affSColin Finck /* as icon doesn't exist anymore - now there will be an error */
56c2c66affSColin Finck nidW.cbSize = sizeof(nidW);
57c2c66affSColin Finck ok(!pShell_NotifyIconW(NIM_DELETE, &nidW) != !ret, "The icon was not deleted\n");
58c2c66affSColin Finck }
59c2c66affSColin Finck
60c2c66affSColin Finck /* same for Shell_NotifyIconA */
61c2c66affSColin Finck ZeroMemory(&nidA, sizeof(nidA));
62c2c66affSColin Finck nidA.cbSize = NOTIFYICONDATAA_V1_SIZE;
63c2c66affSColin Finck nidA.hWnd = hMainWnd;
64c2c66affSColin Finck nidA.uID = 1;
65c2c66affSColin Finck nidA.uFlags = NIF_ICON|NIF_MESSAGE;
66c2c66affSColin Finck nidA.hIcon = LoadIconA(NULL, (LPSTR)IDI_APPLICATION);
67c2c66affSColin Finck nidA.uCallbackMessage = WM_USER+17;
68c2c66affSColin Finck ok(Shell_NotifyIconA(NIM_ADD, &nidA), "NIM_ADD failed!\n");
69c2c66affSColin Finck
70c2c66affSColin Finck /* using an invalid cbSize does work */
71c2c66affSColin Finck nidA.cbSize = 3;
72c2c66affSColin Finck nidA.hWnd = hMainWnd;
73c2c66affSColin Finck nidA.uID = 1;
74c2c66affSColin Finck ret = Shell_NotifyIconA(NIM_DELETE, &nidA);
75c2c66affSColin Finck ok(ret, "NIM_DELETE failed!\n");
76c2c66affSColin Finck /* as icon doesn't exist anymore - now there will be an error */
77c2c66affSColin Finck nidA.cbSize = sizeof(nidA);
78c2c66affSColin Finck ok(!Shell_NotifyIconA(NIM_DELETE, &nidA) != !ret, "The icon was not deleted\n");
79c2c66affSColin Finck }
80c2c66affSColin Finck
START_TEST(systray)81c2c66affSColin Finck START_TEST(systray)
82c2c66affSColin Finck {
83c2c66affSColin Finck WNDCLASSA wc;
84c2c66affSColin Finck MSG msg;
85c2c66affSColin Finck RECT rc;
86c2c66affSColin Finck HMODULE hshell32;
87c2c66affSColin Finck
88c2c66affSColin Finck hshell32 = GetModuleHandleA("shell32.dll");
89c2c66affSColin Finck pShell_NotifyIconW = (void*)GetProcAddress(hshell32, "Shell_NotifyIconW");
90c2c66affSColin Finck
91c2c66affSColin Finck wc.style = CS_HREDRAW | CS_VREDRAW;
92c2c66affSColin Finck wc.cbClsExtra = 0;
93c2c66affSColin Finck wc.cbWndExtra = 0;
94c2c66affSColin Finck wc.hInstance = GetModuleHandleA(NULL);
95c2c66affSColin Finck wc.hIcon = NULL;
96c2c66affSColin Finck wc.hCursor = LoadCursorA(NULL, (LPSTR)IDC_IBEAM);
97c2c66affSColin Finck wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
98c2c66affSColin Finck wc.lpszMenuName = NULL;
99c2c66affSColin Finck wc.lpszClassName = "MyTestWnd";
100c2c66affSColin Finck wc.lpfnWndProc = DefWindowProcA;
101c2c66affSColin Finck RegisterClassA(&wc);
102c2c66affSColin Finck
103c2c66affSColin Finck hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW,
104c2c66affSColin Finck CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
105c2c66affSColin Finck GetClientRect(hMainWnd, &rc);
106c2c66affSColin Finck ShowWindow(hMainWnd, SW_SHOW);
107c2c66affSColin Finck
108c2c66affSColin Finck test_cbsize();
109c2c66affSColin Finck
110c2c66affSColin Finck PostQuitMessage(0);
111c2c66affSColin Finck while(GetMessageA(&msg,0,0,0)) {
112c2c66affSColin Finck TranslateMessage(&msg);
113c2c66affSColin Finck DispatchMessageA(&msg);
114c2c66affSColin Finck }
115c2c66affSColin Finck DestroyWindow(hMainWnd);
116c2c66affSColin Finck }
117