Andrew Nguyen : gdi32: Fix parameter handling of GetBoundsRect.

Alexandre Julliard julliard at winehq.org
Tue Jun 1 12:12:45 CDT 2010


Module: wine
Branch: master
Commit: 9d5a848df103e2cb594a259e31897d5f355595bd
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=9d5a848df103e2cb594a259e31897d5f355595bd

Author: Andrew Nguyen <anguyen at codeweavers.com>
Date:   Tue Jun  1 08:03:24 2010 -0500

gdi32: Fix parameter handling of GetBoundsRect.

---

 dlls/gdi32/dc.c       |   10 +++++--
 dlls/gdi32/tests/dc.c |   63 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+), 3 deletions(-)

diff --git a/dlls/gdi32/dc.c b/dlls/gdi32/dc.c
index 5f304a2..f3a62bd 100644
--- a/dlls/gdi32/dc.c
+++ b/dlls/gdi32/dc.c
@@ -1534,9 +1534,13 @@ UINT WINAPI GetBoundsRect(HDC hdc, LPRECT rect, UINT flags)
 
     if ( !dc ) return 0;
 
-    if (rect) *rect = dc->BoundsRect;
-
-    ret = ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
+    if (rect)
+    {
+        *rect = dc->BoundsRect;
+        ret = ((dc->flags & DC_BOUNDS_SET) ? DCB_SET : DCB_RESET);
+    }
+    else
+        ret = 0;
 
     if (flags & DCB_RESET)
     {
diff --git a/dlls/gdi32/tests/dc.c b/dlls/gdi32/tests/dc.c
index 687a98f..b081376 100644
--- a/dlls/gdi32/tests/dc.c
+++ b/dlls/gdi32/tests/dc.c
@@ -494,6 +494,68 @@ todo_wine
     ok(ret, "UnregisterClassA failed\n");
 }
 
+static void test_boundsrect_invalid(void)
+{
+    HDC hdc;
+    RECT rect, expect;
+    UINT ret;
+
+    hdc = GetDC(NULL);
+    ok(hdc != NULL, "GetDC failed\n");
+
+    ret = GetBoundsRect(hdc, NULL, 0);
+    ok(ret == 0 ||
+       broken(ret == DCB_RESET), /* Win9x */
+       "Expected GetBoundsRect to return 0, got %u\n", ret);
+
+    ret = GetBoundsRect(hdc, NULL, ~0U);
+    ok(ret == 0 ||
+       broken(ret == DCB_RESET), /* Win9x */
+       "Expected GetBoundsRect to return 0, got %u\n", ret);
+
+    if (GetBoundsRect(hdc, NULL, 0) == DCB_RESET)
+        win_skip("Win9x fails catastrophically with first GetBoundsRect call\n");
+    else
+    {
+        /* Test parameter handling order. */
+        SetRect(&rect, 0, 0, 50, 50);
+        ret = SetBoundsRect(hdc, &rect, DCB_SET);
+        ok(ret & DCB_RESET,
+           "Expected return flag DCB_RESET to be set, got %u\n", ret);
+
+        ret = GetBoundsRect(hdc, NULL, DCB_RESET);
+        ok(ret == 0,
+           "Expected GetBoundsRect to return 0, got %u\n", ret);
+
+        ret = GetBoundsRect(hdc, &rect, 0);
+        ok(ret == DCB_RESET,
+           "Expected GetBoundsRect to return DCB_RESET, got %u\n", ret);
+        SetRect(&expect, 0, 0, 0, 0);
+        ok(EqualRect(&rect, &expect),
+           "Expected output rectangle (0,0)-(0,0), got (%d,%d)-(%d,%d)\n",
+           rect.left, rect.top, rect.right, rect.bottom);
+    }
+
+    if (GetBoundsRect(hdc, NULL, 0) == DCB_RESET)
+        win_skip("Win9x fails catastrophically with NULL device context parameter\n");
+    else
+    {
+        ret = GetBoundsRect(NULL, NULL, 0);
+        ok(ret == 0, "Expected GetBoundsRect to return 0, got %u\n", ret);
+
+        ret = GetBoundsRect(NULL, NULL, ~0U);
+        ok(ret == 0, "Expected GetBoundsRect to return 0, got %u\n", ret);
+
+        ret = SetBoundsRect(NULL, NULL, 0);
+        ok(ret == 0, "Expected SetBoundsRect to return 0, got %u\n", ret);
+
+        ret = SetBoundsRect(NULL, NULL, ~0U);
+        ok(ret == 0, "Expected SetBoundsRect to return 0, got %u\n", ret);
+    }
+
+    DeleteDC(hdc);
+}
+
 START_TEST(dc)
 {
     test_savedc();
@@ -502,4 +564,5 @@ START_TEST(dc)
     test_CreateCompatibleDC();
     test_DC_bitmap();
     test_DeleteDC();
+    test_boundsrect_invalid();
 }




More information about the wine-cvs mailing list