From f4597120b150eaa6fd0d7ba6b12b435dbffb53fe Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Thu, 17 Jan 2013 15:31:45 +0100 Subject: [PATCH] wmiutils: Implement IWbemPath::SetNamespaceAt. --- dlls/wmiutils/path.c | 48 ++++++++++++++++++++++--- dlls/wmiutils/tests/path.c | 75 ++++++++++++++++++++++++++++++++++++++++ dlls/wmiutils/wmiutils_private.h | 6 ++++ 3 files changed, 125 insertions(+), 4 deletions(-) diff --git a/dlls/wmiutils/path.c b/dlls/wmiutils/path.c index 73c1c621cb0..afcad67a04d 100644 --- a/dlls/wmiutils/path.c +++ b/dlls/wmiutils/path.c @@ -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) { diff --git a/dlls/wmiutils/tests/path.c b/dlls/wmiutils/tests/path.c index 049d9b3301f..31246e9427f 100644 --- a/dlls/wmiutils/tests/path.c +++ b/dlls/wmiutils/tests/path.c @@ -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(); } diff --git a/dlls/wmiutils/wmiutils_private.h b/dlls/wmiutils/wmiutils_private.h index 9837ce8b401..98180c96aa1 100644 --- a/dlls/wmiutils/wmiutils_private.h +++ b/dlls/wmiutils/wmiutils_private.h @@ -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 ); -- 2.11.4.GIT