[DEVENUM_WINETEST]
[reactos.git] / rostests / winetests / devenum / devenum.c
1 /*
2 * Some unit tests for devenum
3 *
4 * Copyright (C) 2012 Christian Costa
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 WIN32_NO_STATUS
22 #define _INC_WINDOWS
23 #define COM_NO_WINDOWS_H
24
25 #define COBJMACROS
26
27 //#include <stdio.h>
28
29 #include <wine/test.h>
30 #include <wingdi.h>
31 #include <initguid.h>
32 #include <ole2.h>
33 #include <strmif.h>
34 #include <uuids.h>
35
36 static const WCHAR friendly_name[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
37
38 struct category
39 {
40 const char * name;
41 const GUID * clsid;
42 };
43
44 static struct category am_categories[] =
45 {
46 { "Legacy AM Filter category", &CLSID_LegacyAmFilterCategory },
47 { "Audio renderer category", &CLSID_AudioRendererCategory },
48 { "Midi renderer category", &CLSID_MidiRendererCategory },
49 { "Audio input device category", &CLSID_AudioInputDeviceCategory },
50 { "Video input device category", &CLSID_VideoInputDeviceCategory },
51 { "Audio compressor category", &CLSID_AudioCompressorCategory },
52 { "Video compressor category", &CLSID_VideoCompressorCategory }
53 };
54
55 static void test_devenum(IBindCtx *bind_ctx)
56 {
57 HRESULT res;
58 ICreateDevEnum* create_devenum;
59 IEnumMoniker* enum_moniker = NULL;
60 int i;
61
62 res = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC,
63 &IID_ICreateDevEnum, (LPVOID*)&create_devenum);
64 if (res != S_OK) {
65 skip("Cannot create SystemDeviceEnum object (%x)\n", res);
66 return;
67 }
68
69 for (i = 0; i < (sizeof(am_categories) / sizeof(struct category)); i++)
70 {
71 if (winetest_debug > 1)
72 trace("%s:\n", am_categories[i].name);
73
74 res = ICreateDevEnum_CreateClassEnumerator(create_devenum, am_categories[i].clsid, &enum_moniker, 0);
75 ok(SUCCEEDED(res), "Cannot create enum moniker (res = %x)\n", res);
76 if (res == S_OK)
77 {
78 IMoniker* moniker;
79 while (IEnumMoniker_Next(enum_moniker, 1, &moniker, NULL) == S_OK)
80 {
81 IPropertyBag* prop_bag = NULL;
82 VARIANT var;
83 HRESULT hr;
84
85 VariantInit(&var);
86 hr = IMoniker_BindToStorage(moniker, bind_ctx, NULL, &IID_IPropertyBag, (LPVOID*)&prop_bag);
87 ok(hr == S_OK, "IMoniker_BindToStorage failed with error %x\n", hr);
88
89 if (SUCCEEDED(hr))
90 {
91 hr = IPropertyBag_Read(prop_bag, friendly_name, &var, NULL);
92 ok((hr == S_OK) || broken(hr == 0x80070002), "IPropertyBag_Read failed with error %x\n", hr);
93
94 if (SUCCEEDED(hr))
95 {
96 if (winetest_debug > 1)
97 trace(" %s\n", wine_dbgstr_w(V_UNION(&var, bstrVal)));
98 VariantClear(&var);
99 }
100 else
101 {
102 trace(" ???\n");
103 }
104 }
105
106 if (prop_bag)
107 IPropertyBag_Release(prop_bag);
108 IMoniker_Release(moniker);
109 }
110 IEnumMoniker_Release(enum_moniker);
111 }
112 }
113
114 ICreateDevEnum_Release(create_devenum);
115 }
116
117 /* CLSID_CDeviceMoniker */
118
119 START_TEST(devenum)
120 {
121 IBindCtx *bind_ctx = NULL;
122 HRESULT hr;
123
124 CoInitialize(NULL);
125
126 test_devenum(NULL);
127
128 /* IBindCtx is allowed in IMoniker_BindToStorage (IMediaCatMoniker_BindToStorage) */
129 hr = CreateBindCtx(0, &bind_ctx);
130 ok(hr == S_OK, "Cannot create BindCtx: (res = 0x%x)\n", hr);
131 if (bind_ctx) {
132 test_devenum(bind_ctx);
133 IBindCtx_Release(bind_ctx);
134 }
135
136 CoUninitialize();
137 }