Commit 4c61c2ff authored by Andrew Nguyen's avatar Andrew Nguyen Committed by Alexandre Julliard

ddraw: Simplify and test DirectDrawEnumerateA.

parent 611fae61
......@@ -368,7 +368,7 @@ HRESULT WINAPI
DirectDrawEnumerateA(LPDDENUMCALLBACKA Callback,
LPVOID Context)
{
BOOL stop = FALSE;
TRACE("(%p, %p)\n", Callback, Context);
TRACE(" Enumerating default DirectDraw HAL interface\n");
/* We only have one driver */
......@@ -377,11 +377,11 @@ DirectDrawEnumerateA(LPDDENUMCALLBACKA Callback,
static CHAR driver_desc[] = "DirectDraw HAL",
driver_name[] = "display";
stop = !Callback(NULL, driver_desc, driver_name, Context);
Callback(NULL, driver_desc, driver_name, Context);
}
__EXCEPT_PAGE_FAULT
{
return E_INVALIDARG;
return DDERR_INVALIDPARAMS;
}
__ENDTRY
......
......@@ -38,6 +38,14 @@ static int modes_cnt;
static int modes_size;
static LPDDSURFACEDESC modes;
static HRESULT (WINAPI *pDirectDrawEnumerateA)(LPDDENUMCALLBACKA,LPVOID);
static void init_function_pointers(void)
{
HMODULE hmod = GetModuleHandleA("ddraw.dll");
pDirectDrawEnumerateA = (void*)GetProcAddress(hmod, "DirectDrawEnumerateA");
}
static void createwindow(void)
{
wc.style = CS_HREDRAW | CS_VREDRAW;
......@@ -88,6 +96,68 @@ static void releasedirectdraw(void)
}
}
static BOOL WINAPI crash_callbackA(GUID *lpGUID, LPSTR lpDriverDescription,
LPSTR lpDriverName, LPVOID lpContext)
{
*(volatile char*)0 = 2;
return TRUE;
}
static BOOL WINAPI test_nullcontext_callbackA(GUID *lpGUID, LPSTR lpDriverDescription,
LPSTR lpDriverName, LPVOID lpContext)
{
trace("test_nullcontext_callbackA: %p %s %s %p\n",
lpGUID, lpDriverDescription, lpDriverName, lpContext);
ok(!lpContext, "Expected NULL lpContext\n");
return TRUE;
}
static BOOL WINAPI test_context_callbackA(GUID *lpGUID, LPSTR lpDriverDescription,
LPSTR lpDriverName, LPVOID lpContext)
{
trace("test_context_callbackA: %p %s %s %p\n",
lpGUID, lpDriverDescription, lpDriverName, lpContext);
ok(lpContext == (LPVOID)0xdeadbeef, "Expected non-NULL lpContext\n");
return TRUE;
}
static void test_DirectDrawEnumerateA(void)
{
HRESULT ret;
if (!pDirectDrawEnumerateA)
{
win_skip("DirectDrawEnumerateA is not available\n");
return;
}
/* Test with NULL callback parameter. */
ret = pDirectDrawEnumerateA(NULL, NULL);
ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
/* Test with invalid callback parameter. */
ret = pDirectDrawEnumerateA((LPDDENUMCALLBACKA)0xdeadbeef, NULL);
ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
/* Test with callback that crashes. */
ret = pDirectDrawEnumerateA(crash_callbackA, NULL);
ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
/* Test with valid callback parameter and NULL context parameter. */
trace("Calling DirectDrawEnumerateA with test_nullcontext_callbackA callback and NULL context.\n");
ret = pDirectDrawEnumerateA(test_nullcontext_callbackA, NULL);
ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
/* Test with valid callback parameter and valid context parameter. */
trace("Calling DirectDrawEnumerateA with test_context_callbackA callback and non-NULL context.\n");
ret = pDirectDrawEnumerateA(test_context_callbackA, (LPVOID)0xdeadbeef);
ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
}
static void adddisplaymode(LPDDSURFACEDESC lpddsd)
{
if (!modes)
......@@ -409,9 +479,14 @@ static void testddraw3(void)
START_TEST(ddrawmodes)
{
init_function_pointers();
createwindow();
if (!createdirectdraw())
return;
test_DirectDrawEnumerateA();
enumdisplaymodes();
if (winetest_interactive)
testdisplaymodes();
......
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