2 * Unit tests for dc functions
4 * Copyright (c) 2005 Huw Davies
5 * Copyright (c) 2005 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define WINVER 0x0501 /* request latest DEVMODE */
27 #include "wine/test.h"
33 static DWORD (WINAPI *pSetLayout)(HDC hdc, DWORD layout);
35 static void dump_region(HRGN hrgn)
43 printf( "(null) region\n" );
46 if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
47 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
48 GetRegionData( hrgn, size, data );
49 printf( "%d rects:", data->rdh.nCount );
50 for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
51 printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
53 HeapFree( GetProcessHeap(), 0, data );
56 static void test_savedc_2(void)
64 hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
67 ShowWindow(hwnd, SW_SHOW);
70 hrgn = CreateRectRgn(0, 0, 0, 0);
74 ok(hdc != NULL, "GetDC failed\n");
76 ret = GetClipBox(hdc, &rc_clip);
77 ok(ret == SIMPLEREGION || broken(ret == COMPLEXREGION), "GetClipBox returned %d instead of SIMPLEREGION\n", ret);
78 ret = GetClipRgn(hdc, hrgn);
79 ok(ret == 0, "GetClipRgn returned %d instead of 0\n", ret);
80 ret = GetRgnBox(hrgn, &rc);
81 ok(ret == NULLREGION, "GetRgnBox returned %d (%d,%d-%d,%d) instead of NULLREGION\n",
82 ret, rc.left, rc.top, rc.right, rc.bottom);
83 /*dump_region(hrgn);*/
84 SetRect(&rc, 0, 0, 100, 100);
85 ok(EqualRect(&rc, &rc_clip),
86 "rects are not equal: (%d,%d-%d,%d) - (%d,%d-%d,%d)\n",
87 rc.left, rc.top, rc.right, rc.bottom,
88 rc_clip.left, rc_clip.top, rc_clip.right, rc_clip.bottom);
93 ok(ret == 1, "ret = %d\n", ret);
96 ret = IntersectClipRect(hdc, 0, 0, 50, 50);
97 if (ret == COMPLEXREGION)
99 /* XP returns COMPLEXREGION although dump_region reports only 1 rect */
100 trace("Windows BUG: IntersectClipRect returned %d instead of SIMPLEREGION\n", ret);
101 /* let's make sure that it's a simple region */
102 ret = GetClipRgn(hdc, hrgn);
103 ok(ret == 1, "GetClipRgn returned %d instead of 1\n", ret);
107 ok(ret == SIMPLEREGION, "IntersectClipRect returned %d instead of SIMPLEREGION\n", ret);
109 ret = GetClipBox(hdc, &rc_clip);
110 ok(ret == SIMPLEREGION || broken(ret == COMPLEXREGION), "GetClipBox returned %d instead of SIMPLEREGION\n", ret);
111 SetRect(&rc, 0, 0, 50, 50);
112 ok(EqualRect(&rc, &rc_clip),
113 "rects are not equal: (%d,%d-%d,%d) - (%d,%d-%d,%d)\n",
114 rc.left, rc.top, rc.right, rc.bottom,
115 rc_clip.left, rc_clip.top, rc_clip.right, rc_clip.bottom);
117 ret = RestoreDC(hdc, 1);
118 ok(ret, "ret = %d\n", ret);
120 ret = GetClipBox(hdc, &rc_clip);
121 ok(ret == SIMPLEREGION || broken(ret == COMPLEXREGION), "GetClipBox returned %d instead of SIMPLEREGION\n", ret);
122 SetRect(&rc, 0, 0, 100, 100);
123 ok(EqualRect(&rc, &rc_clip),
124 "rects are not equal: (%d,%d-%d,%d) - (%d,%d-%d,%d)\n",
125 rc.left, rc.top, rc.right, rc.bottom,
126 rc_clip.left, rc_clip.top, rc_clip.right, rc_clip.bottom);
129 ReleaseDC(hwnd, hdc);
133 static void test_savedc(void)
135 HDC hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
138 ok(hdc != NULL, "CreateDC rets %p\n", hdc);
141 ok(ret == 1, "ret = %d\n", ret);
143 ok(ret == 2, "ret = %d\n", ret);
145 ok(ret == 3, "ret = %d\n", ret);
146 ret = RestoreDC(hdc, -1);
147 ok(ret, "ret = %d\n", ret);
149 ok(ret == 3, "ret = %d\n", ret);
150 ret = RestoreDC(hdc, 1);
151 ok(ret, "ret = %d\n", ret);
153 ok(ret == 1, "ret = %d\n", ret);
155 ok(ret == 2, "ret = %d\n", ret);
157 ok(ret == 3, "ret = %d\n", ret);
158 ret = RestoreDC(hdc, -2);
159 ok(ret, "ret = %d\n", ret);
161 ok(ret == 2, "ret = %d\n", ret);
162 ret = RestoreDC(hdc, -2);
163 ok(ret, "ret = %d\n", ret);
165 ok(ret == 1, "ret = %d\n", ret);
167 ok(ret == 2, "ret = %d\n", ret);
168 ret = RestoreDC(hdc, -4);
169 ok(!ret, "ret = %d\n", ret);
170 ret = RestoreDC(hdc, 3);
171 ok(!ret, "ret = %d\n", ret);
173 /* Under Win9x the following RestoreDC call succeeds and clears the save stack. */
174 ret = RestoreDC(hdc, -3);
176 broken(ret), /* Win9x */
179 /* Trying to clear an empty save stack fails. */
180 ret = RestoreDC(hdc, -3);
181 ok(!ret, "ret = %d\n", ret);
185 broken(ret == 1), /* Win9x */
188 /* Under Win9x the following RestoreDC call succeeds and clears the save stack. */
189 ret = RestoreDC(hdc, 0);
191 broken(ret), /* Win9x */
194 /* Trying to clear an empty save stack fails. */
195 ret = RestoreDC(hdc, 0);
196 ok(!ret, "ret = %d\n", ret);
198 ret = RestoreDC(hdc, 1);
200 broken(!ret), /* Win9x */
206 static void test_GdiConvertToDevmodeW(void)
208 DEVMODEW * (WINAPI *pGdiConvertToDevmodeW)(const DEVMODEA *);
213 pGdiConvertToDevmodeW = (void *)GetProcAddress(GetModuleHandleA("gdi32.dll"), "GdiConvertToDevmodeW");
214 if (!pGdiConvertToDevmodeW)
216 win_skip("GdiConvertToDevmodeW is not available on this platform\n");
220 ret = EnumDisplaySettingsA(NULL, ENUM_CURRENT_SETTINGS, &dmA);
221 ok(ret, "EnumDisplaySettingsExA error %u\n", GetLastError());
222 ok(dmA.dmSize >= FIELD_OFFSET(DEVMODEA, dmICMMethod), "dmSize is too small: %04x\n", dmA.dmSize);
223 ok(dmA.dmSize <= sizeof(DEVMODEA), "dmSize is too large: %04x\n", dmA.dmSize);
225 dmW = pGdiConvertToDevmodeW(&dmA);
226 ok(dmW->dmSize >= FIELD_OFFSET(DEVMODEW, dmICMMethod), "dmSize is too small: %04x\n", dmW->dmSize);
227 ok(dmW->dmSize <= sizeof(DEVMODEW), "dmSize is too large: %04x\n", dmW->dmSize);
228 HeapFree(GetProcessHeap(), 0, dmW);
230 dmA.dmSize = FIELD_OFFSET(DEVMODEA, dmFields) + sizeof(dmA.dmFields);
231 dmW = pGdiConvertToDevmodeW(&dmA);
232 ok(dmW->dmSize == FIELD_OFFSET(DEVMODEW, dmFields) + sizeof(dmW->dmFields),
233 "wrong size %u\n", dmW->dmSize);
234 HeapFree(GetProcessHeap(), 0, dmW);
236 dmA.dmICMMethod = DMICMMETHOD_NONE;
237 dmA.dmSize = FIELD_OFFSET(DEVMODEA, dmICMMethod) + sizeof(dmA.dmICMMethod);
238 dmW = pGdiConvertToDevmodeW(&dmA);
239 ok(dmW->dmSize == FIELD_OFFSET(DEVMODEW, dmICMMethod) + sizeof(dmW->dmICMMethod),
240 "wrong size %u\n", dmW->dmSize);
241 ok(dmW->dmICMMethod == DMICMMETHOD_NONE,
242 "expected DMICMMETHOD_NONE, got %u\n", dmW->dmICMMethod);
243 HeapFree(GetProcessHeap(), 0, dmW);
246 dmW = pGdiConvertToDevmodeW(&dmA);
247 ok(dmW->dmSize == FIELD_OFFSET(DEVMODEW, dmPanningHeight) + sizeof(dmW->dmPanningHeight),
248 "wrong size %u\n", dmW->dmSize);
249 HeapFree(GetProcessHeap(), 0, dmW);
251 SetLastError(0xdeadbeef);
253 dmW = pGdiConvertToDevmodeW(&dmA);
254 ok(!dmW, "GdiConvertToDevmodeW should fail\n");
255 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %u\n", GetLastError());
257 /* this is the minimal dmSize that XP accepts */
258 dmA.dmSize = FIELD_OFFSET(DEVMODEA, dmFields);
259 dmW = pGdiConvertToDevmodeW(&dmA);
260 ok(dmW->dmSize == FIELD_OFFSET(DEVMODEW, dmFields),
261 "expected %04x, got %04x\n", FIELD_OFFSET(DEVMODEW, dmFields), dmW->dmSize);
262 HeapFree(GetProcessHeap(), 0, dmW);
265 static void test_CreateCompatibleDC(void)
268 HDC hdc, hNewDC, hdcMetafile;
272 bitmap = CreateBitmap( 10, 10, 1, 1, NULL );
274 /* Create a DC compatible with the screen */
275 hdc = CreateCompatibleDC(NULL);
276 ok(hdc != NULL, "CreateCompatibleDC returned %p\n", hdc);
277 ok( SelectObject( hdc, bitmap ) != 0, "SelectObject failed\n" );
278 caps = GetDeviceCaps( hdc, TECHNOLOGY );
279 ok( caps == DT_RASDISPLAY, "wrong caps %u\n", caps );
281 /* Delete this DC, this should succeed */
282 bRet = DeleteDC(hdc);
283 ok(bRet == TRUE, "DeleteDC returned %u\n", bRet);
285 /* Try to create a DC compatible to the deleted DC. This has to fail */
286 hNewDC = CreateCompatibleDC(hdc);
287 ok(hNewDC == NULL, "CreateCompatibleDC returned %p\n", hNewDC);
290 hdcMetafile = CreateEnhMetaFileA(hdc, NULL, NULL, NULL);
291 ok(hdcMetafile != 0, "CreateEnhMetaFileA failed\n");
292 hNewDC = CreateCompatibleDC( hdcMetafile );
293 ok(hNewDC != NULL, "CreateCompatibleDC failed\n");
294 ok( SelectObject( hNewDC, bitmap ) != 0, "SelectObject failed\n" );
295 caps = GetDeviceCaps( hdcMetafile, TECHNOLOGY );
296 ok( caps == DT_RASDISPLAY, "wrong caps %u\n", caps );
297 caps = GetDeviceCaps( hNewDC, TECHNOLOGY );
298 ok( caps == DT_RASDISPLAY, "wrong caps %u\n", caps );
300 DeleteEnhMetaFile( CloseEnhMetaFile( hdcMetafile ));
303 hdcMetafile = CreateMetaFileA(NULL);
304 ok(hdcMetafile != 0, "CreateEnhMetaFileA failed\n");
305 hNewDC = CreateCompatibleDC( hdcMetafile );
306 ok(hNewDC == NULL, "CreateCompatibleDC succeeded\n");
307 caps = GetDeviceCaps( hdcMetafile, TECHNOLOGY );
308 ok( caps == DT_METAFILE, "wrong caps %u\n", caps );
309 DeleteMetaFile( CloseMetaFile( hdcMetafile ));
311 DeleteObject( bitmap );
314 static void test_DC_bitmap(void)
318 HBITMAP hbmp, oldhbmp;
322 /* fill bitmap data with b&w pattern */
323 for( i = 0; i < 64; i++) bits[i] = i & 1 ? 0 : 0xffffff;
326 ok( hdc != NULL, "CreateDC rets %p\n", hdc);
327 bitspixel = GetDeviceCaps( hdc, BITSPIXEL);
328 /* create a memory dc */
329 hdcmem = CreateCompatibleDC( hdc);
330 ok( hdcmem != NULL, "CreateCompatibleDC rets %p\n", hdcmem);
332 /* test monochrome bitmap: should always work */
333 hbmp = CreateBitmap(32, 32, 1, 1, bits);
334 ok( hbmp != NULL, "CreateBitmap returns %p\n", hbmp);
335 oldhbmp = SelectObject( hdcmem, hbmp);
336 ok( oldhbmp != NULL, "SelectObject returned NULL\n" ); /* a memdc always has a bitmap selected */
337 col = GetPixel( hdcmem, 0, 0);
338 ok( col == 0xffffff, "GetPixel returned %08x, expected 00ffffff\n", col);
339 col = GetPixel( hdcmem, 1, 1);
340 ok( col == 0x000000, "GetPixel returned %08x, expected 00000000\n", col);
341 col = GetPixel( hdcmem, 100, 1);
342 ok( col == CLR_INVALID, "GetPixel returned %08x, expected ffffffff\n", col);
343 SelectObject( hdcmem, oldhbmp);
346 /* test with 2 bits color depth, not likely to succeed */
347 hbmp = CreateBitmap(16, 16, 1, 2, bits);
348 ok( hbmp != NULL, "CreateBitmap returns %p\n", hbmp);
349 oldhbmp = SelectObject( hdcmem, hbmp);
351 ok( !oldhbmp, "SelectObject of a bitmap with 2 bits/pixel should return NULL\n");
352 if( oldhbmp) SelectObject( hdcmem, oldhbmp);
355 /* test with 16 bits color depth, might succeed */
356 hbmp = CreateBitmap(6, 6, 1, 16, bits);
357 ok( hbmp != NULL, "CreateBitmap returns %p\n", hbmp);
358 oldhbmp = SelectObject( hdcmem, hbmp);
359 if( bitspixel == 16) {
360 ok( oldhbmp != NULL, "SelectObject returned NULL\n" );
361 col = GetPixel( hdcmem, 0, 0);
363 "GetPixel of a bitmap with 16 bits/pixel returned %08x, expected 00ffffff\n", col);
364 col = GetPixel( hdcmem, 1, 1);
366 "GetPixel of a bitmap with 16 bits/pixel returned returned %08x, expected 00000000\n", col);
368 if( oldhbmp) SelectObject( hdcmem, oldhbmp);
371 /* test with 32 bits color depth, probably succeed */
372 hbmp = CreateBitmap(4, 4, 1, 32, bits);
373 ok( hbmp != NULL, "CreateBitmap returns %p\n", hbmp);
374 oldhbmp = SelectObject( hdcmem, hbmp);
375 if( bitspixel == 32) {
376 ok( oldhbmp != NULL, "SelectObject returned NULL\n" );
377 col = GetPixel( hdcmem, 0, 0);
379 "GetPixel of a bitmap with 32 bits/pixel returned %08x, expected 00ffffff\n", col);
380 col = GetPixel( hdcmem, 1, 1);
382 "GetPixel of a bitmap with 32 bits/pixel returned returned %08x, expected 00000000\n", col);
384 if( oldhbmp) SelectObject( hdcmem, oldhbmp);
389 static void test_DeleteDC(void)
397 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0,0,100,100,
399 ok(hwnd != 0, "CreateWindowExA failed\n");
402 ok(hdc != 0, "GetDC failed\n");
403 ret = GetObjectType(hdc);
404 ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
406 ok(ret, "DeleteDC failed\n");
407 ret = GetObjectType(hdc);
408 ok(!ret || broken(ret) /* win9x */, "GetObjectType should fail for a deleted DC\n");
410 hdc = GetWindowDC(hwnd);
411 ok(hdc != 0, "GetDC failed\n");
412 ret = GetObjectType(hdc);
413 ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
415 ok(ret, "DeleteDC failed\n");
416 ret = GetObjectType(hdc);
417 ok(!ret || broken(ret) /* win9x */, "GetObjectType should fail for a deleted DC\n");
421 /* desktop window DC */
422 hwnd = GetDesktopWindow();
423 ok(hwnd != 0, "GetDesktopWindow failed\n");
426 ok(hdc != 0, "GetDC failed\n");
427 ret = GetObjectType(hdc);
428 ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
430 ok(ret, "DeleteDC failed\n");
431 ret = GetObjectType(hdc);
432 ok(!ret || broken(ret) /* win9x */, "GetObjectType should fail for a deleted DC\n");
434 hdc = GetWindowDC(hwnd);
435 ok(hdc != 0, "GetDC failed\n");
436 ret = GetObjectType(hdc);
437 ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
439 ok(ret, "DeleteDC failed\n");
440 ret = GetObjectType(hdc);
441 ok(!ret || broken(ret) /* win9x */, "GetObjectType should fail for a deleted DC\n");
444 memset(&cls, 0, sizeof(cls));
445 cls.cbSize = sizeof(cls);
446 cls.style = CS_CLASSDC;
447 cls.hInstance = GetModuleHandle(0);
448 cls.lpszClassName = "Wine class DC";
449 cls.lpfnWndProc = DefWindowProcA;
450 ret = RegisterClassExA(&cls);
451 ok(ret, "RegisterClassExA failed\n");
453 hwnd = CreateWindowExA(0, "Wine class DC", NULL, WS_POPUP|WS_VISIBLE, 0,0,100,100,
455 ok(hwnd != 0, "CreateWindowExA failed\n");
458 ok(hdc != 0, "GetDC failed\n");
459 ret = GetObjectType(hdc);
460 ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
462 ok(ret, "DeleteDC failed\n");
463 ret = GetObjectType(hdc);
464 ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
465 ret = ReleaseDC(hwnd, hdc);
466 ok(ret, "ReleaseDC failed\n");
467 ret = GetObjectType(hdc);
468 ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
472 hdc = GetWindowDC(hwnd);
473 ok(hdc != 0, "GetDC failed\n");
474 ret = GetObjectType(hdc);
475 ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
477 ok(ret, "DeleteDC failed\n");
478 ret = GetObjectType(hdc);
479 ok(!ret || broken(ret) /* win9x */, "GetObjectType should fail for a deleted DC\n");
483 ret = GetObjectType(hdc_test);
484 ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
486 ret = UnregisterClassA("Wine class DC", GetModuleHandle(NULL));
487 ok(ret, "UnregisterClassA failed\n");
489 ret = GetObjectType(hdc_test);
491 ok(!ret, "GetObjectType should fail for a deleted DC\n");
494 memset(&cls, 0, sizeof(cls));
495 cls.cbSize = sizeof(cls);
496 cls.style = CS_OWNDC;
497 cls.hInstance = GetModuleHandle(0);
498 cls.lpszClassName = "Wine own DC";
499 cls.lpfnWndProc = DefWindowProcA;
500 ret = RegisterClassExA(&cls);
501 ok(ret, "RegisterClassExA failed\n");
503 hwnd = CreateWindowExA(0, "Wine own DC", NULL, WS_POPUP|WS_VISIBLE, 0,0,100,100,
505 ok(hwnd != 0, "CreateWindowExA failed\n");
508 ok(hdc != 0, "GetDC failed\n");
509 ret = GetObjectType(hdc);
510 ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
512 ok(ret, "DeleteDC failed\n");
513 ret = GetObjectType(hdc);
514 ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
515 ret = ReleaseDC(hwnd, hdc);
516 ok(ret, "ReleaseDC failed\n");
517 ret = GetObjectType(hdc);
518 ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
520 hdc = GetWindowDC(hwnd);
521 ok(hdc != 0, "GetDC failed\n");
522 ret = GetObjectType(hdc);
523 ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
525 ok(ret, "DeleteDC failed\n");
526 ret = GetObjectType(hdc);
527 ok(!ret || broken(ret) /* win9x */, "GetObjectType should fail for a deleted DC\n");
531 ret = UnregisterClassA("Wine own DC", GetModuleHandle(NULL));
532 ok(ret, "UnregisterClassA failed\n");
535 static void test_boundsrect(void)
539 RECT rect, expect, set_rect;
542 hdc = CreateCompatibleDC(0);
543 ok(hdc != NULL, "CreateCompatibleDC failed\n");
544 bitmap = CreateCompatibleBitmap( hdc, 200, 200 );
545 SelectObject( hdc, bitmap );
547 ret = GetBoundsRect(hdc, NULL, 0);
548 ok(ret == 0, "Expected GetBoundsRect to return 0, got %u\n", ret);
550 ret = GetBoundsRect(hdc, NULL, ~0U);
551 ok(ret == 0, "Expected GetBoundsRect to return 0, got %u\n", ret);
553 /* Test parameter handling order. */
554 SetRect(&set_rect, 10, 20, 40, 50);
555 ret = SetBoundsRect(hdc, &set_rect, DCB_SET);
557 "Expected return flag DCB_RESET to be set, got %u\n", ret);
559 ret = GetBoundsRect(hdc, NULL, DCB_RESET);
561 "Expected GetBoundsRect to return 0, got %u\n", ret);
563 ret = GetBoundsRect(hdc, &rect, 0);
565 "Expected GetBoundsRect to return DCB_RESET, got %u\n", ret);
566 SetRect(&expect, 0, 0, 0, 0);
567 ok(EqualRect(&rect, &expect) ||
568 broken(EqualRect(&rect, &set_rect)), /* nt4 sp1-5 */
569 "Expected output rectangle (0,0)-(0,0), got (%d,%d)-(%d,%d)\n",
570 rect.left, rect.top, rect.right, rect.bottom);
572 ret = GetBoundsRect(NULL, NULL, 0);
573 ok(ret == 0, "Expected GetBoundsRect to return 0, got %u\n", ret);
575 ret = GetBoundsRect(NULL, NULL, ~0U);
576 ok(ret == 0, "Expected GetBoundsRect to return 0, got %u\n", ret);
578 ret = SetBoundsRect(NULL, NULL, 0);
579 ok(ret == 0, "Expected SetBoundsRect to return 0, got %u\n", ret);
581 ret = SetBoundsRect(NULL, NULL, ~0U);
582 ok(ret == 0, "Expected SetBoundsRect to return 0, got %u\n", ret);
584 SetRect(&set_rect, 10, 20, 40, 50);
585 ret = SetBoundsRect(hdc, &set_rect, DCB_SET);
586 ok(ret == (DCB_RESET | DCB_DISABLE), "SetBoundsRect returned %x\n", ret);
588 ret = GetBoundsRect(hdc, &rect, 0);
589 ok(ret == DCB_SET, "GetBoundsRect returned %x\n", ret);
590 SetRect(&expect, 10, 20, 40, 50);
591 ok(EqualRect(&rect, &expect), "Got (%d,%d)-(%d,%d)\n",
592 rect.left, rect.top, rect.right, rect.bottom);
594 SetMapMode( hdc, MM_ANISOTROPIC );
595 SetViewportExtEx( hdc, 2, 2, NULL );
596 ret = GetBoundsRect(hdc, &rect, 0);
597 ok(ret == DCB_SET, "GetBoundsRect returned %x\n", ret);
598 SetRect(&expect, 5, 10, 20, 25);
599 ok(EqualRect(&rect, &expect), "Got (%d,%d)-(%d,%d)\n",
600 rect.left, rect.top, rect.right, rect.bottom);
602 SetViewportOrgEx( hdc, 20, 30, NULL );
603 ret = GetBoundsRect(hdc, &rect, 0);
604 ok(ret == DCB_SET, "GetBoundsRect returned %x\n", ret);
605 SetRect(&expect, -5, -5, 10, 10);
606 ok(EqualRect(&rect, &expect), "Got (%d,%d)-(%d,%d)\n",
607 rect.left, rect.top, rect.right, rect.bottom);
609 SetRect(&set_rect, 10, 20, 40, 50);
610 ret = SetBoundsRect(hdc, &set_rect, DCB_SET);
611 ok(ret == (DCB_SET | DCB_DISABLE), "SetBoundsRect returned %x\n", ret);
613 ret = GetBoundsRect(hdc, &rect, 0);
614 ok(ret == DCB_SET, "GetBoundsRect returned %x\n", ret);
615 SetRect(&expect, 10, 20, 40, 50);
616 ok(EqualRect(&rect, &expect), "Got (%d,%d)-(%d,%d)\n",
617 rect.left, rect.top, rect.right, rect.bottom);
619 SetMapMode( hdc, MM_TEXT );
620 SetViewportOrgEx( hdc, 0, 0, NULL );
621 ret = GetBoundsRect(hdc, &rect, 0);
622 ok(ret == DCB_SET, "GetBoundsRect returned %x\n", ret);
623 SetRect(&expect, 40, 70, 100, 130);
624 ok(EqualRect(&rect, &expect), "Got (%d,%d)-(%d,%d)\n",
625 rect.left, rect.top, rect.right, rect.bottom);
629 pSetLayout( hdc, LAYOUT_RTL );
630 ret = GetBoundsRect(hdc, &rect, 0);
631 ok(ret == DCB_SET, "GetBoundsRect returned %x\n", ret);
632 SetRect(&expect, 159, 70, 99, 130);
633 ok(EqualRect(&rect, &expect), "Got (%d,%d)-(%d,%d)\n",
634 rect.left, rect.top, rect.right, rect.bottom);
635 SetRect(&set_rect, 50, 25, 30, 35);
636 ret = SetBoundsRect(hdc, &set_rect, DCB_SET);
637 ok(ret == (DCB_SET | DCB_DISABLE), "SetBoundsRect returned %x\n", ret);
638 ret = GetBoundsRect(hdc, &rect, 0);
639 ok(ret == DCB_SET, "GetBoundsRect returned %x\n", ret);
640 SetRect(&expect, 50, 25, 30, 35);
641 ok(EqualRect(&rect, &expect), "Got (%d,%d)-(%d,%d)\n",
642 rect.left, rect.top, rect.right, rect.bottom);
644 pSetLayout( hdc, LAYOUT_LTR );
645 ret = GetBoundsRect(hdc, &rect, 0);
646 ok(ret == DCB_SET, "GetBoundsRect returned %x\n", ret);
647 SetRect(&expect, 149, 25, 169, 35);
648 ok(EqualRect(&rect, &expect), "Got (%d,%d)-(%d,%d)\n",
649 rect.left, rect.top, rect.right, rect.bottom);
652 /* empty rect resets, except on nt4 */
653 SetRect(&expect, 20, 20, 10, 10);
654 ret = SetBoundsRect(hdc, &set_rect, DCB_SET);
655 ok(ret == (DCB_SET | DCB_DISABLE), "SetBoundsRect returned %x\n", ret);
656 ret = GetBoundsRect(hdc, &rect, 0);
657 ok(ret == DCB_RESET || broken(ret == DCB_SET) /* nt4 */,
658 "GetBoundsRect returned %x\n", ret);
659 if (ret == DCB_RESET)
661 SetRect(&expect, 0, 0, 0, 0);
662 ok(EqualRect(&rect, &expect), "Got (%d,%d)-(%d,%d)\n",
663 rect.left, rect.top, rect.right, rect.bottom);
665 SetRect(&expect, 20, 20, 20, 20);
666 ret = SetBoundsRect(hdc, &set_rect, DCB_SET);
667 ok(ret == (DCB_RESET | DCB_DISABLE), "SetBoundsRect returned %x\n", ret);
668 ret = GetBoundsRect(hdc, &rect, 0);
669 ok(ret == DCB_RESET, "GetBoundsRect returned %x\n", ret);
670 SetRect(&expect, 0, 0, 0, 0);
671 ok(EqualRect(&rect, &expect), "Got (%d,%d)-(%d,%d)\n",
672 rect.left, rect.top, rect.right, rect.bottom);
676 DeleteObject( bitmap );
679 static void test_desktop_colorres(void)
681 HDC hdc = GetDC(NULL);
682 int bitspixel, colorres;
684 bitspixel = GetDeviceCaps(hdc, BITSPIXEL);
685 ok(bitspixel != 0, "Expected to get valid BITSPIXEL capability value\n");
687 colorres = GetDeviceCaps(hdc, COLORRES);
689 broken(colorres == 0), /* Win9x */
690 "Expected to get valid COLORRES capability value\n");
698 "Expected COLORRES to be 18, got %d\n", colorres);
702 "Expected COLORRES to be 16, got %d\n", colorres);
707 "Expected COLORRES to be 24, got %d\n", bitspixel);
710 ok(0, "Got unknown BITSPIXEL %d with COLORRES %d\n", bitspixel, colorres);
715 ReleaseDC(NULL, hdc);
718 static void test_gamma(void)
721 HDC hdc = GetDC(NULL);
722 WORD oldramp[3][256], ramp[3][256];
725 ret = GetDeviceGammaRamp(hdc, &oldramp);
728 win_skip("GetDeviceGammaRamp failed, skipping tests\n");
732 /* try to set back old ramp */
733 ret = SetDeviceGammaRamp(hdc, &oldramp);
736 win_skip("SetDeviceGammaRamp failed, skipping tests\n");
740 memcpy(ramp, oldramp, sizeof(ramp));
742 /* set one color ramp to zeros */
743 memset(ramp[0], 0, sizeof(ramp[0]));
744 ret = SetDeviceGammaRamp(hdc, &ramp);
745 ok(!ret, "SetDeviceGammaRamp succeeded\n");
747 /* set one color ramp to a flat straight rising line */
748 for (i = 0; i < 256; i++) ramp[0][i] = i;
749 ret = SetDeviceGammaRamp(hdc, &ramp);
750 todo_wine ok(!ret, "SetDeviceGammaRamp succeeded\n");
752 /* set one color ramp to a steep straight rising line */
753 for (i = 0; i < 256; i++) ramp[0][i] = i * 256;
754 ret = SetDeviceGammaRamp(hdc, &ramp);
755 ok(ret, "SetDeviceGammaRamp failed\n");
757 /* try a bright gamma ramp */
760 for (i = 2; i < 256; i++) ramp[0][i] = 0xFFFF;
761 ret = SetDeviceGammaRamp(hdc, &ramp);
762 ok(!ret, "SetDeviceGammaRamp succeeded\n");
764 /* try ramps which are not uniform */
766 for (i = 1; i < 256; i++) ramp[0][i] = ramp[0][i - 1] + 512;
767 ret = SetDeviceGammaRamp(hdc, &ramp);
768 ok(ret, "SetDeviceGammaRamp failed\n");
770 for (i = 2; i < 256; i+=2)
772 ramp[0][i - 1] = ramp[0][i - 2];
773 ramp[0][i] = ramp[0][i - 2] + 512;
775 ret = SetDeviceGammaRamp(hdc, &ramp);
776 ok(ret, "SetDeviceGammaRamp failed\n");
778 /* cleanup: set old ramp again */
779 ret = SetDeviceGammaRamp(hdc, &oldramp);
780 ok(ret, "SetDeviceGammaRamp failed\n");
783 ReleaseDC(NULL, hdc);
788 pSetLayout = (void *)GetProcAddress( GetModuleHandle("gdi32.dll"), "SetLayout");
791 test_GdiConvertToDevmodeW();
792 test_CreateCompatibleDC();
796 test_desktop_colorres();