diff --git a/rostests/winetests/gdiplus/region.c b/rostests/winetests/gdiplus/region.c index d48554c48b6..efd2115df1a 100644 --- a/rostests/winetests/gdiplus/region.c +++ b/rostests/winetests/gdiplus/region.c @@ -364,7 +364,9 @@ static void test_getregiondata(void) expect_dword(buf + 5, 12); expect_magic((DWORD*)(buf + 6)); expect_dword(buf + 7, 0); - expect_dword(buf + 8, 0x00004000); + /* flags 0x4000 means its a path of shorts instead of FLOAT */ + ok((*(buf + 8) & (~ 0x00004000)) == 0x00000000, + "expected 00000000 got %08x\n", *(buf + 8) & (~ 0x00004000)); status = GdipDeleteRegion(region); expect(Ok, status); @@ -503,7 +505,8 @@ static void test_getregiondata(void) expect_float(buf + 25, 50); expect_float(buf + 26, 70.2); expect_dword(buf + 27, 0x01010100); - expect_dword(buf + 28, 0x00000101); + ok(*(buf + 28) == 0x00000101 || *(buf + 28) == 0x43050101 /* Win 7 */, + "expected 00000101 or 43050101 got %08x\n", *(buf + 28)); status = GdipDeletePath(path); expect(Ok, status); @@ -704,7 +707,7 @@ static void test_combinereplace(void) static void test_fromhrgn(void) { GpStatus status; - GpRegion *region; + GpRegion *region = (GpRegion*)0xabcdef01; HRGN hrgn; UINT needed; DWORD buf[220]; @@ -720,6 +723,7 @@ static void test_fromhrgn(void) expect(InvalidParameter, status); status = GdipCreateRegionHrgn((HRGN)0xdeadbeef, ®ion); expect(InvalidParameter, status); + ok(region == (GpRegion*)0xabcdef01, "Expected region not to be created\n"); /* empty rectangle */ hrgn = CreateRectRgn(0, 0, 0, 0); @@ -788,21 +792,19 @@ static void test_fromhrgn(void) /* ellipse */ hrgn = CreateEllipticRgn(0, 0, 100, 10); status = GdipCreateRegionHrgn(hrgn, ®ion); - todo_wine expect(Ok, status); + expect(Ok, status); status = GdipGetRegionDataSize(region, &needed); -todo_wine{ expect(Ok, status); ok(needed == 216 || needed == 196, /* win98 */ "Got %.8x\n", needed); -} + status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed); - todo_wine expect(Ok, status); + expect(Ok, status); if(status == Ok && needed == 216) /* Don't try to test win98 layout */ { -todo_wine{ expect(Ok, status); expect(216, needed); expect_dword(buf, 208); @@ -812,8 +814,7 @@ todo_wine{ expect_dword(buf + 5, 0x000000C0); expect_magic((DWORD*)(buf + 6)); expect_dword(buf + 7, 0x00000024); - expect_dword(buf + 8, 0x00006000); /* ?? */ -} + todo_wine expect_dword(buf + 8, 0x00006000); /* ?? */ } GdipDeleteRegion(region); @@ -1176,6 +1177,29 @@ static void test_getbounds(void) ok(rectf.Width == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width); ok(rectf.Height == 100.0, "Expected height = 0.0, got %.2f\n", rectf.Height); + /* the world and page transforms are ignored */ + GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend); + GdipSetPageUnit(graphics, UnitInch); + GdipSetPageScale(graphics, 2.0); + status = GdipGetRegionBounds(region, graphics, &rectf); + ok(status == Ok, "status %08x\n", status); + ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X); + ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y); + ok(rectf.Width == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width); + + rectf.X = 10.0; rectf.Y = 0.0; + rectf.Width = rectf.Height = 100.0; + status = GdipCombineRegionRect(region, &rectf, CombineModeReplace); + ok(status == Ok, "status %08x\n", status); + rectf.X = rectf.Y = 0.0; + rectf.Height = rectf.Width = 0.0; + status = GdipGetRegionBounds(region, graphics, &rectf); + ok(status == Ok, "status %08x\n", status); + ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X); + ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y); + ok(rectf.Width == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width); + ok(rectf.Height == 100.0, "Expected height = 0.0, got %.2f\n", rectf.Height); + status = GdipDeleteRegion(region); ok(status == Ok, "status %08x\n", status); status = GdipDeleteGraphics(graphics); @@ -1183,6 +1207,413 @@ static void test_getbounds(void) ReleaseDC(0, hdc); } +static void test_isvisiblepoint(void) +{ + HDC hdc = GetDC(0); + GpGraphics* graphics; + GpRegion* region; + GpPath* path; + GpRectF rectf; + GpStatus status; + BOOL res; + REAL x, y; + + status = GdipCreateFromHDC(hdc, &graphics); + expect(Ok, status); + + status = GdipCreateRegion(®ion); + expect(Ok, status); + + /* null parameters */ + status = GdipIsVisibleRegionPoint(NULL, 0, 0, graphics, &res); + expect(InvalidParameter, status); + status = GdipIsVisibleRegionPointI(NULL, 0, 0, graphics, &res); + expect(InvalidParameter, status); + + status = GdipIsVisibleRegionPoint(region, 0, 0, NULL, &res); + expect(Ok, status); + status = GdipIsVisibleRegionPointI(region, 0, 0, NULL, &res); + expect(Ok, status); + + status = GdipIsVisibleRegionPoint(region, 0, 0, graphics, NULL); + expect(InvalidParameter, status); + status = GdipIsVisibleRegionPointI(region, 0, 0, graphics, NULL); + expect(InvalidParameter, status); + + /* infinite region */ + status = GdipIsInfiniteRegion(region, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Region should be infinite\n"); + + x = 10; + y = 10; + status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y); + status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y); + + x = -10; + y = -10; + status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y); + status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y); + + /* rectangular region */ + rectf.X = 10; + rectf.Y = 20; + rectf.Width = 30; + rectf.Height = 40; + + status = GdipCombineRegionRect(region, &rectf, CombineModeReplace); + expect(Ok, status); + + x = 0; + y = 0; + status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y); + status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y); + + x = 9; + y = 19; + status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%.2f, %.2f) to be visible\n", x, y); + + x = 9.25; + y = 19.25; + status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%.2f, %.2f) to be visible\n", x, y); + + x = 9.5; + y = 19.5; + status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y); + + x = 9.75; + y = 19.75; + status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y); + + x = 10; + y = 20; + status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y); + + x = 25; + y = 40; + status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y); + status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y); + + x = 40; + y = 60; + status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y); + status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y); + + /* translate into the center of the rectangle */ + status = GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend); + expect(Ok, status); + + /* native ignores the world transform, so treat these as if + * no transform exists */ + x = -20; + y = -30; + status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y); + status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y); + + x = 0; + y = 0; + status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y); + status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y); + + x = 25; + y = 40; + status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y); + status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y); + + /* translate back to origin */ + status = GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend); + expect(Ok, status); + + /* region from path */ + status = GdipCreatePath(FillModeAlternate, &path); + expect(Ok, status); + + status = GdipAddPathEllipse(path, 10, 20, 30, 40); + expect(Ok, status); + + status = GdipCombineRegionPath(region, path, CombineModeReplace); + expect(Ok, status); + + x = 11; + y = 21; + status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y); + status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y); + + x = 25; + y = 40; + status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y); + status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y); + + x = 40; + y = 60; + status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y); + status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y); + + GdipDeletePath(path); + + GdipDeleteRegion(region); + GdipDeleteGraphics(graphics); + ReleaseDC(0, hdc); +} + +static void test_isvisiblerect(void) +{ + HDC hdc = GetDC(0); + GpGraphics* graphics; + GpRegion* region; + GpPath* path; + GpRectF rectf; + GpStatus status; + BOOL res; + REAL x, y, w, h; + + status = GdipCreateFromHDC(hdc, &graphics); + expect(Ok, status); + + status = GdipCreateRegion(®ion); + expect(Ok, status); + + /* null parameters */ + status = GdipIsVisibleRegionRect(NULL, 0, 0, 0, 0, graphics, &res); + expect(InvalidParameter, status); + status = GdipIsVisibleRegionRectI(NULL, 0, 0, 0, 0, graphics, &res); + expect(InvalidParameter, status); + + status = GdipIsVisibleRegionRect(region, 0, 0, 0, 0, NULL, &res); + expect(Ok, status); + status = GdipIsVisibleRegionRectI(region, 0, 0, 0, 0, NULL, &res); + expect(Ok, status); + + status = GdipIsVisibleRegionRect(region, 0, 0, 0, 0, graphics, NULL); + expect(InvalidParameter, status); + status = GdipIsVisibleRegionRectI(region, 0, 0, 0, 0, graphics, NULL); + expect(InvalidParameter, status); + + /* infinite region */ + status = GdipIsInfiniteRegion(region, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Region should be infinite\n"); + + x = 10; w = 10; + y = 10; h = 10; + status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h); + + x = -10; w = 5; + y = -10; h = 5; + status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h); + + /* rectangular region */ + rectf.X = 10; + rectf.Y = 20; + rectf.Width = 30; + rectf.Height = 40; + + status = GdipCombineRegionRect(region, &rectf, CombineModeIntersect); + expect(Ok, status); + + /* entirely within the region */ + x = 11; w = 10; + y = 12; h = 10; + status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h); + status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h); + + /* entirely outside of the region */ + x = 0; w = 5; + y = 0; h = 5; + status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h); + status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h); + + /* corner cases */ + x = 0; w = 10; + y = 0; h = 20; + status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h); + + x = 0; w = 10.25; + y = 0; h = 20.25; + status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h); + + x = 39; w = 10; + y = 59; h = 10; + status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h); + + x = 39.25; w = 10; + y = 59.25; h = 10; + status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h); + + /* corners outside, but some intersection */ + x = 0; w = 100; + y = 0; h = 100; + status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h); + + x = 0; w = 100; + y = 0; h = 40; + status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h); + + x = 0; w = 25; + y = 0; h = 100; + status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h); + + /* translate into the center of the rectangle */ + status = GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend); + expect(Ok, status); + + /* native ignores the world transform, so treat these as if + * no transform exists */ + x = 0; w = 5; + y = 0; h = 5; + status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h); + status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h); + + x = 11; w = 10; + y = 12; h = 10; + status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h); + status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h); + + /* translate back to origin */ + status = GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend); + expect(Ok, status); + + /* region from path */ + status = GdipCreatePath(FillModeAlternate, &path); + expect(Ok, status); + + status = GdipAddPathEllipse(path, 10, 20, 30, 40); + expect(Ok, status); + + status = GdipCombineRegionPath(region, path, CombineModeReplace); + expect(Ok, status); + + x = 0; w = 12; + y = 0; h = 22; + status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h); + status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h); + + x = 0; w = 25; + y = 0; h = 40; + status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h); + status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h); + + x = 38; w = 10; + y = 55; h = 10; + status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h); + status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res); + expect(Ok, status); + ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h); + + x = 0; w = 100; + y = 0; h = 100; + status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h); + status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res); + expect(Ok, status); + ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h); + + GdipDeletePath(path); + + GdipDeleteRegion(region); + GdipDeleteGraphics(graphics); + ReleaseDC(0, hdc); +} + START_TEST(region) { struct GdiplusStartupInput gdiplusStartupInput; @@ -1204,6 +1635,8 @@ START_TEST(region) test_isequal(); test_translate(); test_getbounds(); + test_isvisiblepoint(); + test_isvisiblerect(); GdiplusShutdown(gdiplusToken); }