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 
test_IClientSecurity(void)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 
test_IWbemLocator(void)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 WCHAR path22W[] = {'r','o','o','t','\\','d','e','f','a','u','l','t',0};
112     static const WCHAR path23W[] = {'r','o','o','t','\\','c','i','m','v','0',0};
113     static const WCHAR path24W[] = {'r','o','o','t','\\','c','i','m','v','1',0};
114     static const WCHAR path25W[] = {'\\','\\','l','o','c','a','l','h','o','s','t','\\','R','O','O','T',0};
115     static const WCHAR path26W[] = {'\\','\\','L','O','C','A','L','H','O','S','T','\\','R','O','O','T',0};
116     static const struct
117     {
118         const WCHAR *path;
119         HRESULT      result;
120         BOOL         todo;
121         HRESULT      result_broken;
122     }
123     test[] =
124     {
125         { path0W, WBEM_E_INVALID_NAMESPACE },
126         { path1W, WBEM_E_INVALID_NAMESPACE },
127         { path2W, WBEM_E_INVALID_NAMESPACE },
128         { path3W, WBEM_E_INVALID_NAMESPACE },
129         { path4W, WBEM_E_INVALID_NAMESPACE, FALSE, WBEM_E_INVALID_PARAMETER },
130         { path5W, WBEM_E_INVALID_NAMESPACE },
131         { path6W, 0x800706ba, TRUE },
132         { path7W, 0x800706ba, TRUE },
133         { path8W, WBEM_E_INVALID_NAMESPACE },
134         { path9W, S_OK },
135         { path10W, WBEM_E_INVALID_PARAMETER },
136         { path11W, S_OK, FALSE, WBEM_E_INVALID_PARAMETER },
137         { path12W, S_OK },
138         { path13W, S_OK },
139         { path14W, S_OK },
140         { path15W, WBEM_E_INVALID_NAMESPACE },
141         { path16W, S_OK },
142         { path17W, WBEM_E_INVALID_NAMESPACE },
143         { path18W, S_OK },
144         { path19W, WBEM_E_INVALID_NAMESPACE, FALSE, WBEM_E_INVALID_PARAMETER },
145         { path20W, WBEM_E_INVALID_NAMESPACE, FALSE, WBEM_E_INVALID_PARAMETER },
146         { path21W, S_OK },
147         { path22W, S_OK },
148         { path23W, WBEM_E_INVALID_NAMESPACE },
149         { path24W, WBEM_E_INVALID_NAMESPACE },
150         { path25W, S_OK },
151         { path26W, S_OK }
152     };
153     IWbemLocator *locator;
154     IWbemServices *services;
155     unsigned int i;
156     HRESULT hr;
157     BSTR resource;
158 
159     hr = CoCreateInstance( &CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemLocator, (void **)&locator );
160     if (hr != S_OK)
161     {
162         win_skip("can't create instance of WbemLocator\n");
163         return;
164     }
165     ok( hr == S_OK, "failed to create IWbemLocator interface %08x\n", hr );
166 
167     for (i = 0; i < ARRAY_SIZE( test ); i++)
168     {
169         resource = SysAllocString( test[i].path );
170         hr = IWbemLocator_ConnectServer( locator, resource, NULL, NULL, NULL, 0, NULL, NULL, &services );
171         todo_wine_if (test[i].todo)
172             ok( hr == test[i].result || broken(hr == test[i].result_broken),
173                 "%u: expected %08x got %08x\n", i, test[i].result, hr );
174         SysFreeString( resource );
175         if (hr == S_OK) IWbemServices_Release( services );
176     }
177     IWbemLocator_Release( locator );
178 }
179 
START_TEST(services)180 START_TEST(services)
181 {
182     CoInitialize( NULL );
183     test_IClientSecurity();
184     test_IWbemLocator();
185     CoUninitialize();
186 }
187