dsound8.c 37.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * Tests basic sound playback in DirectSound.
 * In particular we test each standard Windows sound format to make sure
 * we handle the sound card/driver quirks correctly.
 *
 * Part of this test involves playing test tones. But this only makes
 * sense if someone is going to carefully listen to it, and would only
 * bother everyone else.
 * So this is only done if the test is being run in interactive mode.
 *
 * Copyright (c) 2002-2004 Francois Gouget
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
25
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 27 28
 */

#include <windows.h>
29
#include <stdio.h>
30 31 32 33

#include "wine/test.h"
#include "dsound.h"
#include "dsconf.h"
34 35 36
#include "mmreg.h"
#include "ks.h"
#include "ksmedia.h"
37 38 39

#include "dsound_test.h"

40
static HRESULT (WINAPI *pDirectSoundEnumerateA)(LPDSENUMCALLBACKA,LPVOID)=NULL;
41 42
static HRESULT (WINAPI *pDirectSoundCreate8)(LPCGUID,LPDIRECTSOUND8*,LPUNKNOWN)=NULL;

43 44 45 46 47
int align(int length, int align)
{
    return (length / align) * align;
}

48 49 50 51 52 53 54 55 56
static void IDirectSound8_test(LPDIRECTSOUND8 dso, BOOL initialized,
                               LPCGUID lpGuid)
{
    HRESULT rc;
    DSCAPS dscaps;
    int ref;
    IUnknown * unknown;
    IDirectSound * ds;
    IDirectSound8 * ds8;
57
    DWORD speaker_config, new_speaker_config, ref_speaker_config;
58 59 60 61
    DWORD certified;

    /* Try to Query for objects */
    rc=IDirectSound8_QueryInterface(dso,&IID_IUnknown,(LPVOID*)&unknown);
62
    ok(rc==DS_OK,"IDirectSound8_QueryInterface(IID_IUnknown) failed: %08x\n", rc);
63 64 65 66
    if (rc==DS_OK)
        IDirectSound8_Release(unknown);

    rc=IDirectSound8_QueryInterface(dso,&IID_IDirectSound,(LPVOID*)&ds);
67
    ok(rc==DS_OK,"IDirectSound8_QueryInterface(IID_IDirectSound) failed: %08x\n", rc);
68 69 70 71 72
    if (rc==DS_OK)
        IDirectSound_Release(ds);

    rc=IDirectSound8_QueryInterface(dso,&IID_IDirectSound8,(LPVOID*)&ds8);
    ok(rc==DS_OK,"IDirectSound8_QueryInterface(IID_IDirectSound8) "
73
       "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
74 75 76 77
    if (rc==DS_OK)
        IDirectSound8_Release(ds8);

    if (initialized == FALSE) {
78
        /* try uninitialized object */
79 80
        rc=IDirectSound8_GetCaps(dso,0);
        ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_GetCaps(NULL) "
81
           "should have returned DSERR_UNINITIALIZED, returned: %08x\n", rc);
82 83 84

        rc=IDirectSound8_GetCaps(dso,&dscaps);
        ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_GetCaps() "
85
           "should have returned DSERR_UNINITIALIZED, returned: %08x\n", rc);
86 87 88

        rc=IDirectSound8_Compact(dso);
        ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_Compact() "
89
           "should have returned DSERR_UNINITIALIZED, returned: %08x\n", rc);
90 91 92

        rc=IDirectSound8_GetSpeakerConfig(dso,&speaker_config);
        ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_GetSpeakerConfig() "
93
           "should have returned DSERR_UNINITIALIZED, returned: %08x\n", rc);
94 95 96

        rc=IDirectSound8_VerifyCertification(dso, &certified);
        ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_VerifyCertification() "
97
           "should have returned DSERR_UNINITIALIZED, returned: %08x\n", rc);
98 99

        rc=IDirectSound8_Initialize(dso,lpGuid);
100
        ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
101
           "IDirectSound8_Initialize() failed: %08x\n",rc);
102 103
        if (rc==DSERR_NODRIVER) {
            trace("  No Driver\n");
104
            goto EXIT;
105 106
        } else if (rc==E_FAIL) {
            trace("  No Device\n");
107
            goto EXIT;
108
        } else if (rc==DSERR_ALLOCATED) {
109
            trace("  Already In Use\n");
110
            goto EXIT;
Jakob Eriksson's avatar
Jakob Eriksson committed
111
        }
112 113
    }

114 115
    rc=IDirectSound8_Initialize(dso,lpGuid);
    ok(rc==DSERR_ALREADYINITIALIZED, "IDirectSound8_Initialize() "
116
       "should have returned DSERR_ALREADYINITIALIZED: %08x\n", rc);
117

118 119 120
    /* DSOUND: Error: Invalid caps buffer */
    rc=IDirectSound8_GetCaps(dso,0);
    ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_GetCaps() "
121
       "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
122 123 124 125 126 127

    ZeroMemory(&dscaps, sizeof(dscaps));

    /* DSOUND: Error: Invalid caps buffer */
    rc=IDirectSound8_GetCaps(dso,&dscaps);
    ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_GetCaps() "
128
       "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
129 130 131 132 133

    dscaps.dwSize=sizeof(dscaps);

    /* DSOUND: Running on a certified driver */
    rc=IDirectSound8_GetCaps(dso,&dscaps);
134
    ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %08x\n",rc);
135 136

    rc=IDirectSound8_Compact(dso);
137
    ok(rc==DSERR_PRIOLEVELNEEDED,"IDirectSound8_Compact() failed: %08x\n", rc);
138 139

    rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
140
    ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %08x\n", rc);
141 142

    rc=IDirectSound8_Compact(dso);
143
    ok(rc==DS_OK,"IDirectSound8_Compact() failed: %08x\n",rc);
144 145 146

    rc=IDirectSound8_GetSpeakerConfig(dso,0);
    ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_GetSpeakerConfig(NULL) "
147
       "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
148 149

    rc=IDirectSound8_GetSpeakerConfig(dso,&speaker_config);
150
    ok(rc==DS_OK,"IDirectSound8_GetSpeakerConfig() failed: %08x\n", rc);
151
    ref_speaker_config = speaker_config;
152 153 154

    speaker_config = DSSPEAKER_COMBINED(DSSPEAKER_STEREO,
                                        DSSPEAKER_GEOMETRY_WIDE);
155 156 157 158 159 160 161
    if (speaker_config == ref_speaker_config)
        speaker_config = DSSPEAKER_COMBINED(DSSPEAKER_STEREO,
                                            DSSPEAKER_GEOMETRY_NARROW);
    if(rc==DS_OK) {
        rc=IDirectSound8_SetSpeakerConfig(dso,speaker_config);
        ok(rc==DS_OK,"IDirectSound8_SetSpeakerConfig() failed: %08x\n", rc);
    }
162 163
    if (rc==DS_OK) {
        rc=IDirectSound8_GetSpeakerConfig(dso,&new_speaker_config);
164
        ok(rc==DS_OK,"IDirectSound8_GetSpeakerConfig() failed: %08x\n", rc);
165 166
        if (rc==DS_OK && speaker_config!=new_speaker_config)
               trace("IDirectSound8_GetSpeakerConfig() failed to set speaker "
167
               "config: expected 0x%08x, got 0x%08x\n",
168
               speaker_config,new_speaker_config);
169
        IDirectSound8_SetSpeakerConfig(dso,ref_speaker_config);
170 171 172
    }

    rc=IDirectSound8_VerifyCertification(dso, &certified);
173
    ok(rc==DS_OK||rc==E_NOTIMPL,"IDirectSound8_VerifyCertification() failed: %08x\n", rc);
174

175
EXIT:
176 177 178 179
    ref=IDirectSound8_Release(dso);
    ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
}

180
static void IDirectSound8_tests(void)
181 182 183
{
    HRESULT rc;
    LPDIRECTSOUND8 dso=NULL;
184
    LPCLASSFACTORY cf=NULL;
185 186 187

    trace("Testing IDirectSound8\n");

188 189 190
    rc=CoGetClassObject(&CLSID_DirectSound8, CLSCTX_INPROC_SERVER, NULL,
                        &IID_IClassFactory, (void**)&cf);
    ok(rc==S_OK,"CoGetClassObject(CLSID_DirectSound8, IID_IClassFactory) "
191
       "failed: %08x\n", rc);
192 193 194 195

    rc=CoGetClassObject(&CLSID_DirectSound8, CLSCTX_INPROC_SERVER, NULL,
                        &IID_IUnknown, (void**)&cf);
    ok(rc==S_OK,"CoGetClassObject(CLSID_DirectSound8, IID_IUnknown) "
196
       "failed: %08x\n", rc);
197

198 199 200
    /* try the COM class factory method of creation with no device specified */
    rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER,
                        &IID_IDirectSound8, (void**)&dso);
201
    ok(rc==S_OK||rc==REGDB_E_CLASSNOTREG,"CoCreateInstance() failed: %08x\n", rc);
202 203 204 205
    if (rc==REGDB_E_CLASSNOTREG) {
        trace("  Class Not Registered\n");
        return;
    }
206 207 208 209 210 211 212
    if (dso)
        IDirectSound8_test(dso, FALSE, NULL);

    /* try the COM class factory method of creation with default playback
     *  device specified */
    rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER,
                        &IID_IDirectSound8, (void**)&dso);
213
    ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound8) failed: %08x\n", rc);
214 215 216 217 218 219 220
    if (dso)
        IDirectSound8_test(dso, FALSE, &DSDEVID_DefaultPlayback);

    /* try the COM class factory method of creation with default voice
     * playback device specified */
    rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER,
                        &IID_IDirectSound8, (void**)&dso);
221
    ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound8) failed: %08x\n", rc);
222 223 224 225 226 227 228 229 230
    if (dso)
        IDirectSound8_test(dso, FALSE, &DSDEVID_DefaultVoicePlayback);

    /* try the COM class factory method of creation with a bad
     * IID specified */
    rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER,
                        &CLSID_DirectSoundPrivate, (void**)&dso);
    ok(rc==E_NOINTERFACE,
       "CoCreateInstance(CLSID_DirectSound8,CLSID_DirectSoundPrivate) "
231
       "should have failed: %08x\n",rc);
232 233 234 235 236 237 238

    /* try the COM class factory method of creation with a bad
     * GUID and IID specified */
    rc=CoCreateInstance(&CLSID_DirectSoundPrivate, NULL, CLSCTX_INPROC_SERVER,
                        &IID_IDirectSound8, (void**)&dso);
    ok(rc==REGDB_E_CLASSNOTREG,
       "CoCreateInstance(CLSID_DirectSoundPrivate,IID_IDirectSound8) "
239
       "should have failed: %08x\n",rc);
240 241

    /* try with no device specified */
242
    rc=pDirectSoundCreate8(NULL,&dso,NULL);
243
    ok(rc==S_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
244
       "DirectSoundCreate8() failed: %08x\n",rc);
245
    if (rc==DS_OK && dso)
246 247 248
        IDirectSound8_test(dso, TRUE, NULL);

    /* try with default playback device specified */
249
    rc=pDirectSoundCreate8(&DSDEVID_DefaultPlayback,&dso,NULL);
250
    ok(rc==S_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
251
       "DirectSoundCreate8() failed: %08x\n",rc);
252
    if (rc==DS_OK && dso)
253 254 255
        IDirectSound8_test(dso, TRUE, NULL);

    /* try with default voice playback device specified */
256
    rc=pDirectSoundCreate8(&DSDEVID_DefaultVoicePlayback,&dso,NULL);
257
    ok(rc==S_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
258
       "DirectSoundCreate8() failed: %08x\n",rc);
259
    if (rc==DS_OK && dso)
260 261 262
        IDirectSound8_test(dso, TRUE, NULL);

    /* try with a bad device specified */
263
    rc=pDirectSoundCreate8(&DSDEVID_DefaultVoiceCapture,&dso,NULL);
264
    ok(rc==DSERR_NODRIVER,"DirectSoundCreate8(DSDEVID_DefaultVoiceCapture) "
265
       "should have failed: %08x\n",rc);
266 267 268 269 270 271 272 273 274
}

static HRESULT test_dsound8(LPGUID lpGuid)
{
    HRESULT rc;
    LPDIRECTSOUND8 dso=NULL;
    int ref;

    /* DSOUND: Error: Invalid interface buffer */
275
    rc=pDirectSoundCreate8(lpGuid,0,NULL);
276
    ok(rc==DSERR_INVALIDPARAM,"DirectSoundCreate8() should have returned "
277
       "DSERR_INVALIDPARAM, returned: %08x\n",rc);
278 279

    /* Create the DirectSound8 object */
280
    rc=pDirectSoundCreate8(lpGuid,&dso,NULL);
281
    ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
282
       "DirectSoundCreate8() failed: %08x\n",rc);
283 284 285 286 287 288 289 290 291
    if (rc!=DS_OK)
        return rc;

    /* Try the enumerated device */
    IDirectSound8_test(dso, TRUE, lpGuid);

    /* Try the COM class factory method of creation with enumerated device */
    rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER,
                        &IID_IDirectSound8, (void**)&dso);
292
    ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %08x\n", rc);
293 294 295 296
    if (dso)
        IDirectSound8_test(dso, FALSE, lpGuid);

    /* Create a DirectSound8 object */
297
    rc=pDirectSoundCreate8(lpGuid,&dso,NULL);
298
    ok(rc==DS_OK,"DirectSoundCreate8() failed: %08x\n",rc);
299 300 301 302
    if (rc==DS_OK) {
        LPDIRECTSOUND8 dso1=NULL;

        /* Create a second DirectSound8 object */
303
        rc=pDirectSoundCreate8(lpGuid,&dso1,NULL);
304
        ok(rc==DS_OK,"DirectSoundCreate8() failed: %08x\n",rc);
305 306 307
        if (rc==DS_OK) {
            /* Release the second DirectSound8 object */
            ref=IDirectSound8_Release(dso1);
308
            ok(ref==0,"IDirectSound8_Release() has %d references, "
309 310
               "should have 0\n",ref);
            ok(dso!=dso1,"DirectSound8 objects should be unique: "
311
               "dso=%p,dso1=%p\n",dso,dso1);
312 313 314 315
        }

        /* Release the first DirectSound8 object */
        ref=IDirectSound8_Release(dso);
316
        ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",
317 318 319 320 321 322 323
           ref);
        if (ref!=0)
            return DSERR_GENERIC;
    } else
        return rc;

    /* Create a DirectSound8 object */
324
    rc=pDirectSoundCreate8(lpGuid,&dso,NULL);
325
    ok(rc==DS_OK,"DirectSoundCreate8() failed: %08x\n",rc);
326 327 328 329 330 331 332 333 334
    if (rc==DS_OK) {
        LPDIRECTSOUNDBUFFER secondary;
        DSBUFFERDESC bufdesc;
        WAVEFORMATEX wfx;

        init_format(&wfx,WAVE_FORMAT_PCM,11025,8,1);
        ZeroMemory(&bufdesc, sizeof(bufdesc));
        bufdesc.dwSize=sizeof(bufdesc);
        bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRL3D;
335 336
        bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
                                    wfx.nBlockAlign);
337 338 339
        bufdesc.lpwfxFormat=&wfx;
        rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
        ok(rc==DS_OK && secondary!=NULL,
340
           "IDirectSound8_CreateSoundBuffer() failed to create a secondary "
341
           "buffer: %08x\n",rc);
342 343 344 345 346 347 348
        if (rc==DS_OK && secondary!=NULL) {
            LPDIRECTSOUND3DBUFFER buffer3d;
            LPDIRECTSOUNDBUFFER8 buffer8;
            rc=IDirectSound8_QueryInterface(secondary,
                                            &IID_IDirectSound3DBuffer,
                                            (void **)&buffer3d);
            ok(rc==DS_OK && buffer3d!=NULL,
349
               "IDirectSound8_QueryInterface() failed: %08x\n", rc);
350 351
            if (rc==DS_OK && buffer3d!=NULL) {
                ref=IDirectSound3DBuffer_AddRef(buffer3d);
352
                ok(ref==2,"IDirectSound3DBuffer_AddRef() has %d references, "
353 354 355 356 357 358 359
                   "should have 2\n",ref);
            }
            rc=IDirectSound8_QueryInterface(secondary,
                                            &IID_IDirectSoundBuffer8,
                                            (void **)&buffer8);
            if (rc==DS_OK && buffer8!=NULL) {
                ref=IDirectSoundBuffer8_AddRef(buffer8);
360
                ok(ref==3,"IDirectSoundBuffer8_AddRef() has %d references, "
361 362 363
                   "should have 3\n",ref);
            }
            ref=IDirectSoundBuffer_AddRef(secondary);
364
            ok(ref==4,"IDirectSoundBuffer_AddRef() has %d references, "
365 366 367 368
               "should have 4\n",ref);
        }
        /* release with buffer */
        ref=IDirectSound8_Release(dso);
369
        ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",
370 371 372 373 374 375 376 377 378 379 380 381 382 383
           ref);
        if (ref!=0)
            return DSERR_GENERIC;
    } else
        return rc;

    return DS_OK;
}

static HRESULT test_primary8(LPGUID lpGuid)
{
    HRESULT rc;
    LPDIRECTSOUND8 dso=NULL;
    LPDIRECTSOUNDBUFFER primary=NULL,second=NULL,third=NULL;
384
    LPDIRECTSOUNDBUFFER8 pb8 = NULL;
385 386
    DSBUFFERDESC bufdesc;
    DSCAPS dscaps;
387
    WAVEFORMATEX wfx;
388 389 390
    int ref;

    /* Create the DirectSound object */
391
    rc=pDirectSoundCreate8(lpGuid,&dso,NULL);
392
    ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
393
       "DirectSoundCreate8() failed: %08x\n",rc);
394 395 396 397 398 399 400
    if (rc!=DS_OK)
        return rc;

    /* Get the device capabilities */
    ZeroMemory(&dscaps, sizeof(dscaps));
    dscaps.dwSize=sizeof(dscaps);
    rc=IDirectSound8_GetCaps(dso,&dscaps);
401
    ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %08x\n",rc);
402 403 404 405 406 407
    if (rc!=DS_OK)
        goto EXIT;

    /* DSOUND: Error: Invalid buffer description pointer */
    rc=IDirectSound8_CreateSoundBuffer(dso,0,0,NULL);
    ok(rc==DSERR_INVALIDPARAM,
408
       "IDirectSound8_CreateSoundBuffer should have returned "
409
       "DSERR_INVALIDPARAM, returned: %08x\n",rc);
410 411 412 413

    /* DSOUND: Error: Invalid buffer description pointer */
    rc=IDirectSound8_CreateSoundBuffer(dso,0,&primary,NULL);
    ok(rc==DSERR_INVALIDPARAM && primary==0,
414
       "IDirectSound8_CreateSoundBuffer() should have returned "
415 416
       "DSERR_INVALIDPARAM, returned: rc=%08x,dsbo=%p\n",
       rc,primary);
417

418 419 420 421
    ZeroMemory(&bufdesc, sizeof(bufdesc));
    bufdesc.dwSize = sizeof(DSBUFFERDESC);

    /* DSOUND: Error: Invalid dsound buffer interface pointer */
422 423
    rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,0,NULL);
    ok(rc==DSERR_INVALIDPARAM && primary==0,
424 425
       "IDirectSound8_CreateSoundBuffer() should have failed: rc=%08x,"
       "dsbo=%p\n",rc,primary);
426 427 428 429 430 431 432

    ZeroMemory(&bufdesc, sizeof(bufdesc));

    /* DSOUND: Error: Invalid size */
    /* DSOUND: Error: Invalid buffer description */
    rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
    ok(rc==DSERR_INVALIDPARAM && primary==0,
433 434
       "IDirectSound8_CreateSoundBuffer() should have failed: rc=%08x,"
       "primary=%p\n",rc,primary);
435 436 437 438

    /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
    /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
    rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
439
    ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %08x\n", rc);
440 441 442 443
    if (rc!=DS_OK)
        goto EXIT;

    /* Testing the primary buffer */
444 445 446 447 448 449 450 451
    primary=NULL;
    ZeroMemory(&bufdesc, sizeof(bufdesc));
    bufdesc.dwSize=sizeof(bufdesc);
    bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME;
    bufdesc.lpwfxFormat = &wfx;
    init_format(&wfx,WAVE_FORMAT_PCM,11025,8,2);
    rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
    ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_CreateSoundBuffer() should have "
452
       "returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
453 454 455
    if (rc==DS_OK && primary!=NULL)
        IDirectSoundBuffer_Release(primary);

456 457 458 459 460
    primary=NULL;
    ZeroMemory(&bufdesc, sizeof(bufdesc));
    bufdesc.dwSize=sizeof(bufdesc);
    bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME;
    rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
461
    ok((rc==DS_OK && primary!=NULL) || (rc==DSERR_CONTROLUNAVAIL),
462
       "IDirectSound8_CreateSoundBuffer() failed to create a primary buffer: "
463
       "%08x\n",rc);
464 465 466
    if (rc==DSERR_CONTROLUNAVAIL)
        trace("  No Primary\n");
    else if (rc==DS_OK && primary!=NULL) {
467 468 469 470 471 472 473
        LONG vol;

        /* Try to create a second primary buffer */
        /* DSOUND: Error: The primary buffer already exists.
         * Any changes made to the buffer description will be ignored. */
        rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&second,NULL);
        ok(rc==DS_OK && second==primary,
474
           "IDirectSound8_CreateSoundBuffer() should have returned original "
475
           "primary buffer: %08x\n",rc);
476
        ref=IDirectSoundBuffer_Release(second);
477
        ok(ref==1,"IDirectSoundBuffer_Release() primary has %d references, "
478 479 480 481 482 483
           "should have 1\n",ref);

        /* Try to duplicate a primary buffer */
        /* DSOUND: Error: Can't duplicate primary buffers */
        rc=IDirectSound8_DuplicateSoundBuffer(dso,primary,&third);
        /* rc=0x88780032 */
484
        ok(rc!=DS_OK,"IDirectSound8_DuplicateSoundBuffer() primary buffer "
485
           "should have failed %08x\n",rc);
486

487 488
        /* Primary buffers don't have an IDirectSoundBuffer8 */
        rc = IDirectSoundBuffer_QueryInterface(primary, &IID_IDirectSoundBuffer8, (LPVOID*)&pb8);
489
        ok(FAILED(rc), "Primary buffer does have an IDirectSoundBuffer8: %08x\n", rc);
490

491
        rc=IDirectSoundBuffer_GetVolume(primary,&vol);
492
        ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume() failed: %08x\n", rc);
493 494 495 496

        if (winetest_interactive) {
            trace("Playing a 5 seconds reference tone at the current volume.\n");
            if (rc==DS_OK)
497
                trace("(the current volume is %d according to DirectSound)\n",
498 499 500 501
                      vol);
            trace("All subsequent tones should be identical to this one.\n");
            trace("Listen for stutter, changes in pitch, volume, etc.\n");
        }
502
        test_buffer8(dso,&primary,1,FALSE,0,FALSE,0,winetest_interactive &&
503 504 505
                     !(dscaps.dwFlags & DSCAPS_EMULDRIVER),5.0,0,0,0,0);

        ref=IDirectSoundBuffer_Release(primary);
506
        ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
507 508 509 510 511 512
           "should have 0\n",ref);
    }

    /* Set the CooperativeLevel back to normal */
    /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
    rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
513
    ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %08x\n", rc);
514 515 516

EXIT:
    ref=IDirectSound8_Release(dso);
517
    ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
518 519 520 521 522 523
    if (ref!=0)
        return DSERR_GENERIC;

    return rc;
}

524 525 526 527 528 529 530 531 532 533 534 535
/*
 * Test the primary buffer at different formats while keeping the
 * secondary buffer at a constant format.
 */
static HRESULT test_primary_secondary8(LPGUID lpGuid)
{
    HRESULT rc;
    LPDIRECTSOUND8 dso=NULL;
    LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
    DSBUFFERDESC bufdesc;
    DSCAPS dscaps;
    WAVEFORMATEX wfx, wfx2;
536 537
    int ref;
    unsigned int f;
538 539

    /* Create the DirectSound object */
540
    rc=pDirectSoundCreate8(lpGuid,&dso,NULL);
541
    ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
542
       "DirectSoundCreate8() failed: %08x\n",rc);
543 544 545 546 547 548 549
    if (rc!=DS_OK)
        return rc;

    /* Get the device capabilities */
    ZeroMemory(&dscaps, sizeof(dscaps));
    dscaps.dwSize=sizeof(dscaps);
    rc=IDirectSound8_GetCaps(dso,&dscaps);
550
    ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %08x\n",rc);
551 552 553 554 555 556
    if (rc!=DS_OK)
        goto EXIT;

    /* We must call SetCooperativeLevel before creating primary buffer */
    /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
    rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
557
    ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %08x\n", rc);
558 559 560 561 562 563 564 565
    if (rc!=DS_OK)
        goto EXIT;

    ZeroMemory(&bufdesc, sizeof(bufdesc));
    bufdesc.dwSize=sizeof(bufdesc);
    bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
    rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
    ok(rc==DS_OK && primary!=NULL,
566
       "IDirectSound8_CreateSoundBuffer() failed to create a primary buffer "
567
       "%08x\n",rc);
568 569 570

    if (rc==DS_OK && primary!=NULL) {
        for (f=0;f<NB_FORMATS;f++) {
571 572 573 574
            /* We must call SetCooperativeLevel to be allowed to call
             * SetFormat */
            /* DSOUND: Setting DirectSound cooperative level to
             * DSSCL_PRIORITY */
575
            rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
576
            ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %08x\n", rc);
577 578 579 580 581 582 583
            if (rc!=DS_OK)
                goto EXIT;

            init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1],
                        formats[f][2]);
            wfx2=wfx;
            rc=IDirectSoundBuffer_SetFormat(primary,&wfx);
584 585 586
            ok(rc==DS_OK
               || rc==DSERR_INVALIDPARAM, /* 2003 */
               "IDirectSoundBuffer_SetFormat(%s) failed: %08x\n",
587
               format_string(&wfx), rc);
588

589
            /* There is no guarantee that SetFormat will actually change the
590 591 592 593
             * format to what we asked for. It depends on what the soundcard
             * supports. So we must re-query the format.
             */
            rc=IDirectSoundBuffer_GetFormat(primary,&wfx,sizeof(wfx),NULL);
594
            ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %08x\n", rc);
595 596 597 598 599
            if (rc==DS_OK &&
                (wfx.wFormatTag!=wfx2.wFormatTag ||
                 wfx.nSamplesPerSec!=wfx2.nSamplesPerSec ||
                 wfx.wBitsPerSample!=wfx2.wBitsPerSample ||
                 wfx.nChannels!=wfx2.nChannels)) {
600 601
                trace("Requested primary format tag=0x%04x %dx%dx%d "
                      "avg.B/s=%d align=%d\n",
602 603
                      wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample,
                      wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign);
604
                trace("Got tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
605 606 607 608 609 610 611
                      wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
                      wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
            }

            /* Set the CooperativeLevel back to normal */
            /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
            rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
612
            ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %08x\n", rc);
613 614 615 616 617 618 619

            init_format(&wfx2,WAVE_FORMAT_PCM,11025,16,2);

            secondary=NULL;
            ZeroMemory(&bufdesc, sizeof(bufdesc));
            bufdesc.dwSize=sizeof(bufdesc);
            bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
620 621
            bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
                                        wfx.nBlockAlign);
622
            bufdesc.lpwfxFormat=&wfx2;
623
            if (winetest_interactive) {
624 625
                trace("  Testing a primary buffer at %dx%dx%d with a "
                      "secondary buffer at %dx%dx%d\n",
626 627 628
                      wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
                      wfx2.nSamplesPerSec,wfx2.wBitsPerSample,wfx2.nChannels);
            }
629 630
            rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
            ok(rc==DS_OK && secondary!=NULL,
631
               "IDirectSound_CreateSoundBuffer() failed to create a secondary "
632
               "buffer %08x\n",rc);
633 634

            if (rc==DS_OK && secondary!=NULL) {
635
                test_buffer8(dso,&secondary,0,FALSE,0,FALSE,0,
636 637 638
                             winetest_interactive,1.0,0,NULL,0,0);

                ref=IDirectSoundBuffer_Release(secondary);
639
                ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
640 641 642 643 644
                   "should have 0\n",ref);
            }
        }

        ref=IDirectSoundBuffer_Release(primary);
645
        ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
646 647 648 649 650 651
           "should have 0\n",ref);
    }

    /* Set the CooperativeLevel back to normal */
    /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
    rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
652
    ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %08x\n", rc);
653 654 655

EXIT:
    ref=IDirectSound8_Release(dso);
656
    ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
657 658 659 660 661 662
    if (ref!=0)
        return DSERR_GENERIC;

    return rc;
}

663 664 665 666 667 668 669
static HRESULT test_secondary8(LPGUID lpGuid)
{
    HRESULT rc;
    LPDIRECTSOUND8 dso=NULL;
    LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
    DSBUFFERDESC bufdesc;
    DSCAPS dscaps;
670
    WAVEFORMATEX wfx, wfx1;
671 672
    DWORD f;
    int ref;
673 674

    /* Create the DirectSound object */
675
    rc=pDirectSoundCreate8(lpGuid,&dso,NULL);
676
    ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
677
       "DirectSoundCreate8() failed: %08x\n",rc);
678 679 680 681 682 683 684
    if (rc!=DS_OK)
        return rc;

    /* Get the device capabilities */
    ZeroMemory(&dscaps, sizeof(dscaps));
    dscaps.dwSize=sizeof(dscaps);
    rc=IDirectSound8_GetCaps(dso,&dscaps);
685
    ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %08x\n",rc);
686 687 688 689 690 691
    if (rc!=DS_OK)
        goto EXIT;

    /* We must call SetCooperativeLevel before creating primary buffer */
    /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
    rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
692
    ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %08x\n", rc);
693 694 695 696 697 698 699 700
    if (rc!=DS_OK)
        goto EXIT;

    ZeroMemory(&bufdesc, sizeof(bufdesc));
    bufdesc.dwSize=sizeof(bufdesc);
    bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
    rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
    ok(rc==DS_OK && primary!=NULL,
701
       "IDirectSound8_CreateSoundBuffer() failed to create a primary buffer "
702
       "%08x\n",rc);
703 704

    if (rc==DS_OK && primary!=NULL) {
705
        rc=IDirectSoundBuffer_GetFormat(primary,&wfx1,sizeof(wfx1),NULL);
706
        ok(rc==DS_OK,"IDirectSoundBuffer8_Getformat() failed: %08x\n", rc);
707 708 709
        if (rc!=DS_OK)
            goto EXIT1;

710
        for (f=0;f<NB_FORMATS;f++) {
711
            WAVEFORMATEXTENSIBLE wfxe;
712 713 714 715 716 717
            init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1],
                        formats[f][2]);
            secondary=NULL;
            ZeroMemory(&bufdesc, sizeof(bufdesc));
            bufdesc.dwSize=sizeof(bufdesc);
            bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
718 719
            bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
                                        wfx.nBlockAlign);
720 721
            rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
            ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_CreateSoundBuffer() "
722
               "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
723 724 725 726 727 728 729
            if (rc==DS_OK && secondary!=NULL)
                IDirectSoundBuffer_Release(secondary);

            secondary=NULL;
            ZeroMemory(&bufdesc, sizeof(bufdesc));
            bufdesc.dwSize=sizeof(bufdesc);
            bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
730 731
            bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
                                        wfx.nBlockAlign);
732
            bufdesc.lpwfxFormat=&wfx;
733 734
            rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
            if (wfx.wBitsPerSample != 8 && wfx.wBitsPerSample != 16)
735 736 737
                ok(((rc == DSERR_CONTROLUNAVAIL || rc == DSERR_INVALIDCALL || rc == DSERR_INVALIDPARAM /* 2003 */) && !secondary)
                    || rc == DS_OK, /* driver dependent? */
                    "IDirectSound_CreateSoundBuffer() "
738 739
                    "should have returned (DSERR_CONTROLUNAVAIL or DSERR_INVALIDCALL) "
                    "and NULL, returned: %08x %p\n", rc, secondary);
740 741 742
            else
                ok(rc==DS_OK && secondary!=NULL,
                    "IDirectSound_CreateSoundBuffer() failed to create a secondary "
743
                    "buffer %08x\n",rc);
744 745 746 747 748 749 750 751 752 753 754 755 756 757
            if (secondary)
                IDirectSoundBuffer_Release(secondary);
            secondary = NULL;

            bufdesc.lpwfxFormat=(WAVEFORMATEX*)&wfxe;
            wfxe.Format = wfx;
            wfxe.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
            wfxe.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
            wfxe.Format.cbSize = 1;
            wfxe.Samples.wValidBitsPerSample = wfx.wBitsPerSample;
            wfxe.dwChannelMask = (wfx.nChannels == 1 ? KSAUDIO_SPEAKER_MONO : KSAUDIO_SPEAKER_STEREO);

            rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
            ok(rc==DSERR_INVALIDPARAM && !secondary,
758 759
                "IDirectSound_CreateSoundBuffer() returned: %08x %p\n",
                rc, secondary);
760
            if (secondary)
761
            {
762
                IDirectSoundBuffer_Release(secondary);
763 764
                secondary=NULL;
            }
765 766 767 768

            wfxe.Format.cbSize = sizeof(wfxe) - sizeof(wfx) + 1;

            rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
769
            ok(((rc==DSERR_CONTROLUNAVAIL || rc==DSERR_INVALIDCALL /* 2003 */) && !secondary)
770
                || rc==DS_OK /* driver dependent? */,
771 772
                "IDirectSound_CreateSoundBuffer() returned: %08x %p\n",
                rc, secondary);
773
            if (secondary)
774
            {
775
                IDirectSoundBuffer_Release(secondary);
776 777
                secondary=NULL;
            }
778 779 780 781

            wfxe.Format.cbSize = sizeof(wfxe) - sizeof(wfx);
            wfxe.SubFormat = GUID_NULL;
            rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
782
            ok((rc==DSERR_INVALIDPARAM || rc==DSERR_INVALIDCALL) && !secondary,
783 784
                "IDirectSound_CreateSoundBuffer() returned: %08x %p\n",
                rc, secondary);
785
            if (secondary)
786
            {
787
                IDirectSoundBuffer_Release(secondary);
788 789
                secondary=NULL;
            }
790 791 792

            wfxe.Format.cbSize = sizeof(wfxe);
            rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
793
            ok((rc==DSERR_CONTROLUNAVAIL || rc==DSERR_INVALIDCALL || rc==E_INVALIDARG) && !secondary,
794 795 796 797 798 799 800 801
                "IDirectSound_CreateSoundBuffer() returned: %08x %p\n",
                rc, secondary);
            if (secondary)
            {
                IDirectSoundBuffer_Release(secondary);
                secondary=NULL;
            }

802
            wfxe.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
803 804 805 806 807 808 809 810 811
            rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
            ok(rc==DS_OK && secondary,
                "IDirectSound_CreateSoundBuffer() returned: %08x %p\n",
                rc, secondary);
            if (secondary)
            {
                IDirectSoundBuffer_Release(secondary);
                secondary=NULL;
            }
812

813 814
            wfxe.Format.cbSize = sizeof(wfxe) + 1;
            rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
815
            ok(((rc==DSERR_CONTROLUNAVAIL || rc==DSERR_INVALIDCALL /* 2003 */) && !secondary)
816 817 818 819 820 821 822 823 824 825
                || rc==DS_OK /* driver dependent? */,
                "IDirectSound_CreateSoundBuffer() returned: %08x %p\n",
                rc, secondary);
            if (secondary)
            {
                IDirectSoundBuffer_Release(secondary);
                secondary=NULL;
            }

            wfxe.Format.cbSize = sizeof(wfxe) - sizeof(wfx);
826 827 828
            ++wfxe.Samples.wValidBitsPerSample;
            rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
            ok(rc==DSERR_INVALIDPARAM && !secondary,
829 830
                "IDirectSound_CreateSoundBuffer() returned: %08x %p\n",
                rc, secondary);
831
            if (secondary)
832
            {
833
                IDirectSoundBuffer_Release(secondary);
834 835
                secondary=NULL;
            }
836 837 838 839 840
            --wfxe.Samples.wValidBitsPerSample;

            wfxe.Samples.wValidBitsPerSample = 0;
            rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
            ok(rc==DS_OK && secondary,
841 842
                "IDirectSound_CreateSoundBuffer() returned: %08x %p\n",
                rc, secondary);
843
            if (secondary)
844
            {
845
                IDirectSoundBuffer_Release(secondary);
846 847
                secondary=NULL;
            }
848 849 850
            wfxe.Samples.wValidBitsPerSample = wfxe.Format.wBitsPerSample;

            rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
851
            ok(rc==DS_OK && secondary!=NULL,
852
                "IDirectSound_CreateSoundBuffer() failed to create a secondary "
853
                "buffer %08x\n",rc);
854 855

            if (rc==DS_OK && secondary!=NULL) {
856 857 858 859 860 861
                if (winetest_interactive) {
                    trace("  Testing a secondary buffer at %dx%dx%d "
                        "with a primary buffer at %dx%dx%d\n",
                        wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
                        wfx1.nSamplesPerSec,wfx1.wBitsPerSample,wfx1.nChannels);
                }
862
                test_buffer8(dso,&secondary,0,FALSE,0,FALSE,0,
863 864 865
                             winetest_interactive,1.0,0,NULL,0,0);

                ref=IDirectSoundBuffer_Release(secondary);
866
                ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
867 868 869
                   "should have 0\n",ref);
            }
        }
870
EXIT1:
871
        ref=IDirectSoundBuffer_Release(primary);
872
        ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
873 874 875 876 877 878
           "should have 0\n",ref);
    }

    /* Set the CooperativeLevel back to normal */
    /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
    rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
879
    ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %08x\n", rc);
880 881 882

EXIT:
    ref=IDirectSound8_Release(dso);
883
    ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
884 885 886 887 888 889 890 891 892
    if (ref!=0)
        return DSERR_GENERIC;

    return rc;
}

static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
                                   LPCSTR lpcstrModule, LPVOID lpContext)
{
893
    HRESULT rc;
894
    trace("*** Testing %s - %s ***\n",lpcstrDescription,lpcstrModule);
895 896 897
    rc = test_dsound8(lpGuid);
    if (rc == DSERR_NODRIVER)
        trace("  No Driver\n");
898 899
    else if (rc == DSERR_ALLOCATED)
        trace("  Already In Use\n");
900 901
    else if (rc == E_FAIL)
        trace("  No Device\n");
902 903 904 905 906
    else {
        test_primary8(lpGuid);
        test_primary_secondary8(lpGuid);
        test_secondary8(lpGuid);
    }
907 908 909 910

    return 1;
}

911
static void dsound8_tests(void)
912 913
{
    HRESULT rc;
914
    rc=pDirectSoundEnumerateA(&dsenum_callback,NULL);
915
    ok(rc==DS_OK,"DirectSoundEnumerateA() failed: %08x\n",rc);
916 917
}

918

919 920 921 922 923 924
START_TEST(dsound8)
{
    HMODULE hDsound;

    CoInitialize(NULL);

925 926 927 928 929 930 931 932 933 934 935 936 937 938 939
    hDsound = LoadLibrary("dsound.dll");
    if (hDsound)
    {

        pDirectSoundEnumerateA = (void*)GetProcAddress(hDsound,
            "DirectSoundEnumerateA");
        pDirectSoundCreate8 = (void*)GetProcAddress(hDsound,
            "DirectSoundCreate8");
        if (pDirectSoundCreate8)
        {
            IDirectSound8_tests();
            dsound8_tests();
        }
        else
            skip("dsound8 test skipped\n");
940

941
        FreeLibrary(hDsound);
942
    }
943 944
    else
        skip("dsound.dll not found!\n");
945 946

    CoUninitialize();
947
}