Module: wine Branch: master Commit: b85270e3a57df29c49974cbc3616cef7bf62a62a URL: http://source.winehq.org/git/wine.git/?a=commit;h=b85270e3a57df29c49974cbc36...
Author: Dan Kegel dank@kegel.com Date: Tue Jun 19 18:08:07 2012 -0700
gdi32: Add test for SelectClipRgn in metafiles, make it pass.
---
dlls/gdi32/mfdrv/graphics.c | 6 +- dlls/gdi32/tests/metafile.c | 125 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 125 insertions(+), 6 deletions(-)
diff --git a/dlls/gdi32/mfdrv/graphics.c b/dlls/gdi32/mfdrv/graphics.c index 439fca5..e26076f 100644 --- a/dlls/gdi32/mfdrv/graphics.c +++ b/dlls/gdi32/mfdrv/graphics.c @@ -321,9 +321,9 @@ static INT16 MFDRV_CreateRegion(PHYSDEV dev, HRGN hrgn)
mr->rdParm[0] = 0; mr->rdParm[1] = 6; - mr->rdParm[2] = 0x1234; + mr->rdParm[2] = 0x2f6; mr->rdParm[3] = 0; - mr->rdParm[4] = (Param - mr->rdParm) * sizeof(WORD); + mr->rdParm[4] = (Param - &mr->rdFunction) * sizeof(WORD); mr->rdParm[5] = Bands; mr->rdParm[6] = MaxBands; mr->rdParm[7] = rgndata->rdh.rcBound.left; @@ -413,7 +413,7 @@ INT MFDRV_ExtSelectClipRgn( PHYSDEV dev, HRGN hrgn, INT mode ) if (!hrgn) return NULLREGION; iRgn = MFDRV_CreateRegion( dev, hrgn ); if(iRgn == -1) return ERROR; - ret = MFDRV_MetaParam1( dev, META_SELECTCLIPREGION, iRgn ) ? NULLREGION : ERROR; + ret = MFDRV_MetaParam1( dev, META_SELECTOBJECT, iRgn ) ? NULLREGION : ERROR; MFDRV_MetaParam1( dev, META_DELETEOBJECT, iRgn ); MFDRV_RemoveHandle( dev, iRgn ); return ret; diff --git a/dlls/gdi32/tests/metafile.c b/dlls/gdi32/tests/metafile.c index df263c3..e6bab5d 100644 --- a/dlls/gdi32/tests/metafile.c +++ b/dlls/gdi32/tests/metafile.c @@ -2492,6 +2492,124 @@ todo_wine DeleteDC(hdc); }
+static const unsigned char MF_CLIP_BITS[] = { + /* METAHEADER */ + 0x01, 0x00, /* mtType */ + 0x09, 0x00, /* mtHeaderSize */ + 0x00, 0x03, /* mtVersion */ + 0x32, 0x00, 0x00, 0x00, /* mtSize */ + 0x01, 0x00, /* mtNoObjects */ + 0x14, 0x00, 0x00, 0x00, /* mtMaxRecord (size in words of longest record) */ + 0x00, 0x00, /* reserved */ + + /* METARECORD for CreateRectRgn(0x11, 0x22, 0x33, 0x44) */ + 0x14, 0x00, 0x00, 0x00, /* rdSize in words */ + 0xff, 0x06, /* META_CREATEREGION */ + 0x00, 0x00, 0x06, 0x00, 0xf6, 0x02, 0x00, 0x00, + 0x24, 0x00, 0x01, 0x00, 0x02, 0x00, 0x11, 0x00, + 0x22, 0x00, 0x33, 0x00, 0x44, 0x00, 0x02, 0x00, + 0x22, 0x00, 0x44, 0x00, 0x11, 0x00, 0x33, 0x00, + 0x02, 0x00, + + /* METARECORD for SelectObject */ + 0x04, 0x00, 0x00, 0x00, + 0x2d, 0x01, /* META_SELECTOBJECT (not META_SELECTCLIPREGION?!) */ + 0x00, 0x00, + + /* METARECORD */ + 0x04, 0x00, 0x00, 0x00, + 0xf0, 0x01, /* META_DELETEOBJECT */ + 0x00, 0x00, + + /* METARECORD for MoveTo(1,0x30) */ + 0x05, 0x00, 0x00, 0x00, /* rdSize in words */ + 0x14, 0x02, /* META_MOVETO */ + 0x30, 0x00, /* y */ + 0x01, 0x00, /* x */ + + /* METARECORD for LineTo(0x20, 0x30) */ + 0x05, 0x00, 0x00, 0x00, /* rdSize in words */ + 0x13, 0x02, /* META_LINETO */ + 0x30, 0x00, /* y */ + 0x20, 0x00, /* x */ + + /* EOF */ + 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00 +}; + +static int clip_mf_enum_proc_seen_selectclipregion; +static int clip_mf_enum_proc_seen_selectobject; + +static int CALLBACK clip_mf_enum_proc(HDC hdc, HANDLETABLE *handle_table, + METARECORD *mr, int n_objs, LPARAM param) +{ + switch (mr->rdFunction) { + case META_SELECTCLIPREGION: + clip_mf_enum_proc_seen_selectclipregion++; + break; + case META_SELECTOBJECT: + clip_mf_enum_proc_seen_selectobject++; + break; + } + return 1; +} + +static void test_mf_clipping(void) +{ + /* left top right bottom */ + static RECT rc_clip = { 0x11, 0x22, 0x33, 0x44 }; + HWND hwnd; + HDC hdc; + HMETAFILE hmf; + HRGN hrgn; + INT ret; + + SetLastError(0xdeadbeef); + hdc = CreateMetaFileA(NULL); + ok(hdc != 0, "CreateMetaFileA error %d\n", GetLastError()); + + hrgn = CreateRectRgn(rc_clip.left, rc_clip.top, rc_clip.right, rc_clip.bottom); + ret = SelectClipRgn(hdc, hrgn); + /* Seems like it should be SIMPLEREGION, but windows returns NULLREGION? */ + ok(ret == NULLREGION, "expected NULLREGION, got %d\n", ret); + + /* Draw a line that starts off left of the clip region and ends inside it */ + MoveToEx(hdc, 0x1, 0x30, NULL); + LineTo(hdc, 0x20, 0x30); + + SetLastError(0xdeadbeef); + hmf = CloseMetaFile(hdc); + ok(hmf != 0, "CloseMetaFile error %d\n", GetLastError()); + + if (compare_mf_bits(hmf, MF_CLIP_BITS, sizeof(MF_CLIP_BITS), + "mf_clipping") != 0) + { + dump_mf_bits(hmf, "mf_clipping"); + } + + DeleteObject(hrgn); + + hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP | WS_VISIBLE, + 0, 0, 200, 200, 0, 0, 0, NULL); + ok(hwnd != 0, "CreateWindowExA error %d\n", GetLastError()); + + hdc = GetDC(hwnd); + + ret = EnumMetaFile(hdc, hmf, clip_mf_enum_proc, (LPARAM)&rc_clip); + ok(ret, "EnumMetaFile error %d\n", GetLastError()); + + /* Oddly, windows doesn't seem to use META_SELECTCLIPREGION */ + ok(clip_mf_enum_proc_seen_selectclipregion == 0, + "expected 0 selectclipregion, saw %d\n", clip_mf_enum_proc_seen_selectclipregion); + ok(clip_mf_enum_proc_seen_selectobject == 1, + "expected 1 selectobject, saw %d\n", clip_mf_enum_proc_seen_selectobject); + + DeleteMetaFile(hmf); + ReleaseDC(hwnd, hdc); + DestroyWindow(hwnd); +} + static INT CALLBACK EmfEnumProc(HDC hdc, HANDLETABLE *lpHTable, const ENHMETARECORD *lpEMFR, INT nObj, LPARAM lpData) { LPMETAFILEPICT lpMFP = (LPMETAFILEPICT)lpData; @@ -3205,6 +3323,9 @@ START_TEST(metafile) test_SaveDC(); test_emf_BitBlt(); test_emf_DCBrush(); + test_emf_ExtTextOut_on_path(); + test_emf_clipping(); + test_emf_polybezier();
/* For win-format metafiles (mfdrv) */ test_mf_SaveDC(); @@ -3215,9 +3336,7 @@ START_TEST(metafile) test_CopyMetaFile(); test_SetMetaFileBits(); test_mf_ExtTextOut_on_path(); - test_emf_ExtTextOut_on_path(); - test_emf_clipping(); - test_emf_polybezier(); + test_mf_clipping();
/* For metafile conversions */ test_mf_conversions();