Release 1.5.29.
[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     hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL,
86             CLSCTX_INPROC_SERVER, &IID_IDirectMusicPerformance8,
87             (void**)&idmusicperformance);
88     ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
89
90     hr = IDirectMusicPerformance8_InitAudio(idmusicperformance, NULL, NULL,
91             NULL, 0, 64, 0, NULL);
92     ok(hr == S_OK, "InitAudio failed: %08x\n", hr);
93
94     hr = IDirectMusicPerformance8_CloseDown(idmusicperformance);
95     ok(hr == S_OK, "CloseDown failed: %08x\n", hr);
96
97     IDirectMusicPerformance8_Release(idmusicperformance);
98
99     return S_OK;
100 }
101
102 static void test_createport(void)
103 {
104     IDirectMusicPerformance8 *perf;
105     IDirectMusic *music = NULL;
106     IDirectMusicPort *port = NULL;
107     DMUS_PORTCAPS portcaps;
108     DMUS_PORTPARAMS portparams;
109     DWORD i;
110     HRESULT hr;
111
112     hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL,
113             CLSCTX_INPROC_SERVER, &IID_IDirectMusicPerformance8, (void**)&perf);
114     ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
115
116     hr = IDirectMusicPerformance8_Init(perf, &music, NULL, NULL);
117     ok(hr == S_OK, "Init failed: %08x\n", hr);
118     ok(music != NULL, "Didn't get IDirectMusic pointer\n");
119
120     i = 0;
121     while(1){
122         portcaps.dwSize = sizeof(portcaps);
123
124         hr = IDirectMusic_EnumPort(music, i, &portcaps);
125         ok(hr == S_OK || hr == S_FALSE || (i == 0 && hr == E_INVALIDARG), "EnumPort failed: %08x\n", hr);
126         if(hr != S_OK)
127             break;
128
129         ok(portcaps.dwSize == sizeof(portcaps), "Got unexpected portcaps struct size: %08x\n", portcaps.dwSize);
130         trace("portcaps(%u).dwFlags: %08x\n", i, portcaps.dwFlags);
131         trace("portcaps(%u).guidPort: %s\n", i, debugstr_guid(&portcaps.guidPort));
132         trace("portcaps(%u).dwClass: %08x\n", i, portcaps.dwClass);
133         trace("portcaps(%u).dwType: %08x\n", i, portcaps.dwType);
134         trace("portcaps(%u).dwMemorySize: %08x\n", i, portcaps.dwMemorySize);
135         trace("portcaps(%u).dwMaxChannelGroups: %08x\n", i, portcaps.dwMaxChannelGroups);
136         trace("portcaps(%u).dwMaxVoices: %08x\n", i, portcaps.dwMaxVoices);
137         trace("portcaps(%u).dwMaxAudioChannels: %08x\n", i, portcaps.dwMaxAudioChannels);
138         trace("portcaps(%u).dwEffectFlags: %08x\n", i, portcaps.dwEffectFlags);
139         trace("portcaps(%u).wszDescription: %s\n", i, wine_dbgstr_w(portcaps.wszDescription));
140
141         ++i;
142     }
143
144     if(i == 0){
145         win_skip("No ports available, skipping tests\n");
146         return;
147     }
148
149     portparams.dwSize = sizeof(portparams);
150
151     /* dwValidParams == 0 -> S_OK, filled struct */
152     portparams.dwValidParams = 0;
153     hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth,
154             &portparams, &port, NULL);
155     ok(hr == S_OK, "CreatePort failed: %08x\n", hr);
156     ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
157
158     IDirectMusicPort_Release(port);
159     port = NULL;
160
161     todo_wine ok(portparams.dwValidParams != 0, "portparams struct was not filled in\n");
162
163     /* dwValidParams != 0, invalid param -> S_FALSE, filled struct */
164     portparams.dwValidParams = DMUS_PORTPARAMS_CHANNELGROUPS;
165     portparams.dwChannelGroups = 0;
166     hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth,
167             &portparams, &port, NULL);
168     todo_wine ok(hr == S_FALSE, "CreatePort failed: %08x\n", hr);
169     ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
170
171     IDirectMusicPort_Release(port);
172     port = NULL;
173
174     ok(portparams.dwValidParams != 0, "portparams struct was not filled in\n");
175
176     /* dwValidParams != 0, valid params -> S_OK */
177     hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth,
178             &portparams, &port, NULL);
179     ok(hr == S_OK, "CreatePort failed: %08x\n", hr);
180     ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
181
182     IDirectMusicPort_Release(port);
183     port = NULL;
184
185     /* GUID_NULL succeeds */
186     portparams.dwValidParams = 0;
187     hr = IDirectMusic_CreatePort(music, &GUID_NULL, &portparams, &port, NULL);
188     ok(hr == S_OK, "CreatePort failed: %08x\n", hr);
189     ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
190
191     IDirectMusicPort_Release(port);
192     port = NULL;
193
194     todo_wine ok(portparams.dwValidParams != 0, "portparams struct was not filled in\n");
195
196     /* null GUID fails */
197     portparams.dwValidParams = 0;
198     hr = IDirectMusic_CreatePort(music, NULL, &portparams, &port, NULL);
199     ok(hr == E_POINTER, "CreatePort failed: %08x\n", hr);
200     ok(port == NULL, "Get IDirectMusicPort pointer? %p\n", port);
201     ok(portparams.dwValidParams == 0, "portparams struct was filled in?\n");
202
203     /* garbage GUID fails */
204     portparams.dwValidParams = 0;
205     hr = IDirectMusic_CreatePort(music, &GUID_Bunk, &portparams, &port, NULL);
206     ok(hr == E_NOINTERFACE, "CreatePort failed: %08x\n", hr);
207     ok(port == NULL, "Get IDirectMusicPort pointer? %p\n", port);
208     ok(portparams.dwValidParams == 0, "portparams struct was filled in?\n");
209
210     IDirectMusic_Release(music);
211     IDirectMusicPerformance_Release(perf);
212 }
213
214 static void test_COM(void)
215 {
216     IDirectMusicPerformance *dmp = (IDirectMusicPerformance*)0xdeadbeef;
217     IDirectMusicPerformance *dmp2;
218     IDirectMusicPerformance8 *dmp8;
219     ULONG refcount;
220     HRESULT hr;
221
222     /* COM aggregation */
223     hr = CoCreateInstance(&CLSID_DirectMusicPerformance, (IUnknown*)&dmp, CLSCTX_INPROC_SERVER,
224             &IID_IUnknown, (void**)&dmp);
225     ok(hr == CLASS_E_NOAGGREGATION,
226             "DirectMusicPerformance create failed: %08x, expected CLASS_E_NOAGGREGATION\n", hr);
227     ok(!dmp, "dmp = %p\n", dmp);
228
229     /* Invalid RIID */
230     hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC_SERVER,
231             &IID_IDirectSound, (void**)&dmp);
232     ok(hr == E_NOINTERFACE,
233             "DirectMusicPerformance create failed: %08x, expected E_NOINTERFACE\n", hr);
234
235     /* Same refcount */
236     hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC_SERVER,
237             &IID_IDirectMusicPerformance, (void**)&dmp);
238     ok(hr == S_OK, "DirectMusicPerformance create failed: %08x, expected S_OK\n", hr);
239     refcount = IDirectMusicPerformance_AddRef(dmp);
240     ok (refcount == 2, "refcount == %u, expected 2\n", refcount);
241     hr = IDirectMusicPerformance_QueryInterface(dmp, &IID_IDirectMusicPerformance2, (void**)&dmp2);
242     ok(hr == S_OK, "QueryInterface for IID_IDirectMusicPerformance2 failed: %08x\n", hr);
243     IDirectMusicPerformance_AddRef(dmp);
244     refcount = IDirectMusicPerformance_Release(dmp);
245     ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
246     hr = IDirectMusicPerformance_QueryInterface(dmp, &IID_IDirectMusicPerformance8, (void**)&dmp8);
247     ok(hr == S_OK, "QueryInterface for IID_IDirectMusicPerformance8 failed: %08x\n", hr);
248     refcount = IDirectMusicPerformance_Release(dmp);
249     ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
250     refcount = IDirectMusicPerformance8_Release(dmp8);
251     ok (refcount == 2, "refcount == %u, expected 2\n", refcount);
252     refcount = IDirectMusicPerformance_Release(dmp2);
253     ok (refcount == 1, "refcount == %u, expected 1\n", refcount);
254     refcount = IDirectMusicPerformance_Release(dmp);
255     ok (refcount == 0, "refcount == %u, expected 0\n", refcount);
256 }
257
258 static void test_dms_COM(void)
259 {
260     IDirectMusicSegment8 *dms = (IDirectMusicSegment8*)0xdeadbeef;
261     IDirectMusicObject *dmo;
262     IPersistStream *stream;
263     IUnknown *unk;
264     ULONG refcount;
265     HRESULT hr;
266
267     /* COM aggregation */
268     hr = CoCreateInstance(&CLSID_DirectMusicSegment, (IUnknown*)&dms, CLSCTX_INPROC_SERVER,
269             &IID_IUnknown, (void**)&dms);
270     ok(hr == CLASS_E_NOAGGREGATION,
271             "DirectMusicSegment create failed: %08x, expected CLASS_E_NOAGGREGATION\n", hr);
272     ok(!dms, "dms = %p\n", dms);
273
274     /* Invalid RIID */
275     hr = CoCreateInstance(&CLSID_DirectMusicSegment, NULL, CLSCTX_INPROC_SERVER,
276             &IID_IDirectSound, (void**)&dms);
277     ok(hr == E_NOINTERFACE,
278             "DirectMusicSegment create failed: %08x, expected E_NOINTERFACE\n", hr);
279
280     /* Same refcount */
281     hr = CoCreateInstance(&CLSID_DirectMusicSegment, NULL, CLSCTX_INPROC_SERVER,
282             &IID_IDirectMusicSegment8, (void**)&dms);
283     ok(hr == S_OK, "DirectMusicSegment create failed: %08x, expected S_OK\n", hr);
284     refcount = IDirectMusicSegment8_AddRef(dms);
285     ok (refcount == 2, "refcount == %u, expected 2\n", refcount);
286     hr = IDirectMusicSegment8_QueryInterface(dms, &IID_IDirectMusicObject, (void**)&dmo);
287     ok(hr == S_OK, "QueryInterface for IID_IDirectMusicObject failed: %08x\n", hr);
288     IDirectMusicSegment8_AddRef(dms);
289     refcount = IDirectMusicSegment8_Release(dms);
290     ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
291     hr = IDirectMusicSegment8_QueryInterface(dms, &IID_IPersistStream, (void**)&stream);
292     ok(hr == S_OK, "QueryInterface for IID_IPersistStream failed: %08x\n", hr);
293     refcount = IDirectMusicSegment8_Release(dms);
294     ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
295     hr = IDirectMusicSegment8_QueryInterface(dms, &IID_IUnknown, (void**)&unk);
296     ok(hr == S_OK, "QueryInterface for IID_IUnknown failed: %08x\n", hr);
297     refcount = IUnknown_Release(unk);
298     ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
299     refcount = IDirectMusicObject_Release(dmo);
300     ok (refcount == 2, "refcount == %u, expected 2\n", refcount);
301     refcount = IPersistStream_Release(stream);
302     ok (refcount == 1, "refcount == %u, expected 1\n", refcount);
303     refcount = IDirectMusicSegment8_Release(dms);
304     ok (refcount == 0, "refcount == %u, expected 0\n", refcount);
305 }
306
307 START_TEST( performance )
308 {
309     HRESULT hr;
310
311     hr = CoInitialize(NULL);
312     if (FAILED(hr)) {
313         skip("Cannot initialize COM (%x)\n", hr);
314         return;
315     }
316
317     hr = test_InitAudio();
318     if (hr != S_OK) {
319         skip("InitAudio failed (%x)\n", hr);
320         return;
321     }
322
323     test_COM();
324     test_createport();
325
326     test_dms_COM();
327
328     CoUninitialize();
329 }