Fix tests for win9x and old versions of DirectX.
[wine/hacks.git] / dlls / dsound / tests / propset.c
blobe7c7d865cc3cef258b27798d5d153d471a83c5d6
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 "wine/test.h"
27 #include "dsound.h"
28 #include "initguid.h"
29 #include "dsconf.h"
30 #include "dxerr8.h"
32 #include "dsound_test.h"
34 #ifndef DSBCAPS_CTRLDEFAULT
35 #define DSBCAPS_CTRLDEFAULT \
36 DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLPAN|DSBCAPS_CTRLVOLUME
37 #endif
39 DEFINE_GUID(DSPROPSETID_VoiceManager, \
40 0x62A69BAE,0xDF9D,0x11D1,0x99,0xA6,0x00,0xC0,0x4F,0xC9,0x9D,0x46);
41 DEFINE_GUID(DSPROPSETID_EAX20_ListenerProperties, \
42 0x306a6a8,0xb224,0x11d2,0x99,0xe5,0x0,0x0,0xe8,0xd8,0xc7,0x22);
43 DEFINE_GUID(DSPROPSETID_EAX20_BufferProperties, \
44 0x306a6a7,0xb224,0x11d2,0x99,0xe5,0x0,0x0,0xe8,0xd8,0xc7,0x22);
45 DEFINE_GUID(DSPROPSETID_I3DL2_ListenerProperties, \
46 0xDA0F0520,0x300A,0x11D3,0x8A,0x2B,0x00,0x60,0x97,0x0D,0xB0,0x11);
47 DEFINE_GUID(DSPROPSETID_I3DL2_BufferProperties, \
48 0xDA0F0521,0x300A,0x11D3,0x8A,0x2B,0x00,0x60,0x97,0x0D,0xB0,0x11);
49 DEFINE_GUID(DSPROPSETID_ZOOMFX_BufferProperties, \
50 0xCD5368E0,0x3450,0x11D3,0x8B,0x6E,0x00,0x10,0x5A,0x9B,0x7B,0xBC);
52 typedef HRESULT (CALLBACK * MYPROC)(REFCLSID, REFIID, LPVOID *);
54 static HRESULT (WINAPI *pDirectSoundCreate8)(LPCGUID,LPDIRECTSOUND8*,
55 LPUNKNOWN)=NULL;
56 static HRESULT (WINAPI *pDirectSoundCaptureCreate)(LPCGUID,
57 LPDIRECTSOUNDCAPTURE*,LPUNKNOWN)=NULL;
58 static HRESULT (WINAPI *pDirectSoundCaptureCreate8)(LPCGUID,
59 LPDIRECTSOUNDCAPTURE8*,LPUNKNOWN)=NULL;
60 static HRESULT (WINAPI *pDirectSoundFullDuplexCreate)(LPCGUID,LPCGUID,
61 LPCDSCBUFFERDESC,LPCDSBUFFERDESC,HWND,DWORD,LPDIRECTSOUNDFULLDUPLEX*,
62 LPDIRECTSOUNDCAPTUREBUFFER8*,LPDIRECTSOUNDBUFFER8*,LPUNKNOWN)=NULL;
64 BOOL CALLBACK callback(PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_DATA data,
65 LPVOID context)
67 trace("found device:\n");
68 trace("\tType: %s\n",
69 data->Type == DIRECTSOUNDDEVICE_TYPE_EMULATED ? "Emulated" :
70 data->Type == DIRECTSOUNDDEVICE_TYPE_VXD ? "VxD" :
71 data->Type == DIRECTSOUNDDEVICE_TYPE_WDM ? "WDM" : "Unknown");
72 trace("\tDataFlow: %s\n",
73 data->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_RENDER ? "Render" :
74 data->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE ?
75 "Capture" : "Unknown");
76 trace("\tDeviceId: {%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n",
77 data->DeviceId.Data1,data->DeviceId.Data2,data->DeviceId.Data3,
78 data->DeviceId.Data4[0],data->DeviceId.Data4[1],
79 data->DeviceId.Data4[2],data->DeviceId.Data4[3],
80 data->DeviceId.Data4[4],data->DeviceId.Data4[5],
81 data->DeviceId.Data4[6],data->DeviceId.Data4[7]);
82 trace("\tDescription: %s\n", data->Description);
83 trace("\tModule: %s\n", data->Module);
84 trace("\tInterface: %s\n", data->Interface);
85 trace("\tWaveDeviceId: %ld\n", data->WaveDeviceId);
87 return TRUE;
90 static void propset_private_tests()
92 HMODULE hDsound;
93 HRESULT rc;
94 IClassFactory * pcf;
95 IKsPropertySet * pps;
96 MYPROC fProc;
97 ULONG support;
99 hDsound = LoadLibrary("dsound.dll");
100 ok(hDsound!=0,"LoadLibrary(dsound.dll) failed\n");
101 if (hDsound==0)
102 return;
104 fProc = (MYPROC)GetProcAddress(hDsound, "DllGetClassObject");
106 /* try direct sound first */
107 rc = (fProc)(&CLSID_DirectSound, &IID_IClassFactory, (void **)0);
108 ok(rc==DSERR_INVALIDPARAM,"DllGetClassObject(CLSID_DirectSound, "
109 "IID_IClassFactory) should have returned DSERR_INVALIDPARAM, "
110 "returned: %s\n",DXGetErrorString8(rc));
112 rc = (fProc)(&CLSID_DirectSound, &IID_IClassFactory, (void **)(&pcf));
113 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSound, IID_IClassFactory) "
114 "failed: %s\n",DXGetErrorString8(rc));
115 if (pcf==0)
116 goto error;
118 /* direct sound doesn't have an IKsPropertySet */
119 rc = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet,
120 (void **)0);
121 ok(rc==DSERR_INVALIDPARAM, "CreateInstance(IID_IKsPropertySet) should have "
122 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
124 rc = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet,
125 (void **)(&pps));
126 ok(rc==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have "
127 "returned E_NOINTERFACE, returned: %s\n",DXGetErrorString8(rc));
129 /* and the direct sound 8 version */
130 if (pDirectSoundCreate8) {
131 rc = (fProc)(&CLSID_DirectSound8, &IID_IClassFactory, (void **)(&pcf));
132 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSound8, IID_IClassFactory) "
133 "failed: %s\n",DXGetErrorString8(rc));
134 if (pcf==0)
135 goto error;
137 /* direct sound 8 doesn't have an IKsPropertySet */
138 rc = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet,
139 (void **)(&pps));
140 ok(rc==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have "
141 "returned E_NOINTERFACE, returned: %s\n",DXGetErrorString8(rc));
144 /* try direct sound capture next */
145 if (pDirectSoundCaptureCreate) {
146 rc = (fProc)(&CLSID_DirectSoundCapture, &IID_IClassFactory,
147 (void **)(&pcf));
148 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSoundCapture, IID_IClassFactory) "
149 "failed: %s\n",DXGetErrorString8(rc));
150 if (pcf==0)
151 goto error;
153 /* direct sound capture doesn't have an IKsPropertySet */
154 rc = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet,
155 (void **)(&pps));
156 ok(rc==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have "
157 "returned E_NOINTERFACE,returned: %s\n",DXGetErrorString8(rc));
160 /* and the direct sound capture 8 version */
161 if (pDirectSoundCaptureCreate8) {
162 rc = (fProc)(&CLSID_DirectSoundCapture8, &IID_IClassFactory,
163 (void **)(&pcf));
164 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSoundCapture8, "
165 "IID_IClassFactory) failed: %s\n",DXGetErrorString8(rc));
166 if (pcf==0)
167 goto error;
169 /* direct sound capture 8 doesn't have an IKsPropertySet */
170 rc = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet,
171 (void **)(&pps));
172 ok(rc==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have "
173 "returned E_NOINTERFACE, returned: %s\n",DXGetErrorString8(rc));
176 /* try direct sound full duplex next */
177 if (pDirectSoundFullDuplexCreate) {
178 rc = (fProc)(&CLSID_DirectSoundFullDuplex, &IID_IClassFactory,
179 (void **)(&pcf));
180 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSoundFullDuplex, "
181 "IID_IClassFactory) failed: %s\n",DXGetErrorString8(rc));
182 if (pcf==0)
183 goto error;
185 /* direct sound full duplex doesn't have an IKsPropertySet */
186 rc = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet,
187 (void **)(&pps));
188 ok(rc==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have "
189 "returned NOINTERFACE, returned: %s\n",DXGetErrorString8(rc));
192 /* try direct sound private last */
193 rc = (fProc)(&CLSID_DirectSoundPrivate, &IID_IClassFactory,
194 (void **)(&pcf));
195 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSoundPrivate, "
196 "IID_IClassFactory) failed: %s\n",DXGetErrorString8(rc));
197 if (pcf==0)
198 goto error;
200 /* direct sound private does have an IKsPropertySet */
201 rc = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet,
202 (void **)(&pps));
203 ok(rc==DS_OK, "CreateInstance(IID_IKsPropertySet) failed: %s\n",
204 DXGetErrorString8(rc));
205 if (rc!=DS_OK)
206 goto error;
208 rc = pps->lpVtbl->QuerySupport(pps, &DSPROPSETID_DirectSoundDevice,
209 DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION,
210 &support);
211 ok(rc==DS_OK||rc==E_INVALIDARG, "QuerySupport(DSPROPSETID_DirectSoundDevice, "
212 "DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION) failed: %s\n",
213 DXGetErrorString8(rc));
214 if (rc!=DS_OK) {
215 if (rc==E_INVALIDARG)
216 trace(" Not Supported\n");
217 goto error;
220 ok(support & KSPROPERTY_SUPPORT_GET,
221 "Couldn't get DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION: "
222 "support = 0x%lx\n",support);
223 ok(!(support & KSPROPERTY_SUPPORT_SET),
224 "Shouldn't be able to set DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION: "
225 "support = 0x%lx\n",support);
227 rc = pps->lpVtbl->QuerySupport(pps, &DSPROPSETID_DirectSoundDevice,
228 DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING, &support);
229 ok(rc==DS_OK, "QuerySupport(DSPROPSETID_DirectSoundDevice, "
230 "DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING) failed: %s\n",
231 DXGetErrorString8(rc));
232 if (rc!=DS_OK)
233 goto error;
235 ok(support & KSPROPERTY_SUPPORT_GET,
236 "Couldn't get DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING: "
237 "support = 0x%lx\n",support);
238 ok(!(support & KSPROPERTY_SUPPORT_SET), "Shouldn't be able to set "
239 "DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING: support = "
240 "0x%lx\n",support);
242 rc = pps->lpVtbl->QuerySupport(pps, &DSPROPSETID_DirectSoundDevice,
243 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE,
244 &support);
245 ok(rc==DS_OK, "QuerySupport(DSPROPSETID_DirectSoundDevice, "
246 "DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE) failed: %s\n",
247 DXGetErrorString8(rc));
248 if (rc!=DS_OK)
249 goto error;
251 ok(support & KSPROPERTY_SUPPORT_GET,
252 "Couldn't get DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE: "
253 "support = 0x%lx\n",support);
254 ok(!(support & KSPROPERTY_SUPPORT_SET),"Shouldn't be able to set "
255 "DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE: support = 0x%lx\n",support);
257 if (support & KSPROPERTY_SUPPORT_GET) {
258 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_DATA data;
259 ULONG bytes;
261 data.Callback = callback;
262 data.Context = 0;
264 rc = pps->lpVtbl->Get(pps, &DSPROPSETID_DirectSoundDevice,
265 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE,
266 NULL, 0, &data, sizeof(data), &bytes);
267 ok(rc==DS_OK, "Couldn't enumerate: 0x%lx\n",rc);
270 error:
271 FreeLibrary(hDsound);
274 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
275 LPCSTR lpcstrModule, LPVOID lpContext)
277 HRESULT rc;
278 LPDIRECTSOUND dso=NULL;
279 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
280 DSBUFFERDESC bufdesc;
281 WAVEFORMATEX wfx;
282 int ref;
284 trace("*** Testing %s - %s ***\n",lpcstrDescription,lpcstrModule);
286 rc=DirectSoundCreate(lpGuid,&dso,NULL);
287 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
288 "DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
289 if (rc!=DS_OK) {
290 if (rc==DSERR_NODRIVER)
291 trace(" No Driver\n");
292 else if (rc == DSERR_ALLOCATED)
293 trace(" Already In Use\n");
294 else if (rc == E_FAIL)
295 trace(" No Device\n");
296 goto EXIT;
299 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
300 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
301 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
302 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
303 DXGetErrorString8(rc));
304 if (rc!=DS_OK)
305 goto EXIT;
307 /* Testing 3D buffers */
308 primary=NULL;
309 ZeroMemory(&bufdesc, sizeof(bufdesc));
310 bufdesc.dwSize=sizeof(bufdesc);
311 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_LOCHARDWARE|DSBCAPS_CTRL3D;
312 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
313 ok(rc==DS_OK&&primary!=NULL,"IDirectSound_CreateSoundBuffer() failed to "
314 "create a hardware 3D primary buffer: %s\n",DXGetErrorString8(rc));
315 if (rc==DS_OK&&primary!=NULL) {
316 ZeroMemory(&wfx, sizeof(wfx));
317 wfx.wFormatTag=WAVE_FORMAT_PCM;
318 wfx.nChannels=1;
319 wfx.wBitsPerSample=16;
320 wfx.nSamplesPerSec=44100;
321 wfx.nBlockAlign=wfx.nChannels*wfx.wBitsPerSample/8;
322 wfx.nAvgBytesPerSec=wfx.nSamplesPerSec*wfx.nBlockAlign;
323 ZeroMemory(&bufdesc, sizeof(bufdesc));
324 bufdesc.dwSize=sizeof(bufdesc);
325 bufdesc.dwFlags=DSBCAPS_CTRLDEFAULT|DSBCAPS_GETCURRENTPOSITION2;
326 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec;
327 bufdesc.lpwfxFormat=&wfx;
328 trace(" Testing a secondary buffer at %ldx%dx%d\n",
329 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels);
330 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
331 ok(rc==DS_OK&&secondary!=NULL,"IDirectSound_CreateSoundBuffer() "
332 "failed to create a secondary buffer: %s\n",DXGetErrorString8(rc));
333 if (rc==DS_OK&&secondary!=NULL) {
334 IKsPropertySet * pPropertySet=NULL;
335 rc=IDirectSoundBuffer_QueryInterface(secondary,
336 &IID_IKsPropertySet,
337 (void **)&pPropertySet);
338 /* it's not an error for this to fail */
339 if(rc==DS_OK) {
340 ULONG ulTypeSupport;
341 trace(" Supports property sets\n");
342 /* it's not an error for these to fail */
343 rc=IKsPropertySet_QuerySupport(pPropertySet,
344 &DSPROPSETID_VoiceManager,
345 0,&ulTypeSupport);
346 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|
347 KSPROPERTY_SUPPORT_SET)))
348 trace(" DSPROPSETID_VoiceManager supported\n");
349 else
350 trace(" DSPROPSETID_VoiceManager not supported\n");
351 rc=IKsPropertySet_QuerySupport(pPropertySet,
352 &DSPROPSETID_EAX20_ListenerProperties,0,&ulTypeSupport);
353 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|
354 KSPROPERTY_SUPPORT_SET)))
355 trace(" DSPROPSETID_EAX20_ListenerProperties "
356 "supported\n");
357 else
358 trace(" DSPROPSETID_EAX20_ListenerProperties not "
359 "supported\n");
360 rc=IKsPropertySet_QuerySupport(pPropertySet,
361 &DSPROPSETID_EAX20_BufferProperties,0,&ulTypeSupport);
362 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|
363 KSPROPERTY_SUPPORT_SET)))
364 trace(" DSPROPSETID_EAX20_BufferProperties supported\n");
365 else
366 trace(" DSPROPSETID_EAX20_BufferProperties not "
367 "supported\n");
368 rc=IKsPropertySet_QuerySupport(pPropertySet,
369 &DSPROPSETID_I3DL2_ListenerProperties,0,&ulTypeSupport);
370 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|
371 KSPROPERTY_SUPPORT_SET)))
372 trace(" DSPROPSETID_I3DL2_ListenerProperties "
373 "supported\n");
374 else
375 trace(" DSPROPSETID_I3DL2_ListenerProperties not "
376 "supported\n");
377 rc=IKsPropertySet_QuerySupport(pPropertySet,
378 &DSPROPSETID_I3DL2_BufferProperties,0,&ulTypeSupport);
379 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|
380 KSPROPERTY_SUPPORT_SET)))
381 trace(" DSPROPSETID_I3DL2_BufferProperties supported\n");
382 else
383 trace(" DSPROPSETID_I3DL2_BufferProperties not "
384 "supported\n");
385 rc=IKsPropertySet_QuerySupport(pPropertySet,
386 &DSPROPSETID_ZOOMFX_BufferProperties,0,&ulTypeSupport);
387 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|
388 KSPROPERTY_SUPPORT_SET)))
389 trace(" DSPROPSETID_ZOOMFX_BufferProperties "
390 "supported\n");
391 else
392 trace(" DSPROPSETID_ZOOMFX_BufferProperties not "
393 "supported\n");
394 ref=IKsPropertySet_Release(pPropertySet);
395 /* try a few common ones */
396 ok(ref==0,"IKsPropertySet_Release() secondary has %d "
397 "references, should have 0\n",ref);
398 } else
399 trace(" Doesn't support property sets\n");
401 ref=IDirectSoundBuffer_Release(secondary);
402 ok(ref==0,"IDirectSoundBuffer_Release() secondary has %d "
403 "references, should have 0\n",ref);
406 ref=IDirectSoundBuffer_Release(primary);
407 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
408 "should have 0\n",ref);
411 EXIT:
412 if (dso!=NULL) {
413 ref=IDirectSound_Release(dso);
414 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",
415 ref);
417 return 1;
420 static void propset_buffer_tests()
422 HRESULT rc;
423 rc=DirectSoundEnumerateA(&dsenum_callback,NULL);
424 ok(rc==DS_OK,"DirectSoundEnumerateA() failed: %s\n",DXGetErrorString8(rc));
427 START_TEST(propset)
429 HMODULE hDsound;
431 CoInitialize(NULL);
433 hDsound = LoadLibraryA("dsound.dll");
434 if (!hDsound) {
435 trace("dsound.dll not found\n");
436 return;
439 pDirectSoundCreate8 = (void*)GetProcAddress(hDsound, "DirectSoundCreate8");
440 pDirectSoundCaptureCreate=(void*)GetProcAddress(hDsound,"DirectSoundCaptureCreate");
441 pDirectSoundCaptureCreate8=(void*)GetProcAddress(hDsound,"DirectSoundCaptureCreate8");
442 pDirectSoundFullDuplexCreate=(void*)GetProcAddress(hDsound,"DirectSoundFullDuplexCreate");
444 propset_private_tests();
445 propset_buffer_tests();
447 CoUninitialize();