ReactOS 0.4.15-dev-7994-gb388cb6
gdiobj.c
Go to the documentation of this file.
1/*
2 * Unit test suite for GDI objects
3 *
4 * Copyright 2002 Mike McCormack
5 * Copyright 2004 Dmitry Timoshkov
6 *
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.
11 *
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.
16 *
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
20 */
21
22#include <stdarg.h>
23#include <assert.h>
24
25#include "windef.h"
26#include "winbase.h"
27#include "wingdi.h"
28#include "winuser.h"
29
30#include "wine/test.h"
31
32static void test_gdi_objects(void)
33{
34 BYTE buff[256];
35 HDC hdc = GetDC(NULL);
36 HPEN hp;
37 int i;
38 BOOL ret;
39
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.
43 */
44 SetLastError(0);
47 "SelectObject(NULL DC) expected 0, ERROR_INVALID_HANDLE, got %p, %u\n",
48 hp, GetLastError());
49
50 /* With a valid DC and a NULL object, the call returns 0 but does not SetLastError() */
51 SetLastError(0);
52 hp = SelectObject(hdc, NULL);
53 ok(!hp && !GetLastError(),
54 "SelectObject(NULL obj) expected 0, NO_ERROR, got %p, %u\n",
55 hp, GetLastError());
56
57 /* The DC is unaffected by the NULL SelectObject */
58 SetLastError(0);
60 ok(hp && !GetLastError(),
61 "SelectObject(post NULL) expected non-null, NO_ERROR, got %p, %u\n",
62 hp, GetLastError());
63
64 /* GetCurrentObject does not SetLastError() on a null object */
65 SetLastError(0);
67 ok(!hp && !GetLastError(),
68 "GetCurrentObject(NULL DC) expected 0, NO_ERROR, got %p, %u\n",
69 hp, GetLastError());
70
71 /* DeleteObject does not SetLastError() on a null object */
73 ok( !ret && !GetLastError(),
74 "DeleteObject(NULL obj), expected 0, NO_ERROR, got %d, %u\n",
75 ret, GetLastError());
76
77 /* GetObject does not SetLastError() on a null object */
78 SetLastError(0);
79 i = GetObjectA(NULL, sizeof(buff), buff);
81 "GetObject(NULL obj), expected 0, NO_ERROR, got %d, %u\n",
82 i, GetLastError());
83
84 /* GetObject expects ERROR_NOACCESS when passed an invalid buffer */
86 SetLastError(0);
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",
90 i, GetLastError());
91
92 /* GetObjectType does SetLastError() on a null object */
93 SetLastError(0);
96 "GetObjectType(NULL obj), expected 0, ERROR_INVALID_HANDLE, got %d, %u\n",
97 i, GetLastError());
98
99 /* UnrealizeObject does not SetLastError() on a null object */
100 SetLastError(0);
102 ok (!i && !GetLastError(),
103 "UnrealizeObject(NULL obj), expected 0, NO_ERROR, got %d, %u\n",
104 i, GetLastError());
105
107}
108
110{
116};
117
119{
120 LOGPEN lp;
123
124 hgdiobj_event->hdc = CreateDCA("display", NULL, NULL, NULL);
125 ok(hgdiobj_event->hdc != NULL, "CreateDC error %u\n", GetLastError());
126
128 ok(hgdiobj_event->hgdiobj1 != 0, "Failed to create pen\n");
129
130 hgdiobj_event->hgdiobj2 = CreateRectRgn(0, 1, 12, 17);
131 ok(hgdiobj_event->hgdiobj2 != 0, "Failed to create pen\n");
132
135 ok(status == WAIT_OBJECT_0, "WaitForSingleObject error %u\n", GetLastError());
136
137 ok(!GetObjectA(hgdiobj_event->hgdiobj1, sizeof(lp), &lp), "GetObject should fail\n");
138
139 ok(!GetDeviceCaps(hgdiobj_event->hdc, TECHNOLOGY), "GetDeviceCaps(TECHNOLOGY) should fail\n");
140
141 return 0;
142}
143
144static void test_thread_objects(void)
145{
146 LOGPEN lp;
147 DWORD tid, type;
148 HANDLE hthread;
150 INT ret;
152 BOOL bRet;
153
155 ok(hgdiobj_event.stop_event != NULL, "CreateEvent error %u\n", GetLastError());
157 ok(hgdiobj_event.ready_event != NULL, "CreateEvent error %u\n", GetLastError());
158
159 hthread = CreateThread(NULL, 0, thread_proc, &hgdiobj_event, 0, &tid);
160 ok(hthread != NULL, "CreateThread error %u\n", GetLastError());
161
163 ok(status == WAIT_OBJECT_0, "WaitForSingleObject error %u\n", GetLastError());
164
165 ret = GetObjectA(hgdiobj_event.hgdiobj1, sizeof(lp), &lp);
166 ok(ret == sizeof(lp), "GetObject error %u\n", GetLastError());
167 ok(lp.lopnStyle == PS_DASHDOTDOT, "wrong pen style %d\n", lp.lopnStyle);
168 ok(lp.lopnWidth.x == 17, "wrong pen width.y %d\n", lp.lopnWidth.x);
169 ok(lp.lopnWidth.y == 0, "wrong pen width.y %d\n", lp.lopnWidth.y);
170 ok(lp.lopnColor == RGB(1, 2, 3), "wrong pen width.y %08x\n", lp.lopnColor);
171
173 ok(ret == DT_RASDISPLAY, "GetDeviceCaps(TECHNOLOGY) should return DT_RASDISPLAY not %d\n", ret);
174
176 ok(bRet, "DeleteObject error %u\n", GetLastError());
177 bRet = DeleteDC(hgdiobj_event.hdc);
178 ok(bRet, "DeleteDC error %u\n", GetLastError());
179
181 ok(type == OBJ_REGION, "GetObjectType returned %u\n", type);
182
185 ok(status == WAIT_OBJECT_0, "WaitForSingleObject error %u\n", GetLastError());
186 CloseHandle(hthread);
187
189 ok(type == OBJ_REGION, "GetObjectType returned %u\n", type);
191 ok(bRet, "DeleteObject error %u\n", GetLastError());
192
195}
196
197static void test_GetCurrentObject(void)
198{
199 DWORD type;
200 HPEN hpen;
201 HBRUSH hbrush;
202 HPALETTE hpal;
203 HFONT hfont;
205 HRGN hrgn;
206 HDC hdc;
207 HCOLORSPACE hcs;
208 HGDIOBJ hobj;
209 LOGBRUSH lb;
210 LOGCOLORSPACEA lcs;
211
213 assert(hdc != 0);
214
216 ok(type == OBJ_MEMDC, "GetObjectType returned %u\n", type);
217
218 hpen = CreatePen(PS_SOLID, 10, RGB(10, 20, 30));
219 assert(hpen != 0);
222 ok(hobj == hpen, "OBJ_PEN is wrong: %p\n", hobj);
224 ok(hobj == hpen, "OBJ_EXTPEN is wrong: %p\n", hobj);
225
226 hbrush = CreateSolidBrush(RGB(10, 20, 30));
227 assert(hbrush != 0);
230 ok(hobj == hbrush, "OBJ_BRUSH is wrong: %p\n", hobj);
231
233 assert(hpal != 0);
234 SelectPalette(hdc, hpal, FALSE);
236 ok(hobj == hpal, "OBJ_PAL is wrong: %p\n", hobj);
237
238 hfont = CreateFontA(10, 5, 0, 0, FW_DONTCARE, 0, 0, 0, ANSI_CHARSET,
240 DEFAULT_PITCH, "MS Sans Serif");
241 assert(hfont != 0);
244 ok(hobj == hfont, "OBJ_FONT is wrong: %p\n", hobj);
245
246 hbmp = CreateBitmap(100, 100, 1, 1, NULL);
247 assert(hbmp != 0);
250 ok(hobj == hbmp, "OBJ_BITMAP is wrong: %p\n", hobj);
251
252 assert(GetObjectA(hbrush, sizeof(lb), &lb) == sizeof(lb));
254 10, &lb, 0, NULL);
255 assert(hpen != 0);
258 ok(hobj == hpen, "OBJ_PEN is wrong: %p\n", hobj);
260 ok(hobj == hpen, "OBJ_EXTPEN is wrong: %p\n", hobj);
261
262 hcs = GetColorSpace(hdc);
263 if (hcs)
264 {
265 trace("current color space is not NULL\n");
266 ok(GetLogColorSpaceA(hcs, &lcs, sizeof(lcs)), "GetLogColorSpace failed\n");
267 hcs = CreateColorSpaceA(&lcs);
268 ok(hcs != 0, "CreateColorSpace failed\n");
269 SelectObject(hdc, hcs);
271 ok(hobj == hcs, "OBJ_COLORSPACE is wrong: %p\n", hobj);
272 }
273
274 hrgn = CreateRectRgn(1, 1, 100, 100);
275 assert(hrgn != 0);
278 ok(!hobj, "OBJ_REGION is wrong: %p\n", hobj);
279
280 DeleteDC(hdc);
281}
282
283static void test_region(void)
284{
285 HRGN hrgn = CreateRectRgn(10, 10, 20, 20);
286 RECT rc = { 5, 5, 15, 15 };
287 BOOL ret = RectInRegion( hrgn, &rc);
288 ok( ret, "RectInRegion should return TRUE\n");
289 /* swap left and right */
290 SetRect( &rc, 15, 5, 5, 15 );
291 ret = RectInRegion( hrgn, &rc);
292 ok( ret, "RectInRegion should return TRUE\n");
293 /* swap top and bottom */
294 SetRect( &rc, 5, 15, 15, 5 );
295 ret = RectInRegion( hrgn, &rc);
296 ok( ret, "RectInRegion should return TRUE\n");
297 /* swap both */
298 SetRect( &rc, 15, 15, 5, 5 );
299 ret = RectInRegion( hrgn, &rc);
300 ok( ret, "RectInRegion should return TRUE\n");
302 /* swap left and right in the region */
303 hrgn = CreateRectRgn(20, 10, 10, 20);
304 SetRect( &rc, 5, 5, 15, 15 );
305 ret = RectInRegion( hrgn, &rc);
306 ok( ret, "RectInRegion should return TRUE\n");
307 /* swap left and right */
308 SetRect( &rc, 15, 5, 5, 15 );
309 ret = RectInRegion( hrgn, &rc);
310 ok( ret, "RectInRegion should return TRUE\n");
311 /* swap top and bottom */
312 SetRect( &rc, 5, 15, 15, 5 );
313 ret = RectInRegion( hrgn, &rc);
314 ok( ret, "RectInRegion should return TRUE\n");
315 /* swap both */
316 SetRect( &rc, 15, 15, 5, 5 );
317 ret = RectInRegion( hrgn, &rc);
318 ok( ret, "RectInRegion should return TRUE\n");
320}
321
322static void test_handles_on_win64(void)
323{
324 int i;
325 BOOL ret;
326 DWORD type;
327 HRGN hrgn, hrgn_test;
328
329 static const struct
330 {
331 ULONG high;
332 ULONG low;
333 BOOL ret;
334 } cases[] =
335 {
336 { 0x00000000, 0x00000000, TRUE },
337 { 0x00000000, 0x0000ffe0, FALSE }, /* just over MAX_LARGE_HANDLES */
338 { 0x00000000, 0x0000ffb0, FALSE }, /* just under MAX_LARGE_HANDLES */
339 { 0xffffffff, 0xffff0000, FALSE },
340 { 0xffffffff, 0x00000000, TRUE },
341 { 0xdeadbeef, 0x00000000, TRUE },
342 { 0xcccccccc, 0xcccccccc, FALSE }
343 };
344
345 if (sizeof(void*) != 8)
346 return;
347
348 for (i = 0; i < sizeof(cases)/sizeof(cases[0]); i++)
349 {
350 hrgn = CreateRectRgn(10, 10, 20, 20);
351 hrgn_test = (HRGN)(ULONG_PTR)((ULONG_PTR)hrgn | ((ULONGLONG)cases[i].high << 32) | cases[i].low);
352 type = GetObjectType( hrgn_test );
353 if (cases[i].ret)
354 ok( type == OBJ_REGION, "wrong type %u\n", type );
355 else
356 ok( type == 0, "wrong type %u\n", type );
357 ret = DeleteObject(hrgn_test);
358 ok( cases[i].ret == ret, "DeleteObject should return %s (%p)\n",
359 cases[i].ret ? "TRUE" : "FALSE", hrgn_test);
360 /* actually free it if above is expected to fail */
361 if (!ret) DeleteObject(hrgn);
362 }
363}
364
366{
370 test_region();
372}
static HFONT hfont
static HRGN hrgn
static HBRUSH hbrush
static HPEN hpen
static POBJECT_TYPE GetObjectType(IN PCWSTR TypeName)
Definition: ObTypes.c:15
#define broken(x)
Definition: _sntprintf.h:21
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
HBITMAP hbmp
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
#define assert(x)
Definition: debug.h:53
#define RGB(r, g, b)
Definition: precomp.h:71
#define INFINITE
Definition: serial.h:102
#define ULONG_PTR
Definition: config.h:101
static unsigned char buff[32768]
Definition: fatten.c:17
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
pKey DeleteObject()
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLfloat param
Definition: glext.h:5796
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HDC hdc
Definition: main.c:9
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:92
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
static void test_thread_objects(void)
Definition: gdiobj.c:144
static void test_gdi_objects(void)
Definition: gdiobj.c:32
static DWORD WINAPI thread_proc(void *param)
Definition: gdiobj.c:118
static void test_GetCurrentObject(void)
Definition: gdiobj.c:197
static void test_handles_on_win64(void)
Definition: gdiobj.c:322
static void test_region(void)
Definition: gdiobj.c:283
static TfClientId tid
#define OBJ_EXTPEN
Definition: objidl.idl:1419
#define OBJ_REGION
Definition: objidl.idl:1416
#define OBJ_PEN
Definition: objidl.idl:1409
#define OBJ_BRUSH
Definition: objidl.idl:1410
#define OBJ_FONT
Definition: objidl.idl:1414
#define OBJ_BITMAP
Definition: objidl.idl:1415
#define OBJ_PAL
Definition: objidl.idl:1413
#define OBJ_MEMDC
Definition: objidl.idl:1418
HANDLE ready_event
Definition: gdiobj.c:115
HGDIOBJ hgdiobj1
Definition: gdiobj.c:112
HGDIOBJ hgdiobj2
Definition: gdiobj.c:113
HANDLE stop_event
Definition: gdiobj.c:114
Definition: ps.c:97
COLORREF lopnColor
Definition: wingdi.h:1847
POINT lopnWidth
Definition: wingdi.h:1846
UINT lopnStyle
Definition: wingdi.h:1845
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventA(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCSTR lpName OPTIONAL)
Definition: synch.c:637
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
int32_t INT_PTR
Definition: typedefs.h:64
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WAIT_OBJECT_0
Definition: winbase.h:406
#define WINAPI
Definition: msvc.h:6
#define ERROR_NOACCESS
Definition: winerror.h:578
#define DEFAULT_PITCH
Definition: wingdi.h:443
BOOL WINAPI UnrealizeObject(_In_ HGDIOBJ)
HGDIOBJ WINAPI GetStockObject(_In_ int)
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)
#define FW_DONTCARE
Definition: wingdi.h:368
#define DT_RASDISPLAY
Definition: wingdi.h:708
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
#define PS_JOIN_BEVEL
Definition: wingdi.h:597
HRGN WINAPI CreateRectRgn(_In_ int, _In_ int, _In_ int, _In_ int)
int WINAPI GetObjectA(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
HPEN WINAPI ExtCreatePen(_In_ DWORD iPenStyle, _In_ DWORD cWidth, _In_ const LOGBRUSH *plbrush, _In_ DWORD cStyle, _In_reads_opt_(cStyle) const DWORD *pstyle)
#define PS_ENDCAP_SQUARE
Definition: wingdi.h:595
#define DEFAULT_QUALITY
Definition: wingdi.h:436
#define OBJ_COLORSPACE
Definition: wingdi.h:704
BOOL WINAPI GetLogColorSpaceA(_In_ HCOLORSPACE hColorSpace, _Out_writes_bytes_(nSize) LPLOGCOLORSPACEA lpBuffer, _In_ DWORD nSize)
HPALETTE WINAPI SelectPalette(_In_ HDC, _In_ HPALETTE, _In_ BOOL)
HGDIOBJ WINAPI GetCurrentObject(_In_ HDC, _In_ UINT)
Definition: dc.c:428
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
HDC WINAPI CreateDCA(_In_opt_ LPCSTR pszDriver, _In_opt_ LPCSTR pszDevice, _In_opt_ LPCSTR pszOutput, _In_opt_ const DEVMODEA *pdmInit)
#define PS_GEOMETRIC
Definition: wingdi.h:583
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
HCOLORSPACE WINAPI CreateColorSpaceA(_In_ LPLOGCOLORSPACEA pLogColorSpace)
#define OUT_DEFAULT_PRECIS
Definition: wingdi.h:415
#define BLACK_PEN
Definition: wingdi.h:903
#define ANSI_CHARSET
Definition: wingdi.h:383
#define CLIP_DEFAULT_PRECIS
Definition: wingdi.h:426
BOOL WINAPI RectInRegion(_In_ HRGN, _In_ LPCRECT)
HFONT WINAPI CreateFontA(_In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_opt_ LPCSTR)
HCOLORSPACE WINAPI GetColorSpace(_In_ HDC)
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
BOOL WINAPI DeleteDC(_In_ HDC)
HPEN WINAPI CreatePen(_In_ int, _In_ int, _In_ COLORREF)
#define PS_SOLID
Definition: wingdi.h:586
HPALETTE WINAPI CreateHalftonePalette(_In_opt_ HDC)
#define TECHNOLOGY
Definition: wingdi.h:706
#define PS_DASHDOTDOT
Definition: wingdi.h:590
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
HDC WINAPI GetDC(_In_opt_ HWND)
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
unsigned char BYTE
Definition: xxhash.c:193