2 * Unit tests for dsound functions
4 * Copyright (c) 2002 Francois Gouget
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "wine/test.h"
26 BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
27 LPCSTR lpcstrModule, LPVOID lpContext)
30 LPDIRECTSOUND dso=NULL;
31 LPDIRECTSOUNDBUFFER dsbo=NULL;
35 WAVEFORMATEX wfx,wfx2;
36 DWORD size,status,freq;
38 trace("Testing %s - %s\n",lpcstrDescription,lpcstrModule);
39 rc=DirectSoundCreate(lpGuid,&dso,NULL);
40 ok(rc==DS_OK,"DirectSoundCreate failed: 0x%lx\n",rc);
45 rc=IDirectSound_GetCaps(dso,&dscaps);
46 ok(rc==DSERR_INVALIDPARAM,"GetCaps should have failed: 0x%lx\n",rc);
48 dscaps.dwSize=sizeof(dscaps);
49 rc=IDirectSound_GetCaps(dso,&dscaps);
50 ok(rc==DS_OK,"GetCaps failed: 0x%lx\n",rc);
52 trace(" DirectSound Caps: flags=0x%08lx secondary min=%ld max=%ld\n",
53 dscaps.dwFlags,dscaps.dwMinSecondarySampleRate,
54 dscaps.dwMaxSecondarySampleRate);
57 /* Testing the primary buffers */
58 rc=IDirectSound_SetCooperativeLevel(dso,GetDesktopWindow(),DSSCL_PRIORITY);
59 ok(rc==DS_OK,"SetCooperativeLevel failed: 0x%lx\n",rc);
63 bufdesc.dwSize=sizeof(bufdesc);
64 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
65 bufdesc.dwBufferBytes=0;
67 bufdesc.lpwfxFormat=NULL;
68 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&dsbo,NULL);
69 ok(rc==DS_OK,"CreateSoundBuffer failed to create a primary buffer 0x%lx\n",rc);
74 rc=IDirectSoundBuffer_GetCaps(dsbo,&dsbcaps);
75 ok(rc==DSERR_INVALIDPARAM,"GetCaps should have failed: 0x%lx\n",rc);
77 dsbcaps.dwSize=sizeof(dsbcaps);
78 rc=IDirectSoundBuffer_GetCaps(dsbo,&dsbcaps);
79 ok(rc==DS_OK,"GetCaps failed: 0x%lx\n",rc);
81 trace(" PrimaryBuffer Caps: flags=0x%08lx size=%ld\n",dsbcaps.dwFlags,dsbcaps.dwBufferBytes);
84 /* Query the format size. Note that it may not match sizeof(wfx) */
86 rc=IDirectSoundBuffer_GetFormat(dsbo,NULL,0,&size);
87 ok(rc==DS_OK && size!=0,
88 "GetFormat should have returned the needed size: rc=0x%lx size=%ld\n",
91 rc=IDirectSoundBuffer_GetFormat(dsbo,&wfx,sizeof(wfx),NULL);
92 ok(rc==DS_OK,"GetFormat failed: 0x%lx\n",rc);
94 trace(" tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
95 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
96 wfx.nAvgBytesPerSec,wfx.nBlockAlign);
99 rc=IDirectSoundBuffer_GetFrequency(dsbo,&freq);
100 ok(rc==DS_OK || rc==DSERR_CONTROLUNAVAIL,"GetFrequency failed: 0x%lx\n",rc);
102 ok(freq==wfx.nSamplesPerSec,
103 "The frequency returned by GetFrequency %ld does not match the format %ld\n",
104 freq,wfx.nSamplesPerSec);
107 rc=IDirectSoundBuffer_GetStatus(dsbo,&status);
108 ok(rc==DS_OK,"GetStatus failed: 0x%lx\n",rc);
110 trace(" status=0x%04lx\n",status);
113 wfx2.wFormatTag=WAVE_FORMAT_PCM;
115 wfx2.wBitsPerSample=16;
116 wfx2.nSamplesPerSec=11025;
117 wfx2.nBlockAlign=wfx2.nChannels*wfx2.wBitsPerSample/8;
118 wfx2.nAvgBytesPerSec=wfx2.nSamplesPerSec*wfx2.nBlockAlign;
120 rc=IDirectSoundBuffer_SetFormat(dsbo,&wfx2);
121 ok(rc==DS_OK,"SetFormat failed: 0x%lx\n",rc);
123 rc=IDirectSoundBuffer_GetFormat(dsbo,&wfx,sizeof(wfx),NULL);
124 ok(rc==DS_OK,"GetFormat failed: 0x%lx\n",rc);
126 ok(wfx.wFormatTag==wfx2.wFormatTag && wfx.nChannels==wfx2.nChannels &&
127 wfx.wBitsPerSample==wfx2.wBitsPerSample && wfx.nSamplesPerSec==wfx2.nSamplesPerSec &&
128 wfx.nBlockAlign==wfx2.nBlockAlign && wfx.nAvgBytesPerSec==wfx2.nAvgBytesPerSec,
129 "SetFormat did not work right: tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
130 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
131 wfx.nAvgBytesPerSec,wfx.nBlockAlign);
136 IDirectSoundBuffer_Release(dsbo);
138 IDirectSound_Release(dso);
142 void dsound_out_tests()
145 rc=DirectSoundEnumerateA(&dsenum_callback,NULL);
146 ok(rc==DS_OK,"DirectSoundEnumerate failed: %ld\n",rc);