2005-10-31 11:05:52 +01:00
|
|
|
/*
|
|
|
|
* Unit tests for dc functions
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005 Huw Davies
|
2005-11-22 13:00:11 +01:00
|
|
|
* Copyright (c) 2005 Dmitry Timoshkov
|
2005-10-31 11:05:52 +01: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
|
2005-10-31 11:05:52 +01:00
|
|
|
*/
|
|
|
|
|
2007-12-19 04:41:07 +01:00
|
|
|
#define WINVER 0x0501 /* request latest DEVMODE */
|
|
|
|
|
2005-10-31 11:05:52 +01: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 13:00:11 +01: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 22:56:45 +02:00
|
|
|
printf( "%d rects:", data->rdh.nCount );
|
2005-11-22 13:00:11 +01:00
|
|
|
for (i = 0, rect = (RECT *)data->Buffer; i < data->rdh.nCount; i++, rect++)
|
2006-10-12 22:56:45 +02:00
|
|
|
printf( " (%d,%d)-(%d,%d)", rect->left, rect->top, rect->right, rect->bottom );
|
2005-11-22 13:00:11 +01: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);
|
|
|
|
ok(hdc != NULL, "CreateDC rets %p\n", hdc);
|
|
|
|
|
|
|
|
ret = GetClipBox(hdc, &rc_clip);
|
|
|
|
ok(ret == SIMPLEREGION, "GetClipBox returned %d instead of SIMPLEREGION\n", ret);
|
|
|
|
ret = GetClipRgn(hdc, hrgn);
|
|
|
|
ok(ret == 0, "GetClipRgn returned %d instead of 0\n", ret);
|
|
|
|
ret = GetRgnBox(hrgn, &rc);
|
2006-10-12 22:56:45 +02:00
|
|
|
ok(ret == NULLREGION, "GetRgnBox returned %d (%d,%d-%d,%d) instead of NULLREGION\n",
|
2005-11-22 13:00:11 +01: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 22:56:45 +02:00
|
|
|
"rects are not equal: (%d,%d-%d,%d) - (%d,%d-%d,%d)\n",
|
2005-11-22 13:00:11 +01: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 19:30:19 +01:00
|
|
|
if (ret == COMPLEXREGION)
|
2005-11-22 13:00:11 +01:00
|
|
|
{
|
2007-01-06 19:30:19 +01:00
|
|
|
/* XP returns COMPLEXREGION although dump_region reports only 1 rect */
|
2005-11-22 13:00:11 +01: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 19:30:19 +01:00
|
|
|
else
|
|
|
|
ok(ret == SIMPLEREGION, "IntersectClipRect returned %d instead of SIMPLEREGION\n", ret);
|
2005-11-22 13:00:11 +01:00
|
|
|
|
|
|
|
ret = GetClipBox(hdc, &rc_clip);
|
|
|
|
ok(ret == SIMPLEREGION, "GetClipBox returned %d instead of SIMPLEREGION\n", ret);
|
|
|
|
SetRect(&rc, 0, 0, 50, 50);
|
|
|
|
ok(EqualRect(&rc, &rc_clip), "rects are not equal\n");
|
|
|
|
|
|
|
|
ret = RestoreDC(hdc, 1);
|
|
|
|
ok(ret, "ret = %d\n", ret);
|
|
|
|
|
|
|
|
ret = GetClipBox(hdc, &rc_clip);
|
|
|
|
ok(ret == SIMPLEREGION, "GetClipBox returned %d instead of SIMPLEREGION\n", ret);
|
|
|
|
SetRect(&rc, 0, 0, 100, 100);
|
|
|
|
ok(EqualRect(&rc, &rc_clip), "rects are not equal\n");
|
|
|
|
|
|
|
|
DeleteObject(hrgn);
|
|
|
|
ReleaseDC(hwnd, hdc);
|
|
|
|
DestroyWindow(hwnd);
|
|
|
|
}
|
2005-10-31 11:05:52 +01:00
|
|
|
|
2005-11-22 13:00:11 +01:00
|
|
|
static void test_savedc(void)
|
2005-10-31 11:05:52 +01: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);
|
|
|
|
|
|
|
|
/* Under win98 the following two succeed and both clear the save stack
|
|
|
|
ret = RestoreDC(hdc, -3);
|
|
|
|
ok(!ret, "ret = %d\n", ret);
|
|
|
|
ret = RestoreDC(hdc, 0);
|
|
|
|
ok(!ret, "ret = %d\n", ret);
|
|
|
|
*/
|
|
|
|
|
|
|
|
ret = RestoreDC(hdc, 1);
|
|
|
|
ok(ret, "ret = %d\n", ret);
|
|
|
|
|
|
|
|
DeleteDC(hdc);
|
|
|
|
}
|
|
|
|
|
2007-12-18 13:21:40 +01: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)
|
|
|
|
{
|
|
|
|
skip("GdiConvertToDevmodeW is not available on this platform\n");
|
|
|
|
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 17:18:29 +01:00
|
|
|
"wrong size %u\n", dmW->dmSize);
|
2007-12-18 13:21:40 +01: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 17:18:29 +01:00
|
|
|
"wrong size %u\n", dmW->dmSize);
|
2007-12-18 13:21:40 +01: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 17:18:29 +01:00
|
|
|
"wrong size %u\n", dmW->dmSize);
|
2007-12-18 13:21:40 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, dmW);
|
2007-12-20 07:49:59 +01: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 13:21:40 +01:00
|
|
|
}
|
|
|
|
|
2008-04-11 15:07:20 +02: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);
|
|
|
|
}
|
|
|
|
|
2005-10-31 11:05:52 +01:00
|
|
|
START_TEST(dc)
|
|
|
|
{
|
|
|
|
test_savedc();
|
2005-11-22 13:00:11 +01:00
|
|
|
test_savedc_2();
|
2007-12-18 13:21:40 +01:00
|
|
|
test_GdiConvertToDevmodeW();
|
2008-04-11 15:07:20 +02:00
|
|
|
test_CreateCompatibleDC();
|
2005-10-31 11:05:52 +01:00
|
|
|
}
|