push 27a9569132e9fc3a545aded7efca0a004a7b7ea9
[wine/hacks.git] / dlls / dsound / tests / duplex.c
blob66c48839a6fc54f8c10f24d4cb585abab2f8800e
1 /*
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 #include <windows.h>
23 #include <stdio.h>
25 #include "wine/test.h"
26 #include "dsound.h"
27 #include "mmreg.h"
28 #include "dxerr8.h"
29 #include "dsconf.h"
31 #include "dsound_test.h"
33 static HRESULT (WINAPI *pDirectSoundFullDuplexCreate)(LPCGUID, LPCGUID,
34 LPCDSCBUFFERDESC, LPCDSBUFFERDESC, HWND, DWORD, LPDIRECTSOUNDFULLDUPLEX *,
35 LPDIRECTSOUNDCAPTUREBUFFER8*, LPDIRECTSOUNDBUFFER8*, LPUNKNOWN)=NULL;
37 static void IDirectSoundFullDuplex_test(LPDIRECTSOUNDFULLDUPLEX dsfdo,
38 BOOL initialized, LPCGUID lpGuidCapture,
39 LPCGUID lpGuidRender)
41 HRESULT rc;
42 int ref;
43 IUnknown * unknown;
44 IDirectSound * ds;
45 IDirectSound8 * ds8;
46 IDirectSoundCapture * dsc;
47 IDirectSoundFullDuplex * dsfd;
49 /* Try to Query for objects */
50 rc=IDirectSoundFullDuplex_QueryInterface(dsfdo,&IID_IUnknown,(LPVOID*)&unknown);
51 ok(rc==DS_OK,"IDirectSoundFullDuplex_QueryInterface(IID_IUnknown) failed: %s\n",
52 DXGetErrorString8(rc));
53 if (rc==DS_OK) {
54 ref=IDirectSoundFullDuplex_Release(unknown);
55 ok(ref==0, "IDirectSoundFullDuplex_Release() has %d references, "
56 "should have 0\n", ref);
59 rc=IDirectSoundFullDuplex_QueryInterface(dsfdo,&IID_IDirectSound,(LPVOID*)&ds);
60 ok(rc==(initialized?DS_OK:E_NOINTERFACE),"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSound) failed: %s\n",
61 DXGetErrorString8(rc));
62 if (rc==DS_OK) {
63 ref=IDirectSound_Release(ds);
64 ok(ref==0, "IDirectSound_Release() has %d references, "
65 "should have 0\n", ref);
68 rc=IDirectSoundFullDuplex_QueryInterface(dsfdo,&IID_IDirectSound8,(LPVOID*)&ds8);
69 ok(rc==(initialized?DS_OK:E_NOINTERFACE),"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSound8) "
70 "failed: %s\n",DXGetErrorString8(rc));
71 if (rc==DS_OK) {
72 IDirectSoundFullDuplex * dsfd1;
73 rc=IDirectSound8_QueryInterface(ds8,&IID_IDirectSoundFullDuplex,(LPVOID*)&dsfd1);
74 ok(rc==DS_OK,"IDirectSound8_QueryInterface(IID_IDirectSoundFullDuplex) "
75 "failed: %s\n",DXGetErrorString8(rc));
76 if (rc==DS_OK) {
77 ref=IDirectSoundFullDuplex_Release(dsfd1);
78 ok(ref==1, "IDirectSoundFullDuplex_Release() has %d references, "
79 "should have 1\n", ref);
81 ref=IDirectSound8_Release(ds8);
82 ok(ref==0, "IDirectSound8_Release() has %d references, "
83 "should have 0\n", ref);
86 rc=IDirectSoundFullDuplex_QueryInterface(dsfdo,&IID_IDirectSoundCapture,(LPVOID*)&dsc);
87 ok(rc==(initialized?DS_OK:E_NOINTERFACE),"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSoundCapture) "
88 "failed: %s\n",DXGetErrorString8(rc));
89 if (rc==DS_OK) {
90 ref=IDirectSoundCapture_Release(dsc);
91 ok(ref==0, "IDirectSoundCapture_Release() has %d references, "
92 "should have 0\n", ref);
95 rc=IDirectSoundFullDuplex_QueryInterface(dsfdo,&IID_IDirectSoundFullDuplex,(LPVOID*)&dsfd);
96 ok(rc==DS_OK,"IDirectSoundFullDuplex_QueryInterface(IID_IDirectSoundFullDuplex) "
97 "failed: %s\n",DXGetErrorString8(rc));
98 if (rc==DS_OK) {
99 ok (dsfdo==dsfd, "different interfaces\n");
100 ref=IDirectSound8_Release(dsfd);
103 ref=IDirectSoundFullDuplex_Release(dsfdo);
104 ok(ref==0, "IDirectSoundFullDuplex_Release() has %d references, "
105 "should have 0\n", ref);
108 static void IDirectSoundFullDuplex_tests(void)
110 HRESULT rc;
111 LPDIRECTSOUNDFULLDUPLEX dsfdo = NULL;
112 DSCBUFFERDESC DSCBufferDesc;
113 DSBUFFERDESC DSBufferDesc;
114 LPDIRECTSOUNDCAPTUREBUFFER8 pDSCBuffer8;
115 LPDIRECTSOUNDBUFFER8 pDSBuffer8;
116 WAVEFORMATEX wfex;
118 trace("Testing IDirectSoundFullDuplex\n");
120 /* try the COM class factory method of creation with no devices specified */
121 rc=CoCreateInstance(&CLSID_DirectSoundFullDuplex, NULL,
122 CLSCTX_INPROC_SERVER, &IID_IDirectSoundFullDuplex,
123 (void**)&dsfdo);
124 ok(rc==S_OK||rc==REGDB_E_CLASSNOTREG||rc==CLASS_E_CLASSNOTAVAILABLE,
125 "CoCreateInstance(CLSID_DirectSoundFullDuplex) failed: %s (0x%08x)\n",
126 DXGetErrorString8(rc), rc);
127 if (rc==REGDB_E_CLASSNOTREG) {
128 trace(" Class Not Registered\n");
129 return;
130 } else if (rc==CLASS_E_CLASSNOTAVAILABLE) {
131 trace(" Class Not Available\n");
132 return;
134 if (dsfdo)
135 IDirectSoundFullDuplex_test(dsfdo, FALSE, NULL, NULL);
137 /* try the COM class factory method of creation with default devices
138 * specified */
139 rc=CoCreateInstance(&CLSID_DirectSoundFullDuplex, NULL,
140 CLSCTX_INPROC_SERVER, &IID_IDirectSoundFullDuplex,
141 (void**)&dsfdo);
142 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSoundFullDuplex) failed: %s (0x%08x)\n",
143 DXGetErrorString8(rc), rc);
144 if (dsfdo)
145 IDirectSoundFullDuplex_test(dsfdo, FALSE, &DSDEVID_DefaultCapture,
146 &DSDEVID_DefaultPlayback);
148 /* try the COM class factory method of creation with default voice
149 * devices specified */
150 rc=CoCreateInstance(&CLSID_DirectSoundFullDuplex, NULL,
151 CLSCTX_INPROC_SERVER, &IID_IDirectSoundFullDuplex,
152 (void**)&dsfdo);
153 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSoundFullDuplex) failed: %s (0x%08x)\n",
154 DXGetErrorString8(rc), rc);
155 if (dsfdo)
156 IDirectSoundFullDuplex_test(dsfdo, FALSE, &DSDEVID_DefaultVoiceCapture,
157 &DSDEVID_DefaultVoicePlayback);
159 /* try the COM class factory method of creation with a bad
160 * IID specified */
161 rc=CoCreateInstance(&CLSID_DirectSoundFullDuplex, NULL,
162 CLSCTX_INPROC_SERVER, &CLSID_DirectSoundPrivate,
163 (void**)&dsfdo);
164 ok(rc==E_NOINTERFACE,
165 "CoCreateInstance(CLSID_DirectSoundFullDuplex,CLSID_DirectSoundPrivate) "
166 "should have failed: %s (0x%08x)\n",DXGetErrorString8(rc), rc);
168 ZeroMemory(&wfex, sizeof(wfex));
169 wfex.wFormatTag = WAVE_FORMAT_PCM;
170 wfex.nChannels = 1;
171 wfex.nSamplesPerSec = 8000;
172 wfex.wBitsPerSample = 16;
173 wfex.nBlockAlign = (wfex.wBitsPerSample * wfex.nChannels) / 8;
174 wfex.nAvgBytesPerSec = wfex.nSamplesPerSec * wfex.nBlockAlign;
176 ZeroMemory(&DSCBufferDesc, sizeof(DSCBufferDesc));
177 DSCBufferDesc.dwSize = sizeof(DSCBufferDesc);
178 DSCBufferDesc.dwFlags = DSCBCAPS_WAVEMAPPED;
179 DSCBufferDesc.dwBufferBytes = 8192;
180 DSCBufferDesc.lpwfxFormat = &wfex;
182 ZeroMemory(&DSBufferDesc, sizeof(DSBufferDesc));
183 DSBufferDesc.dwSize = sizeof(DSBufferDesc);
184 DSBufferDesc.dwFlags = DSBCAPS_GLOBALFOCUS;
185 DSBufferDesc.dwBufferBytes = 8192;
186 DSBufferDesc.lpwfxFormat = &wfex;
188 /* try with no device specified */
189 rc=pDirectSoundFullDuplexCreate(NULL,NULL,&DSCBufferDesc,&DSBufferDesc,
190 get_hwnd(),DSSCL_EXCLUSIVE ,&dsfdo,&pDSCBuffer8,
191 &pDSBuffer8,NULL);
192 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL||rc==DSERR_INVALIDCALL,
193 "DirectSoundFullDuplexCreate(NULL,NULL) failed: %s\n",DXGetErrorString8(rc));
194 if (rc==S_OK && dsfdo)
195 IDirectSoundFullDuplex_test(dsfdo, TRUE, NULL, NULL);
197 /* try with default devices specified */
198 rc=pDirectSoundFullDuplexCreate(&DSDEVID_DefaultCapture,
199 &DSDEVID_DefaultPlayback,&DSCBufferDesc,
200 &DSBufferDesc,get_hwnd(),DSSCL_EXCLUSIVE,&dsfdo,
201 &pDSCBuffer8,&pDSBuffer8,NULL);
202 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL||rc==DSERR_INVALIDCALL,
203 "DirectSoundFullDuplexCreate(DSDEVID_DefaultCapture,"
204 "DSDEVID_DefaultPlayback) failed: %s\n",
205 DXGetErrorString8(rc));
206 if (rc==DS_OK && dsfdo)
207 IDirectSoundFullDuplex_test(dsfdo, TRUE, NULL, NULL);
209 /* try with default voice devices specified */
210 rc=pDirectSoundFullDuplexCreate(&DSDEVID_DefaultVoiceCapture,
211 &DSDEVID_DefaultVoicePlayback,
212 &DSCBufferDesc,&DSBufferDesc,get_hwnd(),DSSCL_EXCLUSIVE,
213 &dsfdo,&pDSCBuffer8,&pDSBuffer8,NULL);
214 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL||rc==DSERR_INVALIDCALL,
215 "DirectSoundFullDuplexCreate(DSDEVID_DefaultVoiceCapture,"
216 "DSDEVID_DefaultVoicePlayback) failed: %s\n",
217 DXGetErrorString8(rc));
218 if (rc==DS_OK && dsfdo)
219 IDirectSoundFullDuplex_test(dsfdo, TRUE, NULL, NULL);
221 /* try with bad devices specified */
222 rc=pDirectSoundFullDuplexCreate(&DSDEVID_DefaultVoicePlayback,
223 &DSDEVID_DefaultVoiceCapture,
224 &DSCBufferDesc,&DSBufferDesc,get_hwnd(),DSSCL_EXCLUSIVE,
225 &dsfdo,&pDSCBuffer8,&pDSBuffer8,NULL);
226 ok(rc==DSERR_NODRIVER||rc==DSERR_INVALIDCALL,
227 "DirectSoundFullDuplexCreate(DSDEVID_DefaultVoicePlayback,"
228 "DSDEVID_DefaultVoiceCapture) should have failed: %s\n",
229 DXGetErrorString8(rc));
230 if (rc==DS_OK && dsfdo)
231 IDirectSoundFullDuplex_Release(dsfdo);
234 START_TEST(duplex)
236 HMODULE hDsound;
238 CoInitialize(NULL);
240 hDsound = LoadLibrary("dsound.dll");
241 if (hDsound)
243 trace("DLL Version: %s\n", get_file_version("dsound.dll"));
245 pDirectSoundFullDuplexCreate=(void*)GetProcAddress(hDsound,
246 "DirectSoundFullDuplexCreate");
247 if (pDirectSoundFullDuplexCreate)
248 IDirectSoundFullDuplex_tests();
249 else
250 skip("duplex test skipped\n");
252 FreeLibrary(hDsound);
254 else
255 skip("dsound.dll not found!\n");
257 CoUninitialize();