e36b7566da6cdb4158513453b77ca503db87744a
[reactos.git] / rostests / winetests / quartz / dsoundrender.c
1 /*
2 * Unit tests for DSound Renderer functions
3 *
4 * Copyright (C) 2010 Maarten Lankhorst for CodeWeavers
5 * Copyright (C) 2007 Google (Lei Zhang)
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #define NONAMELESSUNION
23 #define COBJMACROS
24
25 #include "wine/test.h"
26 #include "dshow.h"
27 #include "initguid.h"
28 #include "dsound.h"
29 #include "amaudio.h"
30
31 #define QI_SUCCEED(iface, riid, ppv) hr = IUnknown_QueryInterface(iface, &riid, (LPVOID*)&ppv); \
32 ok(hr == S_OK, "IUnknown_QueryInterface returned %x\n", hr); \
33 ok(ppv != NULL, "Pointer is NULL\n");
34
35 #define RELEASE_EXPECT(iface, num) if (iface) { \
36 hr = IUnknown_Release(iface); \
37 ok(hr == num, "IUnknown_Release should return %d, got %d\n", num, hr); \
38 }
39
40 static IUnknown *pDSRender = NULL;
41
42 static int create_dsound_renderer(void)
43 {
44 HRESULT hr;
45
46 hr = CoCreateInstance(&CLSID_DSoundRender, NULL, CLSCTX_INPROC_SERVER,
47 &IID_IUnknown, (LPVOID*)&pDSRender);
48 return (hr == S_OK && pDSRender != NULL);
49 }
50
51 static void release_dsound_renderer(void)
52 {
53 HRESULT hr;
54
55 hr = IUnknown_Release(pDSRender);
56 ok(hr == 0, "IUnknown_Release failed with %x\n", hr);
57 }
58
59 static HRESULT WINAPI PB_QueryInterface(IPropertyBag *iface, REFIID riid, void **ppv)
60 {
61 ok(0, "Should not be called\n");
62 *ppv = NULL;
63 return E_NOINTERFACE;
64 }
65
66 static ULONG WINAPI PB_AddRef(IPropertyBag *iface)
67 {
68 ok(0, "Should not be called\n");
69 return 2;
70 }
71
72 static ULONG WINAPI PB_Release(IPropertyBag *iface)
73 {
74 ok(0, "Should not be called\n");
75 return 1;
76 }
77
78 static HRESULT WINAPI PB_Read(IPropertyBag *iface, LPCOLESTR name, VARIANT *var, IErrorLog *log)
79 {
80 static const WCHAR dsguid[] = { 'D','S','G','u','i','d', 0 };
81 char temp[50];
82 WideCharToMultiByte(CP_ACP, 0, name, -1, temp, sizeof(temp)-1, NULL, NULL);
83 temp[sizeof(temp)-1] = 0;
84 trace("Trying to read %s, type %u\n", temp, var->n1.n2.vt);
85 if (!lstrcmpW(name, dsguid))
86 {
87 static const WCHAR defaultplayback[] =
88 {
89 '{','D','E','F','0','0','0','0','0','-',
90 '9','C','6','D','-','4','7','E','D','-',
91 'A','A','F','1','-','4','D','D','A','8',
92 'F','2','B','5','C','0','3','}',0
93 };
94 ok(var->n1.n2.vt == VT_BSTR, "Wrong type asked: %u\n", var->n1.n2.vt);
95 var->n1.n2.n3.bstrVal = SysAllocString(defaultplayback);
96 return S_OK;
97 }
98 ok(0, "Unknown property '%s' queried\n", temp);
99 return E_FAIL;
100 }
101
102 static HRESULT WINAPI PB_Write(IPropertyBag *iface, LPCOLESTR name, VARIANT *var)
103 {
104 ok(0, "Should not be called\n");
105 return E_FAIL;
106 }
107
108 static IPropertyBagVtbl PB_Vtbl =
109 {
110 PB_QueryInterface,
111 PB_AddRef,
112 PB_Release,
113 PB_Read,
114 PB_Write
115 };
116
117 static void test_query_interface(void)
118 {
119 HRESULT hr;
120 IBaseFilter *pBaseFilter = NULL;
121 IBasicAudio *pBasicAudio = NULL;
122 IMediaPosition *pMediaPosition = NULL;
123 IMediaSeeking *pMediaSeeking = NULL;
124 IQualityControl *pQualityControl = NULL;
125 IPersistPropertyBag *ppb = NULL;
126 IDirectSound3DBuffer *ds3dbuf = NULL;
127 IReferenceClock *clock = NULL;
128 IAMDirectSound *pAMDirectSound = NULL;
129
130 QI_SUCCEED(pDSRender, IID_IBaseFilter, pBaseFilter);
131 RELEASE_EXPECT(pBaseFilter, 1);
132 QI_SUCCEED(pDSRender, IID_IBasicAudio, pBasicAudio);
133 RELEASE_EXPECT(pBasicAudio, 1);
134 QI_SUCCEED(pDSRender, IID_IMediaSeeking, pMediaSeeking);
135 RELEASE_EXPECT(pMediaSeeking, 1);
136 QI_SUCCEED(pDSRender, IID_IReferenceClock, clock);
137 RELEASE_EXPECT(clock, 1);
138 QI_SUCCEED(pDSRender, IID_IAMDirectSound, pAMDirectSound);
139 RELEASE_EXPECT( pAMDirectSound, 1);
140 todo_wine {
141 QI_SUCCEED(pDSRender, IID_IDirectSound3DBuffer, ds3dbuf);
142 RELEASE_EXPECT(ds3dbuf, 1);
143 QI_SUCCEED(pDSRender, IID_IPersistPropertyBag, ppb);
144 if (ppb)
145 {
146 IPropertyBag bag = { &PB_Vtbl };
147 hr = IPersistPropertyBag_Load(ppb, &bag, NULL);
148 ok(hr == S_OK, "Couldn't load default device: %08x\n", hr);
149 }
150 RELEASE_EXPECT(ppb, 1);
151 QI_SUCCEED(pDSRender, IID_IMediaPosition, pMediaPosition);
152 RELEASE_EXPECT(pMediaPosition, 1);
153 QI_SUCCEED(pDSRender, IID_IQualityControl, pQualityControl);
154 RELEASE_EXPECT(pQualityControl, 1);
155 }
156 }
157
158 static void test_pin(IPin *pin)
159 {
160 IMemInputPin *mpin = NULL;
161
162 IPin_QueryInterface(pin, &IID_IMemInputPin, (void **)&mpin);
163
164 ok(mpin != NULL, "No IMemInputPin found!\n");
165 if (mpin)
166 {
167 ok(IMemInputPin_ReceiveCanBlock(mpin) == S_OK, "Receive can't block for pin!\n");
168 ok(IMemInputPin_NotifyAllocator(mpin, NULL, 0) == E_POINTER, "NotifyAllocator likes a NULL pointer argument\n");
169 IMemInputPin_Release(mpin);
170 }
171 /* TODO */
172 }
173
174 static void test_basefilter(void)
175 {
176 IEnumPins *pin_enum = NULL;
177 IBaseFilter *base = NULL;
178 IPin *pins[2];
179 ULONG ref;
180 HRESULT hr;
181
182 IUnknown_QueryInterface(pDSRender, &IID_IBaseFilter, (void *)&base);
183 if (base == NULL)
184 {
185 /* test_query_interface handles this case */
186 skip("No IBaseFilter\n");
187 return;
188 }
189
190 hr = IBaseFilter_EnumPins(base, NULL);
191 ok(hr == E_POINTER, "hr = %08x and not E_POINTER\n", hr);
192
193 hr= IBaseFilter_EnumPins(base, &pin_enum);
194 ok(hr == S_OK, "hr = %08x and not S_OK\n", hr);
195
196 hr = IEnumPins_Next(pin_enum, 1, NULL, NULL);
197 ok(hr == E_POINTER, "hr = %08x and not E_POINTER\n", hr);
198
199 hr = IEnumPins_Next(pin_enum, 2, pins, NULL);
200 ok(hr == E_INVALIDARG, "hr = %08x and not E_INVALIDARG\n", hr);
201
202 pins[0] = (void *)0xdead;
203 pins[1] = (void *)0xdeed;
204
205 hr = IEnumPins_Next(pin_enum, 2, pins, &ref);
206 ok(hr == S_FALSE, "hr = %08x instead of S_FALSE\n", hr);
207 ok(pins[0] != (void *)0xdead && pins[0] != NULL, "pins[0] = %p\n", pins[0]);
208 if (pins[0] != (void *)0xdead && pins[0] != NULL)
209 {
210 test_pin(pins[0]);
211 IPin_Release(pins[0]);
212 }
213
214 ok(pins[1] == (void *)0xdeed, "pins[1] = %p\n", pins[1]);
215
216 ref = IEnumPins_Release(pin_enum);
217 ok(ref == 0, "ref is %u and not 0!\n", ref);
218
219 IBaseFilter_Release(base);
220 }
221
222 START_TEST(dsoundrender)
223 {
224 if(!winetest_interactive)
225 {
226 skip("Skipping dsoundrender test, see ROSTESTS_116\n");
227 return;
228 }
229 CoInitialize(NULL);
230 if (!create_dsound_renderer())
231 return;
232
233 test_query_interface();
234 test_basefilter();
235
236 release_dsound_renderer();
237
238 CoUninitialize();
239 }