Release 1.5.29.
[wine] / dlls / wbemprox / tests / services.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 "objidl.h"
24 #include "wbemcli.h"
25 #include "wine/test.h"
26
27 static void test_IClientSecurity(void)
28 {
29     static const WCHAR rootW[] = {'R','O','O','T','\\','C','I','M','V','2',0};
30     HRESULT hr;
31     IWbemLocator *locator;
32     IWbemServices *services;
33     IClientSecurity *security;
34     BSTR path = SysAllocString( rootW );
35     ULONG refs;
36
37     hr = CoCreateInstance( &CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemLocator, (void **)&locator );
38     if (hr != S_OK)
39     {
40         win_skip("can't create instance of WbemLocator\n");
41         return;
42     }
43     ok( hr == S_OK, "failed to create IWbemLocator interface %08x\n", hr );
44
45     refs = IWbemLocator_Release( locator );
46     ok( refs == 0, "unexpected refcount %u\n", refs );
47
48     hr = CoCreateInstance( &CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemLocator, (void **)&locator );
49     ok( hr == S_OK, "failed to create IWbemLocator interface %08x\n", hr );
50
51     hr = IWbemLocator_ConnectServer( locator, path, NULL, NULL, NULL, 0, NULL, NULL, &services );
52     ok( hr == S_OK, "failed to get IWbemServices interface %08x\n", hr );
53
54     refs = IWbemServices_Release( services );
55     ok( refs == 0, "unexpected refcount %u\n", refs );
56
57     hr = IWbemLocator_ConnectServer( locator, path, NULL, NULL, NULL, 0, NULL, NULL, &services );
58     ok( hr == S_OK, "failed to get IWbemServices interface %08x\n", hr );
59
60     hr = IWbemServices_QueryInterface( services, &IID_IClientSecurity, (void **)&security );
61     ok( hr == S_OK, "failed to query IClientSecurity interface %08x\n", hr );
62     ok( (void *)services != (void *)security, "expected pointers to be different\n" );
63
64     refs = IClientSecurity_Release( security );
65     ok( refs == 1, "unexpected refcount %u\n", refs );
66
67     refs = IWbemServices_Release( services );
68     ok( refs == 0, "unexpected refcount %u\n", refs );
69
70     hr = IWbemLocator_ConnectServer( locator, path, NULL, NULL, NULL, 0, NULL, NULL, &services );
71     ok( hr == S_OK, "failed to get IWbemServices interface %08x\n", hr );
72
73     hr = IWbemServices_QueryInterface( services, &IID_IClientSecurity, (void **)&security );
74     ok( hr == S_OK, "failed to query IClientSecurity interface %08x\n", hr );
75     ok( (void *)services != (void *)security, "expected pointers to be different\n" );
76
77     refs = IWbemServices_Release( services );
78     todo_wine ok( refs == 1, "unexpected refcount %u\n", refs );
79
80     refs = IClientSecurity_Release( security );
81     todo_wine ok( refs == 0, "unexpected refcount %u\n", refs );
82
83     IWbemLocator_Release( locator );
84     SysFreeString( path );
85 }
86
87 static void test_IWbemLocator(void)
88 {
89     static const WCHAR path0W[] = {0};
90     static const WCHAR path1W[] = {'\\',0};
91     static const WCHAR path2W[] = {'\\','\\',0};
92     static const WCHAR path3W[] = {'\\','\\','.',0};
93     static const WCHAR path4W[] = {'\\','\\','.','\\',0};
94     static const WCHAR path5W[] = {'\\','R','O','O','T',0};
95     static const WCHAR path6W[] = {'\\','\\','R','O','O','T',0};
96     static const WCHAR path7W[] = {'\\','\\','.','R','O','O','T',0};
97     static const WCHAR path8W[] = {'\\','\\','.','\\','N','O','N','E',0};
98     static const WCHAR path9W[] = {'\\','\\','.','\\','R','O','O','T',0};
99     static const WCHAR path10W[] = {'\\','\\','\\','.','\\','R','O','O','T',0};
100     static const WCHAR path11W[] = {'\\','/','.','\\','R','O','O','T',0};
101     static const WCHAR path12W[] = {'/','/','.','\\','R','O','O','T',0};
102     static const WCHAR path13W[] = {'\\','\\','.','/','R','O','O','T',0};
103     static const WCHAR path14W[] = {'/','/','.','/','R','O','O','T',0};
104     static const WCHAR path15W[] = {'N','O','N','E',0};
105     static const WCHAR path16W[] = {'R','O','O','T',0};
106     static const WCHAR path17W[] = {'R','O','O','T','\\','N','O','N','E',0};
107     static const WCHAR path18W[] = {'R','O','O','T','\\','C','I','M','V','2',0};
108     static const WCHAR path19W[] = {'R','O','O','T','\\','\\','C','I','M','V','2',0};
109     static const WCHAR path20W[] = {'R','O','O','T','\\','C','I','M','V','2','\\',0};
110     static const WCHAR path21W[] = {'R','O','O','T','/','C','I','M','V','2',0};
111     static const struct
112     {
113         const WCHAR *path;
114         HRESULT      result;
115         int          todo;
116         HRESULT      result_broken;
117     }
118     test[] =
119     {
120         { path0W, WBEM_E_INVALID_NAMESPACE },
121         { path1W, WBEM_E_INVALID_NAMESPACE },
122         { path2W, WBEM_E_INVALID_NAMESPACE },
123         { path3W, WBEM_E_INVALID_NAMESPACE },
124         { path4W, WBEM_E_INVALID_NAMESPACE, 0, WBEM_E_INVALID_PARAMETER },
125         { path5W, WBEM_E_INVALID_NAMESPACE },
126         { path6W, 0x800706ba, 1 },
127         { path7W, 0x800706ba, 1 },
128         { path8W, WBEM_E_INVALID_NAMESPACE },
129         { path9W, S_OK },
130         { path10W, WBEM_E_INVALID_PARAMETER },
131         { path11W, S_OK },
132         { path12W, S_OK },
133         { path13W, S_OK },
134         { path14W, S_OK },
135         { path15W, WBEM_E_INVALID_NAMESPACE },
136         { path16W, S_OK },
137         { path17W, WBEM_E_INVALID_NAMESPACE },
138         { path18W, S_OK },
139         { path19W, WBEM_E_INVALID_NAMESPACE },
140         { path20W, WBEM_E_INVALID_NAMESPACE },
141         { path21W, S_OK }
142     };
143     IWbemLocator *locator;
144     IWbemServices *services;
145     unsigned int i;
146     HRESULT hr;
147     BSTR resource;
148
149     hr = CoCreateInstance( &CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemLocator, (void **)&locator );
150     if (hr != S_OK)
151     {
152         win_skip("can't create instance of WbemLocator\n");
153         return;
154     }
155     ok( hr == S_OK, "failed to create IWbemLocator interface %08x\n", hr );
156
157     for (i = 0; i < sizeof(test) / sizeof(test[0]); i++)
158     {
159         resource = SysAllocString( test[i].path );
160         hr = IWbemLocator_ConnectServer( locator, resource, NULL, NULL, NULL, 0, NULL, NULL, &services );
161         if (test[i].todo) todo_wine
162             ok( hr == test[i].result || broken(hr == test[i].result_broken),
163                 "%u: expected %08x got %08x\n", i, test[i].result, hr );
164         else
165             ok( hr == test[i].result || broken(hr == test[i].result_broken),
166                 "%u: expected %08x got %08x\n", i, test[i].result, hr );
167         SysFreeString( resource );
168         if (hr == S_OK) IWbemServices_Release( services );
169     }
170     IWbemLocator_Release( locator );
171 }
172
173 START_TEST(services)
174 {
175     CoInitialize( NULL );
176     test_IClientSecurity();
177     test_IWbemLocator();
178     CoUninitialize();
179 }