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
);
100 ref
=IDirectSoundFullDuplex_Release(dsfdo
);
101 ok(ref
==0, "IDirectSoundFullDuplex_Release() has %d references, "
102 "should have 0\n", ref
);
105 static void IDirectSoundFullDuplex_tests(void)
108 LPDIRECTSOUNDFULLDUPLEX dsfdo
= NULL
;
109 DSCBUFFERDESC DSCBufferDesc
;
110 DSBUFFERDESC DSBufferDesc
;
111 LPDIRECTSOUNDCAPTUREBUFFER8 pDSCBuffer8
;
112 LPDIRECTSOUNDBUFFER8 pDSBuffer8
;
115 trace("Testing IDirectSoundFullDuplex\n");
117 /* try the COM class factory method of creation with no devices specified */
118 rc
=CoCreateInstance(&CLSID_DirectSoundFullDuplex
, NULL
,
119 CLSCTX_INPROC_SERVER
, &IID_IDirectSoundFullDuplex
,
121 ok(rc
==S_OK
||rc
==REGDB_E_CLASSNOTREG
||rc
==CLASS_E_CLASSNOTAVAILABLE
,
122 "CoCreateInstance(CLSID_DirectSoundFullDuplex) failed: 0x%08x\n", rc
);
123 if (rc
==REGDB_E_CLASSNOTREG
) {
124 trace(" Class Not Registered\n");
126 } else if (rc
==CLASS_E_CLASSNOTAVAILABLE
) {
127 trace(" Class Not Available\n");
131 IDirectSoundFullDuplex_test(dsfdo
, FALSE
, NULL
, NULL
);
133 /* try the COM class factory method of creation with default devices
135 rc
=CoCreateInstance(&CLSID_DirectSoundFullDuplex
, NULL
,
136 CLSCTX_INPROC_SERVER
, &IID_IDirectSoundFullDuplex
,
138 ok(rc
==S_OK
,"CoCreateInstance(CLSID_DirectSoundFullDuplex) failed: 0x%08x\n", rc
);
140 IDirectSoundFullDuplex_test(dsfdo
, FALSE
, &DSDEVID_DefaultCapture
,
141 &DSDEVID_DefaultPlayback
);
143 /* try the COM class factory method of creation with default voice
144 * devices specified */
145 rc
=CoCreateInstance(&CLSID_DirectSoundFullDuplex
, NULL
,
146 CLSCTX_INPROC_SERVER
, &IID_IDirectSoundFullDuplex
,
148 ok(rc
==S_OK
,"CoCreateInstance(CLSID_DirectSoundFullDuplex) failed: 0x%08x\n", rc
);
150 IDirectSoundFullDuplex_test(dsfdo
, FALSE
, &DSDEVID_DefaultVoiceCapture
,
151 &DSDEVID_DefaultVoicePlayback
);
153 /* try the COM class factory method of creation with a bad
155 rc
=CoCreateInstance(&CLSID_DirectSoundFullDuplex
, NULL
,
156 CLSCTX_INPROC_SERVER
, &CLSID_DirectSoundPrivate
,
158 ok(rc
==E_NOINTERFACE
,
159 "CoCreateInstance(CLSID_DirectSoundFullDuplex,CLSID_DirectSoundPrivate) "
160 "should have failed: 0x%08x\n", rc
);
162 ZeroMemory(&wfex
, sizeof(wfex
));
163 wfex
.wFormatTag
= WAVE_FORMAT_PCM
;
165 wfex
.nSamplesPerSec
= 8000;
166 wfex
.wBitsPerSample
= 16;
167 wfex
.nBlockAlign
= (wfex
.wBitsPerSample
* wfex
.nChannels
) / 8;
168 wfex
.nAvgBytesPerSec
= wfex
.nSamplesPerSec
* wfex
.nBlockAlign
;
170 ZeroMemory(&DSCBufferDesc
, sizeof(DSCBufferDesc
));
171 DSCBufferDesc
.dwSize
= sizeof(DSCBufferDesc
);
172 DSCBufferDesc
.dwFlags
= DSCBCAPS_WAVEMAPPED
;
173 DSCBufferDesc
.dwBufferBytes
= 8192;
174 DSCBufferDesc
.lpwfxFormat
= &wfex
;
176 ZeroMemory(&DSBufferDesc
, sizeof(DSBufferDesc
));
177 DSBufferDesc
.dwSize
= sizeof(DSBufferDesc
);
178 DSBufferDesc
.dwFlags
= DSBCAPS_GLOBALFOCUS
;
179 DSBufferDesc
.dwBufferBytes
= 8192;
180 DSBufferDesc
.lpwfxFormat
= &wfex
;
182 /* try with no device specified */
183 rc
=pDirectSoundFullDuplexCreate(NULL
,NULL
,&DSCBufferDesc
,&DSBufferDesc
,
184 get_hwnd(),DSSCL_EXCLUSIVE
,&dsfdo
,&pDSCBuffer8
,
186 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
||rc
==E_FAIL
||rc
==DSERR_INVALIDCALL
,
187 "DirectSoundFullDuplexCreate(NULL,NULL) failed: %08x\n",rc
);
188 if (rc
==S_OK
&& dsfdo
)
189 IDirectSoundFullDuplex_test(dsfdo
, TRUE
, NULL
, NULL
);
191 /* try with default devices specified */
192 rc
=pDirectSoundFullDuplexCreate(&DSDEVID_DefaultCapture
,
193 &DSDEVID_DefaultPlayback
,&DSCBufferDesc
,
194 &DSBufferDesc
,get_hwnd(),DSSCL_EXCLUSIVE
,&dsfdo
,
195 &pDSCBuffer8
,&pDSBuffer8
,NULL
);
196 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
||rc
==E_FAIL
||rc
==DSERR_INVALIDCALL
,
197 "DirectSoundFullDuplexCreate(DSDEVID_DefaultCapture,"
198 "DSDEVID_DefaultPlayback) failed: %08x\n", rc
);
199 if (rc
==DS_OK
&& dsfdo
)
200 IDirectSoundFullDuplex_test(dsfdo
, TRUE
, NULL
, NULL
);
202 /* try with default voice devices specified */
203 rc
=pDirectSoundFullDuplexCreate(&DSDEVID_DefaultVoiceCapture
,
204 &DSDEVID_DefaultVoicePlayback
,
205 &DSCBufferDesc
,&DSBufferDesc
,get_hwnd(),DSSCL_EXCLUSIVE
,
206 &dsfdo
,&pDSCBuffer8
,&pDSBuffer8
,NULL
);
207 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
||rc
==E_FAIL
||rc
==DSERR_INVALIDCALL
,
208 "DirectSoundFullDuplexCreate(DSDEVID_DefaultVoiceCapture,"
209 "DSDEVID_DefaultVoicePlayback) failed: %08x\n", rc
);
210 if (rc
==DS_OK
&& dsfdo
)
211 IDirectSoundFullDuplex_test(dsfdo
, TRUE
, NULL
, NULL
);
213 /* try with bad devices specified */
214 rc
=pDirectSoundFullDuplexCreate(&DSDEVID_DefaultVoicePlayback
,
215 &DSDEVID_DefaultVoiceCapture
,
216 &DSCBufferDesc
,&DSBufferDesc
,get_hwnd(),DSSCL_EXCLUSIVE
,
217 &dsfdo
,&pDSCBuffer8
,&pDSBuffer8
,NULL
);
218 ok(rc
==DSERR_NODRIVER
||rc
==DSERR_INVALIDCALL
,
219 "DirectSoundFullDuplexCreate(DSDEVID_DefaultVoicePlayback,"
220 "DSDEVID_DefaultVoiceCapture) should have failed: %08x\n", rc
);
221 if (rc
==DS_OK
&& dsfdo
)
222 IDirectSoundFullDuplex_Release(dsfdo
);
231 hDsound
= LoadLibrary("dsound.dll");
235 pDirectSoundFullDuplexCreate
=(void*)GetProcAddress(hDsound
,
236 "DirectSoundFullDuplexCreate");
237 if (pDirectSoundFullDuplexCreate
)
238 IDirectSoundFullDuplex_tests();
240 skip("duplex test skipped\n");
242 FreeLibrary(hDsound
);
245 skip("dsound.dll not found!\n");