From: Fabian Maurer Subject: [PATCH v3 1/3] user32/tests: Add tests for monochrome icons Message-Id: <20210911183947.66609-1-dark.shadow4@web.de> Date: Sat, 11 Sep 2021 20:39:45 +0200 Signed-off-by: Fabian Maurer --- dlls/user32/tests/cursoricon.c | 84 ++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/dlls/user32/tests/cursoricon.c b/dlls/user32/tests/cursoricon.c index 33ca2e3cb63..1f9a81e6d0a 100644 --- a/dlls/user32/tests/cursoricon.c +++ b/dlls/user32/tests/cursoricon.c @@ -3096,6 +3096,89 @@ static void test_copy_image(void) } } +/* The test the logic for the same function in user32 */ +static HBITMAP create_masked_bitmap( int width, int height, const void *and, const void *xor ) +{ + HDC dc = CreateCompatibleDC( 0 ); + HBITMAP bitmap; + int line_size = width/8; + const char* and2 = (const char*)and; + const char* xor2 = (const char*)xor; + char buffer[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 2] = {0}; + + BITMAPINFO *bitmap_info = (BITMAPINFO*)buffer; + bitmap_info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + bitmap_info->bmiHeader.biWidth = width; + bitmap_info->bmiHeader.biHeight = height * 2; + bitmap_info->bmiHeader.biPlanes = 1; + bitmap_info->bmiHeader.biBitCount = 1; + bitmap_info->bmiColors[1].rgbRed = 255; + bitmap_info->bmiColors[1].rgbGreen = 255; + bitmap_info->bmiColors[1].rgbBlue = 255; + + bitmap = CreateBitmap( width, height * 2, 1, 1, NULL ); + + for (int i = 0; i < height; i++) + { + SetDIBits( dc, bitmap, height - i - 1, 1, &xor2[i*line_size], bitmap_info, FALSE ); + SetDIBits( dc, bitmap, 2*height - i - 1, 1, &and2[i*line_size], bitmap_info, FALSE ); + } + DeleteDC( dc ); + return bitmap; +} + +static void check_monochrome_icon(HICON icon, int draw_flag, int line, BOOL todo) +{ + HDC dc = CreateCompatibleDC(0); + HBITMAP canvas = CreateCompatibleBitmap(dc, 32, 32); + + SelectObject(dc, canvas); + + DrawIconEx(dc, 0, 0, icon, 16, 16, 0, NULL, draw_flag); + + for (int i = 0; i < 16; i++) + { + COLORREF color = GetPixel(dc, i, 8); + int expect = i % 2 == 0 ? 0 : 0xFFFFFF; + todo_wine_if(todo && (i%2 != 0)) + ok_(__FILE__,line)(color == expect, "At index %d got %x\n", i, color); + } + DeleteObject(canvas); + DeleteDC(dc); +} + +static void test_monochrome_icon_creation(void) +{ + HCURSOR cursor; + HICON icon; + ICONINFO iconinfo = {0}; + static const unsigned char monochrome_bits[] = + { + 0xFF, 0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x55, 0x55, 0x00, 0x00, 0xAA, 0xAA, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0xAA, 0xAA, 0x00, 0x00, + 0x55, 0x55, 0x00, 0x00, 0xAA, 0xAA, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + }; + + iconinfo.fIcon = 1; + iconinfo.hbmMask = create_masked_bitmap(16, 16, monochrome_bits, &monochrome_bits[32]); + + cursor = CreateCursor(0, 8, 8, 16, 16, monochrome_bits, &monochrome_bits[32]); + ok(cursor != NULL, "CreateCursor failed\n"); + check_monochrome_icon(cursor, DI_NORMAL, __LINE__, TRUE); + DestroyCursor(cursor); + + icon = CreateIcon(0, 16, 16, 1, 1, monochrome_bits, &monochrome_bits[32]); + ok(icon != NULL, "CreateIcon failed\n"); + check_monochrome_icon(icon, DI_NORMAL, __LINE__, TRUE); + DestroyIcon(icon); + + icon = CreateIconIndirect(&iconinfo); + ok(icon != NULL, "CreateIconIndirect failed\n"); + check_monochrome_icon(icon, DI_NORMAL, __LINE__, FALSE); + DestroyIcon(icon); +} + START_TEST(cursoricon) { pGetCursorInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetCursorInfo" ); @@ -3132,6 +3215,7 @@ START_TEST(cursoricon) test_DestroyCursor(); test_PrivateExtractIcons(); test_monochrome_icon(); + test_monochrome_icon_creation(); do_parent(); test_child_process(); finish_child_process(); -- 2.33.0