wgl: Move wglGetCurrentDC to gdi32.
[wine/dibdrv.git] / dlls / gdi / tests / dc.c
blob59555facb73d573012b7afc0c807af2697827949
1 /*
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 #include <assert.h>
23 #include <stdio.h>
25 #include "wine/test.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "winerror.h"
31 static void dump_region(HRGN hrgn)
33 DWORD i, size;
34 RGNDATA *data = NULL;
35 RECT *rect;
37 if (!hrgn)
39 printf( "(null) region\n" );
40 return;
42 if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
43 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
44 GetRegionData( hrgn, size, data );
45 printf( "%d rects:", data->rdh.nCount );
46 for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
47 printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
48 printf( "\n" );
49 HeapFree( GetProcessHeap(), 0, data );
52 static void test_savedc_2(void)
54 HWND hwnd;
55 HDC hdc;
56 HRGN hrgn;
57 RECT rc, rc_clip;
58 int ret;
60 hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
61 0, 0, 0, NULL);
62 assert(hwnd != 0);
63 ShowWindow(hwnd, SW_SHOW);
64 UpdateWindow(hwnd);
66 hrgn = CreateRectRgn(0, 0, 0, 0);
67 assert(hrgn != 0);
69 hdc = GetDC(hwnd);
70 ok(hdc != NULL, "CreateDC rets %p\n", hdc);
72 ret = GetClipBox(hdc, &rc_clip);
73 ok(ret == SIMPLEREGION, "GetClipBox returned %d instead of SIMPLEREGION\n", ret);
74 ret = GetClipRgn(hdc, hrgn);
75 ok(ret == 0, "GetClipRgn returned %d instead of 0\n", ret);
76 ret = GetRgnBox(hrgn, &rc);
77 ok(ret == NULLREGION, "GetRgnBox returned %d (%d,%d-%d,%d) instead of NULLREGION\n",
78 ret, rc.left, rc.top, rc.right, rc.bottom);
79 /*dump_region(hrgn);*/
80 SetRect(&rc, 0, 0, 100, 100);
81 ok(EqualRect(&rc, &rc_clip),
82 "rects are not equal: (%d,%d-%d,%d) - (%d,%d-%d,%d)\n",
83 rc.left, rc.top, rc.right, rc.bottom,
84 rc_clip.left, rc_clip.top, rc_clip.right, rc_clip.bottom);
86 ret = SaveDC(hdc);
87 todo_wine
89 ok(ret == 1, "ret = %d\n", ret);
92 ret = IntersectClipRect(hdc, 0, 0, 50, 50);
93 #if 0 /* XP returns COMPLEXREGION although dump_region reports only 1 rect */
94 ok(ret == SIMPLEREGION, "IntersectClipRect returned %d instead of SIMPLEREGION\n", ret);
95 #endif
96 if (ret != SIMPLEREGION)
98 trace("Windows BUG: IntersectClipRect returned %d instead of SIMPLEREGION\n", ret);
99 /* let's make sure that it's a simple region */
100 ret = GetClipRgn(hdc, hrgn);
101 ok(ret == 1, "GetClipRgn returned %d instead of 1\n", ret);
102 dump_region(hrgn);
105 ret = GetClipBox(hdc, &rc_clip);
106 ok(ret == SIMPLEREGION, "GetClipBox returned %d instead of SIMPLEREGION\n", ret);
107 SetRect(&rc, 0, 0, 50, 50);
108 ok(EqualRect(&rc, &rc_clip), "rects are not equal\n");
110 ret = RestoreDC(hdc, 1);
111 ok(ret, "ret = %d\n", ret);
113 ret = GetClipBox(hdc, &rc_clip);
114 ok(ret == SIMPLEREGION, "GetClipBox returned %d instead of SIMPLEREGION\n", ret);
115 SetRect(&rc, 0, 0, 100, 100);
116 ok(EqualRect(&rc, &rc_clip), "rects are not equal\n");
118 DeleteObject(hrgn);
119 ReleaseDC(hwnd, hdc);
120 DestroyWindow(hwnd);
123 static void test_savedc(void)
125 HDC hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
126 int ret;
128 ok(hdc != NULL, "CreateDC rets %p\n", hdc);
130 ret = SaveDC(hdc);
131 ok(ret == 1, "ret = %d\n", ret);
132 ret = SaveDC(hdc);
133 ok(ret == 2, "ret = %d\n", ret);
134 ret = SaveDC(hdc);
135 ok(ret == 3, "ret = %d\n", ret);
136 ret = RestoreDC(hdc, -1);
137 ok(ret, "ret = %d\n", ret);
138 ret = SaveDC(hdc);
139 ok(ret == 3, "ret = %d\n", ret);
140 ret = RestoreDC(hdc, 1);
141 ok(ret, "ret = %d\n", ret);
142 ret = SaveDC(hdc);
143 ok(ret == 1, "ret = %d\n", ret);
144 ret = SaveDC(hdc);
145 ok(ret == 2, "ret = %d\n", ret);
146 ret = SaveDC(hdc);
147 ok(ret == 3, "ret = %d\n", ret);
148 ret = RestoreDC(hdc, -2);
149 ok(ret, "ret = %d\n", ret);
150 ret = SaveDC(hdc);
151 ok(ret == 2, "ret = %d\n", ret);
152 ret = RestoreDC(hdc, -2);
153 ok(ret, "ret = %d\n", ret);
154 ret = SaveDC(hdc);
155 ok(ret == 1, "ret = %d\n", ret);
156 ret = SaveDC(hdc);
157 ok(ret == 2, "ret = %d\n", ret);
158 ret = RestoreDC(hdc, -4);
159 ok(!ret, "ret = %d\n", ret);
160 ret = RestoreDC(hdc, 3);
161 ok(!ret, "ret = %d\n", ret);
163 /* Under win98 the following two succeed and both clear the save stack
164 ret = RestoreDC(hdc, -3);
165 ok(!ret, "ret = %d\n", ret);
166 ret = RestoreDC(hdc, 0);
167 ok(!ret, "ret = %d\n", ret);
170 ret = RestoreDC(hdc, 1);
171 ok(ret, "ret = %d\n", ret);
173 DeleteDC(hdc);
176 START_TEST(dc)
178 test_savedc();
179 test_savedc_2();