From fca4cadaab8d7abe008232d13c814bdc4e3f0f0a Mon Sep 17 00:00:00 2001
From: David Adam <david.adam.cnrs@gmail.com>
Date: Wed, 18 Jun 2008 02:41:53 +0200
Subject: [PATCH] Implement a few tests for MatrixStack

---
 dlls/d3dx8/tests/Makefile.in |    2 +-
 dlls/d3dx8/tests/math.c      |  104 +++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 104 insertions(+), 2 deletions(-)

diff --git a/dlls/d3dx8/tests/Makefile.in b/dlls/d3dx8/tests/Makefile.in
index 5306634..d5e4856 100644
--- a/dlls/d3dx8/tests/Makefile.in
+++ b/dlls/d3dx8/tests/Makefile.in
@@ -3,7 +3,7 @@ TOPOBJDIR = ../../..
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 TESTDLL   = d3dx8.dll
-IMPORTS   = dxguid d3dx8 kernel32
+IMPORTS   = dxerr8 dxguid d3dx8 user32 kernel32
 
 CTESTS = math.c
 
diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c
index e69c6d2..33fec23 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -18,6 +18,7 @@
 
 #include <assert.h>
 #include "d3dx8.h"
+#include <dxerr8.h>
 
 #include "wine/test.h"
 
@@ -685,7 +686,7 @@ static void D3X8QuaternionTest(void)
     Nq1.x = 0.2f; Nq1.y = 0.1f; Nq1.z = 0.3; Nq1.w= 0.9f;
     expectedquat.x = 0.206945f; expectedquat.y = 0.103473f; expectedquat.z = 0.310418f; expectedquat.w = 0.0f;
     D3DXQuaternionLn(&gotquat,&Nq1);
-    todo_wine{ expect_vec4(expectedquat,gotquat) };
+    todo_wine expect_vec4(expectedquat,gotquat);
 
 /*_______________D3DXQuaternionMultiply________________________*/
     expectedquat.x = 3.0f; expectedquat.y = 61.0f; expectedquat.z = -32.0f; expectedquat.w = 85.0f;
@@ -1296,6 +1297,106 @@ static void D3X8Vector4Test(void)
     expect_vec4(expectedtrans,gottrans);
 }
 
+static void MatrixStackTest(void)
+{
+    unsigned int j, size_stack;
+    D3DXMATRIX expectedmat, gotmat, m1, m2, m3, m4;
+    HRESULT hr;
+    LPD3DXMATRIXSTACK pmstack = NULL;
+
+    U(m1).m[0][1] = 1.0f; U(m1).m[0][2] = 2.0f; U(m1).m[0][3] = 3.0f;
+    U(m1).m[1][0] = 4.0f; U(m1).m[1][2] = 5.0f; U(m1).m[1][3] = 6.0f;
+    U(m1).m[2][0] = 7.0f; U(m1).m[2][1] = 8.0f; U(m1).m[2][3] = 9.0f;
+    U(m1).m[3][0] = 10.0f; U(m1).m[3][1] = 11.0f; U(m1).m[3][2] = 12.0f;
+    U(m1).m[0][0] = 13.0f; U(m1).m[1][1] = 14.0f; U(m1).m[2][2] = 15.0f;
+    U(m1).m[3][3] = 16.0f;
+
+    U(m2).m[0][1] = 17.0f; U(m2).m[0][2] = 18.0f; U(m2).m[0][3] = 19.0f;
+    U(m2).m[1][0] = 20.0f; U(m2).m[1][2] = 21.0f; U(m2).m[1][3] = 22.0f;
+    U(m2).m[2][0] = 23.0f; U(m2).m[2][1] = 24.0f; U(m2).m[2][3] = 25.0f;
+    U(m2).m[3][0] = 26.0f; U(m2).m[3][1] = 27.0f; U(m2).m[3][2] = 28.0f;
+    U(m2).m[0][0] = 29.0f; U(m2).m[1][1] = 30.0f; U(m2).m[2][2] = 31.0f;
+    U(m2).m[3][3] = 32.0f;
+
+    U(m3).m[0][1] = 33.0f; U(m3).m[0][2] = 34.0f; U(m3).m[0][3] = 35.0f;
+    U(m3).m[1][0] = 36.0f; U(m3).m[1][2] = 37.0f; U(m3).m[1][3] = 38.0f;
+    U(m3).m[2][0] = 39.0f; U(m3).m[2][1] = 40.0f; U(m3).m[2][3] = 41.0f;
+    U(m3).m[3][0] = 42.0f; U(m3).m[3][1] = 43.0f; U(m3).m[3][2] = 44.0f;
+    U(m3).m[0][0] = 45.0f; U(m3).m[1][1] = 46.0f; U(m3).m[2][2] = 47.0f;
+    U(m3).m[3][3] = 48.0f;
+
+    U(m4).m[0][1] = 49.0f; U(m4).m[0][2] = 50.0f; U(m4).m[0][3] = 51.0f;
+    U(m4).m[1][0] = 52.0f; U(m4).m[1][2] = 53.0f; U(m4).m[1][3] = 54.0f;
+    U(m4).m[2][0] = 55.0f; U(m4).m[2][1] = 56.0f; U(m4).m[2][3] = 57.0f;
+    U(m4).m[3][0] = 58.0f; U(m4).m[3][1] = 59.0f; U(m4).m[3][2] = 60.0f;
+    U(m4).m[0][0] = 61.0f; U(m4).m[1][1] = 62.0f; U(m4).m[2][2] = 63.0f;
+    U(m4).m[3][3] = 64.0f;
+
+/*________________Initialization of MatrixStack________________*/
+    U(expectedmat).m[0][0] = 1.0f; U(expectedmat).m[0][1] = 0.0f; U(expectedmat).m[0][2] = 0.0f; U(expectedmat).m[0][3] = 0.0f;
+    U(expectedmat).m[1][0] = 0.0f; U(expectedmat).m[1][1] = 1.0f; U(expectedmat).m[1][2] = 0.0f; U(expectedmat).m[1][3] = 0.0f;
+    U(expectedmat).m[2][0] = 0.0f; U(expectedmat).m[2][1] = 0.0f; U(expectedmat).m[2][2] = 1.0f; U(expectedmat).m[2][3] = 0.0f;
+    U(expectedmat).m[3][0] = 0.0f; U(expectedmat).m[3][1] = 0.0f; U(expectedmat).m[3][2] = 0.0f; U(expectedmat).m[3][3] = 1.0f;
+    D3DXCreateMatrixStack(0,&pmstack);
+    gotmat= *ID3DXMatrixStack_GetTop(pmstack);
+    expect_mat(expectedmat,gotmat);
+
+/*__To pop a stack with only one element is authorized, and does nothing__*/
+    ID3DXMatrixStack_LoadMatrix(pmstack,&m1);
+    hr=ID3DXMatrixStack_Pop(pmstack);
+    ok(hr == D3D_OK, "Expected D3D_OK, got %s\n",  DXGetErrorString8(hr));
+    gotmat= *ID3DXMatrixStack_GetTop(pmstack);
+    expect_mat(m1,gotmat);
+
+/*__________________Test the basic functions Pop and Push__________________*/
+    ID3DXMatrixStack_Release(pmstack);
+    D3DXCreateMatrixStack(0,&pmstack);
+    size_stack=1000;
+    for (j=0;j<size_stack;j++)
+    {
+     ID3DXMatrixStack_Push(pmstack);
+     ID3DXMatrixStack_LoadMatrix(pmstack,&m1);
+     gotmat= *ID3DXMatrixStack_GetTop(pmstack);
+     expect_mat(m1,gotmat);
+     ID3DXMatrixStack_Push(pmstack);
+     ID3DXMatrixStack_LoadMatrix(pmstack,&m2);
+     gotmat= *ID3DXMatrixStack_GetTop(pmstack);
+     expect_mat(m2,gotmat);
+     ID3DXMatrixStack_Push(pmstack);
+     ID3DXMatrixStack_LoadMatrix(pmstack,&m3);
+     gotmat= *ID3DXMatrixStack_GetTop(pmstack);
+     expect_mat(m3,gotmat);
+     ID3DXMatrixStack_Push(pmstack);
+     ID3DXMatrixStack_LoadMatrix(pmstack,&m4);
+     gotmat= *ID3DXMatrixStack_GetTop(pmstack);
+     expect_mat(m4,gotmat);
+    }
+    ID3DXMatrixStack_Push(pmstack);
+    for (j=0;j<size_stack;j++)
+    {
+     ID3DXMatrixStack_Pop(pmstack);
+     gotmat= *ID3DXMatrixStack_GetTop(pmstack);
+     expect_mat(m4,gotmat);
+     ID3DXMatrixStack_Pop(pmstack);
+     gotmat= *ID3DXMatrixStack_GetTop(pmstack);
+     expect_mat(m3,gotmat);
+     ID3DXMatrixStack_Pop(pmstack);
+     gotmat= *ID3DXMatrixStack_GetTop(pmstack);
+     expect_mat(m2,gotmat);
+     ID3DXMatrixStack_Pop(pmstack);
+     gotmat= *ID3DXMatrixStack_GetTop(pmstack);
+     expect_mat(m1,gotmat);
+    }
+
+/*________________Test LoadMatrix with a null entry_______________*/
+    for (j=0;j<5;j++)
+    {
+     ID3DXMatrixStack_Push(pmstack);
+    }
+    hr=ID3DXMatrixStack_LoadMatrix(pmstack, NULL);
+    ok(hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %s\n",  DXGetErrorString8(hr));
+}
+
 START_TEST(math)
 {
     D3DXColorTest();
@@ -1305,4 +1406,5 @@ START_TEST(math)
     D3X8Vector2Test();
     D3X8Vector3Test();
     D3X8Vector4Test();
+    MatrixStackTest();
 }
-- 
1.5.4.3

