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, 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 if (hr == E_ACCESSDENIED)
121 skip("Not authorized to register filters\n");
124 ok(hr == S_OK, "IFilterMapper2_RegisterFilter failed with %x\n", hr);
126 rgPins2[0].dwFlags = 0;
128 rgPins2[1].dwFlags = REG_PINFLAG_B_OUTPUT;
129 rgPins2[1].cInstances = 1;
130 rgPins2[1].nMediaTypes = 1;
131 rgPins2[1].lpMediaType = &rgPinType;
132 rgPins2[1].nMediums = 0;
133 rgPins2[1].lpMedium = NULL;
134 rgPins2[1].clsPinCategory = NULL;
136 S1(U(rgf2)).cPins2 = 2;
138 hr = IFilterMapper2_RegisterFilter(pMapper, &clsidFilter2, wszFilterName2, NULL,
139 &CLSID_LegacyAmFilterCategory, NULL, &rgf2);
140 ok(hr == S_OK, "IFilterMapper2_RegisterFilter failed with %x\n", hr);
142 hr = IFilterMapper2_EnumMatchingFilters(pMapper, &pEnum, 0, TRUE, MERIT_UNLIKELY, TRUE,
143 0, NULL, NULL, &GUID_NULL, FALSE, FALSE, 0, NULL, NULL, &GUID_NULL);
144 ok(hr == S_OK, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr);
145 if (SUCCEEDED(hr) && pEnum)
147 found = enum_find_filter(wszFilterName1, pEnum);
148 ok(found, "EnumMatchingFilters failed to return the test filter 1\n");
151 if (pEnum) IEnumMoniker_Release(pEnum);
154 hr = IFilterMapper2_EnumMatchingFilters(pMapper, &pEnum, 0, TRUE, MERIT_UNLIKELY, TRUE,
155 0, NULL, NULL, &GUID_NULL, FALSE, FALSE, 0, NULL, NULL, &GUID_NULL);
156 ok(hr == S_OK, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr);
157 if (SUCCEEDED(hr) && pEnum)
159 found = enum_find_filter(wszFilterName2, pEnum);
160 ok(found, "EnumMatchingFilters failed to return the test filter 2\n");
163 if (pEnum) IEnumMoniker_Release(pEnum);
166 /* Non renderer must not be returned with bRender=TRUE */
168 hr = IFilterMapper2_EnumMatchingFilters(pMapper, &pEnum, 0, TRUE, MERIT_UNLIKELY, TRUE,
169 0, NULL, NULL, &GUID_NULL, TRUE, FALSE, 0, NULL, NULL, &GUID_NULL);
170 ok(hr == S_OK, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr);
172 if (SUCCEEDED(hr) && pEnum)
174 found = enum_find_filter(wszFilterName1, pEnum);
175 ok(found, "EnumMatchingFilters failed to return the test filter 1\n");
179 if (pEnum) IEnumMoniker_Release(pEnum);
182 hr = IFilterMapper2_EnumMatchingFilters(pMapper, &pEnum, 0, TRUE, MERIT_UNLIKELY, TRUE,
183 0, NULL, NULL, &GUID_NULL, TRUE, FALSE, 0, NULL, NULL, &GUID_NULL);
184 ok(hr == S_OK, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr);
186 if (SUCCEEDED(hr) && pEnum)
188 found = enum_find_filter(wszFilterName2, pEnum);
189 ok(!found, "EnumMatchingFilters should not return the test filter 2\n");
192 hr = IFilterMapper2_UnregisterFilter(pMapper, &CLSID_LegacyAmFilterCategory, NULL,
194 ok(SUCCEEDED(hr), "IFilterMapper2_UnregisterFilter failed with %x\n", hr);
196 hr = IFilterMapper2_UnregisterFilter(pMapper, &CLSID_LegacyAmFilterCategory, NULL,
198 ok(SUCCEEDED(hr), "IFilterMapper2_UnregisterFilter failed with %x\n", hr);
202 if (pEnum) IEnumMoniker_Release(pEnum);
203 if (pMapper) IFilterMapper2_Release(pMapper);
206 static void test_legacy_filter_registration(void)
208 IFilterMapper2 *pMapper2 = NULL;
209 IFilterMapper *pMapper = NULL;
211 static const WCHAR wszFilterName[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', 0 };
212 static const CHAR szFilterName[] = "Testfilter";
213 static const WCHAR wszPinName[] = {'P', 'i', 'n', '1', 0 };
215 CHAR szRegKey[MAX_PATH];
216 static const CHAR szClsid[] = "CLSID";
217 WCHAR wszGuidstring[MAX_PATH];
218 CHAR szGuidstring[MAX_PATH];
221 IEnumMoniker *pEnum = NULL;
223 IEnumRegFilters *pRegEnum = NULL;
225 /* Test if legacy filter registration scheme works (filter is added to HKCR\Filter). IFilterMapper_RegisterFilter
226 * registers in this way. Filters so registered must then be accessible through both IFilterMapper_EnumMatchingFilters
227 * and IFilterMapper2_EnumMatchingFilters. */
228 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER,
229 &IID_IFilterMapper2, (LPVOID*)&pMapper2);
230 ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr);
231 if (FAILED(hr)) goto out;
233 hr = IFilterMapper2_QueryInterface(pMapper2, &IID_IFilterMapper, (LPVOID)&pMapper);
234 ok(hr == S_OK, "IFilterMapper2_QueryInterface failed with %x\n", hr);
235 if (FAILED(hr)) goto out;
237 /* Register a test filter. */
238 hr = CoCreateGuid(&clsidFilter);
239 ok(hr == S_OK, "CoCreateGuid failed with %x\n", hr);
241 lRet = StringFromGUID2(&clsidFilter, wszGuidstring, MAX_PATH);
242 ok(lRet > 0, "StringFromGUID2 failed\n");
244 WideCharToMultiByte(CP_ACP, 0, wszGuidstring, -1, szGuidstring, MAX_PATH, 0, 0);
246 lstrcpyA(szRegKey, szClsid);
247 lstrcatA(szRegKey, "\\");
248 lstrcatA(szRegKey, szGuidstring);
250 /* Register---- functions need a filter class key to write pin and pin media type data to. Create a bogus
251 * class key for it. */
252 lRet = RegCreateKeyExA(HKEY_CLASSES_ROOT, szRegKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
253 if (lRet == ERROR_ACCESS_DENIED)
254 skip("Not authorized to register filters\n");
257 ok(lRet == ERROR_SUCCESS, "RegCreateKeyExA failed with %x\n", HRESULT_FROM_WIN32(lRet));
259 /* Set default value - this is interpreted as "friendly name" later. */
260 lRet = RegSetValueExA(hKey, NULL, 0, REG_SZ, (LPBYTE)szFilterName, lstrlenA(szFilterName) + 1);
261 ok(lRet == ERROR_SUCCESS, "RegSetValueExA failed with %x\n", HRESULT_FROM_WIN32(lRet));
263 if (hKey) RegCloseKey(hKey);
266 hr = IFilterMapper_RegisterFilter(pMapper, clsidFilter, wszFilterName, MERIT_UNLIKELY);
267 ok(hr == S_OK, "IFilterMapper_RegisterFilter failed with %x\n", hr);
269 hr = IFilterMapper_RegisterPin(pMapper, clsidFilter, wszPinName, TRUE, FALSE, FALSE, FALSE, GUID_NULL, NULL);
270 ok(hr == S_OK, "IFilterMapper_RegisterPin failed with %x\n", hr);
272 hr = IFilterMapper_RegisterPinType(pMapper, clsidFilter, wszPinName, GUID_NULL, GUID_NULL);
273 ok(hr == S_OK, "IFilterMapper_RegisterPinType failed with %x\n", hr);
275 hr = IFilterMapper2_EnumMatchingFilters(pMapper2, &pEnum, 0, TRUE, MERIT_UNLIKELY, TRUE,
276 0, NULL, NULL, &GUID_NULL, FALSE, FALSE, 0, NULL, NULL, &GUID_NULL);
277 ok(hr == S_OK, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr);
278 if (SUCCEEDED(hr) && pEnum)
280 found = enum_find_filter(wszFilterName, pEnum);
281 ok(found, "IFilterMapper2_EnumMatchingFilters failed to return the test filter\n");
284 if (pEnum) IEnumMoniker_Release(pEnum);
288 hr = IFilterMapper_EnumMatchingFilters(pMapper, &pRegEnum, MERIT_UNLIKELY, TRUE, GUID_NULL, GUID_NULL,
289 FALSE, FALSE, GUID_NULL, GUID_NULL);
290 ok(hr == S_OK, "IFilterMapper_EnumMatchingFilters failed with %x\n", hr);
291 if (SUCCEEDED(hr) && pRegEnum)
296 while(!found && IEnumRegFilters_Next(pRegEnum, 1, &prgf, &cFetched) == S_OK)
300 WideCharToMultiByte(CP_ACP, 0, prgf->Name, -1, val, sizeof(val), 0, 0);
301 if (!lstrcmpA(val, szFilterName)) found = TRUE;
306 IEnumRegFilters_Release(pRegEnum);
308 ok(found, "IFilterMapper_EnumMatchingFilters failed to return the test filter\n");
310 hr = IFilterMapper_UnregisterFilter(pMapper, clsidFilter);
311 ok(hr == S_OK, "FilterMapper_UnregisterFilter failed with %x\n", hr);
313 lRet = RegOpenKeyExA(HKEY_CLASSES_ROOT, szClsid, 0, KEY_WRITE | DELETE, &hKey);
314 ok(lRet == ERROR_SUCCESS, "RegOpenKeyExA failed with %x\n", HRESULT_FROM_WIN32(lRet));
316 lRet = RegDeleteKeyA(hKey, szGuidstring);
317 ok(lRet == ERROR_SUCCESS, "RegDeleteKeyA failed with %x\n", HRESULT_FROM_WIN32(lRet));
320 if (hKey) RegCloseKey(hKey);
325 if (pMapper) IFilterMapper_Release(pMapper);
326 if (pMapper2) IFilterMapper2_Release(pMapper2);
329 static ULONG getRefcount(IUnknown *iface)
331 IUnknown_AddRef(iface);
332 return IUnknown_Release(iface);
335 static void test_ifiltermapper_from_filtergraph(void)
337 IFilterGraph2* pgraph2 = NULL;
338 IFilterMapper2 *pMapper2 = NULL;
339 IFilterGraph *filtergraph = NULL;
343 hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterGraph2, (LPVOID*)&pgraph2);
344 ok(hr == S_OK, "CoCreateInstance failed with %08x\n", hr);
345 if (!pgraph2) goto out;
347 hr = IFilterGraph2_QueryInterface(pgraph2, &IID_IFilterMapper2, (LPVOID*)&pMapper2);
348 ok(hr == S_OK, "IFilterGraph2_QueryInterface failed with %08x\n", hr);
349 if (!pMapper2) goto out;
351 refcount = getRefcount((IUnknown*)pgraph2);
352 ok(refcount == 2, "unexpected reference count: %u\n", refcount);
353 refcount = getRefcount((IUnknown*)pMapper2);
354 ok(refcount == 2, "unexpected reference count: %u\n", refcount);
356 IFilterMapper2_AddRef(pMapper2);
357 refcount = getRefcount((IUnknown*)pgraph2);
358 ok(refcount == 3, "unexpected reference count: %u\n", refcount);
359 refcount = getRefcount((IUnknown*)pMapper2);
360 ok(refcount == 3, "unexpected reference count: %u\n", refcount);
361 IFilterMapper2_Release(pMapper2);
363 hr = IFilterMapper2_QueryInterface(pMapper2, &IID_IFilterGraph, (LPVOID*)&filtergraph);
364 ok(hr == S_OK, "IFilterMapper2_QueryInterface failed with %08x\n", hr);
365 if (!filtergraph) goto out;
367 IFilterMapper2_Release(pMapper2);
369 IFilterGraph_Release(filtergraph);
372 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&pMapper2);
373 ok(hr == S_OK, "CoCreateInstance failed with %08x\n", hr);
374 if (!pMapper2) goto out;
376 hr = IFilterMapper2_QueryInterface(pMapper2, &IID_IFilterGraph, (LPVOID*)&filtergraph);
377 ok(hr == E_NOINTERFACE, "IFilterMapper2_QueryInterface unexpected result: %08x\n", hr);
381 if (pMapper2) IFilterMapper2_Release(pMapper2);
382 if (filtergraph) IFilterGraph_Release(filtergraph);
383 if (pgraph2) IFilterGraph2_Release(pgraph2);
386 static void test_register_filter_with_null_clsMinorType(void)
388 IFilterMapper2 *pMapper = NULL;
391 REGFILTERPINS rgPins;
392 REGFILTERPINS2 rgPins2;
393 REGPINTYPES rgPinType;
394 static WCHAR wszPinName[] = {'P', 'i', 'n', 0 };
395 static const WCHAR wszFilterName1[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', '1', 0 };
396 static const WCHAR wszFilterName2[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', '2', 0 };
400 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER,
401 &IID_IFilterMapper2, (LPVOID*)&pMapper);
402 ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr);
403 if (FAILED(hr)) goto out;
405 hr = CoCreateGuid(&clsidFilter1);
406 ok(hr == S_OK, "CoCreateGuid failed with %x\n", hr);
407 hr = CoCreateGuid(&clsidFilter2);
408 ok(hr == S_OK, "CoCreateGuid failed with %x\n", hr);
410 rgPinType.clsMajorType = &GUID_NULL;
411 /* Make sure quartz accepts it without crashing */
412 rgPinType.clsMinorType = NULL;
414 /* Test with pin descript version 1 */
415 ZeroMemory(&rgf2, sizeof(rgf2));
417 rgf2.dwMerit = MERIT_UNLIKELY;
418 S(U(rgf2)).cPins = 1;
419 S(U(rgf2)).rgPins = &rgPins;
421 rgPins.strName = wszPinName;
422 rgPins.bRendered = 1;
426 rgPins.clsConnectsToFilter = NULL;
427 rgPins.strConnectsToPin = NULL;
428 rgPins.nMediaTypes = 1;
429 rgPins.lpMediaType = &rgPinType;
431 hr = IFilterMapper2_RegisterFilter(pMapper, &clsidFilter1, wszFilterName1, NULL,
432 &CLSID_LegacyAmFilterCategory, NULL, &rgf2);
433 if (hr == E_ACCESSDENIED)
435 skip("Not authorized to register filters\n");
438 ok(hr == S_OK, "IFilterMapper2_RegisterFilter failed with %x\n", hr);
440 hr = IFilterMapper2_UnregisterFilter(pMapper, &CLSID_LegacyAmFilterCategory, NULL, &clsidFilter1);
441 ok(hr == S_OK, "FilterMapper_UnregisterFilter failed with %x\n", hr);
443 /* Test with pin descript version 2 */
444 ZeroMemory(&rgf2, sizeof(rgf2));
446 rgf2.dwMerit = MERIT_UNLIKELY;
447 S1(U(rgf2)).cPins2 = 1;
448 S1(U(rgf2)).rgPins2 = &rgPins2;
450 rgPins2.dwFlags = REG_PINFLAG_B_RENDERER;
451 rgPins2.cInstances = 1;
452 rgPins2.nMediaTypes = 1;
453 rgPins2.lpMediaType = &rgPinType;
454 rgPins2.nMediums = 0;
455 rgPins2.lpMedium = NULL;
456 rgPins2.clsPinCategory = NULL;
458 hr = IFilterMapper2_RegisterFilter(pMapper, &clsidFilter2, wszFilterName2, NULL,
459 &CLSID_LegacyAmFilterCategory, NULL, &rgf2);
460 ok(hr == S_OK, "IFilterMapper2_RegisterFilter failed with %x\n", hr);
462 hr = IFilterMapper2_UnregisterFilter(pMapper, &CLSID_LegacyAmFilterCategory, NULL, &clsidFilter2);
463 ok(hr == S_OK, "FilterMapper_UnregisterFilter failed with %x\n", hr);
467 if (pMapper) IFilterMapper2_Release(pMapper);
471 START_TEST(filtermapper)
475 test_fm2_enummatchingfilters();
476 test_legacy_filter_registration();
477 test_ifiltermapper_from_filtergraph();
478 test_register_filter_with_null_clsMinorType();