wbemprox: Both signature parameters are optional in IWbemClassObject::GetMethod.
[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','=','"','C',':','"',0};
63
64 static void test_IWbemPath_SetText(void)
65 {
66     static const struct
67     {
68         const WCHAR *path;
69         ULONG        mode;
70         HRESULT      ret;
71         int          todo;
72     } test[] =
73     {
74         { path1, 0, WBEM_E_INVALID_PARAMETER },
75         { path1, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
76         { path2, 0, WBEM_E_INVALID_PARAMETER },
77         { path2, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
78         { path3, 0, WBEM_E_INVALID_PARAMETER },
79         { path3, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
80         { path4, 0, WBEM_E_INVALID_PARAMETER },
81         { path4, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
82         { path5, 0, WBEM_E_INVALID_PARAMETER },
83         { path5, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
84         { path6, 0, WBEM_E_INVALID_PARAMETER },
85         { path6, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
86         { path7, 0, WBEM_E_INVALID_PARAMETER },
87         { path7, WBEMPATH_CREATE_ACCEPT_RELATIVE, S_OK },
88         { path7, WBEMPATH_CREATE_ACCEPT_ABSOLUTE, S_OK },
89         { path7, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
90         { path7, WBEMPATH_TREAT_SINGLE_IDENT_AS_NS, WBEM_E_INVALID_PARAMETER, 1 },
91         { path7, WBEMPATH_TREAT_SINGLE_IDENT_AS_NS + 1, S_OK },
92         { path8, WBEMPATH_CREATE_ACCEPT_RELATIVE, S_OK },
93         { path8, WBEMPATH_CREATE_ACCEPT_ABSOLUTE, WBEM_E_INVALID_PARAMETER, 1 },
94         { path8, WBEMPATH_CREATE_ACCEPT_ALL, S_OK },
95         { path8, WBEMPATH_TREAT_SINGLE_IDENT_AS_NS, WBEM_E_INVALID_PARAMETER, 1 },
96         { path8, WBEMPATH_TREAT_SINGLE_IDENT_AS_NS + 1, S_OK },
97         { path9, WBEMPATH_CREATE_ACCEPT_ABSOLUTE, S_OK },
98         { path10, WBEMPATH_CREATE_ACCEPT_ABSOLUTE, WBEM_E_INVALID_PARAMETER, 1 },
99         { path11, WBEMPATH_CREATE_ACCEPT_ABSOLUTE, S_OK }
100     };
101     IWbemPath *path;
102     HRESULT hr;
103     UINT i;
104
105     CoInitialize( NULL );
106     hr = CoCreateInstance( &CLSID_WbemDefPath, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemPath, (void **)&path );
107     if (hr != S_OK)
108     {
109         win_skip( "can't create WbemDefPath instance, skipping tests\n" );
110         return;
111     }
112
113     hr = IWbemPath_SetText( path, 0, NULL );
114     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
115
116     hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, NULL );
117     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
118
119     for (i = 0; i < sizeof(test)/sizeof(test[0]); i++)
120     {
121         hr = IWbemPath_SetText( path, test[i].mode, test[i].path );
122         if (test[i].todo) todo_wine ok( hr == test[i].ret, "%u got %08x\n", i, hr );
123         else ok( hr == test[i].ret, "%u got %08x\n", i, hr );
124
125         if (test[i].ret == S_OK)
126         {
127             WCHAR buf[128];
128             ULONG len;
129
130             memset( buf, 0x55, sizeof(buf) );
131             len = sizeof(buf)/sizeof(buf[0]);
132             hr = IWbemPath_GetText( path, WBEMPATH_GET_ORIGINAL, &len, buf );
133             ok( hr == S_OK, "%u got %08x\n", i, hr );
134             ok( !lstrcmpW( buf, test[i].path ), "%u unexpected path %s\n", i, wine_dbgstr_w(buf) );
135             ok( len == lstrlenW( test[i].path ) + 1, "%u unexpected length %u\n", i, len );
136         }
137     }
138
139     IWbemPath_Release( path );
140     CoUninitialize();
141 }
142
143 static void test_IWbemPath_GetText(void)
144 {
145     IWbemPath *path;
146     WCHAR buf[128];
147     ULONG len, count;
148     HRESULT hr;
149
150     CoInitialize( NULL );
151     hr = CoCreateInstance( &CLSID_WbemDefPath, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemPath, (void **)&path );
152     if (hr != S_OK)
153     {
154         win_skip( "can't create WbemDefPath instance, skipping tests\n" );
155         return;
156     }
157
158     hr = IWbemPath_GetText( path, 0, NULL, NULL );
159     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
160
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 );
165
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 );
172
173     hr = IWbemPath_GetText( path, WBEMPATH_GET_ORIGINAL, NULL, NULL );
174     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
175
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 );
180
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 );
187
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 );
194
195     hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path8 );
196     ok( hr == S_OK, "got %08x\n", hr );
197
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 );
202
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 );
209
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 );
216
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 );
223
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 );
230
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 );
237
238     hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path1 );
239     ok( hr == S_OK, "got %08x\n", hr );
240
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 );
245
246     hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path6 );
247     ok( hr == S_OK, "got %08x\n", hr );
248
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 );
253
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 );
258
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 );
265
266     hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path17 );
267     ok( hr == S_OK, "got %08x\n", hr );
268
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 );
275
276     IWbemPath_Release( path );
277     CoUninitialize();
278 }
279
280 START_TEST (path)
281 {
282     test_IWbemPath_SetText();
283     test_IWbemPath_GetText();
284 }