mmdevapi: IMMDeviceEnumerator::GetDevice should fail on unknown device ids.

oldstable
Andrew Eikum 2011-05-13 11:33:59 -05:00 committed by Alexandre Julliard
parent b9bfc10199
commit 91b684325f
2 changed files with 28 additions and 9 deletions

View File

@ -932,6 +932,9 @@ static HRESULT WINAPI MMDevEnum_GetDevice(IMMDeviceEnumerator *iface, const WCHA
DWORD i=0;
IMMDevice *dev = NULL;
if(!name || !device)
return E_POINTER;
TRACE("(%p)->(%s,%p)\n", This, debugstr_w(name), device);
for (i = 0; i < MMDevice_count; ++i)
{
@ -942,18 +945,14 @@ static HRESULT WINAPI MMDevEnum_GetDevice(IMMDeviceEnumerator *iface, const WCHA
if (str && !lstrcmpW(str, name))
{
CoTaskMemFree(str);
break;
IUnknown_AddRef(dev);
*device = dev;
return S_OK;
}
CoTaskMemFree(str);
}
if (dev)
{
IUnknown_AddRef(dev);
*device = dev;
return S_OK;
}
WARN("Could not find device %s\n", debugstr_w(name));
return E_NOTFOUND;
TRACE("Could not find device %s\n", debugstr_w(name));
return E_INVALIDARG;
}
static HRESULT WINAPI MMDevEnum_RegisterEndpointNotificationCallback(IMMDeviceEnumerator *iface, IMMNotificationClient *client)

View File

@ -98,9 +98,17 @@ static void test_collection(IMMDeviceEnumerator *mme, IMMDeviceCollection *col)
WCHAR *id = NULL;
if (IMMDevice_GetId(dev, &id) == S_OK)
{
IMMDevice *dev2;
temp[sizeof(temp)-1] = 0;
WideCharToMultiByte(CP_ACP, 0, id, -1, temp, sizeof(temp)-1, NULL, NULL);
trace("Device found: %s\n", temp);
hr = IMMDeviceEnumerator_GetDevice(mme, id, &dev2);
ok(hr == S_OK, "GetDevice failed: %08x\n", hr);
IMMDevice_Release(dev2);
CoTaskMemFree(id);
}
}
@ -113,11 +121,14 @@ static void test_collection(IMMDeviceEnumerator *mme, IMMDeviceCollection *col)
/* Only do parameter tests here, the actual MMDevice testing should be a separate test */
START_TEST(mmdevenum)
{
static const WCHAR not_a_deviceW[] = {'n','o','t','a','d','e','v','i','c','e',0};
HRESULT hr;
IUnknown *unk = NULL;
IMMDeviceEnumerator *mme, *mme2;
ULONG ref;
IMMDeviceCollection *col;
IMMDevice *dev;
CoInitializeEx(NULL, COINIT_MULTITHREADED);
hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&mme);
@ -152,6 +163,15 @@ START_TEST(mmdevenum)
ok(!unk, "Unk not reset to null after invalid QI\n");
ok(hr == E_NOINTERFACE, "Invalid hr %08x returned on IID_NULL\n", hr);
hr = IMMDeviceEnumerator_GetDevice(mme, not_a_deviceW, NULL);
ok(hr == E_POINTER, "GetDevice gave wrong error: %08x\n", hr);
hr = IMMDeviceEnumerator_GetDevice(mme, NULL, &dev);
ok(hr == E_POINTER, "GetDevice gave wrong error: %08x\n", hr);
hr = IMMDeviceEnumerator_GetDevice(mme, not_a_deviceW, &dev);
ok(hr == E_INVALIDARG, "GetDevice gave wrong error: %08x\n", hr);
col = (void*)(LONG_PTR)0x12345678;
hr = IMMDeviceEnumerator_EnumAudioEndpoints(mme, 0xffff, DEVICE_STATEMASK_ALL, &col);
ok(hr == E_INVALIDARG, "Setting invalid data flow returned 0x%08x\n", hr);