added gdi32 wine regression tests
authorSteven Edwards <winehacker@gmail.com>
Sat, 6 Aug 2005 23:19:47 +0000 (23:19 +0000)
committerSteven Edwards <winehacker@gmail.com>
Sat, 6 Aug 2005 23:19:47 +0000 (23:19 +0000)
svn path=/trunk/; revision=17123

reactos/regtests/winetests/directory.xml
reactos/regtests/winetests/gdi32/.cvsignore [new file with mode: 0755]
reactos/regtests/winetests/gdi32/bitmap.c [new file with mode: 0755]
reactos/regtests/winetests/gdi32/brush.c [new file with mode: 0755]
reactos/regtests/winetests/gdi32/gdi32_test.xml [new file with mode: 0644]
reactos/regtests/winetests/gdi32/gdiobj.c [new file with mode: 0755]
reactos/regtests/winetests/gdi32/metafile.c [new file with mode: 0755]
reactos/regtests/winetests/gdi32/testlist.c [new file with mode: 0644]

index ca84585..b24df7d 100644 (file)
@@ -5,4 +5,16 @@
 <directory name="comctl32">
        <xi:include href="comctl32/comctl32_test.xml" />
 </directory>
+<directory name="gdi32">
+       <xi:include href="gdi32/gdi32_test.xml" />
+</directory>
+<directory name="msvcrt">
+       <xi:include href="msvcrt/msvcrt_test.xml" />
+</directory>
+<directory name="psapi">
+       <xi:include href="psapi/psapi_test.xml" />
+</directory>
+<directory name="version">
+       <xi:include href="version/version_test.xml" />
+</directory>
 </group>
diff --git a/reactos/regtests/winetests/gdi32/.cvsignore b/reactos/regtests/winetests/gdi32/.cvsignore
new file mode 100755 (executable)
index 0000000..4f26ff5
--- /dev/null
@@ -0,0 +1,7 @@
+Makefile
+bitmap.ok
+brush.ok
+gdiobj.ok
+generated.ok
+metafile.ok
+testlist.c
diff --git a/reactos/regtests/winetests/gdi32/bitmap.c b/reactos/regtests/winetests/gdi32/bitmap.c
new file mode 100755 (executable)
index 0000000..dbbb81b
--- /dev/null
@@ -0,0 +1,459 @@
+/*
+ * Unit test suite for bitmaps
+ *
+ * Copyright 2004 Huw Davies
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <stdarg.h>
+#include <assert.h>
+
+#include "windef.h"
+#include "winbase.h"
+#include "wingdi.h"
+#include "winuser.h"
+#include "mmsystem.h"
+
+#include "wine/test.h"
+
+static BOOL is_win9x;
+
+static void test_createdibitmap(void)
+{
+    HDC hdc, hdcmem;
+    BITMAPINFOHEADER bmih;
+    BITMAP bm;
+    HBITMAP hbm, hbm_colour, hbm_old;
+    INT screen_depth;
+
+    hdc = GetDC(0);
+    screen_depth = GetDeviceCaps(hdc, BITSPIXEL);
+    memset(&bmih, 0, sizeof(bmih));
+    bmih.biSize = sizeof(bmih);
+    bmih.biWidth = 10;
+    bmih.biHeight = 10;
+    bmih.biPlanes = 1;
+    bmih.biBitCount = 32;
+    bmih.biCompression = BI_RGB;
+    /* First create an un-initialised bitmap.  The depth of the bitmap
+       should match that of the hdc and not that supplied in bmih.
+    */
+
+    /* First try 32 bits */
+    hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
+    ok(hbm != NULL, "CreateDIBitmap failed\n");
+    ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
+
+    ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
+    DeleteObject(hbm);
+    
+    /* Then 16 */
+    bmih.biBitCount = 16;
+    hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
+    ok(hbm != NULL, "CreateDIBitmap failed\n");
+    ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
+
+    ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
+    DeleteObject(hbm);
+
+    /* Then 1 */
+    bmih.biBitCount = 1;
+    hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
+    ok(hbm != NULL, "CreateDIBitmap failed\n");
+    ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
+
+    ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
+    DeleteObject(hbm);
+
+    /* Now with a monochrome dc we expect a monochrome bitmap */
+    hdcmem = CreateCompatibleDC(hdc);
+
+    /* First try 32 bits */
+    bmih.biBitCount = 32;
+    hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
+    ok(hbm != NULL, "CreateDIBitmap failed\n");
+    ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
+
+    ok(bm.bmBitsPixel == 1, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, 1);
+    DeleteObject(hbm);
+    
+    /* Then 16 */
+    bmih.biBitCount = 16;
+    hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
+    ok(hbm != NULL, "CreateDIBitmap failed\n");
+    ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
+
+    ok(bm.bmBitsPixel == 1, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, 1);
+    DeleteObject(hbm);
+    
+    /* Then 1 */
+    bmih.biBitCount = 1;
+    hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
+    ok(hbm != NULL, "CreateDIBitmap failed\n");
+    ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
+
+    ok(bm.bmBitsPixel == 1, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, 1);
+    DeleteObject(hbm);
+
+    /* Now select a polychrome bitmap into the dc and we expect
+       screen_depth bitmaps again */
+    hbm_colour = CreateCompatibleBitmap(hdc, 1, 1);
+    hbm_old = SelectObject(hdcmem, hbm_colour);
+
+    /* First try 32 bits */
+    bmih.biBitCount = 32;
+    hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
+    ok(hbm != NULL, "CreateDIBitmap failed\n");
+    ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
+
+    ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
+    DeleteObject(hbm);
+    
+    /* Then 16 */
+    bmih.biBitCount = 16;
+    hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
+    ok(hbm != NULL, "CreateDIBitmap failed\n");
+    ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
+
+    ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
+    DeleteObject(hbm);
+    
+    /* Then 1 */
+    bmih.biBitCount = 1;
+    hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
+    ok(hbm != NULL, "CreateDIBitmap failed\n");
+    ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
+
+    ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
+    DeleteObject(hbm);
+
+    SelectObject(hdcmem, hbm_old);
+    DeleteObject(hbm_colour);
+    DeleteDC(hdcmem);
+
+    /* If hdc == 0 then we get a 1 bpp bitmap */
+    if (!is_win9x) {
+        bmih.biBitCount = 32;
+        hbm = CreateDIBitmap(0, &bmih, 0, NULL, NULL, 0);
+        ok(hbm != NULL, "CreateDIBitmap failed\n");
+        ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
+
+        ok(bm.bmBitsPixel == 1, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, 1);
+        DeleteObject(hbm);
+    }
+    
+    ReleaseDC(0, hdc);
+}
+
+#define test_color_todo(got, exp, txt, todo) \
+    if (!todo && got != exp && screen_depth < 24) { \
+      todo_wine ok(0, #txt " failed at %d-bit screen depth: got 0x%06x expected 0x%06x - skipping DIB tests\n", \
+                   screen_depth, (UINT)got, (UINT)exp); \
+      return; \
+    } else if (todo) todo_wine { ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp); } \
+    else ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp) \
+
+#define test_color(hdc, color, exp, todo_setp, todo_getp) \
+{ \
+    COLORREF c; \
+    c = SetPixel(hdc, 0, 0, color); \
+    if (!is_win9x) { test_color_todo(c, exp, SetPixel, todo_setp); } \
+    c = GetPixel(hdc, 0, 0); \
+    test_color_todo(c, exp, GetPixel, todo_getp); \
+}
+
+static void test_dibsections(void)
+{
+    HDC hdc, hdcmem, hdcmem2;
+    HBITMAP hdib, oldbm, hdib2, oldbm2;
+    char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
+    char bcibuf[sizeof(BITMAPCOREINFO) + 256 * sizeof(RGBTRIPLE)];
+    BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
+    BITMAPCOREINFO *pbci = (BITMAPCOREINFO *)bcibuf;
+    HBITMAP hcoredib;
+    char coreBits[256];
+    BYTE *bits;
+    RGBQUAD rgb[256];
+    int ret;
+    char logpalbuf[sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)];
+    LOGPALETTE *plogpal = (LOGPALETTE*)logpalbuf;
+    WORD *index;
+    DWORD *bits32;
+    HPALETTE hpal, oldpal;
+    COLORREF c0, c1;
+    int i;
+    int screen_depth;
+
+    hdc = GetDC(0);
+    screen_depth = GetDeviceCaps(hdc, BITSPIXEL) * GetDeviceCaps(hdc, PLANES);
+    memset(pbmi, 0, sizeof(bmibuf));
+    pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
+    pbmi->bmiHeader.biHeight = 16;
+    pbmi->bmiHeader.biWidth = 16;
+    pbmi->bmiHeader.biBitCount = 1;
+    pbmi->bmiHeader.biPlanes = 1;
+    pbmi->bmiHeader.biCompression = BI_RGB;
+    pbmi->bmiColors[0].rgbRed = 0xff;
+    pbmi->bmiColors[0].rgbGreen = 0;
+    pbmi->bmiColors[0].rgbBlue = 0;
+    pbmi->bmiColors[1].rgbRed = 0;
+    pbmi->bmiColors[1].rgbGreen = 0;
+    pbmi->bmiColors[1].rgbBlue = 0xff;
+
+    hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
+    ok(hdib != NULL, "CreateDIBSection failed\n");
+
+    /* Test if the old BITMAPCOREINFO structure is supported */    
+        
+    pbci->bmciHeader.bcSize = sizeof(BITMAPCOREHEADER);
+    pbci->bmciHeader.bcBitCount = 0;
+
+    if (!is_win9x) {
+        ret = GetDIBits(hdc, hdib, 0, 16, NULL, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
+        ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
+        ok((pbci->bmciHeader.bcWidth == 16) && (pbci->bmciHeader.bcHeight == 16)
+            && (pbci->bmciHeader.bcBitCount == 1) && (pbci->bmciHeader.bcPlanes == 1),
+        "GetDIBits did't fill in the BITMAPCOREHEADER structure properly\n");
+
+        ret = GetDIBits(hdc, hdib, 0, 16, &coreBits, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
+        ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
+        ok((pbci->bmciColors[0].rgbtRed == 0xff) && (pbci->bmciColors[0].rgbtGreen == 0) &&
+            (pbci->bmciColors[0].rgbtBlue == 0) && (pbci->bmciColors[1].rgbtRed == 0) &&
+            (pbci->bmciColors[1].rgbtGreen == 0) && (pbci->bmciColors[1].rgbtBlue == 0xff),
+            "The color table has not been translated to the old BITMAPCOREINFO format\n");
+
+        hcoredib = CreateDIBSection(hdc, (BITMAPINFO*) pbci, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
+        ok(hcoredib != NULL, "CreateDIBSection failed with a BITMAPCOREINFO\n");
+
+        ZeroMemory(pbci->bmciColors, 256 * sizeof(RGBTRIPLE));
+        ret = GetDIBits(hdc, hcoredib, 0, 16, &coreBits, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
+        ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
+        ok((pbci->bmciColors[0].rgbtRed == 0xff) && (pbci->bmciColors[0].rgbtGreen == 0) &&
+            (pbci->bmciColors[0].rgbtBlue == 0) && (pbci->bmciColors[1].rgbtRed == 0) &&
+            (pbci->bmciColors[1].rgbtGreen == 0) && (pbci->bmciColors[1].rgbtBlue == 0xff),
+            "The color table has not been translated to the old BITMAPCOREINFO format\n");
+
+        DeleteObject(hcoredib);
+    }
+
+    hdcmem = CreateCompatibleDC(hdc);
+    oldbm = SelectObject(hdcmem, hdib);
+
+    ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
+    ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
+    ok(!memcmp(rgb, pbmi->bmiColors, 2 * sizeof(RGBQUAD)),
+       "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
+       rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
+       rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
+
+    c0 = RGB(pbmi->bmiColors[0].rgbRed, pbmi->bmiColors[0].rgbGreen, pbmi->bmiColors[0].rgbBlue);
+    c1 = RGB(pbmi->bmiColors[1].rgbRed, pbmi->bmiColors[1].rgbGreen, pbmi->bmiColors[1].rgbBlue);
+
+    test_color(hdcmem, DIBINDEX(0), c0, 0, 1);
+    test_color(hdcmem, DIBINDEX(1), c1, 0, 1);
+    test_color(hdcmem, DIBINDEX(2), c0, 1, 1);
+    test_color(hdcmem, PALETTEINDEX(0), c0, 1, 1);
+    test_color(hdcmem, PALETTEINDEX(1), c0, 1, 1);
+    test_color(hdcmem, PALETTEINDEX(2), c0, 1, 1);
+    test_color(hdcmem, PALETTERGB(pbmi->bmiColors[0].rgbRed, pbmi->bmiColors[0].rgbGreen,
+        pbmi->bmiColors[0].rgbBlue), c0, 1, 1);
+    test_color(hdcmem, PALETTERGB(pbmi->bmiColors[1].rgbRed, pbmi->bmiColors[1].rgbGreen,
+        pbmi->bmiColors[1].rgbBlue), c1, 1, 1);
+    test_color(hdcmem, PALETTERGB(0, 0, 0), c0, 1, 1);
+    test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0, 1, 1);
+    test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c1, 1, 1);
+
+    SelectObject(hdcmem, oldbm);
+    DeleteObject(hdib);
+
+    pbmi->bmiHeader.biBitCount = 8;
+
+    for (i = 0; i < 128; i++) {
+        pbmi->bmiColors[i].rgbRed = 255 - i * 2;
+        pbmi->bmiColors[i].rgbGreen = i * 2;
+        pbmi->bmiColors[i].rgbBlue = 0;
+        pbmi->bmiColors[255 - i].rgbRed = 0;
+        pbmi->bmiColors[255 - i].rgbGreen = i * 2;
+        pbmi->bmiColors[255 - i].rgbBlue = 255 - i * 2;
+    }
+    hdib = CreateDIBSection(hdcmem, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
+    ok(hdib != NULL, "CreateDIBSection failed\n");
+    oldbm = SelectObject(hdcmem, hdib);
+
+    for (i = 0; i < 256; i++) {
+        test_color(hdcmem, DIBINDEX(i), 
+            RGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue), 0, 0);
+        test_color(hdcmem, PALETTERGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue), 
+            RGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue), 0, 0);
+    }
+
+    SelectObject(hdcmem, oldbm);
+    DeleteObject(hdib);
+
+    pbmi->bmiHeader.biBitCount = 1;
+
+    /* Now create a palette and a palette indexed dib section */
+    memset(plogpal, 0, sizeof(logpalbuf));
+    plogpal->palVersion = 0x300;
+    plogpal->palNumEntries = 2;
+    plogpal->palPalEntry[0].peRed = 0xff;
+    plogpal->palPalEntry[0].peBlue = 0xff;
+    plogpal->palPalEntry[1].peGreen = 0xff;
+
+    index = (WORD*)pbmi->bmiColors;
+    *index++ = 0;
+    *index = 1;
+    hpal = CreatePalette(plogpal);
+    ok(hpal != NULL, "CreatePalette failed\n");
+    oldpal = SelectPalette(hdc, hpal, TRUE);
+    hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
+    ok(hdib != NULL, "CreateDIBSection failed\n");
+
+    /* The colour table has already been grabbed from the dc, so we select back the
+       old palette */
+
+    SelectPalette(hdc, oldpal, TRUE);
+    oldbm = SelectObject(hdcmem, hdib);
+    oldpal = SelectPalette(hdcmem, hpal, TRUE);
+
+    ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
+    ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
+    ok(rgb[0].rgbRed == 0xff && rgb[0].rgbBlue == 0xff && rgb[0].rgbGreen == 0 &&
+       rgb[1].rgbRed == 0    && rgb[1].rgbBlue == 0    && rgb[1].rgbGreen == 0xff,
+       "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
+       rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
+       rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
+
+    c0 = RGB(plogpal->palPalEntry[0].peRed, plogpal->palPalEntry[0].peGreen, plogpal->palPalEntry[0].peBlue);
+    c1 = RGB(plogpal->palPalEntry[1].peRed, plogpal->palPalEntry[1].peGreen, plogpal->palPalEntry[1].peBlue);
+
+    test_color(hdcmem, DIBINDEX(0), c0, 0, 1);
+    test_color(hdcmem, DIBINDEX(1), c1, 0, 1);
+    test_color(hdcmem, DIBINDEX(2), c0, 1, 1);
+    test_color(hdcmem, PALETTEINDEX(0), c0, 0, 1);
+    test_color(hdcmem, PALETTEINDEX(1), c1, 0, 1);
+    test_color(hdcmem, PALETTEINDEX(2), c0, 1, 1);
+    test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[0].peRed, plogpal->palPalEntry[0].peGreen,
+        plogpal->palPalEntry[0].peBlue), c0, 1, 1);
+    test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[1].peRed, plogpal->palPalEntry[1].peGreen,
+        plogpal->palPalEntry[1].peBlue), c1, 1, 1);
+    test_color(hdcmem, PALETTERGB(0, 0, 0), c1, 1, 1);
+    test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0, 1, 1);
+    test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c0, 1, 1);
+    test_color(hdcmem, PALETTERGB(0, 1, 0), c1, 1, 1);
+    test_color(hdcmem, PALETTERGB(0x3f, 0, 0x3f), c1, 1, 1);
+    test_color(hdcmem, PALETTERGB(0x40, 0, 0x40), c0, 1, 1);
+
+    /* Bottom and 2nd row from top green, everything else magenta */
+    bits[0] = bits[1] = 0xff;
+    bits[13 * 4] = bits[13*4 + 1] = 0xff;
+
+
+    pbmi->bmiHeader.biBitCount = 32;
+
+    hdib2 = CreateDIBSection(NULL, pbmi, DIB_RGB_COLORS, (void **)&bits32, NULL, 0);
+    ok(hdib2 != NULL, "CreateDIBSection failed\n");
+    hdcmem2 = CreateCompatibleDC(hdc);
+    oldbm2 = SelectObject(hdcmem2, hdib2);
+
+    BitBlt(hdcmem2, 0, 0, 16,16, hdcmem, 0, 0, SRCCOPY);
+
+    ok(bits32[0] == 0xff00, "lower left pixel is %08lx\n", bits32[0]);
+    ok(bits32[17] == 0xff00ff, "bottom but one, left pixel is %08lx\n", bits32[17]);
+
+    SelectObject(hdcmem2, oldbm2);
+    DeleteObject(hdib2);
+
+    SelectObject(hdcmem, oldbm);
+    SelectObject(hdcmem, oldpal);
+    DeleteObject(hdib);
+    DeleteObject(hpal);
+
+
+    pbmi->bmiHeader.biBitCount = 8;
+
+    memset(plogpal, 0, sizeof(logpalbuf));
+    plogpal->palVersion = 0x300;
+    plogpal->palNumEntries = 256;
+
+    for (i = 0; i < 128; i++) {
+        plogpal->palPalEntry[i].peRed = 255 - i * 2;
+        plogpal->palPalEntry[i].peBlue = i * 2;
+        plogpal->palPalEntry[i].peGreen = 0;
+        plogpal->palPalEntry[255 - i].peRed = 0;
+        plogpal->palPalEntry[255 - i].peGreen = i * 2;
+        plogpal->palPalEntry[255 - i].peBlue = 255 - i * 2;
+    }
+
+    index = (WORD*)pbmi->bmiColors;
+    for (i = 0; i < 256; i++) {
+        *index++ = i;
+    }
+
+    hpal = CreatePalette(plogpal);
+    ok(hpal != NULL, "CreatePalette failed\n");
+    oldpal = SelectPalette(hdc, hpal, TRUE);
+    hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
+    ok(hdib != NULL, "CreateDIBSection failed\n");
+
+    SelectPalette(hdc, oldpal, TRUE);
+    oldbm = SelectObject(hdcmem, hdib);
+    oldpal = SelectPalette(hdcmem, hpal, TRUE);
+
+    ret = GetDIBColorTable(hdcmem, 0, 256, rgb);
+    ok(ret == 256, "GetDIBColorTable returned %d\n", ret);
+    for (i = 0; i < 256; i++) {
+        ok(rgb[i].rgbRed == plogpal->palPalEntry[i].peRed && 
+            rgb[i].rgbBlue == plogpal->palPalEntry[i].peBlue && 
+            rgb[i].rgbGreen == plogpal->palPalEntry[i].peGreen, 
+            "GetDIBColorTable returns table %d: r%02x g%02x b%02x res%02x\n",
+            i, rgb[i].rgbRed, rgb[i].rgbGreen, rgb[i].rgbBlue, rgb[i].rgbReserved);
+    }
+
+    for (i = 0; i < 256; i++) {
+        test_color(hdcmem, DIBINDEX(i), 
+            RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
+        test_color(hdcmem, PALETTEINDEX(i), 
+            RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
+        test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 
+            RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
+    }
+
+    SelectPalette(hdcmem, oldpal, TRUE);
+    SelectObject(hdcmem, oldbm);
+    DeleteObject(hdib);
+    DeleteObject(hpal);
+
+
+    DeleteDC(hdcmem);
+    ReleaseDC(0, hdc);
+}    
+
+START_TEST(bitmap)
+{
+    HWND hWnd;
+
+    hWnd = CreateWindowExA(0, "EDIT", NULL, 0,
+                           10, 10, 300, 300,
+                           NULL, NULL, NULL, NULL);
+    assert(hWnd);
+    is_win9x = GetWindowLongW(hWnd, GWL_WNDPROC) == 0;
+    DestroyWindow(hWnd);
+
+    test_createdibitmap();
+    test_dibsections();
+}
diff --git a/reactos/regtests/winetests/gdi32/brush.c b/reactos/regtests/winetests/gdi32/brush.c
new file mode 100755 (executable)
index 0000000..f4e22b6
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Unit test suite for brushes
+ *
+ * Copyright 2004 Kevin Koltzau
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <stdarg.h>
+
+#include "windef.h"
+#include "winbase.h"
+#include "wingdi.h"
+
+#include "wine/test.h"
+
+typedef struct _STOCK_BRUSH {
+    COLORREF color;
+    int stockobj;
+    const char *name;
+} STOCK_BRUSH;
+
+static void test_solidbrush(void)
+{
+    static const STOCK_BRUSH stock[] = {
+        {RGB(255,255,255), WHITE_BRUSH, "white"},
+        {RGB(192,192,192), LTGRAY_BRUSH, "ltgray"},
+        {RGB(128,128,128), GRAY_BRUSH, "gray"},
+        {RGB(0,0,0), BLACK_BRUSH, "black"},
+        {RGB(0,0,255), -1, "blue"}
+    };
+    HBRUSH solidBrush;
+    HBRUSH stockBrush;
+    LOGBRUSH br;
+    size_t i;
+    INT ret;
+
+    for(i=0; i<sizeof(stock)/sizeof(stock[0]); i++) {
+        solidBrush = CreateSolidBrush(stock[i].color);
+        
+        if(stock[i].stockobj != -1) {
+            stockBrush = (HBRUSH)GetStockObject(stock[i].stockobj);
+            ok(stockBrush!=solidBrush, "Stock %s brush equals solid %s brush\n", stock[i].name, stock[i].name);
+        }
+        else
+            stockBrush = NULL;
+        memset(&br, sizeof(br), 0);
+        ret = GetObject(solidBrush, sizeof(br), &br);
+        ok( ret !=0, "GetObject on solid %s brush failed, error=%ld\n", stock[i].name, GetLastError());
+        ok(br.lbStyle==BS_SOLID, "%s brush has wrong style, got %d expected %d\n", stock[i].name, br.lbStyle, BS_SOLID);
+        ok(br.lbColor==stock[i].color, "%s brush has wrong color, got 0x%08lx expected 0x%08lx\n", stock[i].name, br.lbColor, stock[i].color);
+        
+        if(stockBrush) {
+            /* Sanity check, make sure the colors being compared do in fact have a stock brush */
+            ret = GetObject(stockBrush, sizeof(br), &br);
+            ok( ret !=0, "GetObject on stock %s brush failed, error=%ld\n", stock[i].name, GetLastError());
+            ok(br.lbColor==stock[i].color, "stock %s brush unexpected color, got 0x%08lx expected 0x%08lx\n", stock[i].name, br.lbColor, stock[i].color);
+        }
+
+        DeleteObject(solidBrush);
+        ok(GetObject(solidBrush, sizeof(br), &br)==0, "GetObject succeeded on a deleted %s brush\n", stock[i].name);
+    }
+}
+START_TEST(brush)
+{
+    test_solidbrush();
+}
diff --git a/reactos/regtests/winetests/gdi32/gdi32_test.xml b/reactos/regtests/winetests/gdi32/gdi32_test.xml
new file mode 100644 (file)
index 0000000..d0d0d0a
--- /dev/null
@@ -0,0 +1,11 @@
+<module name="gdi32_test" type="win32cui" installbase="bin" installname="gdi32_test.exe" warnings="true">
+    <include base="gdi32_test">.</include>
+    <define name="__USE_W32API" />
+    <library>ntdll</library>
+    <library>gdi32</library>
+    <file>bitmap.c</file>
+    <file>brush.c</file>
+    <file>gdiobj.c</file>
+    <file>metafile.c</file>
+    <file>testlist.c</file>
+</module>
diff --git a/reactos/regtests/winetests/gdi32/gdiobj.c b/reactos/regtests/winetests/gdi32/gdiobj.c
new file mode 100755 (executable)
index 0000000..deed86f
--- /dev/null
@@ -0,0 +1,335 @@
+/*
+ * Unit test suite for GDI objects
+ *
+ * Copyright 2002 Mike McCormack
+ * Copyright 2004 Dmitry Timoshkov
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <stdarg.h>
+
+#include "windef.h"
+#include "winbase.h"
+#include "wingdi.h"
+#include "winuser.h"
+
+#include "wine/test.h"
+
+
+static void check_font(const char* test, const LOGFONTA* lf, HFONT hfont)
+{
+    LOGFONTA getobj_lf;
+    int ret, minlen = 0;
+
+    if (!hfont)
+        return;
+
+    ret = GetObject(hfont, sizeof(getobj_lf), &getobj_lf);
+    /* NT4 tries to be clever and only returns the minimum length */
+    while (lf->lfFaceName[minlen] && minlen < LF_FACESIZE-1)
+        minlen++;
+    minlen += FIELD_OFFSET(LOGFONTA, lfFaceName) + 1;
+    ok(ret == sizeof(LOGFONTA) || ret == minlen,
+       "%s: GetObject returned %d expected %d or %d\n", test, ret, sizeof(LOGFONTA), minlen);
+    ok(!memcmp(&lf, &lf, FIELD_OFFSET(LOGFONTA, lfFaceName)), "%s: fonts don't match\n", test);
+    ok(!lstrcmpA(lf->lfFaceName, getobj_lf.lfFaceName),
+       "%s: font names don't match: %s != %s\n", test, lf->lfFaceName, getobj_lf.lfFaceName);
+}
+
+static HFONT create_font(const char* test, const LOGFONTA* lf)
+{
+    HFONT hfont = CreateFontIndirectA(lf);
+    ok(hfont != 0, "%s: CreateFontIndirect failed\n", test);
+    if (hfont)
+        check_font(test, lf, hfont);
+    return hfont;
+}
+
+static void test_logfont(void)
+{
+    LOGFONTA lf;
+    HFONT hfont;
+
+    memset(&lf, 0, sizeof lf);
+
+    lf.lfCharSet = ANSI_CHARSET;
+    lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
+    lf.lfWeight = FW_DONTCARE;
+    lf.lfHeight = 16;
+    lf.lfWidth = 16;
+    lf.lfQuality = DEFAULT_QUALITY;
+
+    lstrcpyA(lf.lfFaceName, "Arial");
+    hfont = create_font("Arial", &lf);
+    DeleteObject(hfont);
+
+    memset(&lf, 'A', sizeof(lf));
+    hfont = CreateFontIndirectA(&lf);
+    ok(hfont != 0, "CreateFontIndirectA with strange LOGFONT failed\n");
+    
+    lf.lfFaceName[LF_FACESIZE - 1] = 0;
+    check_font("AAA...", &lf, hfont);
+    DeleteObject(hfont);
+}
+
+static INT CALLBACK font_enum_proc(const LOGFONT *elf, const TEXTMETRIC *ntm, DWORD type, LPARAM lParam)
+{
+    if (type & RASTER_FONTTYPE)
+    {
+       LOGFONT *lf = (LOGFONT *)lParam;
+       *lf = *elf;
+       return 0; /* stop enumeration */
+    }
+
+    return 1; /* continue enumeration */
+}
+
+static void test_font_metrics(HDC hdc, HFONT hfont, const char *test_str,
+                             INT test_str_len, const TEXTMETRICA *tm_orig,
+                             const SIZE *size_orig, INT width_orig,
+                             INT scale_x, INT scale_y)
+{
+    HFONT old_hfont;
+    TEXTMETRICA tm;
+    SIZE size;
+    INT width;
+
+    if (!hfont)
+        return;
+
+    old_hfont = SelectObject(hdc, hfont);
+
+    GetTextMetricsA(hdc, &tm);
+
+    ok(tm.tmHeight == tm_orig->tmHeight * scale_y, "%ld != %ld\n", tm.tmHeight, tm_orig->tmHeight * scale_y);
+    ok(tm.tmAscent == tm_orig->tmAscent * scale_y, "%ld != %ld\n", tm.tmAscent, tm_orig->tmAscent * scale_y);
+    ok(tm.tmDescent == tm_orig->tmDescent * scale_y, "%ld != %ld\n", tm.tmDescent, tm_orig->tmDescent * scale_y);
+    ok(tm.tmAveCharWidth == tm_orig->tmAveCharWidth * scale_x, "%ld != %ld\n", tm.tmAveCharWidth, tm_orig->tmAveCharWidth * scale_x);
+
+    GetTextExtentPoint32A(hdc, test_str, test_str_len, &size);
+
+    ok(size.cx == size_orig->cx * scale_x, "%ld != %ld\n", size.cx, size_orig->cx * scale_x);
+    ok(size.cy == size_orig->cy * scale_y, "%ld != %ld\n", size.cy, size_orig->cy * scale_y);
+
+    GetCharWidthA(hdc, 'A', 'A', &width);
+
+    ok(width == width_orig * scale_x, "%d != %d\n", width, width_orig * scale_x);
+
+    SelectObject(hdc, old_hfont);
+}
+
+/* see whether GDI scales bitmap font metrics */
+static void test_bitmap_font(void)
+{
+    static const char test_str[11] = "Test String";
+    HDC hdc;
+    LOGFONTA bitmap_lf;
+    HFONT hfont, old_hfont;
+    TEXTMETRICA tm_orig;
+    SIZE size_orig;
+    INT ret, i, width_orig, height_orig;
+
+    hdc = GetDC(0);
+
+    /* "System" has only 1 pixel size defined, otherwise the test breaks */
+    ret = EnumFontFamiliesA(hdc, "System", font_enum_proc, (LPARAM)&bitmap_lf);
+    if (ret)
+    {
+       ReleaseDC(0, hdc);
+       trace("no bitmap fonts were found, skipping the test\n");
+       return;
+    }
+
+    trace("found bitmap font %s, height %ld\n", bitmap_lf.lfFaceName, bitmap_lf.lfHeight);
+
+    height_orig = bitmap_lf.lfHeight;
+    hfont = create_font("bitmap", &bitmap_lf);
+
+    old_hfont = SelectObject(hdc, hfont);
+    ok(GetTextMetricsA(hdc, &tm_orig), "GetTextMetricsA failed\n");
+    ok(GetTextExtentPoint32A(hdc, test_str, sizeof(test_str), &size_orig), "GetTextExtentPoint32A failed\n");
+    ok(GetCharWidthA(hdc, 'A', 'A', &width_orig), "GetCharWidthA failed\n");
+    SelectObject(hdc, old_hfont);
+    DeleteObject(hfont);
+
+    /* test fractional scaling */
+    for (i = 1; i < height_orig; i++)
+    {
+       hfont = create_font("fractional", &bitmap_lf);
+       test_font_metrics(hdc, hfont, test_str, sizeof(test_str), &tm_orig, &size_orig, width_orig, 1, 1);
+       DeleteObject(hfont);
+    }
+
+    /* test integer scaling 3x2 */
+    bitmap_lf.lfHeight = height_orig * 2;
+    bitmap_lf.lfWidth *= 3;
+    hfont = create_font("3x2", &bitmap_lf);
+todo_wine
+{
+    test_font_metrics(hdc, hfont, test_str, sizeof(test_str), &tm_orig, &size_orig, width_orig, 3, 2);
+}
+    DeleteObject(hfont);
+
+    /* test integer scaling 3x3 */
+    bitmap_lf.lfHeight = height_orig * 3;
+    bitmap_lf.lfWidth = 0;
+    hfont = create_font("3x3", &bitmap_lf);
+
+todo_wine
+{
+    test_font_metrics(hdc, hfont, test_str, sizeof(test_str), &tm_orig, &size_orig, width_orig, 3, 3);
+}
+    DeleteObject(hfont);
+
+    ReleaseDC(0, hdc);
+}
+
+static void test_gdi_objects(void)
+{
+    BYTE buff[256];
+    HDC hdc = GetDC(NULL);
+    HPEN hp;
+    int i;
+    BOOL ret;
+
+    /* SelectObject() with a NULL DC returns 0 and sets ERROR_INVALID_HANDLE.
+     * Note: Under XP at least invalid ptrs can also be passed, not just NULL;
+     *       Don't test that here in case it crashes earlier win versions.
+     */
+    SetLastError(0);
+    hp = SelectObject(NULL, GetStockObject(BLACK_PEN));
+    ok(!hp && GetLastError() == ERROR_INVALID_HANDLE,
+       "SelectObject(NULL DC) expected 0, ERROR_INVALID_HANDLE, got %p, 0x%08lx\n",
+       hp, GetLastError());
+
+    /* With a valid DC and a NULL object, the call returns 0 but does not SetLastError() */
+    SetLastError(0);
+    hp = SelectObject(hdc, NULL);
+    ok(!hp && !GetLastError(),
+       "SelectObject(NULL obj) expected 0, NO_ERROR, got %p, 0x%08lx\n",
+       hp, GetLastError());
+
+    /* The DC is unaffected by the NULL SelectObject */
+    SetLastError(0);
+    hp = SelectObject(hdc, GetStockObject(BLACK_PEN));
+    ok(hp && !GetLastError(),
+       "SelectObject(post NULL) expected non-null, NO_ERROR, got %p, 0x%08lx\n",
+       hp, GetLastError());
+
+    /* GetCurrentObject does not SetLastError() on a null object */
+    SetLastError(0);
+    hp = GetCurrentObject(NULL, OBJ_PEN);
+    ok(!hp && !GetLastError(),
+       "GetCurrentObject(NULL DC) expected 0, NO_ERROR, got %p, 0x%08lx\n",
+       hp, GetLastError());
+
+    /* DeleteObject does not SetLastError() on a null object */
+    ret = DeleteObject(NULL);
+    ok( !ret && !GetLastError(),
+       "DeleteObject(NULL obj), expected 0, NO_ERROR, got %d, 0x%08lx\n",
+       ret, GetLastError());
+
+    /* GetObject does not SetLastError() on a null object */
+    SetLastError(0);
+    i = GetObjectA(NULL, sizeof(buff), buff);
+    ok (!i && !GetLastError(),
+        "GetObject(NULL obj), expected 0, NO_ERROR, got %d, 0x%08lx\n",
+       i, GetLastError());
+
+    /* GetObjectType does SetLastError() on a null object */
+    SetLastError(0);
+    i = GetObjectType(NULL);
+    ok (!i && GetLastError() == ERROR_INVALID_HANDLE,
+        "GetObjectType(NULL obj), expected 0, ERROR_INVALID_HANDLE, got %d, 0x%08lx\n",
+        i, GetLastError());
+
+    /* UnrealizeObject does not SetLastError() on a null object */
+    SetLastError(0);
+    i = UnrealizeObject(NULL);
+    ok (!i && !GetLastError(),
+        "UnrealizeObject(NULL obj), expected 0, NO_ERROR, got %d, 0x%08lx\n",
+        i, GetLastError());
+
+    ReleaseDC(NULL, hdc);
+}
+
+static void test_GdiGetCharDimensions(void)
+{
+    HDC hdc;
+    TEXTMETRICW tm;
+    LONG ret;
+    SIZE size;
+    LONG avgwidth, height;
+    static const char szAlphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+    typedef LONG (WINAPI *fnGdiGetCharDimensions)(HDC hdc, LPTEXTMETRICW lptm, LONG *height);
+    fnGdiGetCharDimensions GdiGetCharDimensions = (fnGdiGetCharDimensions)GetProcAddress(LoadLibrary("gdi32"), "GdiGetCharDimensions");
+    if (!GdiGetCharDimensions) return;
+
+    hdc = CreateCompatibleDC(NULL);
+
+    GetTextExtentPoint(hdc, szAlphabet, strlen(szAlphabet), &size);
+    avgwidth = ((size.cx / 26) + 1) / 2;
+
+    ret = GdiGetCharDimensions(hdc, &tm, &height);
+    ok(ret == avgwidth, "GdiGetCharDimensions should have returned width of %ld instead of %ld\n", avgwidth, ret);
+    ok(height == tm.tmHeight, "GdiGetCharDimensions should have set height to %ld instead of %ld\n", tm.tmHeight, height);
+
+    ret = GdiGetCharDimensions(hdc, &tm, NULL);
+    ok(ret == avgwidth, "GdiGetCharDimensions should have returned width of %ld instead of %ld\n", avgwidth, ret);
+
+    ret = GdiGetCharDimensions(hdc, NULL, NULL);
+    ok(ret == avgwidth, "GdiGetCharDimensions should have returned width of %ld instead of %ld\n", avgwidth, ret);
+
+    height = 0;
+    ret = GdiGetCharDimensions(hdc, NULL, &height);
+    ok(ret == avgwidth, "GdiGetCharDimensions should have returned width of %ld instead of %ld\n", avgwidth, ret);
+    ok(height == size.cy, "GdiGetCharDimensions should have set height to %ld instead of %ld\n", size.cy, height);
+
+    DeleteDC(hdc);
+}
+
+static void test_text_extents(void)
+{
+    LOGFONTA lf;
+    TEXTMETRICA tm;
+    HDC hdc;
+    HFONT hfont;
+    SIZE sz;
+
+    memset(&lf, 0, sizeof(lf));
+    strcpy(lf.lfFaceName, "Arial");
+    lf.lfHeight = 20;
+
+    hfont = CreateFontIndirectA(&lf);
+    hdc = GetDC(0);
+    hfont = SelectObject(hdc, hfont);
+    GetTextMetricsA(hdc, &tm);
+    GetTextExtentPointA(hdc, "o", 1, &sz);
+    ok(sz.cy == tm.tmHeight, "cy %ld tmHeight %ld\n", sz.cy, tm.tmHeight);
+
+    SelectObject(hdc, hfont);
+    DeleteObject(hfont);
+    ReleaseDC(NULL, hdc);
+}
+
+START_TEST(gdiobj)
+{
+    test_logfont();
+    test_bitmap_font();
+    test_gdi_objects();
+    test_GdiGetCharDimensions();
+    test_text_extents();
+}
diff --git a/reactos/regtests/winetests/gdi32/metafile.c b/reactos/regtests/winetests/gdi32/metafile.c
new file mode 100755 (executable)
index 0000000..17f0138
--- /dev/null
@@ -0,0 +1,612 @@
+/*
+ * Unit tests for metafile functions
+ *
+ * Copyright (c) 2002 Dmitry Timoshkov
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <assert.h>
+#include <stdio.h>
+#include <math.h>
+
+#include "wine/test.h"
+#include "winbase.h"
+#include "wingdi.h"
+#include "winuser.h"
+#include "winerror.h"
+
+static LOGFONTA orig_lf;
+static BOOL emr_processed = FALSE;
+
+/* Arbitrarily chosen values for the second co-ordinate of a metafile line */
+#define LINE_X 55.0f
+#define LINE_Y 15.0f
+
+static int CALLBACK emf_enum_proc(HDC hdc, HANDLETABLE *handle_table,
+    const ENHMETARECORD *emr, int n_objs, LPARAM param)
+{
+    static int n_record;
+    DWORD i;
+    const INT *dx;
+    INT *orig_dx = (INT *)param;
+    LOGFONTA device_lf;
+    INT ret;
+
+    trace("hdc %p, emr->iType %ld, emr->nSize %ld, param %p\n",
+           hdc, emr->iType, emr->nSize, (void *)param);
+
+    if(!hdc) return 1;
+
+    PlayEnhMetaFileRecord(hdc, handle_table, emr, n_objs);
+
+    switch (emr->iType)
+    {
+    case EMR_HEADER:
+        n_record = 0;
+        break;
+
+    case EMR_EXTTEXTOUTA:
+    {
+        const EMREXTTEXTOUTA *emr_ExtTextOutA = (const EMREXTTEXTOUTA *)emr;
+        dx = (const INT *)((const char *)emr + emr_ExtTextOutA->emrtext.offDx);
+
+        ret = GetObjectA(GetCurrentObject(hdc, OBJ_FONT), sizeof(device_lf), &device_lf);
+        ok( ret == sizeof(device_lf), "GetObjectA error %ld\n", GetLastError());
+
+        /* compare up to lfOutPrecision, other values are not interesting,
+         * and in fact sometimes arbitrary adapted by Win9x.
+         */
+        ok(!memcmp(&orig_lf, &device_lf, FIELD_OFFSET(LOGFONTA, lfOutPrecision)), "fonts don't match\n");
+        ok(!lstrcmpA(orig_lf.lfFaceName, device_lf.lfFaceName), "font names don't match\n");
+
+        for(i = 0; i < emr_ExtTextOutA->emrtext.nChars; i++)
+        {
+            ok(orig_dx[i] == dx[i], "pass %d: dx[%ld] (%d) didn't match %d\n",
+                                     n_record, i, dx[i], orig_dx[i]);
+        }
+        n_record++;
+        emr_processed = TRUE;
+        break;
+    }
+
+    case EMR_EXTTEXTOUTW:
+    {
+        const EMREXTTEXTOUTW *emr_ExtTextOutW = (const EMREXTTEXTOUTW *)emr;
+        dx = (const INT *)((const char *)emr + emr_ExtTextOutW->emrtext.offDx);
+
+        ret = GetObjectA(GetCurrentObject(hdc, OBJ_FONT), sizeof(device_lf), &device_lf);
+        ok( ret == sizeof(device_lf), "GetObjectA error %ld\n", GetLastError());
+
+        /* compare up to lfOutPrecision, other values are not interesting,
+         * and in fact sometimes arbitrary adapted by Win9x.
+         */
+        ok(!memcmp(&orig_lf, &device_lf, FIELD_OFFSET(LOGFONTA, lfOutPrecision)), "fonts don't match\n");
+        ok(!lstrcmpA(orig_lf.lfFaceName, device_lf.lfFaceName), "font names don't match\n");
+
+        for(i = 0; i < emr_ExtTextOutW->emrtext.nChars; i++)
+        {
+            ok(orig_dx[i] == dx[i], "pass %d: dx[%ld] (%d) didn't match %d\n",
+                                     n_record, i, dx[i], orig_dx[i]);
+        }
+        n_record++;
+        emr_processed = TRUE;
+        break;
+    }
+
+    default:
+        break;
+    }
+
+    return 1;
+}
+
+static void test_ExtTextOut(void)
+{
+    HWND hwnd;
+    HDC hdcDisplay, hdcMetafile;
+    HENHMETAFILE hMetafile;
+    HFONT hFont;
+    static const char text[] = "Simple text to test ExtTextOut on metafiles";
+    INT i, len, dx[256];
+    static const RECT rc = { 0, 0, 100, 100 };
+    BOOL ret;
+
+    assert(sizeof(dx)/sizeof(dx[0]) >= lstrlenA(text));
+
+    /* Win9x doesn't play EMFs on invisible windows */
+    hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP | WS_VISIBLE,
+                           0, 0, 200, 200, 0, 0, 0, NULL);
+    ok(hwnd != 0, "CreateWindowExA error %ld\n", GetLastError());
+
+    hdcDisplay = GetDC(hwnd);
+    ok(hdcDisplay != 0, "GetDC error %ld\n", GetLastError());
+
+    trace("hdcDisplay %p\n", hdcDisplay);
+
+    SetMapMode(hdcDisplay, MM_TEXT);
+
+    memset(&orig_lf, 0, sizeof(orig_lf));
+
+    orig_lf.lfCharSet = ANSI_CHARSET;
+    orig_lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
+    orig_lf.lfWeight = FW_DONTCARE;
+    orig_lf.lfHeight = 7;
+    orig_lf.lfQuality = DEFAULT_QUALITY;
+    lstrcpyA(orig_lf.lfFaceName, "Arial");
+    hFont = CreateFontIndirectA(&orig_lf);
+    ok(hFont != 0, "CreateFontIndirectA error %ld\n", GetLastError());
+
+    hFont = SelectObject(hdcDisplay, hFont);
+
+    len = lstrlenA(text);
+    for (i = 0; i < len; i++)
+    {
+        ret = GetCharWidthA(hdcDisplay, text[i], text[i], &dx[i]);
+        ok( ret, "GetCharWidthA error %ld\n", GetLastError());
+    }
+    hFont = SelectObject(hdcDisplay, hFont);
+
+    hdcMetafile = CreateEnhMetaFileA(hdcDisplay, NULL, NULL, NULL);
+    ok(hdcMetafile != 0, "CreateEnhMetaFileA error %ld\n", GetLastError());
+
+    trace("hdcMetafile %p\n", hdcMetafile);
+
+    ok(GetDeviceCaps(hdcMetafile, TECHNOLOGY) == DT_RASDISPLAY,
+       "GetDeviceCaps(TECHNOLOGY) has to return DT_RASDISPLAY for a display based EMF\n");
+
+    hFont = SelectObject(hdcMetafile, hFont);
+
+    /* 1. pass NULL lpDx */
+    ret = ExtTextOutA(hdcMetafile, 0, 0, 0, &rc, text, lstrlenA(text), NULL);
+    ok( ret, "ExtTextOutA error %ld\n", GetLastError());
+
+    /* 2. pass custom lpDx */
+    ret = ExtTextOutA(hdcMetafile, 0, 20, 0, &rc, text, lstrlenA(text), dx);
+    ok( ret, "ExtTextOutA error %ld\n", GetLastError());
+
+    hFont = SelectObject(hdcMetafile, hFont);
+    ret = DeleteObject(hFont);
+    ok( ret, "DeleteObject error %ld\n", GetLastError());
+
+    hMetafile = CloseEnhMetaFile(hdcMetafile);
+    ok(hMetafile != 0, "CloseEnhMetaFile error %ld\n", GetLastError());
+
+    ok(!GetObjectType(hdcMetafile), "CloseEnhMetaFile has to destroy metafile hdc\n");
+
+    ret = PlayEnhMetaFile(hdcDisplay, hMetafile, &rc);
+    ok( ret, "PlayEnhMetaFile error %ld\n", GetLastError());
+
+    ret = EnumEnhMetaFile(hdcDisplay, hMetafile, emf_enum_proc, dx, &rc);
+    ok( ret, "EnumEnhMetaFile error %ld\n", GetLastError());
+
+    ok(emr_processed, "EnumEnhMetaFile couldn't find EMR_EXTTEXTOUTA or EMR_EXTTEXTOUTW record\n");
+
+    ok(!EnumEnhMetaFile(hdcDisplay, hMetafile, emf_enum_proc, dx, NULL),
+       "A valid hdc has to require a valid rc\n");
+
+    ok(EnumEnhMetaFile(NULL, hMetafile, emf_enum_proc, dx, NULL),
+       "A null hdc does not require a valid rc\n");
+
+    ret = DeleteEnhMetaFile(hMetafile);
+    ok( ret, "DeleteEnhMetaFile error %ld\n", GetLastError());
+    ret = ReleaseDC(hwnd, hdcDisplay);
+    ok( ret, "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, 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<mfsize; i++)
+    {
+        printf ("0x%.2hhx", buf[i]);
+        if (i == mfsize-1)
+            printf ("\n");
+        else if (i % 8 == 7)
+            printf (",\n    ");
+        else
+            printf (", ");
+    }
+    printf ("};\n");
+}
+
+/* Compare the metafile produced by a test function with the
+ * expected raw metafile data in "bits".
+ * Return value is 0 for a perfect match,
+ * -1 if lengths aren't equal,
+ * otherwise returns the number of non-matching bytes.
+ */
+
+static int compare_mf_bits (const HMETAFILE mf, const char *bits, UINT bsize,
+    const char *desc)
+{
+    char buf[MF_BUFSIZE];
+    UINT mfsize, i;
+    int diff;
+
+    mfsize = GetMetaFileBitsEx (mf, MF_BUFSIZE, buf);
+    ok (mfsize > 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; i<bsize; i++)
+    {
+       if (buf[i] !=  bits[i])
+           diff++;
+    }
+    ok (diff == 0, "%s: mfsize=%d, bsize=%d, diff=%d\n",
+        desc, mfsize, bsize, diff);
+
+    return diff; 
+}
+
+/* Test a blank metafile.  May be used as a template for new tests. */
+
+static void test_mf_Blank(void)
+{
+    HDC hdcMetafile;
+    HMETAFILE hMetafile;
+    INT caps;
+    BOOL ret;
+
+    hdcMetafile = CreateMetaFileA(NULL);
+    ok(hdcMetafile != 0, "CreateMetaFileA(NULL) error %ld\n", GetLastError());
+    trace("hdcMetafile %p\n", hdcMetafile);
+
+/* Tests on metafile initialization */
+    caps = GetDeviceCaps (hdcMetafile, TECHNOLOGY);
+    ok (caps == DT_METAFILE,
+        "GetDeviceCaps: TECHNOLOGY=%d != DT_METAFILE.\n", caps);
+
+    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_BLANK_BITS, sizeof(MF_BLANK_BITS),
+        "mf_blank") != 0)
+            dump_mf_bits (hMetafile, "mf_Blank");
+
+    ret = DeleteMetaFile(hMetafile);
+    ok( ret, "DeleteMetaFile(%p) error %ld\n", hMetafile, GetLastError());
+}
+
+/* Simple APIs from mfdrv/graphics.c
+ */
+
+static void test_mf_Graphics(void)
+{
+    HDC hdcMetafile;
+    HMETAFILE hMetafile;
+    POINT oldpoint;
+    BOOL ret;
+
+    hdcMetafile = CreateMetaFileA(NULL);
+    ok(hdcMetafile != 0, "CreateMetaFileA(NULL) error %ld\n", GetLastError());
+    trace("hdcMetafile %p\n", hdcMetafile);
+
+    ret = MoveToEx(hdcMetafile, 1, 1, NULL);
+    ok( ret, "MoveToEx error %ld.\n", GetLastError());
+    ret = LineTo(hdcMetafile, 2, 2);
+    ok( ret, "LineTo error %ld.\n", GetLastError());
+    ret = MoveToEx(hdcMetafile, 1, 1, &oldpoint);
+    ok( ret, "MoveToEx error %ld.\n", GetLastError());
+
+/* oldpoint gets garbage under Win XP, so the following test would
+ * work under Wine but fails under Windows:
+ *
+ *   ok((oldpoint.x == 2) && (oldpoint.y == 2),
+ *       "MoveToEx: (x, y) = (%ld, %ld), should be (2, 2).\n",
+ *       oldpoint.x, oldpoint.y);
+ */
+
+    ret = Ellipse(hdcMetafile, 0, 0, 2, 2);
+    ok( ret, "Ellipse 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_GRAPHICS_BITS, sizeof(MF_GRAPHICS_BITS),
+        "mf_Graphics") != 0)
+            dump_mf_bits (hMetafile, "mf_Graphics");
+
+    ret = DeleteMetaFile(hMetafile);
+    ok( ret, "DeleteMetaFile(%p) error %ld\n",
+        hMetafile, GetLastError());
+}
+
+static void test_mf_PatternBrush(void)
+{
+    HDC hdcMetafile;
+    HMETAFILE hMetafile;
+    LOGBRUSH *orig_lb;
+    HBRUSH hBrush;
+    BOOL ret;
+
+    orig_lb = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LOGBRUSH));
+
+    orig_lb->lbStyle = 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");
+
+    ret = DeleteMetaFile(hMetafile);
+    ok( ret, "DeleteMetaFile error %ld\n", GetLastError());
+    ret = DeleteObject(hBrush);
+    ok( ret, "DeleteObject(HBRUSH) error %ld\n", GetLastError());
+    ret = DeleteObject((HBITMAP *)orig_lb->lbHatch);
+    ok( ret, "DeleteObject(HBITMAP) error %ld\n",
+        GetLastError());
+    HeapFree (GetProcessHeap(), 0, orig_lb);
+}
+
+static INT CALLBACK EmfEnumProc(HDC hdc, HANDLETABLE *lpHTable, const ENHMETARECORD *lpEMFR, INT nObj, LPARAM lpData)
+{
+    LPMETAFILEPICT lpMFP = (LPMETAFILEPICT)lpData;
+    POINT mapping[2] = { { 0, 0 }, { 10, 10 } };
+    /* When using MM_TEXT Win9x does not update the mapping mode 
+     * until a record is played which actually outputs something */
+    PlayEnhMetaFileRecord(hdc, lpHTable, lpEMFR, nObj);
+    LPtoDP(hdc, mapping, 2);
+    trace("Meta record: iType = %ld, (%ld,%ld)-(%ld,%ld)\n", lpEMFR->iType, mapping[0].x, mapping[0].y, mapping[1].x, mapping[1].y);
+    if (lpEMFR->iType == EMR_LINETO)
+    {
+        INT x0, y0, x1, y1;
+        if (!lpMFP || lpMFP->mm == MM_TEXT)
+        {
+            x0 = 0;
+            y0 = 0;
+            x1 = (INT)floor(10 * 100.0 / LINE_X + 0.5);
+            y1 = (INT)floor(10 * 100.0 / LINE_Y + 0.5);
+        }
+        else
+        {
+            ok(lpMFP->mm == MM_ANISOTROPIC, "mm=%ld\n", lpMFP->mm);
+            
+            x0 = MulDiv(0, GetDeviceCaps(hdc, HORZSIZE) * 100, GetDeviceCaps(hdc, HORZRES));
+            y0 = MulDiv(0, GetDeviceCaps(hdc, VERTSIZE) * 100, GetDeviceCaps(hdc, VERTRES));
+            x1 = MulDiv(10, GetDeviceCaps(hdc, HORZSIZE) * 100, GetDeviceCaps(hdc, HORZRES));
+            y1 = MulDiv(10, GetDeviceCaps(hdc, VERTSIZE) * 100, GetDeviceCaps(hdc, VERTRES));
+        }
+        ok(mapping[0].x == x0 && mapping[0].y == y0 && mapping[1].x == x1 && mapping[1].y == y1,
+            "(%ld,%ld)->(%ld,%ld), expected (%d,%d)->(%d,%d)\n",
+            mapping[0].x, mapping[0].y, mapping[1].x, mapping[1].y,
+            x0, y0, x1, y1);
+    }
+    return TRUE;
+}
+
+static HENHMETAFILE create_converted_emf(const METAFILEPICT *mfp)
+{
+    HDC hdcMf;
+    HMETAFILE hmf;
+    BOOL ret;
+    UINT size;
+    LPBYTE pBits;
+
+    hdcMf = CreateMetaFile(NULL);
+    ok(hdcMf != NULL, "CreateMetaFile failed with error %ld\n", GetLastError());
+    ret = LineTo(hdcMf, (INT)LINE_X, (INT)LINE_Y);
+    ok(ret, "LineTo failed with error %ld\n", GetLastError());
+    hmf = CloseMetaFile(hdcMf);
+    ok(hmf != NULL, "CloseMetaFile failed with error %ld\n", GetLastError());
+    size = GetMetaFileBitsEx(hmf, 0, NULL);
+    ok(size, "GetMetaFileBitsEx failed with error %ld\n", GetLastError());
+    pBits = HeapAlloc(GetProcessHeap(), 0, size);
+    GetMetaFileBitsEx(hmf, size, pBits);
+    DeleteMetaFile(hmf);
+    return SetWinMetaFileBits(size, pBits, NULL, mfp);
+}
+
+static void test_mf_conversions(void)
+{
+    trace("Testing MF->EMF conversion (MM_ANISOTROPIC)\n");
+    {
+        HDC hdcOffscreen = CreateCompatibleDC(NULL);
+        HENHMETAFILE hemf;
+        METAFILEPICT mfp;
+        RECT rect = { 0, 0, 100, 100 };
+        mfp.mm = MM_ANISOTROPIC;
+        mfp.xExt = 100;
+        mfp.yExt = 100;
+        mfp.hMF = NULL;
+        hemf = create_converted_emf(&mfp);
+        EnumEnhMetaFile(hdcOffscreen, hemf, EmfEnumProc, &mfp, &rect);
+        DeleteEnhMetaFile(hemf);
+        DeleteDC(hdcOffscreen);
+    }
+
+    trace("Testing MF->EMF conversion (MM_TEXT)\n");
+    {
+        HDC hdcOffscreen = CreateCompatibleDC(NULL);
+        HENHMETAFILE hemf;
+        METAFILEPICT mfp;
+        RECT rect = { 0, 0, 100, 100 };
+        mfp.mm = MM_TEXT;
+        mfp.xExt = 0;
+        mfp.yExt = 0;
+        mfp.hMF = NULL;
+        hemf = create_converted_emf(&mfp);
+        EnumEnhMetaFile(hdcOffscreen, hemf, EmfEnumProc, &mfp, &rect);
+        DeleteEnhMetaFile(hemf);
+        DeleteDC(hdcOffscreen);
+    }
+
+    trace("Testing MF->EMF conversion (NULL mfp)\n");
+    {
+        HDC hdcOffscreen = CreateCompatibleDC(NULL);
+        HENHMETAFILE hemf;
+        RECT rect = { 0, 0, 100, 100 };
+        hemf = create_converted_emf(NULL);
+        EnumEnhMetaFile(hdcOffscreen, hemf, EmfEnumProc, NULL, &rect);
+        DeleteEnhMetaFile(hemf);
+        DeleteDC(hdcOffscreen);
+    }
+}
+
+static BOOL (WINAPI *pGdiIsMetaPrintDC)(HDC);
+static BOOL (WINAPI *pGdiIsMetaFileDC)(HDC);
+static BOOL (WINAPI *pGdiIsPlayMetafileDC)(HDC);
+
+static void test_gdiis(void)
+{
+    RECT rect = {0,0,100,100};
+    HDC hdc, hemfDC, hmfDC;
+    HENHMETAFILE hemf;
+    HMODULE hgdi32;
+
+    /* resolve all the functions */
+    hgdi32 = GetModuleHandle("gdi32");
+    pGdiIsMetaPrintDC = (void*) GetProcAddress(hgdi32, "GdiIsMetaPrintDC");
+    pGdiIsMetaFileDC = (void*) GetProcAddress(hgdi32, "GdiIsMetaFileDC");
+    pGdiIsPlayMetafileDC = (void*) GetProcAddress(hgdi32, "GdiIsPlayMetafileDC");
+
+    /* they should all exist or none should exist */
+    if(!pGdiIsMetaPrintDC)
+        return;
+
+    /* try with nothing */
+    ok(!pGdiIsMetaPrintDC(NULL), "ismetaprint with NULL parameter\n");
+    ok(!pGdiIsMetaFileDC(NULL), "ismetafile with NULL parameter\n");
+    ok(!pGdiIsPlayMetafileDC(NULL), "isplaymetafile with NULL parameter\n");
+
+    /* try with a metafile */
+    hmfDC = CreateMetaFile(NULL);
+    ok(!pGdiIsMetaPrintDC(hmfDC), "ismetaprint on metafile\n");
+    ok(pGdiIsMetaFileDC(hmfDC), "ismetafile on metafile\n");
+    ok(!pGdiIsPlayMetafileDC(hmfDC), "isplaymetafile on metafile\n");
+    DeleteObject(CloseMetaFile(hmfDC));
+
+    /* try with an enhanced metafile */
+    hdc = GetDC(NULL);
+    hemfDC = CreateEnhMetaFileW(hdc, NULL, &rect, NULL);
+    ok(hemfDC != NULL, "failed to create emf\n");
+
+    ok(!pGdiIsMetaPrintDC(hemfDC), "ismetaprint on emf\n");
+    ok(pGdiIsMetaFileDC(hemfDC), "ismetafile on emf\n");
+    ok(!pGdiIsPlayMetafileDC(hemfDC), "isplaymetafile on emf\n");
+
+    hemf = CloseEnhMetaFile(hemfDC);
+    ok(hemf != NULL, "failed to close EMF\n");
+    DeleteObject(hemf);
+    ReleaseDC(NULL,hdc);
+}
+
+START_TEST(metafile)
+{
+    /* For enhanced metafiles (enhmfdrv) */
+    test_ExtTextOut();
+
+    /* For win-format metafiles (mfdrv) */
+    test_mf_Blank();
+    test_mf_Graphics();
+    test_mf_PatternBrush();
+
+    /* For metafile conversions */
+    test_mf_conversions();
+
+    test_gdiis();
+}
diff --git a/reactos/regtests/winetests/gdi32/testlist.c b/reactos/regtests/winetests/gdi32/testlist.c
new file mode 100644 (file)
index 0000000..ffbd0d3
--- /dev/null
@@ -0,0 +1,29 @@
+/* stdarg.h is needed for Winelib */
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "windef.h"
+#include "winbase.h"
+
+extern void func_bitmap(void);
+extern void func_brush(void);
+extern void func_gdiobj(void);
+extern void func_metafile(void);
+
+struct test
+{
+    const char *name;
+    void (*func)(void);
+};
+
+static const struct test winetest_testlist[] =
+{
+    { "bitmap", func_bitmap },
+    { "brush", func_brush },
+    { "gdiobj", func_gdiobj },
+    { "metafile", func_metafile },
+    { 0, 0 }
+};
+
+#define WINETEST_WANT_MAIN
+#include "wine/test.h"