2010-08-24 13:54:10 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS api tests
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* PURPOSE: Test for SelectObject
|
|
|
|
* PROGRAMMERS: Timo Kreuzer
|
|
|
|
*/
|
|
|
|
|
2013-09-22 17:52:42 +00:00
|
|
|
#include <apitest.h>
|
|
|
|
|
2010-08-24 13:54:10 +00:00
|
|
|
#include <stdio.h>
|
2013-02-05 17:54:22 +00:00
|
|
|
#include <wingdi.h>
|
2010-08-24 13:54:10 +00:00
|
|
|
#include <winddi.h>
|
2013-02-05 17:54:22 +00:00
|
|
|
#include <winuser.h>
|
2012-04-02 10:52:54 +00:00
|
|
|
#include <include/ntgdityp.h>
|
|
|
|
#include <include/ntgdihdl.h>
|
2010-08-24 13:54:10 +00:00
|
|
|
|
2010-10-17 14:50:02 +00:00
|
|
|
#define TEST(x) ok(x, #x"\n")
|
|
|
|
#define RTEST(x) ok(x, #x"\n")
|
2010-08-24 13:54:10 +00:00
|
|
|
|
2011-02-27 22:00:13 +00:00
|
|
|
HDC hdc1, hdc2;
|
|
|
|
|
|
|
|
static void
|
|
|
|
Test_SelectObject()
|
2008-06-01 18:06:22 +00:00
|
|
|
{
|
|
|
|
HGDIOBJ hOldObj, hNewObj;
|
2010-08-24 13:54:10 +00:00
|
|
|
// PGDI_TABLE_ENTRY pEntry;
|
|
|
|
// PDC_ATTR pDc_Attr;
|
|
|
|
// HANDLE hcmXform;
|
2008-06-01 18:06:22 +00:00
|
|
|
|
|
|
|
/* Get the Dc_Attr for later testing */
|
2011-02-27 22:00:13 +00:00
|
|
|
// pEntry = &GdiHandleTable[GDI_HANDLE_GET_INDEX(hdc1)];
|
2010-08-24 13:54:10 +00:00
|
|
|
// pDc_Attr = pEntry->UserData;
|
|
|
|
// ok(pDc_Attr != NULL, "Skipping tests.\n");
|
|
|
|
// if (pDc_Attr == NULL) return;
|
2008-06-01 18:06:22 +00:00
|
|
|
|
|
|
|
/* Test incomplete dc handle doesn't work */
|
|
|
|
SetLastError(ERROR_SUCCESS);
|
|
|
|
hNewObj = GetStockObject(GRAY_BRUSH);
|
2011-02-27 22:00:13 +00:00
|
|
|
hOldObj = SelectObject((HDC)GDI_HANDLE_GET_INDEX(hdc1), hNewObj);
|
|
|
|
ok_err(ERROR_INVALID_HANDLE);
|
|
|
|
ok(hOldObj == NULL, "\n");
|
|
|
|
// ok(pDc_Attr->hbrush == GetStockObject(WHITE_BRUSH), "\n");
|
|
|
|
SelectObject(hdc1, hOldObj);
|
2008-06-01 18:06:22 +00:00
|
|
|
|
|
|
|
/* Test incomplete hobj handle works */
|
|
|
|
hNewObj = GetStockObject(GRAY_BRUSH);
|
2011-02-27 22:00:13 +00:00
|
|
|
hOldObj = SelectObject(hdc1, (HGDIOBJ)GDI_HANDLE_GET_INDEX(hNewObj));
|
|
|
|
ok(hOldObj == GetStockObject(WHITE_BRUSH), "\n");
|
|
|
|
// ok(pDc_Attr->hbrush == hNewObj, "\n");
|
|
|
|
SelectObject(hdc1, hOldObj);
|
2008-06-01 18:06:22 +00:00
|
|
|
|
|
|
|
/* Test wrong hDC handle type */
|
|
|
|
SetLastError(ERROR_SUCCESS);
|
|
|
|
hNewObj = GetStockObject(GRAY_BRUSH);
|
2011-02-27 22:00:13 +00:00
|
|
|
hdc2 = (HDC)((UINT_PTR)hdc1 & ~GDI_HANDLE_TYPE_MASK);
|
|
|
|
hdc2 = (HDC)((UINT_PTR)hdc2 | GDI_OBJECT_TYPE_PEN);
|
|
|
|
hOldObj = SelectObject(hdc2, hNewObj);
|
|
|
|
ok_err(ERROR_INVALID_HANDLE);
|
|
|
|
ok(hOldObj == NULL, "\n");
|
2010-08-24 13:54:10 +00:00
|
|
|
// RTEST(pDc_Attr->hbrush == GetStockObject(WHITE_BRUSH));
|
2008-06-01 18:06:22 +00:00
|
|
|
|
|
|
|
/* Test wrong hobj handle type */
|
|
|
|
SetLastError(ERROR_SUCCESS);
|
|
|
|
hNewObj = GetStockObject(GRAY_BRUSH);
|
|
|
|
hNewObj = (HGDIOBJ)((UINT_PTR)hNewObj & ~GDI_HANDLE_TYPE_MASK);
|
|
|
|
hNewObj = (HGDIOBJ)((UINT_PTR)hNewObj | GDI_OBJECT_TYPE_PEN);
|
2011-02-27 22:00:13 +00:00
|
|
|
hOldObj = SelectObject(hdc1, hNewObj);
|
|
|
|
ok_err(ERROR_SUCCESS);
|
|
|
|
ok(hOldObj == NULL, "\n");
|
2010-08-24 13:54:10 +00:00
|
|
|
// RTEST(pDc_Attr->hbrush == GetStockObject(WHITE_BRUSH));
|
2008-06-01 18:06:22 +00:00
|
|
|
|
|
|
|
SetLastError(ERROR_SUCCESS);
|
|
|
|
hNewObj = (HGDIOBJ)0x00761234;
|
2011-02-27 22:00:13 +00:00
|
|
|
hOldObj = SelectObject(hdc1, hNewObj);
|
|
|
|
ok(hOldObj == NULL, "\n");
|
|
|
|
ok_err(ERROR_SUCCESS);
|
|
|
|
SelectObject(hdc1, hOldObj);
|
2008-06-01 18:06:22 +00:00
|
|
|
|
|
|
|
/* Test DC */
|
|
|
|
SetLastError(ERROR_SUCCESS);
|
2011-02-27 22:00:13 +00:00
|
|
|
hOldObj = SelectObject(hdc1, GetDC(NULL));
|
|
|
|
ok(hOldObj == NULL, "\n");
|
|
|
|
ok_err(ERROR_SUCCESS);
|
2008-06-01 18:06:22 +00:00
|
|
|
|
2011-01-16 20:53:48 +00:00
|
|
|
|
2008-06-01 18:06:22 +00:00
|
|
|
/* Test CLIOBJ */
|
|
|
|
|
|
|
|
/* Test PATH */
|
|
|
|
|
|
|
|
/* Test PALETTE */
|
|
|
|
SetLastError(ERROR_SUCCESS);
|
|
|
|
hNewObj = GetStockObject(DEFAULT_PALETTE);
|
2011-02-27 22:00:13 +00:00
|
|
|
hOldObj = SelectObject(hdc1, hNewObj);
|
2008-06-16 15:24:05 +00:00
|
|
|
RTEST(hOldObj == NULL);
|
2011-02-27 22:00:13 +00:00
|
|
|
ok_err(ERROR_INVALID_FUNCTION);
|
2008-06-01 18:06:22 +00:00
|
|
|
|
|
|
|
/* Test COLORSPACE */
|
|
|
|
|
|
|
|
/* Test FONT */
|
|
|
|
|
|
|
|
/* Test PFE */
|
|
|
|
|
|
|
|
/* Test BRUSH */
|
|
|
|
hNewObj = GetStockObject(GRAY_BRUSH);
|
2011-02-27 22:00:13 +00:00
|
|
|
hOldObj = SelectObject(hdc1, hNewObj);
|
2008-06-16 15:24:05 +00:00
|
|
|
RTEST(hOldObj == GetStockObject(WHITE_BRUSH));
|
2010-08-24 13:54:10 +00:00
|
|
|
// RTEST(pDc_Attr->hbrush == hNewObj);
|
2008-06-16 15:24:05 +00:00
|
|
|
RTEST(GDI_HANDLE_GET_TYPE(hOldObj) == GDI_OBJECT_TYPE_BRUSH);
|
2011-02-27 22:00:13 +00:00
|
|
|
SelectObject(hdc1, hOldObj);
|
2008-06-01 18:06:22 +00:00
|
|
|
|
|
|
|
/* Test DC_BRUSH */
|
|
|
|
hNewObj = GetStockObject(DC_BRUSH);
|
2011-02-27 22:00:13 +00:00
|
|
|
hOldObj = SelectObject(hdc1, hNewObj);
|
2010-08-24 13:54:10 +00:00
|
|
|
// RTEST(pDc_Attr->hbrush == hNewObj);
|
2011-02-27 22:00:13 +00:00
|
|
|
SelectObject(hdc1, hOldObj);
|
2008-06-01 18:06:22 +00:00
|
|
|
|
|
|
|
/* Test BRUSH color xform */
|
2010-08-24 13:54:10 +00:00
|
|
|
// hcmXform = (HANDLE)pDc_Attr->hcmXform;
|
2008-06-01 18:06:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Test EMF */
|
|
|
|
|
|
|
|
/* test METAFILE */
|
2012-04-23 22:16:50 +00:00
|
|
|
SetLastError(ERROR_SUCCESS);
|
|
|
|
hNewObj = CreateMetaFile(NULL);
|
|
|
|
ok(hNewObj != 0, "failed to create a meta dc\n");
|
|
|
|
hOldObj = SelectObject(hdc1, hNewObj);
|
|
|
|
RTEST(hOldObj == NULL);
|
|
|
|
ok_err(ERROR_SUCCESS);
|
2008-06-01 18:06:22 +00:00
|
|
|
|
|
|
|
/* Test ENHMETAFILE */
|
|
|
|
|
|
|
|
/* Test EXTPEN */
|
|
|
|
|
|
|
|
/* Test METADC */
|
2010-08-24 13:54:10 +00:00
|
|
|
}
|
2008-06-01 18:06:22 +00:00
|
|
|
|
2011-02-27 22:00:13 +00:00
|
|
|
static void
|
|
|
|
Test_Bitmap()
|
|
|
|
{
|
|
|
|
HBITMAP hbmp, hbmpInvalid, hbmpOld;
|
|
|
|
BYTE bmBits[4] = {0};
|
|
|
|
HDC hdcTmp;
|
|
|
|
|
|
|
|
hbmp = CreateBitmap(2, 2, 1, 1, &bmBits);
|
|
|
|
hbmpInvalid = CreateBitmap(2, 2, 1, 4, &bmBits);
|
|
|
|
if (!hbmp || !hbmpInvalid)
|
|
|
|
{
|
|
|
|
printf("couldn't create bitmaps, skipping\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hbmpOld = SelectObject(hdc1, hbmp);
|
|
|
|
ok(GDI_HANDLE_GET_TYPE(hbmpOld) == GDI_OBJECT_TYPE_BITMAP, "wrong type\n");
|
|
|
|
|
|
|
|
/* Test invalid BITMAP */
|
|
|
|
ok(SelectObject(hdc1, hbmpInvalid) == NULL, "should fail\n");
|
|
|
|
|
|
|
|
/* Test if we get the right bitmap back */
|
|
|
|
hbmpOld = SelectObject(hdc1, hbmpOld);
|
|
|
|
ok(hbmpOld == hbmp, "didn't get the right bitmap back.\n");
|
|
|
|
|
|
|
|
/* Test selecting bitmap into 2 DCs */
|
|
|
|
hbmpOld = SelectObject(hdc1, hbmp);
|
|
|
|
ok(SelectObject(hdc2, hbmp) == NULL, "Should fail.\n");
|
|
|
|
|
|
|
|
/* Test selecting same bitmap twice */
|
|
|
|
hbmpOld = SelectObject(hdc1, hbmp);
|
|
|
|
ok(hbmpOld == hbmp, "didn't get the right bitmap back.\n");
|
|
|
|
SelectObject(hdc1, GetStockObject(DEFAULT_BITMAP));
|
|
|
|
|
|
|
|
/* Test selecting and then deleting the DC */
|
|
|
|
hdcTmp = CreateCompatibleDC(NULL);
|
|
|
|
hbmpOld = SelectObject(hdcTmp, hbmp);
|
|
|
|
ok(hbmpOld == GetStockObject(DEFAULT_BITMAP), "didn't get the right bitmap back.\n");
|
|
|
|
DeleteDC(hdcTmp);
|
|
|
|
hbmpOld = SelectObject(hdc1, hbmp);
|
|
|
|
ok(hbmpOld == GetStockObject(DEFAULT_BITMAP), "didn't get the right bitmap back.\n");
|
|
|
|
|
|
|
|
DeleteObject(hbmp);
|
|
|
|
DeleteObject(hbmpInvalid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
Test_Pen()
|
|
|
|
{
|
|
|
|
HPEN hpen, hpenOld;
|
|
|
|
|
|
|
|
/* Test PEN */
|
|
|
|
hpen = GetStockObject(GRAY_BRUSH);
|
|
|
|
hpenOld = SelectObject(hdc1, hpen);
|
|
|
|
ok(hpenOld == GetStockObject(WHITE_BRUSH), "Got wrong pen.\n");
|
|
|
|
// RTEST(pDc_Attr->hbrush == hpen);
|
|
|
|
ok(GDI_HANDLE_GET_TYPE(hpenOld) == GDI_OBJECT_TYPE_BRUSH, "wrong type.\n");
|
|
|
|
SelectObject(hdc1, hpenOld);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
Test_Region()
|
|
|
|
{
|
|
|
|
HRGN hrgn, hrgnOld;
|
|
|
|
|
|
|
|
/* Test REGION */
|
|
|
|
SetLastError(ERROR_SUCCESS);
|
|
|
|
hrgn = CreateRectRgn(0,0,0,0);
|
|
|
|
hrgnOld = SelectObject(hdc1, hrgn);
|
|
|
|
ok((UINT_PTR)hrgnOld == NULLREGION, "\n");
|
|
|
|
DeleteObject(hrgn);
|
|
|
|
|
|
|
|
hrgn = CreateRectRgn(0,0,10,10);
|
|
|
|
ok((UINT_PTR)SelectObject(hdc1, hrgn) == SIMPLEREGION, "\n");
|
|
|
|
hrgnOld = CreateRectRgn(5,5,20,20);
|
|
|
|
ok(CombineRgn(hrgn, hrgn, hrgnOld, RGN_OR) == COMPLEXREGION, "\n");
|
|
|
|
DeleteObject(hrgnOld);
|
|
|
|
ok((UINT_PTR)SelectObject(hdc1, hrgn) == SIMPLEREGION, "\n"); // ??? Why this?
|
|
|
|
DeleteObject(hrgn);
|
|
|
|
// ok(IsHandleValid(hrgn) == TRUE, "\n");
|
|
|
|
ok_err(ERROR_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2010-08-24 13:54:10 +00:00
|
|
|
START_TEST(SelectObject)
|
|
|
|
{
|
2011-02-27 22:00:13 +00:00
|
|
|
hdc1 = CreateCompatibleDC(NULL);
|
|
|
|
hdc2 = CreateCompatibleDC(NULL);
|
|
|
|
if (!hdc1 || !hdc2)
|
|
|
|
{
|
|
|
|
printf("couldn't create DCs, skipping all tests\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-24 13:54:10 +00:00
|
|
|
Test_SelectObject();
|
2011-02-27 22:00:13 +00:00
|
|
|
Test_Bitmap();
|
|
|
|
Test_Pen();
|
|
|
|
Test_Region();
|
2008-06-01 18:06:22 +00:00
|
|
|
}
|
|
|
|
|