Release 1.5.29.
[wine] / dlls / wmiutils / tests / path.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 <stdarg.h>
22 #include "windows.h"
23 #include "initguid.h"
24 #include "wmiutils.h"
25 #include "wbemcli.h"
26 #include "wine/test.h"
27
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','=',
63      '"','C',':','"',0};
64 static const WCHAR path18[] =
65     {'\\','\\','.','\\','r','o','o','t','\\','c','i','m','v','2',':','W','i','n','3','2','_',
66      'L','o','g','i','c','a','l','D','i','s','k','.','D','e','v','i','c','e','I','d','=',
67      '"','C',':','"',',','D','r','i','v','e','T','y','p','e','=','3',0};
68 static const WCHAR path19[] =
69     {'\\','\\','.','\\','r','o','o','t','\\','c','i','m','v','2',':','W','i','n','3','2','_',
70      'L','o','g','i','c','a','l','D','i','s','k','.','D','e','v','i','c','e','I','d','=',0};
71 static const WCHAR path20[] =
72     {'\\','\\','.','\\','r','o','o','t','\\','c','i','m','v','2',':','W','i','n','3','2','_',
73      'L','o','g','i','c','a','l','D','i','s','k','.','D','e','v','i','c','e','I','d',' ','=',' ',
74      '"','C',':','"',0};
75
76 static IWbemPath *create_path(void)
77 {
78     HRESULT hr;
79     IWbemPath *path;
80
81     hr = CoCreateInstance( &CLSID_WbemDefPath, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemPath, (void **)&path );
82     if (hr != S_OK)
83     {
84         win_skip( "can't create WbemDefPath instance, skipping tests\n" );
85         return NULL;
86     }
87     return path;
88 }
89
90 static void test_IWbemPath_SetText(void)
91 {
92     static const struct
93     {
94         const WCHAR *path;
95         ULONG        mode;
96         HRESULT      ret;
97         int          todo;
98     } test[] =
99     {
100         { path1, 0, WBEM_E_INVALID_PARAMETER },
101         { path1, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
102         { path2, 0, WBEM_E_INVALID_PARAMETER },
103         { path2, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
104         { path3, 0, WBEM_E_INVALID_PARAMETER },
105         { path3, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
106         { path4, 0, WBEM_E_INVALID_PARAMETER },
107         { path4, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
108         { path5, 0, WBEM_E_INVALID_PARAMETER },
109         { path5, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
110         { path6, 0, WBEM_E_INVALID_PARAMETER },
111         { path6, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
112         { path7, 0, WBEM_E_INVALID_PARAMETER },
113         { path7, WBEMPATH_CREATE_ACCEPT_RELATIVE, S_OK },
114         { path7, WBEMPATH_CREATE_ACCEPT_ABSOLUTE, S_OK },
115         { path7, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
116         { path7, WBEMPATH_TREAT_SINGLE_IDENT_AS_NS, WBEM_E_INVALID_PARAMETER, 1 },
117         { path7, WBEMPATH_TREAT_SINGLE_IDENT_AS_NS + 1, S_OK },
118         { path8, WBEMPATH_CREATE_ACCEPT_RELATIVE, S_OK },
119         { path8, WBEMPATH_CREATE_ACCEPT_ABSOLUTE, WBEM_E_INVALID_PARAMETER, 1 },
120         { path8, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
121         { path8, WBEMPATH_TREAT_SINGLE_IDENT_AS_NS, WBEM_E_INVALID_PARAMETER, 1 },
122         { path8, WBEMPATH_TREAT_SINGLE_IDENT_AS_NS + 1, S_OK },
123         { path9, WBEMPATH_CREATE_ACCEPT_ABSOLUTE, S_OK },
124         { path10, WBEMPATH_CREATE_ACCEPT_ABSOLUTE, WBEM_E_INVALID_PARAMETER, 1 },
125         { path11, WBEMPATH_CREATE_ACCEPT_ABSOLUTE, S_OK }
126     };
127     IWbemPath *path;
128     HRESULT hr;
129     UINT i;
130
131     if (!(path = create_path())) return;
132
133     hr = IWbemPath_SetText( path, 0, NULL );
134     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
135
136     hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, NULL );
137     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
138
139     for (i = 0; i < sizeof(test)/sizeof(test[0]); i++)
140     {
141         hr = IWbemPath_SetText( path, test[i].mode, test[i].path );
142         if (test[i].todo) todo_wine ok( hr == test[i].ret, "%u got %08x\n", i, hr );
143         else ok( hr == test[i].ret, "%u got %08x\n", i, hr );
144
145         if (test[i].ret == S_OK)
146         {
147             WCHAR buf[128];
148             ULONG len;
149
150             memset( buf, 0x55, sizeof(buf) );
151             len = sizeof(buf)/sizeof(buf[0]);
152             hr = IWbemPath_GetText( path, WBEMPATH_GET_ORIGINAL, &len, buf );
153             ok( hr == S_OK, "%u got %08x\n", i, hr );
154             ok( !lstrcmpW( buf, test[i].path ), "%u unexpected path %s\n", i, wine_dbgstr_w(buf) );
155             ok( len == lstrlenW( test[i].path ) + 1, "%u unexpected length %u\n", i, len );
156         }
157     }
158     IWbemPath_Release( path );
159 }
160
161 static void test_IWbemPath_GetText(void)
162 {
163     static const WCHAR expected1W[] =
164         {'r','o','o','t','\\','c','i','m','v','2',':','W','i','n','3','2','_',
165          'L','o','g','i','c','a','l','D','i','s','k','.','D','e','v','i','c','e','I','d','=',
166          '"','C',':','"',0};
167     static const WCHAR expected2W[] =
168         {'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k','.',
169          'D','e','v','i','c','e','I','d','=','"','C',':','"',0};
170     WCHAR buf[128];
171     ULONG len, count;
172     IWbemPath *path;
173     HRESULT hr;
174
175     if (!(path = create_path())) return;
176
177     hr = IWbemPath_GetText( path, 0, NULL, NULL );
178     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
179
180     len = sizeof(buf)/sizeof(buf[0]);
181     hr = IWbemPath_GetText( path, 0, &len, NULL );
182     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
183     ok( len == sizeof(buf)/sizeof(buf[0]), "unexpected length %u\n", len );
184
185     len = sizeof(buf)/sizeof(buf[0]);
186     memset( buf, 0x55, sizeof(buf) );
187     hr = IWbemPath_GetText( path, 0, &len, buf );
188     ok( hr == S_OK, "got %08x\n", hr );
189     ok( !buf[0], "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
190     ok( len == 1, "unexpected length %u\n", len );
191
192     hr = IWbemPath_GetText( path, WBEMPATH_GET_ORIGINAL, NULL, NULL );
193     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
194
195     len = sizeof(buf)/sizeof(buf[0]);
196     hr = IWbemPath_GetText( path, WBEMPATH_GET_ORIGINAL, &len, NULL );
197     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
198     ok( len == sizeof(buf)/sizeof(buf[0]), "unexpected length %u\n", len );
199
200     len = sizeof(buf)/sizeof(buf[0]);
201     memset( buf, 0x55, sizeof(buf) );
202     hr = IWbemPath_GetText( path, WBEMPATH_GET_ORIGINAL, &len, buf );
203     ok( hr == S_OK, "got %08x\n", hr );
204     ok( !buf[0], "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
205     ok( len == 1, "unexpected length %u\n", len );
206
207     len = sizeof(buf)/sizeof(buf[0]);
208     memset( buf, 0x55, sizeof(buf) );
209     hr = IWbemPath_GetText( path, WBEMPATH_GET_SERVER_TOO, &len, buf );
210     ok( hr == S_OK, "got %08x\n", hr );
211     todo_wine ok( !buf[0], "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
212     todo_wine ok( len == 1, "unexpected length %u\n", len );
213
214     hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path8 );
215     ok( hr == S_OK, "got %08x\n", hr );
216
217     count = 0xdeadbeef;
218     hr = IWbemPath_GetNamespaceCount( path, &count );
219     ok( hr == S_OK, "got %08x\n", hr );
220     ok( count == 2, "got %u\n", count );
221
222     len = sizeof(buf)/sizeof(buf[0]);
223     memset( buf, 0x55, sizeof(buf) );
224     hr = IWbemPath_GetText( path, WBEMPATH_GET_SERVER_TOO, &len, buf );
225     ok( hr == S_OK, "got %08x\n", hr );
226     ok( !lstrcmpW( buf, path9 ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
227     ok( len == lstrlenW( path9 ) + 1, "unexpected length %u\n", len );
228
229     len = sizeof(buf)/sizeof(buf[0]);
230     memset( buf, 0x55, sizeof(buf) );
231     hr = IWbemPath_GetText( path, WBEMPATH_GET_SERVER_AND_NAMESPACE_ONLY, &len, buf );
232     ok( hr == S_OK, "got %08x\n", hr );
233     ok( !lstrcmpW( buf, path13 ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
234     ok( len == lstrlenW( path13 ) + 1, "unexpected length %u\n", len );
235
236     len = sizeof(buf)/sizeof(buf[0]);
237     memset( buf, 0x55, sizeof(buf) );
238     hr = IWbemPath_GetText( path, WBEMPATH_GET_RELATIVE_ONLY, &len, buf );
239     ok( hr == S_OK, "got %08x\n", hr );
240     ok( !lstrcmpW( buf, path14 ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
241     ok( len == lstrlenW( path14 ) + 1, "unexpected length %u\n", len );
242
243     len = sizeof(buf)/sizeof(buf[0]);
244     memset( buf, 0x55, sizeof(buf) );
245     hr = IWbemPath_GetText( path, WBEMPATH_GET_NAMESPACE_ONLY, &len, buf );
246     ok( hr == S_OK, "got %08x\n", hr );
247     ok( !lstrcmpW( buf, path15 ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
248     ok( len == lstrlenW( path15 ) + 1, "unexpected length %u\n", len );
249
250     len = sizeof(buf)/sizeof(buf[0]);
251     memset( buf, 0x55, sizeof(buf) );
252     hr = IWbemPath_GetText( path, 0, &len, buf );
253     ok( hr == S_OK, "got %08x\n", hr );
254     ok( !lstrcmpW( buf, path12 ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
255     ok( len == lstrlenW( path12 ) + 1, "unexpected length %u\n", len );
256
257     hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path1 );
258     ok( hr == S_OK, "got %08x\n", hr );
259
260     count = 0xdeadbeef;
261     hr = IWbemPath_GetNamespaceCount( path, &count );
262     ok( hr == S_OK, "got %08x\n", hr );
263     ok( !count, "got %u\n", count );
264
265     hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path6 );
266     ok( hr == S_OK, "got %08x\n", hr );
267
268     count = 0xdeadbeef;
269     hr = IWbemPath_GetNamespaceCount( path, &count );
270     ok( hr == S_OK, "got %08x\n", hr );
271     ok( count == 2, "got %u\n", count );
272
273     len = 0;
274     hr = IWbemPath_GetText( path, WBEMPATH_GET_SERVER_TOO, &len, NULL );
275     ok( hr == S_OK, "got %08x\n", hr );
276     ok( len == lstrlenW( path16 ) + 1, "unexpected length %u\n", len );
277
278     len = sizeof(buf)/sizeof(buf[0]);
279     memset( buf, 0x55, sizeof(buf) );
280     hr = IWbemPath_GetText( path, WBEMPATH_GET_SERVER_TOO, &len, buf );
281     ok( hr == S_OK, "got %08x\n", hr );
282     ok( !lstrcmpW( buf, path16 ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
283     ok( len == lstrlenW( path16 ) + 1, "unexpected length %u\n", len );
284
285     hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path17 );
286     ok( hr == S_OK, "got %08x\n", hr );
287
288     len = sizeof(buf)/sizeof(buf[0]);
289     memset( buf, 0x55, sizeof(buf) );
290     hr = IWbemPath_GetText( path, WBEMPATH_GET_SERVER_TOO, &len, buf );
291     ok( hr == S_OK, "got %08x\n", hr );
292     ok( !lstrcmpW( buf, path17 ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
293     ok( len == lstrlenW( path17 ) + 1, "unexpected length %u\n", len );
294
295     len = sizeof(buf)/sizeof(buf[0]);
296     memset( buf, 0x55, sizeof(buf) );
297     hr = IWbemPath_GetText( path, 0, &len, buf );
298     ok( hr == S_OK, "got %08x\n", hr );
299     ok( !lstrcmpW( buf, expected1W ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
300     ok( len == lstrlenW( expected1W ) + 1, "unexpected length %u\n", len );
301
302     len = sizeof(buf)/sizeof(buf[0]);
303     memset( buf, 0x55, sizeof(buf) );
304     hr = IWbemPath_GetText( path, WBEMPATH_GET_RELATIVE_ONLY, &len, buf );
305     ok( hr == S_OK, "got %08x\n", hr );
306     ok( !lstrcmpW( buf, expected2W ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
307     ok( len == lstrlenW( expected2W ) + 1, "unexpected length %u\n", len );
308
309     hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path18 );
310     ok( hr == S_OK, "got %08x\n", hr );
311
312     hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path19 );
313     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
314
315     hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path20 );
316     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
317
318     IWbemPath_Release( path );
319 }
320
321 static void test_IWbemPath_GetClassName(void)
322 {
323     static const WCHAR classW[] = {'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k',0};
324     IWbemPath *path;
325     HRESULT hr;
326     WCHAR buf[32];
327     ULONG len;
328
329     if (!(path = create_path())) return;
330
331     hr = IWbemPath_GetClassName( path, NULL, NULL );
332     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
333
334     len = 0;
335     hr = IWbemPath_GetClassName( path, &len, NULL );
336     ok( hr == WBEM_E_INVALID_OBJECT_PATH, "got %08x\n", hr );
337
338     len = sizeof(buf) / sizeof(buf[0]);
339     hr = IWbemPath_GetClassName( path, &len, buf );
340     ok( hr == WBEM_E_INVALID_OBJECT_PATH, "got %08x\n", hr );
341
342     len = sizeof(buf) / sizeof(buf[0]);
343     hr = IWbemPath_GetClassName( path, &len, NULL );
344     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
345     ok( len == sizeof(buf) / sizeof(buf[0]), "unexpected length %u\n", len );
346
347     hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path17 );
348     ok( hr == S_OK, "got %08x\n", hr );
349
350     len = 0;
351     hr = IWbemPath_GetClassName( path, &len, NULL );
352     ok( hr == S_OK, "got %08x\n", hr );
353
354     len = sizeof(buf) / sizeof(buf[0]);
355     hr = IWbemPath_GetClassName( path, &len, NULL );
356     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
357     ok( len == sizeof(buf) / sizeof(buf[0]), "unexpected length %u\n", len );
358
359     buf[0] = 0;
360     len = sizeof(buf) / sizeof(buf[0]);
361     hr = IWbemPath_GetClassName( path, &len, buf );
362     ok( hr == S_OK, "got %08x\n", hr );
363     ok( !lstrcmpW( buf, classW ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
364     ok( len == lstrlenW( classW ) + 1, "unexpected length %u\n", len );
365
366     IWbemPath_Release( path );
367 }
368
369 static void test_IWbemPath_SetClassName(void)
370 {
371     static const WCHAR classW[] = {'c','l','a','s','s',0};
372     static const WCHAR emptyW[] = {0};
373     IWbemPath *path;
374     WCHAR buf[16];
375     ULONG len;
376     ULONGLONG flags;
377     HRESULT hr;
378
379     if (!(path = create_path())) return;
380
381     hr = IWbemPath_SetClassName( path, NULL );
382     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
383
384     hr = IWbemPath_SetClassName( path, emptyW );
385     ok( hr == S_OK, "got %08x\n", hr );
386
387     hr = IWbemPath_SetClassName( path, classW );
388     ok( hr == S_OK, "got %08x\n", hr );
389
390     buf[0] = 0;
391     len = sizeof(buf) / sizeof(buf[0]);
392     hr = IWbemPath_GetClassName( path, &len, buf );
393     ok( hr == S_OK, "got %08x\n", hr );
394     ok( !lstrcmpW( buf, classW ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
395
396     flags = 0;
397     hr = IWbemPath_GetInfo( path, 0, &flags );
398     ok( hr == S_OK, "got %08x\n", hr );
399     ok( flags == (WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_IS_CLASS_REF |
400                   WBEMPATH_INFO_HAS_SUBSCOPES | WBEMPATH_INFO_V2_COMPLIANT |
401                   WBEMPATH_INFO_CIM_COMPLIANT),
402         "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags );
403
404     IWbemPath_Release( path );
405 }
406
407 static void test_IWbemPath_GetServer(void)
408 {
409     static const WCHAR dotW[] = {'.',0};
410     IWbemPath *path;
411     HRESULT hr;
412     WCHAR buf[32];
413     ULONG len;
414
415     if (!(path = create_path())) return;
416
417     hr = IWbemPath_GetServer( path, NULL, NULL );
418     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
419
420     len = 0;
421     hr = IWbemPath_GetServer( path, &len, NULL );
422     ok( hr == WBEM_E_NOT_AVAILABLE, "got %08x\n", hr );
423
424     len = sizeof(buf) / sizeof(buf[0]);
425     hr = IWbemPath_GetServer( path, &len, buf );
426     ok( hr == WBEM_E_NOT_AVAILABLE, "got %08x\n", hr );
427
428     len = sizeof(buf) / sizeof(buf[0]);
429     hr = IWbemPath_GetServer( path, &len, NULL );
430     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
431     ok( len == sizeof(buf) / sizeof(buf[0]), "unexpected length %u\n", len );
432
433     hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path17 );
434     ok( hr == S_OK, "got %08x\n", hr );
435
436     len = 0;
437     hr = IWbemPath_GetServer( path, &len, NULL );
438     ok( hr == S_OK, "got %08x\n", hr );
439
440     len = sizeof(buf) / sizeof(buf[0]);
441     hr = IWbemPath_GetServer( path, &len, NULL );
442     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
443     ok( len == sizeof(buf) / sizeof(buf[0]), "unexpected length %u\n", len );
444
445     buf[0] = 0;
446     len = sizeof(buf) / sizeof(buf[0]);
447     hr = IWbemPath_GetServer( path, &len, buf );
448     ok( hr == S_OK, "got %08x\n", hr );
449     ok( !lstrcmpW( buf, dotW ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
450     ok( len == lstrlenW( dotW ) + 1, "unexpected length %u\n", len );
451
452     IWbemPath_Release( path );
453 }
454
455 static void test_IWbemPath_GetInfo(void)
456 {
457     IWbemPath *path;
458     HRESULT hr;
459     ULONGLONG resp;
460
461     if (!(path = create_path())) return;
462
463     hr = IWbemPath_GetInfo( path, 0, NULL );
464     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
465
466     hr = IWbemPath_GetInfo( path, 1, NULL );
467     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
468
469     resp = 0xdeadbeef;
470     hr = IWbemPath_GetInfo( path, 0, &resp );
471     ok( hr == S_OK, "got %08x\n", hr );
472     ok( resp == (WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_SERVER_NAMESPACE_ONLY),
473         "got %lx%08lx\n", (unsigned long)(resp >> 32), (unsigned long)resp );
474
475     hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path17 );
476     ok( hr == S_OK, "got %08x\n", hr );
477
478     hr = IWbemPath_GetInfo( path, 0, NULL );
479     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
480
481     hr = IWbemPath_GetInfo( path, 1, NULL );
482     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
483
484     resp = 0xdeadbeef;
485     hr = IWbemPath_GetInfo( path, 0, &resp );
486     ok( hr == S_OK, "got %08x\n", hr );
487     ok( resp == (WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_IS_INST_REF |
488                  WBEMPATH_INFO_HAS_SUBSCOPES | WBEMPATH_INFO_V2_COMPLIANT |
489                  WBEMPATH_INFO_CIM_COMPLIANT | WBEMPATH_INFO_PATH_HAD_SERVER),
490         "got %lx%08lx\n", (unsigned long)(resp >> 32), (unsigned long)resp );
491
492     IWbemPath_Release( path );
493     if (!(path = create_path())) return;
494
495     hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path12 );
496     ok( hr == S_OK, "got %08x\n", hr );
497
498     resp = 0xdeadbeef;
499     hr = IWbemPath_GetInfo( path, 0, &resp );
500     ok( hr == S_OK, "got %08x\n", hr );
501     ok( resp == (WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_IS_CLASS_REF |
502                  WBEMPATH_INFO_HAS_SUBSCOPES | WBEMPATH_INFO_V2_COMPLIANT |
503                  WBEMPATH_INFO_CIM_COMPLIANT),
504         "got %lx%08lx\n", (unsigned long)(resp >> 32), (unsigned long)resp );
505
506     hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path1 );
507     ok( hr == S_OK, "got %08x\n", hr );
508
509     resp = 0xdeadbeef;
510     hr = IWbemPath_GetInfo( path, 0, &resp );
511     ok( hr == S_OK, "got %08x\n", hr );
512     ok( resp == (WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_SERVER_NAMESPACE_ONLY),
513         "got %lx%08lx\n", (unsigned long)(resp >> 32), (unsigned long)resp );
514
515     IWbemPath_Release( path );
516 }
517
518 static void test_IWbemPath_SetServer(void)
519 {
520     static const WCHAR serverW[] = {'s','e','r','v','e','r',0};
521     static const WCHAR emptyW[] = {0};
522     IWbemPath *path;
523     WCHAR buf[16];
524     ULONG len;
525     ULONGLONG flags;
526     HRESULT hr;
527
528     if (!(path = create_path())) return;
529
530     hr = IWbemPath_SetServer( path, NULL );
531     ok( hr == S_OK, "got %08x\n", hr );
532
533     len = sizeof(buf) / sizeof(buf[0]);
534     hr = IWbemPath_GetServer( path, &len, buf );
535     ok( hr == WBEM_E_NOT_AVAILABLE, "got %08x\n", hr );
536
537     hr = IWbemPath_SetServer( path, emptyW );
538     ok( hr == S_OK, "got %08x\n", hr );
539
540     hr = IWbemPath_SetServer( path, serverW );
541     ok( hr == S_OK, "got %08x\n", hr );
542
543     buf[0] = 0;
544     len = sizeof(buf) / sizeof(buf[0]);
545     hr = IWbemPath_GetServer( path, &len, buf );
546     ok( hr == S_OK, "got %08x\n", hr );
547     ok( !lstrcmpW( buf, serverW ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
548
549     flags = 0;
550     hr = IWbemPath_GetInfo( path, 0, &flags );
551     ok( hr == S_OK, "got %08x\n", hr );
552     ok( flags == (WBEMPATH_INFO_HAS_MACHINE_NAME | WBEMPATH_INFO_V1_COMPLIANT |
553                   WBEMPATH_INFO_V2_COMPLIANT | WBEMPATH_INFO_CIM_COMPLIANT |
554                   WBEMPATH_INFO_SERVER_NAMESPACE_ONLY | WBEMPATH_INFO_PATH_HAD_SERVER),
555         "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags );
556
557     hr = IWbemPath_SetServer( path, NULL );
558     ok( hr == S_OK, "got %08x\n", hr );
559
560     len = sizeof(buf) / sizeof(buf[0]);
561     hr = IWbemPath_GetServer( path, &len, buf );
562     ok( hr == WBEM_E_NOT_AVAILABLE, "got %08x\n", hr );
563
564     flags = 0;
565     hr = IWbemPath_GetInfo( path, 0, &flags );
566     ok( hr == S_OK, "got %08x\n", hr );
567     ok( flags == (WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_SERVER_NAMESPACE_ONLY),
568         "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags );
569
570     IWbemPath_Release( path );
571 }
572
573 static void test_IWbemPath_GetNamespaceAt(void)
574 {
575     static const WCHAR rootW[] = {'r','o','o','t',0};
576     static const WCHAR cimv2W[] = {'c','i','m','v','2',0};
577     IWbemPath *path;
578     HRESULT hr;
579     WCHAR buf[32];
580     ULONG len;
581
582     if (!(path = create_path())) return;
583
584     hr = IWbemPath_GetNamespaceAt( path, 0, NULL, NULL );
585     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
586
587     len = 0;
588     hr = IWbemPath_GetNamespaceAt( path, 0, &len, NULL );
589     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
590
591     len = sizeof(buf) / sizeof(buf[0]);
592     hr = IWbemPath_GetNamespaceAt( path, 0, &len, buf );
593     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
594
595     len = sizeof(buf) / sizeof(buf[0]);
596     hr = IWbemPath_GetNamespaceAt( path, 0, &len, NULL );
597     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
598     ok( len == sizeof(buf) / sizeof(buf[0]), "unexpected length %u\n", len );
599
600     hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path17 );
601     ok( hr == S_OK, "got %08x\n", hr );
602
603     len = 0;
604     hr = IWbemPath_GetNamespaceAt( path, 2, &len, NULL );
605     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
606
607     len = sizeof(buf) / sizeof(buf[0]);
608     hr = IWbemPath_GetNamespaceAt( path, 0, &len, NULL );
609     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
610     ok( len == sizeof(buf) / sizeof(buf[0]), "unexpected length %u\n", len );
611
612     buf[0] = 0;
613     len = sizeof(buf) / sizeof(buf[0]);
614     hr = IWbemPath_GetNamespaceAt( path, 0, &len, buf );
615     ok( hr == S_OK, "got %08x\n", hr );
616     ok( !lstrcmpW( buf, rootW ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
617     ok( len == lstrlenW( rootW ) + 1, "unexpected length %u\n", len );
618
619     buf[0] = 0;
620     len = sizeof(buf) / sizeof(buf[0]);
621     hr = IWbemPath_GetNamespaceAt( path, 1, &len, buf );
622     ok( hr == S_OK, "got %08x\n", hr );
623     ok( !lstrcmpW( buf, cimv2W ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
624     ok( len == lstrlenW( cimv2W ) + 1, "unexpected length %u\n", len );
625
626     IWbemPath_Release( path );
627 }
628
629 static void test_IWbemPath_RemoveAllNamespaces(void)
630 {
631     static const ULONGLONG expected_flags =
632         WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_IS_INST_REF |
633         WBEMPATH_INFO_HAS_SUBSCOPES | WBEMPATH_INFO_V2_COMPLIANT |
634         WBEMPATH_INFO_CIM_COMPLIANT | WBEMPATH_INFO_PATH_HAD_SERVER;
635     IWbemPath *path;
636     WCHAR buf[16];
637     ULONG len;
638     ULONGLONG flags;
639     HRESULT hr;
640
641     if (!(path = create_path())) return;
642
643     hr = IWbemPath_RemoveAllNamespaces( path );
644     ok( hr == S_OK, "got %08x\n", hr );
645
646     hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path17 );
647     ok( hr == S_OK, "got %08x\n", hr );
648
649     flags = 0;
650     hr = IWbemPath_GetInfo( path, 0, &flags );
651     ok( hr == S_OK, "got %08x\n", hr );
652     ok( flags == expected_flags,
653         "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags );
654
655     hr = IWbemPath_RemoveAllNamespaces( path );
656     ok( hr == S_OK, "got %08x\n", hr );
657
658     flags = 0;
659     hr = IWbemPath_GetInfo( path, 0, &flags );
660     ok( hr == S_OK, "got %08x\n", hr );
661     ok( flags == expected_flags,
662         "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags );
663
664     buf[0] = 0;
665     len = sizeof(buf) / sizeof(buf[0]);
666     hr = IWbemPath_GetNamespaceAt( path, 0, &len, buf );
667     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
668
669     IWbemPath_Release( path );
670 }
671
672 static void test_IWbemPath_RemoveNamespaceAt(void)
673 {
674     static const ULONGLONG expected_flags =
675         WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_IS_INST_REF |
676         WBEMPATH_INFO_HAS_SUBSCOPES | WBEMPATH_INFO_V2_COMPLIANT |
677         WBEMPATH_INFO_CIM_COMPLIANT | WBEMPATH_INFO_PATH_HAD_SERVER;
678     static const WCHAR cimv2W[] = {'c','i','m','v','2',0};
679     IWbemPath *path;
680     WCHAR buf[16];
681     ULONG len, count;
682     ULONGLONG flags;
683     HRESULT hr;
684
685     if (!(path = create_path())) return;
686
687     hr = IWbemPath_RemoveNamespaceAt( path, 0 );
688     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
689
690     hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path17 );
691     ok( hr == S_OK, "got %08x\n", hr );
692
693     flags = 0;
694     hr = IWbemPath_GetInfo( path, 0, &flags );
695     ok( hr == S_OK, "got %08x\n", hr );
696     ok( flags == expected_flags,
697         "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags );
698
699     count = 0xdeadbeef;
700     hr = IWbemPath_GetNamespaceCount( path, &count );
701     ok( hr == S_OK, "got %08x\n", hr );
702     ok( count == 2, "got %u\n", count );
703
704     hr = IWbemPath_RemoveNamespaceAt( path, 0 );
705     ok( hr == S_OK, "got %08x\n", hr );
706
707     flags = 0;
708     hr = IWbemPath_GetInfo( path, 0, &flags );
709     ok( hr == S_OK, "got %08x\n", hr );
710     ok( flags == expected_flags,
711         "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags );
712
713     count = 0xdeadbeef;
714     hr = IWbemPath_GetNamespaceCount( path, &count );
715     ok( hr == S_OK, "got %08x\n", hr );
716     ok( count == 1, "got %u\n", count );
717
718     buf[0] = 0;
719     len = sizeof(buf) / sizeof(buf[0]);
720     hr = IWbemPath_GetNamespaceAt( path, 0, &len, buf );
721     ok( hr == S_OK, "got %08x\n", hr );
722     ok( !lstrcmpW( buf, cimv2W ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
723     ok( len == lstrlenW( cimv2W ) + 1, "unexpected length %u\n", len );
724
725     hr = IWbemPath_RemoveNamespaceAt( path, 0 );
726     ok( hr == S_OK, "got %08x\n", hr );
727
728     flags = 0;
729     hr = IWbemPath_GetInfo( path, 0, &flags );
730     ok( hr == S_OK, "got %08x\n", hr );
731     ok( flags == expected_flags,
732         "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags );
733
734     count = 0xdeadbeef;
735     hr = IWbemPath_GetNamespaceCount( path, &count );
736     ok( hr == S_OK, "got %08x\n", hr );
737     ok( !count, "got %u\n", count );
738
739     buf[0] = 0;
740     len = sizeof(buf) / sizeof(buf[0]);
741     hr = IWbemPath_GetNamespaceAt( path, 0, &len, buf );
742     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
743
744     IWbemPath_Release( path );
745 }
746
747 static void test_IWbemPath_SetNamespaceAt(void)
748 {
749     static const ULONGLONG expected_flags =
750         WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_V1_COMPLIANT |
751         WBEMPATH_INFO_V2_COMPLIANT | WBEMPATH_INFO_CIM_COMPLIANT |
752         WBEMPATH_INFO_SERVER_NAMESPACE_ONLY;
753     static const WCHAR rootW[] = {'r','o','o','t',0};
754     static const WCHAR cimv2W[] = {'c','i','m','v','2',0};
755     IWbemPath *path;
756     WCHAR buf[16];
757     ULONG len, count;
758     ULONGLONG flags;
759     HRESULT hr;
760
761     if (!(path = create_path())) return;
762
763     hr = IWbemPath_SetNamespaceAt( path, 0, NULL );
764     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
765
766     hr = IWbemPath_SetNamespaceAt( path, 1, cimv2W );
767     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
768
769     hr = IWbemPath_SetNamespaceAt( path, 0, cimv2W );
770     ok( hr == S_OK, "got %08x\n", hr );
771
772     count = 0xdeadbeef;
773     hr = IWbemPath_GetNamespaceCount( path, &count );
774     ok( hr == S_OK, "got %08x\n", hr );
775     ok( count == 1, "got %u\n", count );
776
777     flags = 0;
778     hr = IWbemPath_GetInfo( path, 0, &flags );
779     ok( hr == S_OK, "got %08x\n", hr );
780     ok( flags == expected_flags,
781         "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags );
782
783     buf[0] = 0;
784     len = sizeof(buf) / sizeof(buf[0]);
785     hr = IWbemPath_GetNamespaceAt( path, 0, &len, buf );
786     ok( hr == S_OK, "got %08x\n", hr );
787     ok( !lstrcmpW( buf, cimv2W ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
788     ok( len == lstrlenW( cimv2W ) + 1, "unexpected length %u\n", len );
789
790     hr = IWbemPath_SetNamespaceAt( path, 0, rootW );
791     ok( hr == S_OK, "got %08x\n", hr );
792
793     flags = 0;
794     hr = IWbemPath_GetInfo( path, 0, &flags );
795     ok( hr == S_OK, "got %08x\n", hr );
796     ok( flags == expected_flags,
797         "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags );
798
799     count = 0xdeadbeef;
800     hr = IWbemPath_GetNamespaceCount( path, &count );
801     ok( hr == S_OK, "got %08x\n", hr );
802     ok( count == 2, "got %u\n", count );
803
804     buf[0] = 0;
805     len = sizeof(buf) / sizeof(buf[0]);
806     hr = IWbemPath_GetNamespaceAt( path, 0, &len, buf );
807     ok( hr == S_OK, "got %08x\n", hr );
808     ok( !lstrcmpW( buf, rootW ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
809     ok( len == lstrlenW( rootW ) + 1, "unexpected length %u\n", len );
810
811     buf[0] = 0;
812     len = sizeof(buf) / sizeof(buf[0]);
813     hr = IWbemPath_GetNamespaceAt( path, 1, &len, buf );
814     ok( hr == S_OK, "got %08x\n", hr );
815     ok( !lstrcmpW( buf, cimv2W ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
816     ok( len == lstrlenW( cimv2W ) + 1, "unexpected length %u\n", len );
817
818     IWbemPath_Release( path );
819 }
820
821 START_TEST (path)
822 {
823     CoInitialize( NULL );
824
825     test_IWbemPath_SetText();
826     test_IWbemPath_GetText();
827     test_IWbemPath_GetClassName();
828     test_IWbemPath_SetClassName();
829     test_IWbemPath_GetServer();
830     test_IWbemPath_GetInfo();
831     test_IWbemPath_SetServer();
832     test_IWbemPath_GetNamespaceAt();
833     test_IWbemPath_RemoveAllNamespaces();
834     test_IWbemPath_RemoveNamespaceAt();
835     test_IWbemPath_SetNamespaceAt();
836
837     CoUninitialize();
838 }