[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 static const WCHAR fcc_handlerW[] = {'F','c','c','H','a','n','d','l','e','r',0};
38 static const WCHAR mrleW[] = {'m','r','l','e',0};
39
40 struct category
41 {
42 const char * name;
43 const GUID * clsid;
44 };
45
46 static struct category am_categories[] =
47 {
48 { "Legacy AM Filter category", &CLSID_LegacyAmFilterCategory },
49 { "Audio renderer category", &CLSID_AudioRendererCategory },
50 { "Midi renderer category", &CLSID_MidiRendererCategory },
51 { "Audio input device category", &CLSID_AudioInputDeviceCategory },
52 { "Video input device category", &CLSID_VideoInputDeviceCategory },
53 { "Audio compressor category", &CLSID_AudioCompressorCategory },
54 { "Video compressor category", &CLSID_VideoCompressorCategory }
55 };
56
57 static void test_devenum(IBindCtx *bind_ctx)
58 {
59 HRESULT res;
60 ICreateDevEnum* create_devenum;
61 IEnumMoniker* enum_moniker = NULL;
62 BOOL have_mrle = FALSE;
63 int i;
64
65 res = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC,
66 &IID_ICreateDevEnum, (LPVOID*)&create_devenum);
67 if (res != S_OK) {
68 skip("Cannot create SystemDeviceEnum object (%x)\n", res);
69 return;
70 }
71
72 for (i = 0; i < (sizeof(am_categories) / sizeof(struct category)); i++)
73 {
74 if (winetest_debug > 1)
75 trace("%s:\n", am_categories[i].name);
76
77 res = ICreateDevEnum_CreateClassEnumerator(create_devenum, am_categories[i].clsid, &enum_moniker, 0);
78 ok(SUCCEEDED(res), "Cannot create enum moniker (res = %x)\n", res);
79 if (res == S_OK)
80 {
81 IMoniker* moniker;
82 while (IEnumMoniker_Next(enum_moniker, 1, &moniker, NULL) == S_OK)
83 {
84 IPropertyBag* prop_bag = NULL;
85 VARIANT var;
86 HRESULT hr;
87
88 VariantInit(&var);
89 hr = IMoniker_BindToStorage(moniker, bind_ctx, NULL, &IID_IPropertyBag, (LPVOID*)&prop_bag);
90 ok(hr == S_OK, "IMoniker_BindToStorage failed with error %x\n", hr);
91
92 if (SUCCEEDED(hr))
93 {
94 hr = IPropertyBag_Read(prop_bag, friendly_name, &var, NULL);
95 ok((hr == S_OK) || broken(hr == 0x80070002), "IPropertyBag_Read failed with error %x\n", hr);
96
97 if (SUCCEEDED(hr))
98 {
99 if (winetest_debug > 1)
100 trace(" %s\n", wine_dbgstr_w(V_UNION(&var, bstrVal)));
101 VariantClear(&var);
102 }
103 else
104 {
105 trace(" ???\n");
106 }
107
108 if (IsEqualGUID(&CLSID_VideoCompressorCategory, am_categories[i].clsid)) {
109 /* Test well known compressor to ensure that we really enumerate codecs */
110 hr = IPropertyBag_Read(prop_bag, fcc_handlerW, &var, NULL);
111 if (SUCCEEDED(hr)) {
112 ok(V_VT(&var) == VT_BSTR, "V_VT(var) = %d\n", V_VT(&var));
113 if(!lstrcmpW(V_BSTR(&var), mrleW))
114 have_mrle = TRUE;
115 VariantClear(&var);
116 }
117 }
118 }
119
120 if (prop_bag)
121 IPropertyBag_Release(prop_bag);
122 IMoniker_Release(moniker);
123 }
124 IEnumMoniker_Release(enum_moniker);
125 }
126 }
127
128 ICreateDevEnum_Release(create_devenum);
129
130 /* 64-bit windows are missing mrle codec */
131 if(sizeof(void*) == 4)
132 ok(have_mrle, "mrle codec not found\n");
133 }
134
135 /* CLSID_CDeviceMoniker */
136
137 START_TEST(devenum)
138 {
139 IBindCtx *bind_ctx = NULL;
140 HRESULT hr;
141
142 CoInitialize(NULL);
143
144 test_devenum(NULL);
145
146 /* IBindCtx is allowed in IMoniker_BindToStorage (IMediaCatMoniker_BindToStorage) */
147 hr = CreateBindCtx(0, &bind_ctx);
148 ok(hr == S_OK, "Cannot create BindCtx: (res = 0x%x)\n", hr);
149 if (bind_ctx) {
150 test_devenum(bind_ctx);
151 IBindCtx_Release(bind_ctx);
152 }
153
154 CoUninitialize();
155 }