push 319afc849e77c7d120112c7718dd0b4fc9a636fe
[wine/hacks.git] / dlls / quartz / tests / filtermapper.c
blobcf0a383947b1d6cbd1e8e6ad8621edde84752193
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 if (!lstrcmpW((WCHAR*)V_UNION(&var, bstrVal), wszFilterName)) found = TRUE;
63 IPropertyBag_Release(pPropBagCat);
64 IMoniker_Release(pMoniker);
65 VariantClear(&var);
68 return found;
71 static void test_fm2_enummatchingfilters(void)
73 IFilterMapper2 *pMapper = NULL;
74 HRESULT hr;
75 REGFILTER2 rgf2;
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 };
80 CLSID clsidFilter1;
81 CLSID clsidFilter2;
82 IEnumMoniker *pEnum = NULL;
83 BOOL found;
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 */
98 rgf2.dwVersion = 2;
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);
146 pEnum = NULL;
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,
163 &clsidFilter1);
164 ok(SUCCEEDED(hr), "IFilterMapper2_UnregisterFilter failed with %x\n", hr);
166 hr = IFilterMapper2_UnregisterFilter(pMapper, &CLSID_LegacyAmFilterCategory, NULL,
167 &clsidFilter2);
168 ok(SUCCEEDED(hr), "IFilterMapper2_UnregisterFilter failed with %x\n", hr);
170 out:
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;
180 HRESULT hr;
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 };
183 CLSID clsidFilter;
184 WCHAR wszRegKey[MAX_PATH];
185 static const WCHAR wszClsid[] = {'C','L','S','I','D', 0};
186 static const WCHAR wszSlash[] = {'\\', 0};
187 LONG lRet;
188 HKEY hKey = NULL;
189 IEnumMoniker *pEnum = NULL;
190 BOOL found;
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");
213 if (!lRet) goto out;
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);
225 hKey = NULL;
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);
246 pEnum = NULL;
248 found = FALSE;
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)
254 ULONG cFetched;
255 REGFILTER *prgf;
257 while(!found && IEnumRegFilters_Next(pRegEnum, 1, &prgf, &cFetched) == S_OK)
259 if (!lstrcmpW(prgf->Name, wszFilterName)) found = TRUE;
261 CoTaskMemFree(prgf);
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);
281 hKey = NULL;
283 out:
285 if (pMapper) IFilterMapper_Release(pMapper);
286 if (pMapper2) IFilterMapper2_Release(pMapper2);
289 START_TEST(filtermapper)
291 CoInitialize(NULL);
293 test_fm2_enummatchingfilters();
294 test_legacy_filter_registration();
296 CoUninitialize();