sapi: Add SpMMAudioOut stub.
[wine.git] / dlls / compstui / tests / compstui.c
blob2634875db639d7cfa33c05c0b2ecde37c36d4a72
1 /*
2 * Copyright 2022 Piotr Caban
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <windows.h>
20 #include <prsht.h>
21 #include <ddk/compstui.h>
23 #include "wine/test.h"
25 #define DEFINE_EXPECT(func) \
26 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
28 #define SET_EXPECT(func) \
29 do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
31 #define CHECK_EXPECT2(func) \
32 do { \
33 ok(expect_ ##func, "unexpected call " #func "\n"); \
34 called_ ## func = TRUE; \
35 }while(0)
37 #define CHECK_EXPECT(func) \
38 do { \
39 CHECK_EXPECT2(func); \
40 expect_ ## func = FALSE; \
41 }while(0)
43 #define CHECK_CALLED(func) \
44 do { \
45 ok(called_ ## func, "expected " #func "\n"); \
46 expect_ ## func = called_ ## func = FALSE; \
47 }while(0)
49 #define CLEAR_CALLED(func) \
50 expect_ ## func = called_ ## func = FALSE
52 DEFINE_EXPECT(page_proc_WM_INITDIALOG);
53 DEFINE_EXPECT(page_proc2_WM_INITDIALOG);
54 DEFINE_EXPECT(device_PROPSHEETUI_REASON_INIT);
55 DEFINE_EXPECT(device_PROPSHEETUI_REASON_DESTROY);
56 DEFINE_EXPECT(callback_PROPSHEETUI_REASON_BEFORE_INIT);
57 DEFINE_EXPECT(callback_PROPSHEETUI_REASON_INIT);
58 DEFINE_EXPECT(callback_PROPSHEETUI_REASON_GET_INFO_HEADER);
59 DEFINE_EXPECT(callback_PROPSHEETUI_REASON_DESTROY);
61 typedef struct {
62 WORD cbSize;
63 WORD Flags;
64 LPWSTR pTitle;
65 HWND hWndParent;
66 HINSTANCE hInst;
67 union {
68 HICON hIcon;
69 ULONG_PTR IconID;
71 } PROPSHEETUI_INFO_HEADERW;
73 static INT_PTR CALLBACK prop_page_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
75 if (msg == WM_INITDIALOG)
77 HWND dlg = GetParent(hwnd);
79 CHECK_EXPECT(page_proc_WM_INITDIALOG);
81 PostMessageW(dlg, PSM_PRESSBUTTON, PSBTN_OK, 0);
83 return FALSE;
86 static INT_PTR CALLBACK prop_page_proc2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
88 if (msg == WM_INITDIALOG)
90 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW*)lparam;
91 PSPINFO *info = (PSPINFO*)((BYTE*)lparam + psp->dwSize);
92 HWND dlg = GetParent(hwnd);
94 CHECK_EXPECT(page_proc2_WM_INITDIALOG);
96 ok(psp->dwSize == sizeof(PROPSHEETPAGEW), "psp->dwSize = %ld\n", psp->dwSize);
97 ok(psp->pfnDlgProc == prop_page_proc2, "psp->pfnDlgProc != prop_page_proc2\n");
98 ok(!psp->lParam, "psp->lParam = %Ix\n", psp->lParam);
100 ok(info->cbSize == sizeof(*info), "info->cbSize = %hd\n", info->cbSize);
101 ok(!info->wReserved, "info->wReserved = %hd\n", info->wReserved);
102 ok(info->hComPropSheet != NULL, "info->hComPropSheet = NULL\n");
103 ok(info->hCPSUIPage != NULL, "info->hCPSUIPage = NULL\n");
104 ok(info->pfnComPropSheet != NULL, "info->pfnComPropSheet = NULL\n");
106 PostMessageW(dlg, PSM_SETCURSEL, 1, 0);
108 return FALSE;
111 static LONG WINAPI device_property_sheets(PROPSHEETUI_INFO *info, LPARAM lparam)
113 if (info->Reason == PROPSHEETUI_REASON_INIT)
114 CHECK_EXPECT(device_PROPSHEETUI_REASON_INIT);
115 else
116 CHECK_EXPECT(device_PROPSHEETUI_REASON_DESTROY);
118 ok(info->cbSize == sizeof(*info), "info->cbSize = %hd\n", info->cbSize);
119 ok(info->Version == PROPSHEETUI_INFO_VERSION, "info->Version = %hd\n", info->Version);
120 ok(info->Flags == info->lParamInit ? PSUIINFO_UNICODE : 0, "info->Flags = %hd\n", info->Flags);
121 ok(info->Reason == PROPSHEETUI_REASON_INIT || info->Reason == PROPSHEETUI_REASON_DESTROY,
122 "info->Reason = %hx\n", info->Reason);
123 ok(info->hComPropSheet != NULL, "info->hComPropSheet = NULL\n");
124 ok(info->pfnComPropSheet != NULL, "info->pfnComPropSheet = NULL\n");
125 if (info->Reason == PROPSHEETUI_REASON_INIT)
127 ok(info->lParamInit == lparam, "info->lParamInit = %Ix, lparam = %Ix\n",
128 info->lParamInit, lparam);
130 ok(!info->UserData, "info->UserData = %Ix\n", info->UserData);
131 ok(!info->Result, "info->Result = %Ix\n", info->Result);
132 return lparam;
135 #define ADD_PAGES 0x1
137 static LONG WINAPI propsheetui_callback(PROPSHEETUI_INFO *info, LPARAM lparam)
139 PROPSHEETUI_INFO_HEADERW *info_header;
141 ok(info->cbSize == sizeof(*info), "info->cbSize = %hd\n", info->cbSize);
143 switch(info->Reason)
145 case PROPSHEETUI_REASON_BEFORE_INIT:
146 CHECK_EXPECT(callback_PROPSHEETUI_REASON_BEFORE_INIT);
147 ok(!info->Version, "info->Version = %hd\n", info->Version);
148 ok(!info->Flags, "info->Flags = %hd\n", info->Flags);
149 ok(!info->hComPropSheet, "info->hComPropSheet = %p\n", info->hComPropSheet);
150 ok(!info->pfnComPropSheet, "info->pfnComPropSheet = %p\n", info->pfnComPropSheet);
151 ok(!info->Result, "info->Result = %Ix\n", info->Result);
152 break;
153 case PROPSHEETUI_REASON_INIT:
154 CHECK_EXPECT(callback_PROPSHEETUI_REASON_INIT);
155 ok(info->Version == PROPSHEETUI_INFO_VERSION, "info->Version = %hd\n", info->Version);
156 ok(info->Flags == PSUIINFO_UNICODE, "info->Flags = %hd\n", info->Flags);
157 ok(info->hComPropSheet != NULL, "info->hComPropSheet = NULL\n");
158 ok(info->pfnComPropSheet != NULL, "info->pfnComPropSheet = NULL\n");
159 ok(!info->UserData, "info->UserData = %Ix\n", info->UserData);
160 ok(!info->Result, "info->Result = %Ix\n", info->Result);
161 break;
162 case PROPSHEETUI_REASON_GET_INFO_HEADER:
163 CHECK_EXPECT(callback_PROPSHEETUI_REASON_GET_INFO_HEADER);
164 ok(info->Version == PROPSHEETUI_INFO_VERSION, "info->Version = %hd\n", info->Version);
165 ok(info->Flags == PSUIINFO_UNICODE, "info->Flags = %hd\n", info->Flags);
166 ok(info->hComPropSheet != NULL, "info->hComPropSheet = NULL\n");
167 ok(info->pfnComPropSheet != NULL, "info->pfnComPropSheet = NULL\n");
168 ok(!info->UserData, "info->UserData = %Ix\n", info->UserData);
169 ok(!info->Result, "info->Result = %Ix\n", info->Result);
171 info_header = (PROPSHEETUI_INFO_HEADERW*)lparam;
172 ok(info_header->cbSize == sizeof(*info_header), "info_header->cbSize = %hd\n", info_header->cbSize);
173 ok(!info_header->Flags, "info_header->Flags = %hx\n", info_header->Flags);
174 ok(!info_header->pTitle, "info_header->pTitle = %p\n", info_header->pTitle);
175 ok(info_header->hWndParent == (HWND)0x4321, "info_header->hWndParent = %p\n", info_header->hWndParent);
176 ok(!info_header->hInst, "info_header->hInst = %p\n", info_header->hInst);
178 info_header->hWndParent = 0;
180 if (info->lParamInit & ADD_PAGES)
182 HPROPSHEETPAGE hpsp;
183 PROPSHEETPAGEW psp;
184 LONG_PTR ret;
186 SET_EXPECT(device_PROPSHEETUI_REASON_INIT);
187 SET_EXPECT(device_PROPSHEETUI_REASON_DESTROY);
188 ret = info->pfnComPropSheet(info->hComPropSheet, CPSFUNC_ADD_PFNPROPSHEETUIA, (LPARAM)device_property_sheets, 0);
189 ok(!ret, "ret = %Ix\n", ret);
190 CHECK_CALLED(device_PROPSHEETUI_REASON_INIT);
191 CHECK_CALLED(device_PROPSHEETUI_REASON_DESTROY);
193 SET_EXPECT(device_PROPSHEETUI_REASON_INIT);
194 ret = info->pfnComPropSheet(info->hComPropSheet, CPSFUNC_ADD_PFNPROPSHEETUIW, (LPARAM)device_property_sheets, 1);
195 ok(ret, "ret = 0\n");
196 CHECK_CALLED(device_PROPSHEETUI_REASON_INIT);
197 SET_EXPECT(device_PROPSHEETUI_REASON_DESTROY);
199 memset(&psp, 0, sizeof(psp));
200 psp.dwSize = sizeof(psp);
201 U(psp).pszTemplate = L"prop_page1";
202 psp.pfnDlgProc = prop_page_proc2;
203 ret = info->pfnComPropSheet(info->hComPropSheet, CPSFUNC_ADD_PROPSHEETPAGEW, (LPARAM)&psp, 0);
204 ok(ret, "ret = 0\n");
206 psp.pfnDlgProc = prop_page_proc;
207 hpsp = CreatePropertySheetPageW(&psp);
208 ok(hpsp != NULL, "hpsp = %p\n", hpsp);
209 ret = info->pfnComPropSheet(info->hComPropSheet, CPSFUNC_ADD_HPROPSHEETPAGE, (LPARAM)hpsp, 0);
210 ok(ret, "ret = 0\n");
212 break;
213 case PROPSHEETUI_REASON_DESTROY:
214 CHECK_EXPECT(callback_PROPSHEETUI_REASON_DESTROY);
215 if (info->lParamInit & ADD_PAGES)
217 CHECK_CALLED(device_PROPSHEETUI_REASON_DESTROY);
218 ok(lparam, "lparam = 0\n");
220 else
221 ok(!lparam, "lparam = %Ix\n", lparam);
223 ok(info->Version == PROPSHEETUI_INFO_VERSION, "info->Version = %hd\n", info->Version);
224 ok(info->Flags == PSUIINFO_UNICODE, "info->Flags = %hd\n", info->Flags);
225 ok(info->hComPropSheet != NULL, "info->hComPropSheet = NULL\n");
226 ok(info->pfnComPropSheet != NULL, "info->pfnComPropSheet = NULL\n");
227 ok(!info->UserData, "info->UserData = %Ix\n", info->UserData);
228 ok(!info->Result, "info->Result = %Ix\n", info->Result);
229 break;
230 default:
231 ok(0, "unhandled info->Reason = %hd\n", info->Reason);
232 break;
235 return 1;
238 static void test_CommonPropertySheetUI(void)
240 DWORD res;
241 LONG ret;
243 SetLastError(0xdeadbeef);
244 res = 0xdeadbeef;
245 ret = CommonPropertySheetUIW(0, NULL, 0, &res);
246 ok(ret == ERR_CPSUI_GETLASTERROR, "ret = %ld\n", ret);
247 ok(res == 0xdeadbeef, "res = %lx\n", res);
248 ok(!GetLastError(), "CommonPropertySheetUIW error %ld\n", GetLastError());
250 SET_EXPECT(callback_PROPSHEETUI_REASON_BEFORE_INIT);
251 SET_EXPECT(callback_PROPSHEETUI_REASON_INIT);
252 SET_EXPECT(callback_PROPSHEETUI_REASON_GET_INFO_HEADER);
253 SET_EXPECT(callback_PROPSHEETUI_REASON_DESTROY);
254 res = 0xdeadbeef;
255 ret = CommonPropertySheetUIW((HWND)0x4321, propsheetui_callback, 0, &res);
256 ok(ret == ERR_CPSUI_NO_PROPSHEETPAGE, "CommonPropertySheetUIW returned %ld\n", ret);
257 ok(!res, "res = %lx\n", res);
258 CLEAR_CALLED(callback_PROPSHEETUI_REASON_BEFORE_INIT);
259 CHECK_CALLED(callback_PROPSHEETUI_REASON_INIT);
260 CHECK_CALLED(callback_PROPSHEETUI_REASON_GET_INFO_HEADER);
261 CHECK_CALLED(callback_PROPSHEETUI_REASON_DESTROY);
263 SET_EXPECT(callback_PROPSHEETUI_REASON_BEFORE_INIT);
264 SET_EXPECT(callback_PROPSHEETUI_REASON_INIT);
265 SET_EXPECT(callback_PROPSHEETUI_REASON_GET_INFO_HEADER);
266 SET_EXPECT(page_proc2_WM_INITDIALOG);
267 SET_EXPECT(page_proc_WM_INITDIALOG);
268 SET_EXPECT(callback_PROPSHEETUI_REASON_DESTROY);
269 res = 0xdeadbeef;
270 ret = CommonPropertySheetUIW((HWND)0x4321, propsheetui_callback, ADD_PAGES, &res);
271 ok(ret == CPSUI_OK, "CommonPropertySheetUIW returned %ld\n", ret);
272 ok(!res, "res = %lx\n", res);
273 CLEAR_CALLED(callback_PROPSHEETUI_REASON_BEFORE_INIT);
274 CHECK_CALLED(callback_PROPSHEETUI_REASON_INIT);
275 CHECK_CALLED(callback_PROPSHEETUI_REASON_GET_INFO_HEADER);
276 CHECK_CALLED(page_proc2_WM_INITDIALOG);
277 CHECK_CALLED(page_proc_WM_INITDIALOG);
278 CHECK_CALLED(callback_PROPSHEETUI_REASON_DESTROY);
281 START_TEST(compstui)
283 test_CommonPropertySheetUI();