wbemprox: Implement Win32_DiskDriveToDiskPartition.
[wine.git] / dlls / wbemprox / tests / query.c
blob23641fc0d30c9ef138159cd17935835f03ee21ca
1 /*
2 * Copyright 2012 Hans Leidekker for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
21 #include <stdio.h>
22 #include "windows.h"
23 #include "ocidl.h"
24 #include "sddl.h"
25 #include "initguid.h"
26 #include "objidl.h"
27 #include "wbemcli.h"
28 #include "wine/test.h"
30 static const WCHAR wqlW[] = {'w','q','l',0};
32 static HRESULT exec_query( IWbemServices *services, const WCHAR *str, IEnumWbemClassObject **result )
34 static const WCHAR captionW[] = {'C','a','p','t','i','o','n',0};
35 static const WCHAR descriptionW[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
36 HRESULT hr;
37 IWbemClassObject *obj;
38 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( str );
39 LONG flags = WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY;
40 ULONG count;
42 hr = IWbemServices_ExecQuery( services, wql, query, flags, NULL, result );
43 if (hr == S_OK)
45 trace("%s\n", wine_dbgstr_w(str));
46 for (;;)
48 VARIANT var;
49 IWbemQualifierSet *qualifiers;
50 SAFEARRAY *names;
52 IEnumWbemClassObject_Next( *result, 10000, 1, &obj, &count );
53 if (!count) break;
55 if (IWbemClassObject_Get( obj, captionW, 0, &var, NULL, NULL ) == WBEM_S_NO_ERROR)
57 trace("caption: %s\n", wine_dbgstr_w(V_BSTR(&var)));
58 VariantClear( &var );
60 if (IWbemClassObject_Get( obj, descriptionW, 0, &var, NULL, NULL ) == WBEM_S_NO_ERROR)
62 trace("description: %s\n", wine_dbgstr_w(V_BSTR(&var)));
63 VariantClear( &var );
66 hr = IWbemClassObject_GetQualifierSet( obj, &qualifiers );
67 ok( hr == S_OK, "got %08x\n", hr );
69 hr = IWbemQualifierSet_GetNames( qualifiers, 0, &names );
70 ok( hr == S_OK, "got %08x\n", hr );
72 SafeArrayDestroy( names );
73 IWbemQualifierSet_Release( qualifiers );
74 IWbemClassObject_Release( obj );
77 SysFreeString( wql );
78 SysFreeString( query );
79 return hr;
82 static void test_select( IWbemServices *services )
84 static const WCHAR emptyW[] = {0};
85 static const WCHAR sqlW[] = {'S','Q','L',0};
86 static const WCHAR query1[] =
87 {'S','E','L','E','C','T',' ','H','O','T','F','I','X','I','D',' ','F','R','O','M',' ',
88 'W','i','n','3','2','_','Q','u','i','c','k','F','i','x','E','n','g','i','n','e','e','r','i','n','g',0};
89 static const WCHAR query2[] =
90 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_','B','I','O','S',0};
91 static const WCHAR query3[] =
92 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
93 'L','o','g','i','c','a','l','D','i','s','k',' ','W','H','E','R','E',' ',
94 '\"','N','T','F','S','\"',' ','=',' ','F','i','l','e','S','y','s','t','e','m',0};
95 static const WCHAR query4[] =
96 {'S','E','L','E','C','T',' ','a',' ','F','R','O','M',' ','b',0};
97 static const WCHAR query5[] =
98 {'S','E','L','E','C','T',' ','a',' ','F','R','O','M',' ','W','i','n','3','2','_','B','i','o','s',0};
99 static const WCHAR query6[] =
100 {'S','E','L','E','C','T',' ','D','e','s','c','r','i','p','t','i','o','n',' ','F','R','O','M',' ',
101 'W','i','n','3','2','_','B','i','o','s',0};
102 static const WCHAR query7[] =
103 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
104 'P','r','o','c','e','s','s',' ','W','H','E','R','E',' ','C','a','p','t','i','o','n',' ',
105 'L','I','K','E',' ','\'','%','%','R','E','G','E','D','I','T','%','\'',0};
106 static const WCHAR query8[] =
107 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
108 'D','i','s','k','D','r','i','v','e',' ','W','H','E','R','E',' ','D','e','v','i','c','e','I','D','=',
109 '\"','\\','\\','\\','\\','.','\\','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','0','\"',0};
110 static const WCHAR query9[] =
111 {'S','E','L','E','C','T','\n','a','\r','F','R','O','M','\t','b',0};
112 static const WCHAR query10[] =
113 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
114 'P','r','o','c','e','s','s',' ','W','H','E','R','E',' ','C','a','p','t','i','o','n',' ',
115 'L','I','K','E',' ','"','%','f','i','r','e','f','o','x','.','e','x','e','"',0};
116 static const WCHAR query11[] =
117 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
118 'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',' ','w','h','e','r','e',' ',
119 'a','v','a','i','l','a','b','i','l','i','t','y',' ','=',' ','\'','3','\'',0};
120 static const WCHAR query12[] =
121 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_','B','I','O','S',
122 ' ','W','H','E','R','E',' ','N','A','M','E',' ','<','>',' ','N','U','L','L', 0};
123 static const WCHAR query13[] =
124 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_','B','I','O','S',
125 ' ','W','H','E','R','E',' ','N','U','L','L',' ','=',' ','N','A','M','E', 0};
126 static const WCHAR query14[] =
127 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
128 'L','o','g','i','c','a','l','D','i','s','k','T','o','P','a','r','t','i','t','i','o','n',0};
129 static const WCHAR query15[] =
130 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
131 'D','i','s','k','D','r','i','v','e','T','o','D','i','s','k','P','a','r','t','i','t','i','o','n',0};
132 static const WCHAR *test[] = { query1, query2, query3, query4, query5, query6, query7, query8, query9, query10,
133 query11, query12, query13, query14, query15 };
134 HRESULT hr;
135 IEnumWbemClassObject *result;
136 BSTR wql = SysAllocString( wqlW );
137 BSTR sql = SysAllocString( sqlW );
138 BSTR query = SysAllocString( query1 );
139 UINT i;
141 hr = IWbemServices_ExecQuery( services, NULL, NULL, 0, NULL, &result );
142 ok( hr == WBEM_E_INVALID_PARAMETER, "query failed %08x\n", hr );
144 hr = IWbemServices_ExecQuery( services, NULL, query, 0, NULL, &result );
145 ok( hr == WBEM_E_INVALID_PARAMETER, "query failed %08x\n", hr );
147 hr = IWbemServices_ExecQuery( services, wql, NULL, 0, NULL, &result );
148 ok( hr == WBEM_E_INVALID_PARAMETER, "query failed %08x\n", hr );
150 hr = IWbemServices_ExecQuery( services, sql, query, 0, NULL, &result );
151 ok( hr == WBEM_E_INVALID_QUERY_TYPE, "query failed %08x\n", hr );
153 hr = IWbemServices_ExecQuery( services, sql, NULL, 0, NULL, &result );
154 ok( hr == WBEM_E_INVALID_PARAMETER, "query failed %08x\n", hr );
156 SysFreeString( query );
157 query = SysAllocString( emptyW );
158 hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
159 ok( hr == WBEM_E_INVALID_PARAMETER, "query failed %08x\n", hr );
161 for (i = 0; i < ARRAY_SIZE( test ); i++)
163 hr = exec_query( services, test[i], &result );
164 ok( hr == S_OK, "query %u failed: %08x\n", i, hr );
165 if (result) IEnumWbemClassObject_Release( result );
168 SysFreeString( wql );
169 SysFreeString( sql );
170 SysFreeString( query );
173 static void test_associators( IWbemServices *services )
175 static const WCHAR query1[] =
176 {'A','S','S','O','C','I','A','T','O','R','S',' ',' ','O','F','{','W','i','n','3','2','_',
177 'L','o','g','i','c','a','l','D','i','s','k','.','D','e','v','i','c','e','I','D','=','"','C',':','"','}',0};
178 static const WCHAR query2[] =
179 {'A','S','S','O','C','I','A','T','O','R','S',' ','O','F',' ','{','W','i','n','3','2','_',
180 'L','o','g','i','c','a','l','D','i','s','k','.','D','e','v','i','c','e','I','D','=','"','C',':','"','}',' ',
181 'W','H','E','R','E',' ','A','s','s','o','c','C','l','a','s','s','=','W','i','n','3','2','_',
182 'L','o','g','i','c','a','l','D','i','s','k','T','o','P','a','r','t','i','t','i','o','n',0};
183 static const WCHAR query3[] =
184 {'A','S','S','O','C','I','A','T','O','R','S',' ',' ','O','F',' ','{','W','i','n','3','2','_',
185 'L','o','g','i','c','a','l','D','i','s','k','.','D','e','v','i','c','e','I','D','}',0};
186 static const WCHAR query4[] =
187 {'A','S','S','O','C','I','A','T','O','R','S',' ',' ','O','F',' ','{','W','i','n','3','2','_',
188 'D','i','s','k','D','r','i','v','e','.','D','e','v','i','c','e','I','D','=',
189 '\'','\\','\\','.','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','0','\'','}',0};
190 static const WCHAR query5[] =
191 {'A','S','S','O','C','I','A','T','O','R','S',' ','O','F',' ','{','W','i','n','3','2','_',
192 'L','o','g','i','c','a','l','D','i','s','k','.','D','e','v','i','c','e','I','D','=','"','C',':','"','}',' ',
193 'W','H','E','R','E',' ','A','s','s','o','c','C','l','a','s','s','=','W','i','n','3','2','_',
194 'L','o','g','i','c','a','l','D','i','s','k','T','o','P','a','r','t','i','t','i','o','n',' ',
195 'C','l','a','s','s','D','e','f','s','O','n','l','y',0};
196 static const WCHAR query6[] =
197 {'A','S','S','O','C','I','A','T','O','R','S',' ','O','F',' ','{','W','i','n','3','2','_',
198 'L','o','g','i','c','a','l','D','i','s','k','.','D','e','v','i','c','e','I','D','=','"','C',':','"','}',' ',
199 'W','H','E','R','E',' ','C','l','a','s','s','D','e','f','s','O','n','l','y',0};
200 static const WCHAR query7[] =
201 {'A','S','S','O','C','I','A','T','O','R','S',' ','O','F',' ','{','W','i','n','3','2','_',
202 'L','o','g','i','c','a','l','D','i','s','k','.','D','e','v','i','c','e','I','D','=','"','C',':','"','}',' ',
203 'W','H','E','R','E',' ','C','l','a','s','s','D','e','f','s','O','n','l','y',' ',
204 'A','s','s','o','c','C','l','a','s','s',' ','=',' ','W','i','n','3','2','_',
205 'L','o','g','i','c','a','l','D','i','s','k','T','o','P','a','r','t','i','t','i','o','n',0};
206 static const WCHAR *test[] = { query1, query2, query3, query4, query5, query6, query7 };
207 HRESULT hr;
208 IEnumWbemClassObject *result;
209 UINT i;
211 for (i = 0; i < ARRAY_SIZE( test ); i++)
213 hr = exec_query( services, test[i], &result );
214 ok( hr == S_OK, "query %u failed: %08x\n", i, hr );
215 if (result) IEnumWbemClassObject_Release( result );
219 static void test_Win32_Service( IWbemServices *services )
221 static const WCHAR returnvalueW[] = {'R','e','t','u','r','n','V','a','l','u','e',0};
222 static const WCHAR pauseserviceW[] = {'P','a','u','s','e','S','e','r','v','i','c','e',0};
223 static const WCHAR resumeserviceW[] = {'R','e','s','u','m','e','S','e','r','v','i','c','e',0};
224 static const WCHAR startserviceW[] = {'S','t','a','r','t','S','e','r','v','i','c','e',0};
225 static const WCHAR stopserviceW[] = {'S','t','o','p','S','e','r','v','i','c','e',0};
226 static const WCHAR stateW[] = {'S','t','a','t','e',0};
227 static const WCHAR stoppedW[] = {'S','t','o','p','p','e','d',0};
228 static const WCHAR serviceW[] = {'W','i','n','3','2','_','S','e','r','v','i','c','e','.',
229 'N','a','m','e','=','"','S','p','o','o','l','e','r','"',0};
230 static const WCHAR emptyW[] = {0};
231 BSTR class = SysAllocString( serviceW ), empty = SysAllocString( emptyW ), method;
232 IWbemClassObject *service, *out;
233 VARIANT state, retval;
234 CIMTYPE type;
235 HRESULT hr;
237 hr = IWbemServices_GetObject( services, class, 0, NULL, &service, NULL );
238 if (hr != S_OK)
240 win_skip( "Win32_Service not available\n" );
241 goto out;
243 type = 0xdeadbeef;
244 VariantInit( &state );
245 hr = IWbemClassObject_Get( service, stateW, 0, &state, &type, NULL );
246 ok( hr == S_OK, "failed to get service state %08x\n", hr );
247 ok( V_VT( &state ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &state ) );
248 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
250 if (!lstrcmpW( V_BSTR( &state ), stoppedW ))
252 out = NULL;
253 method = SysAllocString( startserviceW );
254 hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, NULL, &out, NULL );
255 ok( hr == S_OK, "failed to execute method %08x\n", hr );
256 SysFreeString( method );
258 VariantInit( &retval );
259 hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, NULL, NULL );
260 ok( hr == S_OK, "failed to get return value %08x\n", hr );
261 ok( !V_I4( &retval ), "unexpected error %u\n", V_UI4( &retval ) );
262 IWbemClassObject_Release( out );
264 out = NULL;
265 method = SysAllocString( pauseserviceW );
266 hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, NULL, &out, NULL );
267 ok( hr == S_OK, "failed to execute method %08x\n", hr );
268 SysFreeString( method );
270 VariantInit( &retval );
271 hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, NULL, NULL );
272 ok( hr == S_OK, "failed to get return value %08x\n", hr );
273 ok( V_I4( &retval ), "unexpected success\n" );
274 IWbemClassObject_Release( out );
276 out = NULL;
277 method = SysAllocString( resumeserviceW );
278 hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, NULL, &out, NULL );
279 ok( hr == S_OK, "failed to execute method %08x\n", hr );
280 SysFreeString( method );
282 VariantInit( &retval );
283 hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, NULL, NULL );
284 ok( hr == S_OK, "failed to get return value %08x\n", hr );
285 ok( V_I4( &retval ), "unexpected success\n" );
286 IWbemClassObject_Release( out );
288 if (!lstrcmpW( V_BSTR( &state ), stoppedW ))
290 out = NULL;
291 method = SysAllocString( stopserviceW );
292 hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, NULL, &out, NULL );
293 ok( hr == S_OK, "failed to execute method %08x\n", hr );
294 SysFreeString( method );
296 VariantInit( &retval );
297 hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, NULL, NULL );
298 ok( hr == S_OK, "failed to get return value %08x\n", hr );
299 ok( !V_I4( &retval ), "unexpected error %u\n", V_UI4( &retval ) );
300 IWbemClassObject_Release( out );
302 VariantClear( &state );
303 IWbemClassObject_Release( service );
305 service = NULL;
306 hr = IWbemServices_GetObject( services, NULL, 0, NULL, &service, NULL );
307 ok( hr == S_OK, "got %08x\n", hr );
308 if (service) IWbemClassObject_Release( service );
310 service = NULL;
311 hr = IWbemServices_GetObject( services, empty, 0, NULL, &service, NULL );
312 ok( hr == S_OK, "got %08x\n", hr );
313 if (service) IWbemClassObject_Release( service );
315 out:
316 SysFreeString( empty );
317 SysFreeString( class );
320 static void _check_property( ULONG line, IWbemClassObject *obj, const WCHAR *prop, VARTYPE vartype, CIMTYPE cimtype )
322 CIMTYPE type = 0xdeadbeef;
323 VARIANT val;
324 HRESULT hr;
326 VariantInit( &val );
327 hr = IWbemClassObject_Get( obj, prop, 0, &val, &type, NULL );
328 ok( hr == S_OK, "%u: failed to get description %08x\n", line, hr );
329 ok( V_VT( &val ) == vartype, "%u: unexpected variant type 0x%x\n", line, V_VT(&val) );
330 ok( type == cimtype, "%u: unexpected type 0x%x\n", line, type );
331 switch (V_VT(&val))
333 case VT_BSTR:
334 trace( "%s: %s\n", wine_dbgstr_w(prop), wine_dbgstr_w(V_BSTR(&val)) );
335 break;
336 case VT_I4:
337 trace( "%s: %d\n", wine_dbgstr_w(prop), V_I4(&val) );
338 break;
339 default:
340 break;
342 VariantClear( &val );
344 #define check_property(a,b,c,d) _check_property(__LINE__,a,b,c,d)
346 static void test_Win32_Bios( IWbemServices *services )
348 static const WCHAR queryW[] =
349 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_','B','i','o','s',0};
350 static const WCHAR descriptionW[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
351 static const WCHAR identificationcodeW[] = {'I','d','e','n','t','i','f','i','c','a','t','i','o','n','C','o','d','e',0};
352 static const WCHAR manufacturerW[] = {'M','a','n','u','f','a','c','t','u','r','e','r',0};
353 static const WCHAR nameW[] = {'N','a','m','e',0};
354 static const WCHAR releasedateW[] = {'R','e','l','e','a','s','e','D','a','t','e',0};
355 static const WCHAR serialnumberW[] = {'S','e','r','i','a','l','N','u','m','b','e','r',0};
356 static const WCHAR smbiosbiosversionW[] = {'S','M','B','I','O','S','B','I','O','S','V','e','r','s','i','o','n',0};
357 static const WCHAR smbiosmajorversionW[] = {'S','M','B','I','O','S','M','a','j','o','r','V','e','r','s','i','o','n',0};
358 static const WCHAR smbiosminorversionW[] = {'S','M','B','I','O','S','M','i','n','o','r','V','e','r','s','i','o','n',0};
359 static const WCHAR versionW[] = {'V','e','r','s','i','o','n',0};
360 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
361 IEnumWbemClassObject *result;
362 IWbemClassObject *obj;
363 CIMTYPE type;
364 ULONG count;
365 VARIANT val;
366 HRESULT hr;
368 hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
369 ok( hr == S_OK, "IWbemServices_ExecQuery failed %08x\n", hr );
371 hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
372 ok( hr == S_OK, "IEnumWbemClassObject_Next failed %08x\n", hr );
374 check_property( obj, descriptionW, VT_BSTR, CIM_STRING );
375 check_property( obj, identificationcodeW, VT_NULL, CIM_STRING );
376 check_property( obj, manufacturerW, VT_BSTR, CIM_STRING );
377 check_property( obj, nameW, VT_BSTR, CIM_STRING );
378 check_property( obj, releasedateW, VT_BSTR, CIM_DATETIME );
380 type = 0xdeadbeef;
381 VariantInit( &val );
382 hr = IWbemClassObject_Get( obj, serialnumberW, 0, &val, &type, NULL );
383 ok( hr == S_OK, "failed to get serial number %08x\n", hr );
384 ok( V_VT( &val ) == VT_BSTR || V_VT( &val ) == VT_NULL /* Testbot VMs */,
385 "unexpected variant type 0x%x\n", V_VT( &val ) );
386 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
387 VariantClear( &val );
389 check_property( obj, smbiosbiosversionW, VT_BSTR, CIM_STRING );
390 check_property( obj, smbiosmajorversionW, VT_I4, CIM_UINT16 );
391 check_property( obj, smbiosminorversionW, VT_I4, CIM_UINT16 );
392 check_property( obj, versionW, VT_BSTR, CIM_STRING );
394 IWbemClassObject_Release( obj );
395 IEnumWbemClassObject_Release( result );
396 SysFreeString( query );
397 SysFreeString( wql );
400 static void test_Win32_Baseboard( IWbemServices *services )
402 static const WCHAR queryW[] =
403 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_','B','a','s','e','b','o','a','r','d',0};
404 static const WCHAR manufacturerW[] = {'M','a','n','u','f','a','c','t','u','r','e','r',0};
405 static const WCHAR modelW[] = {'M','o','d','e','l',0};
406 static const WCHAR nameW[] = {'N','a','m','e',0};
407 static const WCHAR productW[] = {'P','r','o','d','u','c','t',0};
408 static const WCHAR tagW[] = {'T','a','g',0};
409 static const WCHAR versionW[] = {'V','e','r','s','i','o','n',0};
410 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
411 IEnumWbemClassObject *result;
412 IWbemClassObject *obj;
413 CIMTYPE type;
414 ULONG count;
415 VARIANT val;
416 HRESULT hr;
418 hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
419 ok( hr == S_OK, "IWbemServices_ExecQuery failed %08x\n", hr );
421 hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
422 if (hr != S_OK)
424 win_skip( "Win32_Baseboard not available\n" );
425 return;
427 ok( hr == S_OK, "IEnumWbemClassObject_Next failed %08x\n", hr );
429 check_property( obj, manufacturerW, VT_BSTR, CIM_STRING );
431 type = 0xdeadbeef;
432 VariantInit( &val );
433 hr = IWbemClassObject_Get( obj, modelW, 0, &val, &type, NULL );
434 ok( hr == S_OK, "failed to get model %08x\n", hr );
435 ok( V_VT( &val ) == VT_BSTR || V_VT( &val ) == VT_NULL, "unexpected variant type 0x%x\n", V_VT( &val ) );
436 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
437 trace( "model: %s\n", wine_dbgstr_w(V_BSTR(&val)) );
438 VariantClear( &val );
440 check_property( obj, nameW, VT_BSTR, CIM_STRING );
441 check_property( obj, productW, VT_BSTR, CIM_STRING );
442 check_property( obj, tagW, VT_BSTR, CIM_STRING );
443 check_property( obj, versionW, VT_BSTR, CIM_STRING );
445 IWbemClassObject_Release( obj );
446 IEnumWbemClassObject_Release( result );
447 SysFreeString( query );
448 SysFreeString( wql );
451 static void test_Win32_Process( IWbemServices *services, BOOL use_full_path )
453 static const WCHAR returnvalueW[] = {'R','e','t','u','r','n','V','a','l','u','e',0};
454 static const WCHAR getownerW[] = {'G','e','t','O','w','n','e','r',0};
455 static const WCHAR userW[] = {'U','s','e','r',0};
456 static const WCHAR domainW[] = {'D','o','m','a','i','n',0};
457 static const WCHAR processW[] = {'W','i','n','3','2','_','P','r','o','c','e','s','s',0};
458 static const WCHAR idW[] = {'I','D',0};
459 static const WCHAR fmtW[] = {'W','i','n','3','2','_','P','r','o','c','e','s','s','.',
460 'H','a','n','d','l','e','=','"','%','u','"',0};
461 static const WCHAR full_path_fmt[] =
462 {'\\','\\','%','s','\\','R','O','O','T','\\','C','I','M','V','2',':',0};
463 static const LONG expected_flavor = WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE |
464 WBEM_FLAVOR_NOT_OVERRIDABLE |
465 WBEM_FLAVOR_ORIGIN_PROPAGATED;
466 WCHAR full_path[MAX_COMPUTERNAME_LENGTH + ARRAY_SIZE(full_path_fmt)];
467 BSTR class, method;
468 IWbemClassObject *process, *sig_in, *out;
469 IWbemQualifierSet *qualifiers;
470 VARIANT retval, val;
471 DWORD full_path_len = 0;
472 LONG flavor;
473 CIMTYPE type;
474 HRESULT hr;
476 if (use_full_path)
478 WCHAR server[MAX_COMPUTERNAME_LENGTH+1];
480 full_path_len = ARRAY_SIZE(server);
481 ok( GetComputerNameW(server, &full_path_len), "GetComputerName failed\n" );
482 full_path_len = wsprintfW(full_path, full_path_fmt, server);
485 class = SysAllocStringLen( NULL, full_path_len + ARRAY_SIZE( processW ) );
486 memcpy( class, full_path, full_path_len * sizeof(WCHAR) );
487 memcpy( class + full_path_len, processW, sizeof(processW) );
488 hr = IWbemServices_GetObject( services, class, 0, NULL, &process, NULL );
489 SysFreeString( class );
490 if (hr != S_OK)
492 win_skip( "Win32_Process not available\n" );
493 return;
495 sig_in = (void*)0xdeadbeef;
496 hr = IWbemClassObject_GetMethod( process, getownerW, 0, &sig_in, NULL );
497 ok( hr == S_OK, "failed to get GetOwner method %08x\n", hr );
498 ok( !sig_in, "sig_in != NULL\n");
499 IWbemClassObject_Release( process );
501 out = NULL;
502 method = SysAllocString( getownerW );
503 class = SysAllocStringLen( NULL, full_path_len + ARRAY_SIZE( fmtW ) + 10 );
504 memcpy( class, full_path, full_path_len * sizeof(WCHAR) );
505 wsprintfW( class + full_path_len, fmtW, GetCurrentProcessId() );
506 hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, NULL, &out, NULL );
507 ok( hr == S_OK, "failed to execute method %08x\n", hr );
508 SysFreeString( method );
509 SysFreeString( class );
511 type = 0xdeadbeef;
512 VariantInit( &retval );
513 hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, &type, NULL );
514 ok( hr == S_OK, "failed to get return value %08x\n", hr );
515 ok( V_VT( &retval ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &retval ) );
516 ok( !V_I4( &retval ), "unexpected error %u\n", V_I4( &retval ) );
517 ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
519 check_property( out, userW, VT_BSTR, CIM_STRING );
520 check_property( out, domainW, VT_BSTR, CIM_STRING );
522 hr = IWbemClassObject_GetPropertyQualifierSet( out, userW, &qualifiers );
523 ok( hr == S_OK, "failed to get qualifier set %08x\n", hr );
525 flavor = -1;
526 V_I4(&val) = -1;
527 V_VT(&val) = VT_ERROR;
528 hr = IWbemQualifierSet_Get( qualifiers, idW, 0, &val, &flavor );
529 ok( hr == S_OK, "got %08x\n", hr );
530 ok( flavor == expected_flavor, "got %d\n", flavor );
531 ok( V_VT(&val) == VT_I4, "got %u\n", V_VT(&val) );
532 ok( V_I4(&val) == 0, "got %u\n", V_I4(&val) );
533 VariantClear( &val );
535 IWbemQualifierSet_Release( qualifiers );
536 hr = IWbemClassObject_GetPropertyQualifierSet( out, domainW, &qualifiers );
537 ok( hr == S_OK, "failed to get qualifier set %08x\n", hr );
539 flavor = -1;
540 V_I4(&val) = -1;
541 V_VT(&val) = VT_ERROR;
542 hr = IWbemQualifierSet_Get( qualifiers, idW, 0, &val, &flavor );
543 ok( hr == S_OK, "got %08x\n", hr );
544 ok( flavor == expected_flavor, "got %d\n", flavor );
545 ok( V_VT(&val) == VT_I4, "got %u\n", V_VT(&val) );
546 ok( V_I4(&val) == 1, "got %u\n", V_I4(&val) );
547 VariantClear( &val );
549 IWbemQualifierSet_Release( qualifiers );
550 hr = IWbemClassObject_GetPropertyQualifierSet( out, returnvalueW, &qualifiers );
551 ok( hr == S_OK, "failed to get qualifier set %08x\n", hr );
553 hr = IWbemQualifierSet_Get( qualifiers, idW, 0, &val, &flavor );
554 ok( hr == WBEM_E_NOT_FOUND, "got %08x\n", hr );
556 IWbemQualifierSet_Release( qualifiers );
557 IWbemClassObject_Release( out );
560 static void test_Win32_ComputerSystem( IWbemServices *services )
562 static const WCHAR backslashW[] = {'\\',0};
563 static const WCHAR memorytypeW[] = {'M','e','m','o','r','y','T','y','p','e',0};
564 static const WCHAR modelW[] = {'M','o','d','e','l',0};
565 static const WCHAR nameW[] = {'N','a','m','e',0};
566 static const WCHAR usernameW[] = {'U','s','e','r','N','a','m','e',0};
567 static const WCHAR numprocessorsW[] =
568 {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
569 static const WCHAR numlogicalprocessorsW[] =
570 {'N','u','m','b','e','r','O','f','L','o','g','i','c','a','l','P','r','o','c','e','s','s','o','r','s',0};
571 static const WCHAR queryW[] =
572 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
573 'C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
574 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
575 IEnumWbemClassObject *result;
576 IWbemClassObject *obj;
577 VARIANT value;
578 CIMTYPE type;
579 HRESULT hr;
580 WCHAR compname[MAX_COMPUTERNAME_LENGTH + 1];
581 WCHAR username[128];
582 DWORD len, count;
584 len = ARRAY_SIZE( compname );
585 if (!GetComputerNameW( compname, &len ))
586 compname[0] = 0;
588 lstrcpyW( username, compname );
589 lstrcatW( username, backslashW );
590 len = ARRAY_SIZE( username ) - lstrlenW( username );
591 if (!GetUserNameW( username + lstrlenW( username ), &len ))
592 username[0] = 0;
594 if (!compname[0] || !username[0])
596 skip( "Failed to get user or computer name\n" );
597 goto out;
600 hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
601 if (hr != S_OK)
603 win_skip( "Win32_ComputerSystem not available\n" );
604 goto out;
607 hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
608 ok( hr == S_OK, "got %08x\n", hr );
610 type = 0xdeadbeef;
611 VariantInit( &value );
612 hr = IWbemClassObject_Get( obj, memorytypeW, 0, &value, &type, NULL );
613 ok( hr == WBEM_E_NOT_FOUND, "got %08x\n", hr );
615 check_property( obj, modelW, VT_BSTR, CIM_STRING );
617 type = 0xdeadbeef;
618 VariantInit( &value );
619 hr = IWbemClassObject_Get( obj, nameW, 0, &value, &type, NULL );
620 ok( hr == S_OK, "failed to get computer name %08x\n", hr );
621 ok( V_VT( &value ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &value ) );
622 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
623 ok( !lstrcmpiW( V_BSTR( &value ), compname ), "got %s, expected %s\n", wine_dbgstr_w(V_BSTR(&value)), wine_dbgstr_w(compname) );
624 VariantClear( &value );
626 type = 0xdeadbeef;
627 VariantInit( &value );
628 hr = IWbemClassObject_Get( obj, numlogicalprocessorsW, 0, &value, &type, NULL );
629 ok( hr == S_OK || broken(hr == WBEM_E_NOT_FOUND) /* win2k3 */, "got %08x\n", hr );
630 if (hr == S_OK)
632 ok( V_VT( &value ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &value ) );
633 ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
634 trace( "numlogicalprocessors %u\n", V_I4( &value ) );
637 check_property( obj, numprocessorsW, VT_I4, CIM_UINT32 );
639 type = 0xdeadbeef;
640 VariantInit( &value );
641 hr = IWbemClassObject_Get( obj, usernameW, 0, &value, &type, NULL );
642 ok( hr == S_OK, "failed to get computer name %08x\n", hr );
643 ok( V_VT( &value ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &value ) );
644 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
645 ok( !lstrcmpiW( V_BSTR( &value ), username ), "got %s, expected %s\n", wine_dbgstr_w(V_BSTR(&value)), wine_dbgstr_w(username) );
646 VariantClear( &value );
648 IWbemClassObject_Release( obj );
649 IEnumWbemClassObject_Release( result );
650 out:
651 SysFreeString( query );
652 SysFreeString( wql );
655 static void test_Win32_SystemEnclosure( IWbemServices *services )
657 static const WCHAR queryW[] =
658 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
659 'S','y','s','t','e','m','E','n','c','l','o','s','u','r','e',0};
660 static const WCHAR captionW[] = {'C','a','p','t','i','o','n',0};
661 static const WCHAR chassistypesW[] = {'C','h','a','s','s','i','s','T','y','p','e','s',0};
662 static const WCHAR descriptionW[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
663 static const WCHAR lockpresentW[] = {'L','o','c','k','P','r','e','s','e','n','t',0};
664 static const WCHAR manufacturerW[] = {'M','a','n','u','f','a','c','t','u','r','e','r',0};
665 static const WCHAR nameW[] = {'N','a','m','e',0};
666 static const WCHAR tagW[] = {'T','a','g',0};
667 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
668 IEnumWbemClassObject *result;
669 IWbemClassObject *obj;
670 CIMTYPE type;
671 ULONG count;
672 VARIANT val;
673 DWORD *data;
674 HRESULT hr;
676 hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
677 ok( hr == S_OK, "IWbemServices_ExecQuery failed %08x\n", hr );
679 hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
680 ok( hr == S_OK, "IEnumWbemClassObject_Next failed %08x\n", hr );
682 check_property( obj, captionW, VT_BSTR, CIM_STRING );
684 type = 0xdeadbeef;
685 VariantInit( &val );
686 hr = IWbemClassObject_Get( obj, chassistypesW, 0, &val, &type, NULL );
687 ok( hr == S_OK, "failed to get chassis types %08x\n", hr );
688 ok( V_VT( &val ) == (VT_I4|VT_ARRAY), "unexpected variant type 0x%x\n", V_VT( &val ) );
689 ok( type == (CIM_UINT16|CIM_FLAG_ARRAY), "unexpected type 0x%x\n", type );
690 hr = SafeArrayAccessData( V_ARRAY( &val ), (void **)&data );
691 ok( hr == S_OK, "SafeArrayAccessData failed %x\n", hr );
692 if (SUCCEEDED(hr))
694 LONG i, lower, upper;
696 hr = SafeArrayGetLBound( V_ARRAY( &val ), 1, &lower );
697 ok( hr == S_OK, "SafeArrayGetLBound failed %x\n", hr );
698 hr = SafeArrayGetUBound( V_ARRAY( &val ), 1, &upper );
699 ok( hr == S_OK, "SafeArrayGetUBound failed %x\n", hr );
700 if (V_VT( &val ) == (VT_I4|VT_ARRAY))
702 for (i = 0; i < upper - lower + 1; i++)
703 trace( "chassis type: %u\n", data[i] );
705 hr = SafeArrayUnaccessData( V_ARRAY( &val ) );
706 ok( hr == S_OK, "SafeArrayUnaccessData failed %x\n", hr );
708 VariantClear( &val );
710 check_property( obj, descriptionW, VT_BSTR, CIM_STRING );
711 check_property( obj, lockpresentW, VT_BOOL, CIM_BOOLEAN );
712 check_property( obj, manufacturerW, VT_BSTR, CIM_STRING );
713 check_property( obj, nameW, VT_BSTR, CIM_STRING );
714 check_property( obj, tagW, VT_BSTR, CIM_STRING );
716 IWbemClassObject_Release( obj );
717 IEnumWbemClassObject_Release( result );
718 SysFreeString( query );
719 SysFreeString( wql );
722 static void test_StdRegProv( IWbemServices *services )
724 static const WCHAR createkeyW[] = {'C','r','e','a','t','e','K','e','y',0};
725 static const WCHAR enumkeyW[] = {'E','n','u','m','K','e','y',0};
726 static const WCHAR enumvaluesW[] = {'E','n','u','m','V','a','l','u','e','s',0};
727 static const WCHAR getstringvalueW[] = {'G','e','t','S','t','r','i','n','g','V','a','l','u','e',0};
728 static const WCHAR stdregprovW[] = {'S','t','d','R','e','g','P','r','o','v',0};
729 static const WCHAR defkeyW[] = {'h','D','e','f','K','e','y',0};
730 static const WCHAR subkeynameW[] = {'s','S','u','b','K','e','y','N','a','m','e',0};
731 static const WCHAR returnvalueW[] = {'R','e','t','u','r','n','V','a','l','u','e',0};
732 static const WCHAR namesW[] = {'s','N','a','m','e','s',0};
733 static const WCHAR typesW[] = {'T','y','p','e','s',0};
734 static const WCHAR valueW[] = {'s','V','a','l','u','e',0};
735 static const WCHAR valuenameW[] = {'s','V','a','l','u','e','N','a','m','e',0};
736 static const WCHAR programfilesW[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',0};
737 static const WCHAR windowsW[] =
738 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
739 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
740 static const WCHAR regtestW[] =
741 {'S','o','f','t','w','a','r','e','\\','S','t','d','R','e','g','P','r','o','v','T','e','s','t',0};
742 BSTR class = SysAllocString( stdregprovW ), method, name;
743 IWbemClassObject *reg, *sig_in, *sig_out, *in, *out;
744 VARIANT defkey, subkey, retval, names, types, value, valuename;
745 CIMTYPE type;
746 HRESULT hr;
747 LONG res;
749 hr = IWbemServices_GetObject( services, class, 0, NULL, &reg, NULL );
750 if (hr != S_OK)
752 win_skip( "StdRegProv not available\n" );
753 return;
756 hr = IWbemClassObject_BeginMethodEnumeration( reg, 0 );
757 ok( hr == S_OK, "got %08x\n", hr );
759 while (IWbemClassObject_NextMethod( reg, 0, &name, &sig_in, &sig_out ) == S_OK)
761 SysFreeString( name );
762 IWbemClassObject_Release( sig_in );
763 IWbemClassObject_Release( sig_out );
766 hr = IWbemClassObject_EndMethodEnumeration( reg );
767 ok( hr == S_OK, "got %08x\n", hr );
769 hr = IWbemClassObject_BeginEnumeration( reg, 0 );
770 ok( hr == S_OK, "got %08x\n", hr );
772 while (IWbemClassObject_Next( reg, 0, &name, NULL, NULL, NULL ) == S_OK)
773 SysFreeString( name );
775 hr = IWbemClassObject_EndEnumeration( reg );
776 ok( hr == S_OK, "got %08x\n", hr );
778 hr = IWbemClassObject_GetMethod( reg, createkeyW, 0, &sig_in, NULL );
779 ok( hr == S_OK, "failed to get CreateKey method %08x\n", hr );
781 hr = IWbemClassObject_SpawnInstance( sig_in, 0, &in );
782 ok( hr == S_OK, "failed to spawn instance %08x\n", hr );
784 V_VT( &defkey ) = VT_I4;
785 V_I4( &defkey ) = 0x80000001;
786 hr = IWbemClassObject_Put( in, defkeyW, 0, &defkey, 0 );
787 ok( hr == S_OK, "failed to set root %08x\n", hr );
789 V_VT( &subkey ) = VT_BSTR;
790 V_BSTR( &subkey ) = SysAllocString( regtestW );
791 hr = IWbemClassObject_Put( in, subkeynameW, 0, &subkey, 0 );
792 ok( hr == S_OK, "failed to set subkey %08x\n", hr );
794 out = NULL;
795 method = SysAllocString( createkeyW );
796 hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, in, &out, NULL );
797 ok( hr == S_OK, "failed to execute method %08x\n", hr );
798 SysFreeString( method );
800 type = 0xdeadbeef;
801 VariantInit( &retval );
802 hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, &type, NULL );
803 ok( hr == S_OK, "failed to get return value %08x\n", hr );
804 ok( V_VT( &retval ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &retval ) );
805 ok( !V_I4( &retval ), "unexpected error %u\n", V_UI4( &retval ) );
806 ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
808 res = RegDeleteKeyW( HKEY_CURRENT_USER, regtestW );
809 ok( !res, "got %d\n", res );
811 VariantClear( &subkey );
812 IWbemClassObject_Release( in );
813 IWbemClassObject_Release( out );
814 IWbemClassObject_Release( sig_in );
816 hr = IWbemClassObject_GetMethod( reg, enumkeyW, 0, &sig_in, NULL );
817 ok( hr == S_OK, "failed to get EnumKey method %08x\n", hr );
819 hr = IWbemClassObject_SpawnInstance( sig_in, 0, &in );
820 ok( hr == S_OK, "failed to spawn instance %08x\n", hr );
822 V_VT( &defkey ) = VT_I4;
823 V_I4( &defkey ) = 0x80000002;
824 hr = IWbemClassObject_Put( in, defkeyW, 0, &defkey, 0 );
825 ok( hr == S_OK, "failed to set root %08x\n", hr );
827 V_VT( &subkey ) = VT_BSTR;
828 V_BSTR( &subkey ) = SysAllocString( windowsW );
829 hr = IWbemClassObject_Put( in, subkeynameW, 0, &subkey, 0 );
830 ok( hr == S_OK, "failed to set subkey %08x\n", hr );
832 out = NULL;
833 method = SysAllocString( enumkeyW );
834 hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, in, &out, NULL );
835 ok( hr == S_OK, "failed to execute method %08x\n", hr );
836 SysFreeString( method );
838 type = 0xdeadbeef;
839 VariantInit( &retval );
840 hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, &type, NULL );
841 ok( hr == S_OK, "failed to get return value %08x\n", hr );
842 ok( V_VT( &retval ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &retval ) );
843 ok( !V_I4( &retval ), "unexpected error %u\n", V_UI4( &retval ) );
844 ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
846 check_property( out, namesW, VT_BSTR|VT_ARRAY, CIM_STRING|CIM_FLAG_ARRAY );
848 VariantClear( &names );
849 VariantClear( &subkey );
850 IWbemClassObject_Release( in );
851 IWbemClassObject_Release( out );
852 IWbemClassObject_Release( sig_in );
854 hr = IWbemClassObject_GetMethod( reg, enumvaluesW, 0, &sig_in, NULL );
855 ok( hr == S_OK, "failed to get EnumValues method %08x\n", hr );
857 hr = IWbemClassObject_SpawnInstance( sig_in, 0, &in );
858 ok( hr == S_OK, "failed to spawn instance %08x\n", hr );
860 V_VT( &defkey ) = VT_I4;
861 V_I4( &defkey ) = 0x80000002;
862 hr = IWbemClassObject_Put( in, defkeyW, 0, &defkey, 0 );
863 ok( hr == S_OK, "failed to set root %08x\n", hr );
865 V_VT( &subkey ) = VT_BSTR;
866 V_BSTR( &subkey ) = SysAllocString( windowsW );
867 hr = IWbemClassObject_Put( in, subkeynameW, 0, &subkey, 0 );
868 ok( hr == S_OK, "failed to set subkey %08x\n", hr );
870 out = NULL;
871 method = SysAllocString( enumvaluesW );
872 hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, in, &out, NULL );
873 ok( hr == S_OK, "failed to execute method %08x\n", hr );
874 SysFreeString( method );
876 type = 0xdeadbeef;
877 VariantInit( &retval );
878 hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, &type, NULL );
879 ok( hr == S_OK, "failed to get return value %08x\n", hr );
880 ok( V_VT( &retval ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &retval ) );
881 ok( !V_I4( &retval ), "unexpected error %u\n", V_I4( &retval ) );
882 ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
884 check_property( out, namesW, VT_BSTR|VT_ARRAY, CIM_STRING|CIM_FLAG_ARRAY );
885 check_property( out, typesW, VT_I4|VT_ARRAY, CIM_SINT32|CIM_FLAG_ARRAY );
887 VariantClear( &types );
888 VariantClear( &names );
889 VariantClear( &subkey );
890 IWbemClassObject_Release( in );
891 IWbemClassObject_Release( out );
892 IWbemClassObject_Release( sig_in );
894 hr = IWbemClassObject_GetMethod( reg, getstringvalueW, 0, &sig_in, NULL );
895 ok( hr == S_OK, "failed to get GetStringValue method %08x\n", hr );
897 hr = IWbemClassObject_SpawnInstance( sig_in, 0, &in );
898 ok( hr == S_OK, "failed to spawn instance %08x\n", hr );
900 V_VT( &defkey ) = VT_I4;
901 V_I4( &defkey ) = 0x80000002;
902 hr = IWbemClassObject_Put( in, defkeyW, 0, &defkey, 0 );
903 ok( hr == S_OK, "failed to set root %08x\n", hr );
905 V_VT( &subkey ) = VT_BSTR;
906 V_BSTR( &subkey ) = SysAllocString( windowsW );
907 hr = IWbemClassObject_Put( in, subkeynameW, 0, &subkey, 0 );
908 ok( hr == S_OK, "failed to set subkey %08x\n", hr );
910 V_VT( &valuename ) = VT_BSTR;
911 V_BSTR( &valuename ) = SysAllocString( programfilesW );
912 hr = IWbemClassObject_Put( in, valuenameW, 0, &valuename, 0 );
913 ok( hr == S_OK, "failed to set value name %08x\n", hr );
915 out = NULL;
916 method = SysAllocString( getstringvalueW );
917 hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, in, &out, NULL );
918 ok( hr == S_OK, "failed to execute method %08x\n", hr );
919 SysFreeString( method );
921 type = 0xdeadbeef;
922 VariantInit( &retval );
923 hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, &type, NULL );
924 ok( hr == S_OK, "failed to get return value %08x\n", hr );
925 ok( V_VT( &retval ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &retval ) );
926 ok( !V_I4( &retval ), "unexpected error %u\n", V_I4( &retval ) );
927 ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
929 check_property( out, valueW, VT_BSTR, CIM_STRING );
931 VariantClear( &value );
932 VariantClear( &valuename );
933 VariantClear( &subkey );
934 IWbemClassObject_Release( in );
935 IWbemClassObject_Release( out );
936 IWbemClassObject_Release( sig_in );
938 IWbemClassObject_Release( reg );
939 SysFreeString( class );
942 static HRESULT WINAPI sink_QueryInterface(
943 IWbemObjectSink *iface, REFIID riid, void **ppv )
945 *ppv = NULL;
946 if (IsEqualGUID( &IID_IUnknown, riid ) || IsEqualGUID( &IID_IWbemObjectSink, riid ))
948 *ppv = iface;
949 IWbemObjectSink_AddRef( iface );
950 return S_OK;
952 return E_NOINTERFACE;
955 static ULONG sink_refs;
957 static ULONG WINAPI sink_AddRef(
958 IWbemObjectSink *iface )
960 return ++sink_refs;
963 static ULONG WINAPI sink_Release(
964 IWbemObjectSink *iface )
966 return --sink_refs;
969 static HRESULT WINAPI sink_Indicate(
970 IWbemObjectSink *iface, LONG count, IWbemClassObject **objects )
972 trace("Indicate: %d, %p\n", count, objects);
973 return S_OK;
976 static HRESULT WINAPI sink_SetStatus(
977 IWbemObjectSink *iface, LONG flags, HRESULT hresult, BSTR str_param, IWbemClassObject *obj_param )
979 trace("SetStatus: %08x, %08x, %s, %p\n", flags, hresult, wine_dbgstr_w(str_param), obj_param);
980 return S_OK;
983 static IWbemObjectSinkVtbl sink_vtbl =
985 sink_QueryInterface,
986 sink_AddRef,
987 sink_Release,
988 sink_Indicate,
989 sink_SetStatus
992 static IWbemObjectSink sink = { &sink_vtbl };
994 static void test_notification_query_async( IWbemServices *services )
996 static const WCHAR queryW[] =
997 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
998 'D','e','v','i','c','e','C','h','a','n','g','e','E','v','e','n','t',0};
999 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
1000 ULONG prev_sink_refs;
1001 HRESULT hr;
1003 hr = IWbemServices_ExecNotificationQueryAsync( services, wql, query, 0, NULL, NULL );
1004 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
1006 prev_sink_refs = sink_refs;
1007 hr = IWbemServices_ExecNotificationQueryAsync( services, wql, query, 0, NULL, &sink );
1008 ok( hr == S_OK || broken(hr == WBEM_E_NOT_FOUND), "got %08x\n", hr );
1009 ok( sink_refs > prev_sink_refs || broken(!sink_refs), "got %u refs\n", sink_refs );
1011 hr = IWbemServices_CancelAsyncCall( services, &sink );
1012 ok( hr == S_OK || broken(hr == WBEM_E_NOT_FOUND), "got %08x\n", hr );
1014 SysFreeString( wql );
1015 SysFreeString( query );
1018 static void test_query_async( IWbemServices *services )
1020 static const WCHAR queryW[] =
1021 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
1022 'P','r','o','c','e','s','s',0};
1023 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
1024 HRESULT hr;
1026 hr = IWbemServices_ExecQueryAsync( services, wql, query, 0, NULL, NULL );
1027 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
1029 hr = IWbemServices_ExecQueryAsync( services, wql, query, 0, NULL, &sink );
1030 ok( hr == S_OK || broken(hr == WBEM_E_NOT_FOUND), "got %08x\n", hr );
1032 hr = IWbemServices_CancelAsyncCall( services, NULL );
1033 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
1035 hr = IWbemServices_CancelAsyncCall( services, &sink );
1036 ok( hr == S_OK, "got %08x\n", hr );
1038 SysFreeString( wql );
1039 SysFreeString( query );
1042 static void test_query_semisync( IWbemServices *services )
1044 static const WCHAR queryW[] =
1045 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_','D','u','m','m','y',0};
1046 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
1047 IEnumWbemClassObject *result;
1048 IWbemClassObject *obj;
1049 ULONG count;
1050 HRESULT hr;
1052 hr = IWbemServices_ExecQuery( services, wql, query, WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY,
1053 NULL, &result );
1054 ok( hr == S_OK, "got %08x\n", hr );
1056 count = 1;
1057 obj = (void *)0xdeadbeef;
1058 hr = IEnumWbemClassObject_Next( result, -1, 1, &obj, &count );
1059 todo_wine
1060 ok( hr == WBEM_E_INVALID_CLASS, "Unexpected hr %#x.\n", hr );
1061 ok( count == 0, "Unexpected count %u.\n", count );
1062 ok( obj == (void *)0xdeadbeef, "Got object %p\n", obj );
1064 IEnumWbemClassObject_Release( result );
1066 SysFreeString( wql );
1067 SysFreeString( query );
1070 static void test_GetNames( IWbemServices *services )
1072 static const WCHAR queryW[] =
1073 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
1074 'O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
1075 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
1076 IEnumWbemClassObject *result;
1077 HRESULT hr;
1079 hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
1080 ok( hr == S_OK, "got %08x\n", hr );
1082 for (;;)
1084 IWbemClassObject *obj;
1085 SAFEARRAY *names;
1086 ULONG count;
1087 VARIANT val;
1089 IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
1090 if (!count) break;
1092 VariantInit( &val );
1093 hr = IWbemClassObject_GetNames( obj, NULL, WBEM_FLAG_NONSYSTEM_ONLY, &val, &names );
1094 ok( hr == S_OK, "got %08x\n", hr );
1096 SafeArrayDestroy( names );
1097 IWbemClassObject_Release( obj );
1099 IEnumWbemClassObject_Release( result );
1100 SysFreeString( query );
1101 SysFreeString( wql );
1104 static void test_SystemSecurity( IWbemServices *services )
1106 static const WCHAR systemsecurityW[] = {'_','_','S','y','s','t','e','m','S','e','c','u','r','i','t','y',0};
1107 static const WCHAR getsdW[] = {'G','e','t','S','D',0};
1108 static const WCHAR returnvalueW[] = {'R','e','t','u','r','n','V','a','l','u','e',0};
1109 static const WCHAR sdW[] = {'S','D',0};
1110 BSTR class = SysAllocString( systemsecurityW ), method;
1111 IWbemClassObject *reg, *out;
1112 VARIANT retval, var_sd;
1113 void *data;
1114 SECURITY_DESCRIPTOR_RELATIVE *sd;
1115 CIMTYPE type;
1116 HRESULT hr;
1117 BYTE sid_admin_buffer[SECURITY_MAX_SID_SIZE];
1118 SID *sid_admin = (SID*)sid_admin_buffer;
1119 DWORD sid_size;
1120 BOOL ret;
1122 hr = IWbemServices_GetObject( services, class, 0, NULL, &reg, NULL );
1123 if (hr != S_OK)
1125 win_skip( "__SystemSecurity not available\n" );
1126 return;
1128 IWbemClassObject_Release( reg );
1130 sid_size = sizeof(sid_admin_buffer);
1131 ret = CreateWellKnownSid( WinBuiltinAdministratorsSid, NULL, sid_admin, &sid_size );
1132 ok( ret, "CreateWellKnownSid failed\n" );
1134 out = NULL;
1135 method = SysAllocString( getsdW );
1136 hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, NULL, &out, NULL );
1137 ok( hr == S_OK || hr == WBEM_E_ACCESS_DENIED, "failed to execute method %08x\n", hr );
1138 SysFreeString( method );
1140 if (SUCCEEDED(hr))
1142 type = 0xdeadbeef;
1143 VariantInit( &retval );
1144 hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, &type, NULL );
1145 ok( hr == S_OK, "failed to get return value %08x\n", hr );
1146 ok( V_VT( &retval ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &retval ) );
1147 ok( !V_I4( &retval ), "unexpected error %u\n", V_UI4( &retval ) );
1148 ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
1150 type = 0xdeadbeef;
1151 VariantInit( &var_sd );
1152 hr = IWbemClassObject_Get( out, sdW, 0, &var_sd, &type, NULL );
1153 ok( hr == S_OK, "failed to get names %08x\n", hr );
1154 ok( V_VT( &var_sd ) == (VT_UI1|VT_ARRAY), "unexpected variant type 0x%x\n", V_VT( &var_sd ) );
1155 ok( type == (CIM_UINT8|CIM_FLAG_ARRAY), "unexpected type 0x%x\n", type );
1157 hr = SafeArrayAccessData( V_ARRAY( &var_sd ), &data );
1158 ok( hr == S_OK, "SafeArrayAccessData failed %x\n", hr );
1159 if (SUCCEEDED(hr))
1161 sd = data;
1163 ok( (sd->Control & SE_SELF_RELATIVE) == SE_SELF_RELATIVE, "relative flag unset\n" );
1164 ok( sd->Owner != 0, "no owner SID\n");
1165 ok( sd->Group != 0, "no owner SID\n");
1166 ok( EqualSid( (PSID)((LPBYTE)sd + sd->Owner), sid_admin ), "unexpected owner SID\n" );
1167 ok( EqualSid( (PSID)((LPBYTE)sd + sd->Group), sid_admin ), "unexpected group SID\n" );
1169 hr = SafeArrayUnaccessData( V_ARRAY( &var_sd ) );
1170 ok( hr == S_OK, "SafeArrayUnaccessData failed %x\n", hr );
1173 VariantClear( &var_sd );
1174 IWbemClassObject_Release( out );
1176 else if (hr == WBEM_E_ACCESS_DENIED)
1177 win_skip( "insufficient privs to test __SystemSecurity\n" );
1179 SysFreeString( class );
1182 static void test_Win32_OperatingSystem( IWbemServices *services )
1184 static const WCHAR queryW[] =
1185 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
1186 'O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
1187 static const WCHAR buildnumberW[] = {'B','u','i','l','d','N','u','m','b','e','r',0};
1188 static const WCHAR captionW[] = {'C','a','p','t','i','o','n',0};
1189 static const WCHAR csdversionW[] = {'C','S','D','V','e','r','s','i','o','n',0};
1190 static const WCHAR freephysicalmemoryW[] = {'F','r','e','e','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
1191 static const WCHAR nameW[] = {'N','a','m','e',0};
1192 static const WCHAR operatingsystemskuW[] = {'O','p','e','r','a','t','i','n','g','S','y','s','t','e','m','S','K','U',0};
1193 static const WCHAR osproductsuiteW[] = {'O','S','P','r','o','d','u','c','t','S','u','i','t','e',0};
1194 static const WCHAR ostypeW[] = {'O','S','T','y','p','e',0};
1195 static const WCHAR suitemaskW[] = {'S','u','i','t','e','M','a','s','k',0};
1196 static const WCHAR versionW[] = {'V','e','r','s','i','o','n',0};
1197 static const WCHAR servicepackmajorW[] =
1198 {'S','e','r','v','i','c','e','P','a','c','k','M','a','j','o','r','V','e','r','s','i','o','n',0};
1199 static const WCHAR servicepackminorW[] =
1200 {'S','e','r','v','i','c','e','P','a','c','k','M','i','n','o','r','V','e','r','s','i','o','n',0};
1201 static const WCHAR systemdriveW[] =
1202 {'S','y','s','t','e','m','D','r','i','v','e',0};
1203 static const WCHAR totalvisiblememorysizeW[] =
1204 {'T','o','t','a','l','V','i','s','i','b','l','e','M','e','m','o','r','y','S','i','z','e',0};
1205 static const WCHAR totalvirtualmemorysizeW[] =
1206 {'T','o','t','a','l','V','i','r','t','u','a','l','M','e','m','o','r','y','S','i','z','e',0};
1207 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
1208 IEnumWbemClassObject *result;
1209 IWbemClassObject *obj;
1210 CIMTYPE type;
1211 ULONG count;
1212 VARIANT val;
1213 HRESULT hr;
1215 hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
1216 ok( hr == S_OK, "IWbemServices_ExecQuery failed %08x\n", hr );
1218 hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
1219 ok( hr == S_OK, "IEnumWbemClassObject_Next failed %08x\n", hr );
1221 hr = IWbemClassObject_BeginEnumeration( obj, 0 );
1222 ok( hr == S_OK, "got %08x\n", hr );
1224 while (IWbemClassObject_Next( obj, 0, NULL, NULL, NULL, NULL ) == S_OK) {}
1226 hr = IWbemClassObject_EndEnumeration( obj );
1227 ok( hr == S_OK, "got %08x\n", hr );
1229 check_property( obj, buildnumberW, VT_BSTR, CIM_STRING );
1230 check_property( obj, captionW, VT_BSTR, CIM_STRING );
1232 type = 0xdeadbeef;
1233 VariantInit( &val );
1234 hr = IWbemClassObject_Get( obj, csdversionW, 0, &val, &type, NULL );
1235 ok( hr == S_OK, "failed to get csdversion %08x\n", hr );
1236 ok( V_VT( &val ) == VT_BSTR || V_VT( &val ) == VT_NULL, "unexpected variant type 0x%x\n", V_VT( &val ) );
1237 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1238 trace( "csdversion: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1239 VariantClear( &val );
1241 check_property( obj, freephysicalmemoryW, VT_BSTR, CIM_UINT64 );
1242 check_property( obj, nameW, VT_BSTR, CIM_STRING );
1244 type = 0xdeadbeef;
1245 VariantInit( &val );
1246 hr = IWbemClassObject_Get( obj, operatingsystemskuW, 0, &val, &type, NULL );
1247 ok( hr == S_OK || broken(hr == WBEM_E_NOT_FOUND) /* winxp */, "failed to get operatingsystemsku %08x\n", hr );
1248 if (hr == S_OK)
1250 ok( V_VT( &val ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &val ) );
1251 ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
1252 trace( "operatingsystemsku: %08x\n", V_I4( &val ) );
1253 VariantClear( &val );
1256 type = 0xdeadbeef;
1257 VariantInit( &val );
1258 hr = IWbemClassObject_Get( obj, osproductsuiteW, 0, &val, &type, NULL );
1259 ok( hr == S_OK, "failed to get osproductsuite %08x\n", hr );
1260 ok( V_VT( &val ) == VT_I4 || broken(V_VT( &val ) == VT_NULL) /* winxp */, "unexpected variant type 0x%x\n", V_VT( &val ) );
1261 ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
1262 trace( "osproductsuite: %d (%08x)\n", V_I4( &val ), V_I4( &val ) );
1263 VariantClear( &val );
1265 check_property( obj, ostypeW, VT_I4, CIM_UINT16 );
1266 check_property( obj, servicepackmajorW, VT_I4, CIM_UINT16 );
1267 check_property( obj, servicepackminorW, VT_I4, CIM_UINT16 );
1268 check_property( obj, suitemaskW, VT_I4, CIM_UINT32 );
1269 check_property( obj, versionW, VT_BSTR, CIM_STRING );
1270 check_property( obj, totalvisiblememorysizeW, VT_BSTR, CIM_UINT64 );
1271 check_property( obj, totalvirtualmemorysizeW, VT_BSTR, CIM_UINT64 );
1272 check_property( obj, systemdriveW, VT_BSTR, CIM_STRING );
1274 IWbemClassObject_Release( obj );
1275 IEnumWbemClassObject_Release( result );
1276 SysFreeString( query );
1277 SysFreeString( wql );
1280 static void test_Win32_ComputerSystemProduct( IWbemServices *services )
1282 static const WCHAR identifyingnumberW[] =
1283 {'I','d','e','n','t','i','f','y','i','n','g','N','u','m','b','e','r',0};
1284 static const WCHAR nameW[] =
1285 {'N','a','m','e',0};
1286 static const WCHAR skunumberW[] =
1287 {'S','K','U','N','u','m','b','e','r',0};
1288 static const WCHAR uuidW[] =
1289 {'U','U','I','D',0};
1290 static const WCHAR vendorW[] =
1291 {'V','e','n','d','o','r',0};
1292 static const WCHAR versionW[] =
1293 {'V','e','r','s','i','o','n',0};
1294 static const WCHAR queryW[] =
1295 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
1296 'C','o','m','p','u','t','e','r','S','y','s','t','e','m','P','r','o','d','u','c','t',0};
1297 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
1298 IEnumWbemClassObject *result;
1299 IWbemClassObject *obj;
1300 HRESULT hr;
1301 DWORD count;
1303 hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
1304 if (hr != S_OK)
1306 win_skip( "Win32_ComputerSystemProduct not available\n" );
1307 return;
1310 hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
1311 ok( hr == S_OK, "got %08x\n", hr );
1313 check_property( obj, identifyingnumberW, VT_BSTR, CIM_STRING );
1314 check_property( obj, nameW, VT_BSTR, CIM_STRING );
1315 check_property( obj, skunumberW, VT_NULL, CIM_STRING );
1316 check_property( obj, uuidW, VT_BSTR, CIM_STRING );
1317 check_property( obj, vendorW, VT_BSTR, CIM_STRING );
1318 check_property( obj, versionW, VT_BSTR, CIM_STRING );
1320 IWbemClassObject_Release( obj );
1321 IEnumWbemClassObject_Release( result );
1322 SysFreeString( query );
1323 SysFreeString( wql );
1326 static void test_Win32_PhysicalMemory( IWbemServices *services )
1328 static const WCHAR capacityW[] = {'C','a','p','a','c','i','t','y',0};
1329 static const WCHAR memorytypeW[] = {'M','e','m','o','r','y','T','y','p','e',0};
1330 static const WCHAR devicelocatorW[] = {'D','e','v','i','c','e','L','o','c','a','t','o','r',0};
1331 static const WCHAR queryW[] =
1332 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
1333 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
1334 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
1335 IEnumWbemClassObject *result;
1336 IWbemClassObject *obj;
1337 HRESULT hr;
1338 DWORD count;
1340 hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
1341 if (hr != S_OK)
1343 win_skip( "Win32_PhysicalMemory not available\n" );
1344 return;
1347 hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
1348 ok( hr == S_OK, "got %08x\n", hr );
1350 if (count > 0)
1352 check_property( obj, capacityW, VT_BSTR, CIM_UINT64 );
1353 check_property( obj, devicelocatorW, VT_BSTR, CIM_STRING );
1354 check_property( obj, memorytypeW, VT_I4, CIM_UINT16 );
1355 IWbemClassObject_Release( obj );
1357 IEnumWbemClassObject_Release( result );
1358 SysFreeString( query );
1359 SysFreeString( wql );
1362 static void test_Win32_IP4RouteTable( IWbemServices *services )
1364 static const WCHAR destinationW[] = {'D','e','s','t','i','n','a','t','i','o','n',0};
1365 static const WCHAR interfaceindexW[] = {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
1366 static const WCHAR nexthopW[] = {'N','e','x','t','H','o','p',0};
1367 static const WCHAR queryW[] =
1368 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
1369 'I','P','4','R','o','u','t','e','T','a','b','l','e',0};
1370 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
1371 IEnumWbemClassObject *result;
1372 IWbemClassObject *obj;
1373 HRESULT hr;
1374 DWORD count;
1376 hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
1377 if (hr != S_OK)
1379 win_skip( "Win32_IP4RouteTable not available\n" );
1380 return;
1383 for (;;)
1385 hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
1386 if (hr != S_OK) break;
1388 check_property( obj, destinationW, VT_BSTR, CIM_STRING );
1389 check_property( obj, interfaceindexW, VT_I4, CIM_SINT32 );
1390 check_property( obj, nexthopW, VT_BSTR, CIM_STRING );
1391 IWbemClassObject_Release( obj );
1394 IEnumWbemClassObject_Release( result );
1395 SysFreeString( query );
1396 SysFreeString( wql );
1399 static void test_Win32_Processor( IWbemServices *services )
1401 static const WCHAR architectureW[] =
1402 {'A','r','c','h','i','t','e','c','t','u','r','e',0};
1403 static const WCHAR captionW[] =
1404 {'C','a','p','t','i','o','n',0};
1405 static const WCHAR familyW[] =
1406 {'F','a','m','i','l','y',0};
1407 static const WCHAR levelW[] =
1408 {'L','e','v','e','l',0};
1409 static const WCHAR manufacturerW[] =
1410 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
1411 static const WCHAR nameW[] =
1412 {'N','a','m','e',0};
1413 static const WCHAR numcoresW[] =
1414 {'N','u','m','b','e','r','O','f','C','o','r','e','s',0};
1415 static const WCHAR numlogicalprocessorsW[] =
1416 {'N','u','m','b','e','r','O','f','L','o','g','i','c','a','l','P','r','o','c','e','s','s','o','r','s',0};
1417 static const WCHAR processoridW[] =
1418 {'P','r','o','c','e','s','s','o','r','I','d',0};
1419 static const WCHAR revisionW[] =
1420 {'R','e','v','i','s','i','o','n',0};
1421 static const WCHAR versionW[] =
1422 {'V','e','r','s','i','o','n',0};
1423 static const WCHAR queryW[] =
1424 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
1425 'P','r','o','c','e','s','s','o','r',0};
1426 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
1427 IEnumWbemClassObject *result;
1428 IWbemClassObject *obj;
1429 VARIANT val;
1430 CIMTYPE type;
1431 HRESULT hr;
1432 DWORD count;
1434 hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
1435 ok( hr == S_OK, "got %08x\n", hr );
1437 for (;;)
1439 hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
1440 if (hr != S_OK) break;
1442 check_property( obj, captionW, VT_BSTR, CIM_STRING );
1443 check_property( obj, architectureW, VT_I4, CIM_UINT16 );
1444 check_property( obj, familyW, VT_I4, CIM_UINT16 );
1445 check_property( obj, levelW, VT_I4, CIM_UINT16 );
1446 check_property( obj, manufacturerW, VT_BSTR, CIM_STRING );
1447 check_property( obj, nameW, VT_BSTR, CIM_STRING );
1448 check_property( obj, processoridW, VT_BSTR, CIM_STRING );
1449 check_property( obj, revisionW, VT_I4, CIM_UINT16 );
1450 check_property( obj, versionW, VT_BSTR, CIM_STRING );
1452 type = 0xdeadbeef;
1453 VariantInit( &val );
1454 hr = IWbemClassObject_Get( obj, numlogicalprocessorsW, 0, &val, &type, NULL );
1455 ok( hr == S_OK || broken(hr == WBEM_E_NOT_FOUND) /* win2k3 */, "got %08x\n", hr );
1456 if (hr == S_OK)
1458 ok( V_VT( &val ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &val ) );
1459 ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
1460 trace( "numlogicalprocessors %u\n", V_I4( &val ) );
1463 type = 0xdeadbeef;
1464 VariantInit( &val );
1465 hr = IWbemClassObject_Get( obj, numcoresW, 0, &val, &type, NULL );
1466 ok( hr == S_OK || broken(hr == WBEM_E_NOT_FOUND) /* win2k3 */, "got %08x\n", hr );
1467 if (hr == S_OK)
1469 ok( V_VT( &val ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &val ) );
1470 ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
1471 trace( "numcores %u\n", V_I4( &val ) );
1474 IWbemClassObject_Release( obj );
1477 IEnumWbemClassObject_Release( result );
1478 SysFreeString( query );
1479 SysFreeString( wql );
1482 static void test_Win32_VideoController( IWbemServices *services )
1484 static const WCHAR configmanagererrorcodeW[] =
1485 {'C','o','n','f','i','g','M','a','n','a','g','e','r','E','r','r','o','r','C','o','d','e',0};
1486 static const WCHAR driverdateW[] =
1487 {'D','r','i','v','e','r','D','a','t','e',0};
1488 static const WCHAR installeddisplaydriversW[]=
1489 {'I','n','s','t','a','l','l','e','d','D','i','s','p','l','a','y','D','r','i','v','e','r','s',0};
1490 static const WCHAR statusW[] =
1491 {'S','t','a','t','u','s',0};
1492 static const WCHAR queryW[] =
1493 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
1494 'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
1495 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
1496 IEnumWbemClassObject *result;
1497 IWbemClassObject *obj;
1498 VARIANT val;
1499 CIMTYPE type;
1500 HRESULT hr;
1501 DWORD count;
1503 hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
1504 if (hr != S_OK)
1506 win_skip( "Win32_VideoController not available\n" );
1507 return;
1510 for (;;)
1512 hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
1513 if (hr != S_OK) break;
1515 check_property( obj, configmanagererrorcodeW, VT_I4, CIM_UINT32 );
1516 check_property( obj, driverdateW, VT_BSTR, CIM_DATETIME );
1518 type = 0xdeadbeef;
1519 VariantInit( &val );
1520 hr = IWbemClassObject_Get( obj, installeddisplaydriversW, 0, &val, &type, NULL );
1521 ok( hr == S_OK, "got %08x\n", hr );
1522 ok( V_VT( &val ) == VT_BSTR || V_VT( &val ) == VT_NULL, "unexpected variant type 0x%x\n", V_VT( &val ) );
1523 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1524 trace( "installeddisplaydrivers %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1525 VariantClear( &val );
1527 check_property( obj, statusW, VT_BSTR, CIM_STRING );
1528 IWbemClassObject_Release( obj );
1531 IEnumWbemClassObject_Release( result );
1532 SysFreeString( query );
1533 SysFreeString( wql );
1536 static void test_Win32_Printer( IWbemServices *services )
1538 static const WCHAR deviceidW[] =
1539 {'D','e','v','i','c','e','I','d',0};
1540 static const WCHAR locationW[] =
1541 {'L','o','c','a','t','i','o','n',0};
1542 static const WCHAR portnameW[] =
1543 {'P','o','r','t','N','a','m','e',0};
1544 static const WCHAR queryW[] =
1545 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
1546 'P','r','i','n','t','e','r',0};
1547 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
1548 IEnumWbemClassObject *result;
1549 IWbemClassObject *obj;
1550 VARIANT val;
1551 CIMTYPE type;
1552 HRESULT hr;
1553 DWORD count;
1555 hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
1556 if (hr != S_OK)
1558 win_skip( "Win32_Printer not available\n" );
1559 return;
1562 for (;;)
1564 hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
1565 if (hr != S_OK) break;
1567 check_property( obj, deviceidW, VT_BSTR, CIM_STRING );
1569 type = 0xdeadbeef;
1570 memset( &val, 0, sizeof(val) );
1571 hr = IWbemClassObject_Get( obj, locationW, 0, &val, &type, NULL );
1572 ok( hr == S_OK, "got %08x\n", hr );
1573 ok( V_VT( &val ) == VT_BSTR || V_VT( &val ) == VT_NULL, "unexpected variant type 0x%x\n", V_VT( &val ) );
1574 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1575 trace( "location %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1576 VariantClear( &val );
1578 check_property( obj, portnameW, VT_BSTR, CIM_STRING );
1579 IWbemClassObject_Release( obj );
1582 IEnumWbemClassObject_Release( result );
1583 SysFreeString( query );
1584 SysFreeString( wql );
1587 static void test_Win32_PnPEntity( IWbemServices *services )
1589 HRESULT hr;
1590 IEnumWbemClassObject *enm;
1591 IWbemClassObject *obj;
1592 VARIANT val;
1593 CIMTYPE type;
1594 ULONG count, i;
1595 BSTR bstr;
1597 static WCHAR win32_pnpentityW[] = {'W','i','n','3','2','_','P','n','P','E','n','t','i','t','y',0};
1598 static const WCHAR deviceidW[] = {'D','e','v','i','c','e','I','d',0};
1600 bstr = SysAllocString( win32_pnpentityW );
1602 hr = IWbemServices_CreateInstanceEnum( services, bstr, 0, NULL, &enm );
1603 ok( hr == S_OK, "got %08x\n", hr );
1605 SysFreeString( bstr );
1606 bstr = SysAllocString( deviceidW );
1608 while (1)
1610 hr = IEnumWbemClassObject_Next( enm, 1000, 1, &obj, &count );
1611 ok( (count == 1 && (hr == WBEM_S_FALSE || hr == WBEM_S_NO_ERROR)) ||
1612 (count == 0 && (hr == WBEM_S_FALSE || hr == WBEM_S_TIMEDOUT)),
1613 "got %08x with %u objects returned\n", hr, count );
1615 if (count == 0)
1616 break;
1618 for (i = 0; i < count; ++i)
1620 hr = IWbemClassObject_Get( obj, bstr, 0, &val, &type, NULL );
1621 ok( hr == S_OK, "got %08x\n", hr );
1623 if (SUCCEEDED( hr ))
1625 ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1626 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1627 VariantClear( &val );
1632 SysFreeString( bstr );
1634 IEnumWbemClassObject_Release( enm );
1637 START_TEST(query)
1639 static const WCHAR cimv2W[] = {'R','O','O','T','\\','C','I','M','V','2',0};
1640 BSTR path = SysAllocString( cimv2W );
1641 IWbemLocator *locator;
1642 IWbemServices *services;
1643 HRESULT hr;
1645 CoInitialize( NULL );
1646 CoInitializeSecurity( NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT,
1647 RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL );
1648 hr = CoCreateInstance( &CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemLocator,
1649 (void **)&locator );
1650 if (hr != S_OK)
1652 win_skip("can't create instance of WbemLocator\n");
1653 return;
1655 hr = IWbemLocator_ConnectServer( locator, path, NULL, NULL, NULL, 0, NULL, NULL, &services );
1656 ok( hr == S_OK, "failed to get IWbemServices interface %08x\n", hr );
1658 hr = CoSetProxyBlanket( (IUnknown *)services, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL,
1659 RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE );
1660 ok( hr == S_OK, "failed to set proxy blanket %08x\n", hr );
1662 test_GetNames( services );
1663 test_associators( services );
1664 test_notification_query_async( services );
1665 test_query_async( services );
1666 test_query_semisync( services );
1667 test_select( services );
1669 /* classes */
1670 test_StdRegProv( services );
1671 test_SystemSecurity( services );
1672 test_Win32_Baseboard( services );
1673 test_Win32_ComputerSystem( services );
1674 test_Win32_ComputerSystemProduct( services );
1675 test_Win32_Bios( services );
1676 test_Win32_IP4RouteTable( services );
1677 test_Win32_OperatingSystem( services );
1678 test_Win32_PhysicalMemory( services );
1679 test_Win32_PnPEntity( services );
1680 test_Win32_Printer( services );
1681 test_Win32_Process( services, FALSE );
1682 test_Win32_Process( services, TRUE );
1683 test_Win32_Processor( services );
1684 test_Win32_Service( services );
1685 test_Win32_SystemEnclosure( services );
1686 test_Win32_VideoController( services );
1688 SysFreeString( path );
1689 IWbemServices_Release( services );
1690 IWbemLocator_Release( locator );
1691 CoUninitialize();