From b3f9d34e0f7432afadb14ce8fe614a4215ff6248 Mon Sep 17 00:00:00 2001 From: Amine Khaldi Date: Wed, 25 Mar 2015 11:51:58 +0000 Subject: [PATCH] [GDIPLUS_WINETEST] Sync with Wine Staging 1.7.37. CORE-9246 svn path=/trunk/; revision=66869 --- rostests/winetests/gdiplus/graphics.c | 58 ++++++++++++++++- rostests/winetests/gdiplus/image.c | 91 ++++++++++++++++++++++++++- rostests/winetests/gdiplus/region.c | 65 +++++++++++++++++++ 3 files changed, 212 insertions(+), 2 deletions(-) diff --git a/rostests/winetests/gdiplus/graphics.c b/rostests/winetests/gdiplus/graphics.c index 79df301e5b0..1eea7728078 100644 --- a/rostests/winetests/gdiplus/graphics.c +++ b/rostests/winetests/gdiplus/graphics.c @@ -34,7 +34,6 @@ #define expect(expected, got) ok((got) == (expected), "Expected %d, got %d\n", (INT)(expected), (INT)(got)) #define expectf_(expected, got, precision) ok(fabs((expected) - (got)) <= (precision), "Expected %f, got %f\n", (expected), (got)) #define expectf(expected, got) expectf_((expected), (got), 0.001) -#define TABLE_LEN (23) static const REAL mm_per_inch = 25.4; static const REAL point_per_inch = 72.0; @@ -3776,6 +3775,7 @@ static void test_font_height_scaling(void) hdc = CreateCompatibleDC(0); status = GdipCreateFromHDC(hdc, &graphics); + expect(Ok, status); status = GdipGetDpiY(graphics, &dpi); expect(Ok, status); @@ -5554,6 +5554,61 @@ static void test_GdipFillRectangles(void) ReleaseDC(hwnd, hdc); } +static void test_GdipGetVisibleClipBounds_memoryDC(void) +{ + HDC hdc,dc; + HBITMAP bmp; + HGDIOBJ old; + RECT rect; + POINT pt; + int width = 0; + int height = 0; + GpGraphics* graphics = NULL; + GpRect boundRect; + GpStatus status; + + ok(GetClientRect(hwnd, &rect), "GetClientRect should have succeeded\n"); + width = rect.right - rect.left; + height = rect.bottom - rect.top; + + dc = GetDC(hwnd); + hdc = CreateCompatibleDC ( dc ); + bmp = CreateCompatibleBitmap ( dc, width, height ); + old = SelectObject (hdc, bmp); + + /*change the window origin is the key test point*/ + SetWindowOrgEx (hdc, rect.left+10, rect.top+10, &pt); + + status = GdipCreateFromHDC(hdc, &graphics); + expect(Ok, status); + + status = GdipGetVisibleClipBoundsI(graphics, &boundRect); + expect(Ok, status); + + ok(boundRect.X==rect.left+10 && + boundRect.Y==rect.top+10 && + boundRect.Width==width && + boundRect.Height==height, "Expected GdipGetVisibleClipBoundsI ok\n"); + + status = GdipSetClipRectI(graphics, 0, 0, width, height, CombineModeReplace); + expect(Ok, status); + + status = GdipGetVisibleClipBoundsI(graphics, &boundRect); + expect(Ok, status); + + ok(boundRect.X==rect.left+10 && + boundRect.Y==rect.top+10 && + boundRect.Width==width-10 && + boundRect.Height==height-10, "Expected GdipGetVisibleClipBoundsI ok\n"); + + GdipDeleteGraphics(graphics); + + SelectObject (hdc, old); + DeleteObject (bmp); + DeleteDC (hdc); + ReleaseDC(hwnd, dc); +} + START_TEST(graphics) { struct GdiplusStartupInput gdiplusStartupInput; @@ -5625,6 +5680,7 @@ START_TEST(graphics) test_alpha_hdc(); test_bitmapfromgraphics(); test_GdipFillRectangles(); + test_GdipGetVisibleClipBounds_memoryDC(); GdiplusShutdown(gdiplusToken); DestroyWindow( hwnd ); diff --git a/rostests/winetests/gdiplus/image.c b/rostests/winetests/gdiplus/image.c index b08f425a32d..9aa0b1ef034 100644 --- a/rostests/winetests/gdiplus/image.c +++ b/rostests/winetests/gdiplus/image.c @@ -1703,6 +1703,10 @@ static void test_createhbitmap(void) stat = GdipDisposeImage((GpImage*)bitmap); expect(Ok, stat); + /* make (1,0) have no alpha and (2,0) a different blue value. */ + bits[7] = 0x00; + bits[8] = 0x40; + /* create alpha Bitmap */ stat = GdipCreateBitmapFromScan0(8, 20, 32, PixelFormat32bppARGB, bits, &bitmap); expect(Ok, stat); @@ -1728,21 +1732,106 @@ static void test_createhbitmap(void) { DWORD val = *(DWORD*)bm.bmBits; ok(val == 0x682a2a2a, "got %x, expected 0x682a2a2a\n", val); + val = *((DWORD*)bm.bmBits + (bm.bmHeight-1) * bm.bmWidthBytes/4 + 1); + ok(val == 0x0, "got %x, expected 0x682a2a2a\n", val); } hdc = CreateCompatibleDC(NULL); oldhbitmap = SelectObject(hdc, hbitmap); pixel = GetPixel(hdc, 5, 5); + expect(0x2a2a2a, pixel); + pixel = GetPixel(hdc, 1, 0); + expect(0x0, pixel); + SelectObject(hdc, oldhbitmap); DeleteDC(hdc); - expect(0x2a2a2a, pixel); DeleteObject(hbitmap); } + /* create HBITMAP with bkgnd colour */ + stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0xff00ff); + expect(Ok, stat); + + if (stat == Ok) + { + ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm); + expect(sizeof(BITMAP), ret); + + expect(0, bm.bmType); + expect(8, bm.bmWidth); + expect(20, bm.bmHeight); + expect(32, bm.bmWidthBytes); + expect(1, bm.bmPlanes); + expect(32, bm.bmBitsPixel); + ok(bm.bmBits != NULL, "got DDB, expected DIB\n"); + + if (bm.bmBits) + { + DWORD val = *(DWORD*)bm.bmBits; + ok(val == 0x68c12ac1, "got %x, expected 0x682a2a2a\n", val); + val = *((DWORD*)bm.bmBits + (bm.bmHeight-1) * bm.bmWidthBytes/4 + 1); + ok(val == 0xff00ff, "got %x, expected 0x682a2a2a\n", val); + } + + hdc = CreateCompatibleDC(NULL); + + oldhbitmap = SelectObject(hdc, hbitmap); + pixel = GetPixel(hdc, 5, 5); + expect(0xc12ac1, pixel); + pixel = GetPixel(hdc, 1, 0); + expect(0xff00ff, pixel); + pixel = GetPixel(hdc, 2, 0); + expect(0xb12ac1, pixel); + + SelectObject(hdc, oldhbitmap); + DeleteDC(hdc); + DeleteObject(hbitmap); + } + + /* create HBITMAP with bkgnd colour with alpha and show it behaves with no alpha. */ + stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0x80ff00ff); + expect(Ok, stat); + + if (stat == Ok) + { + ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm); + expect(sizeof(BITMAP), ret); + + expect(0, bm.bmType); + expect(8, bm.bmWidth); + expect(20, bm.bmHeight); + expect(32, bm.bmWidthBytes); + expect(1, bm.bmPlanes); + expect(32, bm.bmBitsPixel); + ok(bm.bmBits != NULL, "got DDB, expected DIB\n"); + + if (bm.bmBits) + { + DWORD val = *(DWORD*)bm.bmBits; + ok(val == 0x68c12ac1, "got %x, expected 0x682a2a2a\n", val); + val = *((DWORD*)bm.bmBits + (bm.bmHeight-1) * bm.bmWidthBytes/4 + 1); + ok(val == 0xff00ff, "got %x, expected 0x682a2a2a\n", val); + } + + hdc = CreateCompatibleDC(NULL); + + oldhbitmap = SelectObject(hdc, hbitmap); + pixel = GetPixel(hdc, 5, 5); + expect(0xc12ac1, pixel); + pixel = GetPixel(hdc, 1, 0); + expect(0xff00ff, pixel); + pixel = GetPixel(hdc, 2, 0); + expect(0xb12ac1, pixel); + + SelectObject(hdc, oldhbitmap); + DeleteDC(hdc); + DeleteObject(hbitmap); + } + stat = GdipDisposeImage((GpImage*)bitmap); expect(Ok, stat); } diff --git a/rostests/winetests/gdiplus/region.c b/rostests/winetests/gdiplus/region.c index 3e409e5891d..9d83db79444 100644 --- a/rostests/winetests/gdiplus/region.c +++ b/rostests/winetests/gdiplus/region.c @@ -107,6 +107,56 @@ static void verify_region(HRGN hrgn, const RECT *rc) rgn.data.rdh.rcBound.left, rgn.data.rdh.rcBound.top, rgn.data.rdh.rcBound.right, rgn.data.rdh.rcBound.bottom); } +static void test_region_data(DWORD *data, UINT size, INT line) +{ + GpStatus status; + GpRegion *region; + DWORD buf[256]; + UINT needed, i; + + status = GdipCreateRegionRgnData((BYTE *)data, size, ®ion); + /* Windows always fails to create an empty path in a region */ + if (data[4] == RGNDATA_PATH) + { + struct _path_header + { + DWORD size; + DWORD magic; + DWORD count; + DWORD flags; + } *path_header = (struct _path_header *)(data + 5); + if (!path_header->count) + { + ok_(__FILE__, line)(status == GenericError, "expected GenericError, got %d\n", status); + return; + } + } + + ok_(__FILE__, line)(status == Ok, "GdipCreateRegionRgnData error %d\n", status); + if (status != Ok) return; + + needed = 0; + status = GdipGetRegionDataSize(region, &needed); + ok_(__FILE__, line)(status == Ok, "status %d\n", status); + ok_(__FILE__, line)(needed == size, "data size mismatch: %u != %u\n", needed, size); + + memset(buf, 0xee, sizeof(buf)); + needed = 0; + status = GdipGetRegionData(region, (BYTE *)buf, sizeof(buf), &needed); + ok_(__FILE__, line)(status == Ok, "status %08x\n", status); + ok_(__FILE__, line)(needed == size, "data size mismatch: %u != %u\n", needed, size); + + size /= sizeof(DWORD); + for (i = 0; i < size - 1; i++) + { + if (i == 1) continue; /* data[1] never matches */ + ok_(__FILE__, line)(data[i] == buf[i], "off %u: %#x != %#x\n", i, data[i], buf[i]); + } + /* some Windows versions fail to properly clear the aligned DWORD */ + ok_(__FILE__, line)(data[size - 1] == buf[size - 1] || broken(data[size - 1] != buf[size - 1]), + "off %u: %#x != %#x\n", size - 1, data[size - 1], buf[size - 1]); +} + static void test_getregiondata(void) { GpStatus status; @@ -148,6 +198,7 @@ static void test_getregiondata(void) expect_dword(buf + 3, 0); expect_dword(buf + 4, RGNDATA_INFINITE_RECT); expect_dword(buf + 6, 0xeeeeeeee); + test_region_data(buf, needed, __LINE__); status = GdipSetEmpty(region); ok(status == Ok, "status %08x\n", status); @@ -165,6 +216,7 @@ static void test_getregiondata(void) expect_dword(buf + 3, 0); expect_dword(buf + 4, RGNDATA_EMPTY_RECT); expect_dword(buf + 6, 0xeeeeeeee); + test_region_data(buf, needed, __LINE__); status = GdipSetInfinite(region); ok(status == Ok, "status %08x\n", status); @@ -182,6 +234,7 @@ static void test_getregiondata(void) expect_dword(buf + 3, 0); expect_dword(buf + 4, RGNDATA_INFINITE_RECT); expect_dword(buf + 6, 0xeeeeeeee); + test_region_data(buf, needed, __LINE__); status = GdipDeleteRegion(region); ok(status == Ok, "status %08x\n", status); @@ -210,6 +263,7 @@ static void test_getregiondata(void) expect_float(buf + 7, 100.0); expect_float(buf + 8, 200.0); expect_dword(buf + 10, 0xeeeeeeee); + test_region_data(buf, needed, __LINE__); rect.X = 50; rect.Y = 30; @@ -295,6 +349,7 @@ static void test_getregiondata(void) expect_float(buf + 37, 22.0); expect_float(buf + 38, 55.0); expect_dword(buf + 39, 0xeeeeeeee); + test_region_data(buf, needed, __LINE__); status = GdipDeleteRegion(region2); ok(status == Ok, "status %08x\n", status); @@ -336,6 +391,7 @@ static void test_getregiondata(void) expect_float(buf + 16, 28.0); expect_dword(buf + 17, 0x81010100); expect_dword(buf + 18, 0xeeeeeeee); + test_region_data(buf, needed, __LINE__); rect.X = 50; rect.Y = 30; @@ -376,6 +432,7 @@ static void test_getregiondata(void) expect_float(buf + 22, 10.0); expect_float(buf + 23, 20.0); expect_dword(buf + 24, 0xeeeeeeee); + test_region_data(buf, needed, __LINE__); status = GdipDeleteRegion(region); ok(status == Ok, "status %08x\n", status); @@ -408,6 +465,7 @@ static void test_getregiondata(void) ok(*(buf + 8) == 0x4000 /* before win7 */ || *(buf + 8) == 0, "expected 0x4000 or 0, got %08x\n", *(buf + 8)); expect_dword(buf + 10, 0xeeeeeeee); + test_region_data(buf, needed, __LINE__); /* Transform an empty region */ status = GdipCreateMatrix(&matrix); @@ -458,6 +516,7 @@ static void test_getregiondata(void) expect(6, point[3].Y); expect_dword(buf + 13, 0x81010100); /* 0x01010100 if we don't close the path */ expect_dword(buf + 14, 0xeeeeeeee); + test_region_data(buf, needed, __LINE__); status = GdipTranslateRegion(region, 0.6, 0.8); expect(Ok, status); @@ -485,6 +544,7 @@ static void test_getregiondata(void) expect_float(buf + 16, 6.8); expect_dword(buf + 17, 0x81010100); /* 0x01010100 if we don't close the path */ expect_dword(buf + 18, 0xeeeeeeee); + test_region_data(buf, needed, __LINE__); status = GdipDeletePath(path); expect(Ok, status); @@ -527,6 +587,7 @@ static void test_getregiondata(void) expect_float(buf + 16, 6.2); expect_dword(buf + 17, 0x01010100); expect_dword(buf + 18, 0xeeeeeeee); + test_region_data(buf, needed, __LINE__); status = GdipDeletePath(path); expect(Ok, status); @@ -589,6 +650,7 @@ static void test_getregiondata(void) ok(*(buf + 28) == 0x00000101 || *(buf + 28) == 0x43050101 /* Win 7 */, "expected 00000101 or 43050101 got %08x\n", *(buf + 28)); expect_dword(buf + 29, 0xeeeeeeee); + test_region_data(buf, needed, __LINE__); status = GdipDeletePath(path); expect(Ok, status); @@ -632,6 +694,7 @@ static void test_getregiondata(void) expect(23, point[3].Y); expect_dword(buf + 13, 0x81010100); /* 0x01010100 if we don't close the path */ expect_dword(buf + 14, 0xeeeeeeee); + test_region_data(buf, needed, __LINE__); status = GdipDeletePath(path); expect(Ok, status); @@ -674,6 +737,7 @@ static void test_getregiondata(void) expect_float(buf + 16, 2300.0); expect_dword(buf + 17, 0x81010100); /* 0x01010100 if we don't close the path */ expect_dword(buf + 18, 0xeeeeeeee); + test_region_data(buf, needed, __LINE__); status = GdipDeletePath(path); expect(Ok, status); @@ -737,6 +801,7 @@ static void test_getregiondata(void) *(buf + 33) == 0x43030303 /* 32-bit win7 */ || *(buf + 33) == 0x4c030303 /* 64-bit win7 */, "expected 0x00030303 or 0x43030303 or 0x4c030303 got %08x\n", *(buf + 33)); expect_dword(buf + 34, 0xeeeeeeee); + test_region_data(buf, needed, __LINE__); status = GdipDeletePath(path); expect(Ok, status);