2 * Unit tests for CLSID_DirectSoundPrivate property set functions (used by dxdiag)
4 * Copyright (c) 2003 Robert Reif
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #define NONAMELESSSTRUCT
22 #define NONAMELESSUNION
28 #include "wine/test.h"
36 #ifndef DSBCAPS_CTRLDEFAULT
37 #define DSBCAPS_CTRLDEFAULT DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLPAN|DSBCAPS_CTRLVOLUME
40 DEFINE_GUID(DSPROPSETID_VoiceManager,0x62A69BAE,0xDF9D,0x11D1,0x99,0xA6,0x00,0xC0,0x4F,0xC9,0x9D,0x46);
41 DEFINE_GUID(DSPROPSETID_EAX20_ListenerProperties,0x306a6a8,0xb224,0x11d2,0x99,0xe5,0x0,0x0,0xe8,0xd8,0xc7,0x22);
42 DEFINE_GUID(DSPROPSETID_EAX20_BufferProperties,0x306a6a7,0xb224,0x11d2,0x99,0xe5,0x0,0x0,0xe8,0xd8,0xc7,0x22);
43 DEFINE_GUID(DSPROPSETID_I3DL2_ListenerProperties,0xDA0F0520,0x300A,0x11D3,0x8A,0x2B,0x00,0x60,0x97,0x0D,0xB0,0x11);
44 DEFINE_GUID(DSPROPSETID_I3DL2_BufferProperties,0xDA0F0521,0x300A,0x11D3,0x8A,0x2B,0x00,0x60,0x97,0x0D,0xB0,0x11);
45 DEFINE_GUID(DSPROPSETID_ZOOMFX_BufferProperties,0xCD5368E0,0x3450,0x11D3,0x8B,0x6E,0x00,0x10,0x5A,0x9B,0x7B,0xBC);
47 typedef HRESULT (CALLBACK * MYPROC)(REFCLSID, REFIID, LPVOID *);
49 BOOL CALLBACK callback(PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_DATA data, LPVOID context)
51 trace("found device:\n");
53 data->Type == DIRECTSOUNDDEVICE_TYPE_EMULATED ? "Emulated" :
54 data->Type == DIRECTSOUNDDEVICE_TYPE_VXD ? "VxD" :
55 data->Type == DIRECTSOUNDDEVICE_TYPE_WDM ? "WDM" : "Unknown");
56 trace("\tDataFlow: %s\n",
57 data->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_RENDER ? "Render" :
58 data->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE ? "Capture" : "Unknown");
59 trace("\tDeviceId: {%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n",
60 data->DeviceId.Data1,data->DeviceId.Data2,data->DeviceId.Data3,
61 data->DeviceId.Data4[0],data->DeviceId.Data4[1],data->DeviceId.Data4[2],data->DeviceId.Data4[3],
62 data->DeviceId.Data4[4],data->DeviceId.Data4[5],data->DeviceId.Data4[6],data->DeviceId.Data4[7]);
63 trace("\tDescription: %s\n", data->Description);
64 trace("\tModule: %s\n", data->Module);
65 trace("\tInterface: %s\n", data->Interface);
66 trace("\tWaveDeviceId: %ld\n", data->WaveDeviceId);
71 static void propset_private_tests()
80 hDsound = LoadLibrary("dsound.dll");
81 ok(hDsound!=0,"LoadLibrary(dsound.dll) failed\n");
85 fProc = (MYPROC)GetProcAddress(hDsound, "DllGetClassObject");
87 /* try direct sound first */
88 hr = (fProc)(&CLSID_DirectSound, &IID_IClassFactory, (void **)0);
89 ok(hr==DSERR_INVALIDPARAM,"DllGetClassObject(CLSID_DirectSound, IID_IClassFactory) should have failed: 0x%lx\n",hr);
91 hr = (fProc)(&CLSID_DirectSound, &IID_IClassFactory, (void **)(&pcf));
92 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSound, IID_IClassFactory) failed: 0x%lx\n",hr);
96 /* direct sound doesn't have an IKsPropertySet */
97 hr = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet, (void **)0);
98 ok(hr==DSERR_INVALIDPARAM, "CreateInstance(IID_IKsPropertySet) should have failed: 0x%lx\n",hr);
100 hr = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet, (void **)(&pps));
101 ok(hr==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have failed: 0x%lx\n",hr);
103 /* and the direct sound 8 version */
104 hr = (fProc)(&CLSID_DirectSound8, &IID_IClassFactory, (void **)(&pcf));
105 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSound8, IID_IClassFactory) failed: 0x%lx\n",hr);
109 /* direct sound 8 doesn't have an IKsPropertySet */
110 hr = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet, (void **)(&pps));
111 ok(hr==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have failed: 0x%lx\n",hr);
113 /* try direct sound capture next */
114 hr = (fProc)(&CLSID_DirectSoundCapture, &IID_IClassFactory, (void **)(&pcf));
115 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSoundCapture, IID_IClassFactory) failed: 0x%lx\n",hr);
119 /* direct sound capture doesn't have an IKsPropertySet */
120 hr = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet, (void **)(&pps));
121 ok(hr==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have failed: 0x%lx\n",hr);
123 /* and the direct sound capture 8 version */
124 hr = (fProc)(&CLSID_DirectSoundCapture8, &IID_IClassFactory, (void **)(&pcf));
125 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSoundCapture8, IID_IClassFactory) failed: 0x%lx\n",hr);
129 /* direct sound capture 8 doesn't have an IKsPropertySet */
130 hr = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet, (void **)(&pps));
131 ok(hr==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have failed: 0x%lx\n",hr);
133 /* try direct sound full duplex next */
134 hr = (fProc)(&CLSID_DirectSoundFullDuplex, &IID_IClassFactory, (void **)(&pcf));
135 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSoundFullDuplex, IID_IClassFactory) failed: 0x%lx\n",hr);
139 /* direct sound full duplex doesn't have an IKsPropertySet */
140 hr = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet, (void **)(&pps));
141 ok(hr==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have failed: 0x%lx\n",hr);
143 /* try direct sound private last */
144 hr = (fProc)(&CLSID_DirectSoundPrivate, &IID_IClassFactory, (void **)(&pcf));
145 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSoundPrivate, IID_IClassFactory) failed: 0x%lx\n",hr);
149 /* direct sound private does have an IKsPropertySet */
150 hr = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet, (void **)(&pps));
151 ok(hr==DS_OK, "CreateInstance(IID_IKsPropertySet) failed: 0x%lx\n",hr);
155 hr = pps->lpVtbl->QuerySupport(pps, &DSPROPSETID_DirectSoundDevice, DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION, &support);
156 ok(hr==DS_OK, "QuerySupport(DSPROPSETID_DirectSoundDevice, DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION) failed: 0x%lx\n",hr);
160 ok (support & KSPROPERTY_SUPPORT_GET, "Couldn't get DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION: support = 0x%lx\n",support);
161 ok (!(support & KSPROPERTY_SUPPORT_SET), "Shouldn't be able to set DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION: support = 0x%lx\n",support);
163 hr = pps->lpVtbl->QuerySupport(pps, &DSPROPSETID_DirectSoundDevice, DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING, &support);
164 ok(hr==DS_OK, "QuerySupport(DSPROPSETID_DirectSoundDevice, DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING) failed: 0x%lx\n",hr);
168 ok (support & KSPROPERTY_SUPPORT_GET, "Couldn't get DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING: support = 0x%lx\n",support);
169 ok (!(support & KSPROPERTY_SUPPORT_SET), "Shouldn't be able to set DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING: support = 0x%lx\n",support);
171 hr = pps->lpVtbl->QuerySupport(pps, &DSPROPSETID_DirectSoundDevice, DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE, &support);
172 ok(hr==DS_OK, "QuerySupport(DSPROPSETID_DirectSoundDevice, DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE) failed: 0x%lx\n",hr);
176 ok (support & KSPROPERTY_SUPPORT_GET, "Couldn't get DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE: support = 0x%lx\n",support);
177 ok (!(support & KSPROPERTY_SUPPORT_SET), "Shouldn't be able to set DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE: support = 0x%lx\n",support);
179 if (support & KSPROPERTY_SUPPORT_GET)
181 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_DATA data;
184 data.Callback = callback;
187 hr = pps->lpVtbl->Get(pps, &DSPROPSETID_DirectSoundDevice,
188 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE,
194 ok(hr==DS_OK, "Couldn't enumerate: 0x%lx\n",hr);
198 FreeLibrary(hDsound);
201 static HWND get_hwnd()
203 HWND hwnd=GetForegroundWindow();
205 hwnd=GetDesktopWindow();
209 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
210 LPCSTR lpcstrModule, LPVOID lpContext)
213 LPDIRECTSOUND dso=NULL;
214 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
215 DSBUFFERDESC bufdesc;
219 rc=DirectSoundCreate(lpGuid,&dso,NULL);
220 ok(rc==DS_OK,"DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
224 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
225 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
226 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
227 ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",DXGetErrorString8(rc));
231 /* Testing 3D buffers */
233 ZeroMemory(&bufdesc, sizeof(bufdesc));
234 bufdesc.dwSize=sizeof(bufdesc);
235 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_LOCHARDWARE|DSBCAPS_CTRL3D;
236 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
237 ok(rc==DS_OK&&primary!=NULL,"IDirectSound_CreateSoundBuffer() failed to create a hardware 3D primary buffer: %s\n",DXGetErrorString8(rc));
238 if (rc==DS_OK&&primary!=NULL) {
239 ZeroMemory(&wfx, sizeof(wfx));
240 wfx.wFormatTag=WAVE_FORMAT_PCM;
242 wfx.wBitsPerSample=16;
243 wfx.nSamplesPerSec=44100;
244 wfx.nBlockAlign=wfx.nChannels*wfx.wBitsPerSample/8;
245 wfx.nAvgBytesPerSec=wfx.nSamplesPerSec*wfx.nBlockAlign;
246 ZeroMemory(&bufdesc, sizeof(bufdesc));
247 bufdesc.dwSize=sizeof(bufdesc);
248 bufdesc.dwFlags=DSBCAPS_CTRLDEFAULT|DSBCAPS_GETCURRENTPOSITION2;
249 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec;
250 bufdesc.lpwfxFormat=&wfx;
251 trace(" Testing a secondary buffer at %ldx%dx%d\n",
252 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels);
253 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
254 ok(rc==DS_OK&&secondary!=NULL,"IDirectSound_CreateSoundBuffer() failed to create a secondary buffer %s\n",DXGetErrorString8(rc));
255 if (rc==DS_OK&&secondary!=NULL) {
256 IKsPropertySet * pPropertySet=NULL;
257 rc=IDirectSoundBuffer_QueryInterface(secondary,&IID_IKsPropertySet,(void **)&pPropertySet);
258 /* it's not an error for this to fail */
261 trace(" Supports property sets\n");
262 /* it's not an error for these to fail */
263 rc=IKsPropertySet_QuerySupport(pPropertySet,&DSPROPSETID_VoiceManager,0,&ulTypeSupport);
264 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|KSPROPERTY_SUPPORT_SET)))
265 trace(" DSPROPSETID_VoiceManager supported\n");
267 trace(" DSPROPSETID_VoiceManager not supported\n");
268 rc=IKsPropertySet_QuerySupport(pPropertySet,&DSPROPSETID_EAX20_ListenerProperties,0,&ulTypeSupport);
269 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|KSPROPERTY_SUPPORT_SET)))
270 trace(" DSPROPSETID_EAX20_ListenerProperties supported\n");
272 trace(" DSPROPSETID_EAX20_ListenerProperties not supported\n");
273 rc=IKsPropertySet_QuerySupport(pPropertySet,&DSPROPSETID_EAX20_BufferProperties,0,&ulTypeSupport);
274 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|KSPROPERTY_SUPPORT_SET)))
275 trace(" DSPROPSETID_EAX20_BufferProperties supported\n");
277 trace(" DSPROPSETID_EAX20_BufferProperties not supported\n");
278 rc=IKsPropertySet_QuerySupport(pPropertySet,&DSPROPSETID_I3DL2_ListenerProperties,0,&ulTypeSupport);
279 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|KSPROPERTY_SUPPORT_SET)))
280 trace(" DSPROPSETID_I3DL2_ListenerProperties supported\n");
282 trace(" DSPROPSETID_I3DL2_ListenerProperties not supported\n");
283 rc=IKsPropertySet_QuerySupport(pPropertySet,&DSPROPSETID_I3DL2_BufferProperties,0,&ulTypeSupport);
284 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|KSPROPERTY_SUPPORT_SET)))
285 trace(" DSPROPSETID_I3DL2_BufferProperties supported\n");
287 trace(" DSPROPSETID_I3DL2_BufferProperties not supported\n");
288 rc=IKsPropertySet_QuerySupport(pPropertySet,&DSPROPSETID_ZOOMFX_BufferProperties,0,&ulTypeSupport);
289 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|KSPROPERTY_SUPPORT_SET)))
290 trace(" DSPROPSETID_ZOOMFX_BufferProperties supported\n");
292 trace(" DSPROPSETID_ZOOMFX_BufferProperties not supported\n");
293 ref=IKsPropertySet_Release(pPropertySet);
294 /* try a few common ones */
295 ok(ref==0,"IKsPropertySet_Release() secondary has %d references, should have 0\n",ref);
297 trace(" Doesn't support property sets\n");
298 ref=IDirectSoundBuffer_Release(secondary);
299 ok(ref==0,"IDirectSoundBuffer_Release() secondary has %d references, should have 0\n",ref);
302 ref=IDirectSoundBuffer_Release(primary);
303 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, should have 0\n",ref);
308 ref=IDirectSound_Release(dso);
309 ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
314 static void propset_buffer_tests()
317 rc=DirectSoundEnumerateA(&dsenum_callback,NULL);
318 ok(rc==DS_OK,"DirectSoundEnumerateA() failed: %s\n",DXGetErrorString8(rc));
323 propset_private_tests();
324 propset_buffer_tests();