Declaration, implemention and test for BuildTrusteeWithSid.
[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 #include "dxerr8.h"
35
36 #ifndef DSBCAPS_CTRLDEFAULT
37 #define DSBCAPS_CTRLDEFAULT DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLPAN|DSBCAPS_CTRLVOLUME
38 #endif
39
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);
46
47 typedef HRESULT  (CALLBACK * MYPROC)(REFCLSID, REFIID, LPVOID *);
48
49 BOOL CALLBACK callback(PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_DATA data, LPVOID context)
50 {
51         trace("found device:\n");
52         trace("\tType: %s\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);
67
68         return TRUE;
69 }
70
71 static void propset_private_tests()
72 {
73         HMODULE hDsound;
74         HRESULT hr;
75         IClassFactory   * pcf;
76         IKsPropertySet  * pps;
77         MYPROC fProc;
78         ULONG   support;
79
80         hDsound = LoadLibrary("dsound.dll");
81         ok(hDsound!=0,"LoadLibrary(dsound.dll) failed\n");
82         if (hDsound==0)
83                 return;
84
85         fProc = (MYPROC)GetProcAddress(hDsound, "DllGetClassObject");
86
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);
90
91         hr = (fProc)(&CLSID_DirectSound, &IID_IClassFactory, (void **)(&pcf));
92         ok(pcf!=0, "DllGetClassObject(CLSID_DirectSound, IID_IClassFactory) failed: 0x%lx\n",hr);
93         if (pcf==0)
94                 goto error;
95
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);
99
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);
102
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);
106         if (pcf==0)
107                 goto error;
108
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);
112
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);
116         if (pcf==0)
117                 goto error;
118
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);
122
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);
126         if (pcf==0)
127                 goto error;
128
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);
132
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);
136         if (pcf==0)
137                 goto error;
138
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);
142
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);
146         if (pcf==0)
147                 goto error;
148
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);
152         if (hr!=DS_OK)
153                 goto error;
154
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);
157         if (hr!=DS_OK)
158                 goto error;
159
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);
162
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);
165         if (hr!=DS_OK)
166                 goto error;
167
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);
170
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);
173         if (hr!=DS_OK)
174                 goto error;
175
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);
178
179         if (support & KSPROPERTY_SUPPORT_GET)
180         {
181                 DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_DATA data;
182                 ULONG bytes;
183
184                 data.Callback = callback;
185                 data.Context = 0;
186
187                 hr = pps->lpVtbl->Get(pps, &DSPROPSETID_DirectSoundDevice, 
188                                           DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE,
189                                           NULL,
190                                           0,
191                                           &data, 
192                                           sizeof(data), 
193                                           &bytes);
194                 ok(hr==DS_OK, "Couldn't enumerate: 0x%lx\n",hr);
195         }
196
197 error:
198         FreeLibrary(hDsound);
199 }
200
201 static HWND get_hwnd()
202 {
203     HWND hwnd=GetForegroundWindow();
204     if (!hwnd)
205         hwnd=GetDesktopWindow();
206     return hwnd;
207 }
208                                                                                 
209 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
210                                    LPCSTR lpcstrModule, LPVOID lpContext)
211 {
212     HRESULT rc;
213     LPDIRECTSOUND dso=NULL;
214     LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
215     DSBUFFERDESC bufdesc;
216     WAVEFORMATEX wfx;
217     int ref;
218                                                                                 
219     rc=DirectSoundCreate(lpGuid,&dso,NULL);
220     ok(rc==DS_OK,"DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
221     if (rc!=DS_OK)
222         goto EXIT;
223
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));
228     if (rc!=DS_OK)
229         goto EXIT;
230                                                                                 
231     /* Testing 3D buffers */
232     primary=NULL;
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;
241         wfx.nChannels=1;
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 */
259             if(rc==DS_OK) {
260                 ULONG ulTypeSupport;
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");
266                 else
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");
271                 else
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");
276                 else
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");
281                 else
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");
286                 else
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");
291                 else
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);
296             } else
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);
300         }
301  
302         ref=IDirectSoundBuffer_Release(primary);
303         ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, should have 0\n",ref);
304     }
305  
306 EXIT:
307     if (dso!=NULL) {
308         ref=IDirectSound_Release(dso);
309         ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
310     }
311     return 1;
312 }
313  
314 static void propset_buffer_tests()
315 {
316     HRESULT rc;
317     rc=DirectSoundEnumerateA(&dsenum_callback,NULL);
318     ok(rc==DS_OK,"DirectSoundEnumerateA() failed: %s\n",DXGetErrorString8(rc));
319 }
320
321 START_TEST(propset)
322 {
323     propset_private_tests();
324     propset_buffer_tests();
325 }