Update the address of the Free Software Foundation.
[wine/gsoc_dplay.git] / dlls / dsound / tests / duplex.c
blob2b238335929909ee5d362545cde292b96a583e8a
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 #define NONAMELESSSTRUCT
22 #define NONAMELESSUNION
23 #include <windows.h>
25 #include <stdio.h>
27 #include "wine/test.h"
28 #include "dsound.h"
29 #include "mmreg.h"
30 #include "dxerr8.h"
31 #include "dsconf.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,
41 LPCGUID lpGuidRender)
43 HRESULT rc;
44 int ref;
45 IUnknown * unknown;
46 IDirectSound * ds;
47 IDirectSound8 * ds8;
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));
55 if (rc==DS_OK) {
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));
64 if (rc==DS_OK) {
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));
73 if (rc==DS_OK) {
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));
78 if (rc==DS_OK) {
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));
91 if (rc==DS_OK) {
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));
100 if (rc==DS_OK) {
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)
112 HRESULT rc;
113 LPDIRECTSOUNDFULLDUPLEX dsfdo = NULL;
114 DSCBUFFERDESC DSCBufferDesc;
115 DSBUFFERDESC DSBufferDesc;
116 LPDIRECTSOUNDCAPTUREBUFFER8 pDSCBuffer8;
117 LPDIRECTSOUNDBUFFER8 pDSBuffer8;
118 WAVEFORMATEX wfex;
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,
125 (void**)&dsfdo);
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");
131 return;
132 } else if (rc==CLASS_E_CLASSNOTAVAILABLE) {
133 trace(" Class Not Available\n");
134 return;
136 if (dsfdo)
137 IDirectSoundFullDuplex_test(dsfdo, FALSE, NULL, NULL);
139 /* try the COM class factory method of creation with default devices
140 * specified */
141 rc=CoCreateInstance(&CLSID_DirectSoundFullDuplex, NULL,
142 CLSCTX_INPROC_SERVER, &IID_IDirectSoundFullDuplex,
143 (void**)&dsfdo);
144 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSoundFullDuplex) failed: %s (0x%08lx)\n",
145 DXGetErrorString8(rc), rc);
146 if (dsfdo)
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,
154 (void**)&dsfdo);
155 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSoundFullDuplex) failed: %s (0x%08lx)\n",
156 DXGetErrorString8(rc), rc);
157 if (dsfdo)
158 IDirectSoundFullDuplex_test(dsfdo, FALSE, &DSDEVID_DefaultVoiceCapture,
159 &DSDEVID_DefaultVoicePlayback);
161 /* try the COM class factory method of creation with a bad
162 * IID specified */
163 rc=CoCreateInstance(&CLSID_DirectSoundFullDuplex, NULL,
164 CLSCTX_INPROC_SERVER, &CLSID_DirectSoundPrivate,
165 (void**)&dsfdo);
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;
172 wfex.nChannels = 1;
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,
193 &pDSBuffer8,NULL);
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);
236 START_TEST(duplex)
238 HMODULE hDsound;
240 CoInitialize(NULL);
242 hDsound = LoadLibraryA("dsound.dll");
243 if (!hDsound) {
244 trace("dsound.dll not found\n");
245 goto done;
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");
254 goto done;
257 IDirectSoundFullDuplex_tests();
259 done:
260 CoUninitialize();