[PATCH 05/11] dmscript/tests: Add COM tests for DirectMusicScript.

Michael Stefaniuc mstefani at redhat.de
Sun Jan 12 15:07:01 CST 2014


---
Nothing like Windows validating and crashing due the pUnkOuter arg, just
to return CLASS_E_NOAGGREGATION...



 configure                       |   1 +
 configure.ac                    |   1 +
 dlls/dmscript/tests/Makefile.in |   5 ++
 dlls/dmscript/tests/dmscript.c  | 148 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 155 insertions(+)
 create mode 100644 dlls/dmscript/tests/Makefile.in
 create mode 100644 dlls/dmscript/tests/dmscript.c

diff --git a/configure b/configure
index a41afa4..573bb96 100755
--- a/configure
+++ b/configure
@@ -16734,6 +16734,7 @@ wine_fn_config_test dlls/dmime/tests dmime_test
 wine_fn_config_dll dmloader enable_dmloader clean
 wine_fn_config_test dlls/dmloader/tests dmloader_test
 wine_fn_config_dll dmscript enable_dmscript clean
+wine_fn_config_test dlls/dmscript/tests dmscript_test
 wine_fn_config_dll dmstyle enable_dmstyle clean
 wine_fn_config_dll dmsynth enable_dmsynth clean
 wine_fn_config_test dlls/dmsynth/tests dmsynth_test
diff --git a/configure.ac b/configure.ac
index 3d3e039..a4f0063 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2787,6 +2787,7 @@ WINE_CONFIG_TEST(dlls/dmime/tests)
 WINE_CONFIG_DLL(dmloader,,[clean])
 WINE_CONFIG_TEST(dlls/dmloader/tests)
 WINE_CONFIG_DLL(dmscript,,[clean])
+WINE_CONFIG_TEST(dlls/dmscript/tests)
 WINE_CONFIG_DLL(dmstyle,,[clean])
 WINE_CONFIG_DLL(dmsynth,,[clean])
 WINE_CONFIG_TEST(dlls/dmsynth/tests)
diff --git a/dlls/dmscript/tests/Makefile.in b/dlls/dmscript/tests/Makefile.in
new file mode 100644
index 0000000..a4b246d
--- /dev/null
+++ b/dlls/dmscript/tests/Makefile.in
@@ -0,0 +1,5 @@
+TESTDLL   = dmscript.dll
+IMPORTS   = ole32
+
+C_SRCS = \
+	dmscript.c
diff --git a/dlls/dmscript/tests/dmscript.c b/dlls/dmscript/tests/dmscript.c
new file mode 100644
index 0000000..f9612fa
--- /dev/null
+++ b/dlls/dmscript/tests/dmscript.c
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2014 Michael Stefaniuc
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#define COBJMACROS
+
+#include <stdarg.h>
+#include <windef.h>
+#include <initguid.h>
+#include <wine/test.h>
+#include <dmusici.h>
+
+static BOOL missing_dmscript(void)
+{
+    IDirectMusicScript *dms;
+    HRESULT hr = CoCreateInstance(&CLSID_DirectMusicScript, NULL, CLSCTX_INPROC_SERVER,
+            &IID_IDirectMusicScript, (void**)&dms);
+
+    if (hr == S_OK && dms)
+    {
+        IDirectMusicScript_Release(dms);
+        return FALSE;
+    }
+    return TRUE;
+}
+
+/* Outer IUnknown for COM aggregation tests */
+struct unk_impl {
+    IUnknown IUnknown_iface;
+    LONG ref;
+    IUnknown *inner_unk;
+};
+
+static inline struct unk_impl *impl_from_IUnknown(IUnknown *iface)
+{
+    return CONTAINING_RECORD(iface, struct unk_impl, IUnknown_iface);
+}
+
+static HRESULT WINAPI unk_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
+{
+    struct unk_impl *This = impl_from_IUnknown(iface);
+
+    return IUnknown_QueryInterface(This->inner_unk, riid, ppv);
+}
+
+static ULONG WINAPI unk_AddRef(IUnknown *iface)
+{
+    struct unk_impl *This = impl_from_IUnknown(iface);
+
+    return InterlockedIncrement(&This->ref);
+}
+
+static ULONG WINAPI unk_Release(IUnknown *iface)
+{
+    struct unk_impl *This = impl_from_IUnknown(iface);
+
+    return InterlockedDecrement(&This->ref);
+}
+
+static const IUnknownVtbl unk_vtbl =
+{
+    unk_QueryInterface,
+    unk_AddRef,
+    unk_Release
+};
+
+static void test_COM(void)
+{
+    IDirectMusicScript *dms = NULL;
+    IDirectMusicObject *dmo;
+    IPersistStream *ps;
+    IUnknown *unk;
+    struct unk_impl unk_obj = {{&unk_vtbl}, 19, NULL};
+    ULONG refcount;
+    HRESULT hr;
+
+    /* COM aggregation */
+    hr = CoCreateInstance(&CLSID_DirectMusicScript, (IUnknown*)&dms, CLSCTX_INPROC_SERVER,
+            &IID_IUnknown, (void**)&dms);
+    todo_wine ok(hr == E_POINTER, "DirectMusicScript create failed: %08x, expected E_POINTER\n", hr);
+    /* An invalid non-NULL pUnkOuter crashes newer Windows versions */
+    hr = CoCreateInstance(&CLSID_DirectMusicScript, &unk_obj.IUnknown_iface, CLSCTX_INPROC_SERVER,
+            &IID_IUnknown, (void**)&unk_obj.inner_unk);
+    ok(hr == CLASS_E_NOAGGREGATION,
+            "DirectMusicScript create failed: %08x, expected CLASS_E_NOAGGREGATION\n", hr);
+    ok(!unk_obj.inner_unk, "unk_obj.inner_unk = %p\n", unk_obj.inner_unk);
+
+    /* Invalid RIID */
+    hr = CoCreateInstance(&CLSID_DirectMusicScript, NULL, CLSCTX_INPROC_SERVER, &IID_IClassFactory,
+            (void**)&dms);
+    ok(hr == E_NOINTERFACE, "DirectMusicScript create failed: %08x, expected E_NOINTERFACE\n", hr);
+
+    /* Same refcount for all DirectMusicScript interfaces */
+    hr = CoCreateInstance(&CLSID_DirectMusicScript, NULL, CLSCTX_INPROC_SERVER,
+            &IID_IDirectMusicScript, (void**)&dms);
+    ok(hr == S_OK, "DirectMusicScript create failed: %08x, expected S_OK\n", hr);
+    refcount = IDirectMusicScript_AddRef(dms);
+    ok(refcount == 2, "refcount == %u, expected 2\n", refcount);
+
+    hr = IDirectMusicScript_QueryInterface(dms, &IID_IDirectMusicObject, (void**)&dmo);
+    ok(hr == S_OK, "QueryInterface for IID_IDirectMusicObject failed: %08x\n", hr);
+    refcount = IDirectMusicObject_AddRef(dmo);
+    ok(refcount == 4, "refcount == %u, expected 4\n", refcount);
+    refcount = IDirectMusicObject_Release(dmo);
+
+    hr = IDirectMusicScript_QueryInterface(dms, &IID_IPersistStream, (void**)&ps);
+    ok(hr == S_OK, "QueryInterface for IID_IPersistStream failed: %08x\n", hr);
+    refcount = IPersistStream_AddRef(ps);
+    ok(refcount == 5, "refcount == %u, expected 5\n", refcount);
+    refcount = IPersistStream_Release(ps);
+
+    hr = IDirectMusicScript_QueryInterface(dms, &IID_IUnknown, (void**)&unk);
+    ok(hr == S_OK, "QueryInterface for IID_IUnknown failed: %08x\n", hr);
+    refcount = IUnknown_AddRef(unk);
+    ok(refcount == 6, "refcount == %u, expected 6\n", refcount);
+    refcount = IUnknown_Release(unk);
+
+    while (IDirectMusicScript_Release(dms));
+}
+
+START_TEST(dmscript)
+{
+    CoInitialize(NULL);
+
+    if (missing_dmscript())
+    {
+        skip("dmscript not available\n");
+        CoUninitialize();
+        return;
+    }
+    test_COM();
+
+    CoUninitialize();
+}
-- 
1.8.3.1



More information about the wine-patches mailing list