shlwapi: Don't cast WCHAR string to BSTR.
[wine/testsucceed.git] / dlls / mmdevapi / tests / render.c
blob05d71b7a17e2dcad8d93c635fad19b7f3263b16e
1 /*
2 * Copyright 2010 Maarten Lankhorst for Codeweavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 /* This test is for audio playback specific mechanisms
20 * Tests:
21 * - IAudioClient with eRender and IAudioRenderClient
24 #include "wine/test.h"
26 #define CINTERFACE
27 #define COBJMACROS
29 #ifdef STANDALONE
30 #include "initguid.h"
31 #endif
33 #include "unknwn.h"
34 #include "uuids.h"
35 #include "mmdeviceapi.h"
36 #include "audioclient.h"
38 static void test_uninitialized(IAudioClient *ac)
40 HRESULT hr;
41 UINT32 num;
42 REFERENCE_TIME t1;
44 HANDLE handle = CreateEventW(NULL, FALSE, FALSE, NULL);
45 IUnknown *unk;
47 hr = IAudioClient_GetBufferSize(ac, &num);
48 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized GetBufferSize call returns %08x\n", hr);
50 hr = IAudioClient_GetStreamLatency(ac, &t1);
51 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized GetStreamLatency call returns %08x\n", hr);
53 hr = IAudioClient_GetCurrentPadding(ac, &num);
54 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized GetCurrentPadding call returns %08x\n", hr);
56 hr = IAudioClient_Start(ac);
57 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized Start call returns %08x\n", hr);
59 hr = IAudioClient_Stop(ac);
60 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized Stop call returns %08x\n", hr);
62 hr = IAudioClient_Reset(ac);
63 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized Reset call returns %08x\n", hr);
65 hr = IAudioClient_SetEventHandle(ac, handle);
66 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized SetEventHandle call returns %08x\n", hr);
68 hr = IAudioClient_GetService(ac, &IID_IAudioStreamVolume, (void**)&unk);
69 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized GetService call returns %08x\n", hr);
71 CloseHandle(handle);
74 static void test_audioclient(IAudioClient *ac)
76 IUnknown *unk;
77 HRESULT hr;
78 ULONG ref;
79 WAVEFORMATEX *pwfx, *pwfx2;
80 REFERENCE_TIME t1, t2;
82 HANDLE handle = CreateEventW(NULL, FALSE, FALSE, NULL);
84 hr = IAudioClient_QueryInterface(ac, &IID_IUnknown, NULL);
85 ok(hr == E_POINTER, "QueryInterface(NULL) returned %08x\n", hr);
87 unk = (void*)(LONG_PTR)0x12345678;
88 hr = IAudioClient_QueryInterface(ac, &IID_NULL, (void**)&unk);
89 ok(hr == E_NOINTERFACE, "QueryInterface(IID_NULL) returned %08x\n", hr);
90 ok(!unk, "QueryInterface(IID_NULL) returned non-null pointer %p\n", unk);
92 hr = IAudioClient_QueryInterface(ac, &IID_IUnknown, (void**)&unk);
93 ok(hr == S_OK, "QueryInterface(IID_IUnknown) returned %08x\n", hr);
94 if (unk)
96 ref = IUnknown_Release(unk);
97 ok(ref == 1, "Released count is %u\n", ref);
100 hr = IAudioClient_QueryInterface(ac, &IID_IAudioClient, (void**)&unk);
101 ok(hr == S_OK, "QueryInterface(IID_IAudioClient) returned %08x\n", hr);
102 if (unk)
104 ref = IUnknown_Release(unk);
105 ok(ref == 1, "Released count is %u\n", ref);
108 hr = IAudioClient_GetDevicePeriod(ac, NULL, NULL);
109 ok(hr == E_POINTER, "Invalid GetDevicePeriod call returns %08x\n", hr);
111 hr = IAudioClient_GetDevicePeriod(ac, &t1, NULL);
112 ok(hr == S_OK, "Valid GetDevicePeriod call returns %08x\n", hr);
114 hr = IAudioClient_GetDevicePeriod(ac, NULL, &t2);
115 ok(hr == S_OK, "Valid GetDevicePeriod call returns %08x\n", hr);
117 hr = IAudioClient_GetDevicePeriod(ac, &t1, &t2);
118 ok(hr == S_OK, "Valid GetDevicePeriod call returns %08x\n", hr);
119 trace("Returned periods: %u.%05u ms %u.%05u ms\n",
120 (UINT)(t1/10000), (UINT)(t1 % 10000),
121 (UINT)(t2/10000), (UINT)(t2 % 10000));
123 hr = IAudioClient_GetMixFormat(ac, NULL);
124 ok(hr == E_POINTER, "GetMixFormat returns %08x\n", hr);
126 hr = IAudioClient_GetMixFormat(ac, &pwfx);
127 ok(hr == S_OK, "Valid GetMixFormat returns %08x\n", hr);
129 trace("Tag: %04x\n", pwfx->wFormatTag);
130 trace("bits: %u\n", pwfx->wBitsPerSample);
131 trace("chan: %u\n", pwfx->nChannels);
132 trace("rate: %u\n", pwfx->nSamplesPerSec);
133 trace("align: %u\n", pwfx->nBlockAlign);
134 trace("extra: %u\n", pwfx->cbSize);
135 ok(pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE, "wFormatTag is %x\n", pwfx->wFormatTag);
136 if (pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
138 WAVEFORMATEXTENSIBLE *pwfxe = (void*)pwfx;
139 trace("Res: %u\n", pwfxe->Samples.wReserved);
140 trace("Mask: %x\n", pwfxe->dwChannelMask);
141 trace("Alg: %s\n",
142 IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM)?"PCM":
143 (IsEqualGUID(&pwfxe->SubFormat,
144 &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)?"FLOAT":"Other"));
147 if (hr == S_OK)
149 hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_SHARED, pwfx, &pwfx2);
150 ok(hr == S_OK, "Valid IsFormatSupported(Shared) call returns %08x\n", hr);
151 ok(pwfx2 == NULL, "pwfx2 is non-null\n");
152 CoTaskMemFree(pwfx2);
154 hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_SHARED, NULL, NULL);
155 ok(hr == E_POINTER, "IsFormatSupported(NULL) call returns %08x\n", hr);
157 hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_SHARED, pwfx, NULL);
158 ok(hr == E_POINTER, "IsFormatSupported(Shared,NULL) call returns %08x\n", hr);
160 hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_EXCLUSIVE, pwfx, NULL);
161 ok(hr == S_OK || hr == AUDCLNT_E_UNSUPPORTED_FORMAT, "IsFormatSupported(Exclusive) call returns %08x\n", hr);
163 hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_EXCLUSIVE, pwfx, &pwfx2);
164 ok(hr == S_OK || hr == AUDCLNT_E_UNSUPPORTED_FORMAT, "IsFormatSupported(Exclusive) call returns %08x\n", hr);
165 ok(pwfx2 == NULL, "pwfx2 non-null on exclusive IsFormatSupported\n");
167 hr = IAudioClient_IsFormatSupported(ac, 0xffffffff, pwfx, NULL);
168 ok(hr == E_INVALIDARG, "IsFormatSupported(0xffffffff) call returns %08x\n", hr);
171 test_uninitialized(ac);
173 hr = IAudioClient_Initialize(ac, 3, 0, 5000000, 0, pwfx, NULL);
174 ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Initialize with invalid sharemode returns %08x\n", hr);
176 hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED, 0xffffffff, 5000000, 0, pwfx, NULL);
177 ok(hr == E_INVALIDARG, "Initialize with invalid flags returns %08x\n", hr);
179 /* It seems that if length > 2s or periodicity != 0 the length is ignored and call succeeds
180 * Since we can only initialize succesfully once skip those tests
182 hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED, 0, 5000000, 0, NULL, NULL);
183 ok(hr == E_POINTER, "Initialize with null format returns %08x\n", hr);
185 hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED, 0, 5000000, 0, pwfx, NULL);
186 ok(hr == S_OK, "Valid Initialize returns %08x\n", hr);
188 if (hr != S_OK)
190 skip("Cannot initialize %08x, remainder of tests is useless\n", hr);
191 CoTaskMemFree(pwfx);
192 return;
195 hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED, 0, 5000000, 0, pwfx, NULL);
196 ok(hr == AUDCLNT_E_ALREADY_INITIALIZED, "Calling Initialize twice returns %08x\n", hr);
198 hr = IAudioClient_SetEventHandle(ac, NULL);
199 ok(hr == E_INVALIDARG, "SetEventHandle(NULL) returns %08x\n", hr);
201 hr = IAudioClient_SetEventHandle(ac, handle);
202 ok(hr == AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED ||
203 hr == HRESULT_FROM_WIN32(ERROR_INVALID_NAME)
204 , "SetEventHandle returns %08x\n", hr);
206 CloseHandle(handle);
207 CoTaskMemFree(pwfx);
210 START_TEST(render)
212 HRESULT hr;
213 IMMDeviceEnumerator *mme = NULL;
214 IMMDevice *dev = NULL;
215 IAudioClient *ac = NULL;
217 CoInitializeEx(NULL, COINIT_MULTITHREADED);
218 hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&mme);
219 if (FAILED(hr))
221 skip("mmdevapi not available: 0x%08x\n", hr);
222 goto cleanup;
225 hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(mme, eRender, eMultimedia, &dev);
226 ok(hr == S_OK || hr == E_NOTFOUND, "GetDefaultAudioEndpoint failed: 0x%08x\n", hr);
227 if (hr != S_OK || !dev)
229 if (hr == E_NOTFOUND)
230 skip("No sound card available\n");
231 else
232 skip("GetDefaultAudioEndpoint returns 0x%08x\n", hr);
233 goto cleanup;
236 hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, NULL, (void**)&ac);
237 ok(hr == S_OK, "Activation failed with %08x\n", hr);
238 if (ac)
240 test_audioclient(ac);
241 IAudioClient_Release(ac);
243 IMMDevice_Release(dev);
245 cleanup:
246 if (mme)
247 IMMDeviceEnumerator_Release(mme);
248 CoUninitialize();