Only print format info when in interactive mode for capture test.
[wine/multimedia.git] / dlls / dsound / tests / propset.c
blob15aaf5550ef99fdf19504bdbd9a9313e39827f60
1 /*
2 * Unit tests for CLSID_DirectSoundPrivate property set functions
3 * (used by dxdiag)
5 * Copyright (c) 2003 Robert Reif
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #define NONAMELESSSTRUCT
23 #define NONAMELESSUNION
24 #include <windows.h>
26 #include <math.h>
27 #include <stdlib.h>
29 #include "wine/test.h"
30 #include "windef.h"
31 #include "wingdi.h"
32 #include "dsound.h"
33 #include "initguid.h"
34 #include "dsconf.h"
35 #include "dxerr8.h"
37 #ifndef DSBCAPS_CTRLDEFAULT
38 #define DSBCAPS_CTRLDEFAULT \
39 DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLPAN|DSBCAPS_CTRLVOLUME
40 #endif
42 DEFINE_GUID(DSPROPSETID_VoiceManager, \
43 0x62A69BAE,0xDF9D,0x11D1,0x99,0xA6,0x00,0xC0,0x4F,0xC9,0x9D,0x46);
44 DEFINE_GUID(DSPROPSETID_EAX20_ListenerProperties, \
45 0x306a6a8,0xb224,0x11d2,0x99,0xe5,0x0,0x0,0xe8,0xd8,0xc7,0x22);
46 DEFINE_GUID(DSPROPSETID_EAX20_BufferProperties, \
47 0x306a6a7,0xb224,0x11d2,0x99,0xe5,0x0,0x0,0xe8,0xd8,0xc7,0x22);
48 DEFINE_GUID(DSPROPSETID_I3DL2_ListenerProperties, \
49 0xDA0F0520,0x300A,0x11D3,0x8A,0x2B,0x00,0x60,0x97,0x0D,0xB0,0x11);
50 DEFINE_GUID(DSPROPSETID_I3DL2_BufferProperties, \
51 0xDA0F0521,0x300A,0x11D3,0x8A,0x2B,0x00,0x60,0x97,0x0D,0xB0,0x11);
52 DEFINE_GUID(DSPROPSETID_ZOOMFX_BufferProperties, \
53 0xCD5368E0,0x3450,0x11D3,0x8B,0x6E,0x00,0x10,0x5A,0x9B,0x7B,0xBC);
55 typedef HRESULT (CALLBACK * MYPROC)(REFCLSID, REFIID, LPVOID *);
57 BOOL CALLBACK callback(PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_DATA data,
58 LPVOID context)
60 trace("found device:\n");
61 trace("\tType: %s\n",
62 data->Type == DIRECTSOUNDDEVICE_TYPE_EMULATED ? "Emulated" :
63 data->Type == DIRECTSOUNDDEVICE_TYPE_VXD ? "VxD" :
64 data->Type == DIRECTSOUNDDEVICE_TYPE_WDM ? "WDM" : "Unknown");
65 trace("\tDataFlow: %s\n",
66 data->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_RENDER ? "Render" :
67 data->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE ?
68 "Capture" : "Unknown");
69 trace("\tDeviceId: {%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n",
70 data->DeviceId.Data1,data->DeviceId.Data2,data->DeviceId.Data3,
71 data->DeviceId.Data4[0],data->DeviceId.Data4[1],
72 data->DeviceId.Data4[2],data->DeviceId.Data4[3],
73 data->DeviceId.Data4[4],data->DeviceId.Data4[5],
74 data->DeviceId.Data4[6],data->DeviceId.Data4[7]);
75 trace("\tDescription: %s\n", data->Description);
76 trace("\tModule: %s\n", data->Module);
77 trace("\tInterface: %s\n", data->Interface);
78 trace("\tWaveDeviceId: %ld\n", data->WaveDeviceId);
80 return TRUE;
83 static void propset_private_tests()
85 HMODULE hDsound;
86 HRESULT rc;
87 IClassFactory * pcf;
88 IKsPropertySet * pps;
89 MYPROC fProc;
90 ULONG support;
92 hDsound = LoadLibrary("dsound.dll");
93 ok(hDsound!=0,"LoadLibrary(dsound.dll) failed\n");
94 if (hDsound==0)
95 return;
97 fProc = (MYPROC)GetProcAddress(hDsound, "DllGetClassObject");
99 /* try direct sound first */
100 rc = (fProc)(&CLSID_DirectSound, &IID_IClassFactory, (void **)0);
101 ok(rc==DSERR_INVALIDPARAM,"DllGetClassObject(CLSID_DirectSound, "
102 "IID_IClassFactory) should have returned DSERR_INVALIDPARAM, "
103 "returned: %s\n",DXGetErrorString8(rc));
105 rc = (fProc)(&CLSID_DirectSound, &IID_IClassFactory, (void **)(&pcf));
106 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSound, IID_IClassFactory) "
107 "failed: %s\n",DXGetErrorString8(rc));
108 if (pcf==0)
109 goto error;
111 /* direct sound doesn't have an IKsPropertySet */
112 rc = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet,
113 (void **)0);
114 ok(rc==DSERR_INVALIDPARAM, "CreateInstance(IID_IKsPropertySet) should have "
115 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
117 rc = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet,
118 (void **)(&pps));
119 ok(rc==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have "
120 "returned E_NOINTERFACE, returned: %s\n",DXGetErrorString8(rc));
122 /* and the direct sound 8 version */
123 rc = (fProc)(&CLSID_DirectSound8, &IID_IClassFactory, (void **)(&pcf));
124 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSound8, IID_IClassFactory) "
125 "failed: %s\n",DXGetErrorString8(rc));
126 if (pcf==0)
127 goto error;
129 /* direct sound 8 doesn't have an IKsPropertySet */
130 rc = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet,
131 (void **)(&pps));
132 ok(rc==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have "
133 "returned E_NOINTERFACE, returned: %s\n",DXGetErrorString8(rc));
135 /* try direct sound capture next */
136 rc = (fProc)(&CLSID_DirectSoundCapture, &IID_IClassFactory,
137 (void **)(&pcf));
138 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSoundCapture, IID_IClassFactory) "
139 "failed: %s\n",DXGetErrorString8(rc));
140 if (pcf==0)
141 goto error;
143 /* direct sound capture doesn't have an IKsPropertySet */
144 rc = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet,
145 (void **)(&pps));
146 ok(rc==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have "
147 "returned E_NOINTERFACE,returned: %s\n",DXGetErrorString8(rc));
149 /* and the direct sound capture 8 version */
150 rc = (fProc)(&CLSID_DirectSoundCapture8, &IID_IClassFactory,
151 (void **)(&pcf));
152 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSoundCapture8, "
153 "IID_IClassFactory) failed: %s\n",DXGetErrorString8(rc));
154 if (pcf==0)
155 goto error;
157 /* direct sound capture 8 doesn't have an IKsPropertySet */
158 rc = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet,
159 (void **)(&pps));
160 ok(rc==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have "
161 "returned E_NOINTERFACE, returned: %s\n",DXGetErrorString8(rc));
163 /* try direct sound full duplex next */
164 rc = (fProc)(&CLSID_DirectSoundFullDuplex, &IID_IClassFactory,
165 (void **)(&pcf));
166 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSoundFullDuplex, "
167 "IID_IClassFactory) failed: %s\n",DXGetErrorString8(rc));
168 if (pcf==0)
169 goto error;
171 /* direct sound full duplex doesn't have an IKsPropertySet */
172 rc = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet,
173 (void **)(&pps));
174 ok(rc==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have "
175 "returned NOINTERFACE, returned: %s\n",DXGetErrorString8(rc));
177 /* try direct sound private last */
178 rc = (fProc)(&CLSID_DirectSoundPrivate, &IID_IClassFactory,
179 (void **)(&pcf));
180 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSoundPrivate, "
181 "IID_IClassFactory) failed: %s\n",DXGetErrorString8(rc));
182 if (pcf==0)
183 goto error;
185 /* direct sound private does have an IKsPropertySet */
186 rc = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet,
187 (void **)(&pps));
188 ok(rc==DS_OK, "CreateInstance(IID_IKsPropertySet) failed: %s\n",
189 DXGetErrorString8(rc));
190 if (rc!=DS_OK)
191 goto error;
193 rc = pps->lpVtbl->QuerySupport(pps, &DSPROPSETID_DirectSoundDevice,
194 DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION,
195 &support);
196 ok(rc==DS_OK, "QuerySupport(DSPROPSETID_DirectSoundDevice, "
197 "DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION) failed: %s\n",
198 DXGetErrorString8(rc));
199 if (rc!=DS_OK)
200 goto error;
202 ok(support & KSPROPERTY_SUPPORT_GET,
203 "Couldn't get DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION: "
204 "support = 0x%lx\n",support);
205 ok(!(support & KSPROPERTY_SUPPORT_SET),
206 "Shouldn't be able to set DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION: "
207 "support = 0x%lx\n",support);
209 rc = pps->lpVtbl->QuerySupport(pps, &DSPROPSETID_DirectSoundDevice,
210 DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING, &support);
211 ok(rc==DS_OK, "QuerySupport(DSPROPSETID_DirectSoundDevice, "
212 "DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING) failed: %s\n",
213 DXGetErrorString8(rc));
214 if (rc!=DS_OK)
215 goto error;
217 ok(support & KSPROPERTY_SUPPORT_GET,
218 "Couldn't get DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING: "
219 "support = 0x%lx\n",support);
220 ok(!(support & KSPROPERTY_SUPPORT_SET), "Shouldn't be able to set "
221 "DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING: support = "
222 "0x%lx\n",support);
224 rc = pps->lpVtbl->QuerySupport(pps, &DSPROPSETID_DirectSoundDevice,
225 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE,
226 &support);
227 ok(rc==DS_OK, "QuerySupport(DSPROPSETID_DirectSoundDevice, "
228 "DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE) failed: %s\n",
229 DXGetErrorString8(rc));
230 if (rc!=DS_OK)
231 goto error;
233 ok(support & KSPROPERTY_SUPPORT_GET,
234 "Couldn't get DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE: "
235 "support = 0x%lx\n",support);
236 ok(!(support & KSPROPERTY_SUPPORT_SET),"Shouldn't be able to set "
237 "DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE: support = 0x%lx\n",support);
239 if (support & KSPROPERTY_SUPPORT_GET) {
240 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_DATA data;
241 ULONG bytes;
243 data.Callback = callback;
244 data.Context = 0;
246 rc = pps->lpVtbl->Get(pps, &DSPROPSETID_DirectSoundDevice,
247 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE,
248 NULL, 0, &data, sizeof(data), &bytes);
249 ok(rc==DS_OK, "Couldn't enumerate: 0x%lx\n",rc);
252 error:
253 FreeLibrary(hDsound);
256 static HWND get_hwnd()
258 HWND hwnd=GetForegroundWindow();
259 if (!hwnd)
260 hwnd=GetDesktopWindow();
261 return hwnd;
264 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
265 LPCSTR lpcstrModule, LPVOID lpContext)
267 HRESULT rc;
268 LPDIRECTSOUND dso=NULL;
269 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
270 DSBUFFERDESC bufdesc;
271 WAVEFORMATEX wfx;
272 int ref;
274 trace("*** Testing %s - %s ***\n",lpcstrDescription,lpcstrModule);
276 rc=DirectSoundCreate(lpGuid,&dso,NULL);
277 ok(rc==DS_OK,"DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
278 if (rc!=DS_OK)
279 goto EXIT;
281 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
282 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
283 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
284 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
285 DXGetErrorString8(rc));
286 if (rc!=DS_OK)
287 goto EXIT;
289 /* Testing 3D buffers */
290 primary=NULL;
291 ZeroMemory(&bufdesc, sizeof(bufdesc));
292 bufdesc.dwSize=sizeof(bufdesc);
293 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_LOCHARDWARE|DSBCAPS_CTRL3D;
294 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
295 ok(rc==DS_OK&&primary!=NULL,"IDirectSound_CreateSoundBuffer() failed to "
296 "create a hardware 3D primary buffer: %s\n",DXGetErrorString8(rc));
297 if (rc==DS_OK&&primary!=NULL) {
298 ZeroMemory(&wfx, sizeof(wfx));
299 wfx.wFormatTag=WAVE_FORMAT_PCM;
300 wfx.nChannels=1;
301 wfx.wBitsPerSample=16;
302 wfx.nSamplesPerSec=44100;
303 wfx.nBlockAlign=wfx.nChannels*wfx.wBitsPerSample/8;
304 wfx.nAvgBytesPerSec=wfx.nSamplesPerSec*wfx.nBlockAlign;
305 ZeroMemory(&bufdesc, sizeof(bufdesc));
306 bufdesc.dwSize=sizeof(bufdesc);
307 bufdesc.dwFlags=DSBCAPS_CTRLDEFAULT|DSBCAPS_GETCURRENTPOSITION2;
308 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec;
309 bufdesc.lpwfxFormat=&wfx;
310 trace(" Testing a secondary buffer at %ldx%dx%d\n",
311 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels);
312 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
313 ok(rc==DS_OK&&secondary!=NULL,"IDirectSound_CreateSoundBuffer() "
314 "failed to create a secondary buffer: %s\n",DXGetErrorString8(rc));
315 if (rc==DS_OK&&secondary!=NULL) {
316 IKsPropertySet * pPropertySet=NULL;
317 rc=IDirectSoundBuffer_QueryInterface(secondary,
318 &IID_IKsPropertySet,
319 (void **)&pPropertySet);
320 /* it's not an error for this to fail */
321 if(rc==DS_OK) {
322 ULONG ulTypeSupport;
323 trace(" Supports property sets\n");
324 /* it's not an error for these to fail */
325 rc=IKsPropertySet_QuerySupport(pPropertySet,
326 &DSPROPSETID_VoiceManager,
327 0,&ulTypeSupport);
328 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|
329 KSPROPERTY_SUPPORT_SET)))
330 trace(" DSPROPSETID_VoiceManager supported\n");
331 else
332 trace(" DSPROPSETID_VoiceManager not supported\n");
333 rc=IKsPropertySet_QuerySupport(pPropertySet,
334 &DSPROPSETID_EAX20_ListenerProperties,0,&ulTypeSupport);
335 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|
336 KSPROPERTY_SUPPORT_SET)))
337 trace(" DSPROPSETID_EAX20_ListenerProperties "
338 "supported\n");
339 else
340 trace(" DSPROPSETID_EAX20_ListenerProperties not "
341 "supported\n");
342 rc=IKsPropertySet_QuerySupport(pPropertySet,
343 &DSPROPSETID_EAX20_BufferProperties,0,&ulTypeSupport);
344 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|
345 KSPROPERTY_SUPPORT_SET)))
346 trace(" DSPROPSETID_EAX20_BufferProperties supported\n");
347 else
348 trace(" DSPROPSETID_EAX20_BufferProperties not "
349 "supported\n");
350 rc=IKsPropertySet_QuerySupport(pPropertySet,
351 &DSPROPSETID_I3DL2_ListenerProperties,0,&ulTypeSupport);
352 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|
353 KSPROPERTY_SUPPORT_SET)))
354 trace(" DSPROPSETID_I3DL2_ListenerProperties "
355 "supported\n");
356 else
357 trace(" DSPROPSETID_I3DL2_ListenerProperties not "
358 "supported\n");
359 rc=IKsPropertySet_QuerySupport(pPropertySet,
360 &DSPROPSETID_I3DL2_BufferProperties,0,&ulTypeSupport);
361 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|
362 KSPROPERTY_SUPPORT_SET)))
363 trace(" DSPROPSETID_I3DL2_BufferProperties supported\n");
364 else
365 trace(" DSPROPSETID_I3DL2_BufferProperties not "
366 "supported\n");
367 rc=IKsPropertySet_QuerySupport(pPropertySet,
368 &DSPROPSETID_ZOOMFX_BufferProperties,0,&ulTypeSupport);
369 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|
370 KSPROPERTY_SUPPORT_SET)))
371 trace(" DSPROPSETID_ZOOMFX_BufferProperties "
372 "supported\n");
373 else
374 trace(" DSPROPSETID_ZOOMFX_BufferProperties not "
375 "supported\n");
376 ref=IKsPropertySet_Release(pPropertySet);
377 /* try a few common ones */
378 ok(ref==0,"IKsPropertySet_Release() secondary has %d "
379 "references, should have 0\n",ref);
380 } else
381 trace(" Doesn't support property sets\n");
383 ref=IDirectSoundBuffer_Release(secondary);
384 ok(ref==0,"IDirectSoundBuffer_Release() secondary has %d "
385 "references, should have 0\n",ref);
388 ref=IDirectSoundBuffer_Release(primary);
389 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
390 "should have 0\n",ref);
393 EXIT:
394 if (dso!=NULL) {
395 ref=IDirectSound_Release(dso);
396 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",
397 ref);
399 return 1;
402 static void propset_buffer_tests()
404 HRESULT rc;
405 rc=DirectSoundEnumerateA(&dsenum_callback,NULL);
406 ok(rc==DS_OK,"DirectSoundEnumerateA() failed: %s\n",DXGetErrorString8(rc));
409 START_TEST(propset)
411 propset_private_tests();
412 propset_buffer_tests();