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 void IDirectSoundFullDuplex_test(LPDIRECTSOUNDFULLDUPLEX dsfdo
,
33 BOOL initialized
, LPCGUID lpGuidCapture
,
41 IDirectSoundCapture
* dsc
;
42 IDirectSoundFullDuplex
* dsfd
;
44 /* Try to Query for objects */
45 rc
=IDirectSoundFullDuplex_QueryInterface(dsfdo
,&IID_IUnknown
,(LPVOID
*)&unknown
);
46 ok(rc
==DS_OK
,"IDirectSoundFullDuplex_QueryInterface(IID_IUnknown) failed: %08x\n", rc
);
48 ref
= IUnknown_Release(unknown
);
49 ok(ref
==0, "IDirectSoundFullDuplex_Release() has %d references, "
50 "should have 0\n", ref
);
53 rc
=IDirectSoundFullDuplex_QueryInterface(dsfdo
,&IID_IDirectSound
,(LPVOID
*)&ds
);
54 ok(rc
==(initialized
?DS_OK
:E_NOINTERFACE
),"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSound) failed: %08x\n", rc
);
56 ref
=IDirectSound_Release(ds
);
57 ok(ref
==0, "IDirectSound_Release() has %d references, "
58 "should have 0\n", ref
);
61 rc
=IDirectSoundFullDuplex_QueryInterface(dsfdo
,&IID_IDirectSound8
,(LPVOID
*)&ds8
);
62 ok(rc
==(initialized
?DS_OK
:E_NOINTERFACE
),"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSound8) "
65 IDirectSoundFullDuplex
* dsfd1
;
66 rc
=IDirectSound8_QueryInterface(ds8
,&IID_IDirectSoundFullDuplex
,(LPVOID
*)&dsfd1
);
67 ok(rc
==DS_OK
,"IDirectSound8_QueryInterface(IID_IDirectSoundFullDuplex) "
70 ref
=IDirectSoundFullDuplex_Release(dsfd1
);
71 ok(ref
==1, "IDirectSoundFullDuplex_Release() has %d references, "
72 "should have 1\n", ref
);
74 ref
=IDirectSound8_Release(ds8
);
75 ok(ref
==0, "IDirectSound8_Release() has %d references, "
76 "should have 0\n", ref
);
79 rc
=IDirectSoundFullDuplex_QueryInterface(dsfdo
,&IID_IDirectSoundCapture
,(LPVOID
*)&dsc
);
80 ok(rc
==(initialized
?DS_OK
:E_NOINTERFACE
),"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSoundCapture) "
83 ref
=IDirectSoundCapture_Release(dsc
);
84 ok(ref
==0, "IDirectSoundCapture_Release() has %d references, "
85 "should have 0\n", ref
);
88 rc
=IDirectSoundFullDuplex_QueryInterface(dsfdo
,&IID_IDirectSoundFullDuplex
,(LPVOID
*)&dsfd
);
89 ok(rc
==DS_OK
,"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSoundFullDuplex) "
92 ok(dsfdo
==dsfd
, "different interfaces\n");
93 ref
=IDirectSoundFullDuplex_Release(dsfd
);
94 ok(ref
==1, "IDirectSoundFullDuplex_Release() has %d references, should have 1\n", ref
);
97 ref
=IDirectSoundFullDuplex_Release(dsfdo
);
98 ok(ref
==0, "IDirectSoundFullDuplex_Release() has %d references, "
99 "should have 0\n", ref
);
102 static void IDirectSoundFullDuplex_tests(void)
105 LPDIRECTSOUNDFULLDUPLEX dsfdo
= NULL
;
106 DSCBUFFERDESC DSCBufferDesc
;
107 DSBUFFERDESC DSBufferDesc
;
108 LPDIRECTSOUNDCAPTUREBUFFER8 pDSCBuffer8
;
109 LPDIRECTSOUNDBUFFER8 pDSBuffer8
;
112 trace("Testing IDirectSoundFullDuplex\n");
114 /* try the COM class factory method of creation with no devices specified */
115 rc
=CoCreateInstance(&CLSID_DirectSoundFullDuplex
, NULL
,
116 CLSCTX_INPROC_SERVER
, &IID_IDirectSoundFullDuplex
,
118 ok(rc
==S_OK
||rc
==REGDB_E_CLASSNOTREG
||rc
==CLASS_E_CLASSNOTAVAILABLE
,
119 "CoCreateInstance(CLSID_DirectSoundFullDuplex) failed: 0x%08x\n", rc
);
120 if (rc
==REGDB_E_CLASSNOTREG
) {
121 trace(" Class Not Registered\n");
123 } else if (rc
==CLASS_E_CLASSNOTAVAILABLE
) {
124 trace(" Class Not Available\n");
128 IDirectSoundFullDuplex_test(dsfdo
, FALSE
, NULL
, NULL
);
130 /* try the COM class factory method of creation with default devices
132 rc
=CoCreateInstance(&CLSID_DirectSoundFullDuplex
, NULL
,
133 CLSCTX_INPROC_SERVER
, &IID_IDirectSoundFullDuplex
,
135 ok(rc
==S_OK
,"CoCreateInstance(CLSID_DirectSoundFullDuplex) failed: 0x%08x\n", rc
);
137 IDirectSoundFullDuplex_test(dsfdo
, FALSE
, &DSDEVID_DefaultCapture
,
138 &DSDEVID_DefaultPlayback
);
140 /* try the COM class factory method of creation with default voice
141 * devices specified */
142 rc
=CoCreateInstance(&CLSID_DirectSoundFullDuplex
, NULL
,
143 CLSCTX_INPROC_SERVER
, &IID_IDirectSoundFullDuplex
,
145 ok(rc
==S_OK
,"CoCreateInstance(CLSID_DirectSoundFullDuplex) failed: 0x%08x\n", rc
);
147 IDirectSoundFullDuplex_test(dsfdo
, FALSE
, &DSDEVID_DefaultVoiceCapture
,
148 &DSDEVID_DefaultVoicePlayback
);
150 /* try the COM class factory method of creation with a bad
152 rc
=CoCreateInstance(&CLSID_DirectSoundFullDuplex
, NULL
,
153 CLSCTX_INPROC_SERVER
, &CLSID_DirectSoundPrivate
,
155 ok(rc
==E_NOINTERFACE
,
156 "CoCreateInstance(CLSID_DirectSoundFullDuplex,CLSID_DirectSoundPrivate) "
157 "should have failed: 0x%08x\n", rc
);
159 ZeroMemory(&wfex
, sizeof(wfex
));
160 wfex
.wFormatTag
= WAVE_FORMAT_PCM
;
162 wfex
.nSamplesPerSec
= 8000;
163 wfex
.wBitsPerSample
= 16;
164 wfex
.nBlockAlign
= (wfex
.wBitsPerSample
* wfex
.nChannels
) / 8;
165 wfex
.nAvgBytesPerSec
= wfex
.nSamplesPerSec
* wfex
.nBlockAlign
;
167 ZeroMemory(&DSCBufferDesc
, sizeof(DSCBufferDesc
));
168 DSCBufferDesc
.dwSize
= sizeof(DSCBufferDesc
);
169 DSCBufferDesc
.dwFlags
= DSCBCAPS_WAVEMAPPED
;
170 DSCBufferDesc
.dwBufferBytes
= 8192;
171 DSCBufferDesc
.lpwfxFormat
= &wfex
;
173 ZeroMemory(&DSBufferDesc
, sizeof(DSBufferDesc
));
174 DSBufferDesc
.dwSize
= sizeof(DSBufferDesc
);
175 DSBufferDesc
.dwFlags
= DSBCAPS_GLOBALFOCUS
;
176 DSBufferDesc
.dwBufferBytes
= 8192;
177 DSBufferDesc
.lpwfxFormat
= &wfex
;
179 /* try with no device specified */
180 rc
= DirectSoundFullDuplexCreate(NULL
, NULL
, &DSCBufferDesc
, &DSBufferDesc
,
181 get_hwnd(), DSSCL_EXCLUSIVE
, &dsfdo
, &pDSCBuffer8
, &pDSBuffer8
, NULL
);
182 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
||rc
==E_FAIL
||rc
==DSERR_INVALIDCALL
,
183 "DirectSoundFullDuplexCreate(NULL,NULL) failed: %08x\n",rc
);
184 if (rc
==S_OK
&& dsfdo
)
185 IDirectSoundFullDuplex_test(dsfdo
, TRUE
, NULL
, NULL
);
187 /* try with default devices specified */
188 rc
= DirectSoundFullDuplexCreate(&DSDEVID_DefaultCapture
,
189 &DSDEVID_DefaultPlayback
, &DSCBufferDesc
, &DSBufferDesc
, get_hwnd(),
190 DSSCL_EXCLUSIVE
, &dsfdo
, &pDSCBuffer8
,&pDSBuffer8
, NULL
);
191 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
||rc
==E_FAIL
||rc
==DSERR_INVALIDCALL
,
192 "DirectSoundFullDuplexCreate(DSDEVID_DefaultCapture,"
193 "DSDEVID_DefaultPlayback) failed: %08x\n", rc
);
194 if (rc
==DS_OK
&& dsfdo
)
195 IDirectSoundFullDuplex_test(dsfdo
, TRUE
, NULL
, NULL
);
197 /* try with default voice devices specified */
198 rc
= DirectSoundFullDuplexCreate(&DSDEVID_DefaultVoiceCapture
,
199 &DSDEVID_DefaultVoicePlayback
, &DSCBufferDesc
, &DSBufferDesc
,
200 get_hwnd(), DSSCL_EXCLUSIVE
, &dsfdo
, &pDSCBuffer8
, &pDSBuffer8
, NULL
);
201 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
||rc
==E_FAIL
||rc
==DSERR_INVALIDCALL
,
202 "DirectSoundFullDuplexCreate(DSDEVID_DefaultVoiceCapture,"
203 "DSDEVID_DefaultVoicePlayback) failed: %08x\n", rc
);
204 if (rc
==DS_OK
&& dsfdo
)
205 IDirectSoundFullDuplex_test(dsfdo
, TRUE
, NULL
, NULL
);
207 /* try with bad devices specified */
208 rc
= DirectSoundFullDuplexCreate(&DSDEVID_DefaultVoicePlayback
,
209 &DSDEVID_DefaultVoiceCapture
, &DSCBufferDesc
, &DSBufferDesc
,
210 get_hwnd(), DSSCL_EXCLUSIVE
, &dsfdo
, &pDSCBuffer8
, &pDSBuffer8
, NULL
);
211 ok(rc
==DSERR_NODRIVER
||rc
==DSERR_INVALIDCALL
,
212 "DirectSoundFullDuplexCreate(DSDEVID_DefaultVoicePlayback,"
213 "DSDEVID_DefaultVoiceCapture) should have failed: %08x\n", rc
);
214 if (rc
==DS_OK
&& dsfdo
)
215 IDirectSoundFullDuplex_Release(dsfdo
);
218 static void test_COM(void)
220 IDirectSoundFullDuplex
*dsfd
= (IDirectSoundFullDuplex
*)0xdeadbeef;
223 IDirectSoundCapture
*dsc
;
224 IUnknown
*unk
, *unk8
;
225 IDirectSoundBuffer8
*dsb8
;
226 IDirectSoundCaptureBuffer8
*dscb8
;
227 DSBUFFERDESC bufdesc
;
228 DSCBUFFERDESC cbufdesc
;
233 /* COM aggregation */
234 hr
= CoCreateInstance(&CLSID_DirectSoundFullDuplex
, (IUnknown
*)0xdeadbeef, CLSCTX_INPROC_SERVER
,
235 &IID_IUnknown
, (void**)&dsfd
);
236 ok(hr
== CLASS_E_NOAGGREGATION
,
237 "DirectSoundFullDuplex create failed: %08x, expected CLASS_E_NOAGGREGATION\n", hr
);
238 ok(!dsfd
, "dsfd = %p\n", dsfd
);
241 hr
= CoCreateInstance(&CLSID_DirectSoundFullDuplex
, NULL
, CLSCTX_INPROC_SERVER
,
242 &IID_IDirectSound3DBuffer
, (void**)&dsfd
);
243 ok(hr
== E_NOINTERFACE
,
244 "DirectSoundFullDuplex create failed: %08x, expected E_NOINTERFACE\n", hr
);
246 /* Different refcount for IDirectSoundFullDuplex and for IUnknown */
247 hr
= CoCreateInstance(&CLSID_DirectSoundFullDuplex
, NULL
, CLSCTX_INPROC_SERVER
,
248 &IID_IDirectSoundFullDuplex
, (void**)&dsfd
);
249 ok(hr
== S_OK
, "DirectSoundFullDuplex create failed: %08x, expected S_OK\n", hr
);
250 refcount
= IDirectSoundFullDuplex_AddRef(dsfd
);
251 ok(refcount
== 2, "refcount == %u, expected 2\n", refcount
);
252 hr
= IDirectSoundFullDuplex_QueryInterface(dsfd
, &IID_IUnknown
, (void**)&unk
);
253 ok(hr
== S_OK
, "QueryInterface for IID_IUnknown failed: %08x\n", hr
);
254 refcount
= IUnknown_AddRef(unk
);
255 ok(refcount
== 2, "refcount == %u, expected 2\n", refcount
);
257 /* Not initialized */
258 hr
= IDirectSoundFullDuplex_QueryInterface(dsfd
, &IID_IDirectSound8
, (void**)&ds8
);
259 ok(hr
== E_NOINTERFACE
,
260 "QueryInterface for IID_IDirectSound8 failed: %08x, expected E_NOINTERFACE\n", hr
);
261 hr
= IDirectSoundFullDuplex_QueryInterface(dsfd
, &IID_IDirectSoundCapture
, (void**)&dsc
);
262 ok(hr
== E_NOINTERFACE
,
263 "QueryInterface for IID_IDirectSoundCapture failed: %08x, expected E_NOINTERFACE\n", hr
);
265 init_format(&wfx
, WAVE_FORMAT_PCM
, 44100, 16, 1);
266 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
267 bufdesc
.dwSize
= sizeof(bufdesc
);
268 bufdesc
.dwBufferBytes
= wfx
.nAvgBytesPerSec
;
269 bufdesc
.lpwfxFormat
= &wfx
;
270 ZeroMemory(&cbufdesc
, sizeof(cbufdesc
));
271 cbufdesc
.dwSize
= sizeof(cbufdesc
);
272 cbufdesc
.dwBufferBytes
= wfx
.nAvgBytesPerSec
;
273 cbufdesc
.lpwfxFormat
= &wfx
;
274 hr
= IDirectSoundFullDuplex_Initialize(dsfd
, NULL
, NULL
, &cbufdesc
, &bufdesc
, get_hwnd(),
275 DSSCL_EXCLUSIVE
, NULL
, NULL
);
276 ok(hr
== E_INVALIDARG
,
277 "IDirectSoundFullDuplex_Initialize failed: %08x, expected E_INVALIDARG\n", hr
);
278 hr
= IDirectSoundFullDuplex_Initialize(dsfd
, NULL
, NULL
, &cbufdesc
, &bufdesc
, get_hwnd(),
279 DSSCL_EXCLUSIVE
, &dscb8
, &dsb8
);
280 if (hr
== DSERR_NODRIVER
|| hr
== DSERR_INVALIDCALL
) {
284 ok(hr
== S_OK
, "IDirectSoundFullDuplex_Initialize failed: %08x\n", hr
);
286 /* IDirectSound and IDirectSound8 */
287 hr
= IDirectSoundFullDuplex_QueryInterface(dsfd
, &IID_IDirectSound8
, (void**)&ds8
);
288 ok(hr
== S_OK
, "QueryInterface for IID_IDirectSound8 failed: %08x\n", hr
);
289 refcount
= IDirectSound8_AddRef(ds8
);
290 ok(refcount
== 2, "refcount == %u, expected 2\n", refcount
);
291 hr
= IDirectSoundFullDuplex_QueryInterface(dsfd
, &IID_IDirectSound
, (void**)&ds
);
292 ok(hr
== S_OK
, "QueryInterface for IID_IDirectSound failed: %08x\n", hr
);
293 refcount
= IDirectSound8_AddRef(ds8
);
294 ok(refcount
== 4, "refcount == %u, expected 4\n", refcount
);
295 refcount
= IDirectSound_AddRef(ds
);
296 ok(refcount
== 5, "refcount == %u, expected 5\n", refcount
);
297 hr
= IDirectSound8_QueryInterface(ds8
, &IID_IUnknown
, (void**)&unk8
);
298 ok(hr
== S_OK
, "QueryInterface for IID_IUnknown failed: %08x\n", hr
);
299 ok(unk
== unk8
, "Got different IUnknown when QI'ing IDirectSoundFullDuplex and IDirectSound\n");
300 refcount
= IUnknown_AddRef(unk8
);
301 ok(refcount
== 4, "refcount == %u, expected 4\n", refcount
);
302 refcount
= IDirectSound_AddRef(ds
);
303 ok(refcount
== 6, "refcount == %u, expected 6\n", refcount
);
304 refcount
= IDirectSoundFullDuplex_AddRef(dsfd
);
305 ok(refcount
== 3, "refcount == %u, expected 3\n", refcount
);
307 /* IDirectSoundCapture */
308 hr
= IDirectSoundFullDuplex_QueryInterface(dsfd
, &IID_IDirectSoundCapture
, (void**)&dsc
);
309 ok(hr
== S_OK
, "QueryInterface for IID_IDirectSoundCapture failed: %08x\n", hr
);
310 refcount
= IDirectSoundCapture_AddRef(dsc
);
311 ok(refcount
== 2, "refcount == %u, expected 2\n", refcount
);
312 refcount
= IDirectSoundFullDuplex_AddRef(dsfd
);
313 ok(refcount
== 4, "refcount == %u, expected 4\n", refcount
);
314 hr
= IDirectSound8_QueryInterface(ds8
, &IID_IUnknown
, (void**)&unk8
);
315 ok(hr
== S_OK
, "QueryInterface for IID_IUnknown failed: %08x\n", hr
);
317 "Got different IUnknown when QI'ing IDirectSoundFullDuplex and IDirectSoundCapture\n");
318 refcount
= IUnknown_AddRef(unk8
);
319 ok(refcount
== 6, "refcount == %u, expected 6\n", refcount
);
321 IDirectSoundBuffer8_Release(dsb8
);
322 IDirectSoundCaptureBuffer8_Release(dscb8
);
323 while (IDirectSound8_Release(ds8
));
324 while (IDirectSoundCapture_Release(dsc
));
325 while (IDirectSoundFullDuplex_Release(dsfd
));
326 while (IUnknown_Release(unk
));
334 IDirectSoundFullDuplex_tests();