devenum: Do not fail with a IBindCtx (with tests).
[wine/multimedia.git] / dlls / devenum / tests / devenum.c
blobc7f765b1bde5915c68e368c5b0a64724b3ef5f97
1 /*
2 * Some unit tests for devenum
4 * Copyright (C) 2012 Christian Costa
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 <stdio.h>
25 #include "wine/test.h"
26 #include "initguid.h"
27 #include "ole2.h"
28 #include "strmif.h"
29 #include "uuids.h"
31 static const WCHAR friendly_name[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
33 struct category
35 const char * name;
36 const GUID * clsid;
39 static struct category am_categories[] =
41 { "Legacy AM Filter category", &CLSID_LegacyAmFilterCategory },
42 { "Audio renderer category", &CLSID_AudioRendererCategory },
43 { "Midi renderer category", &CLSID_MidiRendererCategory },
44 { "Audio input device category", &CLSID_AudioInputDeviceCategory },
45 { "Video input device category", &CLSID_VideoInputDeviceCategory },
46 { "Audio compressor category", &CLSID_AudioCompressorCategory },
47 { "Video compressor category", &CLSID_VideoCompressorCategory }
50 static void test_devenum(IBindCtx *bind_ctx)
52 HRESULT res;
53 ICreateDevEnum* create_devenum;
54 IEnumMoniker* enum_moniker = NULL;
55 int i;
57 res = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC,
58 &IID_ICreateDevEnum, (LPVOID*)&create_devenum);
59 if (res != S_OK) {
60 skip("Cannot create SystemDeviceEnum object (%x)\n", res);
61 return;
64 for (i = 0; i < (sizeof(am_categories) / sizeof(struct category)); i++)
66 if (winetest_debug > 1)
67 trace("%s:\n", am_categories[i].name);
69 res = ICreateDevEnum_CreateClassEnumerator(create_devenum, am_categories[i].clsid, &enum_moniker, 0);
70 ok(SUCCEEDED(res), "Cannot create enum moniker (res = %x)\n", res);
71 if (res == S_OK)
73 IMoniker* moniker;
74 while (IEnumMoniker_Next(enum_moniker, 1, &moniker, NULL) == S_OK)
76 IPropertyBag* prop_bag = NULL;
77 VARIANT var;
78 HRESULT hr;
80 VariantInit(&var);
81 hr = IMoniker_BindToStorage(moniker, bind_ctx, NULL, &IID_IPropertyBag, (LPVOID*)&prop_bag);
82 ok(hr == S_OK, "IMoniker_BindToStorage failed with error %x\n", hr);
84 if (SUCCEEDED(hr))
86 hr = IPropertyBag_Read(prop_bag, friendly_name, &var, NULL);
87 ok((hr == S_OK) || broken(hr == 0x80070002), "IPropertyBag_Read failed with error %x\n", hr);
89 if (SUCCEEDED(hr))
91 if (winetest_debug > 1)
92 trace(" %s\n", wine_dbgstr_w(V_UNION(&var, bstrVal)));
93 VariantClear(&var);
95 else
97 trace(" ???\n");
101 if (prop_bag)
102 IPropertyBag_Release(prop_bag);
103 IMoniker_Release(moniker);
105 IEnumMoniker_Release(enum_moniker);
109 ICreateDevEnum_Release(create_devenum);
112 /* CLSID_CDeviceMoniker */
114 START_TEST(devenum)
116 IBindCtx *bind_ctx = NULL;
117 HRESULT hr;
119 CoInitialize(NULL);
121 test_devenum(NULL);
123 /* IBindCtx is allowed in IMoniker_BindToStorage (IMediaCatMoniker_BindToStorage) */
124 hr = CreateBindCtx(0, &bind_ctx);
125 ok(hr == S_OK, "Cannot create BindCtx: (res = 0x%x)\n", hr);
126 if (bind_ctx) {
127 test_devenum(bind_ctx);
128 IBindCtx_Release(bind_ctx);
131 CoUninitialize();