From: David Adam Subject: d3dx9_36/tests [patch 2/2, resent]: Implement tests for D3DXCreatePolygon Message-Id: Date: Mon, 31 Oct 2011 01:45:49 +0100
From b4e620f0042078f22c3c6047c49cbb972b4366fc Mon Sep 17 00:00:00 2001 From: David Adam Date: Mon, 31 Oct 2011 01:30:47 +0100 Subject: Add tests for D3DXCreatePolygon --- dlls/d3dx9_36/tests/mesh.c | 156 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 156 insertions(+), 0 deletions(-) diff --git a/dlls/d3dx9_36/tests/mesh.c b/dlls/d3dx9_36/tests/mesh.c index f596daf..c2604fc 100644 --- a/dlls/d3dx9_36/tests/mesh.c +++ b/dlls/d3dx9_36/tests/mesh.c @@ -2511,6 +2511,161 @@ end: DestroyWindow(wnd); } +static void D3DXCreatePolygonTest(void) +{ + HRESULT hr; + HWND wnd; + WNDCLASS wndc={0}; + IDirect3D9 *d3d; + IDirect3DDevice9 *device; + D3DPRESENT_PARAMETERS d3dpp; + DWORD *buffer, buffer_size, num_bytes_per_vertex, num_faces, num_vertices; + FLOAT l; + ID3DXMesh *polygon; + ID3DXBuffer *ppBuffer; + unsigned int i, j; + DWORD adjacency[33]; + WORD exp_index, index; + BYTE *data; + D3DXVECTOR3 u, v; + + wndc.lpfnWndProc = DefWindowProcA; + wndc.lpszClassName = "d3dx9_test_wndc"; + if (!RegisterClass(&wndc)) + { + skip("RegisterClass failed\n"); + return; + } + + wnd = CreateWindow("d3dx9_test_wndc", "d3dx9_test", + WS_SYSMENU | WS_POPUP , 0, 0, 640, 480, 0, 0, 0, 0); + ok(wnd != NULL, "Expected to have a window, received NULL\n"); + if (!wnd) + { + skip("Couldn't create application window\n"); + return; + } + + d3d = Direct3DCreate9(D3D_SDK_VERSION); + if (!d3d) + { + skip("Couldn't create IDirect3D9 object\n"); + DestroyWindow(wnd); + return; + } + + memset(&d3dpp, 0, sizeof(d3dpp)); + d3dpp.Windowed = TRUE; + d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; + hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device); + if (FAILED(hr)) + { + skip("Failed to create IDirect3DDevice9 object %#x\n", hr); + IDirect3D9_Release(d3d); + DestroyWindow(wnd); + return; + } + + hr = D3DXCreateBuffer(11 * sizeof(DWORD), &ppBuffer); + ok(hr==D3D_OK, "Expected D3D_OK, received %#x\n", hr); + if (FAILED(hr)) goto end; + + hr = D3DXCreatePolygon(device, 2.0f, 11, NULL, &ppBuffer); + ok(hr==D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, received %#x\n", hr); + + hr = D3DXCreatePolygon(NULL, 2.0f, 11, &polygon, &ppBuffer); + ok(hr==D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, received %#x\n", hr); + + hr = D3DXCreatePolygon(device, -2.0f, 11, &polygon, &ppBuffer); + ok(hr==D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, received %#x\n", hr); + + hr = D3DXCreatePolygon(device, 2.0f, 11, &polygon, NULL); + ok(hr==D3D_OK, "Expected D3D_OK, received %#x\n", hr); + + hr = D3DXCreatePolygon(device, 2.0f, 0, &polygon, &ppBuffer); + ok(hr==D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, received %#x\n", hr); + + hr = D3DXCreatePolygon(device, 2.0f, 11, &polygon, &ppBuffer); + ok(hr==D3D_OK, "Expected D3D_OK, received %#x\n", hr); + + if (FAILED(hr)) + { + skip("D3DXCreatePolygon failed\n"); + goto end; + } + + num_faces = polygon->lpVtbl->GetNumFaces(polygon); + ok(num_faces == 11, "Expected 11 faces, received %d\n", num_faces); + + num_vertices = polygon->lpVtbl->GetNumVertices(polygon); + ok(num_vertices == 12, "Expected 12 vertices, received %d\n", num_vertices); + + num_bytes_per_vertex = polygon->lpVtbl->GetNumBytesPerVertex(polygon); + ok(num_bytes_per_vertex == 6 * sizeof(FLOAT), "Expected num_bytes_per_vertex = 0x18, received %#x\n", num_bytes_per_vertex); + + hr = polygon->lpVtbl->LockIndexBuffer(polygon, D3DLOCK_READONLY, (VOID **)&data); + + if (SUCCEEDED(hr)) + for(i = 0; i < 11; i++) + for(j = 0; j < 3; j++) + { + exp_index = (j == 0) ? 0: i + j; + if ( 3 * i + j == 32 ) exp_index = 1; + + index = *( (WORD*)( data + ( 3 * i + j ) * sizeof(WORD) ) ); + ok(index == exp_index, "Expected index %d = %#x, received = %#x\n", 3 * i + j, exp_index, index); + } + else skip("LockIndexBuffer failed \n"); + + polygon->lpVtbl->UnlockIndexBuffer(polygon); + + data = NULL; + hr = polygon->lpVtbl->LockVertexBuffer(polygon, D3DLOCK_READONLY, (VOID **)&data); + if (SUCCEEDED(hr)) + { + for(i = 0; i < 12; i++) + { + u.x = 0.0f; u.y = 0.0f; u.z = 0.0f; + l = 2.0f / sqrtf(2.0f - 2.0f * cos(2.0f * D3DX_PI / 11.0f )); + + if ( i != 0 ) + { + u.x = l * cos(2.0f * D3DX_PI * (i - 1) / 11.0f); + u.y = l * sin(2.0f * D3DX_PI * (i - 1) / 11.0f); + } + v = *( (D3DXVECTOR3*)(data + i * num_bytes_per_vertex) ); + ok(compare_vec3(v, u), "Expected vertex %d = (%f, %f, %f), received = (%f, %f, %f)\n", i, u.x, u.y, u.z, v.x, v.y, v.z); + + u.x = 0.0f; u.y = 0.0f; u.z = 1.0f; + v = *( (D3DXVECTOR3*)(data + i * num_bytes_per_vertex + sizeof(D3DXVECTOR3)) ); + ok(compare_vec3(v, u), "Expected normal %d = (%f, %f, %f), received = (%f, %f, %f)\n", i, u.x, u.y, u.z, v.x, v.y, v.z); + } + } + else skip("LockIndexVertex failed \n"); + + buffer_size = ID3DXBuffer_GetBufferSize(ppBuffer); + ok(buffer_size == 33 * sizeof(DWORD), "Expected size = %#x, received %#x\n", 33 * sizeof(DWORD), buffer_size); + + buffer = ID3DXBuffer_GetBufferPointer(ppBuffer); + for(i = 0; i < 11; i++) + for(j = 0; j < 2; j++) + { + if (j == 0) adjacency[3 * i] = i - 1; + if (j == 2) adjacency[3 * i + 2] = i + 1; + if (j == 1) adjacency[3 * i +1] = 0xffffffff; + if (i==0 && j==0) adjacency[0] = 10; + ok(adjacency[3 * i + j] == buffer[3 * i + j], "Expected adjacency %d: %#x, received %#x\n", i, adjacency[3 * i + j], buffer[3 * i + j]); + } + + polygon->lpVtbl->Release(polygon); + +end: + IDirect3DDevice9_Release(device); + IDirect3D9_Release(d3d); + ID3DXBuffer_Release(ppBuffer); + DestroyWindow(wnd); +} + struct sincos_table { float *sin; @@ -9852,6 +10007,7 @@ START_TEST(mesh) D3DXCreateMeshFVFTest(); D3DXLoadMeshTest(); D3DXCreateBoxTest(); + D3DXCreatePolygonTest(); D3DXCreateSphereTest(); D3DXCreateCylinderTest(); D3DXCreateTextTest(); -- 1.7.6