Implement A->W call for GetNamedSecurityInfo.
[wine] / dlls / dsound / tests / dsound.c
1 /*
2  * Tests basic sound playback in DirectSound.
3  * In particular we test each standard Windows sound format to make sure
4  * we handle the sound card/driver quirks correctly.
5  *
6  * Part of this test involves playing test tones. But this only makes
7  * sense if someone is going to carefully listen to it, and would only
8  * bother everyone else.
9  * So this is only done if the test is being run in interactive mode.
10  *
11  * Copyright (c) 2002-2004 Francois Gouget
12  *
13  * This library is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU Lesser General Public
15  * License as published by the Free Software Foundation; either
16  * version 2.1 of the License, or (at your option) any later version.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21  * Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public
24  * License along with this library; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26  */
27
28 #define NONAMELESSSTRUCT
29 #define NONAMELESSUNION
30 #include <windows.h>
31
32 #include <math.h>
33 #include <stdlib.h>
34
35 #include "wine/test.h"
36 #include "windef.h"
37 #include "wingdi.h"
38 #include "dsound.h"
39 #include "dxerr8.h"
40 #include "dsconf.h"
41
42 #include "dsound_test.h"
43
44 static void IDirectSound_test(LPDIRECTSOUND dso, BOOL initialized,
45                               LPCGUID lpGuid)
46 {
47     HRESULT rc;
48     DSCAPS dscaps;
49     int ref;
50     IUnknown * unknown;
51     IDirectSound * ds;
52     IDirectSound8 * ds8;
53     DWORD speaker_config, new_speaker_config;
54
55     /* Try to Query for objects */
56     rc=IDirectSound_QueryInterface(dso,&IID_IUnknown,(LPVOID*)&unknown);
57     ok(rc==DS_OK,"IDirectSound_QueryInterface(IID_IUnknown) failed: %s\n",
58        DXGetErrorString8(rc));
59     if (rc==DS_OK)
60         IDirectSound_Release(unknown);
61
62     rc=IDirectSound_QueryInterface(dso,&IID_IDirectSound,(LPVOID*)&ds);
63     ok(rc==DS_OK,"IDirectSound_QueryInterface(IID_IDirectSound) failed: %s\n",
64        DXGetErrorString8(rc));
65     if (rc==DS_OK)
66         IDirectSound_Release(ds);
67
68     rc=IDirectSound_QueryInterface(dso,&IID_IDirectSound8,(LPVOID*)&ds8);
69     ok(rc==E_NOINTERFACE,"IDirectSound_QueryInterface(IID_IDirectSound8) "
70        "should have failed: %s\n",DXGetErrorString8(rc));
71     if (rc==DS_OK)
72         IDirectSound8_Release(ds8);
73
74     if (initialized == FALSE) {
75         /* try unitialized object */
76         rc=IDirectSound_GetCaps(dso,0);
77         ok(rc==DSERR_UNINITIALIZED,"IDirectSound_GetCaps(NULL) "
78            "should have returned DSERR_UNINITIALIZED, returned: %s\n",
79            DXGetErrorString8(rc));
80
81         rc=IDirectSound_GetCaps(dso,&dscaps);
82         ok(rc==DSERR_UNINITIALIZED,"IDirectSound_GetCaps() "
83            "should have returned DSERR_UNINITIALIZED, returned: %s\n",
84            DXGetErrorString8(rc));
85
86         rc=IDirectSound_Compact(dso);
87         ok(rc==DSERR_UNINITIALIZED,"IDirectSound_Compact() "
88            "should have returned DSERR_UNINITIALIZED, returned: %s\n",
89            DXGetErrorString8(rc));
90
91         rc=IDirectSound_GetSpeakerConfig(dso,&speaker_config);
92         ok(rc==DSERR_UNINITIALIZED,"IDirectSound_GetSpeakerConfig() "
93            "should have returned DSERR_UNINITIALIZED, returned: %s\n",
94            DXGetErrorString8(rc));
95
96         rc=IDirectSound_Initialize(dso,lpGuid);
97         ok(rc==DS_OK,"IDirectSound_Initialize() failed: %s\n",
98            DXGetErrorString8(rc));
99     }
100
101     /* DSOUND: Error: Invalid caps buffer */
102     rc=IDirectSound_GetCaps(dso,0);
103     ok(rc==DSERR_INVALIDPARAM,"IDirectSound_GetCaps(NULL) "
104        "should have failed: %s\n",DXGetErrorString8(rc));
105
106     ZeroMemory(&dscaps, sizeof(dscaps));
107
108     /* DSOUND: Error: Invalid caps buffer */
109     rc=IDirectSound_GetCaps(dso,&dscaps);
110     ok(rc==DSERR_INVALIDPARAM,"IDirectSound_GetCaps() "
111        "should have failed: %s\n",DXGetErrorString8(rc));
112
113     dscaps.dwSize=sizeof(dscaps);
114
115     /* DSOUND: Running on a certified driver */
116     rc=IDirectSound_GetCaps(dso,&dscaps);
117     ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc));
118
119     rc=IDirectSound_Compact(dso);
120     ok(rc==DSERR_PRIOLEVELNEEDED,"IDirectSound_Compact() failed: %s\n",
121        DXGetErrorString8(rc));
122
123     rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
124     ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",
125        DXGetErrorString8(rc));
126
127     rc=IDirectSound_Compact(dso);
128     ok(rc==DS_OK,"IDirectSound_Compact() failed: %s\n",DXGetErrorString8(rc));
129
130     rc=IDirectSound_GetSpeakerConfig(dso,0);
131     ok(rc==DSERR_INVALIDPARAM,"IDirectSound_GetSpeakerConfig(NULL) "
132        "should have failed: %s\n",DXGetErrorString8(rc));
133
134     rc=IDirectSound_GetSpeakerConfig(dso,&speaker_config);
135     ok(rc==DS_OK,"IDirectSound_GetSpeakerConfig() failed: %s\n",
136        DXGetErrorString8(rc));
137
138     speaker_config = DSSPEAKER_COMBINED(DSSPEAKER_STEREO,
139                                         DSSPEAKER_GEOMETRY_WIDE);
140     rc=IDirectSound_SetSpeakerConfig(dso,speaker_config);
141     ok(rc==DS_OK,"IDirectSound_SetSpeakerConfig() failed: %s\n",
142        DXGetErrorString8(rc));
143     if (rc==DS_OK) {
144         rc=IDirectSound_GetSpeakerConfig(dso,&new_speaker_config);
145         ok(rc==DS_OK,"IDirectSound_GetSpeakerConfig() failed: %s\n",
146            DXGetErrorString8(rc));
147         if (rc==DS_OK)
148             ok(speaker_config==new_speaker_config,
149                "IDirectSound_GetSpeakerConfig() failed to set speaker config: "
150                "expected 0x%08lx, got 0x%08lx\n",
151                speaker_config,new_speaker_config);
152     }
153
154     ref=IDirectSound_Release(dso);
155     ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
156 }
157
158 static void IDirectSound_tests()
159 {
160     HRESULT rc;
161     LPDIRECTSOUND dso=NULL;
162
163     trace("Testing IDirectSound\n");
164
165     /* try the COM class factory method of creation with no device specified */
166     rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
167                         &IID_IDirectSound, (void**)&dso);
168     ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n",
169        DXGetErrorString8(rc));
170     if (dso)
171         IDirectSound_test(dso, FALSE, NULL);
172
173     /* try the COM class factory method of creation with default playback
174      * device specified */
175     rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
176                         &IID_IDirectSound, (void**)&dso);
177     ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n",
178        DXGetErrorString8(rc));
179     if (dso)
180         IDirectSound_test(dso, FALSE, &DSDEVID_DefaultPlayback);
181
182     /* try the COM class factory method of creation with default voice
183      * playback device specified */
184     rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
185                         &IID_IDirectSound, (void**)&dso);
186     ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n",
187        DXGetErrorString8(rc));
188     if (dso)
189         IDirectSound_test(dso, FALSE, &DSDEVID_DefaultVoicePlayback);
190
191     /* try the COM class factory method of creation with a bad
192      * IID specified */
193     rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
194                         &CLSID_DirectSoundPrivate, (void**)&dso);
195     ok(rc==E_NOINTERFACE,
196        "CoCreateInstance(CLSID_DirectSound,CLSID_DirectSoundPrivate) "
197        "should have failed: %s\n",DXGetErrorString8(rc));
198
199     /* try the COM class factory method of creation with a bad
200      * GUID and IID specified */
201     rc=CoCreateInstance(&CLSID_DirectSoundPrivate, NULL, CLSCTX_INPROC_SERVER,
202                         &IID_IDirectSound, (void**)&dso);
203     ok(rc==REGDB_E_CLASSNOTREG,
204        "CoCreateInstance(CLSID_DirectSoundPrivate,IID_IDirectSound) "
205        "should have failed: %s\n",DXGetErrorString8(rc));
206
207     /* try with no device specified */
208     rc=DirectSoundCreate(NULL,&dso,NULL);
209     ok(rc==S_OK,"DirectSoundCreate(NULL) failed: %s\n",DXGetErrorString8(rc));
210     if (dso)
211         IDirectSound_test(dso, TRUE, NULL);
212
213     /* try with default playback device specified */
214     rc=DirectSoundCreate(&DSDEVID_DefaultPlayback,&dso,NULL);
215     ok(rc==S_OK,"DirectSoundCreate(DSDEVID_DefaultPlayback) failed: %s\n",
216        DXGetErrorString8(rc));
217     if (dso)
218         IDirectSound_test(dso, TRUE, NULL);
219
220     /* try with default voice playback device specified */
221     rc=DirectSoundCreate(&DSDEVID_DefaultVoicePlayback,&dso,NULL);
222     ok(rc==S_OK,"DirectSoundCreate(DSDEVID_DefaultVoicePlayback) failed: %s\n",
223        DXGetErrorString8(rc));
224     if (dso)
225         IDirectSound_test(dso, TRUE, NULL);
226
227     /* try with a bad device specified */
228     rc=DirectSoundCreate(&DSDEVID_DefaultVoiceCapture,&dso,NULL);
229     ok(rc==DSERR_NODRIVER,"DirectSoundCreate(DSDEVID_DefaultVoiceCapture) "
230        "should have failed: %s\n",DXGetErrorString8(rc));
231 }
232
233 static HRESULT test_dsound(LPGUID lpGuid)
234 {
235     HRESULT rc;
236     LPDIRECTSOUND dso=NULL;
237     int ref;
238
239     /* DSOUND: Error: Invalid interface buffer */
240     rc=DirectSoundCreate(lpGuid,0,NULL);
241     ok(rc==DSERR_INVALIDPARAM,"DirectSoundCreate should have failed: %s\n",
242        DXGetErrorString8(rc));
243
244     /* Create the DirectSound object */
245     rc=DirectSoundCreate(lpGuid,&dso,NULL);
246     ok(rc==DS_OK,"DirectSoundCreate failed: %s\n",DXGetErrorString8(rc));
247     if (rc!=DS_OK)
248         return rc;
249
250     /* Try the enumerated device */
251     IDirectSound_test(dso, TRUE, lpGuid);
252
253     /* Try the COM class factory method of creation with enumerated device */
254     rc=CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
255                         &IID_IDirectSound, (void**)&dso);
256     ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n",
257        DXGetErrorString8(rc));
258     if (dso)
259         IDirectSound_test(dso, FALSE, lpGuid);
260
261     /* Create a DirectSound object */
262     rc=DirectSoundCreate(lpGuid,&dso,NULL);
263     ok(rc==DS_OK,"DirectSoundCreate failed: %s\n",DXGetErrorString8(rc));
264     if (rc==DS_OK) {
265         LPDIRECTSOUND dso1=NULL;
266
267         /* Create a second DirectSound object */
268         rc=DirectSoundCreate(lpGuid,&dso1,NULL);
269         ok(rc==DS_OK,"DirectSoundCreate failed: %s\n",DXGetErrorString8(rc));
270         if (rc==DS_OK) {
271             /* Release the second DirectSound object */
272             ref=IDirectSound_Release(dso1);
273             ok(ref==0,"IDirectSound_Release has %d references, should have 0\n",
274                ref);
275             ok(dso!=dso1,"DirectSound objects should be unique: "
276                "dso=0x%08lx,dso1=0x%08lx\n",(DWORD)dso,(DWORD)dso1);
277         }
278
279         /* Release the first DirectSound object */
280         ref=IDirectSound_Release(dso);
281         ok(ref==0,"IDirectSound_Release has %d references, should have 0\n",
282            ref);
283         if (ref!=0)
284             return DSERR_GENERIC;
285     } else
286         return rc;
287
288     /* Create a DirectSound object */
289     rc=DirectSoundCreate(lpGuid,&dso,NULL);
290     ok(rc==DS_OK,"DirectSoundCreate failed: %s\n",DXGetErrorString8(rc));
291     if (rc==DS_OK) {
292         LPDIRECTSOUNDBUFFER secondary;
293         DSBUFFERDESC bufdesc;
294         WAVEFORMATEX wfx;
295
296         init_format(&wfx,WAVE_FORMAT_PCM,11025,8,1);
297         ZeroMemory(&bufdesc, sizeof(bufdesc));
298         bufdesc.dwSize=sizeof(bufdesc);
299         bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRL3D;
300         bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
301         bufdesc.lpwfxFormat=&wfx;
302         rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
303         ok(rc==DS_OK && secondary!=NULL,
304            "IDirectSound_CreateSoundBuffer failed to create a secondary buffer "
305            "%s\n",DXGetErrorString8(rc));
306         if (rc==DS_OK && secondary!=NULL) {
307             LPDIRECTSOUND3DBUFFER buffer3d;
308             rc=IDirectSound_QueryInterface(secondary, &IID_IDirectSound3DBuffer,
309                                            (void **)&buffer3d);
310             ok(rc==DS_OK && buffer3d!=NULL,"QueryInterface failed:  %s\n",
311                DXGetErrorString8(rc));
312             if (rc==DS_OK && buffer3d!=NULL) {
313                 ref=IDirectSound3DBuffer_AddRef(buffer3d);
314                 ok(ref==2,"IDirectSound3DBuffer_AddRef has %d references, "
315                    "should have 2\n",ref);
316             }
317             ref=IDirectSoundBuffer_AddRef(secondary);
318             ok(ref==2,"IDirectSoundBuffer_AddRef has %d references, "
319                "should have 2\n",ref);
320         }
321         /* release with buffer */
322         ref=IDirectSound_Release(dso);
323         ok(ref==0,"IDirectSound_Release has %d references, should have 0\n",
324            ref);
325         if (ref!=0)
326             return DSERR_GENERIC;
327     } else
328         return rc;
329
330     return DS_OK;
331 }
332
333 static HRESULT test_primary(LPGUID lpGuid)
334 {
335     HRESULT rc;
336     LPDIRECTSOUND dso=NULL;
337     LPDIRECTSOUNDBUFFER primary=NULL,second=NULL,third=NULL;
338     DSBUFFERDESC bufdesc;
339     DSCAPS dscaps;
340     int ref;
341
342     /* Create the DirectSound object */
343     rc=DirectSoundCreate(lpGuid,&dso,NULL);
344     ok(rc==DS_OK,"DirectSoundCreate failed: %s\n",DXGetErrorString8(rc));
345     if (rc!=DS_OK)
346         return rc;
347
348     /* Get the device capabilities */
349     ZeroMemory(&dscaps, sizeof(dscaps));
350     dscaps.dwSize=sizeof(dscaps);
351     rc=IDirectSound_GetCaps(dso,&dscaps);
352     ok(rc==DS_OK,"IDirectSound_GetCaps failed: %s\n",DXGetErrorString8(rc));
353     if (rc!=DS_OK)
354         goto EXIT;
355
356     /* DSOUND: Error: Invalid buffer description pointer */
357     rc=IDirectSound_CreateSoundBuffer(dso,0,0,NULL);
358     ok(rc==DSERR_INVALIDPARAM,
359        "IDirectSound_CreateSoundBuffer should have failed: %s\n",
360        DXGetErrorString8(rc));
361
362     /* DSOUND: Error: Invalid buffer description pointer */
363     rc=IDirectSound_CreateSoundBuffer(dso,0,&primary,NULL);
364     ok(rc==DSERR_INVALIDPARAM && primary==0,
365        "IDirectSound_CreateSoundBuffer should have failed: rc=%s,dsbo=0x%lx\n",
366        DXGetErrorString8(rc),(DWORD)primary);
367
368     /* DSOUND: Error: Invalid buffer description pointer */
369     rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,0,NULL);
370     ok(rc==DSERR_INVALIDPARAM && primary==0,
371        "IDirectSound_CreateSoundBuffer should have failed: rc=%s,dsbo=0x%lx\n",
372        DXGetErrorString8(rc),(DWORD)primary);
373
374     ZeroMemory(&bufdesc, sizeof(bufdesc));
375
376     /* DSOUND: Error: Invalid size */
377     /* DSOUND: Error: Invalid buffer description */
378     rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
379     ok(rc==DSERR_INVALIDPARAM && primary==0,
380        "IDirectSound_CreateSoundBuffer should have failed: rc=%s,"
381        "primary=0x%lx\n",DXGetErrorString8(rc),(DWORD)primary);
382
383     /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
384     /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
385     rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
386     ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel failed: %s\n",
387        DXGetErrorString8(rc));
388     if (rc!=DS_OK)
389         goto EXIT;
390
391     /* Testing the primary buffer */
392     primary=NULL;
393     ZeroMemory(&bufdesc, sizeof(bufdesc));
394     bufdesc.dwSize=sizeof(bufdesc);
395     bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME;
396     rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
397     ok(rc==DS_OK && primary!=NULL,
398        "IDirectSound_CreateSoundBuffer failed to create a primary buffer: %s\n",
399        DXGetErrorString8(rc));
400     if (rc==DS_OK && primary!=NULL) {
401         LONG vol;
402
403         /* Try to create a second primary buffer */
404         /* DSOUND: Error: The primary buffer already exists.
405          * Any changes made to the buffer description will be ignored. */
406         rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&second,NULL);
407         ok(rc==DS_OK && second==primary,
408            "IDirectSound_CreateSoundBuffer should have returned original "
409            "primary buffer: %s\n",DXGetErrorString8(rc));
410         ref=IDirectSoundBuffer_Release(second);
411         ok(ref==1,"IDirectSoundBuffer_Release primary has %d references, "
412            "should have 1\n",ref);
413
414         /* Try to duplicate a primary buffer */
415         /* DSOUND: Error: Can't duplicate primary buffers */
416         rc=IDirectSound_DuplicateSoundBuffer(dso,primary,&third);
417         /* rc=0x88780032 */
418         ok(rc!=DS_OK,"IDirectSound_DuplicateSoundBuffer primary buffer should "
419            "have failed %s\n",DXGetErrorString8(rc));
420
421         rc=IDirectSoundBuffer_GetVolume(primary,&vol);
422         ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume failed: %s\n",
423            DXGetErrorString8(rc));
424
425         if (winetest_interactive) {
426             trace("Playing a 5 seconds reference tone at the current volume.\n");
427             if (rc==DS_OK)
428                 trace("(the current volume is %ld according to DirectSound)\n",
429                       vol);
430             trace("All subsequent tones should be identical to this one.\n");
431             trace("Listen for stutter, changes in pitch, volume, etc.\n");
432         }
433         test_buffer(dso,primary,1,FALSE,0,FALSE,0,winetest_interactive &&
434                     !(dscaps.dwFlags & DSCAPS_EMULDRIVER),5.0,0,0,0,0);
435
436         ref=IDirectSoundBuffer_Release(primary);
437         ok(ref==0,"IDirectSoundBuffer_Release primary has %d references, "
438            "should have 0\n",ref);
439     }
440
441     /* Set the CooperativeLevel back to normal */
442     /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
443     rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
444     ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel failed: %s\n",
445        DXGetErrorString8(rc));
446
447 EXIT:
448     ref=IDirectSound_Release(dso);
449     ok(ref==0,"IDirectSound_Release has %d references, should have 0\n",ref);
450     if (ref!=0)
451         return DSERR_GENERIC;
452
453     return rc;
454 }
455
456 static HRESULT test_secondary(LPGUID lpGuid)
457 {
458     HRESULT rc;
459     LPDIRECTSOUND dso=NULL;
460     LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
461     DSBUFFERDESC bufdesc;
462     DSCAPS dscaps;
463     WAVEFORMATEX wfx;
464     int f,ref;
465
466     /* Create the DirectSound object */
467     rc=DirectSoundCreate(lpGuid,&dso,NULL);
468     ok(rc==DS_OK,"DirectSoundCreate failed: %s\n",DXGetErrorString8(rc));
469     if (rc!=DS_OK)
470         return rc;
471
472     /* Get the device capabilities */
473     ZeroMemory(&dscaps, sizeof(dscaps));
474     dscaps.dwSize=sizeof(dscaps);
475     rc=IDirectSound_GetCaps(dso,&dscaps);
476     ok(rc==DS_OK,"IDirectSound_GetCaps failed: %s\n",DXGetErrorString8(rc));
477     if (rc!=DS_OK)
478         goto EXIT;
479
480     /* We must call SetCooperativeLevel before creating primary buffer */
481     /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
482     rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
483     ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel failed: %s\n",
484        DXGetErrorString8(rc));
485     if (rc!=DS_OK)
486         goto EXIT;
487
488     ZeroMemory(&bufdesc, sizeof(bufdesc));
489     bufdesc.dwSize=sizeof(bufdesc);
490     bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
491     rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
492     ok(rc==DS_OK && primary!=NULL,
493        "IDirectSound_CreateSoundBuffer failed to create a primary buffer %s\n",
494        DXGetErrorString8(rc));
495
496     if (rc==DS_OK && primary!=NULL) {
497         for (f=0;f<NB_FORMATS;f++) {
498             init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1],
499                         formats[f][2]);
500             secondary=NULL;
501             ZeroMemory(&bufdesc, sizeof(bufdesc));
502             bufdesc.dwSize=sizeof(bufdesc);
503             bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
504             bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
505             bufdesc.lpwfxFormat=&wfx;
506             trace("  Testing a secondary buffer at %ldx%dx%d\n",
507                   wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels);
508             rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
509             ok(rc==DS_OK && secondary!=NULL,
510                "IDirectSound_CreateSoundBuffer failed to create a secondary "
511                "buffer %s\n",DXGetErrorString8(rc));
512
513             if (rc==DS_OK && secondary!=NULL) {
514                 test_buffer(dso,secondary,0,FALSE,0,FALSE,0,
515                             winetest_interactive,1.0,0,NULL,0,0);
516
517                 ref=IDirectSoundBuffer_Release(secondary);
518                 ok(ref==0,"IDirectSoundBuffer_Release has %d references, "
519                    "should have 0\n",ref);
520             }
521         }
522
523         ref=IDirectSoundBuffer_Release(primary);
524         ok(ref==0,"IDirectSoundBuffer_Release primary has %d references, "
525            "should have 0\n",ref);
526     }
527
528     /* Set the CooperativeLevel back to normal */
529     /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
530     rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
531     ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel failed: %s\n",
532        DXGetErrorString8(rc));
533
534 EXIT:
535     ref=IDirectSound_Release(dso);
536     ok(ref==0,"IDirectSound_Release has %d references, should have 0\n",ref);
537     if (ref!=0)
538         return DSERR_GENERIC;
539
540     return rc;
541 }
542
543 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
544                                    LPCSTR lpcstrModule, LPVOID lpContext)
545 {
546     trace("*** Testing %s - %s\n",lpcstrDescription,lpcstrModule);
547     test_dsound(lpGuid);
548     test_primary(lpGuid);
549     test_secondary(lpGuid);
550
551     return 1;
552 }
553
554 static void dsound_tests()
555 {
556     HRESULT rc;
557     rc=DirectSoundEnumerateA(&dsenum_callback,NULL);
558     ok(rc==DS_OK,"DirectSoundEnumerate failed: %ld\n",rc);
559 }
560
561 START_TEST(dsound)
562 {
563     CoInitialize(NULL);
564
565     IDirectSound_tests();
566     dsound_tests();
567 }