2 * Unit tests for DSound Renderer functions
4 * Copyright (C) 2010 Maarten Lankhorst for Codeweavers
5 * Copyright (C) 2007 Google (Lei Zhang)
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.
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.
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
22 #define NONAMELESSUNION
25 #include "wine/test.h"
30 #define QI_SUCCEED(iface, riid, ppv) hr = IUnknown_QueryInterface(iface, &riid, (LPVOID*)&ppv); \
31 ok(hr == S_OK, "IUnknown_QueryInterface returned %x\n", hr); \
32 ok(ppv != NULL, "Pointer is NULL\n");
34 #define RELEASE_EXPECT(iface, num) if (iface) { \
35 hr = IUnknown_Release(iface); \
36 ok(hr == num, "IUnknown_Release should return %d, got %d\n", num, hr); \
39 static IUnknown *pDSRender = NULL;
41 static int create_dsound_renderer(void)
45 hr = CoCreateInstance(&CLSID_DSoundRender, NULL, CLSCTX_INPROC_SERVER,
46 &IID_IUnknown, (LPVOID*)&pDSRender);
47 return (hr == S_OK && pDSRender != NULL);
50 static void release_dsound_renderer(void)
54 hr = IUnknown_Release(pDSRender);
55 ok(hr == 0, "IUnknown_Release failed with %x\n", hr);
58 static HRESULT WINAPI PB_QueryInterface(IPropertyBag *iface, REFIID riid, void **ppv)
60 ok(0, "Should not be called\n");
65 static ULONG WINAPI PB_AddRef(IPropertyBag *iface)
67 ok(0, "Should not be called\n");
71 static ULONG WINAPI PB_Release(IPropertyBag *iface)
73 ok(0, "Should not be called\n");
77 static HRESULT WINAPI PB_Read(IPropertyBag *iface, LPCOLESTR name, VARIANT *var, IErrorLog *log)
79 static const WCHAR dsguid[] = { 'D','S','G','u','i','d', 0 };
81 WideCharToMultiByte(CP_ACP, 0, name, -1, temp, sizeof(temp)-1, NULL, NULL);
82 temp[sizeof(temp)-1] = 0;
83 trace("Trying to read %s, type %u\n", temp, var->n1.n2.vt);
84 if (!lstrcmpW(name, dsguid))
86 static const WCHAR defaultplayback[] =
88 '{','D','E','F','0','0','0','0','0','-',
89 '9','C','6','D','-','4','7','E','D','-',
90 'A','A','F','1','-','4','D','D','A','8',
91 'F','2','B','5','C','0','3','}',0
93 ok(var->n1.n2.vt == VT_BSTR, "Wrong type asked: %u\n", var->n1.n2.vt);
94 var->n1.n2.n3.bstrVal = SysAllocString(defaultplayback);
97 ok(0, "Unknown property '%s' queried\n", temp);
101 static HRESULT WINAPI PB_Write(IPropertyBag *iface, LPCOLESTR name, VARIANT *var)
103 ok(0, "Should not be called\n");
107 static IPropertyBagVtbl PB_Vtbl =
116 static void test_query_interface(void)
119 IBaseFilter *pBaseFilter = NULL;
120 IBasicAudio *pBasicAudio = NULL;
121 IMediaPosition *pMediaPosition = NULL;
122 IMediaSeeking *pMediaSeeking = NULL;
123 IQualityControl *pQualityControl = NULL;
124 IPersistPropertyBag *ppb = NULL;
125 IDirectSound3DBuffer *ds3dbuf = NULL;
126 IReferenceClock *clock = NULL;
128 QI_SUCCEED(pDSRender, IID_IBaseFilter, pBaseFilter);
129 RELEASE_EXPECT(pBaseFilter, 1);
130 QI_SUCCEED(pDSRender, IID_IBasicAudio, pBasicAudio);
131 RELEASE_EXPECT(pBasicAudio, 1);
132 QI_SUCCEED(pDSRender, IID_IMediaSeeking, pMediaSeeking);
133 RELEASE_EXPECT(pMediaSeeking, 1);
134 QI_SUCCEED(pDSRender, IID_IReferenceClock, clock);
135 RELEASE_EXPECT(clock, 1);
137 QI_SUCCEED(pDSRender, IID_IDirectSound3DBuffer, ds3dbuf);
138 RELEASE_EXPECT(ds3dbuf, 1);
139 QI_SUCCEED(pDSRender, IID_IPersistPropertyBag, ppb);
142 IPropertyBag bag = { &PB_Vtbl };
143 hr = IPersistPropertyBag_Load(ppb, &bag, NULL);
144 ok(hr == S_OK, "Couldn't load default device: %08x\n", hr);
146 RELEASE_EXPECT(ppb, 1);
147 QI_SUCCEED(pDSRender, IID_IMediaPosition, pMediaPosition);
148 RELEASE_EXPECT(pMediaPosition, 1);
149 QI_SUCCEED(pDSRender, IID_IQualityControl, pQualityControl);
150 RELEASE_EXPECT(pQualityControl, 1);
154 static void test_pin(IPin *pin)
156 IMemInputPin *mpin = NULL;
158 IPin_QueryInterface(pin, &IID_IMemInputPin, (void **)&mpin);
160 ok(mpin != NULL, "No IMemInputPin found!\n");
163 ok(IMemInputPin_ReceiveCanBlock(mpin) == S_OK, "Receive can't block for pin!\n");
164 ok(IMemInputPin_NotifyAllocator(mpin, NULL, 0) == E_POINTER, "NotifyAllocator likes a NULL pointer argument\n");
165 IMemInputPin_Release(mpin);
170 static void test_basefilter(void)
172 IEnumPins *pin_enum = NULL;
173 IBaseFilter *base = NULL;
178 IUnknown_QueryInterface(pDSRender, &IID_IBaseFilter, (void *)&base);
181 /* test_query_interface handles this case */
182 skip("No IBaseFilter\n");
186 hr = IBaseFilter_EnumPins(base, NULL);
187 ok(hr == E_POINTER, "hr = %08x and not E_POINTER\n", hr);
189 hr= IBaseFilter_EnumPins(base, &pin_enum);
190 ok(hr == S_OK, "hr = %08x and not S_OK\n", hr);
192 hr = IEnumPins_Next(pin_enum, 1, NULL, NULL);
193 ok(hr == E_POINTER, "hr = %08x and not E_POINTER\n", hr);
195 hr = IEnumPins_Next(pin_enum, 2, pins, NULL);
196 ok(hr == E_INVALIDARG, "hr = %08x and not E_INVALIDARG\n", hr);
198 pins[0] = (void *)0xdead;
199 pins[1] = (void *)0xdeed;
201 hr = IEnumPins_Next(pin_enum, 2, pins, &ref);
202 ok(hr == S_FALSE, "hr = %08x instead of S_FALSE\n", hr);
203 ok(pins[0] != (void *)0xdead && pins[0] != NULL, "pins[0] = %p\n", pins[0]);
204 if (pins[0] != (void *)0xdead && pins[0] != NULL)
207 IPin_Release(pins[0]);
210 ok(pins[1] == (void *)0xdeed, "pins[1] = %p\n", pins[1]);
212 ref = IEnumPins_Release(pin_enum);
213 ok(ref == 0, "ref is %u and not 0!\n", ref);
215 IBaseFilter_Release(base);
218 START_TEST(dsoundrender)
221 if (!create_dsound_renderer())
224 test_query_interface();
227 release_dsound_renderer();