Implement A->W call for GetNamedSecurityInfo.
[wine] / dlls / dsound / tests / propset.c
1 /*
2  * Unit tests for CLSID_DirectSoundPrivate property set functions (used by dxdiag)
3  *
4  * Copyright (c) 2003 Robert Reif
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #define NONAMELESSSTRUCT
22 #define NONAMELESSUNION
23 #include <windows.h>
24
25 #include <math.h>
26 #include <stdlib.h>
27
28 #include "wine/test.h"
29 #include "windef.h"
30 #include "wingdi.h"
31 #include "dsound.h"
32 #include "initguid.h"
33 #include "dsconf.h"
34
35 #ifndef DSBCAPS_CTRLDEFAULT
36 #define DSBCAPS_CTRLDEFAULT DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLPAN|DSBCAPS_CTRLVOLUME
37 #endif
38
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);
45
46 typedef HRESULT  (CALLBACK * MYPROC)(REFCLSID, REFIID, LPVOID *);
47
48 BOOL CALLBACK callback(PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_DATA data, LPVOID context)
49 {
50         trace("found device:\n");
51         trace("\tType: %s\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);
66
67         return TRUE;
68 }
69
70 static void propset_private_tests()
71 {
72         HMODULE hDsound;
73         HRESULT hr;
74         IClassFactory   * pcf;
75         IKsPropertySet  * pps;
76         MYPROC fProc;
77         ULONG   support;
78
79         hDsound = LoadLibrary("dsound.dll");
80         ok(hDsound!=0,"LoadLibrary(dsound.dll) failed\n");
81         if (hDsound==0)
82                 return;
83
84         fProc = (MYPROC)GetProcAddress(hDsound, "DllGetClassObject");
85
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);
89
90         hr = (fProc)(&CLSID_DirectSound, &IID_IClassFactory, (void **)(&pcf));
91         ok(pcf!=0, "DllGetClassObject(CLSID_DirectSound, IID_IClassFactory) failed: 0x%lx\n",hr);
92         if (pcf==0)
93                 goto error;
94
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);
98
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);
101
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);
105         if (pcf==0)
106                 goto error;
107
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);
111
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);
115         if (pcf==0)
116                 goto error;
117
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);
121
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);
125         if (pcf==0)
126                 goto error;
127
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);
131
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);
135         if (pcf==0)
136                 goto error;
137
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);
141
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);
145         if (pcf==0)
146                 goto error;
147
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);
151         if (hr!=DS_OK)
152                 goto error;
153
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);
156         if (hr!=DS_OK)
157                 goto error;
158
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);
161
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);
164         if (hr!=DS_OK)
165                 goto error;
166
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);
169
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);
172         if (hr!=DS_OK)
173                 goto error;
174
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);
177
178         if (support & KSPROPERTY_SUPPORT_GET)
179         {
180                 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_DATA data;
181                 ULONG bytes;
182
183                 data.Callback = callback;
184                 data.Context = 0;
185
186                 hr = pps->lpVtbl->Get(pps, &DSPROPSETID_DirectSoundDevice, 
187                                           DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE,
188                                           NULL,
189                                           0,
190                                           &data, 
191                                           sizeof(data), 
192                                           &bytes);
193                 ok(hr==DS_OK, "Couldn't enumerate: 0x%lx\n",hr);
194         }
195
196 error:
197         FreeLibrary(hDsound);
198 }
199
200 static HWND get_hwnd()
201 {
202     HWND hwnd=GetForegroundWindow();
203     if (!hwnd)
204         hwnd=GetDesktopWindow();
205     return hwnd;
206 }
207                                                                                 
208 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
209                                    LPCSTR lpcstrModule, LPVOID lpContext)
210 {
211     HRESULT rc;
212     LPDIRECTSOUND dso=NULL;
213     LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
214     DSBUFFERDESC bufdesc;
215     WAVEFORMATEX wfx;
216     int ref;
217                                                                                 
218     rc=DirectSoundCreate(lpGuid,&dso,NULL);
219     ok(rc==DS_OK,"DirectSoundCreate failed: 0x%lx\n",rc);
220     if (rc!=DS_OK)
221         goto EXIT;
222
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);
227     if (rc!=DS_OK)
228         goto EXIT;
229                                                                                 
230     /* Testing 3D buffers */
231     primary=NULL;
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;
240         wfx.nChannels=1;
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 */
258             if(rc==DS_OK) {
259                 ULONG ulTypeSupport;
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");
265                 else
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");
270                 else
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");
275                 else
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");
280                 else
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");
285                 else
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");
290                 else
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);
295             } else
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);
299         }
300  
301         ref=IDirectSoundBuffer_Release(primary);
302         ok(ref==0,"IDirectSoundBuffer_Release primary has %d references, should have 0\n",ref);
303     }
304  
305 EXIT:
306     if (dso!=NULL) {
307         ref=IDirectSound_Release(dso);
308         ok(ref==0,"IDirectSound_Release has %d references, should have 0\n",ref);
309     }
310     return 1;
311 }
312  
313 static void propset_buffer_tests()
314 {
315     HRESULT rc;
316     rc=DirectSoundEnumerateA(&dsenum_callback,NULL);
317     ok(rc==DS_OK,"DirectSoundEnumerate failed: %ld\n",rc);
318 }
319
320 START_TEST(propset)
321 {
322     propset_private_tests();
323     propset_buffer_tests();
324 }