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"
35 #ifndef DSBCAPS_CTRLDEFAULT
36 #define DSBCAPS_CTRLDEFAULT DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLPAN|DSBCAPS_CTRLVOLUME
39 DEFINE_GUID(DSPROPSETID_VoiceManager,0x62A69BAE,0xDF9D,0x11D1,0x99,0xA6,0x00,0xC0,0x4F,0xC9,0x9D,0x46);
40 DEFINE_GUID(DSPROPSETID_EAX20_ListenerProperties,0x306a6a8,0xb224,0x11d2,0x99,0xe5,0x0,0x0,0xe8,0xd8,0xc7,0x22);
41 DEFINE_GUID(DSPROPSETID_EAX20_BufferProperties,0x306a6a7,0xb224,0x11d2,0x99,0xe5,0x0,0x0,0xe8,0xd8,0xc7,0x22);
42 DEFINE_GUID(DSPROPSETID_I3DL2_ListenerProperties,0xDA0F0520,0x300A,0x11D3,0x8A,0x2B,0x00,0x60,0x97,0x0D,0xB0,0x11);
43 DEFINE_GUID(DSPROPSETID_I3DL2_BufferProperties,0xDA0F0521,0x300A,0x11D3,0x8A,0x2B,0x00,0x60,0x97,0x0D,0xB0,0x11);
44 DEFINE_GUID(DSPROPSETID_ZOOMFX_BufferProperties,0xCD5368E0,0x3450,0x11D3,0x8B,0x6E,0x00,0x10,0x5A,0x9B,0x7B,0xBC);
46 typedef HRESULT (CALLBACK * MYPROC)(REFCLSID, REFIID, LPVOID *);
48 BOOL CALLBACK callback(PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_DATA data, LPVOID context)
50 trace("found device:\n");
52 data->Type == DIRECTSOUNDDEVICE_TYPE_EMULATED ? "Emulated" :
53 data->Type == DIRECTSOUNDDEVICE_TYPE_VXD ? "VxD" :
54 data->Type == DIRECTSOUNDDEVICE_TYPE_WDM ? "WDM" : "Unknown");
55 trace("\tDataFlow: %s\n",
56 data->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_RENDER ? "Render" :
57 data->DataFlow == DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE ? "Capture" : "Unknown");
58 trace("\tDeviceId: {%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n",
59 data->DeviceId.Data1,data->DeviceId.Data2,data->DeviceId.Data3,
60 data->DeviceId.Data4[0],data->DeviceId.Data4[1],data->DeviceId.Data4[2],data->DeviceId.Data4[3],
61 data->DeviceId.Data4[4],data->DeviceId.Data4[5],data->DeviceId.Data4[6],data->DeviceId.Data4[7]);
62 trace("\tDescription: %s\n", data->Description);
63 trace("\tModule: %s\n", data->Module);
64 trace("\tInterface: %s\n", data->Interface);
65 trace("\tWaveDeviceId: %ld\n", data->WaveDeviceId);
70 static void propset_private_tests()
79 hDsound = LoadLibrary("dsound.dll");
80 ok(hDsound!=0,"LoadLibrary(dsound.dll) failed\n");
84 fProc = (MYPROC)GetProcAddress(hDsound, "DllGetClassObject");
86 /* try direct sound first */
87 hr = (fProc)(&CLSID_DirectSound, &IID_IClassFactory, (void **)0);
88 ok(hr==DSERR_INVALIDPARAM,"DllGetClassObject(CLSID_DirectSound, IID_IClassFactory) should have failed: 0x%lx\n",hr);
90 hr = (fProc)(&CLSID_DirectSound, &IID_IClassFactory, (void **)(&pcf));
91 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSound, IID_IClassFactory) failed: 0x%lx\n",hr);
95 /* direct sound doesn't have an IKsPropertySet */
96 hr = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet, (void **)0);
97 ok(hr==DSERR_INVALIDPARAM, "CreateInstance(IID_IKsPropertySet) should have failed: 0x%lx\n",hr);
99 hr = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet, (void **)(&pps));
100 ok(hr==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have failed: 0x%lx\n",hr);
102 /* and the direct sound 8 version */
103 hr = (fProc)(&CLSID_DirectSound8, &IID_IClassFactory, (void **)(&pcf));
104 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSound8, IID_IClassFactory) failed: 0x%lx\n",hr);
108 /* direct sound 8 doesn't have an IKsPropertySet */
109 hr = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet, (void **)(&pps));
110 ok(hr==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have failed: 0x%lx\n",hr);
112 /* try direct sound capture next */
113 hr = (fProc)(&CLSID_DirectSoundCapture, &IID_IClassFactory, (void **)(&pcf));
114 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSoundCapture, IID_IClassFactory) failed: 0x%lx\n",hr);
118 /* direct sound capture doesn't have an IKsPropertySet */
119 hr = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet, (void **)(&pps));
120 ok(hr==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have failed: 0x%lx\n",hr);
122 /* and the direct sound capture 8 version */
123 hr = (fProc)(&CLSID_DirectSoundCapture8, &IID_IClassFactory, (void **)(&pcf));
124 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSoundCapture8, IID_IClassFactory) failed: 0x%lx\n",hr);
128 /* direct sound capture 8 doesn't have an IKsPropertySet */
129 hr = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet, (void **)(&pps));
130 ok(hr==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have failed: 0x%lx\n",hr);
132 /* try direct sound full duplex next */
133 hr = (fProc)(&CLSID_DirectSoundFullDuplex, &IID_IClassFactory, (void **)(&pcf));
134 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSoundFullDuplex, IID_IClassFactory) failed: 0x%lx\n",hr);
138 /* direct sound full duplex doesn't have an IKsPropertySet */
139 hr = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet, (void **)(&pps));
140 ok(hr==E_NOINTERFACE, "CreateInstance(IID_IKsPropertySet) should have failed: 0x%lx\n",hr);
142 /* try direct sound private last */
143 hr = (fProc)(&CLSID_DirectSoundPrivate, &IID_IClassFactory, (void **)(&pcf));
144 ok(pcf!=0, "DllGetClassObject(CLSID_DirectSoundPrivate, IID_IClassFactory) failed: 0x%lx\n",hr);
148 /* direct sound private does have an IKsPropertySet */
149 hr = pcf->lpVtbl->CreateInstance(pcf, NULL, &IID_IKsPropertySet, (void **)(&pps));
150 ok(hr==DS_OK, "CreateInstance(IID_IKsPropertySet) failed: 0x%lx\n",hr);
154 hr = pps->lpVtbl->QuerySupport(pps, &DSPROPSETID_DirectSoundDevice, DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION, &support);
155 ok(hr==DS_OK, "QuerySupport(DSPROPSETID_DirectSoundDevice, DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION) failed: 0x%lx\n",hr);
159 ok (support & KSPROPERTY_SUPPORT_GET, "Couldn't get DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION: support = 0x%lx\n",support);
160 ok (!(support & KSPROPERTY_SUPPORT_SET), "Shouldn't be able to set DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION: support = 0x%lx\n",support);
162 hr = pps->lpVtbl->QuerySupport(pps, &DSPROPSETID_DirectSoundDevice, DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING, &support);
163 ok(hr==DS_OK, "QuerySupport(DSPROPSETID_DirectSoundDevice, DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING) failed: 0x%lx\n",hr);
167 ok (support & KSPROPERTY_SUPPORT_GET, "Couldn't get DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING: support = 0x%lx\n",support);
168 ok (!(support & KSPROPERTY_SUPPORT_SET), "Shouldn't be able to set DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING: support = 0x%lx\n",support);
170 hr = pps->lpVtbl->QuerySupport(pps, &DSPROPSETID_DirectSoundDevice, DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE, &support);
171 ok(hr==DS_OK, "QuerySupport(DSPROPSETID_DirectSoundDevice, DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE) failed: 0x%lx\n",hr);
175 ok (support & KSPROPERTY_SUPPORT_GET, "Couldn't get DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE: support = 0x%lx\n",support);
176 ok (!(support & KSPROPERTY_SUPPORT_SET), "Shouldn't be able to set DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE: support = 0x%lx\n",support);
178 if (support & KSPROPERTY_SUPPORT_GET)
180 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_DATA data;
183 data.Callback = callback;
186 hr = pps->lpVtbl->Get(pps, &DSPROPSETID_DirectSoundDevice,
187 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE,
193 ok(hr==DS_OK, "Couldn't enumerate: 0x%lx\n",hr);
197 FreeLibrary(hDsound);
200 static HWND get_hwnd()
202 HWND hwnd=GetForegroundWindow();
204 hwnd=GetDesktopWindow();
208 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
209 LPCSTR lpcstrModule, LPVOID lpContext)
212 LPDIRECTSOUND dso=NULL;
213 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
214 DSBUFFERDESC bufdesc;
218 rc=DirectSoundCreate(lpGuid,&dso,NULL);
219 ok(rc==DS_OK,"DirectSoundCreate failed: 0x%lx\n",rc);
223 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
224 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
225 rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
226 ok(rc==DS_OK,"SetCooperativeLevel failed: 0x%lx\n",rc);
230 /* Testing 3D buffers */
232 ZeroMemory(&bufdesc, sizeof(bufdesc));
233 bufdesc.dwSize=sizeof(bufdesc);
234 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_LOCHARDWARE|DSBCAPS_CTRL3D;
235 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
236 ok(rc==DS_OK&&primary!=NULL,"CreateSoundBuffer failed to create a hardware 3D primary buffer: 0x%lx\n",rc);
237 if (rc==DS_OK&&primary!=NULL) {
238 ZeroMemory(&wfx, sizeof(wfx));
239 wfx.wFormatTag=WAVE_FORMAT_PCM;
241 wfx.wBitsPerSample=16;
242 wfx.nSamplesPerSec=44100;
243 wfx.nBlockAlign=wfx.nChannels*wfx.wBitsPerSample/8;
244 wfx.nAvgBytesPerSec=wfx.nSamplesPerSec*wfx.nBlockAlign;
245 ZeroMemory(&bufdesc, sizeof(bufdesc));
246 bufdesc.dwSize=sizeof(bufdesc);
247 bufdesc.dwFlags=DSBCAPS_CTRLDEFAULT|DSBCAPS_GETCURRENTPOSITION2;
248 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec;
249 bufdesc.lpwfxFormat=&wfx;
250 trace(" Testing a secondary buffer at %ldx%dx%d\n",
251 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels);
252 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
253 ok(rc==DS_OK&&secondary!=NULL,"CreateSoundBuffer failed to create a secondary buffer 0x%lx\n",rc);
254 if (rc==DS_OK&&secondary!=NULL) {
255 IKsPropertySet * pPropertySet=NULL;
256 rc=IDirectSoundBuffer_QueryInterface(secondary,&IID_IKsPropertySet,(void **)&pPropertySet);
257 /* it's not an error for this to fail */
260 trace(" Supports property sets\n");
261 /* it's not an error for these to fail */
262 rc=IKsPropertySet_QuerySupport(pPropertySet,&DSPROPSETID_VoiceManager,0,&ulTypeSupport);
263 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|KSPROPERTY_SUPPORT_SET)))
264 trace(" DSPROPSETID_VoiceManager supported\n");
266 trace(" DSPROPSETID_VoiceManager not supported\n");
267 rc=IKsPropertySet_QuerySupport(pPropertySet,&DSPROPSETID_EAX20_ListenerProperties,0,&ulTypeSupport);
268 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|KSPROPERTY_SUPPORT_SET)))
269 trace(" DSPROPSETID_EAX20_ListenerProperties supported\n");
271 trace(" DSPROPSETID_EAX20_ListenerProperties not supported\n");
272 rc=IKsPropertySet_QuerySupport(pPropertySet,&DSPROPSETID_EAX20_BufferProperties,0,&ulTypeSupport);
273 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|KSPROPERTY_SUPPORT_SET)))
274 trace(" DSPROPSETID_EAX20_BufferProperties supported\n");
276 trace(" DSPROPSETID_EAX20_BufferProperties not supported\n");
277 rc=IKsPropertySet_QuerySupport(pPropertySet,&DSPROPSETID_I3DL2_ListenerProperties,0,&ulTypeSupport);
278 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|KSPROPERTY_SUPPORT_SET)))
279 trace(" DSPROPSETID_I3DL2_ListenerProperties supported\n");
281 trace(" DSPROPSETID_I3DL2_ListenerProperties not supported\n");
282 rc=IKsPropertySet_QuerySupport(pPropertySet,&DSPROPSETID_I3DL2_BufferProperties,0,&ulTypeSupport);
283 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|KSPROPERTY_SUPPORT_SET)))
284 trace(" DSPROPSETID_I3DL2_BufferProperties supported\n");
286 trace(" DSPROPSETID_I3DL2_BufferProperties not supported\n");
287 rc=IKsPropertySet_QuerySupport(pPropertySet,&DSPROPSETID_ZOOMFX_BufferProperties,0,&ulTypeSupport);
288 if((rc==DS_OK)&&(ulTypeSupport&(KSPROPERTY_SUPPORT_GET|KSPROPERTY_SUPPORT_SET)))
289 trace(" DSPROPSETID_ZOOMFX_BufferProperties supported\n");
291 trace(" DSPROPSETID_ZOOMFX_BufferProperties not supported\n");
292 ref=IKsPropertySet_Release(pPropertySet);
293 /* try a few common ones */
294 ok(ref==0,"IKsPropertySet_Release secondary has %d references, should have 0\n",ref);
296 trace(" Doesn't support property sets\n");
297 ref=IDirectSoundBuffer_Release(secondary);
298 ok(ref==0,"IDirectSoundBuffer_Release secondary has %d references, should have 0\n",ref);
301 ref=IDirectSoundBuffer_Release(primary);
302 ok(ref==0,"IDirectSoundBuffer_Release primary has %d references, should have 0\n",ref);
307 ref=IDirectSound_Release(dso);
308 ok(ref==0,"IDirectSound_Release has %d references, should have 0\n",ref);
313 static void propset_buffer_tests()
316 rc=DirectSoundEnumerateA(&dsenum_callback,NULL);
317 ok(rc==DS_OK,"DirectSoundEnumerate failed: %ld\n",rc);
322 propset_private_tests();
323 propset_buffer_tests();