[v2 2/4] d3dx9/tests: Add tests for effect state manager.

Paul Gofman gofmanp at gmail.com
Mon Apr 10 04:57:39 CDT 2017


Signed-off-by: Paul Gofman <gofmanp at gmail.com>
---
v2:
    - renamed test_effect_states_record[] to expected_updates[].  
---
 dlls/d3dx9_36/tests/effect.c | 139 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 139 insertions(+)

diff --git a/dlls/d3dx9_36/tests/effect.c b/dlls/d3dx9_36/tests/effect.c
index 1b5d439..6da7686 100644
--- a/dlls/d3dx9_36/tests/effect.c
+++ b/dlls/d3dx9_36/tests/effect.c
@@ -5404,12 +5404,18 @@ static HRESULT WINAPI test_manager_SetMaterial(ID3DXEffectStateManager *iface,
 static HRESULT WINAPI test_manager_SetLight(ID3DXEffectStateManager *iface,
         DWORD index, const D3DLIGHT9 *light)
 {
+    struct test_manager *state_manager = impl_from_ID3DXEffectStateManager(iface);
+
+    IDirect3DDevice9_SetLight(state_manager->device, index, light);
     return test_process_set_state(iface, 2, index, 0);
 }
 
 static HRESULT WINAPI test_manager_LightEnable(ID3DXEffectStateManager *iface,
         DWORD index, BOOL enable)
 {
+    struct test_manager *state_manager = impl_from_ID3DXEffectStateManager(iface);
+
+    IDirect3DDevice9_LightEnable(state_manager->device, index, enable);
     return test_process_set_state(iface, 3, index, 0);
 }
 
@@ -5534,14 +5540,147 @@ static void test_effect_state_manager_init(struct test_manager *state_manager,
     state_manager->device = device;
 }
 
+static const char *test_effect_state_manager_state_names[] =
+{
+    "SetTransform",
+    "SetMaterial",
+    "SetLight",
+    "LightEnable",
+    "SetRenderState",
+    "SetTexture",
+    "SetTextureStageState",
+    "SetSamplerState",
+    "SetNPatchMode",
+    "SetFVF",
+    "SetVertexShader",
+    "SetVertexShaderConstantF",
+    "SetVertexShaderConstantI",
+    "SetVertexShaderConstantB",
+    "SetPixelShader",
+    "SetPixelShaderConstantF",
+    "SetPixelShaderConstantI",
+    "SetPixelShaderConstantB",
+};
+
+static int compare_update_record(const void *a, const void *b)
+{
+    const struct test_state_manager_update *r1 = (const struct test_state_manager_update *)a;
+    const struct test_state_manager_update *r2 = (const struct test_state_manager_update *)b;
+
+    if (r1->state_op != r2->state_op)
+        return r1->state_op - r2->state_op;
+    if (r1->param1 != r2->param1)
+        return r1->param1 - r2->param1;
+    return r1->param2 - r2->param2;
+}
+
 static void test_effect_state_manager(IDirect3DDevice9 *device)
 {
+    static const struct test_state_manager_update expected_updates[] =
+    {
+        {2, 0, 0},
+        {2, 1, 0},
+        {2, 2, 0},
+        {2, 3, 0},
+        {2, 4, 0},
+        {2, 5, 0},
+        {2, 6, 0},
+        {2, 7, 0},
+        {3, 0, 0},
+        {3, 1, 0},
+        {3, 2, 0},
+        {3, 3, 0},
+        {3, 4, 0},
+        {3, 5, 0},
+        {3, 6, 0},
+        {3, 7, 0},
+        {4, 28, 0},
+        {4, 36, 0},
+        {4, 38, 0},
+        {4, 158, 0},
+        {4, 159, 0},
+        {5, 0, 0},
+        {5, 257, 0},
+        {7, 0, 5},
+        {7, 0, 6},
+        {7, 257, 5},
+        {7, 257, 6},
+        {10, 0, 0},
+        {11, 0, 34},
+        {14, 0, 0},
+        {15, 0, 14},
+        {16, 0, 1},
+        {17, 0, 5},
+    };
+    static D3DLIGHT9 light_filler =
+            {D3DLIGHT_DIRECTIONAL, {0.5f, 0.5f, 0.5f, 0.5f}, {0.5f, 0.5f, 0.5f, 0.5f}, {0.5f, 0.5f, 0.5f, 0.5f}};
     struct test_manager *state_manager;
+    unsigned int passes_count, i, n;
+    ID3DXEffect *effect;
     ULONG refcount;
+    HRESULT hr;
 
     state_manager = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*state_manager));
     test_effect_state_manager_init(state_manager, device);
 
+    for (i = 0; i < 8; ++i)
+    {
+        hr = IDirect3DDevice9_SetLight(device, i, &light_filler);
+        ok(hr == D3D_OK, "Got result %#x.\n", hr);
+    }
+
+    hr = D3DXCreateEffect(device, test_effect_preshader_effect_blob, sizeof(test_effect_preshader_effect_blob),
+            NULL, NULL, 0, NULL, &effect, NULL);
+    ok(hr == D3D_OK, "Got result %#x.\n", hr);
+
+    hr = effect->lpVtbl->SetStateManager(effect, &state_manager->ID3DXEffectStateManager_iface);
+    ok(hr == D3D_OK, "Got result %#x.\n", hr);
+
+    hr = effect->lpVtbl->Begin(effect, &passes_count, 0);
+    ok(hr == D3D_OK, "Got result %#x.\n", hr);
+
+    hr = effect->lpVtbl->BeginPass(effect, 0);
+    ok(hr == D3D_OK, "Got result %#x.\n", hr);
+
+    hr = effect->lpVtbl->EndPass(effect);
+    ok(hr == D3D_OK, "Got result %#x.\n", hr);
+
+    hr = effect->lpVtbl->End(effect);
+    ok(hr == D3D_OK, "Got result %#x.\n", hr);
+
+    effect->lpVtbl->Release(effect);
+
+    qsort(state_manager->update_record, state_manager->update_record_count,
+            sizeof(*state_manager->update_record), compare_update_record);
+
+    todo_wine
+    ok(ARRAY_SIZE(expected_updates) == state_manager->update_record_count,
+            "Expected %u update records, got %u.\n", ARRAY_SIZE(expected_updates),
+            state_manager->update_record_count);
+    n = min(ARRAY_SIZE(expected_updates), state_manager->update_record_count);
+    for (i = 0; i < n; ++i)
+    {
+        todo_wine
+        ok(!memcmp(&expected_updates[i], &state_manager->update_record[i],
+                sizeof(expected_updates[i])),
+                "Update record mismatch, expected %s, %u, %u, got %s, %u, %u.\n",
+                test_effect_state_manager_state_names[expected_updates[i].state_op],
+                expected_updates[i].param1, expected_updates[i].param2,
+                test_effect_state_manager_state_names[state_manager->update_record[i].state_op],
+                state_manager->update_record[i].param1, state_manager->update_record[i].param2);
+    }
+
+    for (i = 0; i < 8; ++i)
+    {
+        D3DLIGHT9 light;
+
+        hr = IDirect3DDevice9_GetLight(device, i, &light);
+        ok(hr == D3D_OK, "Got result %#x.\n", hr);
+        todo_wine
+        ok(!memcmp(&light, &light_filler, sizeof(light)), "Light %u mismatch.\n", i);
+    }
+
+
     refcount = state_manager->ID3DXEffectStateManager_iface.lpVtbl
             ->Release(&state_manager->ID3DXEffectStateManager_iface);
     ok(!refcount, "State manager was not properly freed, refcount %u.\n", refcount);
-- 
2.9.3




More information about the wine-patches mailing list