po: Update simplified Chinese translation.
[wine/multimedia.git] / dlls / mmdevapi / tests / mmdevenum.c
blob82658d1f35bc1eb648a4614bad52e8974102c822
1 /*
2 * Copyright 2009 Maarten Lankhorst
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "wine/test.h"
21 #define COBJMACROS
23 #include "initguid.h"
24 #include "mmdeviceapi.h"
25 #include "audioclient.h"
26 #include "audiopolicy.h"
27 #include "dshow.h"
28 #include "dsound.h"
29 #include "devpkey.h"
31 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
33 /* Some of the QueryInterface tests are really just to check if I got the IIDs right :) */
35 /* IMMDeviceCollection appears to have no QueryInterface method and instead forwards to mme */
36 static void test_collection(IMMDeviceEnumerator *mme, IMMDeviceCollection *col)
38 IMMDeviceCollection *col2;
39 IMMDeviceEnumerator *mme2;
40 IUnknown *unk;
41 HRESULT hr;
42 ULONG ref;
43 UINT numdev;
44 IMMDevice *dev;
46 /* collection doesn't keep a ref on parent */
47 IUnknown_AddRef(mme);
48 ref = IUnknown_Release(mme);
49 ok(ref == 2, "Reference count on parent is %u\n", ref);
51 ref = IUnknown_AddRef(col);
52 IUnknown_Release(col);
53 ok(ref == 2, "Invalid reference count %u on collection\n", ref);
55 hr = IUnknown_QueryInterface(col, &IID_IUnknown, NULL);
56 ok(hr == E_POINTER, "Null ppv returns %08x\n", hr);
58 hr = IUnknown_QueryInterface(col, &IID_IUnknown, (void**)&unk);
59 ok(hr == S_OK, "Cannot query for IID_IUnknown: 0x%08x\n", hr);
60 if (hr == S_OK)
62 ok((LONG_PTR)col == (LONG_PTR)unk, "Pointers are not identical %p/%p/%p\n", col, unk, mme);
63 IUnknown_Release(unk);
66 hr = IUnknown_QueryInterface(col, &IID_IMMDeviceCollection, (void**)&col2);
67 ok(hr == S_OK, "Cannot query for IID_IMMDeviceCollection: 0x%08x\n", hr);
68 if (hr == S_OK)
69 IUnknown_Release(col2);
71 hr = IUnknown_QueryInterface(col, &IID_IMMDeviceEnumerator, (void**)&mme2);
72 ok(hr == E_NOINTERFACE, "Query for IID_IMMDeviceEnumerator returned: 0x%08x\n", hr);
73 if (hr == S_OK)
74 IUnknown_Release(mme2);
76 hr = IMMDeviceCollection_GetCount(col, NULL);
77 ok(hr == E_POINTER, "GetCount returned 0x%08x\n", hr);
79 hr = IMMDeviceCollection_GetCount(col, &numdev);
80 ok(hr == S_OK, "GetCount returned 0x%08x\n", hr);
82 dev = (void*)(LONG_PTR)0x12345678;
83 hr = IMMDeviceCollection_Item(col, numdev, &dev);
84 ok(hr == E_INVALIDARG, "Asking for too high device returned 0x%08x\n", hr);
85 ok(dev == NULL, "Returned non-null device\n");
87 if (numdev)
89 hr = IMMDeviceCollection_Item(col, 0, NULL);
90 ok(hr == E_POINTER, "Query with null pointer returned 0x%08x\n", hr);
92 hr = IMMDeviceCollection_Item(col, 0, &dev);
93 ok(hr == S_OK, "Valid Item returned 0x%08x\n", hr);
94 ok(dev != NULL, "Device is null!\n");
95 if (dev != NULL)
97 char temp[128];
98 WCHAR *id = NULL;
99 if (IMMDevice_GetId(dev, &id) == S_OK)
101 IMMDevice *dev2;
103 temp[sizeof(temp)-1] = 0;
104 WideCharToMultiByte(CP_ACP, 0, id, -1, temp, sizeof(temp)-1, NULL, NULL);
105 trace("Device found: %s\n", temp);
107 hr = IMMDeviceEnumerator_GetDevice(mme, id, &dev2);
108 ok(hr == S_OK, "GetDevice failed: %08x\n", hr);
110 IMMDevice_Release(dev2);
112 CoTaskMemFree(id);
115 if (dev)
116 IUnknown_Release(dev);
118 IUnknown_Release(col);
121 /* Only do parameter tests here, the actual MMDevice testing should be a separate test */
122 START_TEST(mmdevenum)
124 static const WCHAR not_a_deviceW[] = {'n','o','t','a','d','e','v','i','c','e',0};
126 HRESULT hr;
127 IUnknown *unk = NULL;
128 IMMDeviceEnumerator *mme, *mme2;
129 ULONG ref;
130 IMMDeviceCollection *col;
131 IMMDevice *dev;
133 CoInitializeEx(NULL, COINIT_MULTITHREADED);
134 hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&mme);
135 if (FAILED(hr))
137 skip("mmdevapi not available: 0x%08x\n", hr);
138 return;
141 /* Odd behavior.. bug? */
142 ref = IUnknown_AddRef(mme);
143 ok(ref == 3, "Invalid reference count after incrementing: %u\n", ref);
144 IUnknown_Release(mme);
146 hr = IUnknown_QueryInterface(mme, &IID_IUnknown, (void**)&unk);
147 ok(hr == S_OK, "returned 0x%08x\n", hr);
148 if (hr != S_OK) return;
150 ok( (LONG_PTR)mme == (LONG_PTR)unk, "Pointers are unequal %p/%p\n", unk, mme);
151 IUnknown_Release(unk);
153 /* Proving that it is static.. */
154 hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&mme2);
155 ok(hr == S_OK, "CoCreateInstance failed: 0x%08x\n", hr);
156 IUnknown_Release(mme2);
157 ok(mme == mme2, "Pointers are not equal!\n");
159 hr = IUnknown_QueryInterface(mme, &IID_IUnknown, NULL);
160 ok(hr == E_POINTER, "Null pointer on QueryInterface returned %08x\n", hr);
162 hr = IUnknown_QueryInterface(mme, &GUID_NULL, (void**)&unk);
163 ok(!unk, "Unk not reset to null after invalid QI\n");
164 ok(hr == E_NOINTERFACE, "Invalid hr %08x returned on IID_NULL\n", hr);
166 hr = IMMDeviceEnumerator_GetDevice(mme, not_a_deviceW, NULL);
167 ok(hr == E_POINTER, "GetDevice gave wrong error: %08x\n", hr);
169 hr = IMMDeviceEnumerator_GetDevice(mme, NULL, &dev);
170 ok(hr == E_POINTER, "GetDevice gave wrong error: %08x\n", hr);
172 hr = IMMDeviceEnumerator_GetDevice(mme, not_a_deviceW, &dev);
173 ok(hr == E_INVALIDARG, "GetDevice gave wrong error: %08x\n", hr);
175 col = (void*)(LONG_PTR)0x12345678;
176 hr = IMMDeviceEnumerator_EnumAudioEndpoints(mme, 0xffff, DEVICE_STATEMASK_ALL, &col);
177 ok(hr == E_INVALIDARG, "Setting invalid data flow returned 0x%08x\n", hr);
178 ok(col == NULL, "Collection pointer non-null on failure\n");
180 hr = IMMDeviceEnumerator_EnumAudioEndpoints(mme, eAll, DEVICE_STATEMASK_ALL+1, &col);
181 ok(hr == E_INVALIDARG, "Setting invalid mask returned 0x%08x\n", hr);
183 hr = IMMDeviceEnumerator_EnumAudioEndpoints(mme, eAll, DEVICE_STATEMASK_ALL, NULL);
184 ok(hr == E_POINTER, "Invalid pointer returned: 0x%08x\n", hr);
186 hr = IMMDeviceEnumerator_EnumAudioEndpoints(mme, eAll, DEVICE_STATEMASK_ALL, &col);
187 ok(hr == S_OK, "Valid EnumAudioEndpoints returned 0x%08x\n", hr);
188 if (hr == S_OK)
190 ok(!!col, "Returned null pointer\n");
191 if (col)
192 test_collection(mme, col);
195 IUnknown_Release(mme);