📄 dce.c
字号:
/*
* Unit tests for DCE support
*
* Copyright 2005 Alexandre Julliard
*
* 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
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#include <assert.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
#include "wine/test.h"
#ifndef DCX_USESTYLE
#define DCX_USESTYLE 0x00010000
#endif
static HWND hwnd_cache, hwnd_owndc, hwnd_classdc, hwnd_classdc2;
/* test behavior of DC attributes with various GetDC/ReleaseDC combinations */
static void test_dc_attributes(void)
{
HDC hdc, old_hdc;
INT rop, def_rop;
/* test cache DC */
hdc = GetDC( hwnd_cache );
def_rop = GetROP2( hdc );
SetROP2( hdc, R2_WHITE );
rop = GetROP2( hdc );
ok( rop == R2_WHITE, "wrong ROP2 %d\n", rop );
ReleaseDC( hwnd_cache, hdc );
hdc = GetDC( hwnd_cache );
rop = GetROP2( hdc );
ok( rop == def_rop, "wrong ROP2 %d after release\n", rop );
SetROP2( hdc, R2_WHITE );
ReleaseDC( hwnd_cache, hdc );
hdc = GetDCEx( hwnd_cache, 0, DCX_USESTYLE | DCX_NORESETATTRS );
rop = GetROP2( hdc );
/* Win9x seems to silently ignore DCX_NORESETATTRS */
ok( rop == def_rop || rop == R2_WHITE, "wrong ROP2 %d\n", rop );
SetROP2( hdc, R2_WHITE );
rop = GetROP2( hdc );
ok( rop == R2_WHITE, "wrong ROP2 %d\n", rop );
ReleaseDC( hwnd_cache, hdc );
hdc = GetDCEx( hwnd_cache, 0, DCX_USESTYLE | DCX_NORESETATTRS );
rop = GetROP2( hdc );
ok( rop == def_rop || rop == R2_WHITE, "wrong ROP2 %d after release\n", rop );
ReleaseDC( hwnd_cache, hdc );
hdc = GetDCEx( hwnd_cache, 0, DCX_USESTYLE );
rop = GetROP2( hdc );
ok( rop == def_rop, "wrong ROP2 %d after release\n", rop );
ReleaseDC( hwnd_cache, hdc );
/* test own DC */
hdc = GetDC( hwnd_owndc );
SetROP2( hdc, R2_WHITE );
rop = GetROP2( hdc );
ok( rop == R2_WHITE, "wrong ROP2 %d\n", rop );
old_hdc = hdc;
ReleaseDC( hwnd_owndc, hdc );
hdc = GetDC( hwnd_owndc );
ok( old_hdc == hdc, "didn't get same DC %p/%p\n", old_hdc, hdc );
rop = GetROP2( hdc );
ok( rop == R2_WHITE, "wrong ROP2 %d after release\n", rop );
ReleaseDC( hwnd_owndc, hdc );
rop = GetROP2( hdc );
ok( rop == R2_WHITE, "wrong ROP2 %d after second release\n", rop );
/* test class DC */
hdc = GetDC( hwnd_classdc );
SetROP2( hdc, R2_WHITE );
rop = GetROP2( hdc );
ok( rop == R2_WHITE, "wrong ROP2 %d\n", rop );
old_hdc = hdc;
ReleaseDC( hwnd_classdc, hdc );
hdc = GetDC( hwnd_classdc );
ok( old_hdc == hdc, "didn't get same DC %p/%p\n", old_hdc, hdc );
rop = GetROP2( hdc );
ok( rop == R2_WHITE, "wrong ROP2 %d after release\n", rop );
ReleaseDC( hwnd_classdc, hdc );
rop = GetROP2( hdc );
ok( rop == R2_WHITE, "wrong ROP2 %d after second release\n", rop );
/* test class DC with 2 windows */
old_hdc = GetDC( hwnd_classdc );
SetROP2( old_hdc, R2_BLACK );
hdc = GetDC( hwnd_classdc2 );
ok( old_hdc == hdc, "didn't get same DC %p/%p\n", old_hdc, hdc );
rop = GetROP2( hdc );
ok( rop == R2_BLACK, "wrong ROP2 %d for other window\n", rop );
ReleaseDC( hwnd_classdc, old_hdc );
ReleaseDC( hwnd_classdc, hdc );
rop = GetROP2( hdc );
ok( rop == R2_BLACK, "wrong ROP2 %d after release\n", rop );
}
/* test behavior with various invalid parameters */
static void test_parameters(void)
{
HDC hdc;
hdc = GetDC( hwnd_cache );
ok( ReleaseDC( hwnd_owndc, hdc ), "ReleaseDC with wrong window should succeed\n" );
hdc = GetDC( hwnd_cache );
ok( !ReleaseDC( hwnd_cache, 0 ), "ReleaseDC with wrong HDC should fail\n" );
ok( ReleaseDC( hwnd_cache, hdc ), "correct ReleaseDC should succeed\n" );
ok( !ReleaseDC( hwnd_cache, hdc ), "second ReleaseDC should fail\n" );
hdc = GetDC( hwnd_owndc );
ok( ReleaseDC( hwnd_cache, hdc ), "ReleaseDC with wrong window should succeed\n" );
hdc = GetDC( hwnd_owndc );
ok( ReleaseDC( hwnd_owndc, hdc ), "correct ReleaseDC should succeed\n" );
ok( ReleaseDC( hwnd_owndc, hdc ), "second ReleaseDC should succeed\n" );
hdc = GetDC( hwnd_classdc );
ok( ReleaseDC( hwnd_cache, hdc ), "ReleaseDC with wrong window should succeed\n" );
hdc = GetDC( hwnd_classdc );
ok( ReleaseDC( hwnd_classdc, hdc ), "correct ReleaseDC should succeed\n" );
ok( ReleaseDC( hwnd_classdc, hdc ), "second ReleaseDC should succeed\n" );
}
static void test_dc_visrgn(void)
{
HDC old_hdc, hdc;
HRGN hrgn, hrgn2;
RECT rect;
/* cache DC */
SetRect( &rect, 10, 10, 20, 20 );
MapWindowPoints( hwnd_cache, 0, (POINT *)&rect, 2 );
hrgn = CreateRectRgnIndirect( &rect );
hdc = GetDCEx( hwnd_cache, hrgn, DCX_INTERSECTRGN | DCX_USESTYLE );
SetRectEmpty( &rect );
GetClipBox( hdc, &rect );
ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
"invalid clip box %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
ok( GetRgnBox( hrgn, &rect ) != ERROR, "region must still be valid\n" );
ReleaseDC( hwnd_cache, hdc );
ok( GetRgnBox( hrgn, &rect ) == ERROR, "region must no longer be valid\n" );
/* cache DC with NORESETATTRS */
SetRect( &rect, 10, 10, 20, 20 );
MapWindowPoints( hwnd_cache, 0, (POINT *)&rect, 2 );
hrgn = CreateRectRgnIndirect( &rect );
hdc = GetDCEx( hwnd_cache, hrgn, DCX_INTERSECTRGN | DCX_USESTYLE | DCX_NORESETATTRS );
SetRectEmpty( &rect );
GetClipBox( hdc, &rect );
ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
"invalid clip box %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
ok( GetRgnBox( hrgn, &rect ) != ERROR, "region must still be valid\n" );
ReleaseDC( hwnd_cache, hdc );
ok( GetRgnBox( hrgn, &rect ) == ERROR, "region must no longer be valid\n" );
hdc = GetDCEx( hwnd_cache, 0, DCX_USESTYLE | DCX_NORESETATTRS );
SetRectEmpty( &rect );
GetClipBox( hdc, &rect );
ok( !(rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20),
"clip box sould have been reset %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
ReleaseDC( hwnd_cache, hdc );
/* window DC */
SetRect( &rect, 10, 10, 20, 20 );
MapWindowPoints( hwnd_owndc, 0, (POINT *)&rect, 2 );
hrgn = CreateRectRgnIndirect( &rect );
hdc = GetDCEx( hwnd_owndc, hrgn, DCX_INTERSECTRGN | DCX_USESTYLE );
SetRectEmpty( &rect );
GetClipBox( hdc, &rect );
ok( rect.left >= 10 && rect.top >= 10 && rect.right <= 20 && rect.bottom <= 20,
"invalid clip box %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
ok( GetRgnBox( hrgn, &rect ) != ERROR, "region must still be valid\n" );
ReleaseDC( hwnd_owndc, hdc );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -