[PATCH 1/2] user32/tests: Add tests for monochrome icons
Fabian Maurer
dark.shadow4 at web.de
Sat Aug 21 08:09:09 CDT 2021
Signed-off-by: Fabian Maurer <dark.shadow4 at web.de>
---
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 f84312f3ea2..dbe2b3a57f0 100644
--- a/dlls/user32/tests/cursoricon.c
+++ b/dlls/user32/tests/cursoricon.c
@@ -3094,6 +3094,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" );
@@ -3130,6 +3213,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
More information about the wine-devel
mailing list