[resend PATCH 1/4] d3dx9/tests: Add test implementation for ID3DXEffectStateManager interface.

Paul Gofman gofmanp at gmail.com
Wed Apr 5 18:32:38 CDT 2017


Signed-off-by: Paul Gofman <gofmanp at gmail.com>
---

Resending to pass testbot after it was updated to latest git, no changes.

---
 dlls/d3dx9_36/tests/effect.c | 262 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 262 insertions(+)

diff --git a/dlls/d3dx9_36/tests/effect.c b/dlls/d3dx9_36/tests/effect.c
index fd94e58..5362dac 100644
--- a/dlls/d3dx9_36/tests/effect.c
+++ b/dlls/d3dx9_36/tests/effect.c
@@ -5309,6 +5309,267 @@ static void test_effect_preshader_relative_addressing(IDirect3DDevice9 *device)
     effect->lpVtbl->Release(effect);
 }
 
+struct test_state_manager_update
+{
+    unsigned int state_op;
+    DWORD param1;
+    DWORD param2;
+};
+
+struct test_ID3DXEffectStateManagerImpl
+{
+    ID3DXEffectStateManager ID3DXEffectStateManager_iface;
+    LONG ref;
+
+    IDirect3DDevice9 *device;
+    struct test_state_manager_update *update_record;
+    unsigned int update_record_count;
+    unsigned int update_record_size;
+};
+
+#define INITIAL_UPDATE_RECORD_SIZE 64
+
+static struct test_ID3DXEffectStateManagerImpl *
+        impl_from_ID3DXEffectStateManager(ID3DXEffectStateManager *iface)
+{
+    return CONTAINING_RECORD(iface, struct test_ID3DXEffectStateManagerImpl,
+            ID3DXEffectStateManager_iface);
+}
+
+static HRESULT WINAPI test_ID3DXEffectStateManagerImpl_QueryInterface(ID3DXEffectStateManager *iface,
+        REFIID riid, void **object)
+{
+    if (IsEqualGUID(riid, &IID_IUnknown)
+            || IsEqualGUID(riid, &IID_ID3DXEffectStateManager))
+    {
+        iface->lpVtbl->AddRef(iface);
+        *object = iface;
+        return S_OK;
+    }
+
+    return E_NOINTERFACE;
+}
+
+static void free_test_effect_state_manager(struct test_ID3DXEffectStateManagerImpl *state_manager)
+{
+    HeapFree(GetProcessHeap(), 0, state_manager->update_record);
+    state_manager->update_record = NULL;
+
+    IDirect3DDevice9_Release(state_manager->device);
+}
+
+static ULONG WINAPI test_ID3DXEffectStateManagerImpl_AddRef(ID3DXEffectStateManager *iface)
+{
+    struct test_ID3DXEffectStateManagerImpl *state_manager = impl_from_ID3DXEffectStateManager(iface);
+
+    return InterlockedIncrement(&state_manager->ref);
+}
+
+static ULONG WINAPI test_ID3DXEffectStateManagerImpl_Release(ID3DXEffectStateManager *iface)
+{
+    struct test_ID3DXEffectStateManagerImpl *state_manager = impl_from_ID3DXEffectStateManager(iface);
+    ULONG ref = InterlockedDecrement(&state_manager->ref);
+
+    if (!ref)
+    {
+        free_test_effect_state_manager(state_manager);
+        HeapFree(GetProcessHeap(), 0, state_manager);
+    }
+    return ref;
+}
+
+static HRESULT test_process_set_state(ID3DXEffectStateManager *iface,
+    unsigned int state_op, DWORD param1, DWORD param2)
+{
+    struct test_ID3DXEffectStateManagerImpl *state_manager = impl_from_ID3DXEffectStateManager(iface);
+
+    if (state_manager->update_record_count == state_manager->update_record_size)
+    {
+        unsigned int new_size;
+        struct test_state_manager_update *new_alloc;
+
+        if (!state_manager->update_record_size)
+        {
+            new_size = INITIAL_UPDATE_RECORD_SIZE;
+            new_alloc = HeapAlloc(GetProcessHeap(), 0, sizeof(*state_manager->update_record) * new_size);
+            ok(!!new_alloc, "Out of memory.\n");
+        }
+        else
+        {
+            new_size = state_manager->update_record_size * 2;
+            new_alloc = HeapReAlloc(GetProcessHeap(), 0, state_manager->update_record,
+                    sizeof(*state_manager->update_record) * new_size);
+            ok(!!new_alloc, "Out of memory.\n");
+        }
+        state_manager->update_record = new_alloc;
+        state_manager->update_record_size = new_size;
+
+    }
+    state_manager->update_record[state_manager->update_record_count].state_op = state_op;
+    state_manager->update_record[state_manager->update_record_count].param1 = param1;
+    state_manager->update_record[state_manager->update_record_count].param2 = param2;
+    ++state_manager->update_record_count;
+    return D3D_OK;
+}
+
+static HRESULT WINAPI test_ID3DXEffectStateManagerImpl_SetTransform(ID3DXEffectStateManager *iface,
+        D3DTRANSFORMSTATETYPE state, const D3DMATRIX *matrix)
+{
+    return test_process_set_state(iface, 0, state, 0);
+}
+
+static HRESULT WINAPI test_ID3DXEffectStateManagerImpl_SetMaterial(ID3DXEffectStateManager *iface,
+        const D3DMATERIAL9 *material)
+{
+    return test_process_set_state(iface, 1, 0, 0);
+}
+
+static HRESULT WINAPI test_ID3DXEffectStateManagerImpl_SetLight(ID3DXEffectStateManager *iface,
+        DWORD index, const D3DLIGHT9 *light)
+{
+    return test_process_set_state(iface, 2, index, 0);
+}
+
+static HRESULT WINAPI test_ID3DXEffectStateManagerImpl_LightEnable(ID3DXEffectStateManager *iface,
+        DWORD index, BOOL enable)
+{
+    return test_process_set_state(iface, 3, index, 0);
+}
+
+static HRESULT WINAPI test_ID3DXEffectStateManagerImpl_SetRenderState(ID3DXEffectStateManager *iface,
+        D3DRENDERSTATETYPE state, DWORD value)
+{
+    return test_process_set_state(iface, 4, state, 0);
+}
+
+static HRESULT WINAPI test_ID3DXEffectStateManagerImpl_SetTexture(ID3DXEffectStateManager *iface,
+        DWORD stage, struct IDirect3DBaseTexture9 *texture)
+{
+    return test_process_set_state(iface, 5, stage, 0);
+}
+
+static HRESULT WINAPI test_ID3DXEffectStateManagerImpl_SetTextureStageState(ID3DXEffectStateManager *iface,
+        DWORD stage, D3DTEXTURESTAGESTATETYPE type, DWORD value)
+{
+    return test_process_set_state(iface, 6, stage, type);
+}
+
+static HRESULT WINAPI test_ID3DXEffectStateManagerImpl_SetSamplerState(ID3DXEffectStateManager *iface,
+        DWORD sampler, D3DSAMPLERSTATETYPE type, DWORD value)
+{
+    return test_process_set_state(iface, 7, sampler, type);
+}
+
+static HRESULT WINAPI test_ID3DXEffectStateManagerImpl_SetNPatchMode(ID3DXEffectStateManager *iface,
+        FLOAT num_segments)
+{
+    return test_process_set_state(iface, 8, 0, 0);
+}
+
+static HRESULT WINAPI test_ID3DXEffectStateManagerImpl_SetFVF(ID3DXEffectStateManager *iface,
+        DWORD format)
+{
+    return test_process_set_state(iface, 9, 0, 0);
+}
+
+static HRESULT WINAPI test_ID3DXEffectStateManagerImpl_SetVertexShader(ID3DXEffectStateManager *iface,
+        struct IDirect3DVertexShader9 *shader)
+{
+    return test_process_set_state(iface, 10, 0, 0);
+}
+
+static HRESULT WINAPI test_ID3DXEffectStateManagerImpl_SetVertexShaderConstantF(ID3DXEffectStateManager *iface,
+        UINT register_index, const FLOAT *constant_data, UINT register_count)
+{
+    return test_process_set_state(iface, 11, register_index, register_count);
+}
+
+static HRESULT WINAPI test_ID3DXEffectStateManagerImpl_SetVertexShaderConstantI(ID3DXEffectStateManager *iface,
+        UINT register_index, const INT *constant_data, UINT register_count)
+{
+    return test_process_set_state(iface, 12, register_index, register_count);
+}
+
+static HRESULT WINAPI test_ID3DXEffectStateManagerImpl_SetVertexShaderConstantB(ID3DXEffectStateManager *iface,
+        UINT register_index, const BOOL *constant_data, UINT register_count)
+{
+    return test_process_set_state(iface, 13, register_index, register_count);
+}
+
+static HRESULT WINAPI test_ID3DXEffectStateManagerImpl_SetPixelShader(ID3DXEffectStateManager *iface,
+        struct IDirect3DPixelShader9 *shader)
+{
+    return test_process_set_state(iface, 14, 0, 0);
+}
+
+static HRESULT WINAPI test_ID3DXEffectStateManagerImpl_SetPixelShaderConstantF(ID3DXEffectStateManager *iface,
+        UINT register_index, const FLOAT *constant_data, UINT register_count)
+{
+    return test_process_set_state(iface, 15, register_index, register_count);
+}
+
+static HRESULT WINAPI test_ID3DXEffectStateManagerImpl_SetPixelShaderConstantI(ID3DXEffectStateManager *iface,
+        UINT register_index, const INT *constant_data, UINT register_count)
+{
+    return test_process_set_state(iface, 16, register_index, register_count);
+}
+
+static HRESULT WINAPI test_ID3DXEffectStateManagerImpl_SetPixelShaderConstantB(ID3DXEffectStateManager *iface,
+        UINT register_index, const BOOL *constant_data, UINT register_count)
+{
+    return test_process_set_state(iface, 17, register_index, register_count);
+}
+
+static void test_effect_state_manager_init(struct test_ID3DXEffectStateManagerImpl *state_manager,
+        IDirect3DDevice9 *device)
+{
+    static const struct ID3DXEffectStateManagerVtbl test_ID3DXEffectStateManager_Vtbl =
+    {
+        /*** IUnknown methods ***/
+        test_ID3DXEffectStateManagerImpl_QueryInterface,
+        test_ID3DXEffectStateManagerImpl_AddRef,
+        test_ID3DXEffectStateManagerImpl_Release,
+        /*** ID3DXEffectStateManager methods ***/
+        test_ID3DXEffectStateManagerImpl_SetTransform,
+        test_ID3DXEffectStateManagerImpl_SetMaterial,
+        test_ID3DXEffectStateManagerImpl_SetLight,
+        test_ID3DXEffectStateManagerImpl_LightEnable,
+        test_ID3DXEffectStateManagerImpl_SetRenderState,
+        test_ID3DXEffectStateManagerImpl_SetTexture,
+        test_ID3DXEffectStateManagerImpl_SetTextureStageState,
+        test_ID3DXEffectStateManagerImpl_SetSamplerState,
+        test_ID3DXEffectStateManagerImpl_SetNPatchMode,
+        test_ID3DXEffectStateManagerImpl_SetFVF,
+        test_ID3DXEffectStateManagerImpl_SetVertexShader,
+        test_ID3DXEffectStateManagerImpl_SetVertexShaderConstantF,
+        test_ID3DXEffectStateManagerImpl_SetVertexShaderConstantI,
+        test_ID3DXEffectStateManagerImpl_SetVertexShaderConstantB,
+        test_ID3DXEffectStateManagerImpl_SetPixelShader,
+        test_ID3DXEffectStateManagerImpl_SetPixelShaderConstantF,
+        test_ID3DXEffectStateManagerImpl_SetPixelShaderConstantI,
+        test_ID3DXEffectStateManagerImpl_SetPixelShaderConstantB,
+    };
+
+    state_manager->ID3DXEffectStateManager_iface.lpVtbl = &test_ID3DXEffectStateManager_Vtbl;
+    state_manager->ref = 1;
+
+    IDirect3DDevice9_AddRef(device);
+    state_manager->device = device;
+}
+
+static void test_effect_state_manager(IDirect3DDevice9 *device)
+{
+    struct test_ID3DXEffectStateManagerImpl *state_manager;
+    ULONG refcount;
+
+    state_manager = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*state_manager));
+    test_effect_state_manager_init(state_manager, device);
+
+    refcount = state_manager->ID3DXEffectStateManager_iface.lpVtbl
+            ->Release(&state_manager->ID3DXEffectStateManager_iface);
+    ok(!refcount, "State manager was not properly freed, refcount %u.\n", refcount);
+}
+
 START_TEST(effect)
 {
     HWND wnd;
@@ -5355,6 +5616,7 @@ START_TEST(effect)
     test_effect_out_of_bounds_selector(device);
     test_effect_commitchanges(device);
     test_effect_preshader_relative_addressing(device);
+    test_effect_state_manager(device);
 
     count = IDirect3DDevice9_Release(device);
     ok(count == 0, "The device was not properly freed: refcount %u\n", count);
-- 
2.9.3




More information about the wine-patches mailing list