From: David Adam Subject: d3dx9_36 [patch 2/2, try 2]: Add tests for D3DXCreatePolygon Message-Id: Date: Thu, 5 Jan 2012 13:16:14 +0100 From 6ec5e1c0581438627160b88f6425d7c966b8e749 Mon Sep 17 00:00:00 2001 From: David Adam Date: Thu, 5 Jan 2012 12:59:28 +0100 Subject: Add tests for D3DXCreatePolygon --- dlls/d3dx9_36/tests/mesh.c | 179 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 179 insertions(+), 0 deletions(-) diff --git a/dlls/d3dx9_36/tests/mesh.c b/dlls/d3dx9_36/tests/mesh.c index af0a9e8..29e695f 100644 --- a/dlls/d3dx9_36/tests/mesh.c +++ b/dlls/d3dx9_36/tests/mesh.c @@ -2511,6 +2511,184 @@ end: DestroyWindow(wnd); } +static void D3DXCreatePolygonTest(void) +{ + D3DPRESENT_PARAMETERS d3dpp; + D3DXVECTOR3 u, v, *vertex_buffer; + DWORD adjacency[33], *buffer, buffer_size, num_bytes_per_vertex, num_faces, num_vertices; + FLOAT l; + HRESULT hr; + HWND wnd; + ID3DXBuffer *received_adjacency = NULL, *received_adjacency2; + ID3DXMesh *polygon = NULL, *polygon2; + IDirect3D9 *d3d = NULL; + IDirect3DDevice9 *device = NULL; + UINT i, j; + ULONG ref; + WNDCLASS wndc = {0}; + WORD exp_index, index, *index_buffer; + + 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 = D3DXCreatePolygon(device, 2.0f, 11, NULL, &received_adjacency); + ok(hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, received %#x\n", hr); + + hr = D3DXCreatePolygon(NULL, 2.0f, 11, &polygon, &received_adjacency); + ok(hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, received %#x\n", hr); + + hr = D3DXCreatePolygon(device, -2.0f, 11, &polygon, &received_adjacency); + ok(hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, received %#x\n", hr); + + polygon2 = (ID3DXMesh *)0xdeadbeef; + received_adjacency2 = (ID3DXBuffer *)0xbeefdead; + hr = D3DXCreatePolygon(device, 2.0f, 0, &polygon2, &received_adjacency2); + ok(hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, received %#x\n", hr); + ok(polygon2 == (ID3DXMesh *)0xdeadbeef, "Expected 0xdeadbeef polygon, received %p\n", polygon2); + ok(received_adjacency2 == (ID3DXBuffer *)0xbeefdead, "Expected 0xbeefdead adjacency buffer, received %p\n", received_adjacency2); + + hr = D3DXCreatePolygon(device, 3.0f, 11, &polygon, &received_adjacency); + 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 = %#x, received %#x\n", 6 * sizeof(FLOAT), num_bytes_per_vertex); + + hr = polygon->lpVtbl->LockIndexBuffer(polygon, D3DLOCK_READONLY, (VOID **)&index_buffer); + ok(hr == D3D_OK, "Expected D3D_OK, received %#x\n", hr); + 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 = index_buffer[3 * i + j]; + ok(index == exp_index, "Expected index %d = %#x, received %#x\n", 3 * i + j, exp_index, index); + } + polygon->lpVtbl->UnlockIndexBuffer(polygon); + } + else + { + skip("LockIndexBuffer failed \n"); + goto end; + } + + hr = polygon->lpVtbl->LockVertexBuffer(polygon, D3DLOCK_READONLY, (VOID **)&vertex_buffer); + ok(hr == D3D_OK, "Expected D3D_OK, received %#x\n", hr); + if (SUCCEEDED(hr)) + { + l = 3.0f * 0.5f / sin(D3DX_PI / 11.0f); + for (i = 0; i < 12; i++) + { + u.x = 0.0f; u.y = 0.0f; u.z = 0.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 = vertex_buffer[2 * i]; + 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 = vertex_buffer[2 * i + 1]; + 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); + } + polygon->lpVtbl->UnlockVertexBuffer(polygon); + } + else + { + skip("LockVertexBuffer failed \n"); + goto end; + } + + buffer_size = ID3DXBuffer_GetBufferSize(received_adjacency); + ok(buffer_size == 33 * sizeof(DWORD), "Expected size = %#x, received %#x\n", 33 * sizeof(DWORD), buffer_size); + + buffer = ID3DXBuffer_GetBufferPointer(received_adjacency); + + adjacency[0] = 10; + for (i = 0; i < 11; i++) + for (j = 0; j < 2; j++) + { + if ((j == 0) && (i != 0)) adjacency[3 * i] = i - 1; + if (j == 1) adjacency[3 * i +1] = 0xffffffff; + if (j == 2) adjacency[3 * i + 2] = i + 1; + 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]); + } + +end: + if (polygon) + { + ref = polygon->lpVtbl->Release(polygon); + ok(ref == 0, "Expected refcount = 0, received %d\n", ref); + } + if (received_adjacency) + { + ref = ID3DXBuffer_Release(received_adjacency); + ok(ref == 0, "Expected refcount = 0, received %d\n", ref); + } + if (device) + { + ref = IDirect3DDevice9_Release(device); + ok(ref == 0, "Expected refcount = 0, received %d\n", ref); + } + if (d3d) + { + ref = IDirect3D9_Release(d3d); + ok(ref == 0, "Expected refcount = 0, received %d\n", ref); + } + + DestroyWindow(wnd); +} + struct sincos_table { float *sin; @@ -10065,6 +10243,7 @@ START_TEST(mesh) D3DXCreateMeshFVFTest(); D3DXLoadMeshTest(); D3DXCreateBoxTest(); + D3DXCreatePolygonTest(); D3DXCreateSphereTest(); D3DXCreateCylinderTest(); D3DXCreateTextTest(); -- 1.7.6