Andrew Eikum : mmdevapi: IMMDeviceEnumerator:: GetDevice should fail on unknown device ids.
Alexandre Julliard
julliard at winehq.org
Mon May 16 11:36:45 CDT 2011
Module: wine
Branch: master
Commit: 91b684325f85c5d3f1c7bc10459066a71caa3629
URL: http://source.winehq.org/git/wine.git/?a=commit;h=91b684325f85c5d3f1c7bc10459066a71caa3629
Author: Andrew Eikum <aeikum at codeweavers.com>
Date: Fri May 13 11:33:59 2011 -0500
mmdevapi: IMMDeviceEnumerator::GetDevice should fail on unknown device ids.
---
dlls/mmdevapi/devenum.c | 17 ++++++++---------
dlls/mmdevapi/tests/mmdevenum.c | 20 ++++++++++++++++++++
2 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/dlls/mmdevapi/devenum.c b/dlls/mmdevapi/devenum.c
index 1e8ffe0..d2a4620 100644
--- a/dlls/mmdevapi/devenum.c
+++ b/dlls/mmdevapi/devenum.c
@@ -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)
diff --git a/dlls/mmdevapi/tests/mmdevenum.c b/dlls/mmdevapi/tests/mmdevenum.c
index a0898b3..ff70177 100644
--- a/dlls/mmdevapi/tests/mmdevenum.c
+++ b/dlls/mmdevapi/tests/mmdevenum.c
@@ -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);
More information about the wine-cvs
mailing list