From dd4901282aeb3406fcc8fda811ad0c269c702708 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Sat, 4 Apr 2015 15:58:18 +0000 Subject: [PATCH] [GDI32_APITEST] Add/fix some tests for CreateDIBPatternBrush, GetDIBits, PatBlt and SetWindowExtEx svn path=/trunk/; revision=67051 --- .../apitests/gdi32/CreateDIBPatternBrush.c | 25 +++++-- rostests/apitests/gdi32/GetDIBits.c | 67 ++++++++++++++++--- rostests/apitests/gdi32/PatBlt.c | 4 ++ rostests/apitests/gdi32/SetWindowExtEx.c | 9 ++- 4 files changed, 90 insertions(+), 15 deletions(-) diff --git a/rostests/apitests/gdi32/CreateDIBPatternBrush.c b/rostests/apitests/gdi32/CreateDIBPatternBrush.c index e2e83861eb4..b1cf27d2f3d 100644 --- a/rostests/apitests/gdi32/CreateDIBPatternBrush.c +++ b/rostests/apitests/gdi32/CreateDIBPatternBrush.c @@ -10,6 +10,9 @@ #include #include "init.h" +/* New color use parameter. See support.microsoft.com/kb/kbview/108497 */ +#define DIB_PAL_INDICES 2 + void Test_CreateDIBPatternBrush() { @@ -30,6 +33,7 @@ void Test_CreateDIBPatternBrushPt() }; HBRUSH hbr, hbrOld; HPALETTE hpalOld; + LOGBRUSH logbrush; SetLastError(0); ok_hdl(CreateDIBPatternBrushPt(NULL, 0), NULL); @@ -59,6 +63,13 @@ void Test_CreateDIBPatternBrushPt() ok(hbr != 0, "CreateDIBPatternBrushPt failed, skipping tests.\n"); if (!hbr) return; + /* Check the logbrush */ + ok(GetObject(hbr, sizeof(logbrush), &logbrush), "GetObject() failed\n"); + ok_int(logbrush.lbStyle, BS_DIBPATTERN); + ok_hex(logbrush.lbColor, 0); + ok(logbrush.lbHatch == (ULONG_PTR)&PackedDIB, + "invalid lbHatch. Got %p, expected %p\n", (PVOID)logbrush.lbHatch, &PackedDIB); + /* Select the brush into the dc */ hbrOld = SelectObject(ghdcDIB32, hbr); @@ -100,11 +111,18 @@ void Test_CreateDIBPatternBrushPt() PackedDIB.ajBuffer[2] = 1; PackedDIB.ajBuffer[3] = 0; - /* Create a DIB brush with unkdocumented iUsage == 2 */ - hbr = CreateDIBPatternBrushPt(&PackedDIB, 2); + /* Create a DIB brush with DIB_PAL_INDICES */ + hbr = CreateDIBPatternBrushPt(&PackedDIB, DIB_PAL_INDICES); ok(hbr != 0, "CreateSolidBrush failed, skipping tests.\n"); if (!hbr) return; + /* Check the logbrush */ + ok(GetObject(hbr, sizeof(logbrush), &logbrush), "GetObject() failed\n"); + ok_int(logbrush.lbStyle, BS_DIBPATTERN); + ok_hex(logbrush.lbColor, 0); + ok(logbrush.lbHatch == (ULONG_PTR)&PackedDIB, + "invalid lbHatch. Got %p, expected %p\n", (PVOID)logbrush.lbHatch, &PackedDIB); + /* Select the brush into the dc */ hbrOld = SelectObject(ghdcDIB32, hbr); ok(hbrOld != 0, "CreateSolidBrush failed, skipping tests.\n"); @@ -155,8 +173,7 @@ void Test_CreateDIBPatternBrushPt_RLE8() /* Create a DIB brush with palette indices */ hbr = CreateDIBPatternBrushPt(&PackedDIB, DIB_PAL_COLORS); - ok(hbr != 0, "CreateDIBPatternBrushPt failed, skipping tests.\n"); - if (!hbr) return; + ok(hbr == 0, "CreateDIBPatternBrushPt should fail.\n"); } diff --git a/rostests/apitests/gdi32/GetDIBits.c b/rostests/apitests/gdi32/GetDIBits.c index 08996a4f0bd..cfc36180705 100644 --- a/rostests/apitests/gdi32/GetDIBits.c +++ b/rostests/apitests/gdi32/GetDIBits.c @@ -271,11 +271,25 @@ void Test_GetDIBits() /* Test with different biBitCount set */ pbi->bmiHeader.biBitCount = 4; - pbi->bmiHeader.biSizeImage = 0; + pbi->bmiHeader.biSizeImage = 1; ok_int(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS), 1); ok_int(pbi->bmiHeader.biSizeImage, 36); ok_int(pbi->bmiHeader.biBitCount, 4); + /* Test with different biBitCount set */ + pbi->bmiHeader.biBitCount = 8; + pbi->bmiHeader.biSizeImage = 1000; + ok_int(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS), 1); + ok_int(pbi->bmiHeader.biSizeImage, 60); + ok_int(pbi->bmiHeader.biBitCount, 8); + + /* Test with invalid biBitCount set */ + pbi->bmiHeader.biBitCount = 123; + pbi->bmiHeader.biSizeImage = -12; + ok_int(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS), 0); + ok_int(pbi->bmiHeader.biSizeImage, -12); + ok_int(pbi->bmiHeader.biBitCount, 123); + /* Set bitmap dimensions */ ok_int(SetBitmapDimensionEx(hbmp, 110, 220, NULL), 1); ZeroMemory(pbi, bisize); @@ -320,16 +334,21 @@ void Test_GetDIBits() ok_int(pbi->bmiHeader.biCompression, 0); ok_int(pbi->bmiHeader.biSizeImage, 0); - /* Get the bitmap bits */ + /* Get the bitmap info */ pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); pbi->bmiHeader.biWidth = 4; pbi->bmiHeader.biHeight = 4; - pbi->bmiHeader.biPlanes = 1; + pbi->bmiHeader.biPlanes = 3; pbi->bmiHeader.biBitCount = 32; pbi->bmiHeader.biCompression = BI_RGB; ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 1); + ok_int(pbi->bmiHeader.biSizeImage, 64); + ok_int(pbi->bmiHeader.biPlanes, 1); pbi->bmiHeader.biWidth = 0; ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0); + pbi->bmiHeader.biWidth = 2; + ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 1); + ok_int(pbi->bmiHeader.biSizeImage, 32); pbi->bmiHeader.biWidth = -3; ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0); pbi->bmiHeader.biWidth = 4; @@ -343,12 +362,24 @@ void Test_GetDIBits() pbi->bmiHeader.biPlanes = 23; ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 1); ok_int(pbi->bmiHeader.biPlanes, 1); + SetLastError(0xdeadbabe); + ok_int(GetDIBits((HDC)0xff00ff00, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0); + ok_err(0x57); + SetLastError(0xdeadbabe); + ok_int(GetDIBits(hdcScreen, (HBITMAP)0xff00ff00, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0); + ok_err(0xdeadbabe); + SetLastError(0xdeadbabe); + ok_int(GetDIBits((HDC)0xff00ff00, (HBITMAP)0xff00ff00, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0); + ok_err(0x57); + SetLastError(0xdeadbabe); + ok_int(GetDIBits(NULL, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0); + ok_err(0x57); + pbi->bmiHeader.biCompression = BI_JPEG; ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0); pbi->bmiHeader.biCompression = BI_PNG; ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0); - /* Get the bitmap bits */ pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); pbi->bmiHeader.biWidth = 4; @@ -364,10 +395,22 @@ void Test_GetDIBits() cjSizeImage = ((pbi->bmiHeader.biWidth * pbi->bmiHeader.biBitCount + 31) / 32) * 4 * pbi->bmiHeader.biHeight; pvBits = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 512); ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 4); + ok_int(pbi->bmiHeader.biSize, sizeof(BITMAPINFOHEADER)); + ok_int(pbi->bmiHeader.biWidth, 4); + ok_int(pbi->bmiHeader.biHeight, 4); + ok_int(pbi->bmiHeader.biPlanes, 1); + ok_int(pbi->bmiHeader.biBitCount, 32); + ok_int(pbi->bmiHeader.biCompression, BI_RGB); + ok_int(pbi->bmiHeader.biSizeImage, 64); + ok_int(pbi->bmiHeader.biXPelsPerMeter, 0); + ok_int(pbi->bmiHeader.biYPelsPerMeter, 0); + ok_int(pbi->bmiHeader.biClrUsed, 0); + ok_int(pbi->bmiHeader.biClrImportant, 0); /* Set biBitCount to 0 */ pbi->bmiHeader.biBitCount = 0; ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 0); + ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, (PVOID)(LONG_PTR)-1, pbi, DIB_RGB_COLORS), 0); ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, NULL, pbi, DIB_RGB_COLORS), 1); ok_int(GetDIBits(NULL, hbmp, 0, 4, NULL, pbi, DIB_RGB_COLORS), 0); @@ -381,6 +424,10 @@ void Test_GetDIBits() pbi->bmiHeader.biWidth = 3; ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 4); + /* Try invalid biBitCount */ + pbi->bmiHeader.biBitCount = 17; + ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 0); + /* Set only biBitCount and pjInit */ ZeroMemory(pbi, bisize); pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); @@ -405,19 +452,19 @@ void Test_GetDIBits() pbi->bmiHeader.biSizeImage = 0; ok_int(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS), 0); + /* Calculate bitmap size and allocate a buffer */ cjSizeImage = ((pbi->bmiHeader.biWidth * pbi->bmiHeader.biBitCount + 31) / 32) * 4 * pbi->bmiHeader.biHeight; + ok_int(cjSizeImage, 20); pvBits = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cjSizeImage); + /* Test using a compatible DC */ hdcMem = CreateCompatibleDC(0); ok(hdcMem != 0, "CreateCompatibleDC failed, skipping tests\n"); if (hdcMem == NULL) return; + ok_int(GetDIBits(hdcMem, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 0); + ok_int(GetDIBits(hdcMem, ghbmpDIB4, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 4); - // FIXME: broken - //ok(SelectObject(hdcMem, ghbmpDIB4) != 0, "Failed to select 4bpp DIB %p into DC %p\n", ghbmpDIB4, hdcMem);; - //ok_int(GetDIBits(hdcMem, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 0); - //ok_int(GetDIBits(hdcMem, ghbmpDIB4, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 3); - - + HeapFree(GetProcessHeap(), 0, pvBits); DeleteDC(hdcMem); ReleaseDC(NULL, hdcScreen); } diff --git a/rostests/apitests/gdi32/PatBlt.c b/rostests/apitests/gdi32/PatBlt.c index c80f519f4a6..a8493775741 100644 --- a/rostests/apitests/gdi32/PatBlt.c +++ b/rostests/apitests/gdi32/PatBlt.c @@ -24,6 +24,10 @@ void Test_PatBlt_Params() ret = PatBlt(hdcTarget, 0, 0, 1, 1, PATCOPY & 0x00FF0000); ok_long(ret, 1); + /* Test a rop that contains arbitrary values outside the operation index */ + ret = PatBlt(hdcTarget, 0, 0, 1, 1, (PATCOPY & 0x00FF0000) | 0xab00cdef); + ok_long(ret, 1); + /* Test an invalid rop */ SetLastError(0); ok_long(PatBlt(hdcTarget, 0, 0, 1, 1, SRCCOPY) , 0); diff --git a/rostests/apitests/gdi32/SetWindowExtEx.c b/rostests/apitests/gdi32/SetWindowExtEx.c index 70f1e55fea7..e17af663420 100644 --- a/rostests/apitests/gdi32/SetWindowExtEx.c +++ b/rostests/apitests/gdi32/SetWindowExtEx.c @@ -96,7 +96,14 @@ void Test_SetWindowExtEx() //pDC_Attr = pEntry->UserData; //ASSERT(pDC_Attr); - /* Test setting it without changing the map mode (MM_TEXT) */ + /* Test setting 0 extents without changing the map mode (MM_TEXT) */ + ret = SetWindowExtEx(hDC, 0, 0, &WindowExt); + TEST(ret == 1); + TEST(WindowExt.cx == 1); + TEST(WindowExt.cy == 1); + + /* Test setting proper extents without changing the map mode (MM_TEXT) */ + WindowExt.cx = WindowExt.cy = 0; ret = SetWindowExtEx(hDC, 10, 20, &WindowExt); TEST(ret == 1); TEST(WindowExt.cx == 1);