wined3d: Add GL_APPLE_flush_buffer_range.
[wine] / dlls / mmdevapi / tests / mmdevenum.c
1 /*
2  * Copyright 2009 Maarten Lankhorst
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include "wine/test.h"
20
21 #define CINTERFACE
22 #define COBJMACROS
23
24 #include "initguid.h"
25 #include "mmdeviceapi.h"
26 #include "dshow.h"
27 #include "dsound.h"
28
29 /* Some of the QueryInterface tests are really just to check if I got the IID's right :) */
30
31 /* IMMDeviceCollection appears to have no QueryInterface method and instead forwards to mme */
32 static void test_collection(IMMDeviceEnumerator *mme, IMMDeviceCollection *col)
33 {
34     IMMDeviceCollection *col2;
35     IMMDeviceEnumerator *mme2;
36     IUnknown *unk;
37     HRESULT hr;
38     ULONG ref;
39     UINT numdev;
40     IMMDevice *dev;
41
42     ref = IUnknown_AddRef(col);
43     IUnknown_Release(col);
44     ok(ref == 2, "Invalid reference count %u on collection\n", ref);
45
46     hr = IUnknown_QueryInterface(col, &IID_IUnknown, (void**)&unk);
47     ok(hr == S_OK, "Cannot query for IID_IUnknown: 0x%08x\n", hr);
48     if (hr == S_OK)
49     {
50         ok((LONG_PTR)col == (LONG_PTR)unk, "Pointers are not identical %p/%p/%p\n", col, unk, mme);
51         IUnknown_Release(unk);
52     }
53
54     hr = IUnknown_QueryInterface(col, &IID_IMMDeviceCollection, (void**)&col2);
55     ok(hr == S_OK, "Cannot query for IID_IMMDeviceCollection: 0x%08x\n", hr);
56     if (hr == S_OK)
57         IUnknown_Release(col2);
58
59     hr = IUnknown_QueryInterface(col, &IID_IMMDeviceEnumerator, (void**)&mme2);
60     ok(hr == E_NOINTERFACE, "Query for IID_IMMDeviceEnumerator returned: 0x%08x\n", hr);
61     if (hr == S_OK)
62         IUnknown_Release(mme2);
63
64     hr = IMMDeviceCollection_GetCount(col, NULL);
65     ok(hr == E_POINTER, "GetCount returned 0x%08x\n", hr);
66
67     hr = IMMDeviceCollection_GetCount(col, &numdev);
68     ok(hr == S_OK, "GetCount returned 0x%08x\n", hr);
69
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");
74
75     if (!numdev) return;
76     hr = IMMDeviceCollection_Item(col, 0, NULL);
77     ok(hr == E_POINTER, "Query with null pointer returned 0x%08x\n", hr);
78
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);
83 }
84
85 START_TEST(mmdevenum)
86 {
87     HRESULT hr;
88     IUnknown *unk = NULL;
89     IMMDeviceEnumerator *mme;
90     ULONG ref;
91     IMMDeviceCollection *col;
92
93     CoInitializeEx(NULL, COINIT_MULTITHREADED);
94     hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&mme);
95     if (FAILED(hr))
96     {
97         skip("mmdevapi not available: 0x%08x\n", hr);
98         return;
99     }
100
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);
105
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;
109
110     ok( (LONG_PTR)mme == (LONG_PTR)unk, "Pointers are unequal %p/%p\n", unk, mme);
111     IUnknown_Release(unk);
112
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");
117
118     hr = IMMDeviceEnumerator_EnumAudioEndpoints(mme, eAll, DEVICE_STATEMASK_ALL+1, &col);
119     ok(hr == E_INVALIDARG, "Setting invalid mask returned 0x%08x\n", hr);
120
121     hr = IMMDeviceEnumerator_EnumAudioEndpoints(mme, eAll, DEVICE_STATEMASK_ALL, NULL);
122     ok(hr == E_POINTER, "Invalid pointer returned: 0x%08x\n", hr);
123
124     hr = IMMDeviceEnumerator_EnumAudioEndpoints(mme, eAll, DEVICE_STATEMASK_ALL, &col);
125     ok(hr == S_OK, "Valid EnumAudioEndpoints returned 0x%08x\n", hr);
126     if (hr == S_OK)
127     {
128         ok(!!col, "Returned null pointer\n");
129         if (col)
130             test_collection(mme, col);
131     }
132
133     IUnknown_Release(mme);
134 }