wined3d: Don't use persistent BOs from the client thread if we might need to do verte...
[wine.git] / dlls / wbemprox / tests / services.c
blobe7fbc90cf61e458c5aada2db70d745eca464bf41
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 "objidl.h"
24 #include "wbemcli.h"
25 #include "wine/test.h"
27 #define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
28 static void _expect_ref(IUnknown* obj, ULONG ref, int line)
30 ULONG rc;
31 IUnknown_AddRef(obj);
32 rc = IUnknown_Release(obj);
33 ok_(__FILE__,line)(rc == ref, "expected refcount %lu, got %lu\n", ref, rc);
36 static void test_IClientSecurity(void)
38 HRESULT hr;
39 IWbemLocator *locator;
40 IWbemServices *services;
41 IClientSecurity *security;
42 BSTR path = SysAllocString( L"ROOT\\CIMV2" );
43 ULONG refs;
45 hr = CoCreateInstance( &CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemLocator, (void **)&locator );
46 if (hr != S_OK)
48 win_skip("can't create instance of WbemLocator\n");
49 return;
51 ok( hr == S_OK, "failed to create IWbemLocator interface %#lx\n", hr );
53 refs = IWbemLocator_Release( locator );
54 ok( refs == 0, "unexpected refcount %lu\n", refs );
56 hr = CoCreateInstance( &CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemLocator, (void **)&locator );
57 ok( hr == S_OK, "failed to create IWbemLocator interface %#lx\n", hr );
59 hr = IWbemLocator_ConnectServer( locator, path, NULL, NULL, NULL, 0, NULL, NULL, &services );
60 ok( hr == S_OK, "failed to get IWbemServices interface %#lx\n", hr );
62 refs = IWbemServices_Release( services );
63 ok( refs == 0, "unexpected refcount %lu\n", refs );
65 hr = IWbemLocator_ConnectServer( locator, path, NULL, NULL, NULL, 0, NULL, NULL, &services );
66 ok( hr == S_OK, "failed to get IWbemServices interface %#lx\n", hr );
68 hr = IWbemServices_QueryInterface( services, &IID_IClientSecurity, (void **)&security );
69 ok( hr == S_OK, "failed to query IClientSecurity interface %#lx\n", hr );
70 ok( (void *)services != (void *)security, "expected pointers to be different\n" );
72 refs = IClientSecurity_Release( security );
73 ok( refs == 1, "unexpected refcount %lu\n", refs );
75 refs = IWbemServices_Release( services );
76 ok( refs == 0, "unexpected refcount %lu\n", refs );
78 hr = IWbemLocator_ConnectServer( locator, path, NULL, NULL, NULL, 0, NULL, NULL, &services );
79 ok( hr == S_OK, "failed to get IWbemServices interface %#lx\n", hr );
81 hr = IWbemServices_QueryInterface( services, &IID_IClientSecurity, (void **)&security );
82 ok( hr == S_OK, "failed to query IClientSecurity interface %#lx\n", hr );
83 ok( (void *)services != (void *)security, "expected pointers to be different\n" );
85 refs = IWbemServices_Release( services );
86 todo_wine ok( refs == 1, "unexpected refcount %lu\n", refs );
88 refs = IClientSecurity_Release( security );
89 todo_wine ok( refs == 0, "unexpected refcount %lu\n", refs );
91 IWbemLocator_Release( locator );
92 SysFreeString( path );
95 static void test_IWbemLocator(void)
97 static const struct
99 const WCHAR *path;
100 HRESULT result;
101 BOOL todo;
102 HRESULT result_broken;
104 test[] =
106 { L"", WBEM_E_INVALID_NAMESPACE },
107 { L"\\", WBEM_E_INVALID_NAMESPACE },
108 { L"\\\\", WBEM_E_INVALID_NAMESPACE },
109 { L"\\\\.", WBEM_E_INVALID_NAMESPACE },
110 { L"\\\\.\\", WBEM_E_INVALID_NAMESPACE, FALSE, WBEM_E_INVALID_PARAMETER },
111 { L"\\ROOT", WBEM_E_INVALID_NAMESPACE },
112 { L"\\\\ROOT", __HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE), TRUE },
113 { L"\\\\.ROOT", __HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE), TRUE },
114 { L"\\\\.\\NONE", WBEM_E_INVALID_NAMESPACE },
115 { L"\\\\.\\ROOT", S_OK },
116 { L"\\\\\\.\\ROOT", WBEM_E_INVALID_PARAMETER },
117 { L"\\/.\\ROOT", S_OK, FALSE, WBEM_E_INVALID_PARAMETER },
118 { L"//.\\ROOT", S_OK },
119 { L"\\\\./ROOT", S_OK },
120 { L"//./ROOT", S_OK },
121 { L"NONE", WBEM_E_INVALID_NAMESPACE },
122 { L"ROOT", S_OK },
123 { L"ROOT\\NONE", WBEM_E_INVALID_NAMESPACE },
124 { L"ROOT\\CIMV2", S_OK },
125 { L"ROOT\\\\CIMV2", WBEM_E_INVALID_NAMESPACE, FALSE, WBEM_E_INVALID_PARAMETER },
126 { L"ROOT\\CIMV2\\", WBEM_E_INVALID_NAMESPACE, FALSE, WBEM_E_INVALID_PARAMETER },
127 { L"ROOT/CIMV2", S_OK },
128 { L"root\\default", S_OK },
129 { L"root\\cimv0", WBEM_E_INVALID_NAMESPACE },
130 { L"root\\cimv1", WBEM_E_INVALID_NAMESPACE },
131 { L"\\\\localhost\\ROOT", S_OK },
132 { L"\\\\LOCALHOST\\ROOT", S_OK }
134 IWbemLocator *locator;
135 IWbemServices *services;
136 IWbemContext *context;
137 unsigned int i;
138 HRESULT hr;
139 BSTR resource;
141 hr = CoCreateInstance( &CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemLocator, (void **)&locator );
142 if (hr != S_OK)
144 win_skip("can't create instance of WbemLocator\n");
145 return;
147 ok( hr == S_OK, "failed to create IWbemLocator interface %#lx\n", hr );
149 for (i = 0; i < ARRAY_SIZE( test ); i++)
151 resource = SysAllocString( test[i].path );
152 hr = IWbemLocator_ConnectServer( locator, resource, NULL, NULL, NULL, 0, NULL, NULL, &services );
153 todo_wine_if (test[i].todo)
154 ok( hr == test[i].result || broken(hr == test[i].result_broken),
155 "%u: expected %#lx got %#lx\n", i, test[i].result, hr );
156 SysFreeString( resource );
157 if (hr == S_OK) IWbemServices_Release( services );
160 hr = CoCreateInstance( &CLSID_WbemContext, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemContext, (void **)&context );
161 ok(hr == S_OK, "failed to create context object, hr %#lx\n", hr);
163 EXPECT_REF(context, 1);
164 resource = SysAllocString( L"root\\default" );
165 hr = IWbemLocator_ConnectServer( locator, resource, NULL, NULL, NULL, 0, NULL, context, &services );
166 ok(hr == S_OK, "failed to connect, hr %#lx\n", hr);
167 SysFreeString( resource );
168 EXPECT_REF(context, 1);
169 IWbemServices_Release( services );
170 IWbemContext_Release( context );
171 IWbemLocator_Release( locator );
174 static void test_IWbemContext(void)
176 IWbemContext *context;
177 VARIANT var;
178 HRESULT hr;
179 BSTR str;
181 hr = CoCreateInstance( &CLSID_WbemContext, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemContext, (void **)&context );
182 ok(hr == S_OK, "failed to create context object, hr %#lx\n", hr);
184 hr = IWbemContext_SetValue(context, L"name", 0, NULL);
185 ok(hr == WBEM_E_INVALID_PARAMETER, "unexpected hr %#lx\n", hr);
187 V_VT(&var) = VT_I4;
188 V_I4(&var) = 12;
189 hr = IWbemContext_SetValue(context, NULL, 0, &var);
190 ok(hr == WBEM_E_INVALID_PARAMETER, "unexpected hr %#lx\n", hr);
192 hr = IWbemContext_SetValue(context, L"name", 0, &var);
193 ok(hr == S_OK, "unexpected hr %#lx\n", hr);
195 hr = IWbemContext_GetValue(context, NULL, 0, &var);
196 ok(hr == WBEM_E_INVALID_PARAMETER, "unexpected hr %#lx\n", hr);
198 hr = IWbemContext_GetValue(context, L"name", 0, NULL);
199 ok(hr == WBEM_E_INVALID_PARAMETER, "unexpected hr %#lx\n", hr);
201 hr = IWbemContext_GetValue(context, L"noname", 0, &var);
202 ok(hr == WBEM_E_NOT_FOUND, "unexpected hr %#lx\n", hr);
204 V_VT(&var) = VT_EMPTY;
205 hr = IWbemContext_GetValue(context, L"NAME", 0, &var);
206 ok(hr == S_OK, "unexpected hr %#lx\n", hr);
207 ok(V_VT(&var) == VT_I4, "unexpected value type\n");
209 V_VT(&var) = VT_I4;
210 V_I4(&var) = 13;
211 hr = IWbemContext_SetValue(context, L"name2", 0, &var);
212 ok(hr == S_OK, "unexpected hr %#lx\n", hr);
214 hr = IWbemContext_Next(context, 0, &str, &var);
215 todo_wine
216 ok(hr == WBEM_E_UNEXPECTED, "unexpected hr %#lx\n", hr);
218 hr = IWbemContext_BeginEnumeration(context, 0);
219 todo_wine
220 ok(hr == S_OK, "unexpected hr %#lx\n", hr);
222 str = NULL;
223 hr = IWbemContext_Next(context, 0, &str, &var);
224 todo_wine {
225 ok(hr == S_OK, "unexpected hr %#lx\n", hr);
226 ok(!lstrcmpW(str, L"name"), "unexpected name %s\n", wine_dbgstr_w(str));
227 SysFreeString(str);
229 hr = IWbemContext_EndEnumeration(context);
230 todo_wine
231 ok(hr == S_OK, "unexpected hr %#lx\n", hr);
233 /* Overwrite */
234 V_VT(&var) = VT_I4;
235 V_I4(&var) = 14;
236 hr = IWbemContext_SetValue(context, L"name", 0, &var);
237 ok(hr == S_OK, "unexpected hr %#lx\n", hr);
239 V_VT(&var) = VT_EMPTY;
240 hr = IWbemContext_GetValue(context, L"name", 0, &var);
241 ok(hr == S_OK, "unexpected hr %#lx\n", hr);
242 ok(V_VT(&var) == VT_I4, "unexpected value type\n");
243 ok(V_I4(&var) == 14, "unexpected value\n");
245 IWbemContext_Release( context );
248 static void test_namespaces(void)
250 static const struct
252 const WCHAR *path;
253 BOOL broken;
255 tests[] =
257 {L"ROOT\\CIMV2"},
258 {L"ROOT\\Microsoft\\Windows\\Storage", TRUE /* Before Win8. */},
259 {L"ROOT\\WMI"},
261 IWbemLocator *locator;
262 IWbemServices *services;
263 unsigned int i;
264 BSTR resource;
265 HRESULT hr;
267 hr = CoCreateInstance( &CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemLocator, (void **)&locator );
268 if (hr != S_OK)
270 win_skip( "can't create instance of WbemLocator.\n" );
271 return;
274 for (i = 0; i < ARRAY_SIZE( tests ); i++)
276 resource = SysAllocString( tests[i].path );
277 hr = IWbemLocator_ConnectServer( locator, resource, NULL, NULL, NULL, 0, NULL, NULL, &services );
278 ok( hr == S_OK || broken( tests[i].broken && hr == WBEM_E_INVALID_NAMESPACE ), "%u: got %#lx\n", i, hr );
279 SysFreeString( resource );
280 if (hr == S_OK)
281 IWbemServices_Release( services );
284 IWbemLocator_Release( locator );
287 START_TEST(services)
289 CoInitialize( NULL );
290 test_IClientSecurity();
291 test_IWbemLocator();
292 test_IWbemContext();
293 test_namespaces();
294 CoUninitialize();