ddraw: Add some NULL pointer tests.

This commit is contained in:
Stefan Dösinger 2011-09-03 21:06:11 +02:00 committed by Alexandre Julliard
parent 252bead280
commit 8e79a7e664
4 changed files with 101 additions and 27 deletions

View File

@ -2308,9 +2308,9 @@ static HRESULT WINAPI ddraw3_EnumDisplayModes(IDirectDraw3 *iface, DWORD flags,
cbcontext.func = callback;
cbcontext.context = context;
DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw7_EnumDisplayModes(&This->IDirectDraw7_iface, flags, &surface_desc2,
&cbcontext, EnumDisplayModesCallbackThunk);
if (surface_desc) DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw7_EnumDisplayModes(&This->IDirectDraw7_iface, flags,
surface_desc ? &surface_desc2 : NULL, &cbcontext, EnumDisplayModesCallbackThunk);
}
static HRESULT WINAPI ddraw2_EnumDisplayModes(IDirectDraw2 *iface, DWORD flags,
@ -2326,9 +2326,9 @@ static HRESULT WINAPI ddraw2_EnumDisplayModes(IDirectDraw2 *iface, DWORD flags,
cbcontext.func = callback;
cbcontext.context = context;
DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw7_EnumDisplayModes(&This->IDirectDraw7_iface, flags, &surface_desc2,
&cbcontext, EnumDisplayModesCallbackThunk);
if (surface_desc) DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw7_EnumDisplayModes(&This->IDirectDraw7_iface, flags,
surface_desc ? &surface_desc2 : NULL, &cbcontext, EnumDisplayModesCallbackThunk);
}
static HRESULT WINAPI ddraw1_EnumDisplayModes(IDirectDraw *iface, DWORD flags,
@ -2344,9 +2344,9 @@ static HRESULT WINAPI ddraw1_EnumDisplayModes(IDirectDraw *iface, DWORD flags,
cbcontext.func = callback;
cbcontext.context = context;
DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw7_EnumDisplayModes(&This->IDirectDraw7_iface, flags, &surface_desc2,
&cbcontext, EnumDisplayModesCallbackThunk);
if (surface_desc) DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw7_EnumDisplayModes(&This->IDirectDraw7_iface, flags,
surface_desc ? &surface_desc2 : NULL, &cbcontext, EnumDisplayModesCallbackThunk);
}
/*****************************************************************************
@ -3730,9 +3730,9 @@ static HRESULT WINAPI ddraw3_EnumSurfaces(IDirectDraw3 *iface, DWORD flags,
cbcontext.func = callback;
cbcontext.context = context;
DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw7_EnumSurfaces(&This->IDirectDraw7_iface, flags, &surface_desc2,
&cbcontext, EnumSurfacesCallbackThunk);
if (surface_desc) DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw7_EnumSurfaces(&This->IDirectDraw7_iface, flags,
surface_desc ? &surface_desc2 : NULL, &cbcontext, EnumSurfacesCallbackThunk);
}
static HRESULT WINAPI ddraw2_EnumSurfaces(IDirectDraw2 *iface, DWORD flags,
@ -3748,9 +3748,9 @@ static HRESULT WINAPI ddraw2_EnumSurfaces(IDirectDraw2 *iface, DWORD flags,
cbcontext.func = callback;
cbcontext.context = context;
DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw7_EnumSurfaces(&This->IDirectDraw7_iface, flags, &surface_desc2,
&cbcontext, EnumSurfacesCallbackThunk);
if (surface_desc) DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw7_EnumSurfaces(&This->IDirectDraw7_iface, flags,
surface_desc ? &surface_desc2 : NULL, &cbcontext, EnumSurfacesCallbackThunk);
}
static HRESULT WINAPI ddraw1_EnumSurfaces(IDirectDraw *iface, DWORD flags,
@ -3766,9 +3766,9 @@ static HRESULT WINAPI ddraw1_EnumSurfaces(IDirectDraw *iface, DWORD flags,
cbcontext.func = callback;
cbcontext.context = context;
DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw7_EnumSurfaces(&This->IDirectDraw7_iface, flags, &surface_desc2,
&cbcontext, EnumSurfacesCallbackThunk);
if (surface_desc) DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw7_EnumSurfaces(&This->IDirectDraw7_iface, flags,
surface_desc ? &surface_desc2 : NULL, &cbcontext, EnumSurfacesCallbackThunk);
}
/*****************************************************************************

View File

@ -2938,9 +2938,9 @@ static HRESULT WINAPI ddraw_surface3_Initialize(IDirectDrawSurface3 *iface,
DDSURFACEDESC2 surface_desc2;
TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface, ddraw, surface_desc);
DDSD_to_DDSD2(surface_desc, &surface_desc2);
if (surface_desc) DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw_surface7_Initialize(&This->IDirectDrawSurface7_iface,
ddraw, &surface_desc2);
ddraw, surface_desc ? &surface_desc2 : NULL);
}
static HRESULT WINAPI ddraw_surface2_Initialize(IDirectDrawSurface2 *iface,
@ -2950,9 +2950,9 @@ static HRESULT WINAPI ddraw_surface2_Initialize(IDirectDrawSurface2 *iface,
DDSURFACEDESC2 surface_desc2;
TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface, ddraw, surface_desc);
DDSD_to_DDSD2(surface_desc, &surface_desc2);
if (surface_desc) DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw_surface7_Initialize(&This->IDirectDrawSurface7_iface,
ddraw, &surface_desc2);
ddraw, surface_desc ? &surface_desc2 : NULL);
}
static HRESULT WINAPI ddraw_surface1_Initialize(IDirectDrawSurface *iface,
@ -2962,9 +2962,9 @@ static HRESULT WINAPI ddraw_surface1_Initialize(IDirectDrawSurface *iface,
DDSURFACEDESC2 surface_desc2;
TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface, ddraw, surface_desc);
DDSD_to_DDSD2(surface_desc, &surface_desc2);
if (surface_desc) DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw_surface7_Initialize(&This->IDirectDrawSurface7_iface,
ddraw, &surface_desc2);
ddraw, surface_desc ? &surface_desc2 : NULL);
}
/*****************************************************************************
@ -3873,8 +3873,16 @@ static HRESULT WINAPI ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7 *iface,
TRACE("iface %p, surface_desc %p, flags %#x.\n", iface, DDSD, Flags);
if(!DDSD)
if (!DDSD)
{
WARN("DDSD is NULL, returning DDERR_INVALIDPARAMS\n");
return DDERR_INVALIDPARAMS;
}
if (Flags)
{
WARN("Flags is %x, returning DDERR_INVALIDPARAMS\n", Flags);
return DDERR_INVALIDPARAMS;
}
EnterCriticalSection(&ddraw_cs);
if (DDSD->dwFlags & DDSD_PIXELFORMAT)
@ -3957,9 +3965,9 @@ static HRESULT WINAPI ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3 *iface,
DDSURFACEDESC2 surface_desc2;
TRACE("iface %p, surface_desc %p, flags %#x.\n", iface, surface_desc, flags);
DDSD_to_DDSD2(surface_desc, &surface_desc2);
if (surface_desc) DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw_surface7_SetSurfaceDesc(&This->IDirectDrawSurface7_iface,
&surface_desc2, flags);
surface_desc ? &surface_desc2 : NULL, flags);
}
/*****************************************************************************

View File

@ -501,8 +501,12 @@ static void enumdisplaymodes(void)
ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
ok(modes16bpp_cnt == refresh_count, "Expected %d modes got %d\n", refresh_count, modes16bpp_cnt);
}
rc = IDirectDraw_EnumDisplayModes(lpDD, 0, NULL, 0, enummodescallback);
ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
}
static void setdisplaymode(int i)
{
HRESULT rc;

View File

@ -1217,6 +1217,11 @@ static void EnumTest(void)
ok(rc == DD_OK, "IDirectDraw_EnumSurfaces returned %08x\n", rc);
ok(ctx.count == 3, "%d surfaces enumerated, expected 3\n", ctx.count);
ctx.count = 0;
rc = IDirectDraw_EnumSurfaces(lpDD, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, NULL, &ctx, enumCB);
ok(rc == DD_OK, "IDirectDraw_EnumSurfaces returned %08x\n", rc);
ok(ctx.count == 3, "%d surfaces enumerated, expected 3\n", ctx.count);
IDirectDrawSurface_Release(ctx.expected[2]);
IDirectDrawSurface_Release(ctx.expected[1]);
IDirectDrawSurface_Release(surface);
@ -1944,6 +1949,10 @@ static void test_lockrect_invalid(void)
continue;
}
hr = IDirectDrawSurface_Lock(surface, NULL, NULL, DDLOCK_WAIT, NULL);
ok(hr == DDERR_INVALIDPARAMS, "Lock returned 0x%08x for NULL DDSURFACEDESC,"
" expected DDERR_INVALIDPARAMS (0x%08x)\n", hr, DDERR_INVALIDPARAMS);
for (i = 0; i < (sizeof(valid) / sizeof(*valid)); ++i)
{
RECT *rect = &valid[i];
@ -4216,6 +4225,58 @@ static void pixelformat_flag_test(void)
test_ddsd(&ddsd, FALSE, TRUE, "Z buffer");
}
static void set_surface_desc_test(void)
{
HRESULT hr;
DDSURFACEDESC ddsd;
IDirectDrawSurface *surface;
IDirectDrawSurface3 *surface3;
BYTE data[8*8*4];
hr = IDirectDraw_CreateSurface(lpDD, NULL, &surface, NULL);
ok(hr == DDERR_INVALIDPARAMS, "CreateSurface with a NULL DDSD returned %#x,"
" expected DDERR_INVALIDPARAMS(%#x)\n", hr, DDERR_INVALIDPARAMS);
reset_ddsd(&ddsd);
ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
ddsd.dwWidth = 8;
ddsd.dwHeight = 8;
ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 32;
U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x00ff0000;
U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x000000ff;
ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY;
hr = IDirectDraw_CreateSurface(lpDD, &ddsd, &surface, NULL);
ok(SUCCEEDED(hr), "IDirectDraw_CreateSurface failed, hr %#x.\n", hr);
hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface3, (void **) &surface3);
ok(SUCCEEDED(hr), "IDirectDrawSurface_QueryInterface failed, hr %#x.\n", hr);
IDirectDrawSurface_Release(surface);
reset_ddsd(&ddsd);
ddsd.dwFlags = DDSD_LPSURFACE;
ddsd.lpSurface = data;
hr = IDirectDrawSurface3_SetSurfaceDesc(surface3, &ddsd, 0);
ok(SUCCEEDED(hr), "IDirectDrawSurface3_SetSurfaceDesc failed, hr %#x.\n", hr);
/* Redundantly setting the same lpSurface is not an error */
hr = IDirectDrawSurface3_SetSurfaceDesc(surface3, &ddsd, 0);
ok(SUCCEEDED(hr), "IDirectDrawSurface3_SetSurfaceDesc failed, hr %#x.\n", hr);
hr = IDirectDrawSurface3_SetSurfaceDesc(surface3, &ddsd, 1);
ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface3_SetSurfaceDesc returned %#x, expected"
" DDERR_INVALIDPARAMS(%#x)\n", hr, DDERR_INVALIDPARAMS);
hr = IDirectDrawSurface3_SetSurfaceDesc(surface3, NULL, 0);
ok(hr == DDERR_INVALIDPARAMS, "IDirectDrawSurface3_SetSurfaceDesc returned %#x, expected"
" DDERR_INVALIDPARAMS(%#x)\n", hr, DDERR_INVALIDPARAMS);
IDirectDrawSurface_Release(surface3);
}
START_TEST(dsurface)
{
HRESULT ret;
@ -4275,5 +4336,6 @@ START_TEST(dsurface)
no_ddsd_caps_test();
zbufferbitdepth_test();
pixelformat_flag_test();
set_surface_desc_test();
ReleaseDirectDraw();
}