dmusic: Support creating default ports with GUID_NULL.

This commit is contained in:
Andrew Eikum 2012-03-30 08:38:20 -05:00 committed by Alexandre Julliard
parent b74c9a6472
commit 47ce8c9755
3 changed files with 168 additions and 41 deletions

View File

@ -24,23 +24,44 @@
#include <wine/test.h> #include <wine/test.h>
#include <dmusici.h> #include <dmusici.h>
static IDirectMusicPerformance8 *idmusicperformance; #include <stdio.h>
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) static HRESULT test_InitAudio(void)
{ {
IDirectMusicPerformance8 *idmusicperformance;
IDirectSound *pDirectSound; IDirectSound *pDirectSound;
IDirectMusicPort *pDirectMusicPort;
IDirectMusicAudioPath *pDirectMusicAudioPath;
HRESULT hr; 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; pDirectSound = NULL;
hr = IDirectMusicPerformance8_InitAudio(idmusicperformance ,NULL, hr = IDirectMusicPerformance8_InitAudio(idmusicperformance ,NULL,
&pDirectSound, NULL, DMUS_APATH_SHARED_STEREOPLUSREVERB, 128, DMUS_AUDIOF_ALL, NULL); &pDirectSound, NULL, DMUS_APATH_SHARED_STEREOPLUSREVERB, 128, DMUS_AUDIOF_ALL, NULL);
return hr; if(hr != S_OK)
} return hr;
static void test_PChannelInfo(void)
{
IDirectMusicPort *pDirectMusicPort;
HRESULT hr;
pDirectMusicPort = NULL; pDirectMusicPort = NULL;
hr = IDirectMusicPerformance8_PChannelInfo(idmusicperformance, 0, &pDirectMusicPort, NULL, 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"); ok(pDirectMusicPort != NULL, "IDirectMusicPort not set\n");
if (hr == S_OK && pDirectMusicPort != NULL) if (hr == S_OK && pDirectMusicPort != NULL)
IDirectMusicPort_Release(pDirectMusicPort); IDirectMusicPort_Release(pDirectMusicPort);
}
static void test_GetDefaultAudioPath(void)
{
IDirectMusicAudioPath *pDirectMusicAudioPath;
HRESULT hr;
hr = IDirectMusicPerformance8_GetDefaultAudioPath(idmusicperformance, &pDirectMusicAudioPath); hr = IDirectMusicPerformance8_GetDefaultAudioPath(idmusicperformance, &pDirectMusicAudioPath);
ok(hr == S_OK, "Failed to call GetDefaultAudioPath (%x)\n", hr); ok(hr == S_OK, "Failed to call GetDefaultAudioPath (%x)\n", hr);
if (hr == S_OK) if (hr == S_OK)
IDirectMusicAudioPath_Release(pDirectMusicAudioPath); IDirectMusicAudioPath_Release(pDirectMusicAudioPath);
}
static void test_CloseDown(void)
{
HRESULT hr;
hr = IDirectMusicPerformance8_CloseDown(idmusicperformance); hr = IDirectMusicPerformance8_CloseDown(idmusicperformance);
ok(hr == S_OK, "Failed to call CloseDown (%x)\n", hr); ok(hr == S_OK, "Failed to call CloseDown (%x)\n", hr);
IDirectMusicPerformance8_Release(idmusicperformance);
return S_OK;
}
static void test_createport(void)
{
IDirectMusicPerformance8 *perf;
IDirectMusic *music = NULL;
IDirectMusicPort *port = NULL;
DMUS_PORTCAPS portcaps;
DMUS_PORTPARAMS portparams;
DWORD i;
HRESULT 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 ) START_TEST( performance )
@ -79,24 +205,13 @@ START_TEST( performance )
return; 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(); hr = test_InitAudio();
if (hr != S_OK) { if (hr != S_OK) {
skip("InitAudio failed (%x)\n", hr); skip("InitAudio failed (%x)\n", hr);
return; return;
} }
test_GetDefaultAudioPath(); test_createport();
test_PChannelInfo();
test_CloseDown();
IDirectMusicPerformance8_Release(idmusicperformance);
CoUninitialize(); CoUninitialize();
} }

View File

@ -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) { static HRESULT WINAPI IDirectMusic8Impl_CreatePort (LPDIRECTMUSIC8 iface, REFCLSID rclsidPort, LPDMUS_PORTPARAMS pPortParams, LPDIRECTMUSICPORT* ppPort, LPUNKNOWN pUnkOuter) {
IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface; IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
int i/*, j*/; int i;
DMUS_PORTCAPS PortCaps; DMUS_PORTCAPS PortCaps;
IDirectMusicPort* pNewPort = NULL; 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)); ZeroMemory(&PortCaps, sizeof(DMUS_PORTCAPS));
PortCaps.dwSize = sizeof(DMUS_PORTCAPS); PortCaps.dwSize = sizeof(DMUS_PORTCAPS);
for (i = 0; S_FALSE != IDirectMusic8Impl_EnumPort(iface, i, &PortCaps); i++) { if(IsEqualGUID(request_port, &GUID_NULL)){
if (IsEqualCLSID (rclsidPort, &PortCaps.guidPort)) { 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); hr = DMUSIC_CreateDirectMusicPortImpl(&IID_IDirectMusicPort, (LPVOID*) &pNewPort, (LPUNKNOWN) This, pPortParams, &PortCaps);
if (FAILED(hr)) { if (FAILED(hr)) {
*ppPort = NULL; *ppPort = NULL;
return hr; return hr;
} }
This->nrofports++; This->nrofports++;
if (!This->ppPorts) This->ppPorts = HeapAlloc(GetProcessHeap(), 0, sizeof(LPDIRECTMUSICPORT) * 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; This->ppPorts[This->nrofports - 1] = pNewPort;
*ppPort = pNewPort; *ppPort = pNewPort;
return S_OK; return S_OK;
} }
} }
/* FIXME: place correct error here */
return E_NOINTERFACE; return E_NOINTERFACE;
} }

View File

@ -68,7 +68,7 @@ static void test_dmusic(void)
/* Test creation of default port with GUID_NULL */ /* Test creation of default port with GUID_NULL */
hr = IDirectMusic_CreatePort(dmusic, &GUID_NULL, &port_params, &port, 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); port_caps.dwSize = sizeof(port_caps);
while (IDirectMusic_EnumPort(dmusic, index, &port_caps) == S_OK) while (IDirectMusic_EnumPort(dmusic, index, &port_caps) == S_OK)