wininet: Support the Cache-Control max-age directive for setting url cache entry...
[wine/testsucceed.git] / dlls / quartz / tests / filtermapper.c
blob4a8a3bb579b3c9785e627bb432610c36f2280e6e
1 /*
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
21 #define COBJMACROS
23 #include "wine/test.h"
24 #include "winbase.h"
25 #include "initguid.h"
26 #include "dshow.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;
34 BOOL found = FALSE;
35 ULONG nb;
36 HRESULT hr;
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;
42 VARIANT var;
44 VariantInit(&var);
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)
50 VariantClear(&var);
51 IMoniker_Release(pMoniker);
52 continue;
55 hr = IPropertyBag_Read(pPropBagCat, wszFriendlyName, &var, NULL);
56 ok(SUCCEEDED(hr), "IPropertyBag_Read failed with %x\n", hr);
58 if (SUCCEEDED(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);
69 VariantClear(&var);
72 return found;
75 static void test_fm2_enummatchingfilters(void)
77 IFilterMapper2 *pMapper = NULL;
78 HRESULT hr;
79 REGFILTER2 rgf2;
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 };
84 CLSID clsidFilter1;
85 CLSID clsidFilter2;
86 IEnumMoniker *pEnum = NULL;
87 BOOL found;
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 */
102 rgf2.dwVersion = 2;
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");
147 if (pEnum) IEnumMoniker_Release(pEnum);
148 pEnum = NULL;
150 hr = IFilterMapper2_EnumMatchingFilters(pMapper, &pEnum, 0, TRUE, MERIT_UNLIKELY, TRUE,
151 0, NULL, NULL, &GUID_NULL, FALSE, FALSE, 0, NULL, NULL, &GUID_NULL);
152 ok(hr == S_OK, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr);
153 if (SUCCEEDED(hr) && pEnum)
155 found = enum_find_filter(wszFilterName2, pEnum);
156 ok(found, "EnumMatchingFilters failed to return the test filter 2\n");
159 if (pEnum) IEnumMoniker_Release(pEnum);
160 pEnum = NULL;
162 /* Non renderer must not be returned with bRender=TRUE */
164 hr = IFilterMapper2_EnumMatchingFilters(pMapper, &pEnum, 0, TRUE, MERIT_UNLIKELY, TRUE,
165 0, NULL, NULL, &GUID_NULL, TRUE, FALSE, 0, NULL, NULL, &GUID_NULL);
166 ok(hr == S_OK, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr);
168 if (SUCCEEDED(hr) && pEnum)
170 found = enum_find_filter(wszFilterName1, pEnum);
171 ok(found, "EnumMatchingFilters failed to return the test filter 1\n");
174 if (pEnum) IEnumMoniker_Release(pEnum);
175 pEnum = NULL;
177 hr = IFilterMapper2_EnumMatchingFilters(pMapper, &pEnum, 0, TRUE, MERIT_UNLIKELY, TRUE,
178 0, NULL, NULL, &GUID_NULL, TRUE, FALSE, 0, NULL, NULL, &GUID_NULL);
179 ok(hr == S_OK, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr);
181 if (SUCCEEDED(hr) && pEnum)
183 found = enum_find_filter(wszFilterName2, pEnum);
184 ok(!found, "EnumMatchingFilters should not return the test filter 2\n");
187 hr = IFilterMapper2_UnregisterFilter(pMapper, &CLSID_LegacyAmFilterCategory, NULL,
188 &clsidFilter1);
189 ok(SUCCEEDED(hr), "IFilterMapper2_UnregisterFilter failed with %x\n", hr);
191 hr = IFilterMapper2_UnregisterFilter(pMapper, &CLSID_LegacyAmFilterCategory, NULL,
192 &clsidFilter2);
193 ok(SUCCEEDED(hr), "IFilterMapper2_UnregisterFilter failed with %x\n", hr);
195 out:
197 if (pEnum) IEnumMoniker_Release(pEnum);
198 if (pMapper) IFilterMapper2_Release(pMapper);
201 static void test_legacy_filter_registration(void)
203 IFilterMapper2 *pMapper2 = NULL;
204 IFilterMapper *pMapper = NULL;
205 HRESULT hr;
206 static const WCHAR wszFilterName[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', 0 };
207 static const CHAR szFilterName[] = "Testfilter";
208 static const WCHAR wszPinName[] = {'P', 'i', 'n', '1', 0 };
209 CLSID clsidFilter;
210 CHAR szRegKey[MAX_PATH];
211 static const CHAR szClsid[] = "CLSID";
212 WCHAR wszGuidstring[MAX_PATH];
213 CHAR szGuidstring[MAX_PATH];
214 LONG lRet;
215 HKEY hKey = NULL;
216 IEnumMoniker *pEnum = NULL;
217 BOOL found;
218 IEnumRegFilters *pRegEnum = NULL;
220 /* Test if legacy filter registration scheme works (filter is added to HKCR\Filter). IFilterMapper_RegisterFilter
221 * registers in this way. Filters so registered must then be accessible through both IFilterMapper_EnumMatchingFilters
222 * and IFilterMapper2_EnumMatchingFilters. */
223 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER,
224 &IID_IFilterMapper2, (LPVOID*)&pMapper2);
225 ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr);
226 if (FAILED(hr)) goto out;
228 hr = IFilterMapper2_QueryInterface(pMapper2, &IID_IFilterMapper, (LPVOID)&pMapper);
229 ok(hr == S_OK, "IFilterMapper2_QueryInterface failed with %x\n", hr);
230 if (FAILED(hr)) goto out;
232 /* Register a test filter. */
233 hr = CoCreateGuid(&clsidFilter);
234 ok(hr == S_OK, "CoCreateGuid failed with %x\n", hr);
236 lRet = StringFromGUID2(&clsidFilter, wszGuidstring, MAX_PATH);
237 ok(lRet > 0, "StringFromGUID2 failed\n");
238 if (!lRet) goto out;
239 WideCharToMultiByte(CP_ACP, 0, wszGuidstring, -1, szGuidstring, MAX_PATH, 0, 0);
241 lstrcpyA(szRegKey, szClsid);
242 lstrcatA(szRegKey, "\\");
243 lstrcatA(szRegKey, szGuidstring);
245 /* Register---- functions need a filter class key to write pin and pin media type data to. Create a bogus
246 * class key for it. */
247 lRet = RegCreateKeyExA(HKEY_CLASSES_ROOT, szRegKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
248 ok(lRet == ERROR_SUCCESS, "RegCreateKeyExA failed with %x\n", HRESULT_FROM_WIN32(lRet));
250 /* Set default value - this is interpreted as "friendly name" later. */
251 lRet = RegSetValueExA(hKey, NULL, 0, REG_SZ, (LPBYTE)szFilterName, lstrlenA(szFilterName) + 1);
252 ok(lRet == ERROR_SUCCESS, "RegSetValueExA failed with %x\n", HRESULT_FROM_WIN32(lRet));
254 if (hKey) RegCloseKey(hKey);
255 hKey = NULL;
257 hr = IFilterMapper_RegisterFilter(pMapper, clsidFilter, wszFilterName, MERIT_UNLIKELY);
258 ok(hr == S_OK, "IFilterMapper_RegisterFilter failed with %x\n", hr);
260 hr = IFilterMapper_RegisterPin(pMapper, clsidFilter, wszPinName, TRUE, FALSE, FALSE, FALSE, GUID_NULL, NULL);
261 ok(hr == S_OK, "IFilterMapper_RegisterPin failed with %x\n", hr);
263 hr = IFilterMapper_RegisterPinType(pMapper, clsidFilter, wszPinName, GUID_NULL, GUID_NULL);
264 ok(hr == S_OK, "IFilterMapper_RegisterPinType failed with %x\n", hr);
266 hr = IFilterMapper2_EnumMatchingFilters(pMapper2, &pEnum, 0, TRUE, MERIT_UNLIKELY, TRUE,
267 0, NULL, NULL, &GUID_NULL, FALSE, FALSE, 0, NULL, NULL, &GUID_NULL);
268 ok(hr == S_OK, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr);
269 if (SUCCEEDED(hr) && pEnum)
271 found = enum_find_filter(wszFilterName, pEnum);
272 ok(found, "IFilterMapper2_EnumMatchingFilters failed to return the test filter\n");
275 if (pEnum) IEnumMoniker_Release(pEnum);
276 pEnum = NULL;
278 found = FALSE;
279 hr = IFilterMapper_EnumMatchingFilters(pMapper, &pRegEnum, MERIT_UNLIKELY, TRUE, GUID_NULL, GUID_NULL,
280 FALSE, FALSE, GUID_NULL, GUID_NULL);
281 ok(hr == S_OK, "IFilterMapper_EnumMatchingFilters failed with %x\n", hr);
282 if (SUCCEEDED(hr) && pRegEnum)
284 ULONG cFetched;
285 REGFILTER *prgf;
287 while(!found && IEnumRegFilters_Next(pRegEnum, 1, &prgf, &cFetched) == S_OK)
289 CHAR val[512];
291 WideCharToMultiByte(CP_ACP, 0, prgf->Name, -1, val, sizeof(val), 0, 0);
292 if (!lstrcmpA(val, szFilterName)) found = TRUE;
294 CoTaskMemFree(prgf);
297 IEnumRegFilters_Release(pRegEnum);
299 ok(found, "IFilterMapper_EnumMatchingFilters failed to return the test filter\n");
301 hr = IFilterMapper_UnregisterFilter(pMapper, clsidFilter);
302 ok(hr == S_OK, "FilterMapper_UnregisterFilter failed with %x\n", hr);
304 lRet = RegOpenKeyExA(HKEY_CLASSES_ROOT, szClsid, 0, KEY_WRITE | DELETE, &hKey);
305 ok(lRet == ERROR_SUCCESS, "RegOpenKeyExA failed with %x\n", HRESULT_FROM_WIN32(lRet));
307 lRet = RegDeleteKeyA(hKey, szGuidstring);
308 ok(lRet == ERROR_SUCCESS, "RegDeleteKeyA failed with %x\n", HRESULT_FROM_WIN32(lRet));
310 if (hKey) RegCloseKey(hKey);
311 hKey = NULL;
313 out:
315 if (pMapper) IFilterMapper_Release(pMapper);
316 if (pMapper2) IFilterMapper2_Release(pMapper2);
319 static ULONG getRefcount(IUnknown *iface)
321 IUnknown_AddRef(iface);
322 return IUnknown_Release(iface);
325 static void test_ifiltermapper_from_filtergraph(void)
327 IFilterGraph2* pgraph2 = NULL;
328 IFilterMapper2 *pMapper2 = NULL;
329 IFilterGraph *filtergraph = NULL;
330 HRESULT hr;
331 ULONG refcount;
333 hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterGraph2, (LPVOID*)&pgraph2);
334 ok(hr == S_OK, "CoCreateInstance failed with %08x\n", hr);
335 if (!pgraph2) goto out;
337 hr = IFilterGraph2_QueryInterface(pgraph2, &IID_IFilterMapper2, (LPVOID*)&pMapper2);
338 ok(hr == S_OK, "IFilterGraph2_QueryInterface failed with %08x\n", hr);
339 if (!pMapper2) goto out;
341 refcount = getRefcount((IUnknown*)pgraph2);
342 ok(refcount == 2, "unexpected reference count: %u\n", refcount);
343 refcount = getRefcount((IUnknown*)pMapper2);
344 ok(refcount == 2, "unexpected reference count: %u\n", refcount);
346 IFilterMapper2_AddRef(pMapper2);
347 refcount = getRefcount((IUnknown*)pgraph2);
348 ok(refcount == 3, "unexpected reference count: %u\n", refcount);
349 refcount = getRefcount((IUnknown*)pMapper2);
350 ok(refcount == 3, "unexpected reference count: %u\n", refcount);
351 IFilterMapper2_Release(pMapper2);
353 hr = IFilterMapper2_QueryInterface(pMapper2, &IID_IFilterGraph, (LPVOID*)&filtergraph);
354 ok(hr == S_OK, "IFilterMapper2_QueryInterface failed with %08x\n", hr);
355 if (!filtergraph) goto out;
357 IFilterMapper2_Release(pMapper2);
358 pMapper2 = NULL;
359 IFilterGraph_Release(filtergraph);
360 filtergraph = NULL;
362 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&pMapper2);
363 ok(hr == S_OK, "CoCreateInstance failed with %08x\n", hr);
364 if (!pMapper2) goto out;
366 hr = IFilterMapper2_QueryInterface(pMapper2, &IID_IFilterGraph, (LPVOID*)&filtergraph);
367 ok(hr == E_NOINTERFACE, "IFilterMapper2_QueryInterface unexpected result: %08x\n", hr);
369 out:
371 if (pMapper2) IFilterMapper2_Release(pMapper2);
372 if (filtergraph) IFilterGraph_Release(filtergraph);
373 if (pgraph2) IFilterGraph2_Release(pgraph2);
376 static void test_register_filter_with_null_clsMinorType(void)
378 IFilterMapper2 *pMapper = NULL;
379 HRESULT hr;
380 REGFILTER2 rgf2;
381 REGFILTERPINS rgPins;
382 REGFILTERPINS2 rgPins2;
383 REGPINTYPES rgPinType;
384 static WCHAR wszPinName[] = {'P', 'i', 'n', 0 };
385 static const WCHAR wszFilterName1[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', '1', 0 };
386 static const WCHAR wszFilterName2[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', '2', 0 };
387 CLSID clsidFilter1;
388 CLSID clsidFilter2;
390 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER,
391 &IID_IFilterMapper2, (LPVOID*)&pMapper);
392 ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr);
393 if (FAILED(hr)) goto out;
395 hr = CoCreateGuid(&clsidFilter1);
396 ok(hr == S_OK, "CoCreateGuid failed with %x\n", hr);
397 hr = CoCreateGuid(&clsidFilter2);
398 ok(hr == S_OK, "CoCreateGuid failed with %x\n", hr);
400 rgPinType.clsMajorType = &GUID_NULL;
401 /* Make sure quartz accepts it without crashing */
402 rgPinType.clsMinorType = NULL;
404 /* Test with pin descript version 1 */
405 ZeroMemory(&rgf2, sizeof(rgf2));
406 rgf2.dwVersion = 1;
407 rgf2.dwMerit = MERIT_UNLIKELY;
408 S(U(rgf2)).cPins = 1;
409 S(U(rgf2)).rgPins = &rgPins;
411 rgPins.strName = wszPinName;
412 rgPins.bRendered = 1;
413 rgPins.bOutput = 0;
414 rgPins.bZero = 0;
415 rgPins.bMany = 0;
416 rgPins.clsConnectsToFilter = NULL;
417 rgPins.strConnectsToPin = NULL;
418 rgPins.nMediaTypes = 1;
419 rgPins.lpMediaType = &rgPinType;
421 hr = IFilterMapper2_RegisterFilter(pMapper, &clsidFilter1, wszFilterName1, NULL,
422 &CLSID_LegacyAmFilterCategory, NULL, &rgf2);
423 ok(hr == S_OK, "IFilterMapper2_RegisterFilter failed with %x\n", hr);
425 hr = IFilterMapper2_UnregisterFilter(pMapper, &CLSID_LegacyAmFilterCategory, NULL, &clsidFilter1);
426 ok(hr == S_OK, "FilterMapper_UnregisterFilter failed with %x\n", hr);
428 /* Test with pin descript version 2 */
429 ZeroMemory(&rgf2, sizeof(rgf2));
430 rgf2.dwVersion = 2;
431 rgf2.dwMerit = MERIT_UNLIKELY;
432 S1(U(rgf2)).cPins2 = 1;
433 S1(U(rgf2)).rgPins2 = &rgPins2;
435 rgPins2.dwFlags = REG_PINFLAG_B_RENDERER;
436 rgPins2.cInstances = 1;
437 rgPins2.nMediaTypes = 1;
438 rgPins2.lpMediaType = &rgPinType;
439 rgPins2.nMediums = 0;
440 rgPins2.lpMedium = NULL;
441 rgPins2.clsPinCategory = NULL;
443 hr = IFilterMapper2_RegisterFilter(pMapper, &clsidFilter2, wszFilterName2, NULL,
444 &CLSID_LegacyAmFilterCategory, NULL, &rgf2);
445 ok(hr == S_OK, "IFilterMapper2_RegisterFilter failed with %x\n", hr);
447 hr = IFilterMapper2_UnregisterFilter(pMapper, &CLSID_LegacyAmFilterCategory, NULL, &clsidFilter2);
448 ok(hr == S_OK, "FilterMapper_UnregisterFilter failed with %x\n", hr);
450 out:
452 if (pMapper) IFilterMapper2_Release(pMapper);
456 START_TEST(filtermapper)
458 CoInitialize(NULL);
460 test_fm2_enummatchingfilters();
461 test_legacy_filter_registration();
462 test_ifiltermapper_from_filtergraph();
463 test_register_filter_with_null_clsMinorType();
465 CoUninitialize();