Christian Costa : d3dx9_36: Implement ID3DXFileImpl_RegisterTemplates + tests.

Alexandre Julliard julliard at winehq.org
Fri Jan 4 12:26:02 CST 2013


Module: wine
Branch: master
Commit: b742b98c55cb775066768b7f86b883cc1ca9ce3a
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=b742b98c55cb775066768b7f86b883cc1ca9ce3a

Author: Christian Costa <titan.costa at gmail.com>
Date:   Fri Jan  4 09:45:08 2013 +0100

d3dx9_36: Implement ID3DXFileImpl_RegisterTemplates + tests.

---

 dlls/d3dx9_36/tests/xfile.c |   59 ++++++++++++++++++++++++++++++++++++++++---
 dlls/d3dx9_36/xfile.c       |   48 +++++++++++++++++++++++++++++++++-
 2 files changed, 101 insertions(+), 6 deletions(-)

diff --git a/dlls/d3dx9_36/tests/xfile.c b/dlls/d3dx9_36/tests/xfile.c
index 5500949..08a2ae1 100644
--- a/dlls/d3dx9_36/tests/xfile.c
+++ b/dlls/d3dx9_36/tests/xfile.c
@@ -20,16 +20,67 @@
 #include "d3dx9.h"
 #include "d3dx9xof.h"
 
-START_TEST(xfile)
+char templates_bad_file_type1[] =
+"xOf 0302txt 0064\n";
+
+char templates_bad_file_version[] =
+"xof 0102txt 0064\n";
+
+char templates_bad_file_type2[] =
+"xof 0302foo 0064\n";
+
+char templates_bad_file_float_size[] =
+"xof 0302txt 0050\n";
+
+char templates_parse_error[] =
+"xof 0302txt 0064"
+"foobar;\n";
+
+char templates[] =
+"xof 0302txt 0064"
+"template Header"
+"{"
+"<3D82AB43-62DA-11CF-AB39-0020AF71E433>"
+"WORD major;"
+"WORD minor;"
+"DWORD flags;"
+"}\n";
+
+
+void test_templates(void)
 {
-    ID3DXFile *file;
+    ID3DXFile *d3dxfile;
     HRESULT ret;
 
     ret = D3DXFileCreate(NULL);
     ok(ret == E_POINTER, "D3DXCreateFile returned %#x, expected %#x\n", ret, E_POINTER);
 
-    ret = D3DXFileCreate(&file);
+    ret = D3DXFileCreate(&d3dxfile);
     ok(ret == S_OK, "D3DXCreateFile failed with %#x\n", ret);
 
-    file->lpVtbl->Release(file);
+    ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, (const void *)templates_bad_file_type1, (SIZE_T)(sizeof(templates_bad_file_type1) - 1));
+    ok(ret == D3DXFERR_BADFILETYPE, "RegisterTemplates returned %#x, expected %#x\n", ret, D3DXFERR_BADFILETYPE);
+
+    ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, (const void *)templates_bad_file_version, (SIZE_T)(sizeof(templates_bad_file_version) - 1));
+    ok(ret == D3DXFERR_BADFILEVERSION, "RegisterTemplates returned %#x, expected %#x\n", ret, D3DXFERR_BADFILEVERSION);
+
+    ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, (const void *)templates_bad_file_type2, (SIZE_T)(sizeof(templates_bad_file_type2) - 1));
+    ok(ret == D3DXFERR_BADFILETYPE, "RegisterTemplates returned %#x, expected %#x\n", ret, D3DXFERR_BADFILETYPE);
+
+    ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, (const void *)templates_bad_file_float_size, (SIZE_T)(sizeof(templates_bad_file_float_size) - 1));
+    ok(ret == D3DXFERR_BADFILEFLOATSIZE, "RegisterTemplates returned %#x, expected %#x\n", ret, D3DXFERR_BADFILEFLOATSIZE);
+
+    ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, (const void *)templates_parse_error, (SIZE_T)(sizeof(templates_parse_error) - 1));
+    todo_wine ok(ret == D3DXFERR_PARSEERROR, "RegisterTemplates returned %#x, expected %#x\n", ret, D3DXFERR_PARSEERROR);
+
+    ret = d3dxfile->lpVtbl->RegisterTemplates(d3dxfile, (const void *)templates, (SIZE_T)(sizeof(templates) - 1));
+    ok(ret == S_OK, "RegisterTemplates with %#x\n", ret);
+
+    d3dxfile->lpVtbl->Release(d3dxfile);
+}
+
+
+START_TEST(xfile)
+{
+    test_templates();
 }
diff --git a/dlls/d3dx9_36/xfile.c b/dlls/d3dx9_36/xfile.c
index ba04857..5d4d6aa 100644
--- a/dlls/d3dx9_36/xfile.c
+++ b/dlls/d3dx9_36/xfile.c
@@ -21,12 +21,33 @@
 
 #include "d3dx9.h"
 #include "d3dx9xof.h"
+#undef MAKE_DDHRESULT
+#include "dxfile.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
 
+HRESULT error_dxfile_to_d3dxfile(HRESULT error)
+{
+    switch (error)
+    {
+        case DXFILEERR_BADFILETYPE:
+            return D3DXFERR_BADFILETYPE;
+        case DXFILEERR_BADFILEVERSION:
+            return D3DXFERR_BADFILEVERSION;
+        case DXFILEERR_BADFILEFLOATSIZE:
+            return D3DXFERR_BADFILEFLOATSIZE;
+        case DXFILEERR_PARSEERROR:
+            return D3DXFERR_PARSEERROR;
+        default:
+            FIXME("Cannot map error %#x\n", error);
+            return E_FAIL;
+    }
+}
+
 typedef struct {
     ID3DXFile ID3DXFile_iface;
     LONG ref;
+    IDirectXFile *dxfile;
 } ID3DXFileImpl;
 
 
@@ -75,7 +96,10 @@ static ULONG WINAPI ID3DXFileImpl_Release(ID3DXFile *iface)
     TRACE("(%p)->(): new ref %d\n", iface, ref);
 
     if (!ref)
+    {
+        IDirectXFile_Release(This->dxfile);
         HeapFree(GetProcessHeap(), 0, This);
+    }
 
     return ref;
 }
@@ -101,9 +125,19 @@ static HRESULT WINAPI ID3DXFileImpl_CreateSaveObject(ID3DXFile *iface, const voi
 
 static HRESULT WINAPI ID3DXFileImpl_RegisterTemplates(ID3DXFile *iface, const void *data, SIZE_T size)
 {
-    FIXME("(%p)->(%p, %lu): stub\n", iface, data, size);
+    ID3DXFileImpl *This = impl_from_ID3DXFile(iface);
+    HRESULT ret;
 
-    return E_NOTIMPL;
+    TRACE("(%p)->(%p, %lu)\n", iface, data, size);
+
+    ret = IDirectXFile_RegisterTemplates(This->dxfile, (void*)data, size);
+    if (ret != DXFILE_OK)
+    {
+        WARN("Error %#x\n", ret);
+        return error_dxfile_to_d3dxfile(ret);
+    }
+
+    return S_OK;
 }
 
 
@@ -129,6 +163,7 @@ static const ID3DXFileVtbl ID3DXFile_Vtbl =
 HRESULT WINAPI D3DXFileCreate(ID3DXFile **d3dxfile)
 {
     ID3DXFileImpl *object;
+    HRESULT ret;
 
     TRACE("(%p)\n", d3dxfile);
 
@@ -141,6 +176,15 @@ HRESULT WINAPI D3DXFileCreate(ID3DXFile **d3dxfile)
     if (!object)
         return E_OUTOFMEMORY;
 
+    ret = DirectXFileCreate(&object->dxfile);
+    if (ret != S_OK)
+    {
+        HeapFree(GetProcessHeap(), 0, object);
+        if (ret == E_OUTOFMEMORY)
+            return ret;
+        return E_FAIL;
+    }
+
     object->ID3DXFile_iface.lpVtbl = &ID3DXFile_Vtbl;
     object->ref = 1;
 




More information about the wine-cvs mailing list