1*c2c66affSColin Finck /*
2*c2c66affSColin Finck  * Unit tests for duplex functions
3*c2c66affSColin Finck  *
4*c2c66affSColin Finck  * Copyright (c) 2006 Robert Reif
5*c2c66affSColin Finck  *
6*c2c66affSColin Finck  * This library is free software; you can redistribute it and/or
7*c2c66affSColin Finck  * modify it under the terms of the GNU Lesser General Public
8*c2c66affSColin Finck  * License as published by the Free Software Foundation; either
9*c2c66affSColin Finck  * version 2.1 of the License, or (at your option) any later version.
10*c2c66affSColin Finck  *
11*c2c66affSColin Finck  * This library is distributed in the hope that it will be useful,
12*c2c66affSColin Finck  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13*c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14*c2c66affSColin Finck  * Lesser General Public License for more details.
15*c2c66affSColin Finck  *
16*c2c66affSColin Finck  * You should have received a copy of the GNU Lesser General Public
17*c2c66affSColin Finck  * License along with this library; if not, write to the Free Software
18*c2c66affSColin Finck  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19*c2c66affSColin Finck  */
20*c2c66affSColin Finck 
21*c2c66affSColin Finck #include "dsound_test.h"
22*c2c66affSColin Finck 
23*c2c66affSColin Finck static HRESULT (WINAPI *pDirectSoundFullDuplexCreate)(LPCGUID, LPCGUID,
24*c2c66affSColin Finck     LPCDSCBUFFERDESC, LPCDSBUFFERDESC, HWND, DWORD, LPDIRECTSOUNDFULLDUPLEX *,
25*c2c66affSColin Finck     LPDIRECTSOUNDCAPTUREBUFFER8*, LPDIRECTSOUNDBUFFER8*, LPUNKNOWN)=NULL;
26*c2c66affSColin Finck 
IDirectSoundFullDuplex_test(LPDIRECTSOUNDFULLDUPLEX dsfdo,BOOL initialized,LPCGUID lpGuidCapture,LPCGUID lpGuidRender)27*c2c66affSColin Finck static void IDirectSoundFullDuplex_test(LPDIRECTSOUNDFULLDUPLEX dsfdo,
28*c2c66affSColin Finck                                         BOOL initialized, LPCGUID lpGuidCapture,
29*c2c66affSColin Finck                                         LPCGUID lpGuidRender)
30*c2c66affSColin Finck {
31*c2c66affSColin Finck     HRESULT rc;
32*c2c66affSColin Finck     int ref;
33*c2c66affSColin Finck     IUnknown * unknown;
34*c2c66affSColin Finck     IDirectSound * ds;
35*c2c66affSColin Finck     IDirectSound8 * ds8;
36*c2c66affSColin Finck     IDirectSoundCapture * dsc;
37*c2c66affSColin Finck     IDirectSoundFullDuplex * dsfd;
38*c2c66affSColin Finck 
39*c2c66affSColin Finck     /* Try to Query for objects */
40*c2c66affSColin Finck     rc=IDirectSoundFullDuplex_QueryInterface(dsfdo,&IID_IUnknown,(LPVOID*)&unknown);
41*c2c66affSColin Finck     ok(rc==DS_OK,"IDirectSoundFullDuplex_QueryInterface(IID_IUnknown) failed: %08x\n", rc);
42*c2c66affSColin Finck     if (rc==DS_OK) {
43*c2c66affSColin Finck         ref=IDirectSoundFullDuplex_Release(unknown);
44*c2c66affSColin Finck         ok(ref==0, "IDirectSoundFullDuplex_Release() has %d references, "
45*c2c66affSColin Finck            "should have 0\n", ref);
46*c2c66affSColin Finck     }
47*c2c66affSColin Finck 
48*c2c66affSColin Finck     rc=IDirectSoundFullDuplex_QueryInterface(dsfdo,&IID_IDirectSound,(LPVOID*)&ds);
49*c2c66affSColin Finck     ok(rc==(initialized?DS_OK:E_NOINTERFACE),"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSound) failed: %08x\n", rc);
50*c2c66affSColin Finck     if (rc==DS_OK) {
51*c2c66affSColin Finck         ref=IDirectSound_Release(ds);
52*c2c66affSColin Finck         ok(ref==0, "IDirectSound_Release() has %d references, "
53*c2c66affSColin Finck            "should have 0\n", ref);
54*c2c66affSColin Finck     }
55*c2c66affSColin Finck 
56*c2c66affSColin Finck     rc=IDirectSoundFullDuplex_QueryInterface(dsfdo,&IID_IDirectSound8,(LPVOID*)&ds8);
57*c2c66affSColin Finck     ok(rc==(initialized?DS_OK:E_NOINTERFACE),"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSound8) "
58*c2c66affSColin Finck        "failed: %08x\n",rc);
59*c2c66affSColin Finck     if (rc==DS_OK) {
60*c2c66affSColin Finck         IDirectSoundFullDuplex * dsfd1;
61*c2c66affSColin Finck         rc=IDirectSound8_QueryInterface(ds8,&IID_IDirectSoundFullDuplex,(LPVOID*)&dsfd1);
62*c2c66affSColin Finck         ok(rc==DS_OK,"IDirectSound8_QueryInterface(IID_IDirectSoundFullDuplex) "
63*c2c66affSColin Finck            "failed: %08x\n",rc);
64*c2c66affSColin Finck         if (rc==DS_OK) {
65*c2c66affSColin Finck             ref=IDirectSoundFullDuplex_Release(dsfd1);
66*c2c66affSColin Finck             ok(ref==1, "IDirectSoundFullDuplex_Release() has %d references, "
67*c2c66affSColin Finck                "should have 1\n", ref);
68*c2c66affSColin Finck         }
69*c2c66affSColin Finck         ref=IDirectSound8_Release(ds8);
70*c2c66affSColin Finck         ok(ref==0, "IDirectSound8_Release() has %d references, "
71*c2c66affSColin Finck            "should have 0\n", ref);
72*c2c66affSColin Finck     }
73*c2c66affSColin Finck 
74*c2c66affSColin Finck     rc=IDirectSoundFullDuplex_QueryInterface(dsfdo,&IID_IDirectSoundCapture,(LPVOID*)&dsc);
75*c2c66affSColin Finck     ok(rc==(initialized?DS_OK:E_NOINTERFACE),"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSoundCapture) "
76*c2c66affSColin Finck        "failed: %08x\n",rc);
77*c2c66affSColin Finck     if (rc==DS_OK) {
78*c2c66affSColin Finck         ref=IDirectSoundCapture_Release(dsc);
79*c2c66affSColin Finck         ok(ref==0, "IDirectSoundCapture_Release() has %d references, "
80*c2c66affSColin Finck            "should have 0\n", ref);
81*c2c66affSColin Finck     }
82*c2c66affSColin Finck 
83*c2c66affSColin Finck     rc=IDirectSoundFullDuplex_QueryInterface(dsfdo,&IID_IDirectSoundFullDuplex,(LPVOID*)&dsfd);
84*c2c66affSColin Finck     ok(rc==DS_OK,"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSoundFullDuplex) "
85*c2c66affSColin Finck        "failed: %08x\n",rc);
86*c2c66affSColin Finck     if (rc==DS_OK) {
87*c2c66affSColin Finck         ok(dsfdo==dsfd, "different interfaces\n");
88*c2c66affSColin Finck         ref=IDirectSound8_Release(dsfd);
89*c2c66affSColin Finck         ok(ref==1, "IDirectSoundFullDuplex_Release() has %d references, should have 1\n", ref);
90*c2c66affSColin Finck     }
91*c2c66affSColin Finck 
92*c2c66affSColin Finck     ref=IDirectSoundFullDuplex_Release(dsfdo);
93*c2c66affSColin Finck     ok(ref==0, "IDirectSoundFullDuplex_Release() has %d references, "
94*c2c66affSColin Finck        "should have 0\n", ref);
95*c2c66affSColin Finck }
96*c2c66affSColin Finck 
IDirectSoundFullDuplex_tests(void)97*c2c66affSColin Finck static void IDirectSoundFullDuplex_tests(void)
98*c2c66affSColin Finck {
99*c2c66affSColin Finck     HRESULT rc;
100*c2c66affSColin Finck     LPDIRECTSOUNDFULLDUPLEX dsfdo = NULL;
101*c2c66affSColin Finck     DSCBUFFERDESC DSCBufferDesc;
102*c2c66affSColin Finck     DSBUFFERDESC DSBufferDesc;
103*c2c66affSColin Finck     LPDIRECTSOUNDCAPTUREBUFFER8 pDSCBuffer8;
104*c2c66affSColin Finck     LPDIRECTSOUNDBUFFER8 pDSBuffer8;
105*c2c66affSColin Finck     WAVEFORMATEX wfex;
106*c2c66affSColin Finck 
107*c2c66affSColin Finck     trace("Testing IDirectSoundFullDuplex\n");
108*c2c66affSColin Finck 
109*c2c66affSColin Finck     /* try the COM class factory method of creation with no devices specified */
110*c2c66affSColin Finck     rc=CoCreateInstance(&CLSID_DirectSoundFullDuplex, NULL,
111*c2c66affSColin Finck                         CLSCTX_INPROC_SERVER, &IID_IDirectSoundFullDuplex,
112*c2c66affSColin Finck                         (void**)&dsfdo);
113*c2c66affSColin Finck     ok(rc==S_OK||rc==REGDB_E_CLASSNOTREG||rc==CLASS_E_CLASSNOTAVAILABLE,
114*c2c66affSColin Finck        "CoCreateInstance(CLSID_DirectSoundFullDuplex) failed: 0x%08x\n", rc);
115*c2c66affSColin Finck     if (rc==REGDB_E_CLASSNOTREG) {
116*c2c66affSColin Finck         trace("  Class Not Registered\n");
117*c2c66affSColin Finck         return;
118*c2c66affSColin Finck     } else if (rc==CLASS_E_CLASSNOTAVAILABLE) {
119*c2c66affSColin Finck         trace("  Class Not Available\n");
120*c2c66affSColin Finck         return;
121*c2c66affSColin Finck     }
122*c2c66affSColin Finck     if (dsfdo)
123*c2c66affSColin Finck         IDirectSoundFullDuplex_test(dsfdo, FALSE, NULL, NULL);
124*c2c66affSColin Finck 
125*c2c66affSColin Finck     /* try the COM class factory method of creation with default devices
126*c2c66affSColin Finck      * specified */
127*c2c66affSColin Finck     rc=CoCreateInstance(&CLSID_DirectSoundFullDuplex, NULL,
128*c2c66affSColin Finck                         CLSCTX_INPROC_SERVER, &IID_IDirectSoundFullDuplex,
129*c2c66affSColin Finck                         (void**)&dsfdo);
130*c2c66affSColin Finck     ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSoundFullDuplex) failed: 0x%08x\n", rc);
131*c2c66affSColin Finck     if (dsfdo)
132*c2c66affSColin Finck         IDirectSoundFullDuplex_test(dsfdo, FALSE, &DSDEVID_DefaultCapture,
133*c2c66affSColin Finck                                     &DSDEVID_DefaultPlayback);
134*c2c66affSColin Finck 
135*c2c66affSColin Finck     /* try the COM class factory method of creation with default voice
136*c2c66affSColin Finck      * devices specified */
137*c2c66affSColin Finck     rc=CoCreateInstance(&CLSID_DirectSoundFullDuplex, NULL,
138*c2c66affSColin Finck                         CLSCTX_INPROC_SERVER, &IID_IDirectSoundFullDuplex,
139*c2c66affSColin Finck                         (void**)&dsfdo);
140*c2c66affSColin Finck     ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSoundFullDuplex) failed: 0x%08x\n", rc);
141*c2c66affSColin Finck     if (dsfdo)
142*c2c66affSColin Finck         IDirectSoundFullDuplex_test(dsfdo, FALSE, &DSDEVID_DefaultVoiceCapture,
143*c2c66affSColin Finck                                     &DSDEVID_DefaultVoicePlayback);
144*c2c66affSColin Finck 
145*c2c66affSColin Finck     /* try the COM class factory method of creation with a bad
146*c2c66affSColin Finck      * IID specified */
147*c2c66affSColin Finck     rc=CoCreateInstance(&CLSID_DirectSoundFullDuplex, NULL,
148*c2c66affSColin Finck                         CLSCTX_INPROC_SERVER, &CLSID_DirectSoundPrivate,
149*c2c66affSColin Finck                         (void**)&dsfdo);
150*c2c66affSColin Finck     ok(rc==E_NOINTERFACE,
151*c2c66affSColin Finck        "CoCreateInstance(CLSID_DirectSoundFullDuplex,CLSID_DirectSoundPrivate) "
152*c2c66affSColin Finck        "should have failed: 0x%08x\n", rc);
153*c2c66affSColin Finck 
154*c2c66affSColin Finck     ZeroMemory(&wfex, sizeof(wfex));
155*c2c66affSColin Finck     wfex.wFormatTag = WAVE_FORMAT_PCM;
156*c2c66affSColin Finck     wfex.nChannels = 1;
157*c2c66affSColin Finck     wfex.nSamplesPerSec = 8000;
158*c2c66affSColin Finck     wfex.wBitsPerSample = 16;
159*c2c66affSColin Finck     wfex.nBlockAlign = (wfex.wBitsPerSample * wfex.nChannels) / 8;
160*c2c66affSColin Finck     wfex.nAvgBytesPerSec = wfex.nSamplesPerSec * wfex.nBlockAlign;
161*c2c66affSColin Finck 
162*c2c66affSColin Finck     ZeroMemory(&DSCBufferDesc, sizeof(DSCBufferDesc));
163*c2c66affSColin Finck     DSCBufferDesc.dwSize = sizeof(DSCBufferDesc);
164*c2c66affSColin Finck     DSCBufferDesc.dwFlags = DSCBCAPS_WAVEMAPPED;
165*c2c66affSColin Finck     DSCBufferDesc.dwBufferBytes = 8192;
166*c2c66affSColin Finck     DSCBufferDesc.lpwfxFormat = &wfex;
167*c2c66affSColin Finck 
168*c2c66affSColin Finck     ZeroMemory(&DSBufferDesc, sizeof(DSBufferDesc));
169*c2c66affSColin Finck     DSBufferDesc.dwSize = sizeof(DSBufferDesc);
170*c2c66affSColin Finck     DSBufferDesc.dwFlags = DSBCAPS_GLOBALFOCUS;
171*c2c66affSColin Finck     DSBufferDesc.dwBufferBytes = 8192;
172*c2c66affSColin Finck     DSBufferDesc.lpwfxFormat = &wfex;
173*c2c66affSColin Finck 
174*c2c66affSColin Finck     /* try with no device specified */
175*c2c66affSColin Finck     rc=pDirectSoundFullDuplexCreate(NULL,NULL,&DSCBufferDesc,&DSBufferDesc,
176*c2c66affSColin Finck                                     get_hwnd(),DSSCL_EXCLUSIVE ,&dsfdo,&pDSCBuffer8,
177*c2c66affSColin Finck                                     &pDSBuffer8,NULL);
178*c2c66affSColin Finck     ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL||rc==DSERR_INVALIDCALL,
179*c2c66affSColin Finck        "DirectSoundFullDuplexCreate(NULL,NULL) failed: %08x\n",rc);
180*c2c66affSColin Finck     if (rc==S_OK && dsfdo)
181*c2c66affSColin Finck         IDirectSoundFullDuplex_test(dsfdo, TRUE, NULL, NULL);
182*c2c66affSColin Finck 
183*c2c66affSColin Finck     /* try with default devices specified */
184*c2c66affSColin Finck     rc=pDirectSoundFullDuplexCreate(&DSDEVID_DefaultCapture,
185*c2c66affSColin Finck                                     &DSDEVID_DefaultPlayback,&DSCBufferDesc,
186*c2c66affSColin Finck                                     &DSBufferDesc,get_hwnd(),DSSCL_EXCLUSIVE,&dsfdo,
187*c2c66affSColin Finck                                     &pDSCBuffer8,&pDSBuffer8,NULL);
188*c2c66affSColin Finck     ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL||rc==DSERR_INVALIDCALL,
189*c2c66affSColin Finck        "DirectSoundFullDuplexCreate(DSDEVID_DefaultCapture,"
190*c2c66affSColin Finck        "DSDEVID_DefaultPlayback) failed: %08x\n", rc);
191*c2c66affSColin Finck     if (rc==DS_OK && dsfdo)
192*c2c66affSColin Finck         IDirectSoundFullDuplex_test(dsfdo, TRUE, NULL, NULL);
193*c2c66affSColin Finck 
194*c2c66affSColin Finck     /* try with default voice devices specified */
195*c2c66affSColin Finck     rc=pDirectSoundFullDuplexCreate(&DSDEVID_DefaultVoiceCapture,
196*c2c66affSColin Finck                                     &DSDEVID_DefaultVoicePlayback,
197*c2c66affSColin Finck                                     &DSCBufferDesc,&DSBufferDesc,get_hwnd(),DSSCL_EXCLUSIVE,
198*c2c66affSColin Finck                                     &dsfdo,&pDSCBuffer8,&pDSBuffer8,NULL);
199*c2c66affSColin Finck     ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL||rc==DSERR_INVALIDCALL,
200*c2c66affSColin Finck        "DirectSoundFullDuplexCreate(DSDEVID_DefaultVoiceCapture,"
201*c2c66affSColin Finck        "DSDEVID_DefaultVoicePlayback) failed: %08x\n", rc);
202*c2c66affSColin Finck     if (rc==DS_OK && dsfdo)
203*c2c66affSColin Finck         IDirectSoundFullDuplex_test(dsfdo, TRUE, NULL, NULL);
204*c2c66affSColin Finck 
205*c2c66affSColin Finck     /* try with bad devices specified */
206*c2c66affSColin Finck     rc=pDirectSoundFullDuplexCreate(&DSDEVID_DefaultVoicePlayback,
207*c2c66affSColin Finck                                     &DSDEVID_DefaultVoiceCapture,
208*c2c66affSColin Finck                                     &DSCBufferDesc,&DSBufferDesc,get_hwnd(),DSSCL_EXCLUSIVE,
209*c2c66affSColin Finck                                     &dsfdo,&pDSCBuffer8,&pDSBuffer8,NULL);
210*c2c66affSColin Finck     ok(rc==DSERR_NODRIVER||rc==DSERR_INVALIDCALL,
211*c2c66affSColin Finck        "DirectSoundFullDuplexCreate(DSDEVID_DefaultVoicePlayback,"
212*c2c66affSColin Finck        "DSDEVID_DefaultVoiceCapture) should have failed: %08x\n", rc);
213*c2c66affSColin Finck     if (rc==DS_OK && dsfdo)
214*c2c66affSColin Finck         IDirectSoundFullDuplex_Release(dsfdo);
215*c2c66affSColin Finck }
216*c2c66affSColin Finck 
test_COM(void)217*c2c66affSColin Finck static void test_COM(void)
218*c2c66affSColin Finck {
219*c2c66affSColin Finck     IDirectSoundFullDuplex *dsfd = (IDirectSoundFullDuplex*)0xdeadbeef;
220*c2c66affSColin Finck     IDirectSound *ds;
221*c2c66affSColin Finck     IDirectSound8 *ds8;
222*c2c66affSColin Finck     IDirectSoundCapture *dsc;
223*c2c66affSColin Finck     IUnknown *unk, *unk8;
224*c2c66affSColin Finck     IDirectSoundBuffer8 *dsb8;
225*c2c66affSColin Finck     IDirectSoundCaptureBuffer8 *dscb8;
226*c2c66affSColin Finck     DSBUFFERDESC bufdesc;
227*c2c66affSColin Finck     DSCBUFFERDESC cbufdesc;
228*c2c66affSColin Finck     WAVEFORMATEX wfx;
229*c2c66affSColin Finck     ULONG refcount;
230*c2c66affSColin Finck     HRESULT hr;
231*c2c66affSColin Finck 
232*c2c66affSColin Finck     /* COM aggregation */
233*c2c66affSColin Finck     hr = CoCreateInstance(&CLSID_DirectSoundFullDuplex, (IUnknown*)&dsfd, CLSCTX_INPROC_SERVER,
234*c2c66affSColin Finck             &IID_IUnknown, (void**)&dsfd);
235*c2c66affSColin Finck     ok(hr == CLASS_E_NOAGGREGATION,
236*c2c66affSColin Finck             "DirectSoundFullDuplex create failed: %08x, expected CLASS_E_NOAGGREGATION\n", hr);
237*c2c66affSColin Finck     ok(!dsfd, "dsfd = %p\n", dsfd);
238*c2c66affSColin Finck 
239*c2c66affSColin Finck     /* Invalid RIID */
240*c2c66affSColin Finck     hr = CoCreateInstance(&CLSID_DirectSoundFullDuplex, NULL, CLSCTX_INPROC_SERVER,
241*c2c66affSColin Finck             &IID_IDirectSound3DBuffer, (void**)&dsfd);
242*c2c66affSColin Finck     ok(hr == E_NOINTERFACE,
243*c2c66affSColin Finck             "DirectSoundFullDuplex create failed: %08x, expected E_NOINTERFACE\n", hr);
244*c2c66affSColin Finck 
245*c2c66affSColin Finck     /* Different refcount for IDirectSoundFullDuplex and for IUnknown */
246*c2c66affSColin Finck     hr = CoCreateInstance(&CLSID_DirectSoundFullDuplex, NULL, CLSCTX_INPROC_SERVER,
247*c2c66affSColin Finck             &IID_IDirectSoundFullDuplex, (void**)&dsfd);
248*c2c66affSColin Finck     ok(hr == S_OK, "DirectSoundFullDuplex create failed: %08x, expected S_OK\n", hr);
249*c2c66affSColin Finck     refcount = IDirectSoundFullDuplex_AddRef(dsfd);
250*c2c66affSColin Finck     ok(refcount == 2, "refcount == %u, expected 2\n", refcount);
251*c2c66affSColin Finck     hr = IDirectSoundFullDuplex_QueryInterface(dsfd, &IID_IUnknown, (void**)&unk);
252*c2c66affSColin Finck     ok(hr == S_OK, "QueryInterface for IID_IUnknown failed: %08x\n", hr);
253*c2c66affSColin Finck     refcount = IUnknown_AddRef(unk);
254*c2c66affSColin Finck     ok(refcount == 2, "refcount == %u, expected 2\n", refcount);
255*c2c66affSColin Finck 
256*c2c66affSColin Finck     /* Not initialized */
257*c2c66affSColin Finck     hr = IDirectSoundFullDuplex_QueryInterface(dsfd, &IID_IDirectSound8, (void**)&ds8);
258*c2c66affSColin Finck     ok(hr == E_NOINTERFACE,
259*c2c66affSColin Finck             "QueryInterface for IID_IDirectSound8 failed: %08x, expected E_NOINTERFACE\n", hr);
260*c2c66affSColin Finck     hr = IDirectSoundFullDuplex_QueryInterface(dsfd, &IID_IDirectSoundCapture, (void**)&dsc);
261*c2c66affSColin Finck     ok(hr == E_NOINTERFACE,
262*c2c66affSColin Finck             "QueryInterface for IID_IDirectSoundCapture failed: %08x, expected E_NOINTERFACE\n", hr);
263*c2c66affSColin Finck 
264*c2c66affSColin Finck     init_format(&wfx, WAVE_FORMAT_PCM, 44100, 16, 1);
265*c2c66affSColin Finck     ZeroMemory(&bufdesc, sizeof(bufdesc));
266*c2c66affSColin Finck     bufdesc.dwSize = sizeof(bufdesc);
267*c2c66affSColin Finck     bufdesc.dwBufferBytes = wfx.nAvgBytesPerSec;
268*c2c66affSColin Finck     bufdesc.lpwfxFormat = &wfx;
269*c2c66affSColin Finck     ZeroMemory(&cbufdesc, sizeof(cbufdesc));
270*c2c66affSColin Finck     cbufdesc.dwSize = sizeof(cbufdesc);
271*c2c66affSColin Finck     cbufdesc.dwBufferBytes = wfx.nAvgBytesPerSec;
272*c2c66affSColin Finck     cbufdesc.lpwfxFormat = &wfx;
273*c2c66affSColin Finck     hr = IDirectSoundFullDuplex_Initialize(dsfd, NULL, NULL, &cbufdesc, &bufdesc, get_hwnd(),
274*c2c66affSColin Finck             DSSCL_EXCLUSIVE, NULL, NULL);
275*c2c66affSColin Finck     ok(hr == E_INVALIDARG,
276*c2c66affSColin Finck             "IDirectSoundFullDuplex_Initialize failed: %08x, expected E_INVALIDARG\n", hr);
277*c2c66affSColin Finck     hr = IDirectSoundFullDuplex_Initialize(dsfd, NULL, NULL, &cbufdesc, &bufdesc, get_hwnd(),
278*c2c66affSColin Finck             DSSCL_EXCLUSIVE, &dscb8, &dsb8);
279*c2c66affSColin Finck     if (hr == DSERR_NODRIVER || hr == DSERR_INVALIDCALL) {
280*c2c66affSColin Finck         skip("No driver\n");
281*c2c66affSColin Finck         return;
282*c2c66affSColin Finck     }
283*c2c66affSColin Finck     ok(hr == S_OK, "IDirectSoundFullDuplex_Initialize failed: %08x\n", hr);
284*c2c66affSColin Finck 
285*c2c66affSColin Finck     /* IDirectSound and IDirectSound8 */
286*c2c66affSColin Finck     hr = IDirectSoundFullDuplex_QueryInterface(dsfd, &IID_IDirectSound8, (void**)&ds8);
287*c2c66affSColin Finck     ok(hr == S_OK, "QueryInterface for IID_IDirectSound8 failed: %08x\n", hr);
288*c2c66affSColin Finck     refcount = IDirectSound8_AddRef(ds8);
289*c2c66affSColin Finck     ok(refcount == 2, "refcount == %u, expected 2\n", refcount);
290*c2c66affSColin Finck     hr = IDirectSoundFullDuplex_QueryInterface(dsfd, &IID_IDirectSound, (void**)&ds);
291*c2c66affSColin Finck     ok(hr == S_OK, "QueryInterface for IID_IDirectSound failed: %08x\n", hr);
292*c2c66affSColin Finck     refcount = IDirectSound8_AddRef(ds8);
293*c2c66affSColin Finck     ok(refcount == 4, "refcount == %u, expected 4\n", refcount);
294*c2c66affSColin Finck     refcount = IDirectSound_AddRef(ds);
295*c2c66affSColin Finck     ok(refcount == 5, "refcount == %u, expected 5\n", refcount);
296*c2c66affSColin Finck     hr = IDirectSound8_QueryInterface(ds8, &IID_IUnknown, (void**)&unk8);
297*c2c66affSColin Finck     ok(hr == S_OK, "QueryInterface for IID_IUnknown failed: %08x\n", hr);
298*c2c66affSColin Finck     ok(unk == unk8, "Got different IUnknown when QI'ing IDirectSoundFullDuplex and IDirectSound\n");
299*c2c66affSColin Finck     refcount = IUnknown_AddRef(unk8);
300*c2c66affSColin Finck     ok(refcount == 4, "refcount == %u, expected 4\n", refcount);
301*c2c66affSColin Finck     refcount = IDirectSound_AddRef(ds);
302*c2c66affSColin Finck     ok(refcount == 6, "refcount == %u, expected 6\n", refcount);
303*c2c66affSColin Finck     refcount = IDirectSoundFullDuplex_AddRef(dsfd);
304*c2c66affSColin Finck     ok(refcount == 3, "refcount == %u, expected 3\n", refcount);
305*c2c66affSColin Finck 
306*c2c66affSColin Finck     /* IDirectSoundCapture */
307*c2c66affSColin Finck     hr = IDirectSoundFullDuplex_QueryInterface(dsfd, &IID_IDirectSoundCapture, (void**)&dsc);
308*c2c66affSColin Finck     ok(hr == S_OK, "QueryInterface for IID_IDirectSoundCapture failed: %08x\n", hr);
309*c2c66affSColin Finck     refcount = IDirectSoundCapture_AddRef(dsc);
310*c2c66affSColin Finck     ok(refcount == 2, "refcount == %u, expected 2\n", refcount);
311*c2c66affSColin Finck     refcount = IDirectSoundFullDuplex_AddRef(dsfd);
312*c2c66affSColin Finck     ok(refcount == 4, "refcount == %u, expected 4\n", refcount);
313*c2c66affSColin Finck     hr = IDirectSoundCapture_QueryInterface(ds8, &IID_IUnknown, (void**)&unk8);
314*c2c66affSColin Finck     ok(hr == S_OK, "QueryInterface for IID_IUnknown failed: %08x\n", hr);
315*c2c66affSColin Finck     ok(unk == unk8,
316*c2c66affSColin Finck             "Got different IUnknown when QI'ing IDirectSoundFullDuplex and IDirectSoundCapture\n");
317*c2c66affSColin Finck     refcount = IUnknown_AddRef(unk8);
318*c2c66affSColin Finck     ok(refcount == 6, "refcount == %u, expected 6\n", refcount);
319*c2c66affSColin Finck 
320*c2c66affSColin Finck     IDirectSoundBuffer8_Release(dsb8);
321*c2c66affSColin Finck     IDirectSoundCaptureBuffer8_Release(dscb8);
322*c2c66affSColin Finck     while (IDirectSound8_Release(ds8));
323*c2c66affSColin Finck     while (IDirectSoundCapture_Release(dsc));
324*c2c66affSColin Finck     while (IDirectSoundFullDuplex_Release(dsfd));
325*c2c66affSColin Finck     while (IUnknown_Release(unk));
326*c2c66affSColin Finck }
327*c2c66affSColin Finck 
START_TEST(duplex)328*c2c66affSColin Finck START_TEST(duplex)
329*c2c66affSColin Finck {
330*c2c66affSColin Finck     HMODULE hDsound;
331*c2c66affSColin Finck 
332*c2c66affSColin Finck     CoInitialize(NULL);
333*c2c66affSColin Finck 
334*c2c66affSColin Finck     hDsound = LoadLibrary("dsound.dll");
335*c2c66affSColin Finck     if (hDsound)
336*c2c66affSColin Finck     {
337*c2c66affSColin Finck 
338*c2c66affSColin Finck         pDirectSoundFullDuplexCreate=(void*)GetProcAddress(hDsound,
339*c2c66affSColin Finck             "DirectSoundFullDuplexCreate");
340*c2c66affSColin Finck         if (pDirectSoundFullDuplexCreate) {
341*c2c66affSColin Finck             test_COM();
342*c2c66affSColin Finck             IDirectSoundFullDuplex_tests();
343*c2c66affSColin Finck         } else
344*c2c66affSColin Finck             skip("DirectSoundFullDuplexCreate missing - skipping all tests\n");
345*c2c66affSColin Finck 
346*c2c66affSColin Finck         FreeLibrary(hDsound);
347*c2c66affSColin Finck     }
348*c2c66affSColin Finck     else
349*c2c66affSColin Finck         skip("dsound.dll not found - skipping all tests\n");
350*c2c66affSColin Finck 
351*c2c66affSColin Finck     CoUninitialize();
352*c2c66affSColin Finck }
353