[PATCH] DDrawex: add a refcount test=0A=

Stefan Doesinger stefan at codeweavers.com
Wed Jan 7 13:48:17 CST 2009


=0A=
---=0A=
 dlls/ddrawex/tests/Makefile.in |    1 +=0A=
 dlls/ddrawex/tests/ddrawex.c   |  120 =
++++++++++++++++++++++++++++++++++++++++=0A=
 2 files changed, 121 insertions(+), 0 deletions(-)=0A=
 create mode 100644 dlls/ddrawex/tests/ddrawex.c=0A=
=0A=
diff --git a/dlls/ddrawex/tests/Makefile.in =
b/dlls/ddrawex/tests/Makefile.in=0A=
index a945c81..709059e 100644=0A=
--- a/dlls/ddrawex/tests/Makefile.in=0A=
+++ b/dlls/ddrawex/tests/Makefile.in=0A=
@@ -6,6 +6,7 @@ TESTDLL   =3D ddrawex.dll=0A=
 IMPORTS   =3D user32 gdi32 kernel32=0A=
 =0A=
 CTESTS =3D \=0A=
+	ddrawex.c \=0A=
 	surface.c=0A=
 =0A=
 @MAKE_TEST_RULES@=0A=
diff --git a/dlls/ddrawex/tests/ddrawex.c b/dlls/ddrawex/tests/ddrawex.c=0A=
new file mode 100644=0A=
index 0000000..8538c84=0A=
--- /dev/null=0A=
+++ b/dlls/ddrawex/tests/ddrawex.c=0A=
@@ -0,0 +1,120 @@=0A=
+/*=0A=
+ * Unit tests for ddrawex specific things=0A=
+ *=0A=
+ * This library is free software; you can redistribute it and/or=0A=
+ * modify it under the terms of the GNU Lesser General Public=0A=
+ * License as published by the Free Software Foundation; either=0A=
+ * version 2.1 of the License, or (at your option) any later version.=0A=
+ *=0A=
+ * This library is distributed in the hope that it will be useful,=0A=
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of=0A=
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU=0A=
+ * Lesser General Public License for more details.=0A=
+ *=0A=
+ * You should have received a copy of the GNU Lesser General Public=0A=
+ * License along with this library; if not, write to the Free Software=0A=
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA =
02110-1301, USA=0A=
+ */=0A=
+#define COBJMACROS=0A=
+=0A=
+#include <assert.h>=0A=
+#include "wine/test.h"=0A=
+#include "windef.h"=0A=
+#include "winbase.h"=0A=
+#include "ddraw.h"=0A=
+#include "ddrawex.h"=0A=
+#include "unknwn.h"=0A=
+=0A=
+IDirectDrawFactory *factory;=0A=
+HRESULT (WINAPI *pDllGetClassObject)(REFCLSID rclsid, REFIID riid, =
LPVOID *ppv);=0A=
+=0A=
+static IDirectDraw *createDD()=0A=
+{=0A=
+    HRESULT hr;=0A=
+    IDirectDraw *dd;=0A=
+=0A=
+    hr =3D IDirectDrawFactory_CreateDirectDraw(factory, NULL, NULL, =
DDSCL_NORMAL, 0,=0A=
+                                             0, &dd);=0A=
+    ok(hr =3D=3D DD_OK, "Failed to create an IDirectDraw interface, hr =
=3D 0x%08x\n", hr);=0A=
+    return SUCCEEDED(hr) ? dd : NULL;=0A=
+}=0A=
+=0A=
+static ULONG get_ref(IUnknown *o)=0A=
+{=0A=
+    IUnknown_AddRef(o);=0A=
+    return IUnknown_Release(o);=0A=
+}=0A=
+=0A=
+static void RefCountTest()=0A=
+{=0A=
+    IDirectDraw *dd1 =3D createDD();=0A=
+    IDirectDraw2 *dd2;=0A=
+    IDirectDraw3 *dd3;=0A=
+    IDirectDraw4 *dd4;=0A=
+    ULONG ref;=0A=
+=0A=
+    ref =3D get_ref((IUnknown *) dd1);=0A=
+    ok(ref =3D=3D 1, "A new ddraw object's refcount is %u, expected =
1\n", ref);=0A=
+=0A=
+    IDirectDraw_AddRef(dd1);=0A=
+    ref =3D get_ref((IUnknown *) dd1);=0A=
+    ok(ref =3D=3D 2, "After AddRef the refcount is %u, expected 2\n", =
ref);=0A=
+    IDirectDraw_Release(dd1);=0A=
+    ref =3D get_ref((IUnknown *) dd1);=0A=
+    ok(ref =3D=3D 1, "After Release the refcount is %u, expected 2\n", =
ref);=0A=
+=0A=
+    IDirectDraw_QueryInterface(dd1, &IID_IDirectDraw2, (void **) &dd2);=0A=
+    ref =3D get_ref((IUnknown *) dd2);=0A=
+    ok(ref =3D=3D 2, "IDirectDraw2 refcount is %u, expected 2\n", ref);=0A=
+=0A=
+    IDirectDraw_QueryInterface(dd1, &IID_IDirectDraw3, (void **) &dd3);=0A=
+    ref =3D get_ref((IUnknown *) dd3);=0A=
+    ok(ref =3D=3D 3, "IDirectDraw3 refcount is %u, expected 3\n", ref);=0A=
+=0A=
+    IDirectDraw_QueryInterface(dd1, &IID_IDirectDraw4, (void **) &dd4);=0A=
+    ref =3D get_ref((IUnknown *) dd4);=0A=
+    ok(ref =3D=3D 4, "IDirectDraw4 refcount is %u, expected 4\n", ref);=0A=
+=0A=
+    IDirectDraw_Release(dd1);=0A=
+    IDirectDraw2_Release(dd2);=0A=
+    IDirectDraw3_Release(dd3);=0A=
+=0A=
+    ref =3D get_ref((IUnknown *) dd4);=0A=
+    ok(ref =3D=3D 1, "IDirectDraw4 refcount is %u, expected 1\n", ref);=0A=
+=0A=
+    IDirectDraw4_Release(dd4);=0A=
+}=0A=
+=0A=
+START_TEST(ddrawex)=0A=
+{=0A=
+    IClassFactory *classfactory =3D NULL;=0A=
+    ULONG ref;=0A=
+    HRESULT hr;=0A=
+    HMODULE hmod =3D LoadLibrary("ddrawex.dll");=0A=
+    if(hmod =3D=3D NULL) {=0A=
+        skip("Failed to load ddrawex.dll\n");=0A=
+        return;=0A=
+    }=0A=
+    pDllGetClassObject =3D (void*)GetProcAddress(hmod, =
"DllGetClassObject");=0A=
+    if(pDllGetClassObject =3D=3D NULL) {=0A=
+        skip("Failed to get DllGetClassObject\n");=0A=
+        return;=0A=
+    }=0A=
+=0A=
+    hr =3D pDllGetClassObject(&CLSID_DirectDrawFactory, =
&IID_IClassFactory, (void **) &classfactory);=0A=
+    ok(hr =3D=3D S_OK, "Failed to create a IClassFactory\n");=0A=
+    hr =3D IClassFactory_CreateInstance(classfactory, NULL, =
&IID_IDirectDrawFactory, (void **) &factory);=0A=
+    ok(hr =3D=3D S_OK, "Failed to create a IDirectDrawFactory\n");=0A=
+=0A=
+    RefCountTest();=0A=
+=0A=
+    if(factory) {=0A=
+        ref =3D IDirectDrawFactory_Release(factory);=0A=
+        ok(ref =3D=3D 0, "IDirectDrawFactory not cleanly released\n");=0A=
+    }=0A=
+    if(classfactory) {=0A=
+        ref =3D IClassFactory_Release(classfactory);=0A=
+        /* Seems broken: Windows always returns 1 here */=0A=
+        todo_wine ok(ref =3D=3D 1, "IClassFactory refcount wrong, ref =
=3D %u\n", ref);=0A=
+    }=0A=
+}=0A=
-- =0A=
1.6.0.6=0A=
=0A=

------=_NextPart_000_0022_01C970CF.864108C0--




More information about the wine-patches mailing list