mshtml: Added better IHTMLWindow2::get_opener stub.
[wine] / dlls / dmime / tests / performance.c
1 /*
2  * Unit test suite for IDirectMusicPerformance
3  *
4  * Copyright 2010 Austin Lund
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #define COBJMACROS
22
23 #include <stdarg.h>
24 #include <windef.h>
25 #include <initguid.h>
26 #include <wine/test.h>
27 #include <dmusici.h>
28
29 #include <stdio.h>
30
31 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
32 DEFINE_GUID(GUID_Bunk,0xFFFFFFFF,0xFFFF,0xFFFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF);
33
34 static const char *debugstr_guid(REFIID riid)
35 {
36     static char buf[50];
37
38     sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
39             riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
40             riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
41             riid->Data4[5], riid->Data4[6], riid->Data4[7]);
42
43     return buf;
44 }
45
46 static HRESULT test_InitAudio(void)
47 {
48     IDirectMusicPerformance8 *idmusicperformance;
49     IDirectSound *pDirectSound;
50     IDirectMusicPort *pDirectMusicPort;
51     IDirectMusicAudioPath *pDirectMusicAudioPath;
52     HRESULT hr;
53
54     hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL,
55             CLSCTX_INPROC_SERVER, &IID_IDirectMusicPerformance8, (LPVOID *)&idmusicperformance);
56     if (hr != S_OK) {
57         skip("Cannot create DirectMusicPerformance object (%x)\n", hr);
58         CoUninitialize();
59         return hr;
60     }
61
62     pDirectSound = NULL;
63     hr = IDirectMusicPerformance8_InitAudio(idmusicperformance ,NULL,
64         &pDirectSound, NULL, DMUS_APATH_SHARED_STEREOPLUSREVERB, 128, DMUS_AUDIOF_ALL, NULL);
65     if(hr != S_OK)
66         return hr;
67
68     pDirectMusicPort = NULL;
69     hr = IDirectMusicPerformance8_PChannelInfo(idmusicperformance, 0, &pDirectMusicPort, NULL, NULL);
70     ok(hr == S_OK, "Failed to call PChannelInfo (%x)\n", hr);
71     ok(pDirectMusicPort != NULL, "IDirectMusicPort not set\n");
72     if (hr == S_OK && pDirectMusicPort != NULL)
73         IDirectMusicPort_Release(pDirectMusicPort);
74
75     hr = IDirectMusicPerformance8_GetDefaultAudioPath(idmusicperformance, &pDirectMusicAudioPath);
76     ok(hr == S_OK, "Failed to call GetDefaultAudioPath (%x)\n", hr);
77     if (hr == S_OK)
78         IDirectMusicAudioPath_Release(pDirectMusicAudioPath);
79
80     hr = IDirectMusicPerformance8_CloseDown(idmusicperformance);
81     ok(hr == S_OK, "Failed to call CloseDown (%x)\n", hr);
82
83     IDirectMusicPerformance8_Release(idmusicperformance);
84
85     return S_OK;
86 }
87
88 static void test_createport(void)
89 {
90     IDirectMusicPerformance8 *perf;
91     IDirectMusic *music = NULL;
92     IDirectMusicPort *port = NULL;
93     DMUS_PORTCAPS portcaps;
94     DMUS_PORTPARAMS portparams;
95     DWORD i;
96     HRESULT hr;
97
98     hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL,
99             CLSCTX_INPROC_SERVER, &IID_IDirectMusicPerformance8, (void**)&perf);
100     ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
101
102     hr = IDirectMusicPerformance8_Init(perf, &music, NULL, NULL);
103     ok(hr == S_OK, "Init failed: %08x\n", hr);
104     ok(music != NULL, "Didn't get IDirectMusic pointer\n");
105
106     i = 0;
107     while(1){
108         portcaps.dwSize = sizeof(portcaps);
109
110         hr = IDirectMusic_EnumPort(music, i, &portcaps);
111         ok(hr == S_OK || hr == S_FALSE || (i == 0 && hr == E_INVALIDARG), "EnumPort failed: %08x\n", hr);
112         if(hr != S_OK)
113             break;
114
115         ok(portcaps.dwSize == sizeof(portcaps), "Got unexpected portcaps struct size: %08x\n", portcaps.dwSize);
116         trace("portcaps(%u).dwFlags: %08x\n", i, portcaps.dwFlags);
117         trace("portcaps(%u).guidPort: %s\n", i, debugstr_guid(&portcaps.guidPort));
118         trace("portcaps(%u).dwClass: %08x\n", i, portcaps.dwClass);
119         trace("portcaps(%u).dwType: %08x\n", i, portcaps.dwType);
120         trace("portcaps(%u).dwMemorySize: %08x\n", i, portcaps.dwMemorySize);
121         trace("portcaps(%u).dwMaxChannelGroups: %08x\n", i, portcaps.dwMaxChannelGroups);
122         trace("portcaps(%u).dwMaxVoices: %08x\n", i, portcaps.dwMaxVoices);
123         trace("portcaps(%u).dwMaxAudioChannels: %08x\n", i, portcaps.dwMaxAudioChannels);
124         trace("portcaps(%u).dwEffectFlags: %08x\n", i, portcaps.dwEffectFlags);
125         trace("portcaps(%u).wszDescription: %s\n", i, wine_dbgstr_w(portcaps.wszDescription));
126
127         ++i;
128     }
129
130     if(i == 0){
131         win_skip("No ports available, skipping tests\n");
132         return;
133     }
134
135     portparams.dwSize = sizeof(portparams);
136
137     /* dwValidParams == 0 -> S_OK, filled struct */
138     portparams.dwValidParams = 0;
139     hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth,
140             &portparams, &port, NULL);
141     ok(hr == S_OK, "CreatePort failed: %08x\n", hr);
142     ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
143
144     IDirectMusicPort_Release(port);
145     port = NULL;
146
147     todo_wine ok(portparams.dwValidParams != 0, "portparams struct was not filled in\n");
148
149     /* dwValidParams != 0, invalid param -> S_FALSE, filled struct */
150     portparams.dwValidParams = DMUS_PORTPARAMS_CHANNELGROUPS;
151     portparams.dwChannelGroups = 0;
152     hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth,
153             &portparams, &port, NULL);
154     todo_wine ok(hr == S_FALSE, "CreatePort failed: %08x\n", hr);
155     ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
156
157     IDirectMusicPort_Release(port);
158     port = NULL;
159
160     ok(portparams.dwValidParams != 0, "portparams struct was not filled in\n");
161
162     /* dwValidParams != 0, valid params -> S_OK */
163     hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth,
164             &portparams, &port, NULL);
165     ok(hr == S_OK, "CreatePort failed: %08x\n", hr);
166     ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
167
168     IDirectMusicPort_Release(port);
169     port = NULL;
170
171     /* GUID_NULL succeeds */
172     portparams.dwValidParams = 0;
173     hr = IDirectMusic_CreatePort(music, &GUID_NULL, &portparams, &port, NULL);
174     ok(hr == S_OK, "CreatePort failed: %08x\n", hr);
175     ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
176
177     IDirectMusicPort_Release(port);
178     port = NULL;
179
180     todo_wine ok(portparams.dwValidParams != 0, "portparams struct was not filled in\n");
181
182     /* null GUID fails */
183     portparams.dwValidParams = 0;
184     hr = IDirectMusic_CreatePort(music, NULL, &portparams, &port, NULL);
185     ok(hr == E_POINTER, "CreatePort failed: %08x\n", hr);
186     ok(port == NULL, "Get IDirectMusicPort pointer? %p\n", port);
187     ok(portparams.dwValidParams == 0, "portparams struct was filled in?\n");
188
189     /* garbage GUID fails */
190     portparams.dwValidParams = 0;
191     hr = IDirectMusic_CreatePort(music, &GUID_Bunk, &portparams, &port, NULL);
192     ok(hr == E_NOINTERFACE, "CreatePort failed: %08x\n", hr);
193     ok(port == NULL, "Get IDirectMusicPort pointer? %p\n", port);
194     ok(portparams.dwValidParams == 0, "portparams struct was filled in?\n");
195
196     IDirectMusic_Release(music);
197     IDirectMusicPerformance_Release(perf);
198 }
199
200 static void test_COM(void)
201 {
202     IDirectMusicPerformance *dmp = (IDirectMusicPerformance*)0xdeadbeef;
203     IDirectMusicPerformance *dmp2;
204     IDirectMusicPerformance8 *dmp8;
205     ULONG refcount;
206     HRESULT hr;
207
208     /* COM aggregation */
209     hr = CoCreateInstance(&CLSID_DirectMusicPerformance, (IUnknown*)&dmp, CLSCTX_INPROC_SERVER,
210             &IID_IUnknown, (void**)&dmp);
211     ok(hr == CLASS_E_NOAGGREGATION,
212             "DirectMusicPerformance create failed: %08x, expected CLASS_E_NOAGGREGATION\n", hr);
213     ok(!dmp, "dmp = %p\n", dmp);
214
215     /* Invalid RIID */
216     hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC_SERVER,
217             &IID_IDirectSound, (void**)&dmp);
218     ok(hr == E_NOINTERFACE,
219             "DirectMusicPerformance create failed: %08x, expected E_NOINTERFACE\n", hr);
220
221     /* Same refcount */
222     hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC_SERVER,
223             &IID_IDirectMusicPerformance, (void**)&dmp);
224     ok(hr == S_OK, "DirectMusicPerformance create failed: %08x, expected S_OK\n", hr);
225     refcount = IDirectMusicPerformance_AddRef(dmp);
226     ok (refcount == 2, "refcount == %u, expected 2\n", refcount);
227     hr = IDirectMusicPerformance_QueryInterface(dmp, &IID_IDirectMusicPerformance2, (void**)&dmp2);
228     ok(hr == S_OK, "QueryInterface for IID_IDirectMusicPerformance2 failed: %08x\n", hr);
229     IDirectMusicPerformance_AddRef(dmp);
230     refcount = IDirectMusicPerformance_Release(dmp);
231     ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
232     hr = IDirectMusicPerformance_QueryInterface(dmp, &IID_IDirectMusicPerformance8, (void**)&dmp8);
233     ok(hr == S_OK, "QueryInterface for IID_IDirectMusicPerformance8 failed: %08x\n", hr);
234     refcount = IDirectMusicPerformance_Release(dmp);
235     ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
236     refcount = IDirectMusicPerformance8_Release(dmp8);
237     ok (refcount == 2, "refcount == %u, expected 2\n", refcount);
238     refcount = IDirectMusicPerformance_Release(dmp2);
239     ok (refcount == 1, "refcount == %u, expected 1\n", refcount);
240     refcount = IDirectMusicPerformance_Release(dmp);
241     ok (refcount == 0, "refcount == %u, expected 0\n", refcount);
242 }
243
244 static void test_dms_COM(void)
245 {
246     IDirectMusicSegment8 *dms = (IDirectMusicSegment8*)0xdeadbeef;
247     IDirectMusicObject *dmo;
248     IPersistStream *stream;
249     IUnknown *unk;
250     ULONG refcount;
251     HRESULT hr;
252
253     /* COM aggregation */
254     hr = CoCreateInstance(&CLSID_DirectMusicSegment, (IUnknown*)&dms, CLSCTX_INPROC_SERVER,
255             &IID_IUnknown, (void**)&dms);
256     ok(hr == CLASS_E_NOAGGREGATION,
257             "DirectMusicSegment create failed: %08x, expected CLASS_E_NOAGGREGATION\n", hr);
258     ok(!dms, "dms = %p\n", dms);
259
260     /* Invalid RIID */
261     hr = CoCreateInstance(&CLSID_DirectMusicSegment, NULL, CLSCTX_INPROC_SERVER,
262             &IID_IDirectSound, (void**)&dms);
263     ok(hr == E_NOINTERFACE,
264             "DirectMusicSegment create failed: %08x, expected E_NOINTERFACE\n", hr);
265
266     /* Same refcount */
267     hr = CoCreateInstance(&CLSID_DirectMusicSegment, NULL, CLSCTX_INPROC_SERVER,
268             &IID_IDirectMusicSegment8, (void**)&dms);
269     ok(hr == S_OK, "DirectMusicSegment create failed: %08x, expected S_OK\n", hr);
270     refcount = IDirectMusicSegment8_AddRef(dms);
271     ok (refcount == 2, "refcount == %u, expected 2\n", refcount);
272     hr = IDirectMusicSegment8_QueryInterface(dms, &IID_IDirectMusicObject, (void**)&dmo);
273     ok(hr == S_OK, "QueryInterface for IID_IDirectMusicObject failed: %08x\n", hr);
274     IDirectMusicSegment8_AddRef(dms);
275     refcount = IDirectMusicSegment8_Release(dms);
276     ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
277     hr = IDirectMusicSegment8_QueryInterface(dms, &IID_IPersistStream, (void**)&stream);
278     ok(hr == S_OK, "QueryInterface for IID_IPersistStream failed: %08x\n", hr);
279     refcount = IDirectMusicSegment8_Release(dms);
280     ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
281     hr = IDirectMusicSegment8_QueryInterface(dms, &IID_IUnknown, (void**)&unk);
282     ok(hr == S_OK, "QueryInterface for IID_IUnknown failed: %08x\n", hr);
283     refcount = IUnknown_Release(unk);
284     ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
285     refcount = IDirectMusicObject_Release(dmo);
286     ok (refcount == 2, "refcount == %u, expected 2\n", refcount);
287     refcount = IPersistStream_Release(stream);
288     ok (refcount == 1, "refcount == %u, expected 1\n", refcount);
289     refcount = IDirectMusicSegment8_Release(dms);
290     ok (refcount == 0, "refcount == %u, expected 0\n", refcount);
291 }
292
293 START_TEST( performance )
294 {
295     HRESULT hr;
296
297     hr = CoInitialize(NULL);
298     if (FAILED(hr)) {
299         skip("Cannot initialize COM (%x)\n", hr);
300         return;
301     }
302
303     hr = test_InitAudio();
304     if (hr != S_OK) {
305         skip("InitAudio failed (%x)\n", hr);
306         return;
307     }
308
309     test_COM();
310     test_createport();
311
312     test_dms_COM();
313
314     CoUninitialize();
315 }