2005-10-31 10:05:52 +00:00
|
|
|
/*
|
|
|
|
* Unit tests for dc functions
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005 Huw Davies
|
2005-11-22 12:00:11 +00:00
|
|
|
* Copyright (c) 2005 Dmitry Timoshkov
|
2005-10-31 10:05:52 +00: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 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-10-31 10:05:52 +00:00
|
|
|
*/
|
|
|
|
|
2007-12-19 03:41:07 +00:00
|
|
|
#define WINVER 0x0501 /* request latest DEVMODE */
|
|
|
|
|
2005-10-31 10:05:52 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
|
2005-11-22 12:00:11 +00:00
|
|
|
static void dump_region(HRGN hrgn)
|
|
|
|
{
|
|
|
|
DWORD i, size;
|
|
|
|
RGNDATA *data = NULL;
|
|
|
|
RECT *rect;
|
|
|
|
|
|
|
|
if (!hrgn)
|
|
|
|
{
|
|
|
|
printf( "(null) region\n" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!(size = GetRegionData( hrgn, 0, NULL ))) return;
|
|
|
|
if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return;
|
|
|
|
GetRegionData( hrgn, size, data );
|
2006-10-12 20:56:45 +00:00
|
|
|
printf( "%d rects:", data->rdh.nCount );
|
2005-11-22 12:00:11 +00:00
|
|
|
for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
|
2006-10-12 20:56:45 +00:00
|
|
|
printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
|
2005-11-22 12:00:11 +00:00
|
|
|
printf( "\n" );
|
|
|
|
HeapFree( GetProcessHeap(), 0, data );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_savedc_2(void)
|
|
|
|
{
|
|
|
|
HWND hwnd;
|
|
|
|
HDC hdc;
|
|
|
|
HRGN hrgn;
|
|
|
|
RECT rc, rc_clip;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
|
|
|
|
0, 0, 0, NULL);
|
|
|
|
assert(hwnd != 0);
|
|
|
|
ShowWindow(hwnd, SW_SHOW);
|
|
|
|
UpdateWindow(hwnd);
|
|
|
|
|
|
|
|
hrgn = CreateRectRgn(0, 0, 0, 0);
|
|
|
|
assert(hrgn != 0);
|
|
|
|
|
|
|
|
hdc = GetDC(hwnd);
|
2010-02-24 14:44:41 +00:00
|
|
|
ok(hdc != NULL, "GetDC failed\n");
|
2005-11-22 12:00:11 +00:00
|
|
|
|
|
|
|
ret = GetClipBox(hdc, &rc_clip);
|
2011-07-15 07:59:13 +00:00
|
|
|
ok(ret == SIMPLEREGION || broken(ret == COMPLEXREGION), "GetClipBox returned %d instead of SIMPLEREGION\n", ret);
|
2005-11-22 12:00:11 +00:00
|
|
|
ret = GetClipRgn(hdc, hrgn);
|
|
|
|
ok(ret == 0, "GetClipRgn returned %d instead of 0\n", ret);
|
|
|
|
ret = GetRgnBox(hrgn, &rc);
|
2006-10-12 20:56:45 +00:00
|
|
|
ok(ret == NULLREGION, "GetRgnBox returned %d (%d,%d-%d,%d) instead of NULLREGION\n",
|
2005-11-22 12:00:11 +00:00
|
|
|
ret, rc.left, rc.top, rc.right, rc.bottom);
|
|
|
|
/*dump_region(hrgn);*/
|
|
|
|
SetRect(&rc, 0, 0, 100, 100);
|
|
|
|
ok(EqualRect(&rc, &rc_clip),
|
2006-10-12 20:56:45 +00:00
|
|
|
"rects are not equal: (%d,%d-%d,%d) - (%d,%d-%d,%d)\n",
|
2005-11-22 12:00:11 +00:00
|
|
|
rc.left, rc.top, rc.right, rc.bottom,
|
|
|
|
rc_clip.left, rc_clip.top, rc_clip.right, rc_clip.bottom);
|
|
|
|
|
|
|
|
ret = SaveDC(hdc);
|
|
|
|
todo_wine
|
|
|
|
{
|
|
|
|
ok(ret == 1, "ret = %d\n", ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = IntersectClipRect(hdc, 0, 0, 50, 50);
|
2007-01-06 18:30:19 +00:00
|
|
|
if (ret == COMPLEXREGION)
|
2005-11-22 12:00:11 +00:00
|
|
|
{
|
2007-01-06 18:30:19 +00:00
|
|
|
/* XP returns COMPLEXREGION although dump_region reports only 1 rect */
|
2005-11-22 12:00:11 +00:00
|
|
|
trace("Windows BUG: IntersectClipRect returned %d instead of SIMPLEREGION\n", ret);
|
|
|
|
/* let's make sure that it's a simple region */
|
|
|
|
ret = GetClipRgn(hdc, hrgn);
|
|
|
|
ok(ret == 1, "GetClipRgn returned %d instead of 1\n", ret);
|
|
|
|
dump_region(hrgn);
|
|
|
|
}
|
2007-01-06 18:30:19 +00:00
|
|
|
else
|
|
|
|
ok(ret == SIMPLEREGION, "IntersectClipRect returned %d instead of SIMPLEREGION\n", ret);
|
2005-11-22 12:00:11 +00:00
|
|
|
|
|
|
|
ret = GetClipBox(hdc, &rc_clip);
|
2011-07-15 07:59:13 +00:00
|
|
|
ok(ret == SIMPLEREGION || broken(ret == COMPLEXREGION), "GetClipBox returned %d instead of SIMPLEREGION\n", ret);
|
2005-11-22 12:00:11 +00:00
|
|
|
SetRect(&rc, 0, 0, 50, 50);
|
2011-08-09 17:17:12 +00:00
|
|
|
ok(EqualRect(&rc, &rc_clip),
|
|
|
|
"rects are not equal: (%d,%d-%d,%d) - (%d,%d-%d,%d)\n",
|
|
|
|
rc.left, rc.top, rc.right, rc.bottom,
|
|
|
|
rc_clip.left, rc_clip.top, rc_clip.right, rc_clip.bottom);
|
2005-11-22 12:00:11 +00:00
|
|
|
|
|
|
|
ret = RestoreDC(hdc, 1);
|
|
|
|
ok(ret, "ret = %d\n", ret);
|
|
|
|
|
|
|
|
ret = GetClipBox(hdc, &rc_clip);
|
2011-07-15 07:59:13 +00:00
|
|
|
ok(ret == SIMPLEREGION || broken(ret == COMPLEXREGION), "GetClipBox returned %d instead of SIMPLEREGION\n", ret);
|
2005-11-22 12:00:11 +00:00
|
|
|
SetRect(&rc, 0, 0, 100, 100);
|
2011-08-09 17:17:12 +00:00
|
|
|
ok(EqualRect(&rc, &rc_clip),
|
|
|
|
"rects are not equal: (%d,%d-%d,%d) - (%d,%d-%d,%d)\n",
|
|
|
|
rc.left, rc.top, rc.right, rc.bottom,
|
|
|
|
rc_clip.left, rc_clip.top, rc_clip.right, rc_clip.bottom);
|
2005-11-22 12:00:11 +00:00
|
|
|
|
|
|
|
DeleteObject(hrgn);
|
|
|
|
ReleaseDC(hwnd, hdc);
|
|
|
|
DestroyWindow(hwnd);
|
|
|
|
}
|
2005-10-31 10:05:52 +00:00
|
|
|
|
2005-11-22 12:00:11 +00:00
|
|
|
static void test_savedc(void)
|
2005-10-31 10:05:52 +00:00
|
|
|
{
|
|
|
|
HDC hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ok(hdc != NULL, "CreateDC rets %p\n", hdc);
|
|
|
|
|
|
|
|
ret = SaveDC(hdc);
|
|
|
|
ok(ret == 1, "ret = %d\n", ret);
|
|
|
|
ret = SaveDC(hdc);
|
|
|
|
ok(ret == 2, "ret = %d\n", ret);
|
|
|
|
ret = SaveDC(hdc);
|
|
|
|
ok(ret == 3, "ret = %d\n", ret);
|
|
|
|
ret = RestoreDC(hdc, -1);
|
|
|
|
ok(ret, "ret = %d\n", ret);
|
|
|
|
ret = SaveDC(hdc);
|
|
|
|
ok(ret == 3, "ret = %d\n", ret);
|
|
|
|
ret = RestoreDC(hdc, 1);
|
|
|
|
ok(ret, "ret = %d\n", ret);
|
|
|
|
ret = SaveDC(hdc);
|
|
|
|
ok(ret == 1, "ret = %d\n", ret);
|
|
|
|
ret = SaveDC(hdc);
|
|
|
|
ok(ret == 2, "ret = %d\n", ret);
|
|
|
|
ret = SaveDC(hdc);
|
|
|
|
ok(ret == 3, "ret = %d\n", ret);
|
|
|
|
ret = RestoreDC(hdc, -2);
|
|
|
|
ok(ret, "ret = %d\n", ret);
|
|
|
|
ret = SaveDC(hdc);
|
|
|
|
ok(ret == 2, "ret = %d\n", ret);
|
|
|
|
ret = RestoreDC(hdc, -2);
|
|
|
|
ok(ret, "ret = %d\n", ret);
|
|
|
|
ret = SaveDC(hdc);
|
|
|
|
ok(ret == 1, "ret = %d\n", ret);
|
|
|
|
ret = SaveDC(hdc);
|
|
|
|
ok(ret == 2, "ret = %d\n", ret);
|
|
|
|
ret = RestoreDC(hdc, -4);
|
|
|
|
ok(!ret, "ret = %d\n", ret);
|
|
|
|
ret = RestoreDC(hdc, 3);
|
|
|
|
ok(!ret, "ret = %d\n", ret);
|
|
|
|
|
2010-06-01 13:03:11 +00:00
|
|
|
/* Under Win9x the following RestoreDC call succeeds and clears the save stack. */
|
|
|
|
ret = RestoreDC(hdc, -3);
|
|
|
|
ok(!ret ||
|
|
|
|
broken(ret), /* Win9x */
|
|
|
|
"ret = %d\n", ret);
|
|
|
|
|
|
|
|
/* Trying to clear an empty save stack fails. */
|
2005-10-31 10:05:52 +00:00
|
|
|
ret = RestoreDC(hdc, -3);
|
|
|
|
ok(!ret, "ret = %d\n", ret);
|
2010-06-01 13:03:11 +00:00
|
|
|
|
|
|
|
ret = SaveDC(hdc);
|
|
|
|
ok(ret == 3 ||
|
|
|
|
broken(ret == 1), /* Win9x */
|
|
|
|
"ret = %d\n", ret);
|
|
|
|
|
|
|
|
/* Under Win9x the following RestoreDC call succeeds and clears the save stack. */
|
|
|
|
ret = RestoreDC(hdc, 0);
|
|
|
|
ok(!ret ||
|
|
|
|
broken(ret), /* Win9x */
|
|
|
|
"ret = %d\n", ret);
|
|
|
|
|
|
|
|
/* Trying to clear an empty save stack fails. */
|
2005-10-31 10:05:52 +00:00
|
|
|
ret = RestoreDC(hdc, 0);
|
|
|
|
ok(!ret, "ret = %d\n", ret);
|
|
|
|
|
|
|
|
ret = RestoreDC(hdc, 1);
|
2010-06-01 13:03:11 +00:00
|
|
|
ok(ret ||
|
|
|
|
broken(!ret), /* Win9x */
|
|
|
|
"ret = %d\n", ret);
|
2005-10-31 10:05:52 +00:00
|
|
|
|
|
|
|
DeleteDC(hdc);
|
|
|
|
}
|
|
|
|
|
2007-12-18 12:21:40 +00:00
|
|
|
static void test_GdiConvertToDevmodeW(void)
|
|
|
|
{
|
|
|
|
DEVMODEW * (WINAPI *pGdiConvertToDevmodeW)(const DEVMODEA *);
|
|
|
|
DEVMODEA dmA;
|
|
|
|
DEVMODEW *dmW;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
pGdiConvertToDevmodeW = (void *)GetProcAddress(GetModuleHandleA("gdi32.dll"), "GdiConvertToDevmodeW");
|
|
|
|
if (!pGdiConvertToDevmodeW)
|
|
|
|
{
|
2009-02-23 23:03:32 +00:00
|
|
|
win_skip("GdiConvertToDevmodeW is not available on this platform\n");
|
2007-12-18 12:21:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = EnumDisplaySettingsA(NULL, ENUM_CURRENT_SETTINGS, &dmA);
|
|
|
|
ok(ret, "EnumDisplaySettingsExA error %u\n", GetLastError());
|
|
|
|
ok(dmA.dmSize >= FIELD_OFFSET(DEVMODEA, dmICMMethod), "dmSize is too small: %04x\n", dmA.dmSize);
|
|
|
|
ok(dmA.dmSize <= sizeof(DEVMODEA), "dmSize is too large: %04x\n", dmA.dmSize);
|
|
|
|
|
|
|
|
dmW = pGdiConvertToDevmodeW(&dmA);
|
|
|
|
ok(dmW->dmSize >= FIELD_OFFSET(DEVMODEW, dmICMMethod), "dmSize is too small: %04x\n", dmW->dmSize);
|
|
|
|
ok(dmW->dmSize <= sizeof(DEVMODEW), "dmSize is too large: %04x\n", dmW->dmSize);
|
|
|
|
HeapFree(GetProcessHeap(), 0, dmW);
|
|
|
|
|
|
|
|
dmA.dmSize = FIELD_OFFSET(DEVMODEA, dmFields) + sizeof(dmA.dmFields);
|
|
|
|
dmW = pGdiConvertToDevmodeW(&dmA);
|
|
|
|
ok(dmW->dmSize == FIELD_OFFSET(DEVMODEW, dmFields) + sizeof(dmW->dmFields),
|
2008-01-07 16:18:29 +00:00
|
|
|
"wrong size %u\n", dmW->dmSize);
|
2007-12-18 12:21:40 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, dmW);
|
|
|
|
|
|
|
|
dmA.dmICMMethod = DMICMMETHOD_NONE;
|
|
|
|
dmA.dmSize = FIELD_OFFSET(DEVMODEA, dmICMMethod) + sizeof(dmA.dmICMMethod);
|
|
|
|
dmW = pGdiConvertToDevmodeW(&dmA);
|
|
|
|
ok(dmW->dmSize == FIELD_OFFSET(DEVMODEW, dmICMMethod) + sizeof(dmW->dmICMMethod),
|
2008-01-07 16:18:29 +00:00
|
|
|
"wrong size %u\n", dmW->dmSize);
|
2007-12-18 12:21:40 +00:00
|
|
|
ok(dmW->dmICMMethod == DMICMMETHOD_NONE,
|
|
|
|
"expected DMICMMETHOD_NONE, got %u\n", dmW->dmICMMethod);
|
|
|
|
HeapFree(GetProcessHeap(), 0, dmW);
|
|
|
|
|
|
|
|
dmA.dmSize = 1024;
|
|
|
|
dmW = pGdiConvertToDevmodeW(&dmA);
|
|
|
|
ok(dmW->dmSize == FIELD_OFFSET(DEVMODEW, dmPanningHeight) + sizeof(dmW->dmPanningHeight),
|
2008-01-07 16:18:29 +00:00
|
|
|
"wrong size %u\n", dmW->dmSize);
|
2007-12-18 12:21:40 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, dmW);
|
2007-12-20 06:49:59 +00:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
dmA.dmSize = 0;
|
|
|
|
dmW = pGdiConvertToDevmodeW(&dmA);
|
|
|
|
ok(!dmW, "GdiConvertToDevmodeW should fail\n");
|
|
|
|
ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %u\n", GetLastError());
|
|
|
|
|
|
|
|
/* this is the minimal dmSize that XP accepts */
|
|
|
|
dmA.dmSize = FIELD_OFFSET(DEVMODEA, dmFields);
|
|
|
|
dmW = pGdiConvertToDevmodeW(&dmA);
|
|
|
|
ok(dmW->dmSize == FIELD_OFFSET(DEVMODEW, dmFields),
|
|
|
|
"expected %04x, got %04x\n", FIELD_OFFSET(DEVMODEW, dmFields), dmW->dmSize);
|
|
|
|
HeapFree(GetProcessHeap(), 0, dmW);
|
2007-12-18 12:21:40 +00:00
|
|
|
}
|
|
|
|
|
2008-04-11 13:07:20 +00:00
|
|
|
static void test_CreateCompatibleDC(void)
|
|
|
|
{
|
|
|
|
BOOL bRet;
|
|
|
|
HDC hDC;
|
|
|
|
HDC hNewDC;
|
|
|
|
|
|
|
|
/* Create a DC compatible with the screen */
|
|
|
|
hDC = CreateCompatibleDC(NULL);
|
|
|
|
ok(hDC != NULL, "CreateCompatibleDC returned %p\n", hDC);
|
|
|
|
|
|
|
|
/* Delete this DC, this should succeed */
|
|
|
|
bRet = DeleteDC(hDC);
|
|
|
|
ok(bRet == TRUE, "DeleteDC returned %u\n", bRet);
|
|
|
|
|
|
|
|
/* Try to create a DC compatible to the deleted DC. This has to fail */
|
|
|
|
hNewDC = CreateCompatibleDC(hDC);
|
|
|
|
ok(hNewDC == NULL, "CreateCompatibleDC returned %p\n", hNewDC);
|
|
|
|
}
|
|
|
|
|
2009-04-28 12:11:04 +00:00
|
|
|
static void test_DC_bitmap(void)
|
|
|
|
{
|
|
|
|
HDC hdc, hdcmem;
|
|
|
|
DWORD bits[64];
|
|
|
|
HBITMAP hbmp, oldhbmp;
|
|
|
|
COLORREF col;
|
|
|
|
int i, bitspixel;
|
|
|
|
|
|
|
|
/* fill bitmap data with b&w pattern */
|
|
|
|
for( i = 0; i < 64; i++) bits[i] = i & 1 ? 0 : 0xffffff;
|
|
|
|
|
|
|
|
hdc = GetDC(0);
|
|
|
|
ok( hdc != NULL, "CreateDC rets %p\n", hdc);
|
|
|
|
bitspixel = GetDeviceCaps( hdc, BITSPIXEL);
|
|
|
|
/* create a memory dc */
|
|
|
|
hdcmem = CreateCompatibleDC( hdc);
|
|
|
|
ok( hdcmem != NULL, "CreateCompatibleDC rets %p\n", hdcmem);
|
|
|
|
/* tests */
|
|
|
|
/* test monochrome bitmap: should always work */
|
|
|
|
hbmp = CreateBitmap(32, 32, 1, 1, bits);
|
|
|
|
ok( hbmp != NULL, "CreateBitmap returns %p\n", hbmp);
|
|
|
|
oldhbmp = SelectObject( hdcmem, hbmp);
|
|
|
|
ok( oldhbmp != NULL, "SelectObject returned NULL\n" ); /* a memdc always has a bitmap selected */
|
|
|
|
col = GetPixel( hdcmem, 0, 0);
|
|
|
|
ok( col == 0xffffff, "GetPixel returned %08x, expected 00ffffff\n", col);
|
|
|
|
col = GetPixel( hdcmem, 1, 1);
|
|
|
|
ok( col == 0x000000, "GetPixel returned %08x, expected 00000000\n", col);
|
|
|
|
col = GetPixel( hdcmem, 100, 1);
|
|
|
|
ok( col == CLR_INVALID, "GetPixel returned %08x, expected ffffffff\n", col);
|
|
|
|
SelectObject( hdcmem, oldhbmp);
|
|
|
|
DeleteObject( hbmp);
|
|
|
|
|
|
|
|
/* test with 2 bits color depth, not likely to succeed */
|
|
|
|
hbmp = CreateBitmap(16, 16, 1, 2, bits);
|
|
|
|
ok( hbmp != NULL, "CreateBitmap returns %p\n", hbmp);
|
|
|
|
oldhbmp = SelectObject( hdcmem, hbmp);
|
|
|
|
if( bitspixel != 2)
|
|
|
|
ok( !oldhbmp, "SelectObject of a bitmap with 2 bits/pixel should return NULL\n");
|
|
|
|
if( oldhbmp) SelectObject( hdcmem, oldhbmp);
|
|
|
|
DeleteObject( hbmp);
|
|
|
|
|
|
|
|
/* test with 16 bits color depth, might succeed */
|
|
|
|
hbmp = CreateBitmap(6, 6, 1, 16, bits);
|
|
|
|
ok( hbmp != NULL, "CreateBitmap returns %p\n", hbmp);
|
|
|
|
oldhbmp = SelectObject( hdcmem, hbmp);
|
|
|
|
if( bitspixel == 16) {
|
|
|
|
ok( oldhbmp != NULL, "SelectObject returned NULL\n" );
|
|
|
|
col = GetPixel( hdcmem, 0, 0);
|
|
|
|
ok( col == 0xffffff,
|
|
|
|
"GetPixel of a bitmap with 16 bits/pixel returned %08x, expected 00ffffff\n", col);
|
|
|
|
col = GetPixel( hdcmem, 1, 1);
|
|
|
|
ok( col == 0x000000,
|
|
|
|
"GetPixel of a bitmap with 16 bits/pixel returned returned %08x, expected 00000000\n", col);
|
|
|
|
}
|
|
|
|
if( oldhbmp) SelectObject( hdcmem, oldhbmp);
|
|
|
|
DeleteObject( hbmp);
|
|
|
|
|
|
|
|
/* test with 32 bits color depth, probably succeed */
|
|
|
|
hbmp = CreateBitmap(4, 4, 1, 32, bits);
|
|
|
|
ok( hbmp != NULL, "CreateBitmap returns %p\n", hbmp);
|
|
|
|
oldhbmp = SelectObject( hdcmem, hbmp);
|
|
|
|
if( bitspixel == 32) {
|
|
|
|
ok( oldhbmp != NULL, "SelectObject returned NULL\n" );
|
|
|
|
col = GetPixel( hdcmem, 0, 0);
|
|
|
|
ok( col == 0xffffff,
|
|
|
|
"GetPixel of a bitmap with 32 bits/pixel returned %08x, expected 00ffffff\n", col);
|
|
|
|
col = GetPixel( hdcmem, 1, 1);
|
|
|
|
ok( col == 0x000000,
|
|
|
|
"GetPixel of a bitmap with 32 bits/pixel returned returned %08x, expected 00000000\n", col);
|
|
|
|
}
|
|
|
|
if( oldhbmp) SelectObject( hdcmem, oldhbmp);
|
|
|
|
DeleteObject( hbmp);
|
|
|
|
ReleaseDC( 0, hdc );
|
|
|
|
}
|
|
|
|
|
2010-02-24 14:44:41 +00:00
|
|
|
static void test_DeleteDC(void)
|
|
|
|
{
|
|
|
|
HWND hwnd;
|
|
|
|
HDC hdc, hdc_test;
|
|
|
|
WNDCLASSEX cls;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* window DC */
|
|
|
|
hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0,0,100,100,
|
|
|
|
0, 0, 0, NULL);
|
|
|
|
ok(hwnd != 0, "CreateWindowExA failed\n");
|
|
|
|
|
|
|
|
hdc = GetDC(hwnd);
|
|
|
|
ok(hdc != 0, "GetDC failed\n");
|
|
|
|
ret = GetObjectType(hdc);
|
|
|
|
ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
|
|
|
|
ret = DeleteDC(hdc);
|
|
|
|
ok(ret, "DeleteDC failed\n");
|
|
|
|
ret = GetObjectType(hdc);
|
2010-02-25 05:17:44 +00:00
|
|
|
ok(!ret || broken(ret) /* win9x */, "GetObjectType should fail for a deleted DC\n");
|
2010-02-24 14:44:41 +00:00
|
|
|
|
|
|
|
hdc = GetWindowDC(hwnd);
|
|
|
|
ok(hdc != 0, "GetDC failed\n");
|
|
|
|
ret = GetObjectType(hdc);
|
|
|
|
ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
|
|
|
|
ret = DeleteDC(hdc);
|
|
|
|
ok(ret, "DeleteDC failed\n");
|
|
|
|
ret = GetObjectType(hdc);
|
2010-02-25 05:17:44 +00:00
|
|
|
ok(!ret || broken(ret) /* win9x */, "GetObjectType should fail for a deleted DC\n");
|
2010-02-24 14:44:41 +00:00
|
|
|
|
|
|
|
DestroyWindow(hwnd);
|
|
|
|
|
|
|
|
/* desktop window DC */
|
|
|
|
hwnd = GetDesktopWindow();
|
|
|
|
ok(hwnd != 0, "GetDesktopWindow failed\n");
|
|
|
|
|
|
|
|
hdc = GetDC(hwnd);
|
|
|
|
ok(hdc != 0, "GetDC failed\n");
|
|
|
|
ret = GetObjectType(hdc);
|
|
|
|
ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
|
|
|
|
ret = DeleteDC(hdc);
|
|
|
|
ok(ret, "DeleteDC failed\n");
|
|
|
|
ret = GetObjectType(hdc);
|
2010-02-25 05:17:44 +00:00
|
|
|
ok(!ret || broken(ret) /* win9x */, "GetObjectType should fail for a deleted DC\n");
|
2010-02-24 14:44:41 +00:00
|
|
|
|
|
|
|
hdc = GetWindowDC(hwnd);
|
|
|
|
ok(hdc != 0, "GetDC failed\n");
|
|
|
|
ret = GetObjectType(hdc);
|
|
|
|
ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
|
|
|
|
ret = DeleteDC(hdc);
|
|
|
|
ok(ret, "DeleteDC failed\n");
|
|
|
|
ret = GetObjectType(hdc);
|
2010-02-25 05:17:44 +00:00
|
|
|
ok(!ret || broken(ret) /* win9x */, "GetObjectType should fail for a deleted DC\n");
|
2010-02-24 14:44:41 +00:00
|
|
|
|
|
|
|
/* CS_CLASSDC */
|
|
|
|
memset(&cls, 0, sizeof(cls));
|
|
|
|
cls.cbSize = sizeof(cls);
|
|
|
|
cls.style = CS_CLASSDC;
|
|
|
|
cls.hInstance = GetModuleHandle(0);
|
|
|
|
cls.lpszClassName = "Wine class DC";
|
|
|
|
cls.lpfnWndProc = DefWindowProcA;
|
|
|
|
ret = RegisterClassExA(&cls);
|
|
|
|
ok(ret, "RegisterClassExA failed\n");
|
|
|
|
|
|
|
|
hwnd = CreateWindowExA(0, "Wine class DC", NULL, WS_POPUP|WS_VISIBLE, 0,0,100,100,
|
|
|
|
0, 0, 0, NULL);
|
|
|
|
ok(hwnd != 0, "CreateWindowExA failed\n");
|
|
|
|
|
|
|
|
hdc = GetDC(hwnd);
|
|
|
|
ok(hdc != 0, "GetDC failed\n");
|
|
|
|
ret = GetObjectType(hdc);
|
|
|
|
ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
|
|
|
|
ret = DeleteDC(hdc);
|
|
|
|
ok(ret, "DeleteDC failed\n");
|
|
|
|
ret = GetObjectType(hdc);
|
|
|
|
ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
|
|
|
|
ret = ReleaseDC(hwnd, hdc);
|
|
|
|
ok(ret, "ReleaseDC failed\n");
|
|
|
|
ret = GetObjectType(hdc);
|
|
|
|
ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
|
|
|
|
|
|
|
|
hdc_test = hdc;
|
|
|
|
|
|
|
|
hdc = GetWindowDC(hwnd);
|
|
|
|
ok(hdc != 0, "GetDC failed\n");
|
|
|
|
ret = GetObjectType(hdc);
|
|
|
|
ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
|
|
|
|
ret = DeleteDC(hdc);
|
|
|
|
ok(ret, "DeleteDC failed\n");
|
|
|
|
ret = GetObjectType(hdc);
|
2010-02-25 05:17:44 +00:00
|
|
|
ok(!ret || broken(ret) /* win9x */, "GetObjectType should fail for a deleted DC\n");
|
2010-02-24 14:44:41 +00:00
|
|
|
|
|
|
|
DestroyWindow(hwnd);
|
|
|
|
|
|
|
|
ret = GetObjectType(hdc_test);
|
|
|
|
ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
|
|
|
|
|
|
|
|
ret = UnregisterClassA("Wine class DC", GetModuleHandle(NULL));
|
|
|
|
ok(ret, "UnregisterClassA failed\n");
|
|
|
|
|
|
|
|
ret = GetObjectType(hdc_test);
|
|
|
|
todo_wine
|
|
|
|
ok(!ret, "GetObjectType should fail for a deleted DC\n");
|
|
|
|
|
|
|
|
/* CS_OWNDC */
|
|
|
|
memset(&cls, 0, sizeof(cls));
|
|
|
|
cls.cbSize = sizeof(cls);
|
|
|
|
cls.style = CS_OWNDC;
|
|
|
|
cls.hInstance = GetModuleHandle(0);
|
|
|
|
cls.lpszClassName = "Wine own DC";
|
|
|
|
cls.lpfnWndProc = DefWindowProcA;
|
|
|
|
ret = RegisterClassExA(&cls);
|
|
|
|
ok(ret, "RegisterClassExA failed\n");
|
|
|
|
|
|
|
|
hwnd = CreateWindowExA(0, "Wine own DC", NULL, WS_POPUP|WS_VISIBLE, 0,0,100,100,
|
|
|
|
0, 0, 0, NULL);
|
|
|
|
ok(hwnd != 0, "CreateWindowExA failed\n");
|
|
|
|
|
|
|
|
hdc = GetDC(hwnd);
|
|
|
|
ok(hdc != 0, "GetDC failed\n");
|
|
|
|
ret = GetObjectType(hdc);
|
|
|
|
ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
|
|
|
|
ret = DeleteDC(hdc);
|
|
|
|
ok(ret, "DeleteDC failed\n");
|
|
|
|
ret = GetObjectType(hdc);
|
|
|
|
ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
|
|
|
|
ret = ReleaseDC(hwnd, hdc);
|
|
|
|
ok(ret, "ReleaseDC failed\n");
|
|
|
|
ret = GetObjectType(hdc);
|
|
|
|
ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
|
|
|
|
|
|
|
|
hdc = GetWindowDC(hwnd);
|
|
|
|
ok(hdc != 0, "GetDC failed\n");
|
|
|
|
ret = GetObjectType(hdc);
|
|
|
|
ok(ret == OBJ_DC, "expected OBJ_DC, got %d\n", ret);
|
|
|
|
ret = DeleteDC(hdc);
|
|
|
|
ok(ret, "DeleteDC failed\n");
|
|
|
|
ret = GetObjectType(hdc);
|
2010-02-25 05:17:44 +00:00
|
|
|
ok(!ret || broken(ret) /* win9x */, "GetObjectType should fail for a deleted DC\n");
|
2010-02-24 14:44:41 +00:00
|
|
|
|
|
|
|
DestroyWindow(hwnd);
|
|
|
|
|
|
|
|
ret = UnregisterClassA("Wine own DC", GetModuleHandle(NULL));
|
|
|
|
ok(ret, "UnregisterClassA failed\n");
|
|
|
|
}
|
|
|
|
|
2010-06-01 13:03:24 +00:00
|
|
|
static void test_boundsrect_invalid(void)
|
|
|
|
{
|
|
|
|
HDC hdc;
|
2011-06-17 13:52:24 +00:00
|
|
|
RECT rect, expect, set_rect;
|
2010-06-01 13:03:24 +00:00
|
|
|
UINT ret;
|
|
|
|
|
|
|
|
hdc = GetDC(NULL);
|
|
|
|
ok(hdc != NULL, "GetDC failed\n");
|
|
|
|
|
|
|
|
ret = GetBoundsRect(hdc, NULL, 0);
|
|
|
|
ok(ret == 0 ||
|
|
|
|
broken(ret == DCB_RESET), /* Win9x */
|
|
|
|
"Expected GetBoundsRect to return 0, got %u\n", ret);
|
|
|
|
|
|
|
|
ret = GetBoundsRect(hdc, NULL, ~0U);
|
|
|
|
ok(ret == 0 ||
|
|
|
|
broken(ret == DCB_RESET), /* Win9x */
|
|
|
|
"Expected GetBoundsRect to return 0, got %u\n", ret);
|
|
|
|
|
|
|
|
if (GetBoundsRect(hdc, NULL, 0) == DCB_RESET)
|
|
|
|
win_skip("Win9x fails catastrophically with first GetBoundsRect call\n");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Test parameter handling order. */
|
2011-06-17 13:52:24 +00:00
|
|
|
SetRect(&set_rect, 10, 20, 40, 50);
|
|
|
|
ret = SetBoundsRect(hdc, &set_rect, DCB_SET);
|
2010-06-01 13:03:24 +00:00
|
|
|
ok(ret & DCB_RESET,
|
|
|
|
"Expected return flag DCB_RESET to be set, got %u\n", ret);
|
|
|
|
|
|
|
|
ret = GetBoundsRect(hdc, NULL, DCB_RESET);
|
|
|
|
ok(ret == 0,
|
|
|
|
"Expected GetBoundsRect to return 0, got %u\n", ret);
|
|
|
|
|
|
|
|
ret = GetBoundsRect(hdc, &rect, 0);
|
2010-11-29 16:52:56 +00:00
|
|
|
if (ret != DCB_SET) /* WinME */
|
|
|
|
{
|
|
|
|
ok(ret == DCB_RESET,
|
|
|
|
"Expected GetBoundsRect to return DCB_RESET, got %u\n", ret);
|
|
|
|
SetRect(&expect, 0, 0, 0, 0);
|
2011-06-17 13:52:24 +00:00
|
|
|
ok(EqualRect(&rect, &expect) ||
|
|
|
|
broken(EqualRect(&rect, &set_rect)), /* nt4 sp1-5 */
|
2010-11-29 16:52:56 +00:00
|
|
|
"Expected output rectangle (0,0)-(0,0), got (%d,%d)-(%d,%d)\n",
|
|
|
|
rect.left, rect.top, rect.right, rect.bottom);
|
|
|
|
}
|
2010-06-01 13:03:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GetBoundsRect(hdc, NULL, 0) == DCB_RESET)
|
|
|
|
win_skip("Win9x fails catastrophically with NULL device context parameter\n");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = GetBoundsRect(NULL, NULL, 0);
|
|
|
|
ok(ret == 0, "Expected GetBoundsRect to return 0, got %u\n", ret);
|
|
|
|
|
|
|
|
ret = GetBoundsRect(NULL, NULL, ~0U);
|
|
|
|
ok(ret == 0, "Expected GetBoundsRect to return 0, got %u\n", ret);
|
|
|
|
|
|
|
|
ret = SetBoundsRect(NULL, NULL, 0);
|
|
|
|
ok(ret == 0, "Expected SetBoundsRect to return 0, got %u\n", ret);
|
|
|
|
|
|
|
|
ret = SetBoundsRect(NULL, NULL, ~0U);
|
|
|
|
ok(ret == 0, "Expected SetBoundsRect to return 0, got %u\n", ret);
|
|
|
|
}
|
|
|
|
|
2011-06-17 13:52:23 +00:00
|
|
|
ReleaseDC(NULL, hdc);
|
2010-06-01 13:03:24 +00:00
|
|
|
}
|
|
|
|
|
2010-06-15 05:26:20 +00:00
|
|
|
static void test_desktop_colorres(void)
|
|
|
|
{
|
|
|
|
HDC hdc = GetDC(NULL);
|
|
|
|
int bitspixel, colorres;
|
|
|
|
|
|
|
|
bitspixel = GetDeviceCaps(hdc, BITSPIXEL);
|
|
|
|
ok(bitspixel != 0, "Expected to get valid BITSPIXEL capability value\n");
|
|
|
|
|
|
|
|
colorres = GetDeviceCaps(hdc, COLORRES);
|
|
|
|
ok(colorres != 0 ||
|
|
|
|
broken(colorres == 0), /* Win9x */
|
|
|
|
"Expected to get valid COLORRES capability value\n");
|
|
|
|
|
|
|
|
if (colorres)
|
|
|
|
{
|
|
|
|
switch (bitspixel)
|
|
|
|
{
|
|
|
|
case 8:
|
|
|
|
ok(colorres == 18,
|
|
|
|
"Expected COLORRES to be 18, got %d\n", colorres);
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
ok(colorres == 16,
|
|
|
|
"Expected COLORRES to be 16, got %d\n", colorres);
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
case 32:
|
|
|
|
ok(colorres == 24,
|
|
|
|
"Expected COLORRES to be 24, got %d\n", bitspixel);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ok(0, "Got unknown BITSPIXEL %d with COLORRES %d\n", bitspixel, colorres);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-17 13:52:23 +00:00
|
|
|
ReleaseDC(NULL, hdc);
|
2010-06-15 05:26:20 +00:00
|
|
|
}
|
|
|
|
|
2011-08-11 18:37:26 +00:00
|
|
|
static void test_gamma(void)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
HDC hdc = GetDC(NULL);
|
|
|
|
WORD oldramp[3][256], ramp[3][256];
|
|
|
|
INT i;
|
|
|
|
|
|
|
|
ret = GetDeviceGammaRamp(hdc, &oldramp);
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
win_skip("GetDeviceGammaRamp failed, skipping tests\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to set back old ramp */
|
|
|
|
ret = SetDeviceGammaRamp(hdc, &oldramp);
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
win_skip("SetDeviceGammaRamp failed, skipping tests\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(ramp, oldramp, sizeof(ramp));
|
|
|
|
|
|
|
|
/* set one color ramp to zeros */
|
|
|
|
memset(ramp[0], 0, sizeof(ramp[0]));
|
|
|
|
ret = SetDeviceGammaRamp(hdc, &ramp);
|
|
|
|
ok(!ret, "SetDeviceGammaRamp succeeded\n");
|
|
|
|
|
|
|
|
/* set one color ramp to a flat straight rising line */
|
|
|
|
for (i = 0; i < 256; i++) ramp[0][i] = i;
|
|
|
|
ret = SetDeviceGammaRamp(hdc, &ramp);
|
|
|
|
todo_wine ok(!ret, "SetDeviceGammaRamp succeeded\n");
|
|
|
|
|
|
|
|
/* set one color ramp to a steep straight rising line */
|
|
|
|
for (i = 0; i < 256; i++) ramp[0][i] = i * 256;
|
|
|
|
ret = SetDeviceGammaRamp(hdc, &ramp);
|
|
|
|
ok(ret, "SetDeviceGammaRamp failed\n");
|
|
|
|
|
2011-08-23 21:16:26 +00:00
|
|
|
/* try a bright gamma ramp */
|
|
|
|
ramp[0][0] = 0;
|
|
|
|
ramp[0][1] = 0x7FFF;
|
|
|
|
for (i = 2; i < 256; i++) ramp[0][i] = 0xFFFF;
|
|
|
|
ret = SetDeviceGammaRamp(hdc, &ramp);
|
|
|
|
ok(!ret, "SetDeviceGammaRamp succeeded\n");
|
|
|
|
|
2011-08-11 18:37:26 +00:00
|
|
|
/* cleanup: set old ramp again */
|
|
|
|
ret = SetDeviceGammaRamp(hdc, &oldramp);
|
|
|
|
ok(ret, "SetDeviceGammaRamp failed\n");
|
|
|
|
|
|
|
|
done:
|
|
|
|
ReleaseDC(NULL, hdc);
|
|
|
|
}
|
|
|
|
|
2005-10-31 10:05:52 +00:00
|
|
|
START_TEST(dc)
|
|
|
|
{
|
|
|
|
test_savedc();
|
2005-11-22 12:00:11 +00:00
|
|
|
test_savedc_2();
|
2007-12-18 12:21:40 +00:00
|
|
|
test_GdiConvertToDevmodeW();
|
2008-04-11 13:07:20 +00:00
|
|
|
test_CreateCompatibleDC();
|
2009-04-28 12:11:04 +00:00
|
|
|
test_DC_bitmap();
|
2010-02-24 14:44:41 +00:00
|
|
|
test_DeleteDC();
|
2010-06-01 13:03:24 +00:00
|
|
|
test_boundsrect_invalid();
|
2010-06-15 05:26:20 +00:00
|
|
|
test_desktop_colorres();
|
2011-08-11 18:37:26 +00:00
|
|
|
test_gamma();
|
2005-10-31 10:05:52 +00:00
|
|
|
}
|