diff --git a/rostests/apitests/gdi32/CMakeLists.txt b/rostests/apitests/gdi32/CMakeLists.txt index f39f5d15975..348ab39e3b0 100644 --- a/rostests/apitests/gdi32/CMakeLists.txt +++ b/rostests/apitests/gdi32/CMakeLists.txt @@ -12,6 +12,7 @@ list(APPEND SOURCE CreateBitmapIndirect.c CreateCompatibleDC.c CreateDIBitmap.c + CreateDIBPatternBrush CreateFont.c CreateFontIndirect.c CreateIconIndirect.c @@ -57,6 +58,7 @@ list(APPEND SOURCE SetSysColors.c SetWindowExtEx.c SetWorldTransform.c + init.c testlist.c) add_executable(gdi32_apitest ${SOURCE}) diff --git a/rostests/apitests/gdi32/CreateDIBPatternBrush.c b/rostests/apitests/gdi32/CreateDIBPatternBrush.c new file mode 100644 index 00000000000..49a882bdd85 --- /dev/null +++ b/rostests/apitests/gdi32/CreateDIBPatternBrush.c @@ -0,0 +1,147 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: GPL - See COPYING in the top level directory + * PURPOSE: Test for CreateDIBPatternBrush + * PROGRAMMERS: Timo Kreuzer + */ + +#include +#include +#include +#include "init.h" + + +void Test_CreateDIBPatternBrush() +{ + +} + +void Test_CreateDIBPatternBrushPt() +{ + struct + { + BITMAPINFOHEADER bmiHeader; + WORD wColors[4]; + BYTE ajBuffer[16]; + } PackedDIB = + { + {sizeof(BITMAPINFOHEADER), 4, -4, 1, 8, BI_RGB, 0, 1, 1, 4, 0}, + {0, 1, 2, 7}, + {0,1,2,3, 1,2,3,0, 2,3,0,1, 3,0,1,2}, + }; + PBITMAPINFO pbmi = (PBITMAPINFO)&PackedDIB; + HBRUSH hbr, hbrOld; + HPALETTE hpalOld; + + SetLastError(0); + ok_hdl(CreateDIBPatternBrushPt(NULL, 0), NULL); + ok_hdl(CreateDIBPatternBrushPt(NULL, DIB_PAL_COLORS), NULL); + ok_hdl(CreateDIBPatternBrushPt(NULL, 2), NULL); + ok_hdl(CreateDIBPatternBrushPt(NULL, 3), NULL); + ok_err(0); + + hbr = CreateDIBPatternBrushPt(&PackedDIB, 0); + ok(hbr != 0, "Expected success\n"); + DeleteObject(hbr); + hbr = CreateDIBPatternBrushPt(&PackedDIB, 2); + ok(hbr != 0, "Expected success\n"); + DeleteObject(hbr); + + SetLastError(0); + hbr = CreateDIBPatternBrushPt(&PackedDIB, 3); + ok(hbr == 0, "Expected failure\n"); + ok_err(ERROR_INVALID_PARAMETER); + SetLastError(0); + hbr = CreateDIBPatternBrushPt(&PackedDIB, 10); + ok(hbr == 0, "Expected failure\n"); + ok_err(ERROR_INVALID_PARAMETER); + + /* Create a DIB brush with palette indices */ + hbr = CreateDIBPatternBrushPt(&PackedDIB, DIB_PAL_COLORS); + ok(hbr != 0, "CreateSolidBrush failed, skipping tests.\n"); + if (!hbr) return; + + /* Select the brush into the dc */ + hbrOld = SelectObject(ghdcDIB32, hbr); + + /* Copy it on the dib section */ + ok_long(PatBlt(ghdcDIB32, 0, 0, 4, 4, PATCOPY), 1); + ok_long(pulDIB32Bits[0], 0x000000); // 0 + ok_long(pulDIB32Bits[1], 0x800000); // 1 + ok_long(pulDIB32Bits[2], 0x008000); // 2 + ok_long(pulDIB32Bits[3], 0xc0c0c0); // 7 + + /* Select a logical palette into the DC */ + hpalOld = SelectPalette(ghdcDIB32, ghpal, FALSE); + ok(hpalOld != 0, "Expected success, error %ld\n", GetLastError()); + + /* Copy it on the dib section */ + ok_long(PatBlt(ghdcDIB32, 0, 0, 4, 4, PATCOPY), 1); + ok_long(pulDIB32Bits[0], 0x102030); // 0 + ok_long(pulDIB32Bits[1], 0x203040); // 1 + ok_long(pulDIB32Bits[2], 0x304050); // 2 + ok_long(pulDIB32Bits[3], 0x8090a0); // 7 + + /* Select back old palette and destroy the DIB data */ + SelectPalette(ghdcDIB32, hpalOld, FALSE); + memset(&PackedDIB.ajBuffer, 0x77, 4); + + /* Copy it on the dib section */ + ok_long(PatBlt(ghdcDIB32, 0, 0, 4, 4, PATCOPY), 1); + ok_long(pulDIB32Bits[0], 0x000000); // 0 + ok_long(pulDIB32Bits[1], 0x800000); // 1 + ok_long(pulDIB32Bits[2], 0x008000); // 2 + ok_long(pulDIB32Bits[3], 0xc0c0c0); // 7 + + SelectObject(ghdcDIB32, hbrOld); + DeleteObject(hbr); + + /* Set some different values */ + PackedDIB.ajBuffer[0] = 3; + PackedDIB.ajBuffer[1] = 2; + PackedDIB.ajBuffer[2] = 1; + PackedDIB.ajBuffer[3] = 0; + + /* Create a DIB brush with unkdocumented iUsage == 2 */ + hbr = CreateDIBPatternBrushPt(&PackedDIB, 2); + ok(hbr != 0, "CreateSolidBrush failed, skipping tests.\n"); + if (!hbr) return; + + /* Select the brush into the dc */ + hbrOld = SelectObject(ghdcDIB32, hbr); + ok(hbrOld != 0, "CreateSolidBrush failed, skipping tests.\n"); + + /* Copy it on a dib section */ + memset(pulDIB32Bits, 0x77, 64); + ok_long(PatBlt(ghdcDIB32, 0, 0, 4, 4, PATCOPY), 1); + ok_long(pulDIB32Bits[0], 0x77777777); + ok_long(pulDIB32Bits[1], 0x77777777); + ok_long(pulDIB32Bits[2], 0x77777777); + ok_long(pulDIB32Bits[3], 0x77777777); + + /* Select a logical palette into the DC */ + hpalOld = SelectPalette(ghdcDIB32, ghpal, FALSE); + ok(hpalOld != 0, "Expected success, error %ld\n", GetLastError()); + + /* Copy it on a dib section */ + ok_long(PatBlt(ghdcDIB32, 0, 0, 4, 4, PATCOPY), 1); + ok_long(pulDIB32Bits[0], 0x77777777); + ok_long(pulDIB32Bits[1], 0x77777777); + ok_long(pulDIB32Bits[2], 0x77777777); + ok_long(pulDIB32Bits[3], 0x77777777); + + SelectPalette(ghdcDIB32, hpalOld, FALSE); + SelectObject(ghdcDIB32, hbrOld); + DeleteObject(hbr); + +} + + +START_TEST(CreateDIBPatternBrush) +{ + InitStuff(); + + Test_CreateDIBPatternBrush(); + Test_CreateDIBPatternBrushPt(); +} + diff --git a/rostests/apitests/gdi32/GetObject.c b/rostests/apitests/gdi32/GetObject.c index 5d3b95e90f3..772aca91046 100644 --- a/rostests/apitests/gdi32/GetObject.c +++ b/rostests/apitests/gdi32/GetObject.c @@ -216,7 +216,7 @@ Test_Bitmap(void) void Test_Dibsection(void) { - BITMAPINFO bmi = {{sizeof(BITMAPINFOHEADER), 10, 9, 1, 8, BI_RGB, 0, 10, 10, 0,0}}; + BITMAPINFO bmi = {{sizeof(BITMAPINFOHEADER), 10, 9, 1, 16, BI_RGB, 0, 10, 10, 0,0}}; HBITMAP hBitmap; BITMAP bitmap; DIBSECTION dibsection; @@ -233,25 +233,25 @@ Test_Dibsection(void) ok(GetObjectW((HANDLE)((UINT_PTR)hBitmap & 0x0000ffff), 0, NULL) == sizeof(BITMAP), "\n"); SetLastError(ERROR_SUCCESS); - ok(GetObject(hBitmap, sizeof(DIBSECTION), NULL) == sizeof(BITMAP), "\n"); - ok(GetObject(hBitmap, 0, NULL) == sizeof(BITMAP), "\n"); - ok(GetObject(hBitmap, 5, NULL) == sizeof(BITMAP), "\n"); - ok(GetObject(hBitmap, -5, NULL) == sizeof(BITMAP), "\n"); - ok(GetObject(hBitmap, 0, &dibsection) == 0, "\n"); - ok(GetObject(hBitmap, 5, &dibsection) == 0, "\n"); - ok(GetObject(hBitmap, sizeof(BITMAP), &bitmap) == sizeof(BITMAP), "\n"); - ok(GetObject(hBitmap, sizeof(BITMAP)+2, &bitmap) == sizeof(BITMAP), "\n"); - ok(bitmap.bmType == 0, "\n"); - ok(bitmap.bmWidth == 10, "\n"); - ok(bitmap.bmHeight == 9, "\n"); - ok(bitmap.bmWidthBytes == 12, "\n"); - ok(bitmap.bmPlanes == 1, "\n"); - ok(bitmap.bmBitsPixel == 8, "\n"); + ok_long(GetObject(hBitmap, sizeof(DIBSECTION), NULL), sizeof(BITMAP)); + ok_long(GetObject(hBitmap, 0, NULL), sizeof(BITMAP)); + ok_long(GetObject(hBitmap, 5, NULL), sizeof(BITMAP)); + ok_long(GetObject(hBitmap, -5, NULL), sizeof(BITMAP)); + ok_long(GetObject(hBitmap, 0, &dibsection), 0); + ok_long(GetObject(hBitmap, 5, &dibsection), 0); + ok_long(GetObject(hBitmap, sizeof(BITMAP), &bitmap), sizeof(BITMAP)); + ok_long(GetObject(hBitmap, sizeof(BITMAP)+2, &bitmap), sizeof(BITMAP)); + ok_long(bitmap.bmType, 0); + ok_long(bitmap.bmWidth, 10); + ok_long(bitmap.bmHeight, 9); + ok_long(bitmap.bmWidthBytes, 20); + ok_long(bitmap.bmPlanes, 1); + ok_long(bitmap.bmBitsPixel, 16); ok(bitmap.bmBits == pData, "\n"); - ok(GetObject(hBitmap, sizeof(DIBSECTION), &dibsection) == sizeof(DIBSECTION), "\n"); - ok(GetObject(hBitmap, sizeof(DIBSECTION)+2, &dibsection) == sizeof(DIBSECTION), "\n"); - ok(GetObject(hBitmap, -5, &dibsection) == sizeof(DIBSECTION), "\n"); - ok(GetLastError() == ERROR_SUCCESS, "\n"); + ok_long(GetObject(hBitmap, sizeof(DIBSECTION), &dibsection), sizeof(DIBSECTION)); + ok_long(GetObject(hBitmap, sizeof(DIBSECTION)+2, &dibsection), sizeof(DIBSECTION)); + ok_long(GetObject(hBitmap, -5, &dibsection), sizeof(DIBSECTION)); + ok_err(ERROR_SUCCESS); DeleteObject(hBitmap); ReleaseDC(0, hDC); } @@ -335,6 +335,59 @@ Test_Brush(void) ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError()); } +void +Test_DIBBrush(void) +{ + struct + { + BITMAPINFOHEADER bmiHeader; + WORD wColors[4]; + BYTE jBuffer[16]; + } PackedDIB = + { + {sizeof(BITMAPINFOHEADER), 4, 4, 1, 8, BI_RGB, 0, 1, 1, 4, 0}, + {1, 7, 3, 1}, + {0,1,2,3, 1,2,3,0, 2,3,0,1, 3,0,1,2}, + }; + PBITMAPINFO pbmi = (PBITMAPINFO)&PackedDIB; + LOGBRUSH logbrush; + HBRUSH hBrush; + + /* Create a DIB brush */ + hBrush = CreateDIBPatternBrushPt(&PackedDIB, DIB_PAL_COLORS); + ok(hBrush != 0, "CreateSolidBrush failed, skipping tests.\n"); + if (!hBrush) return; + + FillMemory(&logbrush, sizeof(LOGBRUSH), 0x77); + SetLastError(ERROR_SUCCESS); + + ok_long(GetObject(hBrush, sizeof(LOGBRUSH), &logbrush), sizeof(LOGBRUSH)); + ok_long(logbrush.lbStyle, BS_DIBPATTERN); + ok_long(logbrush.lbColor, 0); + ok_long(logbrush.lbHatch, (ULONG_PTR)&PackedDIB); + + ok_err(ERROR_SUCCESS); + DeleteObject(hBrush); + + + /* Create a DIB brush with undocumented iUsage 2 */ + hBrush = CreateDIBPatternBrushPt(&PackedDIB, 2); + ok(hBrush != 0, "CreateSolidBrush failed, skipping tests.\n"); + if (!hBrush) return; + + FillMemory(&logbrush, sizeof(LOGBRUSH), 0x77); + SetLastError(ERROR_SUCCESS); + + ok_long(GetObject(hBrush, sizeof(LOGBRUSH), &logbrush), sizeof(LOGBRUSH)); + ok_long(logbrush.lbStyle, BS_DIBPATTERN); + ok_long(logbrush.lbColor, 0); + ok_long(logbrush.lbHatch, (ULONG_PTR)&PackedDIB); + + ok_err(ERROR_SUCCESS); + DeleteObject(hBrush); + +} + void Test_Pen(void) { @@ -632,6 +685,7 @@ START_TEST(GetObject) Test_Dibsection(); Test_Palette(); Test_Brush(); + Test_DIBBrush(); Test_Pen(); Test_ExtPen(); // not implemented yet in ROS Test_MetaDC(); diff --git a/rostests/apitests/gdi32/init.c b/rostests/apitests/gdi32/init.c new file mode 100644 index 00000000000..eceec35da93 --- /dev/null +++ b/rostests/apitests/gdi32/init.c @@ -0,0 +1,51 @@ + +#include +#include + +HBITMAP ghbmpDIB32; +HDC ghdcDIB32; +PULONG pulDIB32Bits; +HPALETTE ghpal; + +struct +{ + WORD palVersion; + WORD palNumEntries; + PALETTEENTRY logpalettedata[8]; +} gpal = +{ + 0x300, 8, + { + { 0x10, 0x20, 0x30, PC_NOCOLLAPSE }, + { 0x20, 0x30, 0x40, PC_NOCOLLAPSE }, + { 0x30, 0x40, 0x50, PC_NOCOLLAPSE }, + { 0x40, 0x50, 0x60, PC_NOCOLLAPSE }, + { 0x50, 0x60, 0x70, PC_NOCOLLAPSE }, + { 0x60, 0x70, 0x80, PC_NOCOLLAPSE }, + { 0x70, 0x80, 0x90, PC_NOCOLLAPSE }, + { 0x80, 0x90, 0xA0, PC_NOCOLLAPSE }, + } +}; + +BOOL InitStuff(void) +{ + BITMAPINFO bmi32 = + {{sizeof(BITMAPINFOHEADER), 4, -4, 1, 32, BI_RGB, 0, 1, 1, 0, 0}, {0}}; + + ghdcDIB32 = CreateCompatibleDC(0); + + ghbmpDIB32 = CreateDIBSection(ghdcDIB32, &bmi32, DIB_PAL_COLORS, (PVOID*)&pulDIB32Bits, 0, 0 ); + if (!ghbmpDIB32) return FALSE; + + SelectObject(ghdcDIB32, ghbmpDIB32); + + /* Initialize a logical palette */ + ghpal = CreatePalette((LOGPALETTE*)&gpal); + if (!ghpal) + { + printf("failed to create a palette \n"); + return FALSE; + } + + return TRUE; +} diff --git a/rostests/apitests/gdi32/init.h b/rostests/apitests/gdi32/init.h new file mode 100644 index 00000000000..ad0f4025c77 --- /dev/null +++ b/rostests/apitests/gdi32/init.h @@ -0,0 +1,13 @@ + +extern HBITMAP ghbmpDIB32; +extern HDC ghdcDIB32; +extern PULONG pulDIB32Bits; +extern HPALETTE ghpal; +extern struct +{ + LOGPALETTE logpal; + PALETTEENTRY logpalettedata[8]; +} gpal; + +BOOL InitStuff(void); + diff --git a/rostests/apitests/gdi32/testlist.c b/rostests/apitests/gdi32/testlist.c index 1a15fbfaa1a..9132a883974 100644 --- a/rostests/apitests/gdi32/testlist.c +++ b/rostests/apitests/gdi32/testlist.c @@ -14,6 +14,7 @@ extern void func_CreateBitmap(void); extern void func_CreateBitmapIndirect(void); extern void func_CreateCompatibleDC(void); extern void func_CreateDIBitmap(void); +extern void func_CreateDIBPatternBrush(void); extern void func_CreateFont(void); extern void func_CreateFontIndirect(void); extern void func_CreateIconIndirect(void); @@ -71,6 +72,7 @@ const struct test winetest_testlist[] = { "CreateBitmapIndirect", func_CreateBitmapIndirect }, { "CreateCompatibleDC", func_CreateCompatibleDC }, { "CreateDIBitmap", func_CreateDIBitmap }, + { "CreateDIBPatternBrush", func_CreateDIBPatternBrush }, { "CreateFont", func_CreateFont }, { "CreateFontIndirect", func_CreateFontIndirect }, { "CreateIconIndirect", func_CreateFontIndirect },