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"
25 #include "mmdeviceapi.h"
29 /* Some of the QueryInterface tests are really just to check if I got the IID's right :) */
31 /* IMMDeviceCollection appears to have no QueryInterface method and instead forwards to mme */
32 static void test_collection(IMMDeviceEnumerator *mme, IMMDeviceCollection *col)
34 IMMDeviceCollection *col2;
35 IMMDeviceEnumerator *mme2;
42 ref = IUnknown_AddRef(col);
43 IUnknown_Release(col);
44 ok(ref == 2, "Invalid reference count %u on collection\n", ref);
46 hr = IUnknown_QueryInterface(col, &IID_IUnknown, (void**)&unk);
47 ok(hr == S_OK, "Cannot query for IID_IUnknown: 0x%08x\n", hr);
50 ok((LONG_PTR)col == (LONG_PTR)unk, "Pointers are not identical %p/%p/%p\n", col, unk, mme);
51 IUnknown_Release(unk);
54 hr = IUnknown_QueryInterface(col, &IID_IMMDeviceCollection, (void**)&col2);
55 ok(hr == S_OK, "Cannot query for IID_IMMDeviceCollection: 0x%08x\n", hr);
57 IUnknown_Release(col2);
59 hr = IUnknown_QueryInterface(col, &IID_IMMDeviceEnumerator, (void**)&mme2);
60 ok(hr == E_NOINTERFACE, "Query for IID_IMMDeviceEnumerator returned: 0x%08x\n", hr);
62 IUnknown_Release(mme2);
64 hr = IMMDeviceCollection_GetCount(col, NULL);
65 ok(hr == E_POINTER, "GetCount returned 0x%08x\n", hr);
67 hr = IMMDeviceCollection_GetCount(col, &numdev);
68 ok(hr == S_OK, "GetCount returned 0x%08x\n", hr);
70 dev = (void*)(LONG_PTR)0x12345678;
71 hr = IMMDeviceCollection_Item(col, numdev, &dev);
72 ok(hr == E_INVALIDARG, "Asking for too high device returned 0x%08x\n", hr);
73 ok(dev == NULL, "Returned non-null device\n");
76 hr = IMMDeviceCollection_Item(col, 0, NULL);
77 ok(hr == E_POINTER, "Query with null pointer returned 0x%08x\n", hr);
79 hr = IMMDeviceCollection_Item(col, 0, &dev);
80 ok(hr == S_OK, "Valid Item returned 0x%08x\n", hr);
81 ok(dev != NULL, "Device is null!\n");
82 if (dev) IUnknown_Release(dev);
89 IMMDeviceEnumerator *mme;
91 IMMDeviceCollection *col;
93 CoInitializeEx(NULL, COINIT_MULTITHREADED);
94 hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&mme);
97 skip("mmdevapi not available: 0x%08x\n", hr);
101 /* Odd behavior.. bug? */
102 ref = IUnknown_AddRef(mme);
103 ok(ref == 3, "Invalid reference count after incrementing: %u\n", ref);
104 IUnknown_Release(mme);
106 hr = IUnknown_QueryInterface(mme, &IID_IUnknown, (void**)&unk);
107 ok(hr == S_OK, "returned 0x%08x\n", hr);
108 if (hr != S_OK) return;
110 ok( (LONG_PTR)mme == (LONG_PTR)unk, "Pointers are unequal %p/%p\n", unk, mme);
111 IUnknown_Release(unk);
113 col = (void*)(LONG_PTR)0x12345678;
114 hr = IMMDeviceEnumerator_EnumAudioEndpoints(mme, 0xffff, DEVICE_STATEMASK_ALL, &col);
115 ok(hr == E_INVALIDARG, "Setting invalid data flow returned 0x%08x\n", hr);
116 ok(col == NULL, "Collection pointer non-null on failure\n");
118 hr = IMMDeviceEnumerator_EnumAudioEndpoints(mme, eAll, DEVICE_STATEMASK_ALL+1, &col);
119 ok(hr == E_INVALIDARG, "Setting invalid mask returned 0x%08x\n", hr);
121 hr = IMMDeviceEnumerator_EnumAudioEndpoints(mme, eAll, DEVICE_STATEMASK_ALL, NULL);
122 ok(hr == E_POINTER, "Invalid pointer returned: 0x%08x\n", hr);
124 hr = IMMDeviceEnumerator_EnumAudioEndpoints(mme, eAll, DEVICE_STATEMASK_ALL, &col);
125 ok(hr == S_OK, "Valid EnumAudioEndpoints returned 0x%08x\n", hr);
128 ok(!!col, "Returned null pointer\n");
130 test_collection(mme, col);
133 IUnknown_Release(mme);