From eca0a256349a274ead2a826818411fee2e80c65b Mon Sep 17 00:00:00 2001 From: Walt Ogburn Date: Thu, 9 Dec 2004 11:37:59 +0000 Subject: [PATCH] Added some tests for win-format metafiles. --- dlls/gdi/tests/metafile.c | 236 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 236 insertions(+) diff --git a/dlls/gdi/tests/metafile.c b/dlls/gdi/tests/metafile.c index efc6aa7ed09..d0cc0be96f7 100644 --- a/dlls/gdi/tests/metafile.c +++ b/dlls/gdi/tests/metafile.c @@ -19,6 +19,7 @@ */ #include +#include #include "wine/test.h" #include "winbase.h" @@ -189,7 +190,242 @@ static void test_ExtTextOut(void) ok(ReleaseDC(hwnd, hdcDisplay), "ReleaseDC error %ld\n", GetLastError()); } +/* Win-format metafile (mfdrv) tests */ +/* These tests compare the generated metafiles byte-by-byte */ +/* with the nominal results. */ + +/* Maximum size of sample metafiles in bytes. */ +#define MF_BUFSIZE 256 + +/* 8x8 bitmap data for a pattern brush */ +static const unsigned char SAMPLE_PATTERN_BRUSH[] = { + 0x01, 0x00, 0x02, 0x00, + 0x03, 0x00, 0x04, 0x00, + 0x05, 0x00, 0x06, 0x00, + 0x07, 0x00, 0x08, 0x00 +}; + +/* Sample metafiles to be compared to the outputs of the + * test functions. + */ + +static const unsigned char MF_BLANK_BITS[] = { + 0x01, 0x00, 0x09, 0x00, 0x00, 0x03, 0x0c, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +static const unsigned char MF_GRAPHICS_BITS[] = { + 0x01, 0x00, 0x09, 0x00, 0x00, 0x03, 0x22, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x14, 0x02, + 0x01, 0x00, 0x01, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x13, 0x02, 0x02, 0x00, 0x02, 0x00, 0x05, 0x00, + 0x00, 0x00, 0x14, 0x02, 0x01, 0x00, 0x01, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x18, 0x04, 0x02, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, + 0x00, 0x00, 0x00, 0x00 +}; + +static const unsigned char MF_PATTERN_BRUSH_BITS[] = { + 0x01, 0x00, 0x09, 0x00, 0x00, 0x03, 0x3d, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x2d, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x42, 0x01, + 0x03, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x2d, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00 +}; + +/* For debugging or dumping the raw metafiles produced by + * new test functions. + */ + +static void dump_mf_bits (const HMETAFILE mf, const char *desc) +{ + char buf[MF_BUFSIZE]; + UINT mfsize; + int i; + + mfsize = GetMetaFileBitsEx (mf, MF_BUFSIZE, buf); + ok (mfsize > 0, "%s: GetMetaFileBitsEx failed.\n", desc); + + printf ("MetaFile %s has bits:\n{\n ", desc); + for (i=0; i 0, "%s: GetMetaFileBitsEx failed.\n", desc); + if (mfsize < MF_BUFSIZE) + ok (mfsize == bsize, "%s: mfsize=%d, bsize=%d.\n", + desc, mfsize, bsize); + else + ok (bsize >= MF_BUFSIZE, "%s: mfsize > bufsize (%d bytes), bsize=%d.\n", + desc, mfsize, bsize); + if (mfsize != bsize) + return -1; + + diff = 0; + for (i=0; ilbStyle = BS_PATTERN; + orig_lb->lbColor = RGB(0, 0, 0); + orig_lb->lbHatch = (INT) CreateBitmap (8, 8, 1, 1, SAMPLE_PATTERN_BRUSH); + ok((HBITMAP *)orig_lb->lbHatch != NULL, "CreateBitmap error %ld.\n", GetLastError()); + + hBrush = CreateBrushIndirect (orig_lb); + ok(hBrush != 0, "CreateBrushIndirect error %ld\n", GetLastError()); + + hdcMetafile = CreateMetaFileA(NULL); + ok(hdcMetafile != 0, "CreateMetaFileA error %ld\n", GetLastError()); + trace("hdcMetafile %p\n", hdcMetafile); + + hBrush = SelectObject(hdcMetafile, hBrush); + ok(hBrush != 0, "SelectObject error %ld.\n", GetLastError()); + + hMetafile = CloseMetaFile(hdcMetafile); + ok(hMetafile != 0, "CloseMetaFile error %ld\n", GetLastError()); + ok(!GetObjectType(hdcMetafile), "CloseMetaFile has to destroy metafile hdc\n"); + + if (compare_mf_bits (hMetafile, MF_PATTERN_BRUSH_BITS, sizeof(MF_PATTERN_BRUSH_BITS), + "mf_Pattern_Brush") != 0) + dump_mf_bits (hMetafile, "mf_Pattern_Brush"); + + ok(DeleteMetaFile(hMetafile), "DeleteMetaFile error %ld\n", GetLastError()); + ok(DeleteObject(hBrush), "DeleteObject(HBRUSH) error %ld\n", GetLastError()); + ok(DeleteObject((HBITMAP *)orig_lb->lbHatch), "DeleteObject(HBITMAP) error %ld\n", + GetLastError()); + HeapFree (GetProcessHeap(), 0, orig_lb); +} + START_TEST(metafile) { + /* For enhanced metafiles (enhmfdrv) */ test_ExtTextOut(); + + /* For win-format metafiles (mfdrv) */ + test_mf_Blank(); + test_mf_Graphics(); + + /* Crashes under wine: */ + /* test_mf_PatternBrush(); */ + }