From db34ccd7f2cb6d509921ca3903636045338cd3df Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Thu, 6 Mar 2014 11:06:07 +0100 Subject: [PATCH] d3d8/tests: Don't bother handling Direct3DCreate8() failures, we verified it works earlier. --- dlls/d3d8/tests/device.c | 580 ++++++++++++++------------------------- 1 file changed, 213 insertions(+), 367 deletions(-) diff --git a/dlls/d3d8/tests/device.c b/dlls/d3d8/tests/device.c index 29214c13ec4..324160bea65 100644 --- a/dlls/d3d8/tests/device.c +++ b/dlls/d3d8/tests/device.c @@ -180,31 +180,26 @@ static void check_mipmap_levels(IDirect3DDevice8 *device, UINT width, UINT heigh static void test_mipmap_levels(void) { - HRESULT hr; - HWND hwnd = NULL; - - IDirect3D8 *pD3d = NULL; IDirect3DDevice8 *pDevice = NULL; D3DPRESENT_PARAMETERS d3dpp; D3DDISPLAYMODE d3ddm; + IDirect3D8 *d3d; + HWND hwnd; - pD3d = Direct3DCreate8(D3D_SDK_VERSION); - ok(pD3d != NULL, "Failed to create IDirect3D8 object\n"); hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL); - ok(hwnd != NULL, "Failed to create window\n"); - if (!pD3d || !hwnd) goto cleanup; + ok(!!hwnd, "Failed to create a window.\n"); + d3d = Direct3DCreate8(D3D_SDK_VERSION); + ok(!!d3d, "Failed to create a D3D object.\n"); - IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm ); + IDirect3D8_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT, &d3ddm); ZeroMemory( &d3dpp, sizeof(d3dpp) ); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = d3ddm.Format; - - hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, - D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice ); - if(FAILED(hr)) + if (FAILED(hr = IDirect3D8_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, + hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice))) { skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr); goto cleanup; @@ -221,15 +216,13 @@ cleanup: UINT refcount = IDirect3DDevice8_Release( pDevice ); ok(!refcount, "Device has %u references left.\n", refcount); } - if (pD3d) IDirect3D8_Release( pD3d ); - DestroyWindow( hwnd ); + IDirect3D8_Release(d3d); + DestroyWindow(hwnd); } static void test_swapchain(void) { HRESULT hr; - HWND hwnd = NULL; - IDirect3D8 *pD3d = NULL; IDirect3DDevice8 *pDevice = NULL; IDirect3DSwapChain8 *swapchain1 = NULL; IDirect3DSwapChain8 *swapchain2 = NULL; @@ -237,24 +230,24 @@ static void test_swapchain(void) IDirect3DSurface8 *backbuffer = NULL; D3DPRESENT_PARAMETERS d3dpp; D3DDISPLAYMODE d3ddm; + IDirect3D8 *d3d; + HWND hwnd; - pD3d = Direct3DCreate8(D3D_SDK_VERSION); - ok(pD3d != NULL, "Failed to create IDirect3D8 object\n"); hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL); - ok(hwnd != NULL, "Failed to create window\n"); - if (!pD3d || !hwnd) goto cleanup; + ok(!!hwnd, "Failed to create a window.\n"); + d3d = Direct3DCreate8(D3D_SDK_VERSION); + ok(!!d3d, "Failed to create a D3D object.\n"); - IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm ); + IDirect3D8_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT, &d3ddm); ZeroMemory( &d3dpp, sizeof(d3dpp) ); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = d3ddm.Format; d3dpp.BackBufferCount = 0; - hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, - D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice ); - if(FAILED(hr)) + if (FAILED(hr = IDirect3D8_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, + hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice))) { skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr); goto cleanup; @@ -344,16 +337,13 @@ cleanup: UINT refcount = IDirect3DDevice8_Release(pDevice); ok(!refcount, "Device has %u references left.\n", refcount); } - if (pD3d) IDirect3D8_Release(pD3d); - DestroyWindow( hwnd ); + IDirect3D8_Release(d3d); + DestroyWindow(hwnd); } static void test_refcount(void) { HRESULT hr; - HWND hwnd = NULL; - IDirect3D8 *pD3d = NULL; - IDirect3D8 *pD3d2 = NULL; IDirect3DDevice8 *pDevice = NULL; IDirect3DVertexBuffer8 *pVertexBuffer = NULL; IDirect3DIndexBuffer8 *pIndexBuffer = NULL; @@ -373,10 +363,11 @@ static void test_refcount(void) DWORD dStateBlock = -1; IDirect3DSwapChain8 *pSwapChain = NULL; D3DCAPS8 caps; - D3DPRESENT_PARAMETERS d3dpp; D3DDISPLAYMODE d3ddm; int refcount = 0, tmp; + IDirect3D8 *d3d, *d3d2; + HWND hwnd; DWORD decl[] = { @@ -386,16 +377,15 @@ static void test_refcount(void) D3DVSD_END() }; - pD3d = Direct3DCreate8(D3D_SDK_VERSION); - ok(pD3d != NULL, "Failed to create IDirect3D8 object\n"); hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL); - ok(hwnd != NULL, "Failed to create window\n"); - if (!pD3d || !hwnd) goto cleanup; + ok(!!hwnd, "Failed to create a window.\n"); + d3d = Direct3DCreate8(D3D_SDK_VERSION); + ok(!!d3d, "Failed to create a D3D object.\n"); - CHECK_REFCOUNT( pD3d, 1 ); + CHECK_REFCOUNT(d3d, 1); - IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm ); + IDirect3D8_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT, &d3ddm); ZeroMemory( &d3dpp, sizeof(d3dpp) ); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; @@ -403,9 +393,8 @@ static void test_refcount(void) d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D16; - hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, - D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice ); - if(FAILED(hr)) + if (FAILED(hr = IDirect3D8_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, + hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice))) { skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr); goto cleanup; @@ -415,14 +404,14 @@ static void test_refcount(void) refcount = get_refcount( (IUnknown *)pDevice ); ok(refcount == 1, "Invalid device RefCount %d\n", refcount); - CHECK_REFCOUNT( pD3d, 2 ); + CHECK_REFCOUNT(d3d, 2); - hr = IDirect3DDevice8_GetDirect3D(pDevice, &pD3d2); + hr = IDirect3DDevice8_GetDirect3D(pDevice, &d3d2); CHECK_CALL( hr, "GetDirect3D", pDevice, refcount ); - ok(pD3d2 == pD3d, "Expected IDirect3D8 pointers to be equal\n"); - CHECK_REFCOUNT( pD3d, 3 ); - CHECK_RELEASE_REFCOUNT( pD3d, 2 ); + ok(d3d2 == d3d, "Expected IDirect3D8 pointers to be equal.\n"); + CHECK_REFCOUNT(d3d, 3); + CHECK_RELEASE_REFCOUNT(d3d, 2); /** * Check refcount of implicit surfaces. Findings: @@ -691,17 +680,13 @@ cleanup: if (dStateBlock != ~0U) IDirect3DDevice8_DeleteStateBlock( pDevice, dStateBlock ); /* This will destroy device - cannot check the refcount here */ if (pSwapChain) CHECK_RELEASE_REFCOUNT( pSwapChain, 0); - - if (pD3d) CHECK_RELEASE_REFCOUNT( pD3d, 0); - + CHECK_RELEASE_REFCOUNT(d3d, 0); DestroyWindow( hwnd ); } static void test_cursor(void) { HRESULT hr; - HWND hwnd = NULL; - IDirect3D8 *pD3d = NULL; IDirect3DDevice8 *pDevice = NULL; D3DPRESENT_PARAMETERS d3dpp; D3DDISPLAYMODE d3ddm; @@ -709,6 +694,8 @@ static void test_cursor(void) IDirect3DSurface8 *cursor = NULL; HCURSOR cur; HMODULE user32_handle = GetModuleHandleA("user32.dll"); + IDirect3D8 *d3d; + HWND hwnd; pGetCursorInfo = (void *)GetProcAddress(user32_handle, "GetCursorInfo"); if (!pGetCursorInfo) @@ -722,22 +709,20 @@ static void test_cursor(void) ok(pGetCursorInfo(&info), "GetCursorInfo failed\n"); cur = info.hCursor; - pD3d = Direct3DCreate8(D3D_SDK_VERSION); - ok(pD3d != NULL, "Failed to create IDirect3D8 object\n"); hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL); - ok(hwnd != NULL, "Failed to create window\n"); - if (!pD3d || !hwnd) goto cleanup; + ok(!!hwnd, "Failed to create a window.\n"); + d3d = Direct3DCreate8(D3D_SDK_VERSION); + ok(!!d3d, "Failed to create a D3D object.\n"); - IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm ); + IDirect3D8_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT, &d3ddm); ZeroMemory( &d3dpp, sizeof(d3dpp) ); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = d3ddm.Format; - hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, - D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice ); - if(FAILED(hr)) + if (FAILED(hr = IDirect3D8_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, + hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice))) { skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr); goto cleanup; @@ -790,7 +775,7 @@ cleanup: UINT refcount = IDirect3DDevice8_Release(pDevice); ok(!refcount, "Device has %u references left.\n", refcount); } - if (pD3d) IDirect3D8_Release(pD3d); + IDirect3D8_Release(d3d); DestroyWindow(hwnd); } @@ -840,18 +825,14 @@ static void test_cursor_pos(void) {0, 0}, }; - if (!(d3d8 = Direct3DCreate8(D3D_SDK_VERSION))) - { - skip("Failed to create IDirect3D8 object, skipping cursor tests.\n"); - return; - } - wc.lpfnWndProc = test_cursor_proc; wc.lpszClassName = "d3d8_test_cursor_wc"; ok(RegisterClassA(&wc), "Failed to register window class.\n"); window = CreateWindowA("d3d8_test_cursor_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, 0, 0, 320, 240, NULL, NULL, NULL, NULL); ShowWindow(window, SW_SHOW); + d3d8 = Direct3DCreate8(D3D_SDK_VERSION); + ok(!!d3d8, "Failed to create a D3D object.\n"); device = create_device(d3d8, window, window, TRUE); if (!device) @@ -911,27 +892,25 @@ static void test_cursor_pos(void) done: DestroyWindow(window); UnregisterClassA("d3d8_test_cursor_wc", GetModuleHandleA(NULL)); - if (d3d8) - IDirect3D8_Release(d3d8); + IDirect3D8_Release(d3d8); } static void test_states(void) { HRESULT hr; - HWND hwnd = NULL; - IDirect3D8 *pD3d = NULL; IDirect3DDevice8 *pDevice = NULL; D3DPRESENT_PARAMETERS d3dpp; D3DDISPLAYMODE d3ddm; + IDirect3D8 *d3d; + HWND hwnd; - pD3d = Direct3DCreate8(D3D_SDK_VERSION); - ok(pD3d != NULL, "Failed to create IDirect3D8 object\n"); hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL); - ok(hwnd != NULL, "Failed to create window\n"); - if (!pD3d || !hwnd) goto cleanup; + ok(!!hwnd, "Failed to create a window.\n"); + d3d = Direct3DCreate8(D3D_SDK_VERSION); + ok(!!d3d, "Failed to create a D3D object.\n"); - IDirect3D8_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm ); + IDirect3D8_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT, &d3ddm); ZeroMemory( &d3dpp, sizeof(d3dpp) ); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; @@ -939,9 +918,8 @@ static void test_states(void) d3dpp.BackBufferHeight = screen_height; d3dpp.BackBufferFormat = d3ddm.Format; - hr = IDirect3D8_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd, - D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice ); - if(FAILED(hr)) + if (FAILED(hr = IDirect3D8_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, + hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice))) { skip("could not create device, IDirect3D8_CreateDevice returned %#08x\n", hr); goto cleanup; @@ -958,29 +936,32 @@ cleanup: UINT refcount = IDirect3DDevice8_Release(pDevice); ok(!refcount, "Device has %u references left.\n", refcount); } - if (pD3d) IDirect3D8_Release(pD3d); + IDirect3D8_Release(d3d); DestroyWindow(hwnd); } static void test_shader_versions(void) { - HRESULT hr; - IDirect3D8 *pD3d = NULL; - D3DCAPS8 d3dcaps; + IDirect3D8 *d3d; + D3DCAPS8 caps; + HRESULT hr; - pD3d = Direct3DCreate8(D3D_SDK_VERSION); - ok(pD3d != NULL, "Failed to create IDirect3D8 object\n"); - if (pD3d != NULL) { - hr = IDirect3D8_GetDeviceCaps(pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dcaps); - ok(SUCCEEDED(hr) || hr == D3DERR_NOTAVAILABLE, "Failed to get D3D8 caps (%#08x)\n", hr); - if (SUCCEEDED(hr)) { - ok(d3dcaps.VertexShaderVersion <= D3DVS_VERSION(1,1), "Unexpected VertexShaderVersion (%#x > %#x)\n", d3dcaps.VertexShaderVersion, D3DVS_VERSION(1,1)); - ok(d3dcaps.PixelShaderVersion <= D3DPS_VERSION(1,4), "Unexpected PixelShaderVersion (%#x > %#x)\n", d3dcaps.PixelShaderVersion, D3DPS_VERSION(1,4)); - } else { - skip("No Direct3D support\n"); - } - IDirect3D8_Release(pD3d); + d3d = Direct3DCreate8(D3D_SDK_VERSION); + ok(!!d3d, "Failed to create a D3D object.\n"); + + hr = IDirect3D8_GetDeviceCaps(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps); + ok(SUCCEEDED(hr) || hr == D3DERR_NOTAVAILABLE, "Failed to get device caps, hr %#x.\n", hr); + IDirect3D8_Release(d3d); + if (FAILED(hr)) + { + skip("No Direct3D support, skipping test.\n"); + return; } + + ok(caps.VertexShaderVersion <= D3DVS_VERSION(1,1), + "Got unexpected VertexShaderVersion %#x.\n", caps.VertexShaderVersion); + ok(caps.PixelShaderVersion <= D3DPS_VERSION(1,4), + "Got unexpected PixelShaderVersion %#x.\n", caps.PixelShaderVersion); } static void test_display_formats(void) @@ -1012,11 +993,8 @@ static void test_display_formats(void) {"D3DFMT_UNKNOWN", D3DFMT_UNKNOWN, 0, FALSE, FALSE}, }; - if (!(d3d8 = Direct3DCreate8(D3D_SDK_VERSION))) - { - skip("Failed to create an IDirect3D8 object, skipping test.\n"); - return; - } + d3d8 = Direct3DCreate8(D3D_SDK_VERSION); + ok(!!d3d8, "Failed to create a D3D object.\n"); for (display = 0; display < sizeof(formats) / sizeof(*formats); ++display) { @@ -1068,20 +1046,20 @@ static void test_display_modes(void) { UINT max_modes, i; D3DDISPLAYMODE dmode; + IDirect3D8 *d3d; HRESULT res; - IDirect3D8 *pD3d; - pD3d = Direct3DCreate8(D3D_SDK_VERSION); - ok(pD3d != NULL, "Failed to create IDirect3D8 object\n"); - if(!pD3d) return; + d3d = Direct3DCreate8(D3D_SDK_VERSION); + ok(!!d3d, "Failed to create a D3D object.\n"); - max_modes = IDirect3D8_GetAdapterModeCount(pD3d, D3DADAPTER_DEFAULT); + max_modes = IDirect3D8_GetAdapterModeCount(d3d, D3DADAPTER_DEFAULT); ok(max_modes > 0 || broken(max_modes == 0), /* VMware */ "GetAdapterModeCount(D3DADAPTER_DEFAULT) returned 0!\n"); - for(i=0; i