wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / uxtheme / tests / system.c
blob5b6c91dc481e4f2a8819063f75e8beeeb988344f
1 /* Unit test suite for uxtheme API functions
3 * Copyright 2006 Paul Vriens
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #include "windows.h"
24 #include "vfwmsgs.h"
25 #include "uxtheme.h"
27 #include "wine/test.h"
29 static HTHEME (WINAPI * pOpenThemeDataEx)(HWND, LPCWSTR, DWORD);
30 static HPAINTBUFFER (WINAPI *pBeginBufferedPaint)(HDC, const RECT *, BP_BUFFERFORMAT, BP_PAINTPARAMS *, HDC *);
31 static HRESULT (WINAPI *pBufferedPaintClear)(HPAINTBUFFER, const RECT *);
32 static HRESULT (WINAPI *pEndBufferedPaint)(HPAINTBUFFER, BOOL);
33 static HRESULT (WINAPI *pGetBufferedPaintBits)(HPAINTBUFFER, RGBQUAD **, int *);
34 static HDC (WINAPI *pGetBufferedPaintDC)(HPAINTBUFFER);
35 static HDC (WINAPI *pGetBufferedPaintTargetDC)(HPAINTBUFFER);
36 static HRESULT (WINAPI *pGetBufferedPaintTargetRect)(HPAINTBUFFER, RECT *);
38 static void init_funcs(void)
40 HMODULE hUxtheme = GetModuleHandleA("uxtheme.dll");
42 #define UXTHEME_GET_PROC(func) p ## func = (void*)GetProcAddress(hUxtheme, #func)
43 UXTHEME_GET_PROC(BeginBufferedPaint);
44 UXTHEME_GET_PROC(BufferedPaintClear);
45 UXTHEME_GET_PROC(EndBufferedPaint);
46 UXTHEME_GET_PROC(GetBufferedPaintBits);
47 UXTHEME_GET_PROC(GetBufferedPaintDC);
48 UXTHEME_GET_PROC(GetBufferedPaintTargetDC);
49 UXTHEME_GET_PROC(GetBufferedPaintTargetRect);
50 UXTHEME_GET_PROC(BufferedPaintClear);
52 UXTHEME_GET_PROC(OpenThemeDataEx);
53 #undef UXTHEME_GET_PROC
56 static void test_IsThemed(void)
58 BOOL bThemeActive;
59 BOOL bAppThemed;
60 BOOL bTPDefined;
62 bThemeActive = IsThemeActive();
63 trace("Theming is %s\n", (bThemeActive) ? "active" : "inactive");
65 bAppThemed = IsAppThemed();
66 trace("Test executable is %s\n", (bAppThemed) ? "themed" : "not themed");
68 SetLastError(0xdeadbeef);
69 bTPDefined = IsThemePartDefined(NULL, 0 , 0);
70 ok( bTPDefined == FALSE, "Expected FALSE\n");
71 ok( GetLastError() == E_HANDLE,
72 "Expected E_HANDLE, got 0x%08x\n",
73 GetLastError());
76 static void test_GetWindowTheme(void)
78 HTHEME hTheme;
79 HWND hWnd;
81 SetLastError(0xdeadbeef);
82 hTheme = GetWindowTheme(NULL);
83 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
84 todo_wine
85 ok( GetLastError() == E_HANDLE,
86 "Expected E_HANDLE, got 0x%08x\n",
87 GetLastError());
89 /* Only do the bare minimum to get a valid hwnd */
90 hWnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,0, 0, 0, NULL);
91 ok(hWnd != NULL, "Failed to create a test window.\n");
93 SetLastError(0xdeadbeef);
94 hTheme = GetWindowTheme(hWnd);
95 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
96 ok( GetLastError() == 0xdeadbeef,
97 "Expected 0xdeadbeef, got 0x%08x\n",
98 GetLastError());
100 DestroyWindow(hWnd);
103 static void test_SetWindowTheme(void)
105 HRESULT hRes;
106 HWND hWnd;
108 hRes = SetWindowTheme(NULL, NULL, NULL);
109 todo_wine
110 ok( hRes == E_HANDLE, "Expected E_HANDLE, got 0x%08x\n", hRes);
112 /* Only do the bare minimum to get a valid hwnd */
113 hWnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,0, 0, 0, NULL);
114 ok(hWnd != NULL, "Failed to create a test window.\n");
116 hRes = SetWindowTheme(hWnd, NULL, NULL);
117 ok( hRes == S_OK, "Expected S_OK, got 0x%08x\n", hRes);
119 DestroyWindow(hWnd);
122 static void test_OpenThemeData(void)
124 HTHEME hTheme, hTheme2;
125 HWND hWnd;
126 BOOL bThemeActive;
127 HRESULT hRes;
128 BOOL bTPDefined;
130 const WCHAR szInvalidClassList[] = L"DEADBEEF";
131 const WCHAR szButtonClassList[] = L"Button";
132 const WCHAR szButtonClassList2[] = L"bUtToN";
133 const WCHAR szClassList[] = L"Button;ListBox";
135 bThemeActive = IsThemeActive();
137 /* All NULL */
138 SetLastError(0xdeadbeef);
139 hTheme = OpenThemeData(NULL, NULL);
140 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
141 ok( GetLastError() == E_POINTER,
142 "Expected GLE() to be E_POINTER, got 0x%08x\n",
143 GetLastError());
145 /* A NULL hWnd and an invalid classlist */
146 SetLastError(0xdeadbeef);
147 hTheme = OpenThemeData(NULL, szInvalidClassList);
148 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
149 todo_wine
150 ok( GetLastError() == E_PROP_ID_UNSUPPORTED,
151 "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08x\n",
152 GetLastError());
154 SetLastError(0xdeadbeef);
155 hTheme = OpenThemeData(NULL, szClassList);
156 if (bThemeActive)
158 ok( hTheme != NULL, "got NULL, expected a HTHEME handle\n");
159 todo_wine
160 ok( GetLastError() == ERROR_SUCCESS,
161 "Expected ERROR_SUCCESS, got 0x%08x\n",
162 GetLastError());
164 else
166 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
167 todo_wine
168 ok( GetLastError() == E_PROP_ID_UNSUPPORTED,
169 "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08x\n",
170 GetLastError());
173 /* Only do the bare minimum to get a valid hdc */
174 hWnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,0, 0, 0, NULL);
175 if (!hWnd) return;
177 SetLastError(0xdeadbeef);
178 hTheme = OpenThemeData(hWnd, NULL);
179 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
180 ok( GetLastError() == E_POINTER,
181 "Expected GLE() to be E_POINTER, got 0x%08x\n",
182 GetLastError());
184 SetLastError(0xdeadbeef);
185 hTheme = OpenThemeData(hWnd, szInvalidClassList);
186 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
187 todo_wine
188 ok( GetLastError() == E_PROP_ID_UNSUPPORTED,
189 "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08x\n",
190 GetLastError());
192 if (!bThemeActive)
194 SetLastError(0xdeadbeef);
195 hTheme = OpenThemeData(hWnd, szButtonClassList);
196 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
197 todo_wine
198 ok( GetLastError() == E_PROP_ID_UNSUPPORTED,
199 "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08x\n",
200 GetLastError());
201 skip("No active theme, skipping rest of OpenThemeData tests\n");
202 return;
205 /* Only do the next checks if we have an active theme */
207 SetLastError(0xdeadbeef);
208 hTheme = OpenThemeData(hWnd, szButtonClassList);
209 ok( hTheme != NULL, "got NULL, expected a HTHEME handle\n");
210 todo_wine
211 ok( GetLastError() == ERROR_SUCCESS,
212 "Expected ERROR_SUCCESS, got 0x%08x\n",
213 GetLastError());
215 /* Test with bUtToN instead of Button */
216 SetLastError(0xdeadbeef);
217 hTheme = OpenThemeData(hWnd, szButtonClassList2);
218 ok( hTheme != NULL, "got NULL, expected a HTHEME handle\n");
219 todo_wine
220 ok( GetLastError() == ERROR_SUCCESS,
221 "Expected ERROR_SUCCESS, got 0x%08x\n",
222 GetLastError());
224 SetLastError(0xdeadbeef);
225 hTheme = OpenThemeData(hWnd, szClassList);
226 ok( hTheme != NULL, "got NULL, expected a HTHEME handle\n");
227 todo_wine
228 ok( GetLastError() == ERROR_SUCCESS,
229 "Expected ERROR_SUCCESS, got 0x%08x\n",
230 GetLastError());
232 /* GetWindowTheme should return the last handle opened by OpenThemeData */
233 SetLastError(0xdeadbeef);
234 hTheme2 = GetWindowTheme(hWnd);
235 ok( hTheme == hTheme2, "Expected the same HTHEME handle (%p<->%p)\n",
236 hTheme, hTheme2);
237 ok( GetLastError() == 0xdeadbeef,
238 "Expected 0xdeadbeef, got 0x%08x\n",
239 GetLastError());
241 hRes = CloseThemeData(hTheme);
242 ok( hRes == S_OK, "Expected S_OK, got 0x%08x\n", hRes);
244 /* Close a second time */
245 hRes = CloseThemeData(hTheme);
246 ok( hRes == S_OK, "Expected S_OK, got 0x%08x\n", hRes);
248 /* See if closing makes a difference for GetWindowTheme */
249 SetLastError(0xdeadbeef);
250 hTheme2 = NULL;
251 hTheme2 = GetWindowTheme(hWnd);
252 ok( hTheme == hTheme2, "Expected the same HTHEME handle (%p<->%p)\n",
253 hTheme, hTheme2);
254 ok( GetLastError() == 0xdeadbeef,
255 "Expected 0xdeadbeef, got 0x%08x\n",
256 GetLastError());
258 SetLastError(0xdeadbeef);
259 bTPDefined = IsThemePartDefined(hTheme, 0 , 0);
260 todo_wine
262 ok( bTPDefined == FALSE, "Expected FALSE\n");
263 ok( GetLastError() == ERROR_SUCCESS,
264 "Expected ERROR_SUCCESS, got 0x%08x\n",
265 GetLastError());
268 DestroyWindow(hWnd);
271 static void test_OpenThemeDataEx(void)
273 HTHEME hTheme;
274 HWND hWnd;
275 BOOL bThemeActive;
277 const WCHAR szInvalidClassList[] = L"DEADBEEF";
278 const WCHAR szButtonClassList[] = L"Button";
279 const WCHAR szButtonClassList2[] = L"bUtToN";
280 const WCHAR szClassList[] = L"Button;ListBox";
282 if (!pOpenThemeDataEx)
284 win_skip("OpenThemeDataEx not available\n");
285 return;
288 bThemeActive = IsThemeActive();
290 /* All NULL */
291 SetLastError(0xdeadbeef);
292 hTheme = pOpenThemeDataEx(NULL, NULL, 0);
293 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
294 ok( GetLastError() == E_POINTER,
295 "Expected GLE() to be E_POINTER, got 0x%08x\n",
296 GetLastError());
298 /* A NULL hWnd and an invalid classlist without flags */
299 SetLastError(0xdeadbeef);
300 hTheme = pOpenThemeDataEx(NULL, szInvalidClassList, 0);
301 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
302 todo_wine
303 ok( GetLastError() == E_PROP_ID_UNSUPPORTED,
304 "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08x\n",
305 GetLastError());
307 SetLastError(0xdeadbeef);
308 hTheme = pOpenThemeDataEx(NULL, szClassList, 0);
309 if (bThemeActive)
311 ok( hTheme != NULL, "got NULL, expected a HTHEME handle\n");
312 todo_wine
313 ok( GetLastError() == ERROR_SUCCESS,
314 "Expected ERROR_SUCCESS, got 0x%08x\n",
315 GetLastError());
317 else
319 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
320 todo_wine
321 ok( GetLastError() == E_PROP_ID_UNSUPPORTED,
322 "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08x\n",
323 GetLastError());
326 /* Only do the bare minimum to get a valid hdc */
327 hWnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,0, 0, 0, NULL);
328 if (!hWnd) return;
330 SetLastError(0xdeadbeef);
331 hTheme = pOpenThemeDataEx(hWnd, NULL, 0);
332 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
333 ok( GetLastError() == E_POINTER,
334 "Expected GLE() to be E_POINTER, got 0x%08x\n",
335 GetLastError());
337 SetLastError(0xdeadbeef);
338 hTheme = pOpenThemeDataEx(hWnd, szInvalidClassList, 0);
339 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
340 todo_wine
341 ok( GetLastError() == E_PROP_ID_UNSUPPORTED,
342 "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08x\n",
343 GetLastError());
345 if (!bThemeActive)
347 SetLastError(0xdeadbeef);
348 hTheme = pOpenThemeDataEx(hWnd, szButtonClassList, 0);
349 ok( hTheme == NULL, "Expected a NULL return, got %p\n", hTheme);
350 todo_wine
351 ok( GetLastError() == E_PROP_ID_UNSUPPORTED,
352 "Expected GLE() to be E_PROP_ID_UNSUPPORTED, got 0x%08x\n",
353 GetLastError());
354 skip("No active theme, skipping rest of OpenThemeDataEx tests\n");
355 return;
358 /* Only do the next checks if we have an active theme */
360 SetLastError(0xdeadbeef);
361 hTheme = pOpenThemeDataEx(hWnd, szButtonClassList, 0);
362 ok( hTheme != NULL, "got NULL, expected a HTHEME handle\n");
363 todo_wine
364 ok( GetLastError() == ERROR_SUCCESS,
365 "Expected ERROR_SUCCESS, got 0x%08x\n",
366 GetLastError());
368 SetLastError(0xdeadbeef);
369 hTheme = pOpenThemeDataEx(hWnd, szButtonClassList, OTD_FORCE_RECT_SIZING);
370 ok( hTheme != NULL, "got NULL, expected a HTHEME handle\n");
371 todo_wine
372 ok( GetLastError() == ERROR_SUCCESS,
373 "Expected ERROR_SUCCESS, got 0x%08x\n",
374 GetLastError());
376 SetLastError(0xdeadbeef);
377 hTheme = pOpenThemeDataEx(hWnd, szButtonClassList, OTD_NONCLIENT);
378 ok( hTheme != NULL, "got NULL, expected a HTHEME handle\n");
379 todo_wine
380 ok( GetLastError() == ERROR_SUCCESS,
381 "Expected ERROR_SUCCESS, got 0x%08x\n",
382 GetLastError());
384 SetLastError(0xdeadbeef);
385 hTheme = pOpenThemeDataEx(hWnd, szButtonClassList, 0x3);
386 ok( hTheme != NULL, "got NULL, expected a HTHEME handle\n");
387 todo_wine
388 ok( GetLastError() == ERROR_SUCCESS,
389 "Expected ERROR_SUCCESS, got 0x%08x\n",
390 GetLastError());
392 /* Test with bUtToN instead of Button */
393 SetLastError(0xdeadbeef);
394 hTheme = pOpenThemeDataEx(hWnd, szButtonClassList2, 0);
395 ok( hTheme != NULL, "got NULL, expected a HTHEME handle\n");
396 todo_wine
397 ok( GetLastError() == ERROR_SUCCESS,
398 "Expected ERROR_SUCCESS, got 0x%08x\n",
399 GetLastError());
401 SetLastError(0xdeadbeef);
402 hTheme = pOpenThemeDataEx(hWnd, szClassList, 0);
403 ok( hTheme != NULL, "got NULL, expected a HTHEME handle\n");
404 todo_wine
405 ok( GetLastError() == ERROR_SUCCESS,
406 "Expected ERROR_SUCCESS, got 0x%08x\n",
407 GetLastError());
409 DestroyWindow(hWnd);
412 static void test_GetCurrentThemeName(void)
414 BOOL bThemeActive;
415 HRESULT hRes;
416 WCHAR currentTheme[MAX_PATH];
417 WCHAR currentColor[MAX_PATH];
418 WCHAR currentSize[MAX_PATH];
420 bThemeActive = IsThemeActive();
422 /* All NULLs */
423 hRes = GetCurrentThemeName(NULL, 0, NULL, 0, NULL, 0);
424 if (bThemeActive)
425 ok( hRes == S_OK, "Expected S_OK, got 0x%08x\n", hRes);
426 else
427 ok( hRes == E_PROP_ID_UNSUPPORTED, "Expected E_PROP_ID_UNSUPPORTED, got 0x%08x\n", hRes);
429 /* Number of characters given is 0 */
430 hRes = GetCurrentThemeName(currentTheme, 0, NULL, 0, NULL, 0);
431 if (bThemeActive)
432 ok( hRes == S_OK || broken(hRes == E_FAIL /* WinXP SP1 */), "Expected S_OK, got 0x%08x\n", hRes);
433 else
434 ok( hRes == E_PROP_ID_UNSUPPORTED, "Expected E_PROP_ID_UNSUPPORTED, got 0x%08x\n", hRes);
436 hRes = GetCurrentThemeName(currentTheme, 2, NULL, 0, NULL, 0);
437 if (bThemeActive)
438 todo_wine
439 ok(hRes == E_NOT_SUFFICIENT_BUFFER ||
440 broken(hRes == E_FAIL /* WinXP SP1 */),
441 "Expected E_NOT_SUFFICIENT_BUFFER, got 0x%08x\n", hRes);
442 else
443 ok( hRes == E_PROP_ID_UNSUPPORTED, "Expected E_PROP_ID_UNSUPPORTED, got 0x%08x\n", hRes);
445 /* The same is true if the number of characters is too small for Color and/or Size */
446 hRes = GetCurrentThemeName(currentTheme, ARRAY_SIZE(currentTheme), currentColor, 2,
447 currentSize, ARRAY_SIZE(currentSize));
448 if (bThemeActive)
449 todo_wine
450 ok(hRes == E_NOT_SUFFICIENT_BUFFER ||
451 broken(hRes == E_FAIL /* WinXP SP1 */),
452 "Expected E_NOT_SUFFICIENT_BUFFER, got 0x%08x\n", hRes);
453 else
454 ok( hRes == E_PROP_ID_UNSUPPORTED, "Expected E_PROP_ID_UNSUPPORTED, got 0x%08x\n", hRes);
456 /* Given number of characters is correct */
457 hRes = GetCurrentThemeName(currentTheme, ARRAY_SIZE(currentTheme), NULL, 0, NULL, 0);
458 if (bThemeActive)
459 ok( hRes == S_OK, "Expected S_OK, got 0x%08x\n", hRes);
460 else
461 ok( hRes == E_PROP_ID_UNSUPPORTED, "Expected E_PROP_ID_UNSUPPORTED, got 0x%08x\n", hRes);
463 /* Given number of characters for the theme name is too large */
464 hRes = GetCurrentThemeName(currentTheme, sizeof(currentTheme), NULL, 0, NULL, 0);
465 if (bThemeActive)
466 ok( hRes == E_POINTER || hRes == S_OK, "Expected E_POINTER or S_OK, got 0x%08x\n", hRes);
467 else
468 ok( hRes == E_PROP_ID_UNSUPPORTED ||
469 hRes == E_POINTER, /* win2k3 */
470 "Expected E_PROP_ID_UNSUPPORTED, got 0x%08x\n", hRes);
472 /* The too large case is only for the theme name, not for color name or size name */
473 hRes = GetCurrentThemeName(currentTheme, ARRAY_SIZE(currentTheme), currentColor,
474 sizeof(currentTheme), currentSize, ARRAY_SIZE(currentSize));
475 if (bThemeActive)
476 ok( hRes == S_OK, "Expected S_OK, got 0x%08x\n", hRes);
477 else
478 ok( hRes == E_PROP_ID_UNSUPPORTED, "Expected E_PROP_ID_UNSUPPORTED, got 0x%08x\n", hRes);
480 hRes = GetCurrentThemeName(currentTheme, ARRAY_SIZE(currentTheme), currentColor,
481 ARRAY_SIZE(currentTheme), currentSize, sizeof(currentSize));
482 if (bThemeActive)
483 ok( hRes == S_OK, "Expected S_OK, got 0x%08x\n", hRes);
484 else
485 ok( hRes == E_PROP_ID_UNSUPPORTED, "Expected E_PROP_ID_UNSUPPORTED, got 0x%08x\n", hRes);
487 /* Correct call */
488 hRes = GetCurrentThemeName(currentTheme, ARRAY_SIZE(currentTheme), currentColor,
489 ARRAY_SIZE(currentColor), currentSize, ARRAY_SIZE(currentSize));
490 if (bThemeActive)
491 ok( hRes == S_OK, "Expected S_OK, got 0x%08x\n", hRes);
492 else
493 ok( hRes == E_PROP_ID_UNSUPPORTED, "Expected E_PROP_ID_UNSUPPORTED, got 0x%08x\n", hRes);
496 static void test_CloseThemeData(void)
498 HRESULT hRes;
500 hRes = CloseThemeData(NULL);
501 ok( hRes == E_HANDLE, "Expected E_HANDLE, got 0x%08x\n", hRes);
502 hRes = CloseThemeData(INVALID_HANDLE_VALUE);
503 ok( hRes == E_HANDLE, "Expected E_HANDLE, got 0x%08x\n", hRes);
506 static void test_buffer_dc_props(HDC hdc, const RECT *rect)
508 static const XFORM ident = { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f };
509 XFORM xform;
510 POINT org;
511 RECT box;
512 BOOL ret;
514 ret = GetWorldTransform(hdc, &xform);
515 ok(ret, "Failed to get world transform\n");
516 ok(!memcmp(&xform, &ident, sizeof(xform)), "Unexpected world transform\n");
518 ret = GetViewportOrgEx(hdc, &org);
519 ok(ret, "Failed to get vport origin\n");
520 ok(org.x == 0 && org.y == 0, "Unexpected vport origin\n");
522 ret = GetWindowOrgEx(hdc, &org);
523 ok(ret, "Failed to get vport origin\n");
524 ok(org.x == rect->left && org.y == rect->top, "Unexpected window origin\n");
526 ret = GetClipBox(hdc, &box);
527 ok(ret, "Failed to get clip box\n");
528 ok(box.left == rect->left && box.top == rect->top, "Unexpected clip box\n");
530 ok(GetGraphicsMode(hdc) == GM_COMPATIBLE, "wrong graphics mode\n");
533 static void test_buffered_paint(void)
535 HDC target, src, hdc, screen_dc;
536 BP_PAINTPARAMS params = { 0 };
537 BP_BUFFERFORMAT format;
538 HPAINTBUFFER buffer;
539 RECT rect, rect2;
540 RGBQUAD *bits;
541 HBITMAP hbm;
542 HRESULT hr;
543 int row;
545 if (!pBeginBufferedPaint)
547 win_skip("Buffered painting API is not supported.\n");
548 return;
551 buffer = pBeginBufferedPaint(NULL, NULL, BPBF_COMPATIBLEBITMAP,
552 NULL, NULL);
553 ok(buffer == NULL, "Unexpected buffer %p\n", buffer);
555 target = CreateCompatibleDC(0);
556 buffer = pBeginBufferedPaint(target, NULL, BPBF_COMPATIBLEBITMAP,
557 NULL, NULL);
558 ok(buffer == NULL, "Unexpected buffer %p\n", buffer);
560 params.cbSize = sizeof(params);
561 buffer = pBeginBufferedPaint(target, NULL, BPBF_COMPATIBLEBITMAP,
562 &params, NULL);
563 ok(buffer == NULL, "Unexpected buffer %p\n", buffer);
565 src = (void *)0xdeadbeef;
566 buffer = pBeginBufferedPaint(target, NULL, BPBF_COMPATIBLEBITMAP,
567 &params, &src);
568 ok(buffer == NULL, "Unexpected buffer %p\n", buffer);
569 ok(src == NULL, "Unexpected buffered dc %p\n", src);
571 /* target rect is mandatory */
572 SetRectEmpty(&rect);
573 src = (void *)0xdeadbeef;
574 buffer = pBeginBufferedPaint(target, &rect, BPBF_COMPATIBLEBITMAP,
575 &params, &src);
576 ok(buffer == NULL, "Unexpected buffer %p\n", buffer);
577 ok(src == NULL, "Unexpected buffered dc %p\n", src);
579 /* inverted rectangle */
580 SetRect(&rect, 10, 0, 5, 5);
581 src = (void *)0xdeadbeef;
582 buffer = pBeginBufferedPaint(target, &rect, BPBF_COMPATIBLEBITMAP,
583 &params, &src);
584 ok(buffer == NULL, "Unexpected buffer %p\n", buffer);
585 ok(src == NULL, "Unexpected buffered dc %p\n", src);
587 SetRect(&rect, 0, 10, 5, 0);
588 src = (void *)0xdeadbeef;
589 buffer = pBeginBufferedPaint(target, &rect, BPBF_COMPATIBLEBITMAP,
590 &params, &src);
591 ok(buffer == NULL, "Unexpected buffer %p\n", buffer);
592 ok(src == NULL, "Unexpected buffered dc %p\n", src);
594 /* valid rectangle, no target dc */
595 SetRect(&rect, 0, 0, 5, 5);
596 src = (void *)0xdeadbeef;
597 buffer = pBeginBufferedPaint(NULL, &rect, BPBF_COMPATIBLEBITMAP,
598 &params, &src);
599 ok(buffer == NULL, "Unexpected buffer %p\n", buffer);
600 ok(src == NULL, "Unexpected buffered dc %p\n", src);
602 SetRect(&rect, 0, 0, 5, 5);
603 src = NULL;
604 buffer = pBeginBufferedPaint(target, &rect, BPBF_COMPATIBLEBITMAP,
605 &params, &src);
606 ok(buffer != NULL, "Unexpected buffer %p\n", buffer);
607 ok(src != NULL, "Expected buffered dc\n");
608 hr = pEndBufferedPaint(buffer, FALSE);
609 ok(hr == S_OK, "Unexpected return code %#x\n", hr);
611 SetRect(&rect, 0, 0, 5, 5);
612 buffer = pBeginBufferedPaint(target, &rect, BPBF_COMPATIBLEBITMAP,
613 &params, &src);
614 ok(buffer != NULL, "Unexpected buffer %p\n", buffer);
616 /* clearing */
617 hr = pBufferedPaintClear(NULL, NULL);
618 todo_wine
619 ok(hr == E_FAIL, "Unexpected return code %#x\n", hr);
621 hr = pBufferedPaintClear(buffer, NULL);
622 todo_wine
623 ok(hr == S_OK, "Unexpected return code %#x\n", hr);
625 /* access buffer attributes */
626 hdc = pGetBufferedPaintDC(buffer);
627 ok(hdc == src, "Unexpected hdc, %p, buffered dc %p\n", hdc, src);
629 hdc = pGetBufferedPaintTargetDC(buffer);
630 ok(hdc == target, "Unexpected target hdc %p, original %p\n", hdc, target);
632 hr = pGetBufferedPaintTargetRect(NULL, NULL);
633 ok(hr == E_POINTER, "Unexpected return code %#x\n", hr);
635 hr = pGetBufferedPaintTargetRect(buffer, NULL);
636 ok(hr == E_POINTER, "Unexpected return code %#x\n", hr);
638 hr = pGetBufferedPaintTargetRect(NULL, &rect2);
639 ok(hr == E_FAIL, "Unexpected return code %#x\n", hr);
641 SetRectEmpty(&rect2);
642 hr = pGetBufferedPaintTargetRect(buffer, &rect2);
643 ok(hr == S_OK, "Unexpected return code %#x\n", hr);
644 ok(EqualRect(&rect, &rect2), "Wrong target rect\n");
646 hr = pEndBufferedPaint(buffer, FALSE);
647 ok(hr == S_OK, "Unexpected return code %#x\n", hr);
649 /* invalid buffer handle */
650 hr = pEndBufferedPaint(NULL, FALSE);
651 ok(hr == E_INVALIDARG, "Unexpected return code %#x\n", hr);
653 hdc = pGetBufferedPaintDC(NULL);
654 ok(hdc == NULL, "Unexpected hdc %p\n", hdc);
656 hdc = pGetBufferedPaintTargetDC(NULL);
657 ok(hdc == NULL, "Unexpected target hdc %p\n", hdc);
659 hr = pGetBufferedPaintTargetRect(NULL, &rect2);
660 ok(hr == E_FAIL, "Unexpected return code %#x\n", hr);
662 hr = pGetBufferedPaintTargetRect(NULL, NULL);
663 ok(hr == E_POINTER, "Unexpected return code %#x\n", hr);
665 bits = (void *)0xdeadbeef;
666 row = 10;
667 hr = pGetBufferedPaintBits(NULL, &bits, &row);
668 ok(hr == E_FAIL, "Unexpected return code %#x\n", hr);
669 ok(row == 10, "Unexpected row count %d\n", row);
670 ok(bits == (void *)0xdeadbeef, "Unexpected data pointer %p\n", bits);
672 hr = pGetBufferedPaintBits(NULL, NULL, NULL);
673 ok(hr == E_POINTER, "Unexpected return code %#x\n", hr);
675 hr = pGetBufferedPaintBits(NULL, &bits, NULL);
676 ok(hr == E_POINTER, "Unexpected return code %#x\n", hr);
678 hr = pGetBufferedPaintBits(NULL, NULL, &row);
679 ok(hr == E_POINTER, "Unexpected return code %#x\n", hr);
681 screen_dc = GetDC(0);
683 hdc = CreateCompatibleDC(screen_dc);
684 ok(hdc != NULL, "Failed to create a DC\n");
685 hbm = CreateCompatibleBitmap(screen_dc, 64, 64);
686 ok(hbm != NULL, "Failed to create a bitmap\n");
687 SelectObject(hdc, hbm);
689 ReleaseDC(0, screen_dc);
691 SetRect(&rect, 1, 2, 34, 56);
693 buffer = pBeginBufferedPaint(hdc, &rect, BPBF_COMPATIBLEBITMAP, NULL, &src);
694 test_buffer_dc_props(src, &rect);
695 hr = pEndBufferedPaint(buffer, FALSE);
696 ok(hr == S_OK, "Unexpected return code %#x\n", hr);
698 DeleteObject(hbm);
699 DeleteDC(hdc);
701 buffer = pBeginBufferedPaint(target, &rect, BPBF_COMPATIBLEBITMAP, NULL, &src);
702 test_buffer_dc_props(src, &rect);
703 hr = pEndBufferedPaint(buffer, FALSE);
704 ok(hr == S_OK, "Unexpected return code %#x\n", hr);
706 /* access buffer bits */
707 for (format = BPBF_COMPATIBLEBITMAP; format <= BPBF_TOPDOWNMONODIB; format++)
709 buffer = pBeginBufferedPaint(target, &rect, format, &params, &src);
711 /* only works for DIB buffers */
712 bits = NULL;
713 row = 0;
714 hr = pGetBufferedPaintBits(buffer, &bits, &row);
715 if (format == BPBF_COMPATIBLEBITMAP)
716 ok(hr == E_FAIL, "Unexpected return code %#x\n", hr);
717 else
719 ok(hr == S_OK, "Unexpected return code %#x\n", hr);
720 ok(bits != NULL, "Bitmap bits %p\n", bits);
721 ok(row >= (rect.right - rect.left), "format %d: bitmap width %d\n", format, row);
724 hr = pEndBufferedPaint(buffer, FALSE);
725 ok(hr == S_OK, "Unexpected return code %#x\n", hr);
728 DeleteDC(target);
731 START_TEST(system)
733 init_funcs();
735 /* No real functional theme API tests will be done (yet). The current tests
736 * only show input/return behaviour
739 test_IsThemed();
740 test_GetWindowTheme();
741 test_SetWindowTheme();
742 test_OpenThemeData();
743 test_OpenThemeDataEx();
744 test_GetCurrentThemeName();
745 test_CloseThemeData();
746 test_buffered_paint();