Christian Costa : d3dxof: Make FileEnumObject keep references to top level objects. Add corresponding test.

Alexandre Julliard julliard at winehq.org
Tue Dec 23 13:41:43 CST 2008


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

Author: Christian Costa <titan.costa at wanadoo.fr>
Date:   Tue Dec 23 12:47:48 2008 +0100

d3dxof: Make FileEnumObject keep references to top level objects. Add corresponding test.

---

 dlls/d3dxof/d3dxof.c         |    7 +++++
 dlls/d3dxof/d3dxof_private.h |    1 +
 dlls/d3dxof/tests/d3dxof.c   |   51 +++++++++++++++++++++++++++++++++++++----
 3 files changed, 54 insertions(+), 5 deletions(-)

diff --git a/dlls/d3dxof/d3dxof.c b/dlls/d3dxof/d3dxof.c
index 0dc93af..46f3db9 100644
--- a/dlls/d3dxof/d3dxof.c
+++ b/dlls/d3dxof/d3dxof.c
@@ -1909,6 +1909,9 @@ static ULONG WINAPI IDirectXFileEnumObjectImpl_Release(IDirectXFileEnumObject* i
 
   if (!ref)
   {
+    int i;
+    for (i = 0; i < This->nb_xobjects; i++)
+      IDirectXFileData_Release(This->pRefObjects[i]);
     if (This->source == DXFILELOAD_FROMFILE)
       HeapFree(GetProcessHeap(), 0, This->buf.buffer);
     if (This->hFile != INVALID_HANDLE_VALUE)
@@ -2302,6 +2305,10 @@ static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetNextDataObject(IDirectXFileE
 
   *ppDataObj = (LPDIRECTXFILEDATA)object;
 
+  /* Get a reference to created object */
+  This->pRefObjects[This->nb_xobjects] = (LPDIRECTXFILEDATA)object;
+  IDirectXFileData_AddRef(This->pRefObjects[This->nb_xobjects]);
+
   This->nb_xobjects++;
 
   return DXFILE_OK;
diff --git a/dlls/d3dxof/d3dxof_private.h b/dlls/d3dxof/d3dxof_private.h
index 58b0416..bc78bc0 100644
--- a/dlls/d3dxof/d3dxof_private.h
+++ b/dlls/d3dxof/d3dxof_private.h
@@ -151,6 +151,7 @@ typedef struct {
     IDirectXFileImpl* pDirectXFile;
     ULONG nb_xobjects;
     xobject* xobjects[MAX_OBJECTS];
+    IDirectXFileData* pRefObjects[MAX_OBJECTS];
 } IDirectXFileEnumObjectImpl;
 
 typedef struct {
diff --git a/dlls/d3dxof/tests/d3dxof.c b/dlls/d3dxof/tests/d3dxof.c
index f707586..12df0c6 100644
--- a/dlls/d3dxof/tests/d3dxof.c
+++ b/dlls/d3dxof/tests/d3dxof.c
@@ -46,6 +46,13 @@ char template[] =
 "DWORD flags;\n"
 "}\n";
 
+char object[] =
+"xof 0302txt 0064\n"
+"Header Object\n"
+"{\n"
+"1; 2; 3;\n"
+"}\n";
+
 static void init_function_pointers(void)
 {
     /* We have to use LoadLibrary as no d3dxof functions are referenced directly */
@@ -60,11 +67,14 @@ static unsigned long getRefcount(IUnknown *iface)
     return IUnknown_Release(iface);
 }
 
-static void test_d3dxof(void)
+static void test_refcount(void)
 {
     HRESULT hr;
     unsigned long ref;
     LPDIRECTXFILE lpDirectXFile = NULL;
+    LPDIRECTXFILEENUMOBJECT lpdxfeo;
+    LPDIRECTXFILEDATA lpdxfd;
+    DXFILELOADMEMORY dxflm;
 
     if (!pDirectXFileCreate)
     {
@@ -82,18 +92,49 @@ static void test_d3dxof(void)
 
     ref = getRefcount( (IUnknown *) lpDirectXFile);
     ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
-
     ref = IDirectXFile_AddRef(lpDirectXFile);
     ok(ref == 2, "Got refcount %ld, expected 1\n", ref);
-
     ref = IDirectXFile_Release(lpDirectXFile);
     ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
 
     hr = IDirectXFile_RegisterTemplates(lpDirectXFile, template, strlen(template));
     ok(hr == DXFILE_OK, "IDirectXFileImpl_RegisterTemplates: %x\n", hr);
 
+    dxflm.lpMemory = &object;
+    dxflm.dSize = strlen(object);
+    hr = IDirectXFile_CreateEnumObject(lpDirectXFile, &dxflm, DXFILELOAD_FROMMEMORY, &lpdxfeo);
+    ok(hr == DXFILE_OK, "IDirectXFile_CreateEnumObject: %x\n", hr);
+    ref = getRefcount( (IUnknown *) lpDirectXFile);
+    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
+    ref = getRefcount( (IUnknown *) lpdxfeo);
+    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
+
+    hr = IDirectXFileEnumObject_GetNextDataObject(lpdxfeo, &lpdxfd);
+    ok(hr == DXFILE_OK, "IDirectXFileEnumObject_GetNextDataObject: %x\n", hr);
+    ref = getRefcount( (IUnknown *) lpDirectXFile);
+    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
+    ref = getRefcount( (IUnknown *) lpdxfeo);
+    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
+    /* Enum object gets references to all top level objects */
+    ref = getRefcount( (IUnknown *) lpdxfd);
+    ok(ref == 2, "Got refcount %ld, expected 2\n", ref);
+
     ref = IDirectXFile_Release(lpDirectXFile);
-    ok(ref == 0, "Got refcount %ld, expected 1\n", ref);
+    ok(ref == 0, "Got refcount %ld, expected 0\n", ref);
+    /* Nothing changes for all other objects */
+    ref = getRefcount( (IUnknown *) lpdxfeo);
+    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
+    ref = getRefcount( (IUnknown *) lpdxfd);
+    ok(ref == 2, "Got refcount %ld, expected 1\n", ref);
+
+    ref = IDirectXFileEnumObject_Release(lpdxfeo);
+    ok(ref == 0, "Got refcount %ld, expected 0\n", ref);
+    /* Enum object releases references to all top level objects */
+    ref = getRefcount( (IUnknown *) lpdxfd);
+    ok(ref == 1, "Got refcount %ld, expected 1\n", ref);
+
+    ref = IDirectXFileData_Release(lpdxfd);
+    ok(ref == 0, "Got refcount %ld, expected 0\n", ref);
 }
 
 /* Set it to 1 to expand the string when dumping the object. This is usefull when there is
@@ -268,7 +309,7 @@ START_TEST(d3dxof)
 {
     init_function_pointers();
 
-    test_d3dxof();
+    test_refcount();
     test_dump();
 
     FreeLibrary(hd3dxof);




More information about the wine-cvs mailing list