[PATCH 6/6] d3dx9: Test raw vertex data for D3DXCreateSphere.

Misha Koshelev misha680 at gmail.com
Fri Jun 25 21:19:53 CDT 2010


---
 dlls/d3dx9_36/tests/mesh.c |   45 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/dlls/d3dx9_36/tests/mesh.c b/dlls/d3dx9_36/tests/mesh.c
index 312d412..4b33f89 100644
--- a/dlls/d3dx9_36/tests/mesh.c
+++ b/dlls/d3dx9_36/tests/mesh.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#include <assert.h>
 #include "wine/test.h"
 #include "d3dx9.h"
 
@@ -476,6 +477,28 @@ static void D3DXIntersectTriTest(void)
     ok( got_res == exp_res, "Expected result = %d, got %d\n",exp_res,got_res);
 }
 
+/* http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
+ * "I think the answer is 10,000 but since floating point math is imperfect I’ll accept the maxUlps floats above and the maxUlps floats below that value." */
+static BOOLEAN AlmostEqual2sComplement(float A, float B, int maxUlps)
+{
+    int aInt, bInt, intDiff;
+    /* Make sure maxUlps is non-negative and small enough that the
+     * default NAN won't compare as equal to anything. */
+    assert(maxUlps > 0 && maxUlps < 4 * 1024 * 1024);
+    aInt= *(int*)&A;
+    /* Make aInt lexicographically ordered as a twos-complement int */
+    if (aInt < 0)
+        aInt = 0x80000000 - aInt;
+    /* Make bInt lexicographically ordered as a twos-complement int */
+    bInt = *(int*)&B;
+    if (bInt < 0)
+        bInt = 0x80000000 - bInt;
+    intDiff = abs(aInt - bInt);
+    if (intDiff <= maxUlps)
+        return TRUE;
+    return FALSE;
+}
+
 static void D3DXCreateSphereTest(void)
 {
     HRESULT hr;
@@ -488,6 +511,8 @@ static void D3DXCreateSphereTest(void)
     IDirect3DVertexBuffer9* vertex_buffer = NULL;
     D3DVERTEXBUFFER_DESC vertex_buffer_description;
     D3DXVECTOR3* vertex_data = NULL;
+    D3DXVECTOR3 test_vertex_data[8];
+    int i;
 
     hr = D3DXCreateSphere(NULL, 0.0f, 0, 0, NULL, NULL);
     todo_wine ok( hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n",hr,D3DERR_INVALIDCALL);
@@ -556,6 +581,26 @@ static void D3DXCreateSphereTest(void)
             hr = IDirect3DVertexBuffer9_Lock(vertex_buffer, 0, 0, (LPVOID *)&vertex_data, D3DLOCK_DISCARD);
             todo_wine ok( hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n",hr);
 
+            if (vertex_data)
+            {
+                test_vertex_data[0].x = 0.0f; test_vertex_data[0].y = 0.0f; test_vertex_data[0].z = 1.0f;
+                test_vertex_data[1].x = 0.0f; test_vertex_data[1].y = 0.0f; test_vertex_data[1].z = 1.0f;
+                test_vertex_data[2].x = 0.0f; test_vertex_data[2].y = 1.0f; test_vertex_data[2].z = -4.37114e-008f;
+                test_vertex_data[3].x = 0.0f; test_vertex_data[3].y = 1.0f; test_vertex_data[3].z = -4.37114e-008f;
+                test_vertex_data[4].x = -8.74228e-008f; test_vertex_data[4].y = -1.0f; test_vertex_data[4].z = -4.37114e-008f;
+                test_vertex_data[5].x = -8.74228e-008f; test_vertex_data[5].y = -1.0f; test_vertex_data[5].z = -4.37114e-008f;
+                test_vertex_data[6].x = 0.0f; test_vertex_data[6].y = 0.0f; test_vertex_data[6].z = -1.0f;
+                test_vertex_data[7].x = 0.0f; test_vertex_data[7].y = 0.0f; test_vertex_data[7].z = -1.0f;
+
+                /* number_of_vertices*2 as we have both (x,y,z) and normals (nx,ny,nz) */
+                for (i=0; i<number_of_vertices*2; i++)
+                {
+                    todo_wine ok( AlmostEqual2sComplement(vertex_data[i].x,test_vertex_data[i].x,5), "Got result %g, expected %g\n",vertex_data[i].x,test_vertex_data[i].x);
+                    todo_wine ok( AlmostEqual2sComplement(vertex_data[i].y,test_vertex_data[i].y,5), "Got result %g, expected %g\n",vertex_data[i].y,test_vertex_data[i].y);
+                    todo_wine ok( AlmostEqual2sComplement(vertex_data[i].z,test_vertex_data[i].z,5), "Got result %g, expected %g\n",vertex_data[i].z,test_vertex_data[i].z);
+                }
+            }
+
             IDirect3DVertexBuffer9_Unlock(vertex_buffer);
         }
 
-- 
1.7.1






More information about the wine-patches mailing list