wmiutils: Implement IWbemPath::SetNamespaceAt.
This commit is contained in:
parent
9548eb79ad
commit
f4597120b1
|
@ -500,11 +500,50 @@ static HRESULT WINAPI path_GetNamespaceCount(
|
|||
|
||||
static HRESULT WINAPI path_SetNamespaceAt(
|
||||
IWbemPath *iface,
|
||||
ULONG uIndex,
|
||||
LPCWSTR pszName)
|
||||
ULONG idx,
|
||||
LPCWSTR name)
|
||||
{
|
||||
FIXME("%p, %u, %s\n", iface, uIndex, debugstr_w(pszName));
|
||||
return E_NOTIMPL;
|
||||
struct path *path = impl_from_IWbemPath( iface );
|
||||
static const ULONGLONG flags =
|
||||
WBEMPATH_INFO_V1_COMPLIANT | WBEMPATH_INFO_V2_COMPLIANT |
|
||||
WBEMPATH_INFO_CIM_COMPLIANT;
|
||||
int i, *tmp_len;
|
||||
WCHAR **tmp, *new;
|
||||
DWORD size;
|
||||
|
||||
TRACE("%p, %u, %s\n", iface, idx, debugstr_w(name));
|
||||
|
||||
if (idx > path->num_namespaces || !name) return WBEM_E_INVALID_PARAMETER;
|
||||
if (!(new = strdupW( name ))) return WBEM_E_OUT_OF_MEMORY;
|
||||
|
||||
size = (path->num_namespaces + 1) * sizeof(WCHAR *);
|
||||
if (path->namespaces) tmp = heap_realloc( path->namespaces, size );
|
||||
else tmp = heap_alloc( size );
|
||||
if (!tmp)
|
||||
{
|
||||
heap_free( new );
|
||||
return WBEM_E_OUT_OF_MEMORY;
|
||||
}
|
||||
path->namespaces = tmp;
|
||||
size = (path->num_namespaces + 1) * sizeof(int);
|
||||
if (path->len_namespaces) tmp_len = heap_realloc( path->len_namespaces, size );
|
||||
else tmp_len = heap_alloc( size );
|
||||
if (!tmp_len)
|
||||
{
|
||||
heap_free( new );
|
||||
return WBEM_E_OUT_OF_MEMORY;
|
||||
}
|
||||
path->len_namespaces = tmp_len;
|
||||
for (i = idx; i < path->num_namespaces; i++)
|
||||
{
|
||||
path->namespaces[i + 1] = path->namespaces[i];
|
||||
path->len_namespaces[i + 1] = path->len_namespaces[i];
|
||||
}
|
||||
path->namespaces[idx] = new;
|
||||
path->len_namespaces[idx] = strlenW( new );
|
||||
path->num_namespaces++;
|
||||
path->flags |= flags;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI path_GetNamespaceAt(
|
||||
|
@ -532,6 +571,7 @@ static HRESULT WINAPI path_RemoveNamespaceAt(
|
|||
TRACE("%p, %u\n", iface, idx);
|
||||
|
||||
if (idx >= path->num_namespaces) return WBEM_E_INVALID_PARAMETER;
|
||||
|
||||
heap_free( path->namespaces[idx] );
|
||||
while (idx < path->num_namespaces - 1)
|
||||
{
|
||||
|
|
|
@ -702,6 +702,80 @@ static void test_IWbemPath_RemoveNamespaceAt(void)
|
|||
IWbemPath_Release( path );
|
||||
}
|
||||
|
||||
static void test_IWbemPath_SetNamespaceAt(void)
|
||||
{
|
||||
static const ULONGLONG expected_flags =
|
||||
WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_V1_COMPLIANT |
|
||||
WBEMPATH_INFO_V2_COMPLIANT | WBEMPATH_INFO_CIM_COMPLIANT |
|
||||
WBEMPATH_INFO_SERVER_NAMESPACE_ONLY;
|
||||
static const WCHAR rootW[] = {'r','o','o','t',0};
|
||||
static const WCHAR cimv2W[] = {'c','i','m','v','2',0};
|
||||
IWbemPath *path;
|
||||
WCHAR buf[16];
|
||||
ULONG len, count;
|
||||
ULONGLONG flags;
|
||||
HRESULT hr;
|
||||
|
||||
if (!(path = create_path())) return;
|
||||
|
||||
hr = IWbemPath_SetNamespaceAt( path, 0, NULL );
|
||||
ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
|
||||
|
||||
hr = IWbemPath_SetNamespaceAt( path, 1, cimv2W );
|
||||
ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
|
||||
|
||||
hr = IWbemPath_SetNamespaceAt( path, 0, cimv2W );
|
||||
ok( hr == S_OK, "got %08x\n", hr );
|
||||
|
||||
count = 0xdeadbeef;
|
||||
hr = IWbemPath_GetNamespaceCount( path, &count );
|
||||
ok( hr == S_OK, "got %08x\n", hr );
|
||||
ok( count == 1, "got %u\n", count );
|
||||
|
||||
flags = 0;
|
||||
hr = IWbemPath_GetInfo( path, 0, &flags );
|
||||
ok( hr == S_OK, "got %08x\n", hr );
|
||||
ok( flags == expected_flags,
|
||||
"got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags );
|
||||
|
||||
buf[0] = 0;
|
||||
len = sizeof(buf) / sizeof(buf[0]);
|
||||
hr = IWbemPath_GetNamespaceAt( path, 0, &len, buf );
|
||||
ok( hr == S_OK, "got %08x\n", hr );
|
||||
ok( !lstrcmpW( buf, cimv2W ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
|
||||
ok( len == lstrlenW( cimv2W ) + 1, "unexpected length %u\n", len );
|
||||
|
||||
hr = IWbemPath_SetNamespaceAt( path, 0, rootW );
|
||||
ok( hr == S_OK, "got %08x\n", hr );
|
||||
|
||||
flags = 0;
|
||||
hr = IWbemPath_GetInfo( path, 0, &flags );
|
||||
ok( hr == S_OK, "got %08x\n", hr );
|
||||
ok( flags == expected_flags,
|
||||
"got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags );
|
||||
|
||||
count = 0xdeadbeef;
|
||||
hr = IWbemPath_GetNamespaceCount( path, &count );
|
||||
ok( hr == S_OK, "got %08x\n", hr );
|
||||
ok( count == 2, "got %u\n", count );
|
||||
|
||||
buf[0] = 0;
|
||||
len = sizeof(buf) / sizeof(buf[0]);
|
||||
hr = IWbemPath_GetNamespaceAt( path, 0, &len, buf );
|
||||
ok( hr == S_OK, "got %08x\n", hr );
|
||||
ok( !lstrcmpW( buf, rootW ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
|
||||
ok( len == lstrlenW( rootW ) + 1, "unexpected length %u\n", len );
|
||||
|
||||
buf[0] = 0;
|
||||
len = sizeof(buf) / sizeof(buf[0]);
|
||||
hr = IWbemPath_GetNamespaceAt( path, 1, &len, buf );
|
||||
ok( hr == S_OK, "got %08x\n", hr );
|
||||
ok( !lstrcmpW( buf, cimv2W ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) );
|
||||
ok( len == lstrlenW( cimv2W ) + 1, "unexpected length %u\n", len );
|
||||
|
||||
IWbemPath_Release( path );
|
||||
}
|
||||
|
||||
START_TEST (path)
|
||||
{
|
||||
CoInitialize( NULL );
|
||||
|
@ -716,6 +790,7 @@ START_TEST (path)
|
|||
test_IWbemPath_GetNamespaceAt();
|
||||
test_IWbemPath_RemoveAllNamespaces();
|
||||
test_IWbemPath_RemoveNamespaceAt();
|
||||
test_IWbemPath_SetNamespaceAt();
|
||||
|
||||
CoUninitialize();
|
||||
}
|
||||
|
|
|
@ -27,6 +27,12 @@ static inline void *heap_alloc( size_t len )
|
|||
return HeapAlloc( GetProcessHeap(), 0, len );
|
||||
}
|
||||
|
||||
static void *heap_realloc( void *mem, size_t len ) __WINE_ALLOC_SIZE(2);
|
||||
static inline void *heap_realloc( void *mem, size_t len )
|
||||
{
|
||||
return HeapReAlloc( GetProcessHeap(), 0, mem, len );
|
||||
}
|
||||
|
||||
static inline BOOL heap_free( void *mem )
|
||||
{
|
||||
return HeapFree( GetProcessHeap(), 0, mem );
|
||||
|
|
Loading…
Reference in New Issue