From dd25b0e4c077ce3a2a9c76b96c33f2fd17ff938c Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Sat, 14 Feb 2015 13:19:02 +0000 Subject: [PATCH] [GDI32_APITEST] Add tests for OffsetRgn, PaintRgn and FrameRgn, fix 1BPP DIB creation in InitStuff() svn path=/trunk/; revision=66259 --- rostests/apitests/gdi32/CMakeLists.txt | 3 + rostests/apitests/gdi32/FrameRgn.c | 146 +++++++++++++++++++++++++ rostests/apitests/gdi32/OffsetRgn.c | 58 ++++++++++ rostests/apitests/gdi32/PaintRgn.c | 63 +++++++++++ rostests/apitests/gdi32/init.c | 11 +- rostests/apitests/gdi32/init.h | 2 +- rostests/apitests/gdi32/testlist.c | 6 + 7 files changed, 285 insertions(+), 4 deletions(-) create mode 100644 rostests/apitests/gdi32/FrameRgn.c create mode 100644 rostests/apitests/gdi32/OffsetRgn.c create mode 100644 rostests/apitests/gdi32/PaintRgn.c diff --git a/rostests/apitests/gdi32/CMakeLists.txt b/rostests/apitests/gdi32/CMakeLists.txt index e93290f4a7b..ad05ef14175 100644 --- a/rostests/apitests/gdi32/CMakeLists.txt +++ b/rostests/apitests/gdi32/CMakeLists.txt @@ -26,6 +26,7 @@ list(APPEND SOURCE ExcludeClipRect.c ExtCreatePen.c ExtCreateRegion.c + FrameRgn.c GdiConvertBitmap.c GdiConvertBrush.c GdiConvertDC.c @@ -51,6 +52,8 @@ list(APPEND SOURCE GetTextFace.c MaskBlt.c OffsetClipRgn.c + OffsetRgn.c + PaintRgn.c PatBlt.c Rectangle.c RealizePalette.c diff --git a/rostests/apitests/gdi32/FrameRgn.c b/rostests/apitests/gdi32/FrameRgn.c new file mode 100644 index 00000000000..99f9481be20 --- /dev/null +++ b/rostests/apitests/gdi32/FrameRgn.c @@ -0,0 +1,146 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: GPL - See COPYING in the top level directory + * PURPOSE: Test for FrameRgn + * PROGRAMMERS: Timo Kreuzer + */ + +#include +#include +#include +#include "init.h" + +#if 0 +BOOL +MyFrameRgn( + HDC hdc, + HRGN hrgn, + HBRUSH hbr, + INT cx, + INT cy) +{ + HRGN hrgnTemp; + + hrgnTemp = CreateRectRgn(0, 0, 0, 0); + if (hrgnTemp == NULL) + { + return FALSE; + } + + if (CombineRgn(hrgnTemp, hrgn, NULL, RGN_COPY) == ERROR) + goto Failure; + + if (OffsetRgn(hrgn, cx, cy) == ERROR) + goto Failure; + + if (CombineRgn(hrgnTemp, hrgnTemp, hrgn, RGN_AND) == ERROR) + goto Failure; + + if (OffsetRgn(hrgn, -2 * cx, 0) == ERROR) + goto Failure; + + if (CombineRgn(hrgnTemp, hrgnTemp, hrgn, RGN_AND) == ERROR) + goto Failure; + + if (OffsetRgn(hrgn, 0, -2 * cy) == ERROR) + goto Failure; + + if (CombineRgn(hrgnTemp, hrgnTemp, hrgn, RGN_AND) == ERROR) + goto Failure; + + if (OffsetRgn(hrgn, 2 * cx, 0) == ERROR) + goto Failure; + + if (CombineRgn(hrgnTemp, hrgnTemp, hrgn, RGN_AND) == ERROR) + goto Failure; + + if (OffsetRgn(hrgn, -cx, cy) == ERROR) + goto Failure; + + if (CombineRgn(hrgnTemp, hrgn, hrgnTemp, RGN_DIFF) == ERROR) + goto Failure; + + if (!FillRgn(hdc, hrgnTemp, hbr)) + goto Failure; + + DeleteObject(hrgnTemp); + return TRUE; + +Failure: + DeleteObject(hrgnTemp); + return FALSE; +} +#endif // 0 + +static +void +CheckBitmapBitsWithLine( + ULONG Line, + HDC hdc, + UINT cx, + UINT cy, + PUCHAR pjBits, + COLORREF *pcrColors) +{ + UINT x, y, i; + + for (y = 0; y < cy; y++) + { + for (x = 0; x < cy; x++) + { + i = y * cx + x; + ok(GetPixel(hdc, x, y) == pcrColors[pjBits[i]], + "Wrong pixel at (%u,%u): expected 0x%08x, got 0x%08x\n", + x, y, pcrColors[pjBits[i]], GetPixel(hdc, x, y)); + } + } +} + +#define CheckBitmapBits(hdc,cx,cy,pj,pcr) \ + CheckBitmapBitsWithLine(__LINE__, hdc,cx,cy,pj,pcr) + +void Test_FrameRgn() +{ + RECT rc = {0, 0, 8, 8 }; + HRGN hrgn1, hrgn2; + BOOL bRet; + UCHAR ajBits[64] = { + 0, 0, 0, 0, 0, 0, 0, 0, // 0000000 + 0, 1, 1, 1, 1, 0, 0, 0, // 0****00 + 0, 1, 2, 2, 1, 0, 0, 0, // 0*xx**0 + 0, 1, 2, 2, 1, 1, 1, 0, // 0*xxx*0 + 0, 1, 1, 1, 2, 2, 1, 0, // 0**xx*0 + 0, 0, 0, 1, 2, 2, 1, 0, // 00****0 + 0, 0, 0, 1, 1, 1, 1, 0, // 0000000 + 0, 0, 0, 0, 0, 0, 0, 0 // 0000000 + }; + COLORREF acrColors[16] = {RGB(0,0,0), RGB(255,255,255), RGB(128,128,128), 0}; + + FillRect(ghdcDIB32, &rc, GetStockObject(BLACK_BRUSH)); + + hrgn1 = CreateRectRgn(1, 1, 5, 5); + ok(hrgn1 != NULL, "failed to create region\n"); + + hrgn2 = CreateRectRgn(3, 3, 7, 7); + ok(hrgn1 != NULL, "failed to create region\n"); + + CombineRgn(hrgn1, hrgn1, hrgn2, RGN_OR); + + bRet = FillRgn(ghdcDIB32, hrgn1, GetStockObject(GRAY_BRUSH)); + ok(bRet != 0, "FrameRgn failed\n"); + + bRet = FrameRgn(ghdcDIB32, hrgn1, GetStockObject(WHITE_BRUSH), 1, 1); + ok(bRet != 0, "FrameRgn failed\n"); + + CheckBitmapBits(ghdcDIB32, 8, 8, ajBits, acrColors); + +} + + + +START_TEST(FrameRgn) +{ + InitStuff(); + Test_FrameRgn(); +} + diff --git a/rostests/apitests/gdi32/OffsetRgn.c b/rostests/apitests/gdi32/OffsetRgn.c new file mode 100644 index 00000000000..11bb882637f --- /dev/null +++ b/rostests/apitests/gdi32/OffsetRgn.c @@ -0,0 +1,58 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: GPL - See COPYING in the top level directory + * PURPOSE: Test for FrameRgn + * PROGRAMMERS: Timo Kreuzer + */ + +#include +#include +#include +#include "init.h" + +void Test_OffsetRgn() +{ + HRGN hrgn1, hrgn2; + HDC hdc; + + hrgn1 = CreateRectRgn(0, 0, 0, 0); + ok(hrgn1 != NULL, "CreateRectRgn failed\n"); + ok_int(OffsetRgn(hrgn1, INT_MIN + 10, 10), NULLREGION); + ok_int(OffsetRgn(hrgn1, 0xF000000, 0xF000000), NULLREGION); + DeleteObject(hrgn1); + + hrgn1 = CreateRectRgn(0, 0, 100, 100); + ok(hrgn1 != NULL, "CreateRectRgn failed\n"); + ok_int(OffsetRgn(hrgn1, 10, 10), SIMPLEREGION); + ok_int(OffsetRgn(hrgn1, 0x8000000 - 110, 10), ERROR); + ok_int(OffsetRgn(hrgn1, 0x8000000 - 111, 10), SIMPLEREGION); + DeleteObject(hrgn1); + + hrgn1 = CreateRectRgn(0, 0, 100, 100); + ok(hrgn1 != NULL, "CreateRectRgn failed\n"); + ok_int(OffsetRgn(hrgn1, -10, 10), SIMPLEREGION); + ok_int(OffsetRgn(hrgn1, -(0x8000000 - 9), 10), ERROR); + ok_int(OffsetRgn(hrgn1, -(0x8000000 - 10), 10), SIMPLEREGION); + DeleteObject(hrgn1); + + hrgn1 = CreateRectRgn(0, 0, 10, 10); + hrgn2 = CreateRectRgn(1000, 20, 1010, 30); + ok_int(CombineRgn(hrgn1, hrgn1, hrgn2, RGN_OR), COMPLEXREGION); + ok_int(OffsetRgn(hrgn1, 0x8000000 - 100, 10), ERROR); + ok_int(CombineRgn(hrgn1, hrgn1, hrgn2, RGN_XOR), SIMPLEREGION); + DeleteObject(hrgn2); + hrgn2 = CreateRectRgn(0, 0, 10, 10); + ok_int(CombineRgn(hrgn1, hrgn1, hrgn2, RGN_XOR), NULLREGION); + + hrgn1 = CreateRectRgn(0, 0, 0, 0); + hdc = CreateCompatibleDC(NULL); + ok_int(GetClipRgn(hdc, hrgn1), 0); + ok_int(OffsetRgn(hrgn1, 10, 10), NULLREGION); + +} + +START_TEST(OffsetRgn) +{ + Test_OffsetRgn(); +} + diff --git a/rostests/apitests/gdi32/PaintRgn.c b/rostests/apitests/gdi32/PaintRgn.c new file mode 100644 index 00000000000..36fa935cb0e --- /dev/null +++ b/rostests/apitests/gdi32/PaintRgn.c @@ -0,0 +1,63 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: GPL - See COPYING in the top level directory + * PURPOSE: Test for FrameRgn + * PROGRAMMERS: Timo Kreuzer + */ + +#include +#include +#include +#include "init.h" + + +void Test_PaintRgn() +{ + RECT rc = { 0, 0, 100, 100 }; + HRGN hrgn1, hrgn2; + BOOL bRet; + XFORM xform; + PULONG pulDIB = gpvDIB1; + + FillRect(ghdcDIB1, &rc, GetStockObject(BLACK_BRUSH)); + + hrgn1 = CreateRectRgn(0, 0, 8, 3); + ok(hrgn1 != NULL, "failed to create region\n"); + + hrgn2 = CreateRectRgn(2, 3, 5, 8); + ok(hrgn1 != NULL, "failed to create region\n"); + + CombineRgn(hrgn1, hrgn1, hrgn2, RGN_OR); + + xform.eM11 = 1.0; + xform.eM12 = 0.5f; + xform.eM21 = 0.0; + xform.eM22 = 1.0; + xform.eDx = 0.0; + xform.eDy = 0.0; + + SetGraphicsMode(ghdcDIB1, GM_ADVANCED); + ok(SetWorldTransform(ghdcDIB1, &xform) == TRUE, "SetWorldTransform failed\n"); + + SelectObject(ghdcDIB1, GetStockObject(WHITE_BRUSH)); + + bRet = PaintRgn(ghdcDIB1, hrgn1); + ok(bRet == TRUE, "PaintRgn failed\n"); + + ok_long(pulDIB[0], 0x00000000); // 000000000 + ok_long(pulDIB[1], 0x000000C0); // 110000000 + ok_long(pulDIB[2], 0x000000F0); // 111110000 + ok_long(pulDIB[3], 0x000000FC); // 111111000 + ok_long(pulDIB[4], 0x0000003F); // 001111110 + ok_long(pulDIB[5], 0x0000003F); // 001111110 + ok_long(pulDIB[6], 0x0000003B); // 001110110 + ok_long(pulDIB[7], 0x00000038); // 001110000 + ok_long(pulDIB[8], 0x00000038); // 001110000 +} + +START_TEST(PaintRgn) +{ + InitStuff(); + Test_PaintRgn(); +} + diff --git a/rostests/apitests/gdi32/init.c b/rostests/apitests/gdi32/init.c index c7b633f70c2..fcac6142d59 100644 --- a/rostests/apitests/gdi32/init.c +++ b/rostests/apitests/gdi32/init.c @@ -9,7 +9,6 @@ HBITMAP ghbmpDIB1, ghbmpDIB4, ghbmpDIB8, ghbmpDIB16, ghbmpDIB24, ghbmpDIB32; HDC ghdcDIB1, ghdcDIB4, ghdcDIB8, ghdcDIB16, ghdcDIB24, ghdcDIB32; PVOID gpvDIB1, gpvDIB4, gpvDIB8, gpvDIB16, gpvDIB24, gpvDIB32; ULONG (*gpDIB32)[8][8]; -PULONG pulDIB4Bits; HPALETTE ghpal; MYPAL gpal = @@ -40,7 +39,7 @@ InitPerBitDepth( struct { BITMAPINFOHEADER bmiHeader; - RGBQUAD bmiColors[256]; + ULONG bmiColors[256]; } bmiBuffer; LPBITMAPINFO pbmi = (LPBITMAPINFO)&bmiBuffer; @@ -66,6 +65,13 @@ InitPerBitDepth( pbmi->bmiHeader.biClrUsed = 0; pbmi->bmiHeader.biClrImportant = 0; + if (cBitsPerPixel == 1) + { + bmiBuffer.bmiColors[0] = 0; + bmiBuffer.bmiColors[1] = 0xFFFFFF; + pbmi->bmiHeader.biClrUsed = 2; + } + /* Create a compatible DC for the DIB */ *phdcDIB = CreateCompatibleDC(0); if (*phdcDIB == NULL) @@ -110,7 +116,6 @@ BOOL InitStuff(void) } gpDIB32 = gpvDIB32; - pulDIB4Bits = gpvDIB4; return TRUE; } diff --git a/rostests/apitests/gdi32/init.h b/rostests/apitests/gdi32/init.h index 5ca6856e6f4..48d5ce8df78 100644 --- a/rostests/apitests/gdi32/init.h +++ b/rostests/apitests/gdi32/init.h @@ -2,7 +2,7 @@ extern HBITMAP ghbmp1, ghbmp4, ghbmp8, ghbmp16, ghbmp24, ghbmp32; extern HBITMAP ghbmpDIB1, ghbmpDIB4, ghbmpDIB8, ghbmpDIB16, ghbmpDIB24, ghbmpDIB32; extern HDC ghdcDIB1, ghdcDIB4, ghdcDIB8, ghdcDIB16, ghdcDIB24, ghdcDIB32; -extern PVOID pvBits1Bpp, pvBits4Bpp, pvBits8Bpp, pvBits16Bpp, pvBits24Bpp, pvBits32Bpp; +extern PVOID gpvDIB1, gpvDIB4, gpvDIB8, gpvDIB16, gpvDIB24, gpvDIB32; extern HBITMAP ghbmpDIB32; //extern PULONG pulDIB32Bits; diff --git a/rostests/apitests/gdi32/testlist.c b/rostests/apitests/gdi32/testlist.c index 14619b3ac40..55a576c7bda 100644 --- a/rostests/apitests/gdi32/testlist.c +++ b/rostests/apitests/gdi32/testlist.c @@ -27,6 +27,7 @@ extern void func_EnumFontFamilies(void); extern void func_ExcludeClipRect(void); extern void func_ExtCreatePen(void); extern void func_ExtCreateRegion(void); +extern void func_FrameRgn(void); extern void func_GdiConvertBitmap(void); extern void func_GdiConvertBrush(void); extern void func_GdiConvertDC(void); @@ -52,6 +53,8 @@ extern void func_GetTextExtentExPoint(void); extern void func_GetTextFace(void); extern void func_MaskBlt(void); extern void func_OffsetClipRgn(void); +extern void func_OffsetRgn(void); +extern void func_PaintRgn(void); extern void func_PatBlt(void); extern void func_Rectangle(void); extern void func_RealizePalette(void); @@ -92,6 +95,7 @@ const struct test winetest_testlist[] = { "ExcludeClipRect", func_ExcludeClipRect }, { "ExtCreatePen", func_ExtCreatePen }, { "ExtCreateRegion", func_ExtCreateRegion }, + { "FrameRgn", func_FrameRgn }, { "GdiConvertBitmap", func_GdiConvertBitmap }, { "GdiConvertBrush", func_GdiConvertBrush }, { "GdiConvertDC", func_GdiConvertDC }, @@ -117,6 +121,8 @@ const struct test winetest_testlist[] = { "GetTextFace", func_GetTextFace }, { "MaskBlt", func_MaskBlt }, { "OffsetClipRgn", func_OffsetClipRgn }, + { "OffsetRgn", func_OffsetRgn }, + { "PaintRgn", func_PaintRgn }, { "PatBlt", func_PatBlt }, { "Rectangle", func_Rectangle }, { "RealizePalette", func_RealizePalette },