2 * Unit tests for duplex functions
4 * Copyright (c) 2006 Robert Reif
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/test.h"
30 #include "dsound_test.h"
32 static HRESULT (WINAPI *pDirectSoundFullDuplexCreate)(LPCGUID, LPCGUID,
33 LPCDSCBUFFERDESC, LPCDSBUFFERDESC, HWND, DWORD, LPDIRECTSOUNDFULLDUPLEX *,
34 LPDIRECTSOUNDCAPTUREBUFFER8*, LPDIRECTSOUNDBUFFER8*, LPUNKNOWN)=NULL;
36 static void IDirectSoundFullDuplex_test(LPDIRECTSOUNDFULLDUPLEX dsfdo,
37 BOOL initialized, LPCGUID lpGuidCapture,
45 IDirectSoundCapture * dsc;
46 IDirectSoundFullDuplex * dsfd;
48 /* Try to Query for objects */
49 rc=IDirectSoundFullDuplex_QueryInterface(dsfdo,&IID_IUnknown,(LPVOID*)&unknown);
50 ok(rc==DS_OK,"IDirectSoundFullDuplex_QueryInterface(IID_IUnknown) failed: %08x\n", rc);
52 ref=IDirectSoundFullDuplex_Release(unknown);
53 ok(ref==0, "IDirectSoundFullDuplex_Release() has %d references, "
54 "should have 0\n", ref);
57 rc=IDirectSoundFullDuplex_QueryInterface(dsfdo,&IID_IDirectSound,(LPVOID*)&ds);
58 ok(rc==(initialized?DS_OK:E_NOINTERFACE),"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSound) failed: %08x\n", rc);
60 ref=IDirectSound_Release(ds);
61 ok(ref==0, "IDirectSound_Release() has %d references, "
62 "should have 0\n", ref);
65 rc=IDirectSoundFullDuplex_QueryInterface(dsfdo,&IID_IDirectSound8,(LPVOID*)&ds8);
66 ok(rc==(initialized?DS_OK:E_NOINTERFACE),"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSound8) "
69 IDirectSoundFullDuplex * dsfd1;
70 rc=IDirectSound8_QueryInterface(ds8,&IID_IDirectSoundFullDuplex,(LPVOID*)&dsfd1);
71 ok(rc==DS_OK,"IDirectSound8_QueryInterface(IID_IDirectSoundFullDuplex) "
74 ref=IDirectSoundFullDuplex_Release(dsfd1);
75 ok(ref==1, "IDirectSoundFullDuplex_Release() has %d references, "
76 "should have 1\n", ref);
78 ref=IDirectSound8_Release(ds8);
79 ok(ref==0, "IDirectSound8_Release() has %d references, "
80 "should have 0\n", ref);
83 rc=IDirectSoundFullDuplex_QueryInterface(dsfdo,&IID_IDirectSoundCapture,(LPVOID*)&dsc);
84 ok(rc==(initialized?DS_OK:E_NOINTERFACE),"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSoundCapture) "
87 ref=IDirectSoundCapture_Release(dsc);
88 ok(ref==0, "IDirectSoundCapture_Release() has %d references, "
89 "should have 0\n", ref);
92 rc=IDirectSoundFullDuplex_QueryInterface(dsfdo,&IID_IDirectSoundFullDuplex,(LPVOID*)&dsfd);
93 ok(rc==DS_OK,"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSoundFullDuplex) "
96 ok(dsfdo==dsfd, "different interfaces\n");
97 ref=IDirectSound8_Release(dsfd);
98 ok(ref==1, "IDirectSoundFullDuplex_Release() has %d references, should have 1\n", ref);
101 ref=IDirectSoundFullDuplex_Release(dsfdo);
102 ok(ref==0, "IDirectSoundFullDuplex_Release() has %d references, "
103 "should have 0\n", ref);
106 static void IDirectSoundFullDuplex_tests(void)
109 LPDIRECTSOUNDFULLDUPLEX dsfdo = NULL;
110 DSCBUFFERDESC DSCBufferDesc;
111 DSBUFFERDESC DSBufferDesc;
112 LPDIRECTSOUNDCAPTUREBUFFER8 pDSCBuffer8;
113 LPDIRECTSOUNDBUFFER8 pDSBuffer8;
116 trace("Testing IDirectSoundFullDuplex\n");
118 /* try the COM class factory method of creation with no devices specified */
119 rc=CoCreateInstance(&CLSID_DirectSoundFullDuplex, NULL,
120 CLSCTX_INPROC_SERVER, &IID_IDirectSoundFullDuplex,
122 ok(rc==S_OK||rc==REGDB_E_CLASSNOTREG||rc==CLASS_E_CLASSNOTAVAILABLE,
123 "CoCreateInstance(CLSID_DirectSoundFullDuplex) failed: 0x%08x\n", rc);
124 if (rc==REGDB_E_CLASSNOTREG) {
125 trace(" Class Not Registered\n");
127 } else if (rc==CLASS_E_CLASSNOTAVAILABLE) {
128 trace(" Class Not Available\n");
132 IDirectSoundFullDuplex_test(dsfdo, FALSE, NULL, NULL);
134 /* try the COM class factory method of creation with default devices
136 rc=CoCreateInstance(&CLSID_DirectSoundFullDuplex, NULL,
137 CLSCTX_INPROC_SERVER, &IID_IDirectSoundFullDuplex,
139 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSoundFullDuplex) failed: 0x%08x\n", rc);
141 IDirectSoundFullDuplex_test(dsfdo, FALSE, &DSDEVID_DefaultCapture,
142 &DSDEVID_DefaultPlayback);
144 /* try the COM class factory method of creation with default voice
145 * devices specified */
146 rc=CoCreateInstance(&CLSID_DirectSoundFullDuplex, NULL,
147 CLSCTX_INPROC_SERVER, &IID_IDirectSoundFullDuplex,
149 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSoundFullDuplex) failed: 0x%08x\n", rc);
151 IDirectSoundFullDuplex_test(dsfdo, FALSE, &DSDEVID_DefaultVoiceCapture,
152 &DSDEVID_DefaultVoicePlayback);
154 /* try the COM class factory method of creation with a bad
156 rc=CoCreateInstance(&CLSID_DirectSoundFullDuplex, NULL,
157 CLSCTX_INPROC_SERVER, &CLSID_DirectSoundPrivate,
159 ok(rc==E_NOINTERFACE,
160 "CoCreateInstance(CLSID_DirectSoundFullDuplex,CLSID_DirectSoundPrivate) "
161 "should have failed: 0x%08x\n", rc);
163 ZeroMemory(&wfex, sizeof(wfex));
164 wfex.wFormatTag = WAVE_FORMAT_PCM;
166 wfex.nSamplesPerSec = 8000;
167 wfex.wBitsPerSample = 16;
168 wfex.nBlockAlign = (wfex.wBitsPerSample * wfex.nChannels) / 8;
169 wfex.nAvgBytesPerSec = wfex.nSamplesPerSec * wfex.nBlockAlign;
171 ZeroMemory(&DSCBufferDesc, sizeof(DSCBufferDesc));
172 DSCBufferDesc.dwSize = sizeof(DSCBufferDesc);
173 DSCBufferDesc.dwFlags = DSCBCAPS_WAVEMAPPED;
174 DSCBufferDesc.dwBufferBytes = 8192;
175 DSCBufferDesc.lpwfxFormat = &wfex;
177 ZeroMemory(&DSBufferDesc, sizeof(DSBufferDesc));
178 DSBufferDesc.dwSize = sizeof(DSBufferDesc);
179 DSBufferDesc.dwFlags = DSBCAPS_GLOBALFOCUS;
180 DSBufferDesc.dwBufferBytes = 8192;
181 DSBufferDesc.lpwfxFormat = &wfex;
183 /* try with no device specified */
184 rc=pDirectSoundFullDuplexCreate(NULL,NULL,&DSCBufferDesc,&DSBufferDesc,
185 get_hwnd(),DSSCL_EXCLUSIVE ,&dsfdo,&pDSCBuffer8,
187 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL||rc==DSERR_INVALIDCALL,
188 "DirectSoundFullDuplexCreate(NULL,NULL) failed: %08x\n",rc);
189 if (rc==S_OK && dsfdo)
190 IDirectSoundFullDuplex_test(dsfdo, TRUE, NULL, NULL);
192 /* try with default devices specified */
193 rc=pDirectSoundFullDuplexCreate(&DSDEVID_DefaultCapture,
194 &DSDEVID_DefaultPlayback,&DSCBufferDesc,
195 &DSBufferDesc,get_hwnd(),DSSCL_EXCLUSIVE,&dsfdo,
196 &pDSCBuffer8,&pDSBuffer8,NULL);
197 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL||rc==DSERR_INVALIDCALL,
198 "DirectSoundFullDuplexCreate(DSDEVID_DefaultCapture,"
199 "DSDEVID_DefaultPlayback) failed: %08x\n", rc);
200 if (rc==DS_OK && dsfdo)
201 IDirectSoundFullDuplex_test(dsfdo, TRUE, NULL, NULL);
203 /* try with default voice devices specified */
204 rc=pDirectSoundFullDuplexCreate(&DSDEVID_DefaultVoiceCapture,
205 &DSDEVID_DefaultVoicePlayback,
206 &DSCBufferDesc,&DSBufferDesc,get_hwnd(),DSSCL_EXCLUSIVE,
207 &dsfdo,&pDSCBuffer8,&pDSBuffer8,NULL);
208 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL||rc==DSERR_INVALIDCALL,
209 "DirectSoundFullDuplexCreate(DSDEVID_DefaultVoiceCapture,"
210 "DSDEVID_DefaultVoicePlayback) failed: %08x\n", rc);
211 if (rc==DS_OK && dsfdo)
212 IDirectSoundFullDuplex_test(dsfdo, TRUE, NULL, NULL);
214 /* try with bad devices specified */
215 rc=pDirectSoundFullDuplexCreate(&DSDEVID_DefaultVoicePlayback,
216 &DSDEVID_DefaultVoiceCapture,
217 &DSCBufferDesc,&DSBufferDesc,get_hwnd(),DSSCL_EXCLUSIVE,
218 &dsfdo,&pDSCBuffer8,&pDSBuffer8,NULL);
219 ok(rc==DSERR_NODRIVER||rc==DSERR_INVALIDCALL,
220 "DirectSoundFullDuplexCreate(DSDEVID_DefaultVoicePlayback,"
221 "DSDEVID_DefaultVoiceCapture) should have failed: %08x\n", rc);
222 if (rc==DS_OK && dsfdo)
223 IDirectSoundFullDuplex_Release(dsfdo);
232 hDsound = LoadLibrary("dsound.dll");
236 pDirectSoundFullDuplexCreate=(void*)GetProcAddress(hDsound,
237 "DirectSoundFullDuplexCreate");
238 if (pDirectSoundFullDuplexCreate)
239 IDirectSoundFullDuplex_tests();
241 skip("duplex test skipped\n");
243 FreeLibrary(hDsound);
246 skip("dsound.dll not found!\n");