[1/2] user32/tests/cursoricon.c: DrawState: New Testcase for correct drawing of Icons (try 2)

Wilfried Pasquazzo wilfried.pasquazzo at gmail.com
Fri Oct 2 15:27:37 CDT 2009


Rewrite of previous patch(es), rebased on current git. See:
http://www.winehq.org/pipermail/wine-patches/2009-October/079305.html and
http://www.winehq.org/pipermail/wine-patches/2009-October/079306.html

The [1/2] can now be commited on its own without breaking anything,
because the relevant test is marked with todo_wine (as suggested by
Nicolas Le Cam's).
The [2/2] will remove the todo and make the size test pass. (This time
for real).

[1/2] New Testcase to check if DrawState() behaves correctly when
drawing Icons (try 2)

affected files: dlls/user32/tests/cursoricon.c

The Testcase does the same, but I've restructured it.

Now it's split into 2 seperate functions and everything
was cleaned up a bit, to make the tests later (when there
will be more) easier to manage. The first "check_DrawState_Size"
will only check if an Icon is drawn in the correct size and
at the correct location. The second "check_DrawState_Color"
will only check if it is drawn with the correct color.

This seperation was neccessary to make working with todo_wine
possible, because previously Icons could be drawn in the correct
color but wrong size, or wrong size but correct color, and therefore
produce successful tests inside todos.

The error messages also got more descriptive and only at most
one is emitted per check.

----

[2/2] Make Wine pass the new Testcase and Fix Regression Bug 20153 (try 2)

affected files: dlls/user32/uitools.c
affected files: dlls/user32/tests/cursoricon.c

I modified the fix slightly by omitting width/height as a
parameter for DrawIconEx completely, because DrawIconEx
does calculate these values on its own anyway.

The fix of course also removes the "todo_wine" in front of the
size-check that is introduced in [1/2].

----

Sorry again for the previous, broken patch.


Wilfried Pasquazzo
-------------- next part --------------
From 740e871c413479f27ab7624186b85824144761a3 Mon Sep 17 00:00:00 2001
From: Wilfried Pasquazzo <wilfried.pasquazzo at gmail.com>
Date: Fri, 2 Oct 2009 21:47:19 +0000
Subject: [PATCH 1/2] Testcase for DrawState with Icons checking for size and colors

---
 dlls/user32/tests/cursoricon.c |  125 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 125 insertions(+), 0 deletions(-)

diff --git a/dlls/user32/tests/cursoricon.c b/dlls/user32/tests/cursoricon.c
index 064f6c7..1019c73 100644
--- a/dlls/user32/tests/cursoricon.c
+++ b/dlls/user32/tests/cursoricon.c
@@ -1229,6 +1229,130 @@ cleanup:
         DeleteDC(hdcDst);
 }
 
+static void check_DrawState_Size(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, HBRUSH hbr, UINT flags, int line)
+{
+    COLORREF result, background;
+    BOOL passed[2];
+    HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
+    background = 0x00FFFFFF;
+    /* Set color of the 2 pixels that will be checked afterwards */
+    SetPixelV(hdc, 0, 0, background);
+    SetPixelV(hdc, 2, 2, background);
+
+    /* Let DrawState calculate the size of the icon (it's 1x1) */
+    DrawState(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 0, 0, (DST_ICON | flags ));
+
+    result = GetPixel(hdc, 0, 0);
+    passed[0] = color_match(result, background);
+    result = GetPixel(hdc, 2, 2);
+    passed[0] = passed[0] & color_match(result, background);
+
+    /* Check if manually specifying the icon size DOESN'T work */
+
+    /* IMPORTANT: For Icons, DrawState wants the size of the source image, not the
+     *            size in which it should be ultimately drawn. Therefore giving
+     *            width/height 2x2 if the icon is only 1x1 pixels in size should
+     *            result in drawing it with size 1x1. The size parameters must be
+     *            ignored if a Icon has to be drawn! */
+    DrawState(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 2, 2, (DST_ICON | flags ));
+
+    result = GetPixel(hdc, 0, 0);
+    passed[1] = color_match(result, background);
+    result = GetPixel(hdc, 2, 2);
+    passed[1] = passed[0] & color_match(result, background);
+    
+    if(!passed[0]&&!passed[1]) 
+        ok (passed[1],
+        "DrawState failed to draw a 1x1 Icon in the correct size, independent of the "
+        "width and height settings passed to it, for Icon with: Overlaying Mask %d on "
+        "Color %06X with flags %08X. Line %d\n",
+        maskvalue, color, (DST_ICON | flags), line);
+    else if(!passed[1])
+        ok (passed[1],
+        "DrawState failed to draw a 1x1 Icon in the correct size, if the width and height "
+        "parameters passed to it are bigger than the real Icon size, for Icon with: Overlaying "
+        "Mask %d on Color %06X with flags %08X. Line %d\n",
+        maskvalue, color, (DST_ICON | flags), line);
+    else
+        ok (passed[0],
+        "DrawState failed to draw a 1x1 Icon in the correct size, if the width and height "
+        "parameters passed to it are 0, for Icon with: Overlaying Mask %d on "
+        "Color %06X with flags %08X. Line %d\n",
+        maskvalue, color, (DST_ICON | flags), line);
+}
+
+static void check_DrawState_Color(HDC hdc, BOOL maskvalue, UINT32 color, int bpp, HBRUSH hbr, UINT flags, 
+                             COLORREF background, COLORREF modern_expected, COLORREF legacy_expected, int line)
+{
+    COLORREF result;
+    HICON hicon = create_test_icon(hdc, 1, 1, bpp, maskvalue, &color, sizeof(color));
+    if (!hicon) return;
+    /* Set color of the pixel that will be checked afterwards */
+    SetPixelV(hdc, 1, 1, background);
+
+    DrawState(hdc, hbr, NULL, (LPARAM) hicon, 0, 1, 1, 0, 0, ( DST_ICON | flags ));
+
+    /* Check the color of the pixel is correct */
+    result = GetPixel(hdc, 1, 1);
+
+    ok (color_match(result, modern_expected) ||         /* Windows 2000 and up */
+        broken(color_match(result, legacy_expected)),   /* Windows NT 4.0, 9X and below */
+        "DrawState drawing Icon with Overlaying Mask %d on Color %06X with flags %08X. "
+        "Expected a close match to %06X (modern) or %06X (legacy). Got %06X from line %d\n",
+        maskvalue, color, (DST_ICON | flags), modern_expected, legacy_expected, result, line);
+}
+
+static void test_DrawState(void)
+{
+    BITMAPINFO bitmapInfo;
+    HDC hdcDst = NULL;
+    HBITMAP bmpDst = NULL;
+    HBITMAP bmpOld = NULL;
+    UINT32 bits = 0;
+
+    hdcDst = CreateCompatibleDC(0);
+    ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
+    if (!hdcDst)
+        return;
+
+    if(GetDeviceCaps(hdcDst, BITSPIXEL) <= 8)
+    {
+        skip("Windows will distort DrawIconEx colors at 8-bpp and less due to palletizing.\n");
+        goto cleanup;
+    }
+
+    memset(&bitmapInfo, 0, sizeof(bitmapInfo));
+    bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+    bitmapInfo.bmiHeader.biWidth = 3;
+    bitmapInfo.bmiHeader.biHeight = 3;
+    bitmapInfo.bmiHeader.biBitCount = 32;
+    bitmapInfo.bmiHeader.biPlanes = 1;
+    bitmapInfo.bmiHeader.biCompression = BI_RGB;
+    bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
+    bmpDst = CreateDIBSection(hdcDst, &bitmapInfo, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
+    ok (bmpDst && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
+    if (!bmpDst || !bits)
+        goto cleanup;
+    bmpOld = SelectObject(hdcDst, bmpDst);
+
+    /* potential flags to test with DrawState are: */
+    /* DSS_DISABLED embosses the icon */
+    /* DSS_MONO draw Icon using a brush as parameter 5 */
+    /* DSS_NORMAL draw Icon without any modifications */
+    /* DSS_UNION draw the Icon dithered */
+
+    todo_wine check_DrawState_Size(hdcDst, FALSE, 0x00A0B0C0, 32, 0, DSS_NORMAL, __LINE__);
+    check_DrawState_Color(hdcDst, FALSE, 0x00A0B0C0, 32, 0, DSS_NORMAL, 0x00FFFFFF, 0x00C0B0A0, 0x00C0B0A0, __LINE__);
+
+cleanup:
+    if(bmpOld)
+        SelectObject(hdcDst, bmpOld);
+    if(bmpDst)
+        DeleteObject(bmpDst);
+    if(hdcDst)
+        DeleteDC(hdcDst);
+}
+
 static void test_DestroyCursor(void)
 {
     static const BYTE bmp_bits[4096];
@@ -1338,6 +1462,7 @@ START_TEST(cursoricon)
     test_CreateIconFromResource();
     test_DrawIcon();
     test_DrawIconEx();
+    test_DrawState();
     test_DestroyCursor();
     do_parent();
     test_child_process();
-- 
1.6.4.4


More information about the wine-patches mailing list