wmiutils: Implement IWbemPath::SetNamespaceAt.
[wine/multimedia.git] / dlls / wmiutils / tests / path.c
blob31246e9427fc94cb3e2350ce3e44beb9933f608e
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 <stdarg.h>
22 #include "windows.h"
23 #include "initguid.h"
24 #include "wmiutils.h"
25 #include "wbemcli.h"
26 #include "wine/test.h"
28 static const WCHAR path1[] = {0};
29 static const WCHAR path2[] = {'\\',0};
30 static const WCHAR path3[] = {'\\','\\','s','e','r','v','e','r',0};
31 static const WCHAR path4[] = {'\\','\\','s','e','r','v','e','r','\\',0};
32 static const WCHAR path5[] = {'\\','\\','.','\\',0};
33 static const WCHAR path6[] = {'/','/','.','/','r','o','o','t','/','c','i','m','v','2',0};
34 static const WCHAR path7[] =
35 {'/','/','.','/','r','o','o','t','/','c','i','m','v','2',':','W','i','n','3','2','_',
36 'O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
37 static const WCHAR path8[] =
38 {'/','r','o','o','t','/','c','i','m','v','2',':','W','i','n','3','2','_',
39 'O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
40 static const WCHAR path9[] =
41 {'\\','\\','.','\\','r','o','o','t','\\','c','i','m','v','2',':','W','i','n','3','2','_',
42 'O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
43 static const WCHAR path10[] =
44 {'/','\\','.','\\','r','o','o','t','\\','c','i','m','v','2',':','W','i','n','3','2','_',
45 'O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
46 static const WCHAR path11[] =
47 {'/','/','.','\\','r','o','o','t','\\','c','i','m','v','2',':','W','i','n','3','2','_',
48 'O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
49 static const WCHAR path12[] =
50 {'r','o','o','t','\\','c','i','m','v','2',':','W','i','n','3','2','_',
51 'O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
52 static const WCHAR path13[] =
53 {'\\','\\','.','\\','r','o','o','t','\\','c','i','m','v','2',0};
54 static const WCHAR path14[] =
55 {'W','i','n','3','2','_','O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
56 static const WCHAR path15[] =
57 {'r','o','o','t','\\','c','i','m','v','2',0};
58 static const WCHAR path16[] =
59 {'\\','\\','.','\\','r','o','o','t','\\','c','i','m','v','2',0};
60 static const WCHAR path17[] =
61 {'\\','\\','.','\\','r','o','o','t','\\','c','i','m','v','2',':','W','i','n','3','2','_',
62 'L','o','g','i','c','a','l','D','i','s','k','.','D','e','v','i','c','e','I','d','=','"','C',':','"',0};
64 static IWbemPath *create_path(void)
66 HRESULT hr;
67 IWbemPath *path;
69 hr = CoCreateInstance( &CLSID_WbemDefPath, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemPath, (void **)&path );
70 if (hr != S_OK)
72 win_skip( "can't create WbemDefPath instance, skipping tests\n" );
73 return NULL;
75 return path;
78 static void test_IWbemPath_SetText(void)
80 static const struct
82 const WCHAR *path;
83 ULONG mode;
84 HRESULT ret;
85 int todo;
86 } test[] =
88 { path1, 0, WBEM_E_INVALID_PARAMETER },
89 { path1, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
90 { path2, 0, WBEM_E_INVALID_PARAMETER },
91 { path2, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
92 { path3, 0, WBEM_E_INVALID_PARAMETER },
93 { path3, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
94 { path4, 0, WBEM_E_INVALID_PARAMETER },
95 { path4, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
96 { path5, 0, WBEM_E_INVALID_PARAMETER },
97 { path5, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
98 { path6, 0, WBEM_E_INVALID_PARAMETER },
99 { path6, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
100 { path7, 0, WBEM_E_INVALID_PARAMETER },
101 { path7, WBEMPATH_CREATE_ACCEPT_RELATIVE, S_OK },
102 { path7, WBEMPATH_CREATE_ACCEPT_ABSOLUTE, S_OK },
103 { path7, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
104 { path7, WBEMPATH_TREAT_SINGLE_IDENT_AS_NS, WBEM_E_INVALID_PARAMETER, 1 },
105 { path7, WBEMPATH_TREAT_SINGLE_IDENT_AS_NS + 1, S_OK },
106 { path8, WBEMPATH_CREATE_ACCEPT_RELATIVE, S_OK },
107 { path8, WBEMPATH_CREATE_ACCEPT_ABSOLUTE, WBEM_E_INVALID_PARAMETER, 1 },
108 { path8, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
109 { path8, WBEMPATH_TREAT_SINGLE_IDENT_AS_NS, WBEM_E_INVALID_PARAMETER, 1 },
110 { path8, WBEMPATH_TREAT_SINGLE_IDENT_AS_NS + 1, S_OK },
111 { path9, WBEMPATH_CREATE_ACCEPT_ABSOLUTE, S_OK },
112 { path10, WBEMPATH_CREATE_ACCEPT_ABSOLUTE, WBEM_E_INVALID_PARAMETER, 1 },
113 { path11, WBEMPATH_CREATE_ACCEPT_ABSOLUTE, S_OK }
115 IWbemPath *path;
116 HRESULT hr;
117 UINT i;
119 if (!(path = create_path())) return;
121 hr = IWbemPath_SetText( path, 0, NULL );
122 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
124 hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, NULL );
125 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
127 for (i = 0; i < sizeof(test)/sizeof(test[0]); i++)
129 hr = IWbemPath_SetText( path, test[i].mode, test[i].path );
130 if (test[i].todo) todo_wine ok( hr == test[i].ret, "%u got %08x\n", i, hr );
131 else ok( hr == test[i].ret, "%u got %08x\n", i, hr );
133 if (test[i].ret == S_OK)
135 WCHAR buf[128];
136 ULONG len;
138 memset( buf, 0x55, sizeof(buf) );
139 len = sizeof(buf)/sizeof(buf[0]);
140 hr = IWbemPath_GetText( path, WBEMPATH_GET_ORIGINAL, &len, buf );
141 ok( hr == S_OK, "%u got %08x\n", i, hr );
142 ok( !lstrcmpW( buf, test[i].path ), "%u unexpected path %s\n", i, wine_dbgstr_w(buf) );
143 ok( len == lstrlenW( test[i].path ) + 1, "%u unexpected length %u\n", i, len );
146 IWbemPath_Release( path );
149 static void test_IWbemPath_GetText(void)
151 WCHAR buf[128];
152 ULONG len, count;
153 IWbemPath *path;
154 HRESULT hr;
156 if (!(path = create_path())) return;
158 hr = IWbemPath_GetText( path, 0, NULL, NULL );
159 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
161 len = sizeof(buf)/sizeof(buf[0]);
162 hr = IWbemPath_GetText( path, 0, &len, NULL );
163 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
164 ok( len == sizeof(buf)/sizeof(buf[0]), "unexpected length %u\n", len );
166 len = sizeof(buf)/sizeof(buf[0]);
167 memset( buf, 0x55, sizeof(buf) );
168 hr = IWbemPath_GetText( path, 0, &len, buf );
169 ok( hr == S_OK, "got %08x\n", hr );
170 ok( !buf[0], "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
171 ok( len == 1, "unexpected length %u\n", len );
173 hr = IWbemPath_GetText( path, WBEMPATH_GET_ORIGINAL, NULL, NULL );
174 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
176 len = sizeof(buf)/sizeof(buf[0]);
177 hr = IWbemPath_GetText( path, WBEMPATH_GET_ORIGINAL, &len, NULL );
178 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
179 ok( len == sizeof(buf)/sizeof(buf[0]), "unexpected length %u\n", len );
181 len = sizeof(buf)/sizeof(buf[0]);
182 memset( buf, 0x55, sizeof(buf) );
183 hr = IWbemPath_GetText( path, WBEMPATH_GET_ORIGINAL, &len, buf );
184 ok( hr == S_OK, "got %08x\n", hr );
185 ok( !buf[0], "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
186 ok( len == 1, "unexpected length %u\n", len );
188 len = sizeof(buf)/sizeof(buf[0]);
189 memset( buf, 0x55, sizeof(buf) );
190 hr = IWbemPath_GetText( path, WBEMPATH_GET_SERVER_TOO, &len, buf );
191 ok( hr == S_OK, "got %08x\n", hr );
192 todo_wine ok( !buf[0], "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
193 todo_wine ok( len == 1, "unexpected length %u\n", len );
195 hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path8 );
196 ok( hr == S_OK, "got %08x\n", hr );
198 count = 0xdeadbeef;
199 hr = IWbemPath_GetNamespaceCount( path, &count );
200 ok( hr == S_OK, "got %08x\n", hr );
201 ok( count == 2, "got %u\n", count );
203 len = sizeof(buf)/sizeof(buf[0]);
204 memset( buf, 0x55, sizeof(buf) );
205 hr = IWbemPath_GetText( path, WBEMPATH_GET_SERVER_TOO, &len, buf );
206 ok( hr == S_OK, "got %08x\n", hr );
207 ok( !lstrcmpW( buf, path9 ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
208 ok( len == lstrlenW( path9 ) + 1, "unexpected length %u\n", len );
210 len = sizeof(buf)/sizeof(buf[0]);
211 memset( buf, 0x55, sizeof(buf) );
212 hr = IWbemPath_GetText( path, WBEMPATH_GET_SERVER_AND_NAMESPACE_ONLY, &len, buf );
213 ok( hr == S_OK, "got %08x\n", hr );
214 ok( !lstrcmpW( buf, path13 ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
215 ok( len == lstrlenW( path13 ) + 1, "unexpected length %u\n", len );
217 len = sizeof(buf)/sizeof(buf[0]);
218 memset( buf, 0x55, sizeof(buf) );
219 hr = IWbemPath_GetText( path, WBEMPATH_GET_RELATIVE_ONLY, &len, buf );
220 ok( hr == S_OK, "got %08x\n", hr );
221 ok( !lstrcmpW( buf, path14 ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
222 ok( len == lstrlenW( path14 ) + 1, "unexpected length %u\n", len );
224 len = sizeof(buf)/sizeof(buf[0]);
225 memset( buf, 0x55, sizeof(buf) );
226 hr = IWbemPath_GetText( path, WBEMPATH_GET_NAMESPACE_ONLY, &len, buf );
227 ok( hr == S_OK, "got %08x\n", hr );
228 ok( !lstrcmpW( buf, path15 ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
229 ok( len == lstrlenW( path15 ) + 1, "unexpected length %u\n", len );
231 len = sizeof(buf)/sizeof(buf[0]);
232 memset( buf, 0x55, sizeof(buf) );
233 hr = IWbemPath_GetText( path, 0, &len, buf );
234 ok( hr == S_OK, "got %08x\n", hr );
235 ok( !lstrcmpW( buf, path12 ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
236 ok( len == lstrlenW( path12 ) + 1, "unexpected length %u\n", len );
238 hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path1 );
239 ok( hr == S_OK, "got %08x\n", hr );
241 count = 0xdeadbeef;
242 hr = IWbemPath_GetNamespaceCount( path, &count );
243 ok( hr == S_OK, "got %08x\n", hr );
244 ok( !count, "got %u\n", count );
246 hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path6 );
247 ok( hr == S_OK, "got %08x\n", hr );
249 count = 0xdeadbeef;
250 hr = IWbemPath_GetNamespaceCount( path, &count );
251 ok( hr == S_OK, "got %08x\n", hr );
252 ok( count == 2, "got %u\n", count );
254 len = 0;
255 hr = IWbemPath_GetText( path, WBEMPATH_GET_SERVER_TOO, &len, NULL );
256 ok( hr == S_OK, "got %08x\n", hr );
257 ok( len == lstrlenW( path16 ) + 1, "unexpected length %u\n", len );
259 len = sizeof(buf)/sizeof(buf[0]);
260 memset( buf, 0x55, sizeof(buf) );
261 hr = IWbemPath_GetText( path, WBEMPATH_GET_SERVER_TOO, &len, buf );
262 ok( hr == S_OK, "got %08x\n", hr );
263 ok( !lstrcmpW( buf, path16 ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
264 ok( len == lstrlenW( path16 ) + 1, "unexpected length %u\n", len );
266 hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path17 );
267 ok( hr == S_OK, "got %08x\n", hr );
269 len = sizeof(buf)/sizeof(buf[0]);
270 memset( buf, 0x55, sizeof(buf) );
271 hr = IWbemPath_GetText( path, WBEMPATH_GET_SERVER_TOO, &len, buf );
272 ok( hr == S_OK, "got %08x\n", hr );
273 todo_wine ok( !lstrcmpW( buf, path17 ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
274 todo_wine ok( len == lstrlenW( path17 ) + 1, "unexpected length %u\n", len );
276 IWbemPath_Release( path );
279 static void test_IWbemPath_GetClassName(void)
281 static const WCHAR classW[] = {'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k',0};
282 IWbemPath *path;
283 HRESULT hr;
284 WCHAR buf[32];
285 ULONG len;
287 if (!(path = create_path())) return;
289 hr = IWbemPath_GetClassName( path, NULL, NULL );
290 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
292 len = 0;
293 hr = IWbemPath_GetClassName( path, &len, NULL );
294 ok( hr == WBEM_E_INVALID_OBJECT_PATH, "got %08x\n", hr );
296 len = sizeof(buf) / sizeof(buf[0]);
297 hr = IWbemPath_GetClassName( path, &len, buf );
298 ok( hr == WBEM_E_INVALID_OBJECT_PATH, "got %08x\n", hr );
300 len = sizeof(buf) / sizeof(buf[0]);
301 hr = IWbemPath_GetClassName( path, &len, NULL );
302 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
303 ok( len == sizeof(buf) / sizeof(buf[0]), "unexpected length %u\n", len );
305 hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path17 );
306 ok( hr == S_OK, "got %08x\n", hr );
308 len = 0;
309 hr = IWbemPath_GetClassName( path, &len, NULL );
310 ok( hr == S_OK, "got %08x\n", hr );
312 len = sizeof(buf) / sizeof(buf[0]);
313 hr = IWbemPath_GetClassName( path, &len, NULL );
314 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
315 ok( len == sizeof(buf) / sizeof(buf[0]), "unexpected length %u\n", len );
317 buf[0] = 0;
318 len = sizeof(buf) / sizeof(buf[0]);
319 hr = IWbemPath_GetClassName( path, &len, buf );
320 ok( hr == S_OK, "got %08x\n", hr );
321 ok( !lstrcmpW( buf, classW ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
322 ok( len == lstrlenW( classW ) + 1, "unexpected length %u\n", len );
324 IWbemPath_Release( path );
327 static void test_IWbemPath_SetClassName(void)
329 static const WCHAR classW[] = {'c','l','a','s','s',0};
330 static const WCHAR emptyW[] = {0};
331 IWbemPath *path;
332 WCHAR buf[16];
333 ULONG len;
334 ULONGLONG flags;
335 HRESULT hr;
337 if (!(path = create_path())) return;
339 hr = IWbemPath_SetClassName( path, NULL );
340 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
342 hr = IWbemPath_SetClassName( path, emptyW );
343 ok( hr == S_OK, "got %08x\n", hr );
345 hr = IWbemPath_SetClassName( path, classW );
346 ok( hr == S_OK, "got %08x\n", hr );
348 buf[0] = 0;
349 len = sizeof(buf) / sizeof(buf[0]);
350 hr = IWbemPath_GetClassName( path, &len, buf );
351 ok( hr == S_OK, "got %08x\n", hr );
352 ok( !lstrcmpW( buf, classW ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
354 flags = 0;
355 hr = IWbemPath_GetInfo( path, 0, &flags );
356 ok( hr == S_OK, "got %08x\n", hr );
357 ok( flags == (WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_IS_CLASS_REF |
358 WBEMPATH_INFO_HAS_SUBSCOPES | WBEMPATH_INFO_V2_COMPLIANT |
359 WBEMPATH_INFO_CIM_COMPLIANT),
360 "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags );
362 IWbemPath_Release( path );
365 static void test_IWbemPath_GetServer(void)
367 static const WCHAR dotW[] = {'.',0};
368 IWbemPath *path;
369 HRESULT hr;
370 WCHAR buf[32];
371 ULONG len;
373 if (!(path = create_path())) return;
375 hr = IWbemPath_GetServer( path, NULL, NULL );
376 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
378 len = 0;
379 hr = IWbemPath_GetServer( path, &len, NULL );
380 ok( hr == WBEM_E_NOT_AVAILABLE, "got %08x\n", hr );
382 len = sizeof(buf) / sizeof(buf[0]);
383 hr = IWbemPath_GetServer( path, &len, buf );
384 ok( hr == WBEM_E_NOT_AVAILABLE, "got %08x\n", hr );
386 len = sizeof(buf) / sizeof(buf[0]);
387 hr = IWbemPath_GetServer( path, &len, NULL );
388 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
389 ok( len == sizeof(buf) / sizeof(buf[0]), "unexpected length %u\n", len );
391 hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path17 );
392 ok( hr == S_OK, "got %08x\n", hr );
394 len = 0;
395 hr = IWbemPath_GetServer( path, &len, NULL );
396 ok( hr == S_OK, "got %08x\n", hr );
398 len = sizeof(buf) / sizeof(buf[0]);
399 hr = IWbemPath_GetServer( path, &len, NULL );
400 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
401 ok( len == sizeof(buf) / sizeof(buf[0]), "unexpected length %u\n", len );
403 buf[0] = 0;
404 len = sizeof(buf) / sizeof(buf[0]);
405 hr = IWbemPath_GetServer( path, &len, buf );
406 ok( hr == S_OK, "got %08x\n", hr );
407 ok( !lstrcmpW( buf, dotW ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
408 ok( len == lstrlenW( dotW ) + 1, "unexpected length %u\n", len );
410 IWbemPath_Release( path );
413 static void test_IWbemPath_GetInfo(void)
415 IWbemPath *path;
416 HRESULT hr;
417 ULONGLONG resp;
419 if (!(path = create_path())) return;
421 hr = IWbemPath_GetInfo( path, 0, NULL );
422 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
424 hr = IWbemPath_GetInfo( path, 1, NULL );
425 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
427 resp = 0xdeadbeef;
428 hr = IWbemPath_GetInfo( path, 0, &resp );
429 ok( hr == S_OK, "got %08x\n", hr );
430 ok( resp == (WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_SERVER_NAMESPACE_ONLY),
431 "got %lx%08lx\n", (unsigned long)(resp >> 32), (unsigned long)resp );
433 hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path17 );
434 ok( hr == S_OK, "got %08x\n", hr );
436 hr = IWbemPath_GetInfo( path, 0, NULL );
437 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
439 hr = IWbemPath_GetInfo( path, 1, NULL );
440 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
442 resp = 0xdeadbeef;
443 hr = IWbemPath_GetInfo( path, 0, &resp );
444 ok( hr == S_OK, "got %08x\n", hr );
445 ok( resp == (WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_IS_INST_REF |
446 WBEMPATH_INFO_HAS_SUBSCOPES | WBEMPATH_INFO_V2_COMPLIANT |
447 WBEMPATH_INFO_CIM_COMPLIANT | WBEMPATH_INFO_PATH_HAD_SERVER),
448 "got %lx%08lx\n", (unsigned long)(resp >> 32), (unsigned long)resp );
450 IWbemPath_Release( path );
451 if (!(path = create_path())) return;
453 hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path12 );
454 ok( hr == S_OK, "got %08x\n", hr );
456 resp = 0xdeadbeef;
457 hr = IWbemPath_GetInfo( path, 0, &resp );
458 ok( hr == S_OK, "got %08x\n", hr );
459 ok( resp == (WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_IS_CLASS_REF |
460 WBEMPATH_INFO_HAS_SUBSCOPES | WBEMPATH_INFO_V2_COMPLIANT |
461 WBEMPATH_INFO_CIM_COMPLIANT),
462 "got %lx%08lx\n", (unsigned long)(resp >> 32), (unsigned long)resp );
464 hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path1 );
465 ok( hr == S_OK, "got %08x\n", hr );
467 resp = 0xdeadbeef;
468 hr = IWbemPath_GetInfo( path, 0, &resp );
469 ok( hr == S_OK, "got %08x\n", hr );
470 ok( resp == (WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_SERVER_NAMESPACE_ONLY),
471 "got %lx%08lx\n", (unsigned long)(resp >> 32), (unsigned long)resp );
473 IWbemPath_Release( path );
476 static void test_IWbemPath_SetServer(void)
478 static const WCHAR serverW[] = {'s','e','r','v','e','r',0};
479 static const WCHAR emptyW[] = {0};
480 IWbemPath *path;
481 WCHAR buf[16];
482 ULONG len;
483 ULONGLONG flags;
484 HRESULT hr;
486 if (!(path = create_path())) return;
488 hr = IWbemPath_SetServer( path, NULL );
489 ok( hr == S_OK, "got %08x\n", hr );
491 len = sizeof(buf) / sizeof(buf[0]);
492 hr = IWbemPath_GetServer( path, &len, buf );
493 ok( hr == WBEM_E_NOT_AVAILABLE, "got %08x\n", hr );
495 hr = IWbemPath_SetServer( path, emptyW );
496 ok( hr == S_OK, "got %08x\n", hr );
498 hr = IWbemPath_SetServer( path, serverW );
499 ok( hr == S_OK, "got %08x\n", hr );
501 buf[0] = 0;
502 len = sizeof(buf) / sizeof(buf[0]);
503 hr = IWbemPath_GetServer( path, &len, buf );
504 ok( hr == S_OK, "got %08x\n", hr );
505 ok( !lstrcmpW( buf, serverW ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
507 flags = 0;
508 hr = IWbemPath_GetInfo( path, 0, &flags );
509 ok( hr == S_OK, "got %08x\n", hr );
510 ok( flags == (WBEMPATH_INFO_HAS_MACHINE_NAME | WBEMPATH_INFO_V1_COMPLIANT |
511 WBEMPATH_INFO_V2_COMPLIANT | WBEMPATH_INFO_CIM_COMPLIANT |
512 WBEMPATH_INFO_SERVER_NAMESPACE_ONLY | WBEMPATH_INFO_PATH_HAD_SERVER),
513 "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags );
515 hr = IWbemPath_SetServer( path, NULL );
516 ok( hr == S_OK, "got %08x\n", hr );
518 len = sizeof(buf) / sizeof(buf[0]);
519 hr = IWbemPath_GetServer( path, &len, buf );
520 ok( hr == WBEM_E_NOT_AVAILABLE, "got %08x\n", hr );
522 flags = 0;
523 hr = IWbemPath_GetInfo( path, 0, &flags );
524 ok( hr == S_OK, "got %08x\n", hr );
525 ok( flags == (WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_SERVER_NAMESPACE_ONLY),
526 "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags );
528 IWbemPath_Release( path );
531 static void test_IWbemPath_GetNamespaceAt(void)
533 static const WCHAR rootW[] = {'r','o','o','t',0};
534 static const WCHAR cimv2W[] = {'c','i','m','v','2',0};
535 IWbemPath *path;
536 HRESULT hr;
537 WCHAR buf[32];
538 ULONG len;
540 if (!(path = create_path())) return;
542 hr = IWbemPath_GetNamespaceAt( path, 0, NULL, NULL );
543 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
545 len = 0;
546 hr = IWbemPath_GetNamespaceAt( path, 0, &len, NULL );
547 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
549 len = sizeof(buf) / sizeof(buf[0]);
550 hr = IWbemPath_GetNamespaceAt( path, 0, &len, buf );
551 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
553 len = sizeof(buf) / sizeof(buf[0]);
554 hr = IWbemPath_GetNamespaceAt( path, 0, &len, NULL );
555 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
556 ok( len == sizeof(buf) / sizeof(buf[0]), "unexpected length %u\n", len );
558 hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path17 );
559 ok( hr == S_OK, "got %08x\n", hr );
561 len = 0;
562 hr = IWbemPath_GetNamespaceAt( path, 2, &len, NULL );
563 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
565 len = sizeof(buf) / sizeof(buf[0]);
566 hr = IWbemPath_GetNamespaceAt( path, 0, &len, NULL );
567 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
568 ok( len == sizeof(buf) / sizeof(buf[0]), "unexpected length %u\n", len );
570 buf[0] = 0;
571 len = sizeof(buf) / sizeof(buf[0]);
572 hr = IWbemPath_GetNamespaceAt( path, 0, &len, buf );
573 ok( hr == S_OK, "got %08x\n", hr );
574 ok( !lstrcmpW( buf, rootW ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
575 ok( len == lstrlenW( rootW ) + 1, "unexpected length %u\n", len );
577 buf[0] = 0;
578 len = sizeof(buf) / sizeof(buf[0]);
579 hr = IWbemPath_GetNamespaceAt( path, 1, &len, buf );
580 ok( hr == S_OK, "got %08x\n", hr );
581 ok( !lstrcmpW( buf, cimv2W ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
582 ok( len == lstrlenW( cimv2W ) + 1, "unexpected length %u\n", len );
584 IWbemPath_Release( path );
587 static void test_IWbemPath_RemoveAllNamespaces(void)
589 static const ULONGLONG expected_flags =
590 WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_IS_INST_REF |
591 WBEMPATH_INFO_HAS_SUBSCOPES | WBEMPATH_INFO_V2_COMPLIANT |
592 WBEMPATH_INFO_CIM_COMPLIANT | WBEMPATH_INFO_PATH_HAD_SERVER;
593 IWbemPath *path;
594 WCHAR buf[16];
595 ULONG len;
596 ULONGLONG flags;
597 HRESULT hr;
599 if (!(path = create_path())) return;
601 hr = IWbemPath_RemoveAllNamespaces( path );
602 ok( hr == S_OK, "got %08x\n", hr );
604 hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path17 );
605 ok( hr == S_OK, "got %08x\n", hr );
607 flags = 0;
608 hr = IWbemPath_GetInfo( path, 0, &flags );
609 ok( hr == S_OK, "got %08x\n", hr );
610 ok( flags == expected_flags,
611 "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags );
613 hr = IWbemPath_RemoveAllNamespaces( path );
614 ok( hr == S_OK, "got %08x\n", hr );
616 flags = 0;
617 hr = IWbemPath_GetInfo( path, 0, &flags );
618 ok( hr == S_OK, "got %08x\n", hr );
619 ok( flags == expected_flags,
620 "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags );
622 buf[0] = 0;
623 len = sizeof(buf) / sizeof(buf[0]);
624 hr = IWbemPath_GetNamespaceAt( path, 0, &len, buf );
625 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
627 IWbemPath_Release( path );
630 static void test_IWbemPath_RemoveNamespaceAt(void)
632 static const ULONGLONG expected_flags =
633 WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_IS_INST_REF |
634 WBEMPATH_INFO_HAS_SUBSCOPES | WBEMPATH_INFO_V2_COMPLIANT |
635 WBEMPATH_INFO_CIM_COMPLIANT | WBEMPATH_INFO_PATH_HAD_SERVER;
636 static const WCHAR cimv2W[] = {'c','i','m','v','2',0};
637 IWbemPath *path;
638 WCHAR buf[16];
639 ULONG len, count;
640 ULONGLONG flags;
641 HRESULT hr;
643 if (!(path = create_path())) return;
645 hr = IWbemPath_RemoveNamespaceAt( path, 0 );
646 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
648 hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path17 );
649 ok( hr == S_OK, "got %08x\n", hr );
651 flags = 0;
652 hr = IWbemPath_GetInfo( path, 0, &flags );
653 ok( hr == S_OK, "got %08x\n", hr );
654 ok( flags == expected_flags,
655 "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags );
657 count = 0xdeadbeef;
658 hr = IWbemPath_GetNamespaceCount( path, &count );
659 ok( hr == S_OK, "got %08x\n", hr );
660 ok( count == 2, "got %u\n", count );
662 hr = IWbemPath_RemoveNamespaceAt( path, 0 );
663 ok( hr == S_OK, "got %08x\n", hr );
665 flags = 0;
666 hr = IWbemPath_GetInfo( path, 0, &flags );
667 ok( hr == S_OK, "got %08x\n", hr );
668 ok( flags == expected_flags,
669 "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags );
671 count = 0xdeadbeef;
672 hr = IWbemPath_GetNamespaceCount( path, &count );
673 ok( hr == S_OK, "got %08x\n", hr );
674 ok( count == 1, "got %u\n", count );
676 buf[0] = 0;
677 len = sizeof(buf) / sizeof(buf[0]);
678 hr = IWbemPath_GetNamespaceAt( path, 0, &len, buf );
679 ok( hr == S_OK, "got %08x\n", hr );
680 ok( !lstrcmpW( buf, cimv2W ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
681 ok( len == lstrlenW( cimv2W ) + 1, "unexpected length %u\n", len );
683 hr = IWbemPath_RemoveNamespaceAt( path, 0 );
684 ok( hr == S_OK, "got %08x\n", hr );
686 flags = 0;
687 hr = IWbemPath_GetInfo( path, 0, &flags );
688 ok( hr == S_OK, "got %08x\n", hr );
689 ok( flags == expected_flags,
690 "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags );
692 count = 0xdeadbeef;
693 hr = IWbemPath_GetNamespaceCount( path, &count );
694 ok( hr == S_OK, "got %08x\n", hr );
695 ok( !count, "got %u\n", count );
697 buf[0] = 0;
698 len = sizeof(buf) / sizeof(buf[0]);
699 hr = IWbemPath_GetNamespaceAt( path, 0, &len, buf );
700 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
702 IWbemPath_Release( path );
705 static void test_IWbemPath_SetNamespaceAt(void)
707 static const ULONGLONG expected_flags =
708 WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_V1_COMPLIANT |
709 WBEMPATH_INFO_V2_COMPLIANT | WBEMPATH_INFO_CIM_COMPLIANT |
710 WBEMPATH_INFO_SERVER_NAMESPACE_ONLY;
711 static const WCHAR rootW[] = {'r','o','o','t',0};
712 static const WCHAR cimv2W[] = {'c','i','m','v','2',0};
713 IWbemPath *path;
714 WCHAR buf[16];
715 ULONG len, count;
716 ULONGLONG flags;
717 HRESULT hr;
719 if (!(path = create_path())) return;
721 hr = IWbemPath_SetNamespaceAt( path, 0, NULL );
722 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
724 hr = IWbemPath_SetNamespaceAt( path, 1, cimv2W );
725 ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
727 hr = IWbemPath_SetNamespaceAt( path, 0, cimv2W );
728 ok( hr == S_OK, "got %08x\n", hr );
730 count = 0xdeadbeef;
731 hr = IWbemPath_GetNamespaceCount( path, &count );
732 ok( hr == S_OK, "got %08x\n", hr );
733 ok( count == 1, "got %u\n", count );
735 flags = 0;
736 hr = IWbemPath_GetInfo( path, 0, &flags );
737 ok( hr == S_OK, "got %08x\n", hr );
738 ok( flags == expected_flags,
739 "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags );
741 buf[0] = 0;
742 len = sizeof(buf) / sizeof(buf[0]);
743 hr = IWbemPath_GetNamespaceAt( path, 0, &len, buf );
744 ok( hr == S_OK, "got %08x\n", hr );
745 ok( !lstrcmpW( buf, cimv2W ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
746 ok( len == lstrlenW( cimv2W ) + 1, "unexpected length %u\n", len );
748 hr = IWbemPath_SetNamespaceAt( path, 0, rootW );
749 ok( hr == S_OK, "got %08x\n", hr );
751 flags = 0;
752 hr = IWbemPath_GetInfo( path, 0, &flags );
753 ok( hr == S_OK, "got %08x\n", hr );
754 ok( flags == expected_flags,
755 "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags );
757 count = 0xdeadbeef;
758 hr = IWbemPath_GetNamespaceCount( path, &count );
759 ok( hr == S_OK, "got %08x\n", hr );
760 ok( count == 2, "got %u\n", count );
762 buf[0] = 0;
763 len = sizeof(buf) / sizeof(buf[0]);
764 hr = IWbemPath_GetNamespaceAt( path, 0, &len, buf );
765 ok( hr == S_OK, "got %08x\n", hr );
766 ok( !lstrcmpW( buf, rootW ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
767 ok( len == lstrlenW( rootW ) + 1, "unexpected length %u\n", len );
769 buf[0] = 0;
770 len = sizeof(buf) / sizeof(buf[0]);
771 hr = IWbemPath_GetNamespaceAt( path, 1, &len, buf );
772 ok( hr == S_OK, "got %08x\n", hr );
773 ok( !lstrcmpW( buf, cimv2W ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
774 ok( len == lstrlenW( cimv2W ) + 1, "unexpected length %u\n", len );
776 IWbemPath_Release( path );
779 START_TEST (path)
781 CoInitialize( NULL );
783 test_IWbemPath_SetText();
784 test_IWbemPath_GetText();
785 test_IWbemPath_GetClassName();
786 test_IWbemPath_SetClassName();
787 test_IWbemPath_GetServer();
788 test_IWbemPath_GetInfo();
789 test_IWbemPath_SetServer();
790 test_IWbemPath_GetNamespaceAt();
791 test_IWbemPath_RemoveAllNamespaces();
792 test_IWbemPath_RemoveNamespaceAt();
793 test_IWbemPath_SetNamespaceAt();
795 CoUninitialize();