Module: wine Branch: refs/heads/master Commit: 5c1b27a02958504501a93dfad3c36b044d3d923f URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=5c1b27a02958504501a93dfa...
Author: Dmitry Timoshkov dmitry@codeweavers.com Date: Mon Mar 20 18:36:53 2006 +0800
gdi: Add a simple test for bitmap bits/metrics
Add a simple test for bitmap bits/metrics, fix GetBitmapBits for an empty (not selected into a DC) bitmap.
---
dlls/gdi/bitmap.c | 5 ++- dlls/gdi/tests/gdiobj.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 2 deletions(-)
diff --git a/dlls/gdi/bitmap.c b/dlls/gdi/bitmap.c index 5c2b6c3..a5b249b 100644 --- a/dlls/gdi/bitmap.c +++ b/dlls/gdi/bitmap.c @@ -366,8 +366,9 @@ LONG WINAPI GetBitmapBits( } else {
if(!bmp->bitmap.bmBits) { - WARN("Bitmap is empty\n"); - ret = 0; + TRACE("Bitmap is empty\n"); + memset(bits, 0, count); + ret = count; } else { memcpy(bits, bmp->bitmap.bmBits, count); ret = count; diff --git a/dlls/gdi/tests/gdiobj.c b/dlls/gdi/tests/gdiobj.c index 2dee9ab..ec4d2d4 100644 --- a/dlls/gdi/tests/gdiobj.c +++ b/dlls/gdi/tests/gdiobj.c @@ -982,10 +982,91 @@ else } }
+static void test_bitmap(void) +{ + char buf[256], buf_cmp[256]; + HBITMAP hbmp, hbmp_old; + HDC hdc; + BITMAP bm; + INT ret; + + hdc = CreateCompatibleDC(0); + assert(hdc != 0); + + hbmp = CreateBitmap(15, 15, 1, 1, NULL); + assert(hbmp != NULL); + + ret = GetObject(hbmp, sizeof(bm), &bm); + ok(ret == sizeof(bm), "%d != %d\n", ret, sizeof(bm)); + + ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType); + ok(bm.bmWidth == 15, "wrong bm.bmWidth %d\n", bm.bmWidth); + ok(bm.bmHeight == 15, "wrong bm.bmHeight %d\n", bm.bmHeight); + ok(bm.bmWidthBytes == 2, "wrong bm.bmWidthBytes %d\n", bm.bmWidthBytes); + ok(bm.bmPlanes == 1, "wrong bm.bmPlanes %d\n", bm.bmPlanes); + ok(bm.bmBitsPixel == 1, "wrong bm.bmBitsPixel %d\n", bm.bmBitsPixel); + ok(bm.bmBits == NULL, "wrong bm.bmBits %p\n", bm.bmBits); + + assert(sizeof(buf) >= bm.bmWidthBytes * bm.bmHeight); + assert(sizeof(buf) == sizeof(buf_cmp)); + + memset(buf_cmp, 0xAA, sizeof(buf_cmp)); + memset(buf_cmp, 0, bm.bmWidthBytes * bm.bmHeight); + + memset(buf, 0xAA, sizeof(buf)); + ret = GetBitmapBits(hbmp, sizeof(buf), buf); + ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight); + ok(!memcmp(buf, buf_cmp, sizeof(buf)), "buffers do not match\n"); + + hbmp_old = SelectObject(hdc, hbmp); + + ret = GetObject(hbmp, sizeof(bm), &bm); + ok(ret == sizeof(bm), "%d != %d\n", ret, sizeof(bm)); + + ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType); + ok(bm.bmWidth == 15, "wrong bm.bmWidth %d\n", bm.bmWidth); + ok(bm.bmHeight == 15, "wrong bm.bmHeight %d\n", bm.bmHeight); + ok(bm.bmWidthBytes == 2, "wrong bm.bmWidthBytes %d\n", bm.bmWidthBytes); + ok(bm.bmPlanes == 1, "wrong bm.bmPlanes %d\n", bm.bmPlanes); + ok(bm.bmBitsPixel == 1, "wrong bm.bmBitsPixel %d\n", bm.bmBitsPixel); + ok(bm.bmBits == NULL, "wrong bm.bmBits %p\n", bm.bmBits); + + memset(buf, 0xAA, sizeof(buf)); + ret = GetBitmapBits(hbmp, sizeof(buf), buf); + ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight); +todo_wine { + ok(!memcmp(buf, buf_cmp, sizeof(buf)), "buffers do not match\n"); +} + + hbmp_old = SelectObject(hdc, hbmp_old); + ok(hbmp_old == hbmp, "wrong old bitmap %p\n", hbmp_old); + + /* test various buffer sizes for GetObject */ + ret = GetObject(hbmp, sizeof(bm) * 2, &bm); + ok(ret == sizeof(bm), "%d != %d\n", ret, sizeof(bm)); + + ret = GetObject(hbmp, sizeof(bm) / 2, &bm); +todo_wine { + ok(ret == 0, "%d != 0\n", ret); +} + + ret = GetObject(hbmp, 0, &bm); + ok(ret == 0, "%d != 0\n", ret); + + ret = GetObject(hbmp, 1, &bm); +todo_wine { + ok(ret == 0, "%d != 0\n", ret); +} + + DeleteObject(hbmp); + DeleteDC(hdc); +} + START_TEST(gdiobj) { test_logfont(); test_logpen(); + test_bitmap(); test_bitmap_font(); test_bitmap_font_metrics(); test_gdi_objects();