From 47ce8c9755ae67c23dcc485b226540227d719794 Mon Sep 17 00:00:00 2001 From: Andrew Eikum Date: Fri, 30 Mar 2012 08:38:20 -0500 Subject: [PATCH] dmusic: Support creating default ports with GUID_NULL. --- dlls/dmime/tests/performance.c | 173 ++++++++++++++++++++++++++++++++++------- dlls/dmusic/dmusic.c | 30 ++++--- dlls/dmusic/tests/dmusic.c | 2 +- 3 files changed, 166 insertions(+), 39 deletions(-) diff --git a/dlls/dmime/tests/performance.c b/dlls/dmime/tests/performance.c index a5a6c6ef9c0..ddeed5d0ff5 100644 --- a/dlls/dmime/tests/performance.c +++ b/dlls/dmime/tests/performance.c @@ -24,23 +24,44 @@ #include #include -static IDirectMusicPerformance8 *idmusicperformance; +#include + +DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0); +DEFINE_GUID(GUID_Bunk,0xFFFFFFFF,0xFFFF,0xFFFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF); + +static const char *debugstr_guid(REFIID riid) +{ + static char buf[50]; + + sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}", + riid->Data1, riid->Data2, riid->Data3, riid->Data4[0], + riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4], + riid->Data4[5], riid->Data4[6], riid->Data4[7]); + + return buf; +} static HRESULT test_InitAudio(void) { + IDirectMusicPerformance8 *idmusicperformance; IDirectSound *pDirectSound; + IDirectMusicPort *pDirectMusicPort; + IDirectMusicAudioPath *pDirectMusicAudioPath; HRESULT hr; + hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL, + CLSCTX_INPROC_SERVER, &IID_IDirectMusicPerformance8, (LPVOID *)&idmusicperformance); + if (hr != S_OK) { + skip("Cannot create DirectMusicPerformance object (%x)\n", hr); + CoUninitialize(); + return hr; + } + pDirectSound = NULL; hr = IDirectMusicPerformance8_InitAudio(idmusicperformance ,NULL, &pDirectSound, NULL, DMUS_APATH_SHARED_STEREOPLUSREVERB, 128, DMUS_AUDIOF_ALL, NULL); - return hr; -} - -static void test_PChannelInfo(void) -{ - IDirectMusicPort *pDirectMusicPort; - HRESULT hr; + if(hr != S_OK) + return hr; pDirectMusicPort = NULL; hr = IDirectMusicPerformance8_PChannelInfo(idmusicperformance, 0, &pDirectMusicPort, NULL, NULL); @@ -48,25 +69,130 @@ static void test_PChannelInfo(void) ok(pDirectMusicPort != NULL, "IDirectMusicPort not set\n"); if (hr == S_OK && pDirectMusicPort != NULL) IDirectMusicPort_Release(pDirectMusicPort); -} - -static void test_GetDefaultAudioPath(void) -{ - IDirectMusicAudioPath *pDirectMusicAudioPath; - HRESULT hr; hr = IDirectMusicPerformance8_GetDefaultAudioPath(idmusicperformance, &pDirectMusicAudioPath); ok(hr == S_OK, "Failed to call GetDefaultAudioPath (%x)\n", hr); if (hr == S_OK) IDirectMusicAudioPath_Release(pDirectMusicAudioPath); + + hr = IDirectMusicPerformance8_CloseDown(idmusicperformance); + ok(hr == S_OK, "Failed to call CloseDown (%x)\n", hr); + + IDirectMusicPerformance8_Release(idmusicperformance); + + return S_OK; } -static void test_CloseDown(void) +static void test_createport(void) { + IDirectMusicPerformance8 *perf; + IDirectMusic *music = NULL; + IDirectMusicPort *port = NULL; + DMUS_PORTCAPS portcaps; + DMUS_PORTPARAMS portparams; + DWORD i; HRESULT hr; - hr = IDirectMusicPerformance8_CloseDown(idmusicperformance); - ok(hr == S_OK, "Failed to call CloseDown (%x)\n", hr); + hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL, + CLSCTX_INPROC_SERVER, &IID_IDirectMusicPerformance8, (void**)&perf); + ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr); + + hr = IDirectMusicPerformance8_Init(perf, &music, NULL, NULL); + ok(hr == S_OK, "Init failed: %08x\n", hr); + ok(music != NULL, "Didn't get IDirectMusic pointer\n"); + + i = 0; + while(1){ + portcaps.dwSize = sizeof(portcaps); + + hr = IDirectMusic_EnumPort(music, i, &portcaps); + ok(hr == S_OK || hr == S_FALSE || (i == 0 && hr == E_INVALIDARG), "EnumPort failed: %08x\n", hr); + if(hr != S_OK) + break; + + ok(portcaps.dwSize == sizeof(portcaps), "Got unexpected portcaps struct size: %08x\n", portcaps.dwSize); + trace("portcaps(%u).dwFlags: %08x\n", i, portcaps.dwFlags); + trace("portcaps(%u).guidPort: %s\n", i, debugstr_guid(&portcaps.guidPort)); + trace("portcaps(%u).dwClass: %08x\n", i, portcaps.dwClass); + trace("portcaps(%u).dwType: %08x\n", i, portcaps.dwType); + trace("portcaps(%u).dwMemorySize: %08x\n", i, portcaps.dwMemorySize); + trace("portcaps(%u).dwMaxChannelGroups: %08x\n", i, portcaps.dwMaxChannelGroups); + trace("portcaps(%u).dwMaxVoices: %08x\n", i, portcaps.dwMaxVoices); + trace("portcaps(%u).dwMaxAudioChannels: %08x\n", i, portcaps.dwMaxAudioChannels); + trace("portcaps(%u).dwEffectFlags: %08x\n", i, portcaps.dwEffectFlags); + trace("portcaps(%u).wszDescription: %s\n", i, wine_dbgstr_w(portcaps.wszDescription)); + + ++i; + } + + if(i == 0){ + win_skip("No ports available, skipping tests\n"); + return; + } + + portparams.dwSize = sizeof(portparams); + + /* dwValidParams == 0 -> S_OK, filled struct */ + portparams.dwValidParams = 0; + hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth, + &portparams, &port, NULL); + ok(hr == S_OK, "CreatePort failed: %08x\n", hr); + ok(port != NULL, "Didn't get IDirectMusicPort pointer\n"); + + IDirectMusicPort_Release(port); + port = NULL; + + todo_wine ok(portparams.dwValidParams != 0, "portparams struct was not filled in\n"); + + /* dwValidParams != 0, invalid param -> S_FALSE, filled struct */ + portparams.dwValidParams = DMUS_PORTPARAMS_CHANNELGROUPS; + portparams.dwChannelGroups = 0; + hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth, + &portparams, &port, NULL); + todo_wine ok(hr == S_FALSE, "CreatePort failed: %08x\n", hr); + ok(port != NULL, "Didn't get IDirectMusicPort pointer\n"); + + IDirectMusicPort_Release(port); + port = NULL; + + ok(portparams.dwValidParams != 0, "portparams struct was not filled in\n"); + + /* dwValidParams != 0, valid params -> S_OK */ + hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth, + &portparams, &port, NULL); + ok(hr == S_OK, "CreatePort failed: %08x\n", hr); + ok(port != NULL, "Didn't get IDirectMusicPort pointer\n"); + + IDirectMusicPort_Release(port); + port = NULL; + + /* GUID_NULL succeeds */ + portparams.dwValidParams = 0; + hr = IDirectMusic_CreatePort(music, &GUID_NULL, &portparams, &port, NULL); + ok(hr == S_OK, "CreatePort failed: %08x\n", hr); + ok(port != NULL, "Didn't get IDirectMusicPort pointer\n"); + + IDirectMusicPort_Release(port); + port = NULL; + + todo_wine ok(portparams.dwValidParams != 0, "portparams struct was not filled in\n"); + + /* null GUID fails */ + portparams.dwValidParams = 0; + hr = IDirectMusic_CreatePort(music, NULL, &portparams, &port, NULL); + ok(hr == E_POINTER, "CreatePort failed: %08x\n", hr); + ok(port == NULL, "Get IDirectMusicPort pointer? %p\n", port); + ok(portparams.dwValidParams == 0, "portparams struct was filled in?\n"); + + /* garbage GUID fails */ + portparams.dwValidParams = 0; + hr = IDirectMusic_CreatePort(music, &GUID_Bunk, &portparams, &port, NULL); + ok(hr == E_NOINTERFACE, "CreatePort failed: %08x\n", hr); + ok(port == NULL, "Get IDirectMusicPort pointer? %p\n", port); + ok(portparams.dwValidParams == 0, "portparams struct was filled in?\n"); + + IDirectMusic_Release(music); + IDirectMusicPerformance_Release(perf); } START_TEST( performance ) @@ -79,24 +205,13 @@ START_TEST( performance ) return; } - hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL, - CLSCTX_INPROC_SERVER, &IID_IDirectMusicPerformance8, (LPVOID *)&idmusicperformance); - if (hr != S_OK) { - skip("Cannot create DirectMusicPerformance object (%x)\n", hr); - CoUninitialize(); - return; - } - hr = test_InitAudio(); if (hr != S_OK) { skip("InitAudio failed (%x)\n", hr); return; } - test_GetDefaultAudioPath(); - test_PChannelInfo(); - test_CloseDown(); + test_createport(); - IDirectMusicPerformance8_Release(idmusicperformance); CoUninitialize(); } diff --git a/dlls/dmusic/dmusic.c b/dlls/dmusic/dmusic.c index e4678e13957..80c5d4b70d7 100644 --- a/dlls/dmusic/dmusic.c +++ b/dlls/dmusic/dmusic.c @@ -123,31 +123,43 @@ static HRESULT WINAPI IDirectMusic8Impl_CreateMusicBuffer (LPDIRECTMUSIC8 iface, static HRESULT WINAPI IDirectMusic8Impl_CreatePort (LPDIRECTMUSIC8 iface, REFCLSID rclsidPort, LPDMUS_PORTPARAMS pPortParams, LPDIRECTMUSICPORT* ppPort, LPUNKNOWN pUnkOuter) { IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface; - int i/*, j*/; + int i; DMUS_PORTCAPS PortCaps; IDirectMusicPort* pNewPort = NULL; - HRESULT hr = E_FAIL; + HRESULT hr; + GUID default_port; + const GUID *request_port = rclsidPort; + + TRACE("(%p, %s, %p, %p, %p)\n", This, debugstr_dmguid(rclsidPort), pPortParams, ppPort, pUnkOuter); + + if(!rclsidPort) + return E_POINTER; - TRACE("(%p, %s, %p, %p, %p)\n", This, debugstr_dmguid(rclsidPort), pPortParams, ppPort, pUnkOuter); ZeroMemory(&PortCaps, sizeof(DMUS_PORTCAPS)); PortCaps.dwSize = sizeof(DMUS_PORTCAPS); - for (i = 0; S_FALSE != IDirectMusic8Impl_EnumPort(iface, i, &PortCaps); i++) { - if (IsEqualCLSID (rclsidPort, &PortCaps.guidPort)) { + if(IsEqualGUID(request_port, &GUID_NULL)){ + hr = IDirectMusic8_GetDefaultPort(iface, &default_port); + if(FAILED(hr)) + return hr; + request_port = &default_port; + } + + for (i = 0; S_FALSE != IDirectMusic8Impl_EnumPort(iface, i, &PortCaps); i++) { + if (IsEqualCLSID (request_port, &PortCaps.guidPort)) { hr = DMUSIC_CreateDirectMusicPortImpl(&IID_IDirectMusicPort, (LPVOID*) &pNewPort, (LPUNKNOWN) This, pPortParams, &PortCaps); if (FAILED(hr)) { - *ppPort = NULL; + *ppPort = NULL; return hr; } This->nrofports++; if (!This->ppPorts) This->ppPorts = HeapAlloc(GetProcessHeap(), 0, sizeof(LPDIRECTMUSICPORT) * This->nrofports); - else This->ppPorts = HeapReAlloc(GetProcessHeap(), 0, This->ppPorts, sizeof(LPDIRECTMUSICPORT) * This->nrofports); + else This->ppPorts = HeapReAlloc(GetProcessHeap(), 0, This->ppPorts, sizeof(LPDIRECTMUSICPORT) * This->nrofports); This->ppPorts[This->nrofports - 1] = pNewPort; *ppPort = pNewPort; - return S_OK; + return S_OK; } } - /* FIXME: place correct error here */ return E_NOINTERFACE; } diff --git a/dlls/dmusic/tests/dmusic.c b/dlls/dmusic/tests/dmusic.c index 043dd4d35bc..6853ad9c3b5 100644 --- a/dlls/dmusic/tests/dmusic.c +++ b/dlls/dmusic/tests/dmusic.c @@ -68,7 +68,7 @@ static void test_dmusic(void) /* Test creation of default port with GUID_NULL */ hr = IDirectMusic_CreatePort(dmusic, &GUID_NULL, &port_params, &port, NULL); - todo_wine ok(hr == S_OK, "IDirectMusic_CreatePort returned: %x\n", hr); + ok(hr == S_OK, "IDirectMusic_CreatePort returned: %x\n", hr); port_caps.dwSize = sizeof(port_caps); while (IDirectMusic_EnumPort(dmusic, index, &port_caps) == S_OK) -- 2.11.4.GIT