fdopen: don't rewind the file after creating the FILE* handle. Added
[wine] / dlls / dsound / tests / dsound.c
1 /*
2  * Unit tests for dsound functions
3  *
4  * Copyright (c) 2002 Francois Gouget
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 #include "wine/test.h"
22 #include "dsound.h"
23
24
25
26 BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
27                             LPCSTR lpcstrModule, LPVOID lpContext)
28 {
29     HRESULT rc;
30     LPDIRECTSOUND dso=NULL;
31     LPDIRECTSOUNDBUFFER dsbo=NULL;
32     DSCAPS dscaps;
33     DSBCAPS dsbcaps;
34     DSBUFFERDESC bufdesc;
35     WAVEFORMATEX wfx,wfx2;
36     DWORD size,status,freq;
37
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);
41     if (rc!=DS_OK)
42         goto EXIT;
43
44     dscaps.dwSize=0;
45     rc=IDirectSound_GetCaps(dso,&dscaps);
46     ok(rc==DSERR_INVALIDPARAM,"GetCaps should have failed: 0x%lx\n",rc);
47
48     dscaps.dwSize=sizeof(dscaps);
49     rc=IDirectSound_GetCaps(dso,&dscaps);
50     ok(rc==DS_OK,"GetCaps failed: 0x%lx\n",rc);
51     if (rc==DS_OK) {
52         trace("  DirectSound Caps: flags=0x%08lx secondary min=%ld max=%ld\n",
53               dscaps.dwFlags,dscaps.dwMinSecondarySampleRate,
54               dscaps.dwMaxSecondarySampleRate);
55     }
56
57     /* Testing the primary buffers */
58     rc=IDirectSound_SetCooperativeLevel(dso,GetDesktopWindow(),DSSCL_PRIORITY);
59     ok(rc==DS_OK,"SetCooperativeLevel failed: 0x%lx\n",rc);
60     if (rc!=DS_OK)
61         goto EXIT;
62
63     bufdesc.dwSize=sizeof(bufdesc);
64     bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
65     bufdesc.dwBufferBytes=0;
66     bufdesc.dwReserved=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);
70     if (rc!=DS_OK)
71         goto EXIT;
72
73     dsbcaps.dwSize=0;
74     rc=IDirectSoundBuffer_GetCaps(dsbo,&dsbcaps);
75     ok(rc==DSERR_INVALIDPARAM,"GetCaps should have failed: 0x%lx\n",rc);
76
77     dsbcaps.dwSize=sizeof(dsbcaps);
78     rc=IDirectSoundBuffer_GetCaps(dsbo,&dsbcaps);
79     ok(rc==DS_OK,"GetCaps failed: 0x%lx\n",rc);
80     if (rc==DS_OK) {
81         trace("  PrimaryBuffer Caps: flags=0x%08lx size=%ld\n",dsbcaps.dwFlags,dsbcaps.dwBufferBytes);
82     }
83
84     /* Query the format size. Note that it may not match sizeof(wfx) */
85     size=0;
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",
89        rc,size);
90
91     rc=IDirectSoundBuffer_GetFormat(dsbo,&wfx,sizeof(wfx),NULL);
92     ok(rc==DS_OK,"GetFormat failed: 0x%lx\n",rc);
93     if (rc==DS_OK) {
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);
97     }
98
99     rc=IDirectSoundBuffer_GetFrequency(dsbo,&freq);
100     ok(rc==DS_OK || rc==DSERR_CONTROLUNAVAIL,"GetFrequency failed: 0x%lx\n",rc);
101     if (rc==DS_OK) {
102         ok(freq==wfx.nSamplesPerSec,
103            "The frequency returned by GetFrequency %ld does not match the format %ld\n",
104            freq,wfx.nSamplesPerSec);
105     }
106
107     rc=IDirectSoundBuffer_GetStatus(dsbo,&status);
108     ok(rc==DS_OK,"GetStatus failed: 0x%lx\n",rc);
109     if (rc==DS_OK) {
110         trace("  status=0x%04lx\n",status);
111     }
112
113     wfx2.wFormatTag=WAVE_FORMAT_PCM;
114     wfx2.nChannels=2;
115     wfx2.wBitsPerSample=16;
116     wfx2.nSamplesPerSec=11025;
117     wfx2.nBlockAlign=wfx2.nChannels*wfx2.wBitsPerSample/8;
118     wfx2.nAvgBytesPerSec=wfx2.nSamplesPerSec*wfx2.nBlockAlign;
119     wfx2.cbSize=0;
120     rc=IDirectSoundBuffer_SetFormat(dsbo,&wfx2);
121     ok(rc==DS_OK,"SetFormat failed: 0x%lx\n",rc);
122
123     rc=IDirectSoundBuffer_GetFormat(dsbo,&wfx,sizeof(wfx),NULL);
124     ok(rc==DS_OK,"GetFormat failed: 0x%lx\n",rc);
125     if (rc==DS_OK) {
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);
132     }
133
134 EXIT:
135     if (dsbo!=NULL)
136         IDirectSoundBuffer_Release(dsbo);
137     if (dso!=NULL)
138         IDirectSound_Release(dso);
139     return 1;
140 }
141
142 void dsound_out_tests()
143 {
144     HRESULT rc;
145     rc=DirectSoundEnumerateA(&dsenum_callback,NULL);
146     ok(rc==DS_OK,"DirectSoundEnumerate failed: %ld\n",rc);
147 }
148
149 START_TEST(dsound)
150 {
151     dsound_out_tests();
152 }