ReactOS  0.4.14-dev-384-g5b37caa
filtermapper.c
Go to the documentation of this file.
1 /*
2  * Filtermapper unit tests for Quartz
3  *
4  * Copyright (C) 2008 Alexander Dorofeyev
5  *
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.
10  *
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.
15  *
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
19  */
20 
21 #define COBJMACROS
22 
23 #include "wine/test.h"
24 #include "winbase.h"
25 #include "initguid.h"
26 #include "dshow.h"
27 #include "wine/winternl.h"
28 
29 #include "fil_data.h"
30 
31 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
32 
33 /* Helper function, checks if filter with given name was enumerated. */
34 static BOOL enum_find_filter(const WCHAR *wszFilterName, IEnumMoniker *pEnum)
35 {
37  BOOL found = FALSE;
38  ULONG nb;
39  HRESULT hr;
40  static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
41 
42  while(!found && IEnumMoniker_Next(pEnum, 1, &pMoniker, &nb) == S_OK)
43  {
44  IPropertyBag * pPropBagCat = NULL;
45  VARIANT var;
46 
47  VariantInit(&var);
48 
49  hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
50  ok(SUCCEEDED(hr), "IMoniker_BindToStorage failed with %x\n", hr);
51 
52  hr = IPropertyBag_Read(pPropBagCat, wszFriendlyName, &var, NULL);
53  ok(SUCCEEDED(hr), "IPropertyBag_Read failed with %x\n", hr);
54 
55  if (!lstrcmpW(V_BSTR(&var), wszFilterName))
56  found = TRUE;
57 
58  IPropertyBag_Release(pPropBagCat);
59  IMoniker_Release(pMoniker);
60  VariantClear(&var);
61  }
62 
63  return found;
64 }
65 
67 {
68  IEnumRegFilters *enum_reg;
69  IFilterMapper2 *pMapper = NULL;
70  IFilterMapper *mapper;
71  HRESULT hr;
72  REGFILTER2 rgf2;
73  REGFILTERPINS2 rgPins2[2];
74  REGPINTYPES rgPinType;
75  static const WCHAR wszFilterName1[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', '1', 0 };
76  static const WCHAR wszFilterName2[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', '2', 0 };
77  CLSID clsidFilter1;
78  CLSID clsidFilter2;
79  IEnumMoniker *pEnum = NULL;
80  BOOL found, registered = TRUE;
81  REGFILTER *regfilter;
82  ULONG count;
83 
84  ZeroMemory(&rgf2, sizeof(rgf2));
85 
86  hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER,
87  &IID_IFilterMapper2, (LPVOID*)&pMapper);
88  ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr);
89  if (FAILED(hr)) goto out;
90 
91  hr = CoCreateGuid(&clsidFilter1);
92  ok(hr == S_OK, "CoCreateGuid failed with %x\n", hr);
93  hr = CoCreateGuid(&clsidFilter2);
94  ok(hr == S_OK, "CoCreateGuid failed with %x\n", hr);
95 
96  /* Test that a test renderer filter is returned when enumerating filters with bRender=FALSE */
97  rgf2.dwVersion = 2;
98  rgf2.dwMerit = MERIT_UNLIKELY;
99  S2(U(rgf2)).cPins2 = 1;
100  S2(U(rgf2)).rgPins2 = rgPins2;
101 
102  rgPins2[0].dwFlags = REG_PINFLAG_B_RENDERER;
103  rgPins2[0].cInstances = 1;
104  rgPins2[0].nMediaTypes = 1;
105  rgPins2[0].lpMediaType = &rgPinType;
106  rgPins2[0].nMediums = 0;
107  rgPins2[0].lpMedium = NULL;
108  rgPins2[0].clsPinCategory = NULL;
109 
110  rgPinType.clsMajorType = &GUID_NULL;
111  rgPinType.clsMinorType = &GUID_NULL;
112 
113  hr = IFilterMapper2_RegisterFilter(pMapper, &clsidFilter1, wszFilterName1, NULL,
114  &CLSID_LegacyAmFilterCategory, NULL, &rgf2);
115  if (hr == E_ACCESSDENIED)
116  {
117  registered = FALSE;
118  skip("Not authorized to register filters\n");
119  }
120  else
121  {
122  ok(hr == S_OK, "IFilterMapper2_RegisterFilter failed with %x\n", hr);
123 
124  rgPins2[0].dwFlags = 0;
125 
126  rgPins2[1].dwFlags = REG_PINFLAG_B_OUTPUT;
127  rgPins2[1].cInstances = 1;
128  rgPins2[1].nMediaTypes = 1;
129  rgPins2[1].lpMediaType = &rgPinType;
130  rgPins2[1].nMediums = 0;
131  rgPins2[1].lpMedium = NULL;
132  rgPins2[1].clsPinCategory = NULL;
133 
134  S2(U(rgf2)).cPins2 = 2;
135 
136  hr = IFilterMapper2_RegisterFilter(pMapper, &clsidFilter2, wszFilterName2, NULL,
137  &CLSID_LegacyAmFilterCategory, NULL, &rgf2);
138  ok(hr == S_OK, "IFilterMapper2_RegisterFilter failed with %x\n", hr);
139 
140  hr = IFilterMapper2_EnumMatchingFilters(pMapper, &pEnum, 0, TRUE, MERIT_UNLIKELY, TRUE,
141  0, NULL, NULL, &GUID_NULL, FALSE, FALSE, 0, NULL, NULL, &GUID_NULL);
142  ok(hr == S_OK, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr);
143  if (SUCCEEDED(hr) && pEnum)
144  {
145  found = enum_find_filter(wszFilterName1, pEnum);
146  ok(found, "EnumMatchingFilters failed to return the test filter 1\n");
147  }
148 
149  if (pEnum) IEnumMoniker_Release(pEnum);
150  pEnum = NULL;
151 
152  hr = IFilterMapper2_EnumMatchingFilters(pMapper, &pEnum, 0, TRUE, MERIT_UNLIKELY, TRUE,
153  0, NULL, NULL, &GUID_NULL, FALSE, FALSE, 0, NULL, NULL, &GUID_NULL);
154  ok(hr == S_OK, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr);
155  if (SUCCEEDED(hr) && pEnum)
156  {
157  found = enum_find_filter(wszFilterName2, pEnum);
158  ok(found, "EnumMatchingFilters failed to return the test filter 2\n");
159  }
160 
161  if (pEnum) IEnumMoniker_Release(pEnum);
162  pEnum = NULL;
163 
164  /* Non renderer must not be returned with bRender=TRUE */
165 
166  hr = IFilterMapper2_EnumMatchingFilters(pMapper, &pEnum, 0, TRUE, MERIT_UNLIKELY, TRUE,
167  0, NULL, NULL, &GUID_NULL, TRUE, FALSE, 0, NULL, NULL, &GUID_NULL);
168  ok(hr == S_OK, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr);
169 
170  if (SUCCEEDED(hr) && pEnum)
171  {
172  found = enum_find_filter(wszFilterName1, pEnum);
173  ok(found, "EnumMatchingFilters failed to return the test filter 1\n");
174  }
175 
176  hr = IFilterMapper2_QueryInterface(pMapper, &IID_IFilterMapper, (void **)&mapper);
177  ok(hr == S_OK, "QueryInterface(IFilterMapper) failed: %#x\n", hr);
178 
179  found = FALSE;
180  hr = IFilterMapper_EnumMatchingFilters(mapper, &enum_reg, MERIT_UNLIKELY,
182  ok(hr == S_OK, "IFilterMapper_EnumMatchingFilters failed: %#x\n", hr);
183  while (!found && IEnumRegFilters_Next(enum_reg, 1, &regfilter, &count) == S_OK)
184  {
185  if (!lstrcmpW(regfilter->Name, wszFilterName1) && IsEqualGUID(&clsidFilter1, &regfilter->Clsid))
186  found = TRUE;
187  }
188  IEnumRegFilters_Release(enum_reg);
189  ok(found, "IFilterMapper didn't find filter\n");
190  }
191 
192  if (pEnum) IEnumMoniker_Release(pEnum);
193  pEnum = NULL;
194 
195  hr = IFilterMapper2_EnumMatchingFilters(pMapper, &pEnum, 0, TRUE, MERIT_UNLIKELY, TRUE,
196  0, NULL, NULL, &GUID_NULL, TRUE, FALSE, 0, NULL, NULL, &GUID_NULL);
197  ok(hr == S_OK, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr);
198 
199  if (SUCCEEDED(hr) && pEnum)
200  {
201  found = enum_find_filter(wszFilterName2, pEnum);
202  ok(!found, "EnumMatchingFilters should not return the test filter 2\n");
203  }
204 
205  if (registered)
206  {
207  hr = IFilterMapper2_UnregisterFilter(pMapper, &CLSID_LegacyAmFilterCategory, NULL,
208  &clsidFilter1);
209  ok(SUCCEEDED(hr), "IFilterMapper2_UnregisterFilter failed with %x\n", hr);
210 
211  hr = IFilterMapper2_UnregisterFilter(pMapper, &CLSID_LegacyAmFilterCategory, NULL,
212  &clsidFilter2);
213  ok(SUCCEEDED(hr), "IFilterMapper2_UnregisterFilter failed with %x\n", hr);
214  }
215 
216  out:
217 
218  if (pEnum) IEnumMoniker_Release(pEnum);
219  if (pMapper) IFilterMapper2_Release(pMapper);
220 }
221 
223 {
224  static const WCHAR testfilterW[] = {'T','e','s','t','f','i','l','t','e','r',0};
225  static const WCHAR clsidW[] = {'C','L','S','I','D','\\',0};
226  static const WCHAR pinW[] = {'P','i','n','1',0};
227  IEnumRegFilters *enum_reg;
228  IEnumMoniker *enum_mon;
229  IFilterMapper2 *mapper2;
230  IFilterMapper *mapper;
231  REGFILTER *regfilter;
232  WCHAR clsidstring[40];
233  WCHAR key_name[50];
234  ULONG count;
235  CLSID clsid;
236  LRESULT ret;
237  HRESULT hr;
238  BOOL found;
239  HKEY hkey;
240 
241  /* Register* functions need a filter class key to write pin and pin media
242  * type data to. Create a bogus class key for it. */
244  StringFromGUID2(&clsid, clsidstring, sizeof(clsidstring));
246  lstrcatW(key_name, clsidstring);
248  if (ret == ERROR_ACCESS_DENIED)
249  {
250  skip("Not authorized to register filters\n");
251  return;
252  }
253 
254  /* Test if legacy filter registration scheme works (filter is added to HKCR\Filter). IFilterMapper_RegisterFilter
255  * registers in this way. Filters so registered must then be accessible through both IFilterMapper_EnumMatchingFilters
256  * and IFilterMapper2_EnumMatchingFilters. */
257  hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (void **)&mapper2);
258  ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr);
259 
260  hr = IFilterMapper2_QueryInterface(mapper2, &IID_IFilterMapper, (void **)&mapper);
261  ok(hr == S_OK, "IFilterMapper2_QueryInterface failed with %x\n", hr);
262 
263  /* Set default value - this is interpreted as "friendly name" later. */
264  RegSetValueExW(hkey, NULL, 0, REG_SZ, (BYTE *)testfilterW, sizeof(testfilterW));
265  RegCloseKey(hkey);
266 
267  hr = IFilterMapper_RegisterFilter(mapper, clsid, testfilterW, MERIT_UNLIKELY);
268  ok(hr == S_OK, "RegisterFilter failed: %#x\n", hr);
269 
270  hr = IFilterMapper_RegisterPin(mapper, clsid, pinW, TRUE, FALSE, FALSE, FALSE, GUID_NULL, NULL);
271  ok(hr == S_OK, "RegisterPin failed: %#x\n", hr);
272 
273  hr = IFilterMapper_RegisterPinType(mapper, clsid, pinW, GUID_NULL, GUID_NULL);
274  ok(hr == S_OK, "RegisterPinType failed: %#x\n", hr);
275 
276  hr = IFilterMapper2_EnumMatchingFilters(mapper2, &enum_mon, 0, TRUE, MERIT_UNLIKELY, TRUE,
277  0, NULL, NULL, &GUID_NULL, FALSE, FALSE, 0, NULL, NULL, &GUID_NULL);
278  ok(hr == S_OK, "IFilterMapper2_EnumMatchingFilters failed: %x\n", hr);
279  ok(enum_find_filter(testfilterW, enum_mon), "IFilterMapper2 didn't find filter\n");
280  IEnumMoniker_Release(enum_mon);
281 
282  found = FALSE;
283  hr = IFilterMapper_EnumMatchingFilters(mapper, &enum_reg, MERIT_UNLIKELY, TRUE, GUID_NULL, GUID_NULL,
285  ok(hr == S_OK, "IFilterMapper_EnumMatchingFilters failed with %x\n", hr);
286  while(!found && IEnumRegFilters_Next(enum_reg, 1, &regfilter, &count) == S_OK)
287  {
288  if (!lstrcmpW(regfilter->Name, testfilterW) && IsEqualGUID(&clsid, &regfilter->Clsid))
289  found = TRUE;
290  }
291  IEnumRegFilters_Release(enum_reg);
292  ok(found, "IFilterMapper didn't find filter\n");
293 
294  hr = IFilterMapper_UnregisterFilter(mapper, clsid);
295  ok(hr == S_OK, "FilterMapper_UnregisterFilter failed with %x\n", hr);
296 
297  hr = IFilterMapper2_EnumMatchingFilters(mapper2, &enum_mon, 0, TRUE, MERIT_UNLIKELY, TRUE,
298  0, NULL, NULL, &GUID_NULL, FALSE, FALSE, 0, NULL, NULL, &GUID_NULL);
299  ok(hr == S_OK, "IFilterMapper2_EnumMatchingFilters failed: %x\n", hr);
300  ok(!enum_find_filter(testfilterW, enum_mon), "IFilterMapper2 shouldn't find filter\n");
301  IEnumMoniker_Release(enum_mon);
302 
303  found = FALSE;
304  hr = IFilterMapper_EnumMatchingFilters(mapper, &enum_reg, MERIT_UNLIKELY, TRUE, GUID_NULL, GUID_NULL,
306  ok(hr == S_OK, "IFilterMapper_EnumMatchingFilters failed with %x\n", hr);
307  while(!found && IEnumRegFilters_Next(enum_reg, 1, &regfilter, &count) == S_OK)
308  {
309  if (!lstrcmpW(regfilter->Name, testfilterW) && IsEqualGUID(&clsid, &regfilter->Clsid))
310  found = TRUE;
311  }
312  IEnumRegFilters_Release(enum_reg);
313  ok(!found, "IFilterMapper shouldn't find filter\n");
314 
316  ok(!ret, "RegDeleteKeyA failed: %lu\n", ret);
317 
318  hr = IFilterMapper_RegisterFilter(mapper, clsid, testfilterW, MERIT_UNLIKELY);
319  ok(hr == S_OK, "RegisterFilter failed: %#x\n", hr);
320 
321  hr = IFilterMapper_UnregisterFilter(mapper, clsid);
322  ok(hr == S_OK, "FilterMapper_UnregisterFilter failed with %x\n", hr);
323 
324  IFilterMapper_Release(mapper);
325  IFilterMapper2_Release(mapper2);
326 }
327 
328 static ULONG getRefcount(IUnknown *iface)
329 {
330  IUnknown_AddRef(iface);
331  return IUnknown_Release(iface);
332 }
333 
335 {
336  IFilterGraph2* pgraph2 = NULL;
337  IFilterMapper2 *pMapper2 = NULL;
338  IFilterGraph *filtergraph = NULL;
339  HRESULT hr;
340  ULONG refcount;
341 
342  hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterGraph2, (LPVOID*)&pgraph2);
343  ok(hr == S_OK, "CoCreateInstance failed with %08x\n", hr);
344  if (!pgraph2) goto out;
345 
346  hr = IFilterGraph2_QueryInterface(pgraph2, &IID_IFilterMapper2, (LPVOID*)&pMapper2);
347  ok(hr == S_OK, "IFilterGraph2_QueryInterface failed with %08x\n", hr);
348  if (!pMapper2) goto out;
349 
350  refcount = getRefcount((IUnknown*)pgraph2);
351  ok(refcount == 2, "unexpected reference count: %u\n", refcount);
352  refcount = getRefcount((IUnknown*)pMapper2);
353  ok(refcount == 2, "unexpected reference count: %u\n", refcount);
354 
355  IFilterMapper2_AddRef(pMapper2);
356  refcount = getRefcount((IUnknown*)pgraph2);
357  ok(refcount == 3, "unexpected reference count: %u\n", refcount);
358  refcount = getRefcount((IUnknown*)pMapper2);
359  ok(refcount == 3, "unexpected reference count: %u\n", refcount);
360  IFilterMapper2_Release(pMapper2);
361 
362  hr = IFilterMapper2_QueryInterface(pMapper2, &IID_IFilterGraph, (LPVOID*)&filtergraph);
363  ok(hr == S_OK, "IFilterMapper2_QueryInterface failed with %08x\n", hr);
364  if (!filtergraph) goto out;
365 
366  IFilterMapper2_Release(pMapper2);
367  pMapper2 = NULL;
368  IFilterGraph_Release(filtergraph);
369  filtergraph = NULL;
370 
371  hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&pMapper2);
372  ok(hr == S_OK, "CoCreateInstance failed with %08x\n", hr);
373  if (!pMapper2) goto out;
374 
375  hr = IFilterMapper2_QueryInterface(pMapper2, &IID_IFilterGraph, (LPVOID*)&filtergraph);
376  ok(hr == E_NOINTERFACE, "IFilterMapper2_QueryInterface unexpected result: %08x\n", hr);
377 
378  out:
379 
380  if (pMapper2) IFilterMapper2_Release(pMapper2);
381  if (filtergraph) IFilterGraph_Release(filtergraph);
382  if (pgraph2) IFilterGraph2_Release(pgraph2);
383 }
384 
386 {
387  IFilterMapper2 *pMapper = NULL;
388  HRESULT hr;
389  REGFILTER2 rgf2;
390  REGFILTERPINS rgPins;
391  REGFILTERPINS2 rgPins2;
392  REGPINTYPES rgPinType;
393  static WCHAR wszPinName[] = {'P', 'i', 'n', 0 };
394  static const WCHAR wszFilterName1[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', '1', 0 };
395  static const WCHAR wszFilterName2[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', '2', 0 };
396  CLSID clsidFilter1;
397  CLSID clsidFilter2;
398 
399  hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER,
400  &IID_IFilterMapper2, (LPVOID*)&pMapper);
401  ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr);
402  if (FAILED(hr)) goto out;
403 
404  hr = CoCreateGuid(&clsidFilter1);
405  ok(hr == S_OK, "CoCreateGuid failed with %x\n", hr);
406  hr = CoCreateGuid(&clsidFilter2);
407  ok(hr == S_OK, "CoCreateGuid failed with %x\n", hr);
408 
409  rgPinType.clsMajorType = &GUID_NULL;
410  /* Make sure quartz accepts it without crashing */
411  rgPinType.clsMinorType = NULL;
412 
413  /* Test with pin descript version 1 */
414  ZeroMemory(&rgf2, sizeof(rgf2));
415  rgf2.dwVersion = 1;
416  rgf2.dwMerit = MERIT_UNLIKELY;
417  S1(U(rgf2)).cPins = 1;
418  S1(U(rgf2)).rgPins = &rgPins;
419 
420  rgPins.strName = wszPinName;
421  rgPins.bRendered = 1;
422  rgPins.bOutput = 0;
423  rgPins.bZero = 0;
424  rgPins.bMany = 0;
425  rgPins.clsConnectsToFilter = NULL;
426  rgPins.strConnectsToPin = NULL;
427  rgPins.nMediaTypes = 1;
428  rgPins.lpMediaType = &rgPinType;
429 
430  hr = IFilterMapper2_RegisterFilter(pMapper, &clsidFilter1, wszFilterName1, NULL,
431  &CLSID_LegacyAmFilterCategory, NULL, &rgf2);
432  if (hr == E_ACCESSDENIED)
433  {
434  skip("Not authorized to register filters\n");
435  goto out;
436  }
437  ok(hr == S_OK, "IFilterMapper2_RegisterFilter failed with %x\n", hr);
438 
439  hr = IFilterMapper2_UnregisterFilter(pMapper, &CLSID_LegacyAmFilterCategory, NULL, &clsidFilter1);
440  ok(hr == S_OK, "FilterMapper_UnregisterFilter failed with %x\n", hr);
441 
442  /* Test with pin descript version 2 */
443  ZeroMemory(&rgf2, sizeof(rgf2));
444  rgf2.dwVersion = 2;
445  rgf2.dwMerit = MERIT_UNLIKELY;
446  S2(U(rgf2)).cPins2 = 1;
447  S2(U(rgf2)).rgPins2 = &rgPins2;
448 
450  rgPins2.cInstances = 1;
451  rgPins2.nMediaTypes = 1;
452  rgPins2.lpMediaType = &rgPinType;
453  rgPins2.nMediums = 0;
454  rgPins2.lpMedium = NULL;
455  rgPins2.clsPinCategory = NULL;
456 
457  hr = IFilterMapper2_RegisterFilter(pMapper, &clsidFilter2, wszFilterName2, NULL,
458  &CLSID_LegacyAmFilterCategory, NULL, &rgf2);
459  ok(hr == S_OK, "IFilterMapper2_RegisterFilter failed with %x\n", hr);
460 
461  hr = IFilterMapper2_UnregisterFilter(pMapper, &CLSID_LegacyAmFilterCategory, NULL, &clsidFilter2);
462  ok(hr == S_OK, "FilterMapper_UnregisterFilter failed with %x\n", hr);
463 
464  out:
465 
466  if (pMapper) IFilterMapper2_Release(pMapper);
467 }
468 
469 static void test_parse_filter_data(void)
470 {
471  static const BYTE data_block[] = {
472  0x02,0x00,0x00,0x00,0xff,0xff,0x5f,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x70,0x69,0x33,
473  0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
474  0x30,0x74,0x79,0x33,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x31,0x70,0x69,0x33,
475  0x08,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
476  0x30,0x74,0x79,0x33,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x76,0x69,0x64,0x73,
477  0x00,0x00,0x10,0x00,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
478  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
479 
480  BYTE *prgbRegFilter2 = NULL;
481  REGFILTER2 *pRegFilter = NULL;
482  IFilterMapper2 *pMapper = NULL;
483  SAFEARRAYBOUND saBound;
484  SAFEARRAY *psa = NULL;
485  LPBYTE pbSAData = NULL;
486  HRESULT hr;
487 
489 
490  hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER,
491  &IID_IFilterMapper2, (LPVOID*)&pMapper);
492  ok((hr == S_OK || broken(hr != S_OK)), "CoCreateInstance failed with %x\n", hr);
493  if (FAILED(hr)) goto out;
494 
495  hr = IFilterMapper2_QueryInterface(pMapper, &IID_IAMFilterData, (LPVOID*)&pData);
496  ok((hr == S_OK || broken(hr != S_OK)), "Unable to find IID_IAMFilterData interface\n");
497  if (FAILED(hr)) goto out;
498 
499  saBound.lLbound = 0;
500  saBound.cElements = sizeof(data_block);
501  psa = SafeArrayCreate(VT_UI1, 1, &saBound);
502  ok(psa != NULL, "Unable to create safe array\n");
503  if (!psa) goto out;
504  hr = SafeArrayAccessData(psa, (LPVOID *)&pbSAData);
505  ok(hr == S_OK, "Unable to access array data\n");
506  if (FAILED(hr)) goto out;
507  memcpy(pbSAData, data_block, sizeof(data_block));
508 
509  hr = IAMFilterData_ParseFilterData(pData, pbSAData, sizeof(data_block), &prgbRegFilter2);
510  /* We cannot do anything here. prgbRegFilter2 is very unstable */
511  /* Pre Vista, this is a stack pointer so anything that changes the stack invalidats it */
512  /* Post Vista, it is a static pointer in the data section of the module */
513  pRegFilter =((REGFILTER2**)prgbRegFilter2)[0];
514  ok (hr==S_OK,"Failed to Parse filter Data\n");
515 
516  ok(IsBadReadPtr(prgbRegFilter2,sizeof(REGFILTER2*))==0,"Bad read pointer returned\n");
517  ok(IsBadReadPtr(pRegFilter,sizeof(REGFILTER2))==0,"Bad read pointer for FilterData\n");
518  ok(pRegFilter->dwMerit == 0x5fffff,"Incorrect merit returned\n");
519 
520 out:
521  CoTaskMemFree(pRegFilter);
522  if (psa)
523  {
526  }
527  if (pData)
528  IAMFilterData_Release(pData);
529  if (pMapper)
530  IFilterMapper2_Release(pMapper);
531 }
532 
533 typedef struct IUnknownImpl
534 {
536  int AddRef_called;
537  int Release_called;
538 } IUnknownImpl;
539 
541 {
542  return CONTAINING_RECORD(iface, IUnknownImpl, IUnknown_iface);
543 }
544 
546 {
547  ok(0, "QueryInterface should not be called for %s\n", wine_dbgstr_guid(riid));
548  return E_NOINTERFACE;
549 }
550 
552 {
554  This->AddRef_called++;
555  return 2;
556 }
557 
559 {
561  This->Release_called++;
562  return 1;
563 }
564 
565 static CONST_VTBL IUnknownVtbl IUnknownImpl_Vtbl =
566 {
570 };
571 
573 {
574  HRESULT hr;
575  IUnknown *pmapper;
576  IUnknown *punk;
577  IUnknownImpl unk_outer = { { &IUnknownImpl_Vtbl }, 0, 0 };
578 
579  hr = CoCreateInstance(&CLSID_FilterMapper2, &unk_outer.IUnknown_iface, CLSCTX_INPROC_SERVER,
580  &IID_IUnknown, (void **)&pmapper);
581  ok(hr == S_OK, "CoCreateInstance returned %x\n", hr);
582  ok(pmapper != &unk_outer.IUnknown_iface, "pmapper = %p, expected not %p\n", pmapper, &unk_outer.IUnknown_iface);
583 
584  hr = IUnknown_QueryInterface(pmapper, &IID_IUnknown, (void **)&punk);
585  ok(hr == S_OK, "IUnknown_QueryInterface returned %x\n", hr);
586  ok(punk != &unk_outer.IUnknown_iface, "punk = %p, expected not %p\n", punk, &unk_outer.IUnknown_iface);
587  IUnknown_Release(punk);
588 
589  ok(unk_outer.AddRef_called == 0, "IUnknownImpl_AddRef called %d times\n", unk_outer.AddRef_called);
590  ok(unk_outer.Release_called == 0, "IUnknownImpl_Release called %d times\n", unk_outer.Release_called);
591  unk_outer.AddRef_called = 0;
592  unk_outer.Release_called = 0;
593 
594  hr = IUnknown_QueryInterface(pmapper, &IID_IFilterMapper, (void **)&punk);
595  ok(hr == S_OK, "IUnknown_QueryInterface returned %x\n", hr);
596  ok(punk != &unk_outer.IUnknown_iface, "punk = %p, expected not %p\n", punk, &unk_outer.IUnknown_iface);
597  IUnknown_Release(punk);
598 
599  ok(unk_outer.AddRef_called == 1, "IUnknownImpl_AddRef called %d times\n", unk_outer.AddRef_called);
600  ok(unk_outer.Release_called == 1, "IUnknownImpl_Release called %d times\n", unk_outer.Release_called);
601  unk_outer.AddRef_called = 0;
602  unk_outer.Release_called = 0;
603 
604  hr = IUnknown_QueryInterface(pmapper, &IID_IFilterMapper2, (void **)&punk);
605  ok(hr == S_OK, "IUnknown_QueryInterface returned %x\n", hr);
606  ok(punk != &unk_outer.IUnknown_iface, "punk = %p, expected not %p\n", punk, &unk_outer.IUnknown_iface);
607  IUnknown_Release(punk);
608 
609  ok(unk_outer.AddRef_called == 1, "IUnknownImpl_AddRef called %d times\n", unk_outer.AddRef_called);
610  ok(unk_outer.Release_called == 1, "IUnknownImpl_Release called %d times\n", unk_outer.Release_called);
611  unk_outer.AddRef_called = 0;
612  unk_outer.Release_called = 0;
613 
614  hr = IUnknown_QueryInterface(pmapper, &IID_IFilterMapper3, (void **)&punk);
615  ok(hr == S_OK, "IUnknown_QueryInterface returned %x\n", hr);
616  ok(punk != &unk_outer.IUnknown_iface, "punk = %p, expected not %p\n", punk, &unk_outer.IUnknown_iface);
617  IUnknown_Release(punk);
618 
619  ok(unk_outer.AddRef_called == 1, "IUnknownImpl_AddRef called %d times\n", unk_outer.AddRef_called);
620  ok(unk_outer.Release_called == 1, "IUnknownImpl_Release called %d times\n", unk_outer.Release_called);
621 
622  IUnknown_Release(pmapper);
623 }
624 
625 START_TEST(filtermapper)
626 {
628 
635 
636  CoUninitialize();
637 }
#define E_ACCESSDENIED
Definition: winerror.h:2849
#define REFIID
Definition: guiddef.h:118
#define TRUE
Definition: types.h:120
#define E_NOINTERFACE
Definition: winerror.h:2364
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:420
static IUnknownImpl * IUnknownImpl_from_iface(IUnknown *iface)
Definition: filtermapper.c:540
HRESULT hr
Definition: shlfolder.c:183
#define S1(x)
Definition: test.h:191
REFIID riid
Definition: precomp.h:44
int WINAPI lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:170
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define U(x)
Definition: wordpad.c:44
#define S2(x)
Definition: test.h:192
const REGPINTYPES * lpMediaType
Definition: axextend.idl:199
LONG WINAPI RegDeleteKeyW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey)
Definition: reg.c:1237
REFIID LPVOID * ppv
Definition: atlbase.h:39
LPWSTR strName
Definition: axextend.idl:191
const CLSID * clsConnectsToFilter
Definition: axextend.idl:196
static BOOL enum_find_filter(const WCHAR *wszFilterName, IEnumMoniker *pEnum)
Definition: filtermapper.c:34
const char * wine_dbgstr_guid(const GUID *guid)
#define ZeroMemory
Definition: winbase.h:1642
static ULONG WINAPI IUnknownImpl_AddRef(IUnknown *iface)
Definition: filtermapper.c:551
static void test_register_filter_with_null_clsMinorType(void)
Definition: filtermapper.c:385
CLSID Clsid
Definition: axextend.idl:76
void WINAPI VariantInit(VARIANTARG *pVarg)
Definition: variant.c:571
IUnknown IUnknown_iface
Definition: filtergraph.c:2200
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1091
REGPINTYPES
Definition: axextend.idl:187
DWORD dwMerit
Definition: axextend.idl:232
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
#define CONST_VTBL
Definition: objbase.h:222
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
HRESULT WINAPI SafeArrayAccessData(SAFEARRAY *psa, void **ppvData)
Definition: safearray.c:1139
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
const GUID IID_IPropertyBag
START_TEST(filtermapper)
Definition: filtermapper.c:625
const CLSID * clsPinCategory
Definition: axextend.idl:226
static void test_legacy_filter_registration(void)
Definition: filtermapper.c:222
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define KEY_WRITE
Definition: nt_native.h:1031
static void test_ifiltermapper_from_filtergraph(void)
Definition: filtermapper.c:334
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4895
static const WCHAR clsidW[]
__wchar_t WCHAR
Definition: xmlstorage.h:180
static ULONG WINAPI IUnknownImpl_Release(IUnknown *iface)
Definition: filtermapper.c:558
LONG HRESULT
Definition: typedefs.h:77
const GUID IID_IUnknown
#define WINAPI
Definition: msvc.h:8
INT WINAPI StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax)
Definition: compobj.c:2434
const WCHAR * strConnectsToPin
Definition: axextend.idl:197
static FILE * out
Definition: regtests2xml.c:44
HRESULT WINAPI SafeArrayDestroy(SAFEARRAY *psa)
Definition: safearray.c:1349
IMoniker * pMoniker
Definition: filtermapper.c:134
HRESULT WINAPI CoCreateGuid(GUID *pguid)
Definition: compobj.c:2206
int ret
REFCLSID clsid
Definition: msctf.c:82
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:651
static const WCHAR wszFriendlyName[]
Definition: filtermapper.c:86
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
#define GUID_NULL
Definition: ks.h:106
UINT nMediaTypes
Definition: axextend.idl:198
#define V_BSTR(A)
Definition: oleauto.h:226
#define broken(x)
Definition: _sntprintf.h:21
DEFINE_GUID(GUID_NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
SAFEARRAY *WINAPI SafeArrayCreate(VARTYPE vt, UINT cDims, SAFEARRAYBOUND *rgsabound)
Definition: safearray.c:602
#define S_OK
Definition: intsafe.h:59
#define lstrcpyW
Definition: compat.h:414
LPWSTR Name
Definition: axextend.idl:77
static ULONG getRefcount(IUnknown *iface)
Definition: filtermapper.c:328
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
DWORD dwVersion
Definition: axextend.idl:231
static HRESULT WINAPI IUnknownImpl_QueryInterface(IUnknown *iface, REFIID riid, LPVOID *ppv)
Definition: filtermapper.c:545
static void test_aggregate_filter_mapper(void)
Definition: filtermapper.c:572
#define ok(value,...)
Definition: atltest.h:57
struct IUnknownImpl IUnknownImpl
BOOL WINAPI IsBadReadPtr(IN LPCVOID lp, IN UINT_PTR ucb)
Definition: except.c:807
const REGPINTYPES * lpMediaType
Definition: axextend.idl:223
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
static CONST_VTBL IUnknownVtbl IUnknownImpl_Vtbl
Definition: filtermapper.c:565
const REGPINMEDIUM * lpMedium
Definition: axextend.idl:225
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
#define skip(...)
Definition: atltest.h:64
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
unsigned int ULONG
Definition: retypes.h:1
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:274
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
LONG_PTR LRESULT
Definition: windef.h:209
static void test_fm2_enummatchingfilters(void)
Definition: filtermapper.c:66
HRESULT WINAPI SafeArrayUnaccessData(SAFEARRAY *psa)
Definition: safearray.c:1170
static void test_parse_filter_data(void)
Definition: filtermapper.c:469
#define SUCCEEDED(hr)
Definition: intsafe.h:57
#define REG_SZ
Definition: layer.c:22