2012-06-18 14:00:58 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Hans Leidekker for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "windows.h"
|
|
|
|
#include "objidl.h"
|
|
|
|
#include "wbemcli.h"
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2021-03-03 07:05:48 +01:00
|
|
|
#define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
|
|
|
|
static void _expect_ref(IUnknown* obj, ULONG ref, int line)
|
|
|
|
{
|
|
|
|
ULONG rc;
|
|
|
|
IUnknown_AddRef(obj);
|
|
|
|
rc = IUnknown_Release(obj);
|
|
|
|
ok_(__FILE__,line)(rc == ref, "expected refcount %d, got %d\n", ref, rc);
|
|
|
|
}
|
|
|
|
|
2012-06-18 14:00:58 +02:00
|
|
|
static void test_IClientSecurity(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IWbemLocator *locator;
|
|
|
|
IWbemServices *services;
|
|
|
|
IClientSecurity *security;
|
2020-02-25 11:39:53 +01:00
|
|
|
BSTR path = SysAllocString( L"ROOT\\CIMV2" );
|
2012-06-18 14:00:58 +02:00
|
|
|
ULONG refs;
|
|
|
|
|
|
|
|
hr = CoCreateInstance( &CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemLocator, (void **)&locator );
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
win_skip("can't create instance of WbemLocator\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok( hr == S_OK, "failed to create IWbemLocator interface %08x\n", hr );
|
|
|
|
|
|
|
|
refs = IWbemLocator_Release( locator );
|
|
|
|
ok( refs == 0, "unexpected refcount %u\n", refs );
|
|
|
|
|
|
|
|
hr = CoCreateInstance( &CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemLocator, (void **)&locator );
|
|
|
|
ok( hr == S_OK, "failed to create IWbemLocator interface %08x\n", hr );
|
|
|
|
|
|
|
|
hr = IWbemLocator_ConnectServer( locator, path, NULL, NULL, NULL, 0, NULL, NULL, &services );
|
|
|
|
ok( hr == S_OK, "failed to get IWbemServices interface %08x\n", hr );
|
|
|
|
|
|
|
|
refs = IWbemServices_Release( services );
|
|
|
|
ok( refs == 0, "unexpected refcount %u\n", refs );
|
|
|
|
|
|
|
|
hr = IWbemLocator_ConnectServer( locator, path, NULL, NULL, NULL, 0, NULL, NULL, &services );
|
|
|
|
ok( hr == S_OK, "failed to get IWbemServices interface %08x\n", hr );
|
|
|
|
|
|
|
|
hr = IWbemServices_QueryInterface( services, &IID_IClientSecurity, (void **)&security );
|
|
|
|
ok( hr == S_OK, "failed to query IClientSecurity interface %08x\n", hr );
|
|
|
|
ok( (void *)services != (void *)security, "expected pointers to be different\n" );
|
|
|
|
|
|
|
|
refs = IClientSecurity_Release( security );
|
|
|
|
ok( refs == 1, "unexpected refcount %u\n", refs );
|
|
|
|
|
|
|
|
refs = IWbemServices_Release( services );
|
|
|
|
ok( refs == 0, "unexpected refcount %u\n", refs );
|
|
|
|
|
|
|
|
hr = IWbemLocator_ConnectServer( locator, path, NULL, NULL, NULL, 0, NULL, NULL, &services );
|
|
|
|
ok( hr == S_OK, "failed to get IWbemServices interface %08x\n", hr );
|
|
|
|
|
|
|
|
hr = IWbemServices_QueryInterface( services, &IID_IClientSecurity, (void **)&security );
|
|
|
|
ok( hr == S_OK, "failed to query IClientSecurity interface %08x\n", hr );
|
|
|
|
ok( (void *)services != (void *)security, "expected pointers to be different\n" );
|
|
|
|
|
|
|
|
refs = IWbemServices_Release( services );
|
|
|
|
todo_wine ok( refs == 1, "unexpected refcount %u\n", refs );
|
|
|
|
|
2012-08-28 11:10:56 +02:00
|
|
|
refs = IClientSecurity_Release( security );
|
2012-06-18 14:00:58 +02:00
|
|
|
todo_wine ok( refs == 0, "unexpected refcount %u\n", refs );
|
|
|
|
|
|
|
|
IWbemLocator_Release( locator );
|
|
|
|
SysFreeString( path );
|
|
|
|
}
|
|
|
|
|
2012-06-25 11:20:21 +02:00
|
|
|
static void test_IWbemLocator(void)
|
|
|
|
{
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
const WCHAR *path;
|
|
|
|
HRESULT result;
|
2014-01-07 00:14:36 +01:00
|
|
|
BOOL todo;
|
2012-06-25 11:20:21 +02:00
|
|
|
HRESULT result_broken;
|
|
|
|
}
|
|
|
|
test[] =
|
|
|
|
{
|
2020-02-25 11:39:53 +01:00
|
|
|
{ L"", WBEM_E_INVALID_NAMESPACE },
|
|
|
|
{ L"\\", WBEM_E_INVALID_NAMESPACE },
|
|
|
|
{ L"\\\\", WBEM_E_INVALID_NAMESPACE },
|
|
|
|
{ L"\\\\.", WBEM_E_INVALID_NAMESPACE },
|
|
|
|
{ L"\\\\.\\", WBEM_E_INVALID_NAMESPACE, FALSE, WBEM_E_INVALID_PARAMETER },
|
|
|
|
{ L"\\ROOT", WBEM_E_INVALID_NAMESPACE },
|
2021-03-04 16:40:00 +01:00
|
|
|
{ L"\\\\ROOT", __HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE), TRUE },
|
|
|
|
{ L"\\\\.ROOT", __HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE), TRUE },
|
2020-02-25 11:39:53 +01:00
|
|
|
{ L"\\\\.\\NONE", WBEM_E_INVALID_NAMESPACE },
|
|
|
|
{ L"\\\\.\\ROOT", S_OK },
|
|
|
|
{ L"\\\\\\.\\ROOT", WBEM_E_INVALID_PARAMETER },
|
|
|
|
{ L"\\/.\\ROOT", S_OK, FALSE, WBEM_E_INVALID_PARAMETER },
|
|
|
|
{ L"//.\\ROOT", S_OK },
|
|
|
|
{ L"\\\\./ROOT", S_OK },
|
|
|
|
{ L"//./ROOT", S_OK },
|
|
|
|
{ L"NONE", WBEM_E_INVALID_NAMESPACE },
|
|
|
|
{ L"ROOT", S_OK },
|
|
|
|
{ L"ROOT\\NONE", WBEM_E_INVALID_NAMESPACE },
|
|
|
|
{ L"ROOT\\CIMV2", S_OK },
|
|
|
|
{ L"ROOT\\\\CIMV2", WBEM_E_INVALID_NAMESPACE, FALSE, WBEM_E_INVALID_PARAMETER },
|
|
|
|
{ L"ROOT\\CIMV2\\", WBEM_E_INVALID_NAMESPACE, FALSE, WBEM_E_INVALID_PARAMETER },
|
|
|
|
{ L"ROOT/CIMV2", S_OK },
|
|
|
|
{ L"root\\default", S_OK },
|
|
|
|
{ L"root\\cimv0", WBEM_E_INVALID_NAMESPACE },
|
|
|
|
{ L"root\\cimv1", WBEM_E_INVALID_NAMESPACE },
|
|
|
|
{ L"\\\\localhost\\ROOT", S_OK },
|
|
|
|
{ L"\\\\LOCALHOST\\ROOT", S_OK }
|
2012-06-25 11:20:21 +02:00
|
|
|
};
|
|
|
|
IWbemLocator *locator;
|
|
|
|
IWbemServices *services;
|
2021-03-03 07:05:48 +01:00
|
|
|
IWbemContext *context;
|
2012-06-25 11:20:21 +02:00
|
|
|
unsigned int i;
|
|
|
|
HRESULT hr;
|
|
|
|
BSTR resource;
|
|
|
|
|
|
|
|
hr = CoCreateInstance( &CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemLocator, (void **)&locator );
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
win_skip("can't create instance of WbemLocator\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok( hr == S_OK, "failed to create IWbemLocator interface %08x\n", hr );
|
|
|
|
|
2018-05-30 21:15:33 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE( test ); i++)
|
2012-06-25 11:20:21 +02:00
|
|
|
{
|
|
|
|
resource = SysAllocString( test[i].path );
|
|
|
|
hr = IWbemLocator_ConnectServer( locator, resource, NULL, NULL, NULL, 0, NULL, NULL, &services );
|
2016-02-19 23:12:13 +01:00
|
|
|
todo_wine_if (test[i].todo)
|
2012-06-25 11:20:21 +02:00
|
|
|
ok( hr == test[i].result || broken(hr == test[i].result_broken),
|
|
|
|
"%u: expected %08x got %08x\n", i, test[i].result, hr );
|
|
|
|
SysFreeString( resource );
|
|
|
|
if (hr == S_OK) IWbemServices_Release( services );
|
|
|
|
}
|
2021-03-03 07:05:48 +01:00
|
|
|
|
|
|
|
hr = CoCreateInstance( &CLSID_WbemContext, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemContext, (void **)&context );
|
|
|
|
ok(hr == S_OK, "Failed to create context object, hr %#x.\n", hr);
|
|
|
|
|
|
|
|
EXPECT_REF(context, 1);
|
|
|
|
resource = SysAllocString( L"root\\default" );
|
|
|
|
hr = IWbemLocator_ConnectServer( locator, resource, NULL, NULL, NULL, 0, NULL, context, &services );
|
|
|
|
ok(hr == S_OK, "Failed to connect, hr %#x.\n", hr);
|
|
|
|
SysFreeString( resource );
|
|
|
|
EXPECT_REF(context, 1);
|
|
|
|
IWbemServices_Release( services );
|
|
|
|
|
|
|
|
IWbemContext_Release( context );
|
|
|
|
|
2012-06-25 11:20:21 +02:00
|
|
|
IWbemLocator_Release( locator );
|
|
|
|
}
|
|
|
|
|
2021-02-23 21:06:33 +01:00
|
|
|
static void test_IWbemContext(void)
|
|
|
|
{
|
|
|
|
IWbemContext *context;
|
2021-02-25 08:04:30 +01:00
|
|
|
VARIANT var;
|
2021-02-23 21:06:33 +01:00
|
|
|
HRESULT hr;
|
2021-02-25 08:04:30 +01:00
|
|
|
BSTR str;
|
2021-02-23 21:06:33 +01:00
|
|
|
|
|
|
|
hr = CoCreateInstance( &CLSID_WbemContext, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemContext, (void **)&context );
|
|
|
|
ok(hr == S_OK, "Failed to create context object, hr %#x.\n", hr);
|
|
|
|
|
2021-02-25 08:04:30 +01:00
|
|
|
hr = IWbemContext_SetValue(context, L"name", 0, NULL);
|
|
|
|
ok(hr == WBEM_E_INVALID_PARAMETER, "Unexpected hr %#x.\n", hr);
|
|
|
|
|
|
|
|
V_VT(&var) = VT_I4;
|
|
|
|
V_I4(&var) = 12;
|
|
|
|
hr = IWbemContext_SetValue(context, NULL, 0, &var);
|
|
|
|
ok(hr == WBEM_E_INVALID_PARAMETER, "Unexpected hr %#x.\n", hr);
|
|
|
|
|
|
|
|
hr = IWbemContext_SetValue(context, L"name", 0, &var);
|
|
|
|
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
|
|
|
|
|
|
|
|
hr = IWbemContext_GetValue(context, NULL, 0, &var);
|
|
|
|
ok(hr == WBEM_E_INVALID_PARAMETER, "Unexpected hr %#x.\n", hr);
|
|
|
|
|
|
|
|
hr = IWbemContext_GetValue(context, L"name", 0, NULL);
|
|
|
|
ok(hr == WBEM_E_INVALID_PARAMETER, "Unexpected hr %#x.\n", hr);
|
|
|
|
|
|
|
|
hr = IWbemContext_GetValue(context, L"noname", 0, &var);
|
|
|
|
ok(hr == WBEM_E_NOT_FOUND, "Unexpected hr %#x.\n", hr);
|
|
|
|
|
|
|
|
V_VT(&var) = VT_EMPTY;
|
|
|
|
hr = IWbemContext_GetValue(context, L"NAME", 0, &var);
|
|
|
|
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
|
|
|
|
ok(V_VT(&var) == VT_I4, "Unexpected value type.\n");
|
|
|
|
|
|
|
|
V_VT(&var) = VT_I4;
|
|
|
|
V_I4(&var) = 13;
|
|
|
|
hr = IWbemContext_SetValue(context, L"name2", 0, &var);
|
|
|
|
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
|
|
|
|
|
|
|
|
hr = IWbemContext_Next(context, 0, &str, &var);
|
|
|
|
todo_wine
|
|
|
|
ok(hr == WBEM_E_UNEXPECTED, "Unexpected hr %#x.\n", hr);
|
|
|
|
|
|
|
|
hr = IWbemContext_BeginEnumeration(context, 0);
|
|
|
|
todo_wine
|
|
|
|
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
|
|
|
|
|
|
|
|
str = NULL;
|
|
|
|
hr = IWbemContext_Next(context, 0, &str, &var);
|
|
|
|
todo_wine {
|
|
|
|
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
|
|
|
|
ok(!lstrcmpW(str, L"name"), "Unexpected name %s.\n", wine_dbgstr_w(str));
|
|
|
|
SysFreeString(str);
|
|
|
|
}
|
|
|
|
hr = IWbemContext_EndEnumeration(context);
|
|
|
|
todo_wine
|
|
|
|
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
|
|
|
|
|
|
|
|
/* Overwrite */
|
|
|
|
V_VT(&var) = VT_I4;
|
|
|
|
V_I4(&var) = 14;
|
|
|
|
hr = IWbemContext_SetValue(context, L"name", 0, &var);
|
|
|
|
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
|
|
|
|
|
|
|
|
V_VT(&var) = VT_EMPTY;
|
|
|
|
hr = IWbemContext_GetValue(context, L"name", 0, &var);
|
|
|
|
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
|
|
|
|
ok(V_VT(&var) == VT_I4, "Unexpected value type.\n");
|
|
|
|
ok(V_I4(&var) == 14, "Unexpected value.\n");
|
|
|
|
|
2021-02-23 21:06:33 +01:00
|
|
|
IWbemContext_Release( context );
|
|
|
|
}
|
|
|
|
|
2012-06-18 14:00:58 +02:00
|
|
|
START_TEST(services)
|
|
|
|
{
|
|
|
|
CoInitialize( NULL );
|
|
|
|
test_IClientSecurity();
|
2012-06-25 11:20:21 +02:00
|
|
|
test_IWbemLocator();
|
2021-02-23 21:06:33 +01:00
|
|
|
test_IWbemContext();
|
2012-06-18 14:00:58 +02:00
|
|
|
CoUninitialize();
|
|
|
|
}
|