2004-09-01 19:29:28 +02:00
|
|
|
/*
|
|
|
|
* Unit test suite for GDI objects
|
|
|
|
*
|
|
|
|
* Copyright 2002 Mike McCormack
|
2004-09-02 22:06:55 +02:00
|
|
|
* Copyright 2004 Dmitry Timoshkov
|
2004-09-01 19:29:28 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-09-01 19:29:28 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2005-10-26 12:10:23 +02:00
|
|
|
#include <assert.h>
|
2004-09-01 19:29:28 +02:00
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2004-11-23 13:19:24 +01:00
|
|
|
static void test_gdi_objects(void)
|
|
|
|
{
|
|
|
|
BYTE buff[256];
|
|
|
|
HDC hdc = GetDC(NULL);
|
|
|
|
HPEN hp;
|
|
|
|
int i;
|
2004-12-27 18:26:37 +01:00
|
|
|
BOOL ret;
|
2004-11-23 13:19:24 +01:00
|
|
|
|
|
|
|
/* SelectObject() with a NULL DC returns 0 and sets ERROR_INVALID_HANDLE.
|
|
|
|
* Note: Under XP at least invalid ptrs can also be passed, not just NULL;
|
|
|
|
* Don't test that here in case it crashes earlier win versions.
|
|
|
|
*/
|
|
|
|
SetLastError(0);
|
|
|
|
hp = SelectObject(NULL, GetStockObject(BLACK_PEN));
|
|
|
|
ok(!hp && GetLastError() == ERROR_INVALID_HANDLE,
|
2007-01-05 21:49:04 +01:00
|
|
|
"SelectObject(NULL DC) expected 0, ERROR_INVALID_HANDLE, got %p, %u\n",
|
2004-11-23 13:19:24 +01:00
|
|
|
hp, GetLastError());
|
|
|
|
|
|
|
|
/* With a valid DC and a NULL object, the call returns 0 but does not SetLastError() */
|
|
|
|
SetLastError(0);
|
|
|
|
hp = SelectObject(hdc, NULL);
|
|
|
|
ok(!hp && !GetLastError(),
|
2007-01-05 21:49:04 +01:00
|
|
|
"SelectObject(NULL obj) expected 0, NO_ERROR, got %p, %u\n",
|
2004-11-23 13:19:24 +01:00
|
|
|
hp, GetLastError());
|
|
|
|
|
|
|
|
/* The DC is unaffected by the NULL SelectObject */
|
|
|
|
SetLastError(0);
|
|
|
|
hp = SelectObject(hdc, GetStockObject(BLACK_PEN));
|
|
|
|
ok(hp && !GetLastError(),
|
2007-01-05 21:49:04 +01:00
|
|
|
"SelectObject(post NULL) expected non-null, NO_ERROR, got %p, %u\n",
|
2004-11-23 13:19:24 +01:00
|
|
|
hp, GetLastError());
|
|
|
|
|
|
|
|
/* GetCurrentObject does not SetLastError() on a null object */
|
|
|
|
SetLastError(0);
|
|
|
|
hp = GetCurrentObject(NULL, OBJ_PEN);
|
|
|
|
ok(!hp && !GetLastError(),
|
2007-01-05 21:49:04 +01:00
|
|
|
"GetCurrentObject(NULL DC) expected 0, NO_ERROR, got %p, %u\n",
|
2004-11-23 13:19:24 +01:00
|
|
|
hp, GetLastError());
|
|
|
|
|
|
|
|
/* DeleteObject does not SetLastError() on a null object */
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = DeleteObject(NULL);
|
|
|
|
ok( !ret && !GetLastError(),
|
2007-01-05 21:49:04 +01:00
|
|
|
"DeleteObject(NULL obj), expected 0, NO_ERROR, got %d, %u\n",
|
2004-12-27 18:26:37 +01:00
|
|
|
ret, GetLastError());
|
2004-11-23 13:19:24 +01:00
|
|
|
|
|
|
|
/* GetObject does not SetLastError() on a null object */
|
|
|
|
SetLastError(0);
|
|
|
|
i = GetObjectA(NULL, sizeof(buff), buff);
|
|
|
|
ok (!i && !GetLastError(),
|
2007-01-05 21:49:04 +01:00
|
|
|
"GetObject(NULL obj), expected 0, NO_ERROR, got %d, %u\n",
|
2004-11-23 13:19:24 +01:00
|
|
|
i, GetLastError());
|
|
|
|
|
|
|
|
/* GetObjectType does SetLastError() on a null object */
|
|
|
|
SetLastError(0);
|
|
|
|
i = GetObjectType(NULL);
|
|
|
|
ok (!i && GetLastError() == ERROR_INVALID_HANDLE,
|
2007-01-05 21:49:04 +01:00
|
|
|
"GetObjectType(NULL obj), expected 0, ERROR_INVALID_HANDLE, got %d, %u\n",
|
2004-11-23 13:19:24 +01:00
|
|
|
i, GetLastError());
|
|
|
|
|
|
|
|
/* UnrealizeObject does not SetLastError() on a null object */
|
|
|
|
SetLastError(0);
|
|
|
|
i = UnrealizeObject(NULL);
|
|
|
|
ok (!i && !GetLastError(),
|
2007-01-05 21:49:04 +01:00
|
|
|
"UnrealizeObject(NULL obj), expected 0, NO_ERROR, got %d, %u\n",
|
2004-11-23 13:19:24 +01:00
|
|
|
i, GetLastError());
|
|
|
|
|
|
|
|
ReleaseDC(NULL, hdc);
|
|
|
|
}
|
|
|
|
|
2005-08-08 13:07:25 +02:00
|
|
|
struct hgdiobj_event
|
|
|
|
{
|
|
|
|
HDC hdc;
|
2005-10-26 12:10:23 +02:00
|
|
|
HGDIOBJ hgdiobj1;
|
|
|
|
HGDIOBJ hgdiobj2;
|
2005-08-08 13:07:25 +02:00
|
|
|
HANDLE stop_event;
|
|
|
|
HANDLE ready_event;
|
|
|
|
};
|
|
|
|
|
|
|
|
static DWORD WINAPI thread_proc(void *param)
|
|
|
|
{
|
|
|
|
LOGPEN lp;
|
|
|
|
struct hgdiobj_event *hgdiobj_event = (struct hgdiobj_event *)param;
|
|
|
|
|
|
|
|
hgdiobj_event->hdc = CreateDC("display", NULL, NULL, NULL);
|
2007-01-05 21:49:04 +01:00
|
|
|
ok(hgdiobj_event->hdc != NULL, "CreateDC error %u\n", GetLastError());
|
2005-08-08 13:07:25 +02:00
|
|
|
|
2005-10-26 12:10:23 +02:00
|
|
|
hgdiobj_event->hgdiobj1 = CreatePen(PS_DASHDOTDOT, 17, RGB(1, 2, 3));
|
|
|
|
ok(hgdiobj_event->hgdiobj1 != 0, "Failed to create pen\n");
|
|
|
|
|
|
|
|
hgdiobj_event->hgdiobj2 = CreateRectRgn(0, 1, 12, 17);
|
|
|
|
ok(hgdiobj_event->hgdiobj2 != 0, "Failed to create pen\n");
|
2005-08-08 13:07:25 +02:00
|
|
|
|
|
|
|
SetEvent(hgdiobj_event->ready_event);
|
|
|
|
ok(WaitForSingleObject(hgdiobj_event->stop_event, INFINITE) == WAIT_OBJECT_0,
|
2007-01-05 21:49:04 +01:00
|
|
|
"WaitForSingleObject error %u\n", GetLastError());
|
2005-08-08 13:07:25 +02:00
|
|
|
|
2005-10-26 12:10:23 +02:00
|
|
|
ok(!GetObject(hgdiobj_event->hgdiobj1, sizeof(lp), &lp), "GetObject should fail\n");
|
2005-08-08 13:07:25 +02:00
|
|
|
|
|
|
|
ok(!GetDeviceCaps(hgdiobj_event->hdc, TECHNOLOGY), "GetDeviceCaps(TECHNOLOGY) should fail\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_thread_objects(void)
|
|
|
|
{
|
|
|
|
LOGPEN lp;
|
2005-10-26 12:10:23 +02:00
|
|
|
DWORD tid, type;
|
2005-08-08 13:07:25 +02:00
|
|
|
HANDLE hthread;
|
|
|
|
struct hgdiobj_event hgdiobj_event;
|
|
|
|
INT ret;
|
|
|
|
|
|
|
|
hgdiobj_event.stop_event = CreateEvent(NULL, 0, 0, NULL);
|
2007-01-05 21:49:04 +01:00
|
|
|
ok(hgdiobj_event.stop_event != NULL, "CreateEvent error %u\n", GetLastError());
|
2005-08-08 13:07:25 +02:00
|
|
|
hgdiobj_event.ready_event = CreateEvent(NULL, 0, 0, NULL);
|
2007-01-05 21:49:04 +01:00
|
|
|
ok(hgdiobj_event.ready_event != NULL, "CreateEvent error %u\n", GetLastError());
|
2005-08-08 13:07:25 +02:00
|
|
|
|
|
|
|
hthread = CreateThread(NULL, 0, thread_proc, &hgdiobj_event, 0, &tid);
|
2007-01-05 21:49:04 +01:00
|
|
|
ok(hthread != NULL, "CreateThread error %u\n", GetLastError());
|
2005-08-08 13:07:25 +02:00
|
|
|
|
|
|
|
ok(WaitForSingleObject(hgdiobj_event.ready_event, INFINITE) == WAIT_OBJECT_0,
|
2007-01-05 21:49:04 +01:00
|
|
|
"WaitForSingleObject error %u\n", GetLastError());
|
2005-08-08 13:07:25 +02:00
|
|
|
|
2005-10-26 12:10:23 +02:00
|
|
|
ok(GetObject(hgdiobj_event.hgdiobj1, sizeof(lp), &lp) == sizeof(lp),
|
2007-01-05 21:49:04 +01:00
|
|
|
"GetObject error %u\n", GetLastError());
|
2005-08-08 13:07:25 +02:00
|
|
|
ok(lp.lopnStyle == PS_DASHDOTDOT, "wrong pen style %d\n", lp.lopnStyle);
|
2006-10-12 22:56:45 +02:00
|
|
|
ok(lp.lopnWidth.x == 17, "wrong pen width.y %d\n", lp.lopnWidth.x);
|
|
|
|
ok(lp.lopnWidth.y == 0, "wrong pen width.y %d\n", lp.lopnWidth.y);
|
|
|
|
ok(lp.lopnColor == RGB(1, 2, 3), "wrong pen width.y %08x\n", lp.lopnColor);
|
2005-08-08 13:07:25 +02:00
|
|
|
|
|
|
|
ret = GetDeviceCaps(hgdiobj_event.hdc, TECHNOLOGY);
|
|
|
|
ok(ret == DT_RASDISPLAY, "GetDeviceCaps(TECHNOLOGY) should return DT_RASDISPLAY not %d\n", ret);
|
|
|
|
|
2007-01-05 21:49:04 +01:00
|
|
|
ok(DeleteObject(hgdiobj_event.hgdiobj1), "DeleteObject error %u\n", GetLastError());
|
|
|
|
ok(DeleteDC(hgdiobj_event.hdc), "DeleteDC error %u\n", GetLastError());
|
2005-08-08 13:07:25 +02:00
|
|
|
|
2005-10-26 12:10:23 +02:00
|
|
|
type = GetObjectType(hgdiobj_event.hgdiobj2);
|
2006-10-12 22:56:45 +02:00
|
|
|
ok(type == OBJ_REGION, "GetObjectType returned %u\n", type);
|
2005-10-26 12:10:23 +02:00
|
|
|
|
2005-08-08 13:07:25 +02:00
|
|
|
SetEvent(hgdiobj_event.stop_event);
|
|
|
|
ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0,
|
2007-01-05 21:49:04 +01:00
|
|
|
"WaitForSingleObject error %u\n", GetLastError());
|
2005-08-08 13:07:25 +02:00
|
|
|
CloseHandle(hthread);
|
|
|
|
|
2005-10-26 12:10:23 +02:00
|
|
|
type = GetObjectType(hgdiobj_event.hgdiobj2);
|
2006-10-12 22:56:45 +02:00
|
|
|
ok(type == OBJ_REGION, "GetObjectType returned %u\n", type);
|
2007-01-05 21:49:04 +01:00
|
|
|
ok(DeleteObject(hgdiobj_event.hgdiobj2), "DeleteObject error %u\n", GetLastError());
|
2005-10-26 12:10:23 +02:00
|
|
|
|
2005-08-08 13:07:25 +02:00
|
|
|
CloseHandle(hgdiobj_event.stop_event);
|
|
|
|
CloseHandle(hgdiobj_event.ready_event);
|
|
|
|
}
|
|
|
|
|
2005-10-26 12:10:23 +02:00
|
|
|
static void test_GetCurrentObject(void)
|
|
|
|
{
|
|
|
|
DWORD type;
|
|
|
|
HPEN hpen;
|
|
|
|
HBRUSH hbrush;
|
|
|
|
HPALETTE hpal;
|
|
|
|
HFONT hfont;
|
|
|
|
HBITMAP hbmp;
|
|
|
|
HRGN hrgn;
|
|
|
|
HDC hdc;
|
|
|
|
HCOLORSPACE hcs;
|
|
|
|
HGDIOBJ hobj;
|
|
|
|
LOGBRUSH lb;
|
|
|
|
LOGCOLORSPACEA lcs;
|
|
|
|
|
|
|
|
hdc = CreateCompatibleDC(0);
|
|
|
|
assert(hdc != 0);
|
|
|
|
|
|
|
|
type = GetObjectType(hdc);
|
2006-10-12 22:56:45 +02:00
|
|
|
ok(type == OBJ_MEMDC, "GetObjectType returned %u\n", type);
|
2005-10-26 12:10:23 +02:00
|
|
|
|
|
|
|
hpen = CreatePen(PS_SOLID, 10, RGB(10, 20, 30));
|
|
|
|
assert(hpen != 0);
|
|
|
|
SelectObject(hdc, hpen);
|
|
|
|
hobj = GetCurrentObject(hdc, OBJ_PEN);
|
|
|
|
ok(hobj == hpen, "OBJ_PEN is wrong: %p\n", hobj);
|
|
|
|
hobj = GetCurrentObject(hdc, OBJ_EXTPEN);
|
|
|
|
ok(hobj == hpen, "OBJ_EXTPEN is wrong: %p\n", hobj);
|
|
|
|
|
|
|
|
hbrush = CreateSolidBrush(RGB(10, 20, 30));
|
|
|
|
assert(hbrush != 0);
|
|
|
|
SelectObject(hdc, hbrush);
|
|
|
|
hobj = GetCurrentObject(hdc, OBJ_BRUSH);
|
|
|
|
ok(hobj == hbrush, "OBJ_BRUSH is wrong: %p\n", hobj);
|
|
|
|
|
|
|
|
hpal = CreateHalftonePalette(hdc);
|
|
|
|
assert(hpal != 0);
|
|
|
|
SelectPalette(hdc, hpal, FALSE);
|
|
|
|
hobj = GetCurrentObject(hdc, OBJ_PAL);
|
|
|
|
ok(hobj == hpal, "OBJ_PAL is wrong: %p\n", hobj);
|
|
|
|
|
|
|
|
hfont = CreateFontA(10, 5, 0, 0, FW_DONTCARE, 0, 0, 0, ANSI_CHARSET,
|
|
|
|
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
|
|
|
|
DEFAULT_PITCH, "MS Sans Serif");
|
|
|
|
assert(hfont != 0);
|
|
|
|
SelectObject(hdc, hfont);
|
|
|
|
hobj = GetCurrentObject(hdc, OBJ_FONT);
|
|
|
|
ok(hobj == hfont, "OBJ_FONT is wrong: %p\n", hobj);
|
|
|
|
|
|
|
|
hbmp = CreateBitmap(100, 100, 1, 1, NULL);
|
|
|
|
assert(hbmp != 0);
|
|
|
|
SelectObject(hdc, hbmp);
|
|
|
|
hobj = GetCurrentObject(hdc, OBJ_BITMAP);
|
|
|
|
ok(hobj == hbmp, "OBJ_BITMAP is wrong: %p\n", hobj);
|
|
|
|
|
|
|
|
assert(GetObject(hbrush, sizeof(lb), &lb) == sizeof(lb));
|
|
|
|
hpen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_SQUARE | PS_JOIN_BEVEL,
|
|
|
|
10, &lb, 0, NULL);
|
|
|
|
assert(hpen != 0);
|
|
|
|
SelectObject(hdc, hpen);
|
|
|
|
hobj = GetCurrentObject(hdc, OBJ_PEN);
|
|
|
|
ok(hobj == hpen, "OBJ_PEN is wrong: %p\n", hobj);
|
|
|
|
hobj = GetCurrentObject(hdc, OBJ_EXTPEN);
|
|
|
|
ok(hobj == hpen, "OBJ_EXTPEN is wrong: %p\n", hobj);
|
|
|
|
|
|
|
|
hcs = GetColorSpace(hdc);
|
|
|
|
if (hcs)
|
|
|
|
{
|
|
|
|
trace("current color space is not NULL\n");
|
|
|
|
ok(GetLogColorSpaceA(hcs, &lcs, sizeof(lcs)), "GetLogColorSpace failed\n");
|
|
|
|
hcs = CreateColorSpaceA(&lcs);
|
|
|
|
ok(hcs != 0, "CreateColorSpace failed\n");
|
|
|
|
SelectObject(hdc, hcs);
|
|
|
|
hobj = GetCurrentObject(hdc, OBJ_COLORSPACE);
|
|
|
|
ok(hobj == hcs, "OBJ_COLORSPACE is wrong: %p\n", hobj);
|
|
|
|
}
|
|
|
|
|
|
|
|
hrgn = CreateRectRgn(1, 1, 100, 100);
|
|
|
|
assert(hrgn != 0);
|
|
|
|
SelectObject(hdc, hrgn);
|
|
|
|
hobj = GetCurrentObject(hdc, OBJ_REGION);
|
|
|
|
ok(!hobj, "OBJ_REGION is wrong: %p\n", hobj);
|
|
|
|
|
|
|
|
DeleteDC(hdc);
|
|
|
|
}
|
|
|
|
|
2004-09-01 19:29:28 +02:00
|
|
|
START_TEST(gdiobj)
|
|
|
|
{
|
2004-11-23 13:19:24 +01:00
|
|
|
test_gdi_objects();
|
2005-08-08 13:07:25 +02:00
|
|
|
test_thread_objects();
|
2005-10-26 12:10:23 +02:00
|
|
|
test_GetCurrentObject();
|
2004-09-01 19:29:28 +02:00
|
|
|
}
|