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 if (!lstrcmpW((WCHAR
*)V_UNION(&var
, bstrVal
), wszFilterName
)) found
= TRUE
;
63 IPropertyBag_Release(pPropBagCat
);
64 IMoniker_Release(pMoniker
);
71 static void test_fm2_enummatchingfilters(void)
73 IFilterMapper2
*pMapper
= NULL
;
76 REGFILTERPINS2 rgPins2
[2];
77 REGPINTYPES rgPinType
;
78 static const WCHAR wszFilterName1
[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', '1', 0 };
79 static const WCHAR wszFilterName2
[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', '2', 0 };
82 IEnumMoniker
*pEnum
= NULL
;
85 ZeroMemory(&rgf2
, sizeof(rgf2
));
87 hr
= CoCreateInstance(&CLSID_FilterMapper2
, NULL
, CLSCTX_INPROC_SERVER
,
88 &IID_IFilterMapper2
, (LPVOID
*)&pMapper
);
89 ok(hr
== S_OK
, "CoCreateInstance failed with %x\n", hr
);
90 if (FAILED(hr
)) goto out
;
92 hr
= CoCreateGuid(&clsidFilter1
);
93 ok(hr
== S_OK
, "CoCreateGuid failed with %x\n", hr
);
94 hr
= CoCreateGuid(&clsidFilter2
);
95 ok(hr
== S_OK
, "CoCreateGuid failed with %x\n", hr
);
97 /* Test that a test renderer filter is returned when enumerating filters with bRender=FALSE */
99 rgf2
.dwMerit
= MERIT_UNLIKELY
;
100 S1(U(rgf2
)).cPins2
= 1;
101 S1(U(rgf2
)).rgPins2
= rgPins2
;
103 rgPins2
[0].dwFlags
= REG_PINFLAG_B_RENDERER
;
104 rgPins2
[0].cInstances
= 1;
105 rgPins2
[0].nMediaTypes
= 1;
106 rgPins2
[0].lpMediaType
= &rgPinType
;
107 rgPins2
[0].nMediums
= 0;
108 rgPins2
[0].lpMedium
= NULL
;
109 rgPins2
[0].clsPinCategory
= NULL
;
111 rgPinType
.clsMajorType
= &GUID_NULL
;
112 rgPinType
.clsMinorType
= &GUID_NULL
;
114 hr
= IFilterMapper2_RegisterFilter(pMapper
, &clsidFilter1
, wszFilterName1
, NULL
,
115 &CLSID_LegacyAmFilterCategory
, NULL
, &rgf2
);
116 ok(hr
== S_OK
, "IFilterMapper2_RegisterFilter failed with %x\n", hr
);
118 rgPins2
[0].dwFlags
= 0;
120 rgPins2
[1].dwFlags
= REG_PINFLAG_B_OUTPUT
;
121 rgPins2
[1].cInstances
= 1;
122 rgPins2
[1].nMediaTypes
= 1;
123 rgPins2
[1].lpMediaType
= &rgPinType
;
124 rgPins2
[1].nMediums
= 0;
125 rgPins2
[1].lpMedium
= NULL
;
126 rgPins2
[1].clsPinCategory
= NULL
;
128 S1(U(rgf2
)).cPins2
= 2;
130 hr
= IFilterMapper2_RegisterFilter(pMapper
, &clsidFilter2
, wszFilterName2
, NULL
,
131 &CLSID_LegacyAmFilterCategory
, NULL
, &rgf2
);
132 ok(hr
== S_OK
, "IFilterMapper2_RegisterFilter failed with %x\n", hr
);
134 hr
= IFilterMapper2_EnumMatchingFilters(pMapper
, &pEnum
, 0, TRUE
, MERIT_UNLIKELY
, TRUE
,
135 0, NULL
, NULL
, &GUID_NULL
, FALSE
, FALSE
, 0, NULL
, NULL
, &GUID_NULL
);
136 ok(hr
== S_OK
, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr
);
137 if (SUCCEEDED(hr
) && pEnum
)
139 found
= enum_find_filter(wszFilterName1
, pEnum
);
140 ok(found
, "EnumMatchingFilters failed to return the test filter 1\n");
141 found
= enum_find_filter(wszFilterName2
, pEnum
);
142 ok(found
, "EnumMatchingFilters failed to return the test filter 2\n");
145 if (pEnum
) IEnumMoniker_Release(pEnum
);
148 /* Non renderer must not be returned with bRender=TRUE */
150 hr
= IFilterMapper2_EnumMatchingFilters(pMapper
, &pEnum
, 0, TRUE
, MERIT_UNLIKELY
, TRUE
,
151 0, NULL
, NULL
, &GUID_NULL
, TRUE
, FALSE
, 0, NULL
, NULL
, &GUID_NULL
);
152 ok(hr
== S_OK
, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr
);
154 if (SUCCEEDED(hr
) && pEnum
)
156 found
= enum_find_filter(wszFilterName1
, pEnum
);
157 ok(found
, "EnumMatchingFilters failed to return the test filter 1\n");
158 found
= enum_find_filter(wszFilterName2
, pEnum
);
159 ok(!found
, "EnumMatchingFilters should not return the test filter 2\n");
162 hr
= IFilterMapper2_UnregisterFilter(pMapper
, &CLSID_LegacyAmFilterCategory
, NULL
,
164 ok(SUCCEEDED(hr
), "IFilterMapper2_UnregisterFilter failed with %x\n", hr
);
166 hr
= IFilterMapper2_UnregisterFilter(pMapper
, &CLSID_LegacyAmFilterCategory
, NULL
,
168 ok(SUCCEEDED(hr
), "IFilterMapper2_UnregisterFilter failed with %x\n", hr
);
172 if (pEnum
) IEnumMoniker_Release(pEnum
);
173 if (pMapper
) IFilterMapper2_Release(pMapper
);
176 static void test_legacy_filter_registration(void)
178 IFilterMapper2
*pMapper2
= NULL
;
179 IFilterMapper
*pMapper
= NULL
;
181 static const WCHAR wszFilterName
[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', 0 };
182 static const WCHAR wszPinName
[] = {'P', 'i', 'n', '1', 0 };
184 WCHAR wszRegKey
[MAX_PATH
];
185 static const WCHAR wszClsid
[] = {'C','L','S','I','D', 0};
186 static const WCHAR wszSlash
[] = {'\\', 0};
189 IEnumMoniker
*pEnum
= NULL
;
191 IEnumRegFilters
*pRegEnum
= NULL
;
193 /* Test if legacy filter registration scheme works (filter is added to HKCR\Filter). IFilterMapper_RegisterFilter
194 * registers in this way. Filters so registered must then be accessible through both IFilterMapper_EnumMatchingFilters
195 * and IFilterMapper2_EnumMatchingFilters. */
196 hr
= CoCreateInstance(&CLSID_FilterMapper2
, NULL
, CLSCTX_INPROC_SERVER
,
197 &IID_IFilterMapper2
, (LPVOID
*)&pMapper2
);
198 ok(hr
== S_OK
, "CoCreateInstance failed with %x\n", hr
);
199 if (FAILED(hr
)) goto out
;
201 hr
= IFilterMapper2_QueryInterface(pMapper2
, &IID_IFilterMapper
, (LPVOID
)&pMapper
);
202 ok(hr
== S_OK
, "IFilterMapper2_QueryInterface failed with %x\n", hr
);
203 if (FAILED(hr
)) goto out
;
205 /* Register a test filter. */
206 hr
= CoCreateGuid(&clsidFilter
);
207 ok(hr
== S_OK
, "CoCreateGuid failed with %x\n", hr
);
209 lstrcpyW(wszRegKey
, wszClsid
);
210 lstrcatW(wszRegKey
, wszSlash
);
211 lRet
= StringFromGUID2(&clsidFilter
, wszRegKey
+ lstrlenW(wszRegKey
), MAX_PATH
- lstrlenW(wszRegKey
));
212 ok(lRet
> 0, "StringFromGUID2 failed\n");
215 /* Register---- functions need a filter class key to write pin and pin media type data to. Create a bogus
216 * class key for it. */
217 lRet
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, wszRegKey
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
218 ok(lRet
== ERROR_SUCCESS
, "RegCreateKeyExW failed with %x\n", HRESULT_FROM_WIN32(lRet
));
220 /* Set default value - this is interpreted as "friendly name" later. */
221 lRet
= RegSetValueExW(hKey
, NULL
, 0, REG_SZ
, (LPBYTE
)wszFilterName
, (lstrlenW(wszFilterName
) + 1) * 2);
222 ok(lRet
== ERROR_SUCCESS
, "RegSetValueExW failed with %x\n", HRESULT_FROM_WIN32(lRet
));
224 if (hKey
) RegCloseKey(hKey
);
227 hr
= IFilterMapper_RegisterFilter(pMapper
, clsidFilter
, wszFilterName
, MERIT_UNLIKELY
);
228 ok(hr
== S_OK
, "IFilterMapper_RegisterFilter failed with %x\n", hr
);
230 hr
= IFilterMapper_RegisterPin(pMapper
, clsidFilter
, wszPinName
, TRUE
, FALSE
, FALSE
, FALSE
, GUID_NULL
, NULL
);
231 ok(hr
== S_OK
, "IFilterMapper_RegisterPin failed with %x\n", hr
);
233 hr
= IFilterMapper_RegisterPinType(pMapper
, clsidFilter
, wszPinName
, GUID_NULL
, GUID_NULL
);
234 ok(hr
== S_OK
, "IFilterMapper_RegisterPinType failed with %x\n", hr
);
236 hr
= IFilterMapper2_EnumMatchingFilters(pMapper2
, &pEnum
, 0, TRUE
, MERIT_UNLIKELY
, TRUE
,
237 0, NULL
, NULL
, &GUID_NULL
, FALSE
, FALSE
, 0, NULL
, NULL
, &GUID_NULL
);
238 ok(hr
== S_OK
, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr
);
239 if (SUCCEEDED(hr
) && pEnum
)
241 found
= enum_find_filter(wszFilterName
, pEnum
);
242 ok(found
, "IFilterMapper2_EnumMatchingFilters failed to return the test filter\n");
245 if (pEnum
) IEnumMoniker_Release(pEnum
);
249 hr
= IFilterMapper_EnumMatchingFilters(pMapper
, &pRegEnum
, MERIT_UNLIKELY
, TRUE
, GUID_NULL
, GUID_NULL
,
250 FALSE
, FALSE
, GUID_NULL
, GUID_NULL
);
251 ok(hr
== S_OK
, "IFilterMapper_EnumMatchingFilters failed with %x\n", hr
);
252 if (SUCCEEDED(hr
) && pRegEnum
)
257 while(!found
&& IEnumRegFilters_Next(pRegEnum
, 1, &prgf
, &cFetched
) == S_OK
)
259 if (!lstrcmpW(prgf
->Name
, wszFilterName
)) found
= TRUE
;
264 IEnumRegFilters_Release(pRegEnum
);
266 ok(found
, "IFilterMapper_EnumMatchingFilters failed to return the test filter\n");
268 hr
= IFilterMapper_UnregisterFilter(pMapper
, clsidFilter
);
269 ok(hr
== S_OK
, "FilterMapper_UnregisterFilter failed with %x\n", hr
);
271 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszClsid
, 0, KEY_WRITE
| DELETE
, &hKey
);
272 ok(lRet
== ERROR_SUCCESS
, "RegOpenKeyExW failed with %x\n", HRESULT_FROM_WIN32(lRet
));
274 lRet
= StringFromGUID2(&clsidFilter
, wszRegKey
, MAX_PATH
);
275 ok(lRet
> 0, "StringFromGUID2 failed\n");
277 lRet
= RegDeleteKeyW(hKey
, wszRegKey
);
278 ok(lRet
== ERROR_SUCCESS
, "RegDeleteKeyW failed with %x\n", HRESULT_FROM_WIN32(lRet
));
280 if (hKey
) RegCloseKey(hKey
);
285 if (pMapper
) IFilterMapper_Release(pMapper
);
286 if (pMapper2
) IFilterMapper2_Release(pMapper2
);
289 static ULONG
getRefcount(IUnknown
*iface
)
291 IUnknown_AddRef(iface
);
292 return IUnknown_Release(iface
);
295 static void test_ifiltermapper_from_filtergraph(void)
297 IFilterGraph2
* pgraph2
= NULL
;
298 IFilterMapper2
*pMapper2
= NULL
;
299 IFilterGraph
*filtergraph
= NULL
;
303 hr
= CoCreateInstance(&CLSID_FilterGraph
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IFilterGraph2
, (LPVOID
*)&pgraph2
);
304 ok(hr
== S_OK
, "CoCreateInstance failed with %08x\n", hr
);
305 if (!pgraph2
) goto out
;
307 hr
= IFilterGraph2_QueryInterface(pgraph2
, &IID_IFilterMapper2
, (LPVOID
*)&pMapper2
);
308 ok(hr
== S_OK
, "IFilterGraph2_QueryInterface failed with %08x\n", hr
);
309 if (!pMapper2
) goto out
;
311 refcount
= getRefcount((IUnknown
*)pgraph2
);
312 ok(refcount
== 2, "unexpected reference count: %u\n", refcount
);
313 refcount
= getRefcount((IUnknown
*)pMapper2
);
314 ok(refcount
== 2, "unexpected reference count: %u\n", refcount
);
316 IFilterMapper2_AddRef(pMapper2
);
317 refcount
= getRefcount((IUnknown
*)pgraph2
);
318 ok(refcount
== 3, "unexpected reference count: %u\n", refcount
);
319 refcount
= getRefcount((IUnknown
*)pMapper2
);
320 ok(refcount
== 3, "unexpected reference count: %u\n", refcount
);
321 IFilterMapper2_Release(pMapper2
);
323 hr
= IFilterMapper2_QueryInterface(pMapper2
, &IID_IFilterGraph
, (LPVOID
*)&filtergraph
);
324 ok(hr
== S_OK
, "IFilterMapper2_QueryInterface failed with %08x\n", hr
);
325 if (!filtergraph
) goto out
;
327 IFilterMapper2_Release(pMapper2
);
329 IFilterGraph_Release(filtergraph
);
332 hr
= CoCreateInstance(&CLSID_FilterMapper2
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IFilterMapper2
, (LPVOID
*)&pMapper2
);
333 ok(hr
== S_OK
, "CoCreateInstance failed with %08x\n", hr
);
334 if (!pMapper2
) goto out
;
336 hr
= IFilterMapper2_QueryInterface(pMapper2
, &IID_IFilterGraph
, (LPVOID
*)&filtergraph
);
337 ok(hr
== E_NOINTERFACE
, "IFilterMapper2_QueryInterface unexpected result: %08x\n", hr
);
341 if (pMapper2
) IFilterMapper2_Release(pMapper2
);
342 if (filtergraph
) IFilterGraph_Release(filtergraph
);
343 if (pgraph2
) IFilterGraph2_Release(pgraph2
);
346 START_TEST(filtermapper
)
350 test_fm2_enummatchingfilters();
351 test_legacy_filter_registration();
352 test_ifiltermapper_from_filtergraph();