[WBOMPROX_WINETEST] Sync with Wine Staging 1.9.23. CORE-12409
[reactos.git] / rostests / winetests / wbemprox / query.c
1 /*
2 * Copyright 2012 Hans Leidekker for CodeWeavers
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #define COBJMACROS
20
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"
29
30 static const WCHAR wqlW[] = {'w','q','l',0};
31
32 static HRESULT exec_query( IWbemServices *services, const WCHAR *str, IEnumWbemClassObject **result )
33 {
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;
41
42 hr = IWbemServices_ExecQuery( services, wql, query, flags, NULL, result );
43 if (hr == S_OK)
44 {
45 trace("%s\n", wine_dbgstr_w(str));
46 for (;;)
47 {
48 VARIANT var;
49
50 IEnumWbemClassObject_Next( *result, 10000, 1, &obj, &count );
51 if (!count) break;
52
53 if (IWbemClassObject_Get( obj, captionW, 0, &var, NULL, NULL ) == WBEM_S_NO_ERROR)
54 {
55 trace("caption: %s\n", wine_dbgstr_w(V_BSTR(&var)));
56 VariantClear( &var );
57 }
58 if (IWbemClassObject_Get( obj, descriptionW, 0, &var, NULL, NULL ) == WBEM_S_NO_ERROR)
59 {
60 trace("description: %s\n", wine_dbgstr_w(V_BSTR(&var)));
61 VariantClear( &var );
62 }
63 IWbemClassObject_Release( obj );
64 }
65 }
66 SysFreeString( wql );
67 SysFreeString( query );
68 return hr;
69 }
70
71 static void test_select( IWbemServices *services )
72 {
73 static const WCHAR emptyW[] = {0};
74 static const WCHAR sqlW[] = {'S','Q','L',0};
75 static const WCHAR query1[] =
76 {'S','E','L','E','C','T',' ','H','O','T','F','I','X','I','D',' ','F','R','O','M',' ',
77 '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};
78 static const WCHAR query2[] =
79 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_','B','I','O','S',0};
80 static const WCHAR query3[] =
81 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
82 'L','o','g','i','c','a','l','D','i','s','k',' ','W','H','E','R','E',' ',
83 '\"','N','T','F','S','\"',' ','=',' ','F','i','l','e','S','y','s','t','e','m',0};
84 static const WCHAR query4[] =
85 {'S','E','L','E','C','T',' ','a',' ','F','R','O','M',' ','b',0};
86 static const WCHAR query5[] =
87 {'S','E','L','E','C','T',' ','a',' ','F','R','O','M',' ','W','i','n','3','2','_','B','i','o','s',0};
88 static const WCHAR query6[] =
89 {'S','E','L','E','C','T',' ','D','e','s','c','r','i','p','t','i','o','n',' ','F','R','O','M',' ',
90 'W','i','n','3','2','_','B','i','o','s',0};
91 static const WCHAR query7[] =
92 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
93 'P','r','o','c','e','s','s',' ','W','H','E','R','E',' ','C','a','p','t','i','o','n',' ',
94 'L','I','K','E',' ','\'','%','%','R','E','G','E','D','I','T','%','\'',0};
95 static const WCHAR query8[] =
96 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
97 'D','i','s','k','D','r','i','v','e',' ','W','H','E','R','E',' ','D','e','v','i','c','e','I','D','=',
98 '\"','\\','\\','\\','\\','.','\\','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','0','\"',0};
99 static const WCHAR query9[] =
100 {'S','E','L','E','C','T','\n','a','\r','F','R','O','M','\t','b',0};
101 static const WCHAR query10[] =
102 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
103 'P','r','o','c','e','s','s',' ','W','H','E','R','E',' ','C','a','p','t','i','o','n',' ',
104 'L','I','K','E',' ','"','%','f','i','r','e','f','o','x','.','e','x','e','"',0};
105 static const WCHAR query11[] =
106 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
107 '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',' ',
108 'a','v','a','i','l','a','b','i','l','i','t','y',' ','=',' ','\'','3','\'',0};
109 static const WCHAR *test[] = { query1, query2, query3, query4, query5, query6, query7, query8, query9, query10,
110 query11 };
111 HRESULT hr;
112 IEnumWbemClassObject *result;
113 BSTR wql = SysAllocString( wqlW );
114 BSTR sql = SysAllocString( sqlW );
115 BSTR query = SysAllocString( query1 );
116 UINT i;
117
118 hr = IWbemServices_ExecQuery( services, NULL, NULL, 0, NULL, &result );
119 ok( hr == WBEM_E_INVALID_PARAMETER, "query failed %08x\n", hr );
120
121 hr = IWbemServices_ExecQuery( services, NULL, query, 0, NULL, &result );
122 ok( hr == WBEM_E_INVALID_PARAMETER, "query failed %08x\n", hr );
123
124 hr = IWbemServices_ExecQuery( services, wql, NULL, 0, NULL, &result );
125 ok( hr == WBEM_E_INVALID_PARAMETER, "query failed %08x\n", hr );
126
127 hr = IWbemServices_ExecQuery( services, sql, query, 0, NULL, &result );
128 ok( hr == WBEM_E_INVALID_QUERY_TYPE, "query failed %08x\n", hr );
129
130 hr = IWbemServices_ExecQuery( services, sql, NULL, 0, NULL, &result );
131 ok( hr == WBEM_E_INVALID_PARAMETER, "query failed %08x\n", hr );
132
133 SysFreeString( query );
134 query = SysAllocString( emptyW );
135 hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
136 ok( hr == WBEM_E_INVALID_PARAMETER, "query failed %08x\n", hr );
137
138 for (i = 0; i < sizeof(test)/sizeof(test[0]); i++)
139 {
140 hr = exec_query( services, test[i], &result );
141 ok( hr == S_OK, "query %u failed: %08x\n", i, hr );
142 if (result) IEnumWbemClassObject_Release( result );
143 }
144
145 SysFreeString( wql );
146 SysFreeString( sql );
147 SysFreeString( query );
148 }
149
150 static void test_associators( IWbemServices *services )
151 {
152 static const WCHAR query1[] =
153 {'A','S','S','O','C','I','A','T','O','R','S',' ','O','F',' ','{','W','i','n','3','2','_',
154 'L','o','g','i','c','a','l','D','i','s','k','.','D','e','v','i','c','e','I','D','=','"','C',':','"','}',0};
155 static const WCHAR query2[] =
156 {'A','S','S','O','C','I','A','T','O','R','S',' ','O','F',' ','{','W','i','n','3','2','_',
157 'L','o','g','i','c','a','l','D','i','s','k','.','D','e','v','i','c','e','I','D','=','"','C',':','"','}',' ',
158 'W','H','E','R','E',' ','A','s','s','o','c','C','l','a','s','s',' ','=',' ','W','i','n','3','2','_',
159 'L','o','g','i','c','a','l','D','i','s','k','T','o','P','a','r','t','i','t','i','o','n',0};
160 static const WCHAR *test[] = { query1, query2 };
161 HRESULT hr;
162 IEnumWbemClassObject *result;
163 UINT i;
164
165 for (i = 0; i < sizeof(test)/sizeof(test[0]); i++)
166 {
167 hr = exec_query( services, test[i], &result );
168 todo_wine ok( hr == S_OK, "query %u failed: %08x\n", i, hr );
169 if (result) IEnumWbemClassObject_Release( result );
170 }
171 }
172
173 static void test_Win32_Service( IWbemServices *services )
174 {
175 static const WCHAR returnvalueW[] = {'R','e','t','u','r','n','V','a','l','u','e',0};
176 static const WCHAR pauseserviceW[] = {'P','a','u','s','e','S','e','r','v','i','c','e',0};
177 static const WCHAR resumeserviceW[] = {'R','e','s','u','m','e','S','e','r','v','i','c','e',0};
178 static const WCHAR startserviceW[] = {'S','t','a','r','t','S','e','r','v','i','c','e',0};
179 static const WCHAR stopserviceW[] = {'S','t','o','p','S','e','r','v','i','c','e',0};
180 static const WCHAR stateW[] = {'S','t','a','t','e',0};
181 static const WCHAR stoppedW[] = {'S','t','o','p','p','e','d',0};
182 static const WCHAR serviceW[] = {'W','i','n','3','2','_','S','e','r','v','i','c','e','.',
183 'N','a','m','e','=','"','S','p','o','o','l','e','r','"',0};
184 static const WCHAR emptyW[] = {0};
185 BSTR class = SysAllocString( serviceW ), empty = SysAllocString( emptyW ), method;
186 IWbemClassObject *service, *out;
187 VARIANT state, retval;
188 CIMTYPE type;
189 HRESULT hr;
190
191 hr = IWbemServices_GetObject( services, class, 0, NULL, &service, NULL );
192 if (hr != S_OK)
193 {
194 win_skip( "Win32_Service not available\n" );
195 goto out;
196 }
197 type = 0xdeadbeef;
198 VariantInit( &state );
199 hr = IWbemClassObject_Get( service, stateW, 0, &state, &type, NULL );
200 ok( hr == S_OK, "failed to get service state %08x\n", hr );
201 ok( V_VT( &state ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &state ) );
202 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
203
204 if (!lstrcmpW( V_BSTR( &state ), stoppedW ))
205 {
206 out = NULL;
207 method = SysAllocString( startserviceW );
208 hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, NULL, &out, NULL );
209 ok( hr == S_OK, "failed to execute method %08x\n", hr );
210 SysFreeString( method );
211
212 VariantInit( &retval );
213 hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, NULL, NULL );
214 ok( hr == S_OK, "failed to get return value %08x\n", hr );
215 ok( !V_I4( &retval ), "unexpected error %u\n", V_UI4( &retval ) );
216 IWbemClassObject_Release( out );
217 }
218 out = NULL;
219 method = SysAllocString( pauseserviceW );
220 hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, NULL, &out, NULL );
221 ok( hr == S_OK, "failed to execute method %08x\n", hr );
222 SysFreeString( method );
223
224 VariantInit( &retval );
225 hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, NULL, NULL );
226 ok( hr == S_OK, "failed to get return value %08x\n", hr );
227 ok( V_I4( &retval ), "unexpected success\n" );
228 IWbemClassObject_Release( out );
229
230 out = NULL;
231 method = SysAllocString( resumeserviceW );
232 hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, NULL, &out, NULL );
233 ok( hr == S_OK, "failed to execute method %08x\n", hr );
234 SysFreeString( method );
235
236 VariantInit( &retval );
237 hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, NULL, NULL );
238 ok( hr == S_OK, "failed to get return value %08x\n", hr );
239 ok( V_I4( &retval ), "unexpected success\n" );
240 IWbemClassObject_Release( out );
241
242 if (!lstrcmpW( V_BSTR( &state ), stoppedW ))
243 {
244 out = NULL;
245 method = SysAllocString( stopserviceW );
246 hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, NULL, &out, NULL );
247 ok( hr == S_OK, "failed to execute method %08x\n", hr );
248 SysFreeString( method );
249
250 VariantInit( &retval );
251 hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, NULL, NULL );
252 ok( hr == S_OK, "failed to get return value %08x\n", hr );
253 ok( !V_I4( &retval ), "unexpected error %u\n", V_UI4( &retval ) );
254 IWbemClassObject_Release( out );
255 }
256 VariantClear( &state );
257 IWbemClassObject_Release( service );
258
259 service = NULL;
260 hr = IWbemServices_GetObject( services, NULL, 0, NULL, &service, NULL );
261 ok( hr == S_OK, "got %08x\n", hr );
262 if (service) IWbemClassObject_Release( service );
263
264 service = NULL;
265 hr = IWbemServices_GetObject( services, empty, 0, NULL, &service, NULL );
266 ok( hr == S_OK, "got %08x\n", hr );
267 if (service) IWbemClassObject_Release( service );
268
269 out:
270 SysFreeString( empty );
271 SysFreeString( class );
272 }
273
274 static void test_Win32_Bios( IWbemServices *services )
275 {
276 static const WCHAR queryW[] =
277 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_', 'B','i','o','s',0};
278 static const WCHAR descriptionW[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
279 static const WCHAR identificationcodeW[] = {'I','d','e','n','t','i','f','i','c','a','t','i','o','n','C','o','d','e',0};
280 static const WCHAR manufacturerW[] = {'M','a','n','u','f','a','c','t','u','r','e','r',0};
281 static const WCHAR nameW[] = {'N','a','m','e',0};
282 static const WCHAR releasedateW[] = {'R','e','l','e','a','s','e','D','a','t','e',0};
283 static const WCHAR serialnumberW[] = {'S','e','r','i','a','l','N','u','m','b','e','r',0};
284 static const WCHAR smbiosbiosversionW[] = {'S','M','B','I','O','S','B','I','O','S','V','e','r','s','i','o','n',0};
285 static const WCHAR versionW[] = {'V','e','r','s','i','o','n',0};
286 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
287 IEnumWbemClassObject *result;
288 IWbemClassObject *obj;
289 CIMTYPE type;
290 ULONG count;
291 VARIANT val;
292 HRESULT hr;
293
294 hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
295 ok( hr == S_OK, "IWbemServices_ExecQuery failed %08x\n", hr );
296
297 hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
298 ok( hr == S_OK, "IEnumWbemClassObject_Next failed %08x\n", hr );
299
300 type = 0xdeadbeef;
301 VariantInit( &val );
302 hr = IWbemClassObject_Get( obj, descriptionW, 0, &val, &type, NULL );
303 ok( hr == S_OK, "failed to get description %08x\n", hr );
304 ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
305 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
306 trace( "description: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
307 VariantClear( &val );
308
309 type = 0xdeadbeef;
310 VariantInit( &val );
311 hr = IWbemClassObject_Get( obj, identificationcodeW, 0, &val, &type, NULL );
312 ok( hr == S_OK, "failed to get identication code %08x\n", hr );
313 ok( V_VT( &val ) == VT_NULL, "unexpected variant type 0x%x\n", V_VT( &val ) );
314 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
315 VariantClear( &val );
316
317 type = 0xdeadbeef;
318 VariantInit( &val );
319 hr = IWbemClassObject_Get( obj, manufacturerW, 0, &val, &type, NULL );
320 ok( hr == S_OK, "failed to get manufacturer %08x\n", hr );
321 ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
322 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
323 trace( "manufacturer: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
324 VariantClear( &val );
325
326 type = 0xdeadbeef;
327 VariantInit( &val );
328 hr = IWbemClassObject_Get( obj, nameW, 0, &val, &type, NULL );
329 ok( hr == S_OK, "failed to get name %08x\n", hr );
330 ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
331 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
332 trace( "name: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
333 VariantClear( &val );
334
335 type = 0xdeadbeef;
336 VariantInit( &val );
337 hr = IWbemClassObject_Get( obj, releasedateW, 0, &val, &type, NULL );
338 ok( hr == S_OK, "failed to get release date %08x\n", hr );
339 ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
340 ok( type == CIM_DATETIME, "unexpected type 0x%x\n", type );
341 trace( "release date: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
342 VariantClear( &val );
343
344 type = 0xdeadbeef;
345 VariantInit( &val );
346 hr = IWbemClassObject_Get( obj, serialnumberW, 0, &val, &type, NULL );
347 ok( hr == S_OK, "failed to get serial number %08x\n", hr );
348 ok( V_VT( &val ) == VT_BSTR || V_VT( &val ) == VT_NULL /* Testbot VMs */,
349 "unexpected variant type 0x%x\n", V_VT( &val ) );
350 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
351 VariantClear( &val );
352
353 type = 0xdeadbeef;
354 VariantInit( &val );
355 hr = IWbemClassObject_Get( obj, smbiosbiosversionW, 0, &val, &type, NULL );
356 ok( hr == S_OK, "failed to get bios version %08x\n", hr );
357 ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
358 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
359 trace( "bios version: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
360 VariantClear( &val );
361
362 type = 0xdeadbeef;
363 VariantInit( &val );
364 hr = IWbemClassObject_Get( obj, versionW, 0, &val, &type, NULL );
365 ok( hr == S_OK, "failed to get version %08x\n", hr );
366 ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
367 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
368 trace( "version: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
369 VariantClear( &val );
370
371 IWbemClassObject_Release( obj );
372 IEnumWbemClassObject_Release( result );
373 SysFreeString( query );
374 SysFreeString( wql );
375 }
376
377 static void test_Win32_Process( IWbemServices *services )
378 {
379 static const WCHAR returnvalueW[] = {'R','e','t','u','r','n','V','a','l','u','e',0};
380 static const WCHAR getownerW[] = {'G','e','t','O','w','n','e','r',0};
381 static const WCHAR userW[] = {'U','s','e','r',0};
382 static const WCHAR domainW[] = {'D','o','m','a','i','n',0};
383 static const WCHAR processW[] = {'W','i','n','3','2','_','P','r','o','c','e','s','s',0};
384 static const WCHAR idW[] = {'I','D',0};
385 static const WCHAR fmtW[] = {'W','i','n','3','2','_','P','r','o','c','e','s','s','.',
386 'H','a','n','d','l','e','=','"','%','u','"',0};
387 static const LONG expected_flavor = WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE |
388 WBEM_FLAVOR_NOT_OVERRIDABLE |
389 WBEM_FLAVOR_ORIGIN_PROPAGATED;
390 BSTR class, method;
391 IWbemClassObject *process, *out;
392 IWbemQualifierSet *qualifiers;
393 VARIANT user, domain, retval, val;
394 LONG flavor;
395 CIMTYPE type;
396 HRESULT hr;
397
398 class = SysAllocString( processW );
399 hr = IWbemServices_GetObject( services, class, 0, NULL, &process, NULL );
400 SysFreeString( class );
401 if (hr != S_OK)
402 {
403 win_skip( "Win32_Process not available\n" );
404 return;
405 }
406 hr = IWbemClassObject_GetMethod( process, getownerW, 0, NULL, NULL );
407 ok( hr == S_OK, "failed to get GetOwner method %08x\n", hr );
408 IWbemClassObject_Release( process );
409
410 out = NULL;
411 method = SysAllocString( getownerW );
412 class = SysAllocStringLen( NULL, sizeof(fmtW)/sizeof(fmtW[0]) + 10 );
413 wsprintfW( class, fmtW, GetCurrentProcessId() );
414 hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, NULL, &out, NULL );
415 ok( hr == S_OK, "failed to execute method %08x\n", hr );
416 SysFreeString( method );
417 SysFreeString( class );
418
419 type = 0xdeadbeef;
420 VariantInit( &retval );
421 hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, &type, NULL );
422 ok( hr == S_OK, "failed to get return value %08x\n", hr );
423 ok( V_VT( &retval ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &retval ) );
424 ok( !V_I4( &retval ), "unexpected error %u\n", V_I4( &retval ) );
425 ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
426
427 type = 0xdeadbeef;
428 VariantInit( &user );
429 hr = IWbemClassObject_Get( out, userW, 0, &user, &type, NULL );
430 ok( hr == S_OK, "failed to get user %08x\n", hr );
431 ok( V_VT( &user ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &user ) );
432 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
433 trace("%s\n", wine_dbgstr_w(V_BSTR(&user)));
434
435 type = 0xdeadbeef;
436 VariantInit( &domain );
437 hr = IWbemClassObject_Get( out, domainW, 0, &domain, &type, NULL );
438 ok( hr == S_OK, "failed to get domain %08x\n", hr );
439 ok( V_VT( &domain ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &domain ) );
440 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
441 trace("%s\n", wine_dbgstr_w(V_BSTR(&domain)));
442
443 hr = IWbemClassObject_GetPropertyQualifierSet( out, userW, &qualifiers );
444 ok( hr == S_OK, "failed to get qualifier set %08x\n", hr );
445
446 flavor = -1;
447 V_I4(&val) = -1;
448 V_VT(&val) = VT_ERROR;
449 hr = IWbemQualifierSet_Get( qualifiers, idW, 0, &val, &flavor );
450 ok( hr == S_OK, "got %08x\n", hr );
451 ok( flavor == expected_flavor, "got %d\n", flavor );
452 ok( V_VT(&val) == VT_I4, "got %u\n", V_VT(&val) );
453 ok( V_I4(&val) == 0, "got %u\n", V_I4(&val) );
454 VariantClear( &val );
455
456 IWbemQualifierSet_Release( qualifiers );
457 hr = IWbemClassObject_GetPropertyQualifierSet( out, domainW, &qualifiers );
458 ok( hr == S_OK, "failed to get qualifier set %08x\n", hr );
459
460 flavor = -1;
461 V_I4(&val) = -1;
462 V_VT(&val) = VT_ERROR;
463 hr = IWbemQualifierSet_Get( qualifiers, idW, 0, &val, &flavor );
464 ok( hr == S_OK, "got %08x\n", hr );
465 ok( flavor == expected_flavor, "got %d\n", flavor );
466 ok( V_VT(&val) == VT_I4, "got %u\n", V_VT(&val) );
467 ok( V_I4(&val) == 1, "got %u\n", V_I4(&val) );
468 VariantClear( &val );
469
470 IWbemQualifierSet_Release( qualifiers );
471 hr = IWbemClassObject_GetPropertyQualifierSet( out, returnvalueW, &qualifiers );
472 ok( hr == S_OK, "failed to get qualifier set %08x\n", hr );
473
474 hr = IWbemQualifierSet_Get( qualifiers, idW, 0, &val, &flavor );
475 ok( hr == WBEM_E_NOT_FOUND, "got %08x\n", hr );
476
477 IWbemQualifierSet_Release( qualifiers );
478 VariantClear( &user );
479 VariantClear( &domain );
480 IWbemClassObject_Release( out );
481 }
482
483 static void test_Win32_ComputerSystem( IWbemServices *services )
484 {
485 static const WCHAR nameW[] = {'N','a','m','e',0};
486 static const WCHAR usernameW[] = {'U','s','e','r','N','a','m','e',0};
487 static const WCHAR backslashW[] = {'\\',0};
488 static const WCHAR queryW[] =
489 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
490 'C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
491 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
492 IEnumWbemClassObject *result;
493 IWbemClassObject *service;
494 VARIANT value;
495 CIMTYPE type;
496 HRESULT hr;
497 WCHAR compname[MAX_COMPUTERNAME_LENGTH + 1];
498 WCHAR username[128];
499 DWORD len, count;
500
501 len = sizeof(compname) / sizeof(compname[0]);
502 if (!GetComputerNameW( compname, &len ))
503 compname[0] = 0;
504
505 lstrcpyW( username, compname );
506 lstrcatW( username, backslashW );
507 len = sizeof(username) / sizeof(username[0]) - lstrlenW( username );
508 if (!GetUserNameW( username + lstrlenW( username ), &len ))
509 username[0] = 0;
510
511 if (!compname[0] || !username[0])
512 {
513 skip( "Failed to get user or computer name\n" );
514 goto out;
515 }
516
517 hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
518 if (hr != S_OK)
519 {
520 win_skip( "Win32_ComputerSystem not available\n" );
521 goto out;
522 }
523
524 hr = IEnumWbemClassObject_Next( result, 10000, 1, &service, &count );
525 ok( hr == S_OK, "got %08x\n", hr );
526
527 type = 0xdeadbeef;
528 VariantInit( &value );
529 hr = IWbemClassObject_Get( service, nameW, 0, &value, &type, NULL );
530 ok( hr == S_OK, "failed to get computer name %08x\n", hr );
531 ok( V_VT( &value ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &value ) );
532 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
533 ok( !lstrcmpiW( V_BSTR( &value ), compname ), "got %s, expected %s\n", wine_dbgstr_w(V_BSTR(&value)), wine_dbgstr_w(compname) );
534 VariantClear( &value );
535
536 type = 0xdeadbeef;
537 VariantInit( &value );
538 hr = IWbemClassObject_Get( service, usernameW, 0, &value, &type, NULL );
539 ok( hr == S_OK, "failed to get computer name %08x\n", hr );
540 ok( V_VT( &value ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &value ) );
541 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
542 ok( !lstrcmpiW( V_BSTR( &value ), username ), "got %s, expected %s\n", wine_dbgstr_w(V_BSTR(&value)), wine_dbgstr_w(username) );
543 VariantClear( &value );
544
545 IWbemClassObject_Release( service );
546 IEnumWbemClassObject_Release( result );
547 out:
548 SysFreeString( query );
549 SysFreeString( wql );
550 }
551
552 static void test_Win32_SystemEnclosure( IWbemServices *services )
553 {
554 static const WCHAR queryW[] =
555 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
556 'S','y','s','t','e','m','E','n','c','l','o','s','u','r','e',0};
557 static const WCHAR captionW[] = {'C','a','p','t','i','o','n',0};
558 static const WCHAR chassistypesW[] = {'C','h','a','s','s','i','s','T','y','p','e','s',0};
559 static const WCHAR descriptionW[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
560 static const WCHAR lockpresentW[] = {'L','o','c','k','P','r','e','s','e','n','t',0};
561 static const WCHAR manufacturerW[] = {'M','a','n','u','f','a','c','t','u','r','e','r',0};
562 static const WCHAR nameW[] = {'N','a','m','e',0};
563 static const WCHAR tagW[] = {'T','a','g',0};
564 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
565 IEnumWbemClassObject *result;
566 IWbemClassObject *obj;
567 CIMTYPE type;
568 ULONG count;
569 VARIANT val;
570 DWORD *data;
571 HRESULT hr;
572
573 hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
574 ok( hr == S_OK, "IWbemServices_ExecQuery failed %08x\n", hr );
575
576 hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
577 ok( hr == S_OK, "IEnumWbemClassObject_Next failed %08x\n", hr );
578
579 type = 0xdeadbeef;
580 VariantInit( &val );
581 hr = IWbemClassObject_Get( obj, captionW, 0, &val, &type, NULL );
582 ok( hr == S_OK, "failed to get caption %08x\n", hr );
583 ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
584 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
585 trace( "caption: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
586 VariantClear( &val );
587
588 type = 0xdeadbeef;
589 VariantInit( &val );
590 hr = IWbemClassObject_Get( obj, chassistypesW, 0, &val, &type, NULL );
591 ok( hr == S_OK, "failed to get chassis types %08x\n", hr );
592 ok( V_VT( &val ) == (VT_I4|VT_ARRAY), "unexpected variant type 0x%x\n", V_VT( &val ) );
593 ok( type == (CIM_UINT16|CIM_FLAG_ARRAY), "unexpected type 0x%x\n", type );
594 hr = SafeArrayAccessData( V_ARRAY( &val ), (void **)&data );
595 ok( hr == S_OK, "SafeArrayAccessData failed %x\n", hr );
596 if (SUCCEEDED(hr))
597 {
598 LONG i, lower, upper;
599
600 hr = SafeArrayGetLBound( V_ARRAY( &val ), 1, &lower );
601 ok( hr == S_OK, "SafeArrayGetLBound failed %x\n", hr );
602 hr = SafeArrayGetUBound( V_ARRAY( &val ), 1, &upper );
603 ok( hr == S_OK, "SafeArrayGetUBound failed %x\n", hr );
604 if (V_VT( &val ) == (VT_I4|VT_ARRAY))
605 {
606 for (i = 0; i < upper - lower + 1; i++)
607 trace( "chassis type: %u\n", data[i] );
608 }
609 hr = SafeArrayUnaccessData( V_ARRAY( &val ) );
610 ok( hr == S_OK, "SafeArrayUnaccessData failed %x\n", hr );
611 }
612 VariantClear( &val );
613
614 type = 0xdeadbeef;
615 VariantInit( &val );
616 hr = IWbemClassObject_Get( obj, descriptionW, 0, &val, &type, NULL );
617 ok( hr == S_OK, "failed to get description %08x\n", hr );
618 ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
619 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
620 trace( "description: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
621 VariantClear( &val );
622
623 type = 0xdeadbeef;
624 VariantInit( &val );
625 hr = IWbemClassObject_Get( obj, lockpresentW, 0, &val, &type, NULL );
626 ok( hr == S_OK, "failed to get lockpresent %08x\n", hr );
627 ok( V_VT( &val ) == VT_BOOL, "unexpected variant type 0x%x\n", V_VT( &val ) );
628 ok( type == CIM_BOOLEAN, "unexpected type 0x%x\n", type );
629 trace( "lockpresent: %u\n", V_BOOL( &val ) );
630 VariantClear( &val );
631
632 type = 0xdeadbeef;
633 VariantInit( &val );
634 hr = IWbemClassObject_Get( obj, manufacturerW, 0, &val, &type, NULL );
635 ok( hr == S_OK, "failed to get manufacturer %08x\n", hr );
636 ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
637 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
638 trace( "manufacturer: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
639 VariantClear( &val );
640
641 type = 0xdeadbeef;
642 VariantInit( &val );
643 hr = IWbemClassObject_Get( obj, nameW, 0, &val, &type, NULL );
644 ok( hr == S_OK, "failed to get name %08x\n", hr );
645 ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
646 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
647 trace( "name: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
648 VariantClear( &val );
649
650 type = 0xdeadbeef;
651 VariantInit( &val );
652 hr = IWbemClassObject_Get( obj, tagW, 0, &val, &type, NULL );
653 ok( hr == S_OK, "failed to get tag %08x\n", hr );
654 ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
655 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
656 trace( "tag: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
657 VariantClear( &val );
658
659 IWbemClassObject_Release( obj );
660 IEnumWbemClassObject_Release( result );
661 SysFreeString( query );
662 SysFreeString( wql );
663 }
664
665 static void test_StdRegProv( IWbemServices *services )
666 {
667 static const WCHAR enumkeyW[] = {'E','n','u','m','K','e','y',0};
668 static const WCHAR enumvaluesW[] = {'E','n','u','m','V','a','l','u','e','s',0};
669 static const WCHAR getstringvalueW[] = {'G','e','t','S','t','r','i','n','g','V','a','l','u','e',0};
670 static const WCHAR stdregprovW[] = {'S','t','d','R','e','g','P','r','o','v',0};
671 static const WCHAR defkeyW[] = {'h','D','e','f','K','e','y',0};
672 static const WCHAR subkeynameW[] = {'s','S','u','b','K','e','y','N','a','m','e',0};
673 static const WCHAR returnvalueW[] = {'R','e','t','u','r','n','V','a','l','u','e',0};
674 static const WCHAR namesW[] = {'s','N','a','m','e','s',0};
675 static const WCHAR typesW[] = {'T','y','p','e','s',0};
676 static const WCHAR valueW[] = {'s','V','a','l','u','e',0};
677 static const WCHAR valuenameW[] = {'s','V','a','l','u','e','N','a','m','e',0};
678 static const WCHAR programfilesW[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',0};
679 static const WCHAR windowsW[] =
680 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
681 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
682 BSTR class = SysAllocString( stdregprovW ), method;
683 IWbemClassObject *reg, *sig_in, *in, *out;
684 VARIANT defkey, subkey, retval, names, types, value, valuename;
685 CIMTYPE type;
686 HRESULT hr;
687
688 hr = IWbemServices_GetObject( services, class, 0, NULL, &reg, NULL );
689 if (hr != S_OK)
690 {
691 win_skip( "StdRegProv not available\n" );
692 return;
693 }
694 hr = IWbemClassObject_GetMethod( reg, enumkeyW, 0, &sig_in, NULL );
695 ok( hr == S_OK, "failed to get EnumKey method %08x\n", hr );
696
697 hr = IWbemClassObject_SpawnInstance( sig_in, 0, &in );
698 ok( hr == S_OK, "failed to spawn instance %08x\n", hr );
699
700 V_VT( &defkey ) = VT_I4;
701 V_I4( &defkey ) = 0x80000002;
702 hr = IWbemClassObject_Put( in, defkeyW, 0, &defkey, 0 );
703 ok( hr == S_OK, "failed to set root %08x\n", hr );
704
705 V_VT( &subkey ) = VT_BSTR;
706 V_BSTR( &subkey ) = SysAllocString( windowsW );
707 hr = IWbemClassObject_Put( in, subkeynameW, 0, &subkey, 0 );
708 ok( hr == S_OK, "failed to set subkey %08x\n", hr );
709
710 out = NULL;
711 method = SysAllocString( enumkeyW );
712 hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, in, &out, NULL );
713 ok( hr == S_OK, "failed to execute method %08x\n", hr );
714 SysFreeString( method );
715
716 type = 0xdeadbeef;
717 VariantInit( &retval );
718 hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, &type, NULL );
719 ok( hr == S_OK, "failed to get return value %08x\n", hr );
720 ok( V_VT( &retval ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &retval ) );
721 ok( !V_I4( &retval ), "unexpected error %u\n", V_UI4( &retval ) );
722 ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
723
724 type = 0xdeadbeef;
725 VariantInit( &names );
726 hr = IWbemClassObject_Get( out, namesW, 0, &names, &type, NULL );
727 ok( hr == S_OK, "failed to get names %08x\n", hr );
728 ok( V_VT( &names ) == (VT_BSTR|VT_ARRAY), "unexpected variant type 0x%x\n", V_VT( &names ) );
729 ok( type == (CIM_STRING|CIM_FLAG_ARRAY), "unexpected type 0x%x\n", type );
730
731 VariantClear( &names );
732 VariantClear( &subkey );
733 IWbemClassObject_Release( in );
734 IWbemClassObject_Release( out );
735 IWbemClassObject_Release( sig_in );
736
737 hr = IWbemClassObject_GetMethod( reg, enumvaluesW, 0, &sig_in, NULL );
738 ok( hr == S_OK, "failed to get EnumValues method %08x\n", hr );
739
740 hr = IWbemClassObject_SpawnInstance( sig_in, 0, &in );
741 ok( hr == S_OK, "failed to spawn instance %08x\n", hr );
742
743 V_VT( &defkey ) = VT_I4;
744 V_I4( &defkey ) = 0x80000002;
745 hr = IWbemClassObject_Put( in, defkeyW, 0, &defkey, 0 );
746 ok( hr == S_OK, "failed to set root %08x\n", hr );
747
748 V_VT( &subkey ) = VT_BSTR;
749 V_BSTR( &subkey ) = SysAllocString( windowsW );
750 hr = IWbemClassObject_Put( in, subkeynameW, 0, &subkey, 0 );
751 ok( hr == S_OK, "failed to set subkey %08x\n", hr );
752
753 out = NULL;
754 method = SysAllocString( enumvaluesW );
755 hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, in, &out, NULL );
756 ok( hr == S_OK, "failed to execute method %08x\n", hr );
757 SysFreeString( method );
758
759 type = 0xdeadbeef;
760 VariantInit( &retval );
761 hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, &type, NULL );
762 ok( hr == S_OK, "failed to get return value %08x\n", hr );
763 ok( V_VT( &retval ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &retval ) );
764 ok( !V_I4( &retval ), "unexpected error %u\n", V_I4( &retval ) );
765 ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
766
767 type = 0xdeadbeef;
768 VariantInit( &names );
769 hr = IWbemClassObject_Get( out, namesW, 0, &names, &type, NULL );
770 ok( hr == S_OK, "failed to get names %08x\n", hr );
771 ok( V_VT( &names ) == (VT_BSTR|VT_ARRAY), "unexpected variant type 0x%x\n", V_VT( &names ) );
772 ok( type == (CIM_STRING|CIM_FLAG_ARRAY), "unexpected type 0x%x\n", type );
773
774 type = 0xdeadbeef;
775 VariantInit( &types );
776 hr = IWbemClassObject_Get( out, typesW, 0, &types, &type, NULL );
777 ok( hr == S_OK, "failed to get names %08x\n", hr );
778 ok( V_VT( &types ) == (VT_I4|VT_ARRAY), "unexpected variant type 0x%x\n", V_VT( &types ) );
779 ok( type == (CIM_SINT32|CIM_FLAG_ARRAY), "unexpected type 0x%x\n", type );
780
781 VariantClear( &types );
782 VariantClear( &names );
783 VariantClear( &subkey );
784 IWbemClassObject_Release( in );
785 IWbemClassObject_Release( out );
786 IWbemClassObject_Release( sig_in );
787
788 hr = IWbemClassObject_GetMethod( reg, getstringvalueW, 0, &sig_in, NULL );
789 ok( hr == S_OK, "failed to get GetStringValue method %08x\n", hr );
790
791 hr = IWbemClassObject_SpawnInstance( sig_in, 0, &in );
792 ok( hr == S_OK, "failed to spawn instance %08x\n", hr );
793
794 V_VT( &defkey ) = VT_I4;
795 V_I4( &defkey ) = 0x80000002;
796 hr = IWbemClassObject_Put( in, defkeyW, 0, &defkey, 0 );
797 ok( hr == S_OK, "failed to set root %08x\n", hr );
798
799 V_VT( &subkey ) = VT_BSTR;
800 V_BSTR( &subkey ) = SysAllocString( windowsW );
801 hr = IWbemClassObject_Put( in, subkeynameW, 0, &subkey, 0 );
802 ok( hr == S_OK, "failed to set subkey %08x\n", hr );
803
804 V_VT( &valuename ) = VT_BSTR;
805 V_BSTR( &valuename ) = SysAllocString( programfilesW );
806 hr = IWbemClassObject_Put( in, valuenameW, 0, &valuename, 0 );
807 ok( hr == S_OK, "failed to set value name %08x\n", hr );
808
809 out = NULL;
810 method = SysAllocString( getstringvalueW );
811 hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, in, &out, NULL );
812 ok( hr == S_OK, "failed to execute method %08x\n", hr );
813 SysFreeString( method );
814
815 type = 0xdeadbeef;
816 VariantInit( &retval );
817 hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, &type, NULL );
818 ok( hr == S_OK, "failed to get return value %08x\n", hr );
819 ok( V_VT( &retval ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &retval ) );
820 ok( !V_I4( &retval ), "unexpected error %u\n", V_I4( &retval ) );
821 ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
822
823 type = 0xdeadbeef;
824 VariantInit( &value );
825 hr = IWbemClassObject_Get( out, valueW, 0, &value, &type, NULL );
826 ok( hr == S_OK, "failed to get value %08x\n", hr );
827 ok( V_VT( &value ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &value ) );
828 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
829
830 VariantClear( &value );
831 VariantClear( &valuename );
832 VariantClear( &subkey );
833 IWbemClassObject_Release( in );
834 IWbemClassObject_Release( out );
835 IWbemClassObject_Release( sig_in );
836
837 IWbemClassObject_Release( reg );
838 SysFreeString( class );
839 }
840
841 static HRESULT WINAPI sink_QueryInterface(
842 IWbemObjectSink *iface, REFIID riid, void **ppv )
843 {
844 *ppv = NULL;
845 if (IsEqualGUID( &IID_IUnknown, riid ) || IsEqualGUID( &IID_IWbemObjectSink, riid ))
846 {
847 *ppv = iface;
848 IWbemObjectSink_AddRef( iface );
849 return S_OK;
850 }
851 return E_NOINTERFACE;
852 }
853
854 static ULONG sink_refs;
855
856 static ULONG WINAPI sink_AddRef(
857 IWbemObjectSink *iface )
858 {
859 return ++sink_refs;
860 }
861
862 static ULONG WINAPI sink_Release(
863 IWbemObjectSink *iface )
864 {
865 return --sink_refs;
866 }
867
868 static HRESULT WINAPI sink_Indicate(
869 IWbemObjectSink *iface, LONG count, IWbemClassObject **objects )
870 {
871 trace("Indicate: %d, %p\n", count, objects);
872 return S_OK;
873 }
874
875 static HRESULT WINAPI sink_SetStatus(
876 IWbemObjectSink *iface, LONG flags, HRESULT hresult, BSTR str_param, IWbemClassObject *obj_param )
877 {
878 trace("SetStatus: %08x, %08x, %s, %p\n", flags, hresult, wine_dbgstr_w(str_param), obj_param);
879 return S_OK;
880 }
881
882 static IWbemObjectSinkVtbl sink_vtbl =
883 {
884 sink_QueryInterface,
885 sink_AddRef,
886 sink_Release,
887 sink_Indicate,
888 sink_SetStatus
889 };
890
891 static IWbemObjectSink sink = { &sink_vtbl };
892
893 static void test_notification_query_async( IWbemServices *services )
894 {
895 static const WCHAR queryW[] =
896 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
897 'D','e','v','i','c','e','C','h','a','n','g','e','E','v','e','n','t',0};
898 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
899 ULONG prev_sink_refs;
900 HRESULT hr;
901
902 hr = IWbemServices_ExecNotificationQueryAsync( services, wql, query, 0, NULL, NULL );
903 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
904
905 prev_sink_refs = sink_refs;
906 hr = IWbemServices_ExecNotificationQueryAsync( services, wql, query, 0, NULL, &sink );
907 ok( hr == S_OK || broken(hr == WBEM_E_NOT_FOUND), "got %08x\n", hr );
908 ok( sink_refs > prev_sink_refs || broken(!sink_refs), "got %u refs\n", sink_refs );
909
910 hr = IWbemServices_CancelAsyncCall( services, &sink );
911 ok( hr == S_OK || broken(hr == WBEM_E_NOT_FOUND), "got %08x\n", hr );
912
913 SysFreeString( wql );
914 SysFreeString( query );
915 }
916
917 static void test_query_async( IWbemServices *services )
918 {
919 static const WCHAR queryW[] =
920 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
921 'P','r','o','c','e','s','s',0};
922 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
923 HRESULT hr;
924
925 hr = IWbemServices_ExecQueryAsync( services, wql, query, 0, NULL, NULL );
926 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
927
928 hr = IWbemServices_ExecQueryAsync( services, wql, query, 0, NULL, &sink );
929 ok( hr == S_OK || broken(hr == WBEM_E_NOT_FOUND), "got %08x\n", hr );
930
931 hr = IWbemServices_CancelAsyncCall( services, NULL );
932 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
933
934 hr = IWbemServices_CancelAsyncCall( services, &sink );
935 ok( hr == S_OK, "got %08x\n", hr );
936
937 SysFreeString( wql );
938 SysFreeString( query );
939 }
940
941 static void test_GetNames( IWbemServices *services )
942 {
943 static const WCHAR queryW[] =
944 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
945 'O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
946 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
947 IEnumWbemClassObject *result;
948 HRESULT hr;
949
950 hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
951 ok( hr == S_OK, "got %08x\n", hr );
952
953 for (;;)
954 {
955 IWbemClassObject *obj;
956 SAFEARRAY *names;
957 ULONG count;
958 VARIANT val;
959
960 IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
961 if (!count) break;
962
963 VariantInit( &val );
964 hr = IWbemClassObject_GetNames( obj, NULL, WBEM_FLAG_NONSYSTEM_ONLY, &val, &names );
965 ok( hr == S_OK, "got %08x\n", hr );
966
967 SafeArrayDestroy( names );
968 IWbemClassObject_Release( obj );
969 }
970 IEnumWbemClassObject_Release( result );
971 SysFreeString( query );
972 SysFreeString( wql );
973 }
974
975 static void test_SystemSecurity( IWbemServices *services )
976 {
977 static const WCHAR systemsecurityW[] = {'_','_','S','y','s','t','e','m','S','e','c','u','r','i','t','y',0};
978 static const WCHAR getsdW[] = {'G','e','t','S','D',0};
979 static const WCHAR returnvalueW[] = {'R','e','t','u','r','n','V','a','l','u','e',0};
980 static const WCHAR sdW[] = {'S','D',0};
981 BSTR class = SysAllocString( systemsecurityW ), method;
982 IWbemClassObject *reg, *out;
983 VARIANT retval, var_sd;
984 void *data;
985 SECURITY_DESCRIPTOR_RELATIVE *sd;
986 CIMTYPE type;
987 HRESULT hr;
988 BYTE sid_admin_buffer[SECURITY_MAX_SID_SIZE];
989 SID *sid_admin = (SID*)sid_admin_buffer;
990 DWORD sid_size;
991 BOOL ret;
992
993 hr = IWbemServices_GetObject( services, class, 0, NULL, &reg, NULL );
994 if (hr != S_OK)
995 {
996 win_skip( "__SystemSecurity not available\n" );
997 return;
998 }
999
1000 sid_size = sizeof(sid_admin_buffer);
1001 ret = CreateWellKnownSid( WinBuiltinAdministratorsSid, NULL, sid_admin, &sid_size );
1002 ok( ret, "CreateWellKnownSid failed\n" );
1003
1004 out = NULL;
1005 method = SysAllocString( getsdW );
1006 hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, NULL, &out, NULL );
1007 ok( hr == S_OK || hr == WBEM_E_ACCESS_DENIED, "failed to execute method %08x\n", hr );
1008 SysFreeString( method );
1009
1010 if (SUCCEEDED(hr))
1011 {
1012 type = 0xdeadbeef;
1013 VariantInit( &retval );
1014 hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, &type, NULL );
1015 ok( hr == S_OK, "failed to get return value %08x\n", hr );
1016 ok( V_VT( &retval ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &retval ) );
1017 ok( !V_I4( &retval ), "unexpected error %u\n", V_UI4( &retval ) );
1018 ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
1019
1020 type = 0xdeadbeef;
1021 VariantInit( &var_sd );
1022 hr = IWbemClassObject_Get( out, sdW, 0, &var_sd, &type, NULL );
1023 ok( hr == S_OK, "failed to get names %08x\n", hr );
1024 ok( V_VT( &var_sd ) == (VT_UI1|VT_ARRAY), "unexpected variant type 0x%x\n", V_VT( &var_sd ) );
1025 ok( type == (CIM_UINT8|CIM_FLAG_ARRAY), "unexpected type 0x%x\n", type );
1026
1027 hr = SafeArrayAccessData( V_ARRAY( &var_sd ), &data );
1028 ok( hr == S_OK, "SafeArrayAccessData failed %x\n", hr );
1029 if (SUCCEEDED(hr))
1030 {
1031 sd = data;
1032
1033 ok( (sd->Control & SE_SELF_RELATIVE) == SE_SELF_RELATIVE, "relative flag unset\n" );
1034 ok( sd->Owner != 0, "no owner SID\n");
1035 ok( sd->Group != 0, "no owner SID\n");
1036 ok( EqualSid( (PSID)((LPBYTE)sd + sd->Owner), sid_admin ), "unexpected owner SID\n" );
1037 ok( EqualSid( (PSID)((LPBYTE)sd + sd->Group), sid_admin ), "unexpected group SID\n" );
1038
1039 hr = SafeArrayUnaccessData( V_ARRAY( &var_sd ) );
1040 ok( hr == S_OK, "SafeArrayUnaccessData failed %x\n", hr );
1041 }
1042
1043 VariantClear( &var_sd );
1044 IWbemClassObject_Release( out );
1045 }
1046 else if (hr == WBEM_E_ACCESS_DENIED)
1047 win_skip( "insufficient privs to test __SystemSecurity\n" );
1048
1049 SysFreeString( class );
1050 }
1051
1052 static void test_OperatingSystem( IWbemServices *services )
1053 {
1054 static const WCHAR queryW[] =
1055 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
1056 'O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
1057 static const WCHAR buildnumberW[] = {'B','u','i','l','d','N','u','m','b','e','r',0};
1058 static const WCHAR captionW[] = {'C','a','p','t','i','o','n',0};
1059 static const WCHAR csdversionW[] = {'C','S','D','V','e','r','s','i','o','n',0};
1060 static const WCHAR nameW[] = {'N','a','m','e',0};
1061 static const WCHAR osproductsuiteW[] = {'O','S','P','r','o','d','u','c','t','S','u','i','t','e',0};
1062 static const WCHAR ostypeW[] = {'O','S','T','y','p','e',0};
1063 static const WCHAR suitemaskW[] = {'S','u','i','t','e','M','a','s','k',0};
1064 static const WCHAR versionW[] = {'V','e','r','s','i','o','n',0};
1065 static const WCHAR servicepackmajorW[] =
1066 {'S','e','r','v','i','c','e','P','a','c','k','M','a','j','o','r','V','e','r','s','i','o','n',0};
1067 static const WCHAR servicepackminorW[] =
1068 {'S','e','r','v','i','c','e','P','a','c','k','M','i','n','o','r','V','e','r','s','i','o','n',0};
1069 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
1070 IEnumWbemClassObject *result;
1071 IWbemClassObject *obj;
1072 CIMTYPE type;
1073 ULONG count;
1074 VARIANT val;
1075 HRESULT hr;
1076
1077 hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
1078 ok( hr == S_OK, "IWbemServices_ExecQuery failed %08x\n", hr );
1079
1080 hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
1081 ok( hr == S_OK, "IEnumWbemClassObject_Next failed %08x\n", hr );
1082
1083 type = 0xdeadbeef;
1084 VariantInit( &val );
1085 hr = IWbemClassObject_Get( obj, buildnumberW, 0, &val, &type, NULL );
1086 ok( hr == S_OK, "failed to get buildnumber %08x\n", hr );
1087 ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1088 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1089 trace( "buildnumber: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1090 VariantClear( &val );
1091
1092 type = 0xdeadbeef;
1093 VariantInit( &val );
1094 hr = IWbemClassObject_Get( obj, captionW, 0, &val, &type, NULL );
1095 ok( hr == S_OK, "failed to get caption %08x\n", hr );
1096 ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1097 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1098 trace( "caption: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1099 VariantClear( &val );
1100
1101 type = 0xdeadbeef;
1102 VariantInit( &val );
1103 hr = IWbemClassObject_Get( obj, csdversionW, 0, &val, &type, NULL );
1104 ok( hr == S_OK, "failed to get csdversion %08x\n", hr );
1105 ok( V_VT( &val ) == VT_BSTR || V_VT( &val ) == VT_NULL, "unexpected variant type 0x%x\n", V_VT( &val ) );
1106 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1107 trace( "csdversion: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1108 VariantClear( &val );
1109
1110 type = 0xdeadbeef;
1111 VariantInit( &val );
1112 hr = IWbemClassObject_Get( obj, nameW, 0, &val, &type, NULL );
1113 ok( hr == S_OK, "failed to get name %08x\n", hr );
1114 ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1115 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1116 trace( "name: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1117 VariantClear( &val );
1118
1119 type = 0xdeadbeef;
1120 VariantInit( &val );
1121 hr = IWbemClassObject_Get( obj, osproductsuiteW, 0, &val, &type, NULL );
1122 ok( hr == S_OK, "failed to get osproductsuite %08x\n", hr );
1123 ok( V_VT( &val ) == VT_I4 || broken(V_VT( &val ) == VT_NULL) /* winxp */, "unexpected variant type 0x%x\n", V_VT( &val ) );
1124 ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
1125 trace( "osproductsuite: %d (%08x)\n", V_I4( &val ), V_I4( &val ) );
1126 VariantClear( &val );
1127
1128 type = 0xdeadbeef;
1129 VariantInit( &val );
1130 hr = IWbemClassObject_Get( obj, ostypeW, 0, &val, &type, NULL );
1131 ok( hr == S_OK, "failed to get ostype %08x\n", hr );
1132 ok( V_VT( &val ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &val ) );
1133 ok( type == CIM_UINT16, "unexpected type 0x%x\n", type );
1134 trace( "ostype: %d\n", V_I4( &val ) );
1135 VariantClear( &val );
1136
1137 type = 0xdeadbeef;
1138 VariantInit( &val );
1139 hr = IWbemClassObject_Get( obj, servicepackmajorW, 0, &val, &type, NULL );
1140 ok( hr == S_OK, "failed to get servicepackmajor %08x\n", hr );
1141 ok( V_VT( &val ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &val ) );
1142 ok( type == CIM_UINT16, "unexpected type 0x%x\n", type );
1143 trace( "servicepackmajor: %d\n", V_I4( &val ) );
1144 VariantClear( &val );
1145
1146 type = 0xdeadbeef;
1147 VariantInit( &val );
1148 hr = IWbemClassObject_Get( obj, servicepackminorW, 0, &val, &type, NULL );
1149 ok( hr == S_OK, "failed to get servicepackminor %08x\n", hr );
1150 ok( V_VT( &val ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &val ) );
1151 ok( type == CIM_UINT16, "unexpected type 0x%x\n", type );
1152 trace( "servicepackminor: %d\n", V_I4( &val ) );
1153 VariantClear( &val );
1154
1155 type = 0xdeadbeef;
1156 VariantInit( &val );
1157 hr = IWbemClassObject_Get( obj, suitemaskW, 0, &val, &type, NULL );
1158 ok( hr == S_OK, "failed to get suitemask %08x\n", hr );
1159 ok( V_VT( &val ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &val ) );
1160 ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
1161 trace( "suitemask: %d (%08x)\n", V_I4( &val ), V_I4( &val ) );
1162 VariantClear( &val );
1163
1164 type = 0xdeadbeef;
1165 VariantInit( &val );
1166 hr = IWbemClassObject_Get( obj, versionW, 0, &val, &type, NULL );
1167 ok( hr == S_OK, "failed to get version %08x\n", hr );
1168 ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1169 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1170 trace( "version: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1171 VariantClear( &val );
1172
1173 IWbemClassObject_Release( obj );
1174 IEnumWbemClassObject_Release( result );
1175 SysFreeString( query );
1176 SysFreeString( wql );
1177 }
1178
1179 static void test_ComputerSystemProduct( IWbemServices *services )
1180 {
1181 static const WCHAR uuidW[] = {'U','U','I','D',0};
1182 static const WCHAR queryW[] =
1183 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
1184 'C','o','m','p','u','t','e','r','S','y','s','t','e','m','P','r','o','d','u','c','t',0};
1185 BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
1186 IEnumWbemClassObject *result;
1187 IWbemClassObject *service;
1188 VARIANT value;
1189 CIMTYPE type;
1190 HRESULT hr;
1191 DWORD count;
1192
1193 hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
1194 if (hr != S_OK)
1195 {
1196 win_skip( "Win32_ComputerSystemProduct not available\n" );
1197 return;
1198 }
1199
1200 hr = IEnumWbemClassObject_Next( result, 10000, 1, &service, &count );
1201 ok( hr == S_OK, "got %08x\n", hr );
1202
1203 type = 0xdeadbeef;
1204 VariantInit( &value );
1205 hr = IWbemClassObject_Get( service, uuidW, 0, &value, &type, NULL );
1206 ok( hr == S_OK, "failed to get computer name %08x\n", hr );
1207 ok( V_VT( &value ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &value ) );
1208 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1209 trace( "uuid %s\n", wine_dbgstr_w(V_BSTR(&value)) );
1210 VariantClear( &value );
1211
1212 IWbemClassObject_Release( service );
1213 IEnumWbemClassObject_Release( result );
1214 SysFreeString( query );
1215 SysFreeString( wql );
1216 }
1217
1218 START_TEST(query)
1219 {
1220 static const WCHAR cimv2W[] = {'R','O','O','T','\\','C','I','M','V','2',0};
1221 BSTR path = SysAllocString( cimv2W );
1222 IWbemLocator *locator;
1223 IWbemServices *services;
1224 HRESULT hr;
1225
1226 CoInitialize( NULL );
1227 CoInitializeSecurity( NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT,
1228 RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL );
1229 hr = CoCreateInstance( &CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemLocator,
1230 (void **)&locator );
1231 if (hr != S_OK)
1232 {
1233 win_skip("can't create instance of WbemLocator\n");
1234 return;
1235 }
1236 hr = IWbemLocator_ConnectServer( locator, path, NULL, NULL, NULL, 0, NULL, NULL, &services );
1237 ok( hr == S_OK, "failed to get IWbemServices interface %08x\n", hr );
1238
1239 hr = CoSetProxyBlanket( (IUnknown *)services, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL,
1240 RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE );
1241 ok( hr == S_OK, "failed to set proxy blanket %08x\n", hr );
1242
1243 test_select( services );
1244 test_associators( services );
1245 test_Win32_Bios( services );
1246 test_Win32_Process( services );
1247 test_Win32_Service( services );
1248 test_Win32_ComputerSystem( services );
1249 test_Win32_SystemEnclosure( services );
1250 test_StdRegProv( services );
1251 test_notification_query_async( services );
1252 test_query_async( services );
1253 test_GetNames( services );
1254 test_SystemSecurity( services );
1255 test_OperatingSystem( services );
1256 test_ComputerSystemProduct( services );
1257
1258 SysFreeString( path );
1259 IWbemServices_Release( services );
1260 IWbemLocator_Release( locator );
1261 CoUninitialize();
1262 }