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
21 #define NONAMELESSSTRUCT
22 #define NONAMELESSUNION
27 #include "wine/test.h"
33 #include "dsound_test.h"
35 static HRESULT (WINAPI
*pDirectSoundFullDuplexCreate
)(LPCGUID
, LPCGUID
,
36 LPCDSCBUFFERDESC
, LPCDSBUFFERDESC
, HWND
, DWORD
, LPDIRECTSOUNDFULLDUPLEX
*,
37 LPDIRECTSOUNDCAPTUREBUFFER8
*, LPDIRECTSOUNDBUFFER8
*, LPUNKNOWN
)=NULL
;
39 static void IDirectSoundFullDuplex_test(LPDIRECTSOUNDFULLDUPLEX dsfdo
,
40 BOOL initialized
, LPCGUID lpGuidCapture
,
48 IDirectSoundCapture
* dsc
;
49 IDirectSoundFullDuplex
* dsfd
;
51 /* Try to Query for objects */
52 rc
=IDirectSoundFullDuplex_QueryInterface(dsfdo
,&IID_IUnknown
,(LPVOID
*)&unknown
);
53 ok(rc
==DS_OK
,"IDirectSoundFullDuplex_QueryInterface(IID_IUnknown) failed: %s\n",
54 DXGetErrorString8(rc
));
56 ref
=IDirectSoundFullDuplex_Release(unknown
);
57 ok(ref
==0, "IDirectSoundFullDuplex_Release() has %d references, "
58 "should have 0\n", ref
);
61 rc
=IDirectSoundFullDuplex_QueryInterface(dsfdo
,&IID_IDirectSound
,(LPVOID
*)&ds
);
62 ok(rc
==(initialized
?DS_OK
:E_NOINTERFACE
),"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSound) failed: %s\n",
63 DXGetErrorString8(rc
));
65 ref
=IDirectSound_Release(ds
);
66 ok(ref
==0, "IDirectSound_Release() has %d references, "
67 "should have 0\n", ref
);
70 rc
=IDirectSoundFullDuplex_QueryInterface(dsfdo
,&IID_IDirectSound8
,(LPVOID
*)&ds8
);
71 ok(rc
==(initialized
?DS_OK
:E_NOINTERFACE
),"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSound8) "
72 "failed: %s\n",DXGetErrorString8(rc
));
74 IDirectSoundFullDuplex
* dsfd1
;
75 rc
=IDirectSound8_QueryInterface(ds8
,&IID_IDirectSoundFullDuplex
,(LPVOID
*)&dsfd1
);
76 ok(rc
==DS_OK
,"IDirectSound8_QueryInterface(IID_IDirectSoundFullDuplex) "
77 "failed: %s\n",DXGetErrorString8(rc
));
79 ref
=IDirectSoundFullDuplex_Release(dsfd1
);
80 ok(ref
==1, "IDirectSoundFullDuplex_Release() has %d references, "
81 "should have 1\n", ref
);
83 ref
=IDirectSound8_Release(ds8
);
84 ok(ref
==0, "IDirectSound8_Release() has %d references, "
85 "should have 0\n", ref
);
88 rc
=IDirectSoundFullDuplex_QueryInterface(dsfdo
,&IID_IDirectSoundCapture
,(LPVOID
*)&dsc
);
89 ok(rc
==(initialized
?DS_OK
:E_NOINTERFACE
),"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSoundCapture) "
90 "failed: %s\n",DXGetErrorString8(rc
));
92 ref
=IDirectSoundCapture_Release(dsc
);
93 ok(ref
==0, "IDirectSoundCapture_Release() has %d references, "
94 "should have 0\n", ref
);
97 rc
=IDirectSoundFullDuplex_QueryInterface(dsfdo
,&IID_IDirectSoundFullDuplex
,(LPVOID
*)&dsfd
);
98 ok(rc
==DS_OK
,"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSoundFullDuplex) "
99 "failed: %s\n",DXGetErrorString8(rc
));
101 ok (dsfdo
==dsfd
, "different interfaces\n");
102 ref
=IDirectSound8_Release(dsfd
);
105 ref
=IDirectSoundFullDuplex_Release(dsfdo
);
106 ok(ref
==0, "IDirectSoundFullDuplex_Release() has %d references, "
107 "should have 0\n", ref
);
110 static void IDirectSoundFullDuplex_tests(void)
113 LPDIRECTSOUNDFULLDUPLEX dsfdo
= NULL
;
114 DSCBUFFERDESC DSCBufferDesc
;
115 DSBUFFERDESC DSBufferDesc
;
116 LPDIRECTSOUNDCAPTUREBUFFER8 pDSCBuffer8
;
117 LPDIRECTSOUNDBUFFER8 pDSBuffer8
;
120 trace("Testing IDirectSoundFullDuplex\n");
122 /* try the COM class factory method of creation with no devices specified */
123 rc
=CoCreateInstance(&CLSID_DirectSoundFullDuplex
, NULL
,
124 CLSCTX_INPROC_SERVER
, &IID_IDirectSoundFullDuplex
,
126 ok(rc
==S_OK
||rc
==REGDB_E_CLASSNOTREG
||rc
==CLASS_E_CLASSNOTAVAILABLE
,
127 "CoCreateInstance(CLSID_DirectSoundFullDuplex) failed: %s (0x%08lx)\n",
128 DXGetErrorString8(rc
), rc
);
129 if (rc
==REGDB_E_CLASSNOTREG
) {
130 trace(" Class Not Registered\n");
132 } else if (rc
==CLASS_E_CLASSNOTAVAILABLE
) {
133 trace(" Class Not Available\n");
137 IDirectSoundFullDuplex_test(dsfdo
, FALSE
, NULL
, NULL
);
139 /* try the COM class factory method of creation with default devices
141 rc
=CoCreateInstance(&CLSID_DirectSoundFullDuplex
, NULL
,
142 CLSCTX_INPROC_SERVER
, &IID_IDirectSoundFullDuplex
,
144 ok(rc
==S_OK
,"CoCreateInstance(CLSID_DirectSoundFullDuplex) failed: %s (0x%08lx)\n",
145 DXGetErrorString8(rc
), rc
);
147 IDirectSoundFullDuplex_test(dsfdo
, FALSE
, &DSDEVID_DefaultCapture
,
148 &DSDEVID_DefaultPlayback
);
150 /* try the COM class factory method of creation with default voice
151 * devices specified */
152 rc
=CoCreateInstance(&CLSID_DirectSoundFullDuplex
, NULL
,
153 CLSCTX_INPROC_SERVER
, &IID_IDirectSoundFullDuplex
,
155 ok(rc
==S_OK
,"CoCreateInstance(CLSID_DirectSoundFullDuplex) failed: %s (0x%08lx)\n",
156 DXGetErrorString8(rc
), rc
);
158 IDirectSoundFullDuplex_test(dsfdo
, FALSE
, &DSDEVID_DefaultVoiceCapture
,
159 &DSDEVID_DefaultVoicePlayback
);
161 /* try the COM class factory method of creation with a bad
163 rc
=CoCreateInstance(&CLSID_DirectSoundFullDuplex
, NULL
,
164 CLSCTX_INPROC_SERVER
, &CLSID_DirectSoundPrivate
,
166 ok(rc
==E_NOINTERFACE
,
167 "CoCreateInstance(CLSID_DirectSoundFullDuplex,CLSID_DirectSoundPrivate) "
168 "should have failed: %s (0x%08lx)\n",DXGetErrorString8(rc
), rc
);
170 ZeroMemory(&wfex
, sizeof(wfex
));
171 wfex
.wFormatTag
= WAVE_FORMAT_PCM
;
173 wfex
.nSamplesPerSec
= 8000;
174 wfex
.wBitsPerSample
= 16;
175 wfex
.nBlockAlign
= (wfex
.wBitsPerSample
* wfex
.nChannels
) / 8;
176 wfex
.nAvgBytesPerSec
= wfex
.nSamplesPerSec
* wfex
.nBlockAlign
;
178 ZeroMemory(&DSCBufferDesc
, sizeof(DSCBufferDesc
));
179 DSCBufferDesc
.dwSize
= sizeof(DSCBufferDesc
);
180 DSCBufferDesc
.dwFlags
= DSCBCAPS_WAVEMAPPED
;
181 DSCBufferDesc
.dwBufferBytes
= 8192;
182 DSCBufferDesc
.lpwfxFormat
= &wfex
;
184 ZeroMemory(&DSBufferDesc
, sizeof(DSBufferDesc
));
185 DSBufferDesc
.dwSize
= sizeof(DSBufferDesc
);
186 DSBufferDesc
.dwFlags
= DSBCAPS_GLOBALFOCUS
;
187 DSBufferDesc
.dwBufferBytes
= 8192;
188 DSBufferDesc
.lpwfxFormat
= &wfex
;
190 /* try with no device specified */
191 rc
=pDirectSoundFullDuplexCreate(NULL
,NULL
,&DSCBufferDesc
,&DSBufferDesc
,
192 get_hwnd(),DSSCL_EXCLUSIVE
,&dsfdo
,&pDSCBuffer8
,
194 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
||rc
==E_FAIL
||rc
==DSERR_INVALIDCALL
,
195 "DirectSoundFullDuplexCreate(NULL,NULL) failed: %s\n",DXGetErrorString8(rc
));
196 if (rc
==S_OK
&& dsfdo
)
197 IDirectSoundFullDuplex_test(dsfdo
, TRUE
, NULL
, NULL
);
199 /* try with default devices specified */
200 rc
=pDirectSoundFullDuplexCreate(&DSDEVID_DefaultCapture
,
201 &DSDEVID_DefaultPlayback
,&DSCBufferDesc
,
202 &DSBufferDesc
,get_hwnd(),DSSCL_EXCLUSIVE
,&dsfdo
,
203 &pDSCBuffer8
,&pDSBuffer8
,NULL
);
204 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
||rc
==E_FAIL
||rc
==DSERR_INVALIDCALL
,
205 "DirectSoundFullDuplexCreate(DSDEVID_DefaultCapture,"
206 "DSDEVID_DefaultPlayback) failed: %s\n",
207 DXGetErrorString8(rc
));
208 if (rc
==DS_OK
&& dsfdo
)
209 IDirectSoundFullDuplex_test(dsfdo
, TRUE
, NULL
, NULL
);
211 /* try with default voice devices specified */
212 rc
=pDirectSoundFullDuplexCreate(&DSDEVID_DefaultVoiceCapture
,
213 &DSDEVID_DefaultVoicePlayback
,
214 &DSCBufferDesc
,&DSBufferDesc
,get_hwnd(),DSSCL_EXCLUSIVE
,
215 &dsfdo
,&pDSCBuffer8
,&pDSBuffer8
,NULL
);
216 ok(rc
==DS_OK
||rc
==DSERR_NODRIVER
||rc
==DSERR_ALLOCATED
||rc
==E_FAIL
||rc
==DSERR_INVALIDCALL
,
217 "DirectSoundFullDuplexCreate(DSDEVID_DefaultVoiceCapture,"
218 "DSDEVID_DefaultVoicePlayback) failed: %s\n",
219 DXGetErrorString8(rc
));
220 if (rc
==DS_OK
&& dsfdo
)
221 IDirectSoundFullDuplex_test(dsfdo
, TRUE
, NULL
, NULL
);
223 /* try with bad devices specified */
224 rc
=pDirectSoundFullDuplexCreate(&DSDEVID_DefaultVoicePlayback
,
225 &DSDEVID_DefaultVoiceCapture
,
226 &DSCBufferDesc
,&DSBufferDesc
,get_hwnd(),DSSCL_EXCLUSIVE
,
227 &dsfdo
,&pDSCBuffer8
,&pDSBuffer8
,NULL
);
228 ok(rc
==DSERR_NODRIVER
||rc
==DSERR_INVALIDCALL
,
229 "DirectSoundFullDuplexCreate(DSDEVID_DefaultVoicePlayback,"
230 "DSDEVID_DefaultVoiceCapture) should have failed: %s\n",
231 DXGetErrorString8(rc
));
232 if (rc
==DS_OK
&& dsfdo
)
233 IDirectSoundFullDuplex_Release(dsfdo
);
242 hDsound
= LoadLibraryA("dsound.dll");
244 trace("dsound.dll not found\n");
248 trace("DLL Version: %s\n", get_file_version("dsound.dll"));
250 pDirectSoundFullDuplexCreate
=(void*)GetProcAddress(hDsound
,"DirectSoundFullDuplexCreate");
251 if (!pDirectSoundFullDuplexCreate
)
253 trace("duplex test skipped\n");
257 IDirectSoundFullDuplex_tests();