Commit beb2dfec authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

gdi32: Add a GdiConvertToDevmodeW test, make it pass under Wine.

parent 2f83e460
......@@ -413,8 +413,12 @@ DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
DEVMODEW *dmW;
WORD dmW_size;
dmW_size = dmA->dmSize + CCHDEVICENAME;
if (dmA->dmSize >= (const char *)dmA->dmFormName - (const char *)dmA + CCHFORMNAME)
dmW_size = dmA->dmSize;
if (dmW_size > sizeof(DEVMODEA))
dmW_size = sizeof(DEVMODEA);
dmW_size += CCHDEVICENAME;
if (dmA->dmSize >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
dmW_size += CCHFORMNAME;
dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
......@@ -425,12 +429,12 @@ DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
/* copy slightly more, to avoid long computations */
memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA->dmSize - CCHDEVICENAME);
if (dmA->dmSize >= (const char *)dmA->dmFormName - (const char *)dmA + CCHFORMNAME)
if (dmA->dmSize >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
{
MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, CCHFORMNAME,
dmW->dmFormName, CCHFORMNAME);
if (dmA->dmSize > (const char *)&dmA->dmLogPixels - (const char *)dmA)
memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA->dmSize - ((const char *)&dmA->dmLogPixels - (const char *)dmA));
if (dmA->dmSize > FIELD_OFFSET(DEVMODEA, dmLogPixels))
memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA->dmSize - FIELD_OFFSET(DEVMODEA, dmLogPixels));
}
if (dmA->dmDriverExtra)
......
......@@ -173,8 +173,58 @@ static void test_savedc(void)
DeleteDC(hdc);
}
static void test_GdiConvertToDevmodeW(void)
{
DEVMODEW * (WINAPI *pGdiConvertToDevmodeW)(const DEVMODEA *);
DEVMODEA dmA;
DEVMODEW *dmW;
BOOL ret;
pGdiConvertToDevmodeW = (void *)GetProcAddress(GetModuleHandleA("gdi32.dll"), "GdiConvertToDevmodeW");
if (!pGdiConvertToDevmodeW)
{
skip("GdiConvertToDevmodeW is not available on this platform\n");
return;
}
ret = EnumDisplaySettingsA(NULL, ENUM_CURRENT_SETTINGS, &dmA);
ok(ret, "EnumDisplaySettingsExA error %u\n", GetLastError());
ok(dmA.dmSize >= FIELD_OFFSET(DEVMODEA, dmICMMethod), "dmSize is too small: %04x\n", dmA.dmSize);
ok(dmA.dmSize <= sizeof(DEVMODEA), "dmSize is too large: %04x\n", dmA.dmSize);
dmW = pGdiConvertToDevmodeW(&dmA);
ok(dmW->dmSize >= FIELD_OFFSET(DEVMODEW, dmICMMethod), "dmSize is too small: %04x\n", dmW->dmSize);
ok(dmW->dmSize <= sizeof(DEVMODEW), "dmSize is too large: %04x\n", dmW->dmSize);
HeapFree(GetProcessHeap(), 0, dmW);
dmA.dmSize = FIELD_OFFSET(DEVMODEA, dmFields) + sizeof(dmA.dmFields);
dmW = pGdiConvertToDevmodeW(&dmA);
ok(dmW->dmSize == FIELD_OFFSET(DEVMODEW, dmFields) + sizeof(dmW->dmFields),
"expected %04x, got %04x\n",
FIELD_OFFSET(DEVMODEW, dmFields) + sizeof(dmW->dmFields), dmW->dmSize);
HeapFree(GetProcessHeap(), 0, dmW);
dmA.dmICMMethod = DMICMMETHOD_NONE;
dmA.dmSize = FIELD_OFFSET(DEVMODEA, dmICMMethod) + sizeof(dmA.dmICMMethod);
dmW = pGdiConvertToDevmodeW(&dmA);
ok(dmW->dmSize == FIELD_OFFSET(DEVMODEW, dmICMMethod) + sizeof(dmW->dmICMMethod),
"expected %04x, got %04x\n",
FIELD_OFFSET(DEVMODEW, dmICMMethod) + sizeof(dmW->dmICMMethod), dmW->dmSize);
ok(dmW->dmICMMethod == DMICMMETHOD_NONE,
"expected DMICMMETHOD_NONE, got %u\n", dmW->dmICMMethod);
HeapFree(GetProcessHeap(), 0, dmW);
dmA.dmSize = 1024;
dmW = pGdiConvertToDevmodeW(&dmA);
ok(dmW->dmSize == FIELD_OFFSET(DEVMODEW, dmPanningHeight) + sizeof(dmW->dmPanningHeight),
"expected %04x, got %04x\n",
FIELD_OFFSET(DEVMODEW, dmPanningHeight) + sizeof(dmW->dmPanningHeight), dmW->dmSize);
HeapFree(GetProcessHeap(), 0, dmW);
}
START_TEST(dc)
{
test_savedc();
test_savedc_2();
test_GdiConvertToDevmodeW();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment