msxml: getElementsByTagName does not respect namespaces.
[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 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
30
31 /* Some of the QueryInterface tests are really just to check if I got the IID's right :) */
32
33 /* IMMDeviceCollection appears to have no QueryInterface method and instead forwards to mme */
34 static void test_collection(IMMDeviceEnumerator *mme, IMMDeviceCollection *col)
35 {
36     IMMDeviceCollection *col2;
37     IMMDeviceEnumerator *mme2;
38     IUnknown *unk;
39     HRESULT hr;
40     ULONG ref;
41     UINT numdev;
42     IMMDevice *dev;
43
44     /* collection doesn't keep a ref on parent */
45     IUnknown_AddRef(mme);
46     ref = IUnknown_Release(mme);
47     ok(ref == 2, "Reference count on parent is %u\n", ref);
48
49     ref = IUnknown_AddRef(col);
50     IUnknown_Release(col);
51     ok(ref == 2, "Invalid reference count %u on collection\n", ref);
52
53     hr = IUnknown_QueryInterface(col, &IID_IUnknown, NULL);
54     ok(hr == E_POINTER, "Null ppv returns %08x\n", hr);
55
56     hr = IUnknown_QueryInterface(col, &IID_IUnknown, (void**)&unk);
57     ok(hr == S_OK, "Cannot query for IID_IUnknown: 0x%08x\n", hr);
58     if (hr == S_OK)
59     {
60         ok((LONG_PTR)col == (LONG_PTR)unk, "Pointers are not identical %p/%p/%p\n", col, unk, mme);
61         IUnknown_Release(unk);
62     }
63
64     hr = IUnknown_QueryInterface(col, &IID_IMMDeviceCollection, (void**)&col2);
65     ok(hr == S_OK, "Cannot query for IID_IMMDeviceCollection: 0x%08x\n", hr);
66     if (hr == S_OK)
67         IUnknown_Release(col2);
68
69     hr = IUnknown_QueryInterface(col, &IID_IMMDeviceEnumerator, (void**)&mme2);
70     ok(hr == E_NOINTERFACE, "Query for IID_IMMDeviceEnumerator returned: 0x%08x\n", hr);
71     if (hr == S_OK)
72         IUnknown_Release(mme2);
73
74     hr = IMMDeviceCollection_GetCount(col, NULL);
75     ok(hr == E_POINTER, "GetCount returned 0x%08x\n", hr);
76
77     hr = IMMDeviceCollection_GetCount(col, &numdev);
78     ok(hr == S_OK, "GetCount returned 0x%08x\n", hr);
79
80     dev = (void*)(LONG_PTR)0x12345678;
81     hr = IMMDeviceCollection_Item(col, numdev, &dev);
82     ok(hr == E_INVALIDARG, "Asking for too high device returned 0x%08x\n", hr);
83     ok(dev == NULL, "Returned non-null device\n");
84
85     if (numdev)
86     {
87         hr = IMMDeviceCollection_Item(col, 0, NULL);
88         ok(hr == E_POINTER, "Query with null pointer returned 0x%08x\n", hr);
89
90         hr = IMMDeviceCollection_Item(col, 0, &dev);
91         ok(hr == S_OK, "Valid Item returned 0x%08x\n", hr);
92         ok(dev != NULL, "Device is null!\n");
93         if (dev)
94             IUnknown_Release(dev);
95     }
96     IUnknown_Release(col);
97 }
98
99 /* Only do parameter tests here, the actual MMDevice testing should be a separate test */
100 START_TEST(mmdevenum)
101 {
102     HRESULT hr;
103     IUnknown *unk = NULL;
104     IMMDeviceEnumerator *mme, *mme2;
105     ULONG ref;
106     IMMDeviceCollection *col;
107
108     CoInitializeEx(NULL, COINIT_MULTITHREADED);
109     hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&mme);
110     if (FAILED(hr))
111     {
112         skip("mmdevapi not available: 0x%08x\n", hr);
113         return;
114     }
115
116     /* Odd behavior.. bug? */
117     ref = IUnknown_AddRef(mme);
118     ok(ref == 3, "Invalid reference count after incrementing: %u\n", ref);
119     IUnknown_Release(mme);
120
121     hr = IUnknown_QueryInterface(mme, &IID_IUnknown, (void**)&unk);
122     ok(hr == S_OK, "returned 0x%08x\n", hr);
123     if (hr != S_OK) return;
124
125     ok( (LONG_PTR)mme == (LONG_PTR)unk, "Pointers are unequal %p/%p\n", unk, mme);
126     IUnknown_Release(unk);
127
128     /* Proving that it is static.. */
129     hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&mme2);
130     IUnknown_Release(mme2);
131     ok(mme == mme2, "Pointers are not equal!\n");
132
133     hr = IUnknown_QueryInterface(mme, &IID_IUnknown, NULL);
134     ok(hr == E_POINTER, "Null pointer on QueryInterface returned %08x\n", hr);
135
136     hr = IUnknown_QueryInterface(mme, &GUID_NULL, (void**)&unk);
137     ok(!unk, "Unk not reset to null after invalid QI\n");
138     ok(hr == E_NOINTERFACE, "Invalid hr %08x returned on IID_NULL\n", hr);
139
140     col = (void*)(LONG_PTR)0x12345678;
141     hr = IMMDeviceEnumerator_EnumAudioEndpoints(mme, 0xffff, DEVICE_STATEMASK_ALL, &col);
142     ok(hr == E_INVALIDARG, "Setting invalid data flow returned 0x%08x\n", hr);
143     ok(col == NULL, "Collection pointer non-null on failure\n");
144
145     hr = IMMDeviceEnumerator_EnumAudioEndpoints(mme, eAll, DEVICE_STATEMASK_ALL+1, &col);
146     ok(hr == E_INVALIDARG, "Setting invalid mask returned 0x%08x\n", hr);
147
148     hr = IMMDeviceEnumerator_EnumAudioEndpoints(mme, eAll, DEVICE_STATEMASK_ALL, NULL);
149     ok(hr == E_POINTER, "Invalid pointer returned: 0x%08x\n", hr);
150
151     hr = IMMDeviceEnumerator_EnumAudioEndpoints(mme, eAll, DEVICE_STATEMASK_ALL, &col);
152     ok(hr == S_OK, "Valid EnumAudioEndpoints returned 0x%08x\n", hr);
153     if (hr == S_OK)
154     {
155         ok(!!col, "Returned null pointer\n");
156         if (col)
157             test_collection(mme, col);
158     }
159
160     IUnknown_Release(mme);
161 }