configure: Changes from running autconf after previous patch.
[wine/hacks.git] / dlls / dsound / tests / duplex.c
blob11fb2a7b90a4289ad21f97b5b058d767f1820718
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 "dsconf.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,
38 LPCGUID lpGuidRender)
40 HRESULT rc;
41 int ref;
42 IUnknown * unknown;
43 IDirectSound * ds;
44 IDirectSound8 * ds8;
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);
51 if (rc==DS_OK) {
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);
59 if (rc==DS_OK) {
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) "
67 "failed: %08x\n",rc);
68 if (rc==DS_OK) {
69 IDirectSoundFullDuplex * dsfd1;
70 rc=IDirectSound8_QueryInterface(ds8,&IID_IDirectSoundFullDuplex,(LPVOID*)&dsfd1);
71 ok(rc==DS_OK,"IDirectSound8_QueryInterface(IID_IDirectSoundFullDuplex) "
72 "failed: %08x\n",rc);
73 if (rc==DS_OK) {
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) "
85 "failed: %08x\n",rc);
86 if (rc==DS_OK) {
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) "
94 "failed: %08x\n",rc);
95 if (rc==DS_OK) {
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)
107 HRESULT rc;
108 LPDIRECTSOUNDFULLDUPLEX dsfdo = NULL;
109 DSCBUFFERDESC DSCBufferDesc;
110 DSBUFFERDESC DSBufferDesc;
111 LPDIRECTSOUNDCAPTUREBUFFER8 pDSCBuffer8;
112 LPDIRECTSOUNDBUFFER8 pDSBuffer8;
113 WAVEFORMATEX wfex;
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,
120 (void**)&dsfdo);
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");
125 return;
126 } else if (rc==CLASS_E_CLASSNOTAVAILABLE) {
127 trace(" Class Not Available\n");
128 return;
130 if (dsfdo)
131 IDirectSoundFullDuplex_test(dsfdo, FALSE, NULL, NULL);
133 /* try the COM class factory method of creation with default devices
134 * specified */
135 rc=CoCreateInstance(&CLSID_DirectSoundFullDuplex, NULL,
136 CLSCTX_INPROC_SERVER, &IID_IDirectSoundFullDuplex,
137 (void**)&dsfdo);
138 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSoundFullDuplex) failed: 0x%08x\n", rc);
139 if (dsfdo)
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,
147 (void**)&dsfdo);
148 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSoundFullDuplex) failed: 0x%08x\n", rc);
149 if (dsfdo)
150 IDirectSoundFullDuplex_test(dsfdo, FALSE, &DSDEVID_DefaultVoiceCapture,
151 &DSDEVID_DefaultVoicePlayback);
153 /* try the COM class factory method of creation with a bad
154 * IID specified */
155 rc=CoCreateInstance(&CLSID_DirectSoundFullDuplex, NULL,
156 CLSCTX_INPROC_SERVER, &CLSID_DirectSoundPrivate,
157 (void**)&dsfdo);
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;
164 wfex.nChannels = 1;
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,
185 &pDSBuffer8,NULL);
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);
225 START_TEST(duplex)
227 HMODULE hDsound;
229 CoInitialize(NULL);
231 hDsound = LoadLibrary("dsound.dll");
232 if (hDsound)
235 pDirectSoundFullDuplexCreate=(void*)GetProcAddress(hDsound,
236 "DirectSoundFullDuplexCreate");
237 if (pDirectSoundFullDuplexCreate)
238 IDirectSoundFullDuplex_tests();
239 else
240 skip("duplex test skipped\n");
242 FreeLibrary(hDsound);
244 else
245 skip("dsound.dll not found!\n");
247 CoUninitialize();