2 * Filtermapper unit tests for Quartz
4 * Copyright (C) 2008 Alexander Dorofeyev
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
23 #include "wine/test.h"
28 DEFINE_GUID(GUID_NULL
,0,0,0,0,0,0,0,0,0,0,0);
30 /* Helper function, checks if filter with given name was enumerated. */
31 static BOOL
enum_find_filter(const WCHAR
*wszFilterName
, IEnumMoniker
*pEnum
)
33 IMoniker
*pMoniker
= NULL
;
37 static const WCHAR wszFriendlyName
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
39 while(!found
&& IEnumMoniker_Next(pEnum
, 1, &pMoniker
, &nb
) == S_OK
)
41 IPropertyBag
* pPropBagCat
= NULL
;
46 hr
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBagCat
);
47 ok(SUCCEEDED(hr
), "IMoniker_BindToStorage failed with %x\n", hr
);
48 if (FAILED(hr
) || !pPropBagCat
)
51 IMoniker_Release(pMoniker
);
55 hr
= IPropertyBag_Read(pPropBagCat
, wszFriendlyName
, &var
, NULL
);
56 ok(SUCCEEDED(hr
), "IPropertyBag_Read failed with %x\n", hr
);
60 CHAR val1
[512], val2
[512];
62 WideCharToMultiByte(CP_ACP
, 0, (WCHAR
*)V_UNION(&var
, bstrVal
), -1, val1
, sizeof(val1
), 0, 0);
63 WideCharToMultiByte(CP_ACP
, 0, wszFilterName
, -1, val2
, sizeof(val2
), 0, 0);
64 if (!lstrcmpA(val1
, val2
)) found
= TRUE
;
67 IPropertyBag_Release(pPropBagCat
);
68 IMoniker_Release(pMoniker
);
75 static void test_fm2_enummatchingfilters(void)
77 IFilterMapper2
*pMapper
= NULL
;
80 REGFILTERPINS2 rgPins2
[2];
81 REGPINTYPES rgPinType
;
82 static const WCHAR wszFilterName1
[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', '1', 0 };
83 static const WCHAR wszFilterName2
[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', '2', 0 };
86 IEnumMoniker
*pEnum
= NULL
;
89 ZeroMemory(&rgf2
, sizeof(rgf2
));
91 hr
= CoCreateInstance(&CLSID_FilterMapper2
, NULL
, CLSCTX_INPROC_SERVER
,
92 &IID_IFilterMapper2
, (LPVOID
*)&pMapper
);
93 ok(hr
== S_OK
, "CoCreateInstance failed with %x\n", hr
);
94 if (FAILED(hr
)) goto out
;
96 hr
= CoCreateGuid(&clsidFilter1
);
97 ok(hr
== S_OK
, "CoCreateGuid failed with %x\n", hr
);
98 hr
= CoCreateGuid(&clsidFilter2
);
99 ok(hr
== S_OK
, "CoCreateGuid failed with %x\n", hr
);
101 /* Test that a test renderer filter is returned when enumerating filters with bRender=FALSE */
103 rgf2
.dwMerit
= MERIT_UNLIKELY
;
104 S1(U(rgf2
)).cPins2
= 1;
105 S1(U(rgf2
)).rgPins2
= rgPins2
;
107 rgPins2
[0].dwFlags
= REG_PINFLAG_B_RENDERER
;
108 rgPins2
[0].cInstances
= 1;
109 rgPins2
[0].nMediaTypes
= 1;
110 rgPins2
[0].lpMediaType
= &rgPinType
;
111 rgPins2
[0].nMediums
= 0;
112 rgPins2
[0].lpMedium
= NULL
;
113 rgPins2
[0].clsPinCategory
= NULL
;
115 rgPinType
.clsMajorType
= &GUID_NULL
;
116 rgPinType
.clsMinorType
= &GUID_NULL
;
118 hr
= IFilterMapper2_RegisterFilter(pMapper
, &clsidFilter1
, wszFilterName1
, NULL
,
119 &CLSID_LegacyAmFilterCategory
, NULL
, &rgf2
);
120 ok(hr
== S_OK
, "IFilterMapper2_RegisterFilter failed with %x\n", hr
);
122 rgPins2
[0].dwFlags
= 0;
124 rgPins2
[1].dwFlags
= REG_PINFLAG_B_OUTPUT
;
125 rgPins2
[1].cInstances
= 1;
126 rgPins2
[1].nMediaTypes
= 1;
127 rgPins2
[1].lpMediaType
= &rgPinType
;
128 rgPins2
[1].nMediums
= 0;
129 rgPins2
[1].lpMedium
= NULL
;
130 rgPins2
[1].clsPinCategory
= NULL
;
132 S1(U(rgf2
)).cPins2
= 2;
134 hr
= IFilterMapper2_RegisterFilter(pMapper
, &clsidFilter2
, wszFilterName2
, NULL
,
135 &CLSID_LegacyAmFilterCategory
, NULL
, &rgf2
);
136 ok(hr
== S_OK
, "IFilterMapper2_RegisterFilter failed with %x\n", hr
);
138 hr
= IFilterMapper2_EnumMatchingFilters(pMapper
, &pEnum
, 0, TRUE
, MERIT_UNLIKELY
, TRUE
,
139 0, NULL
, NULL
, &GUID_NULL
, FALSE
, FALSE
, 0, NULL
, NULL
, &GUID_NULL
);
140 ok(hr
== S_OK
, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr
);
141 if (SUCCEEDED(hr
) && pEnum
)
143 found
= enum_find_filter(wszFilterName1
, pEnum
);
144 ok(found
, "EnumMatchingFilters failed to return the test filter 1\n");
145 found
= enum_find_filter(wszFilterName2
, pEnum
);
146 ok(found
, "EnumMatchingFilters failed to return the test filter 2\n");
149 if (pEnum
) IEnumMoniker_Release(pEnum
);
152 /* Non renderer must not be returned with bRender=TRUE */
154 hr
= IFilterMapper2_EnumMatchingFilters(pMapper
, &pEnum
, 0, TRUE
, MERIT_UNLIKELY
, TRUE
,
155 0, NULL
, NULL
, &GUID_NULL
, TRUE
, FALSE
, 0, NULL
, NULL
, &GUID_NULL
);
156 ok(hr
== S_OK
, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr
);
158 if (SUCCEEDED(hr
) && pEnum
)
160 found
= enum_find_filter(wszFilterName1
, pEnum
);
161 ok(found
, "EnumMatchingFilters failed to return the test filter 1\n");
162 found
= enum_find_filter(wszFilterName2
, pEnum
);
163 ok(!found
, "EnumMatchingFilters should not return the test filter 2\n");
166 hr
= IFilterMapper2_UnregisterFilter(pMapper
, &CLSID_LegacyAmFilterCategory
, NULL
,
168 ok(SUCCEEDED(hr
), "IFilterMapper2_UnregisterFilter failed with %x\n", hr
);
170 hr
= IFilterMapper2_UnregisterFilter(pMapper
, &CLSID_LegacyAmFilterCategory
, NULL
,
172 ok(SUCCEEDED(hr
), "IFilterMapper2_UnregisterFilter failed with %x\n", hr
);
176 if (pEnum
) IEnumMoniker_Release(pEnum
);
177 if (pMapper
) IFilterMapper2_Release(pMapper
);
180 static void test_legacy_filter_registration(void)
182 IFilterMapper2
*pMapper2
= NULL
;
183 IFilterMapper
*pMapper
= NULL
;
185 static const WCHAR wszFilterName
[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', 0 };
186 static const CHAR szFilterName
[] = "Testfilter";
187 static const WCHAR wszPinName
[] = {'P', 'i', 'n', '1', 0 };
189 WCHAR wszRegKey
[MAX_PATH
];
190 CHAR szRegKey
[MAX_PATH
];
191 static const WCHAR wszClsid
[] = {'C','L','S','I','D', 0};
192 static const CHAR szClsid
[] = "CLSID";
193 static const WCHAR wszSlash
[] = {'\\', 0};
196 IEnumMoniker
*pEnum
= NULL
;
198 IEnumRegFilters
*pRegEnum
= NULL
;
200 /* Test if legacy filter registration scheme works (filter is added to HKCR\Filter). IFilterMapper_RegisterFilter
201 * registers in this way. Filters so registered must then be accessible through both IFilterMapper_EnumMatchingFilters
202 * and IFilterMapper2_EnumMatchingFilters. */
203 hr
= CoCreateInstance(&CLSID_FilterMapper2
, NULL
, CLSCTX_INPROC_SERVER
,
204 &IID_IFilterMapper2
, (LPVOID
*)&pMapper2
);
205 ok(hr
== S_OK
, "CoCreateInstance failed with %x\n", hr
);
206 if (FAILED(hr
)) goto out
;
208 hr
= IFilterMapper2_QueryInterface(pMapper2
, &IID_IFilterMapper
, (LPVOID
)&pMapper
);
209 ok(hr
== S_OK
, "IFilterMapper2_QueryInterface failed with %x\n", hr
);
210 if (FAILED(hr
)) goto out
;
212 /* Register a test filter. */
213 hr
= CoCreateGuid(&clsidFilter
);
214 ok(hr
== S_OK
, "CoCreateGuid failed with %x\n", hr
);
216 lstrcpyW(wszRegKey
, wszClsid
);
217 lstrcatW(wszRegKey
, wszSlash
);
218 lRet
= StringFromGUID2(&clsidFilter
, wszRegKey
+ lstrlenW(wszRegKey
), MAX_PATH
- lstrlenW(wszRegKey
));
219 ok(lRet
> 0, "StringFromGUID2 failed\n");
221 WideCharToMultiByte(CP_ACP
, 0, wszRegKey
, -1, szRegKey
, sizeof(szRegKey
), 0, 0);
223 /* Register---- functions need a filter class key to write pin and pin media type data to. Create a bogus
224 * class key for it. */
225 lRet
= RegCreateKeyExA(HKEY_CLASSES_ROOT
, szRegKey
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
226 ok(lRet
== ERROR_SUCCESS
, "RegCreateKeyExA failed with %x\n", HRESULT_FROM_WIN32(lRet
));
228 /* Set default value - this is interpreted as "friendly name" later. */
229 lRet
= RegSetValueExA(hKey
, NULL
, 0, REG_SZ
, (LPBYTE
)szFilterName
, lstrlenA(szFilterName
) + 1);
230 ok(lRet
== ERROR_SUCCESS
, "RegSetValueExA failed with %x\n", HRESULT_FROM_WIN32(lRet
));
232 if (hKey
) RegCloseKey(hKey
);
235 hr
= IFilterMapper_RegisterFilter(pMapper
, clsidFilter
, wszFilterName
, MERIT_UNLIKELY
);
236 ok(hr
== S_OK
, "IFilterMapper_RegisterFilter failed with %x\n", hr
);
238 hr
= IFilterMapper_RegisterPin(pMapper
, clsidFilter
, wszPinName
, TRUE
, FALSE
, FALSE
, FALSE
, GUID_NULL
, NULL
);
239 ok(hr
== S_OK
, "IFilterMapper_RegisterPin failed with %x\n", hr
);
241 hr
= IFilterMapper_RegisterPinType(pMapper
, clsidFilter
, wszPinName
, GUID_NULL
, GUID_NULL
);
242 ok(hr
== S_OK
, "IFilterMapper_RegisterPinType failed with %x\n", hr
);
244 hr
= IFilterMapper2_EnumMatchingFilters(pMapper2
, &pEnum
, 0, TRUE
, MERIT_UNLIKELY
, TRUE
,
245 0, NULL
, NULL
, &GUID_NULL
, FALSE
, FALSE
, 0, NULL
, NULL
, &GUID_NULL
);
246 ok(hr
== S_OK
, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr
);
247 if (SUCCEEDED(hr
) && pEnum
)
249 found
= enum_find_filter(wszFilterName
, pEnum
);
250 ok(found
, "IFilterMapper2_EnumMatchingFilters failed to return the test filter\n");
253 if (pEnum
) IEnumMoniker_Release(pEnum
);
257 hr
= IFilterMapper_EnumMatchingFilters(pMapper
, &pRegEnum
, MERIT_UNLIKELY
, TRUE
, GUID_NULL
, GUID_NULL
,
258 FALSE
, FALSE
, GUID_NULL
, GUID_NULL
);
259 ok(hr
== S_OK
, "IFilterMapper_EnumMatchingFilters failed with %x\n", hr
);
260 if (SUCCEEDED(hr
) && pRegEnum
)
265 while(!found
&& IEnumRegFilters_Next(pRegEnum
, 1, &prgf
, &cFetched
) == S_OK
)
269 WideCharToMultiByte(CP_ACP
, 0, prgf
->Name
, -1, val
, sizeof(val
), 0, 0);
270 if (!lstrcmpA(val
, szFilterName
)) found
= TRUE
;
275 IEnumRegFilters_Release(pRegEnum
);
277 ok(found
, "IFilterMapper_EnumMatchingFilters failed to return the test filter\n");
279 hr
= IFilterMapper_UnregisterFilter(pMapper
, clsidFilter
);
280 ok(hr
== S_OK
, "FilterMapper_UnregisterFilter failed with %x\n", hr
);
282 lRet
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, szClsid
, 0, KEY_WRITE
| DELETE
, &hKey
);
283 ok(lRet
== ERROR_SUCCESS
, "RegOpenKeyExA failed with %x\n", HRESULT_FROM_WIN32(lRet
));
285 lRet
= StringFromGUID2(&clsidFilter
, wszRegKey
, MAX_PATH
);
286 ok(lRet
> 0, "StringFromGUID2 failed\n");
287 WideCharToMultiByte(CP_ACP
, 0, wszRegKey
, -1, szRegKey
, sizeof(szRegKey
), 0, 0);
289 lRet
= RegDeleteKeyA(hKey
, szRegKey
);
290 ok(lRet
== ERROR_SUCCESS
, "RegDeleteKeyA failed with %x\n", HRESULT_FROM_WIN32(lRet
));
292 if (hKey
) RegCloseKey(hKey
);
297 if (pMapper
) IFilterMapper_Release(pMapper
);
298 if (pMapper2
) IFilterMapper2_Release(pMapper2
);
301 static ULONG
getRefcount(IUnknown
*iface
)
303 IUnknown_AddRef(iface
);
304 return IUnknown_Release(iface
);
307 static void test_ifiltermapper_from_filtergraph(void)
309 IFilterGraph2
* pgraph2
= NULL
;
310 IFilterMapper2
*pMapper2
= NULL
;
311 IFilterGraph
*filtergraph
= NULL
;
315 hr
= CoCreateInstance(&CLSID_FilterGraph
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IFilterGraph2
, (LPVOID
*)&pgraph2
);
316 ok(hr
== S_OK
, "CoCreateInstance failed with %08x\n", hr
);
317 if (!pgraph2
) goto out
;
319 hr
= IFilterGraph2_QueryInterface(pgraph2
, &IID_IFilterMapper2
, (LPVOID
*)&pMapper2
);
320 ok(hr
== S_OK
, "IFilterGraph2_QueryInterface failed with %08x\n", hr
);
321 if (!pMapper2
) goto out
;
323 refcount
= getRefcount((IUnknown
*)pgraph2
);
324 ok(refcount
== 2, "unexpected reference count: %u\n", refcount
);
325 refcount
= getRefcount((IUnknown
*)pMapper2
);
326 ok(refcount
== 2, "unexpected reference count: %u\n", refcount
);
328 IFilterMapper2_AddRef(pMapper2
);
329 refcount
= getRefcount((IUnknown
*)pgraph2
);
330 ok(refcount
== 3, "unexpected reference count: %u\n", refcount
);
331 refcount
= getRefcount((IUnknown
*)pMapper2
);
332 ok(refcount
== 3, "unexpected reference count: %u\n", refcount
);
333 IFilterMapper2_Release(pMapper2
);
335 hr
= IFilterMapper2_QueryInterface(pMapper2
, &IID_IFilterGraph
, (LPVOID
*)&filtergraph
);
336 ok(hr
== S_OK
, "IFilterMapper2_QueryInterface failed with %08x\n", hr
);
337 if (!filtergraph
) goto out
;
339 IFilterMapper2_Release(pMapper2
);
341 IFilterGraph_Release(filtergraph
);
344 hr
= CoCreateInstance(&CLSID_FilterMapper2
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IFilterMapper2
, (LPVOID
*)&pMapper2
);
345 ok(hr
== S_OK
, "CoCreateInstance failed with %08x\n", hr
);
346 if (!pMapper2
) goto out
;
348 hr
= IFilterMapper2_QueryInterface(pMapper2
, &IID_IFilterGraph
, (LPVOID
*)&filtergraph
);
349 ok(hr
== E_NOINTERFACE
, "IFilterMapper2_QueryInterface unexpected result: %08x\n", hr
);
353 if (pMapper2
) IFilterMapper2_Release(pMapper2
);
354 if (filtergraph
) IFilterGraph_Release(filtergraph
);
355 if (pgraph2
) IFilterGraph2_Release(pgraph2
);
358 static void test_register_filter_with_null_clsMinorType(void)
360 IFilterMapper2
*pMapper
= NULL
;
363 REGFILTERPINS rgPins
;
364 REGFILTERPINS2 rgPins2
;
365 REGPINTYPES rgPinType
;
366 static WCHAR wszPinName
[] = {'P', 'i', 'n', 0 };
367 static const WCHAR wszFilterName1
[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', '1', 0 };
368 static const WCHAR wszFilterName2
[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', '2', 0 };
372 hr
= CoCreateInstance(&CLSID_FilterMapper2
, NULL
, CLSCTX_INPROC_SERVER
,
373 &IID_IFilterMapper2
, (LPVOID
*)&pMapper
);
374 ok(hr
== S_OK
, "CoCreateInstance failed with %x\n", hr
);
375 if (FAILED(hr
)) goto out
;
377 hr
= CoCreateGuid(&clsidFilter1
);
378 ok(hr
== S_OK
, "CoCreateGuid failed with %x\n", hr
);
379 hr
= CoCreateGuid(&clsidFilter2
);
380 ok(hr
== S_OK
, "CoCreateGuid failed with %x\n", hr
);
382 rgPinType
.clsMajorType
= &GUID_NULL
;
383 /* Make sure quartz accepts it without crashing */
384 rgPinType
.clsMinorType
= NULL
;
386 /* Test with pin descript version 1 */
387 ZeroMemory(&rgf2
, sizeof(rgf2
));
389 rgf2
.dwMerit
= MERIT_UNLIKELY
;
390 S(U(rgf2
)).cPins
= 1;
391 S(U(rgf2
)).rgPins
= &rgPins
;
393 rgPins
.strName
= wszPinName
;
394 rgPins
.bRendered
= 1;
398 rgPins
.clsConnectsToFilter
= NULL
;
399 rgPins
.strConnectsToPin
= NULL
;
400 rgPins
.nMediaTypes
= 1;
401 rgPins
.lpMediaType
= &rgPinType
;
403 hr
= IFilterMapper2_RegisterFilter(pMapper
, &clsidFilter1
, wszFilterName1
, NULL
,
404 &CLSID_LegacyAmFilterCategory
, NULL
, &rgf2
);
405 ok(hr
== S_OK
, "IFilterMapper2_RegisterFilter failed with %x\n", hr
);
407 hr
= IFilterMapper2_UnregisterFilter(pMapper
, &CLSID_LegacyAmFilterCategory
, NULL
, &clsidFilter1
);
408 ok(hr
== S_OK
, "FilterMapper_UnregisterFilter failed with %x\n", hr
);
410 /* Test with pin descript version 2 */
411 ZeroMemory(&rgf2
, sizeof(rgf2
));
413 rgf2
.dwMerit
= MERIT_UNLIKELY
;
414 S1(U(rgf2
)).cPins2
= 1;
415 S1(U(rgf2
)).rgPins2
= &rgPins2
;
417 rgPins2
.dwFlags
= REG_PINFLAG_B_RENDERER
;
418 rgPins2
.cInstances
= 1;
419 rgPins2
.nMediaTypes
= 1;
420 rgPins2
.lpMediaType
= &rgPinType
;
421 rgPins2
.nMediums
= 0;
422 rgPins2
.lpMedium
= NULL
;
423 rgPins2
.clsPinCategory
= NULL
;
425 hr
= IFilterMapper2_RegisterFilter(pMapper
, &clsidFilter2
, wszFilterName2
, NULL
,
426 &CLSID_LegacyAmFilterCategory
, NULL
, &rgf2
);
427 ok(hr
== S_OK
, "IFilterMapper2_RegisterFilter failed with %x\n", hr
);
429 hr
= IFilterMapper2_UnregisterFilter(pMapper
, &CLSID_LegacyAmFilterCategory
, NULL
, &clsidFilter2
);
430 ok(hr
== S_OK
, "FilterMapper_UnregisterFilter failed with %x\n", hr
);
434 if (pMapper
) IFilterMapper2_Release(pMapper
);
438 START_TEST(filtermapper
)
442 test_fm2_enummatchingfilters();
443 test_legacy_filter_registration();
444 test_ifiltermapper_from_filtergraph();
445 test_register_filter_with_null_clsMinorType();