From 3bfeaa9a0974aae86f16cb8910759a5ab61e3b24 Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Mon, 10 Oct 2005 19:53:22 +0000 Subject: [PATCH] GetRandomRgn only returns the SYSRGN in screen coordinates. Add a bunch of tests for GetRandomRgn. --- dlls/gdi/clipping.c | 4 +- dlls/gdi/tests/.cvsignore | 1 + dlls/gdi/tests/Makefile.in | 1 + dlls/gdi/tests/clipping.c | 131 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 dlls/gdi/tests/clipping.c diff --git a/dlls/gdi/clipping.c b/dlls/gdi/clipping.c index 0f69be7c725..19e0ad2e173 100644 --- a/dlls/gdi/clipping.c +++ b/dlls/gdi/clipping.c @@ -578,8 +578,8 @@ INT WINAPI GetRandomRgn(HDC hDC, HRGN hRgn, INT iCode) if (rgn) CombineRgn( hRgn, rgn, 0, RGN_COPY ); GDI_ReleaseObj( hDC ); - /* On Windows NT/2000, the region returned is in screen coordinates */ - if (!(GetVersion() & 0x80000000)) + /* On Windows NT/2000, the SYSRGN returned is in screen coordinates */ + if (iCode == SYSRGN && !(GetVersion() & 0x80000000)) { POINT org; GetDCOrgEx( hDC, &org ); diff --git a/dlls/gdi/tests/.cvsignore b/dlls/gdi/tests/.cvsignore index 115f75c3077..47ec78485ec 100644 --- a/dlls/gdi/tests/.cvsignore +++ b/dlls/gdi/tests/.cvsignore @@ -1,6 +1,7 @@ Makefile bitmap.ok brush.ok +clipping.ok gdiobj.ok generated.ok metafile.ok diff --git a/dlls/gdi/tests/Makefile.in b/dlls/gdi/tests/Makefile.in index 2e2a05436a3..ce36808a21e 100644 --- a/dlls/gdi/tests/Makefile.in +++ b/dlls/gdi/tests/Makefile.in @@ -8,6 +8,7 @@ IMPORTS = user32 gdi32 kernel32 CTESTS = \ bitmap.c \ brush.c \ + clipping.c \ gdiobj.c \ generated.c \ metafile.c \ diff --git a/dlls/gdi/tests/clipping.c b/dlls/gdi/tests/clipping.c new file mode 100644 index 00000000000..6156feecf8f --- /dev/null +++ b/dlls/gdi/tests/clipping.c @@ -0,0 +1,131 @@ +/* + * Unit test suite for clipping + * + * Copyright 2005 Huw Davies + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "wine/test.h" +#include "winbase.h" +#include "wingdi.h" +#include "winuser.h" + +static void test_GetRandomRgn(void) +{ + HWND hwnd = CreateWindowExA(0,"BUTTON","test",WS_VISIBLE|WS_POPUP,0,0,100,100,GetDesktopWindow(),0,0,0); + HDC hdc; + HRGN hrgn = CreateRectRgn(0, 0, 0, 0); + int ret; + RECT rc, rc2; + RECT ret_rc, window_rc; + + ok( hwnd != 0, "CreateWindow failed\n" ); + + SetRect(&window_rc, 400, 300, 500, 400); + MoveWindow(hwnd, window_rc.left, window_rc.top, window_rc.right - window_rc.left, window_rc.bottom - window_rc.top, FALSE); + hdc = GetDC(hwnd); + + ret = GetRandomRgn(hdc, hrgn, 1); + ok(ret == 0, "GetRandomRgn rets %d\n", ret); + ret = GetRandomRgn(hdc, hrgn, 2); + ok(ret == 0, "GetRandomRgn rets %d\n", ret); + ret = GetRandomRgn(hdc, hrgn, 3); + ok(ret == 0, "GetRandomRgn rets %d\n", ret); + + /* Set a clip region */ + SetRect(&rc, 20, 20, 80, 80); + IntersectClipRect(hdc, rc.left, rc.top, rc.right, rc.bottom); + + ret = GetRandomRgn(hdc, hrgn, 1); + ok(ret != 0, "GetRandomRgn rets %d\n", ret); + GetRgnBox(hrgn, &ret_rc); + ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %ld,%ld - %ld,%ld\n", + ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom); + + ret = GetRandomRgn(hdc, hrgn, 2); + ok(ret == 0, "GetRandomRgn rets %d\n", ret); + + todo_wine + { + ret = GetRandomRgn(hdc, hrgn, 3); + ok(ret != 0, "GetRandomRgn rets %d\n", ret); + } + GetRgnBox(hrgn, &ret_rc); + ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %ld,%ld - %ld,%ld\n", + ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom); + + /* Move the clip to the meta and clear the clip */ + SetMetaRgn(hdc); + + ret = GetRandomRgn(hdc, hrgn, 1); + ok(ret == 0, "GetRandomRgn rets %d\n", ret); + ret = GetRandomRgn(hdc, hrgn, 2); + ok(ret != 0, "GetRandomRgn rets %d\n", ret); + GetRgnBox(hrgn, &ret_rc); + ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %ld,%ld - %ld,%ld\n", + ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom); + + todo_wine + { + ret = GetRandomRgn(hdc, hrgn, 3); + ok(ret != 0, "GetRandomRgn rets %d\n", ret); + } + GetRgnBox(hrgn, &ret_rc); + ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %ld,%ld - %ld,%ld\n", + ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom); + + /* Set a new clip (still got the meta) */ + SetRect(&rc2, 10, 30, 70, 90); + IntersectClipRect(hdc, rc2.left, rc2.top, rc2.right, rc2.bottom); + + ret = GetRandomRgn(hdc, hrgn, 1); + ok(ret != 0, "GetRandomRgn rets %d\n", ret); + GetRgnBox(hrgn, &ret_rc); + ok(EqualRect(&rc2, &ret_rc), "GetRandomRgn %ld,%ld - %ld,%ld\n", + ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom); + + ret = GetRandomRgn(hdc, hrgn, 2); + ok(ret != 0, "GetRandomRgn rets %d\n", ret); + GetRgnBox(hrgn, &ret_rc); + ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %ld,%ld - %ld,%ld\n", + ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom); + + IntersectRect(&rc2, &rc, &rc2); + + ret = GetRandomRgn(hdc, hrgn, 3); + ok(ret != 0, "GetRandomRgn rets %d\n", ret); + GetRgnBox(hrgn, &ret_rc); + ok(EqualRect(&rc2, &ret_rc), "GetRandomRgn %ld,%ld - %ld,%ld\n", + ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom); + + + ret = GetRandomRgn(hdc, hrgn, SYSRGN); + ok(ret != 0, "GetRandomRgn rets %d\n", ret); + GetRgnBox(hrgn, &ret_rc); + if(GetVersion() & 0x80000000) + OffsetRect(&window_rc, -window_rc.left, -window_rc.top); + ok(EqualRect(&window_rc, &ret_rc), "GetRandomRgn %ld,%ld - %ld,%ld\n", + ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom); + + DeleteObject(hrgn); + ReleaseDC(hwnd, hdc); + DestroyWindow(hwnd); +} + +START_TEST(clipping) +{ + test_GetRandomRgn(); +} -- 2.11.4.GIT