2 * Unit test suite for GDI objects
4 * Copyright 2002 Mike McCormack
5 * Copyright 2004 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
30 #include "wine/test.h"
32 static void test_gdi_objects(void)
35 HDC hdc
= GetDC(NULL
);
40 /* SelectObject() with a NULL DC returns 0 and sets ERROR_INVALID_HANDLE.
41 * Note: Under XP at least invalid ptrs can also be passed, not just NULL;
42 * Don't test that here in case it crashes earlier win versions.
45 hp
= SelectObject(NULL
, GetStockObject(BLACK_PEN
));
46 ok(!hp
&& (GetLastError() == ERROR_INVALID_HANDLE
|| broken(!GetLastError())),
47 "SelectObject(NULL DC) expected 0, ERROR_INVALID_HANDLE, got %p, %u\n",
50 /* With a valid DC and a NULL object, the call returns 0 but does not SetLastError() */
52 hp
= SelectObject(hdc
, NULL
);
53 ok(!hp
&& !GetLastError(),
54 "SelectObject(NULL obj) expected 0, NO_ERROR, got %p, %u\n",
57 /* The DC is unaffected by the NULL SelectObject */
59 hp
= SelectObject(hdc
, GetStockObject(BLACK_PEN
));
60 ok(hp
&& !GetLastError(),
61 "SelectObject(post NULL) expected non-null, NO_ERROR, got %p, %u\n",
64 /* GetCurrentObject does not SetLastError() on a null object */
66 hp
= GetCurrentObject(NULL
, OBJ_PEN
);
67 ok(!hp
&& !GetLastError(),
68 "GetCurrentObject(NULL DC) expected 0, NO_ERROR, got %p, %u\n",
71 /* DeleteObject does not SetLastError() on a null object */
72 ret
= DeleteObject(NULL
);
73 ok( !ret
&& !GetLastError(),
74 "DeleteObject(NULL obj), expected 0, NO_ERROR, got %d, %u\n",
77 /* GetObject does not SetLastError() on a null object */
79 i
= GetObjectA(NULL
, sizeof(buff
), buff
);
80 ok (!i
&& (GetLastError() == 0 || GetLastError() == ERROR_INVALID_PARAMETER
),
81 "GetObject(NULL obj), expected 0, NO_ERROR, got %d, %u\n",
84 /* GetObject expects ERROR_NOACCESS when passed an invalid buffer */
85 hp
= SelectObject(hdc
, GetStockObject(BLACK_PEN
));
87 i
= GetObjectA(hp
, (INT_PTR
)buff
, (LPVOID
)sizeof(buff
));
88 ok (!i
&& (GetLastError() == 0 || GetLastError() == ERROR_NOACCESS
),
89 "GetObject(invalid buff), expected 0, ERROR_NOACCESS, got %d, %u\n",
92 /* GetObjectType does SetLastError() on a null object */
94 i
= GetObjectType(NULL
);
95 ok (!i
&& GetLastError() == ERROR_INVALID_HANDLE
,
96 "GetObjectType(NULL obj), expected 0, ERROR_INVALID_HANDLE, got %d, %u\n",
99 /* UnrealizeObject does not SetLastError() on a null object */
101 i
= UnrealizeObject(NULL
);
102 ok (!i
&& !GetLastError(),
103 "UnrealizeObject(NULL obj), expected 0, NO_ERROR, got %d, %u\n",
106 ReleaseDC(NULL
, hdc
);
118 static DWORD WINAPI
thread_proc(void *param
)
121 struct hgdiobj_event
*hgdiobj_event
= param
;
123 hgdiobj_event
->hdc
= CreateDC("display", NULL
, NULL
, NULL
);
124 ok(hgdiobj_event
->hdc
!= NULL
, "CreateDC error %u\n", GetLastError());
126 hgdiobj_event
->hgdiobj1
= CreatePen(PS_DASHDOTDOT
, 17, RGB(1, 2, 3));
127 ok(hgdiobj_event
->hgdiobj1
!= 0, "Failed to create pen\n");
129 hgdiobj_event
->hgdiobj2
= CreateRectRgn(0, 1, 12, 17);
130 ok(hgdiobj_event
->hgdiobj2
!= 0, "Failed to create pen\n");
132 SetEvent(hgdiobj_event
->ready_event
);
133 ok(WaitForSingleObject(hgdiobj_event
->stop_event
, INFINITE
) == WAIT_OBJECT_0
,
134 "WaitForSingleObject error %u\n", GetLastError());
136 ok(!GetObject(hgdiobj_event
->hgdiobj1
, sizeof(lp
), &lp
), "GetObject should fail\n");
138 ok(!GetDeviceCaps(hgdiobj_event
->hdc
, TECHNOLOGY
), "GetDeviceCaps(TECHNOLOGY) should fail\n");
143 static void test_thread_objects(void)
148 struct hgdiobj_event hgdiobj_event
;
151 hgdiobj_event
.stop_event
= CreateEvent(NULL
, 0, 0, NULL
);
152 ok(hgdiobj_event
.stop_event
!= NULL
, "CreateEvent error %u\n", GetLastError());
153 hgdiobj_event
.ready_event
= CreateEvent(NULL
, 0, 0, NULL
);
154 ok(hgdiobj_event
.ready_event
!= NULL
, "CreateEvent error %u\n", GetLastError());
156 hthread
= CreateThread(NULL
, 0, thread_proc
, &hgdiobj_event
, 0, &tid
);
157 ok(hthread
!= NULL
, "CreateThread error %u\n", GetLastError());
159 ok(WaitForSingleObject(hgdiobj_event
.ready_event
, INFINITE
) == WAIT_OBJECT_0
,
160 "WaitForSingleObject error %u\n", GetLastError());
162 ok(GetObject(hgdiobj_event
.hgdiobj1
, sizeof(lp
), &lp
) == sizeof(lp
),
163 "GetObject error %u\n", GetLastError());
164 ok(lp
.lopnStyle
== PS_DASHDOTDOT
, "wrong pen style %d\n", lp
.lopnStyle
);
165 ok(lp
.lopnWidth
.x
== 17, "wrong pen width.y %d\n", lp
.lopnWidth
.x
);
166 ok(lp
.lopnWidth
.y
== 0, "wrong pen width.y %d\n", lp
.lopnWidth
.y
);
167 ok(lp
.lopnColor
== RGB(1, 2, 3), "wrong pen width.y %08x\n", lp
.lopnColor
);
169 ret
= GetDeviceCaps(hgdiobj_event
.hdc
, TECHNOLOGY
);
170 ok(ret
== DT_RASDISPLAY
, "GetDeviceCaps(TECHNOLOGY) should return DT_RASDISPLAY not %d\n", ret
);
172 ok(DeleteObject(hgdiobj_event
.hgdiobj1
), "DeleteObject error %u\n", GetLastError());
173 ok(DeleteDC(hgdiobj_event
.hdc
), "DeleteDC error %u\n", GetLastError());
175 type
= GetObjectType(hgdiobj_event
.hgdiobj2
);
176 ok(type
== OBJ_REGION
, "GetObjectType returned %u\n", type
);
178 SetEvent(hgdiobj_event
.stop_event
);
179 ok(WaitForSingleObject(hthread
, INFINITE
) == WAIT_OBJECT_0
,
180 "WaitForSingleObject error %u\n", GetLastError());
181 CloseHandle(hthread
);
183 type
= GetObjectType(hgdiobj_event
.hgdiobj2
);
184 ok(type
== OBJ_REGION
, "GetObjectType returned %u\n", type
);
185 ok(DeleteObject(hgdiobj_event
.hgdiobj2
), "DeleteObject error %u\n", GetLastError());
187 CloseHandle(hgdiobj_event
.stop_event
);
188 CloseHandle(hgdiobj_event
.ready_event
);
191 static void test_GetCurrentObject(void)
206 hdc
= CreateCompatibleDC(0);
209 type
= GetObjectType(hdc
);
210 ok(type
== OBJ_MEMDC
, "GetObjectType returned %u\n", type
);
212 hpen
= CreatePen(PS_SOLID
, 10, RGB(10, 20, 30));
214 SelectObject(hdc
, hpen
);
215 hobj
= GetCurrentObject(hdc
, OBJ_PEN
);
216 ok(hobj
== hpen
, "OBJ_PEN is wrong: %p\n", hobj
);
217 hobj
= GetCurrentObject(hdc
, OBJ_EXTPEN
);
218 ok(hobj
== hpen
|| broken(hobj
== 0) /* win9x */, "OBJ_EXTPEN is wrong: %p\n", hobj
);
220 hbrush
= CreateSolidBrush(RGB(10, 20, 30));
222 SelectObject(hdc
, hbrush
);
223 hobj
= GetCurrentObject(hdc
, OBJ_BRUSH
);
224 ok(hobj
== hbrush
, "OBJ_BRUSH is wrong: %p\n", hobj
);
226 hpal
= CreateHalftonePalette(hdc
);
228 SelectPalette(hdc
, hpal
, FALSE
);
229 hobj
= GetCurrentObject(hdc
, OBJ_PAL
);
230 ok(hobj
== hpal
, "OBJ_PAL is wrong: %p\n", hobj
);
232 hfont
= CreateFontA(10, 5, 0, 0, FW_DONTCARE
, 0, 0, 0, ANSI_CHARSET
,
233 OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
, DEFAULT_QUALITY
,
234 DEFAULT_PITCH
, "MS Sans Serif");
236 SelectObject(hdc
, hfont
);
237 hobj
= GetCurrentObject(hdc
, OBJ_FONT
);
238 ok(hobj
== hfont
, "OBJ_FONT is wrong: %p\n", hobj
);
240 hbmp
= CreateBitmap(100, 100, 1, 1, NULL
);
242 SelectObject(hdc
, hbmp
);
243 hobj
= GetCurrentObject(hdc
, OBJ_BITMAP
);
244 ok(hobj
== hbmp
, "OBJ_BITMAP is wrong: %p\n", hobj
);
246 assert(GetObject(hbrush
, sizeof(lb
), &lb
) == sizeof(lb
));
247 hpen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_SQUARE
| PS_JOIN_BEVEL
,
250 SelectObject(hdc
, hpen
);
251 hobj
= GetCurrentObject(hdc
, OBJ_PEN
);
252 ok(hobj
== hpen
, "OBJ_PEN is wrong: %p\n", hobj
);
253 hobj
= GetCurrentObject(hdc
, OBJ_EXTPEN
);
254 ok(hobj
== hpen
|| broken(hobj
== 0) /* win9x */, "OBJ_EXTPEN is wrong: %p\n", hobj
);
256 hcs
= GetColorSpace(hdc
);
259 trace("current color space is not NULL\n");
260 ok(GetLogColorSpaceA(hcs
, &lcs
, sizeof(lcs
)), "GetLogColorSpace failed\n");
261 hcs
= CreateColorSpaceA(&lcs
);
262 ok(hcs
!= 0, "CreateColorSpace failed\n");
263 SelectObject(hdc
, hcs
);
264 hobj
= GetCurrentObject(hdc
, OBJ_COLORSPACE
);
265 ok(hobj
== hcs
|| broken(hobj
== 0) /* win9x */, "OBJ_COLORSPACE is wrong: %p\n", hobj
);
268 hrgn
= CreateRectRgn(1, 1, 100, 100);
270 SelectObject(hdc
, hrgn
);
271 hobj
= GetCurrentObject(hdc
, OBJ_REGION
);
272 ok(!hobj
, "OBJ_REGION is wrong: %p\n", hobj
);
277 static void test_region(void)
279 HRGN hrgn
= CreateRectRgn(10, 10, 20, 20);
280 RECT rc
= { 5, 5, 15, 15 };
281 BOOL ret
= RectInRegion( hrgn
, &rc
);
282 ok( ret
, "RectInRegion should return TRUE\n");
283 /* swap left and right */
284 SetRect( &rc
, 15, 5, 5, 15 );
285 ret
= RectInRegion( hrgn
, &rc
);
286 ok( ret
, "RectInRegion should return TRUE\n");
287 /* swap top and bottom */
288 SetRect( &rc
, 5, 15, 15, 5 );
289 ret
= RectInRegion( hrgn
, &rc
);
290 ok( ret
, "RectInRegion should return TRUE\n");
292 SetRect( &rc
, 15, 15, 5, 5 );
293 ret
= RectInRegion( hrgn
, &rc
);
294 ok( ret
, "RectInRegion should return TRUE\n");
296 /* swap left and right in the region */
297 hrgn
= CreateRectRgn(20, 10, 10, 20);
298 SetRect( &rc
, 5, 5, 15, 15 );
299 ret
= RectInRegion( hrgn
, &rc
);
300 ok( ret
, "RectInRegion should return TRUE\n");
301 /* swap left and right */
302 SetRect( &rc
, 15, 5, 5, 15 );
303 ret
= RectInRegion( hrgn
, &rc
);
304 ok( ret
, "RectInRegion should return TRUE\n");
305 /* swap top and bottom */
306 SetRect( &rc
, 5, 15, 15, 5 );
307 ret
= RectInRegion( hrgn
, &rc
);
308 ok( ret
, "RectInRegion should return TRUE\n");
310 SetRect( &rc
, 15, 15, 5, 5 );
311 ret
= RectInRegion( hrgn
, &rc
);
312 ok( ret
, "RectInRegion should return TRUE\n");
319 test_thread_objects();
320 test_GetCurrentObject();