Module: wine Branch: master Commit: c245c6ed0974fc5bac2e8abc6db869a2cca35f5b URL: http://source.winehq.org/git/wine.git/?a=commit;h=c245c6ed0974fc5bac2e8abc6d...
Author: Andrew Nguyen arethusa26@gmail.com Date: Sun Mar 14 11:04:07 2010 -0600
dxdiagn: Initialize output pointer to NULL in IDxDiagContainer::GetChildContainer.
---
dlls/dxdiagn/container.c | 4 +- dlls/dxdiagn/tests/container.c | 71 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 2 deletions(-)
diff --git a/dlls/dxdiagn/container.c b/dlls/dxdiagn/container.c index d1c023f..94d2774 100644 --- a/dlls/dxdiagn/container.c +++ b/dlls/dxdiagn/container.c @@ -129,7 +129,7 @@ static HRESULT IDxDiagContainerImpl_GetChildContainerInternal(PDXDIAGCONTAINER i
static HRESULT WINAPI IDxDiagContainerImpl_GetChildContainer(PDXDIAGCONTAINER iface, LPCWSTR pwszContainer, IDxDiagContainer** ppInstance) { IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface; - IDxDiagContainer* pContainer = NULL; + IDxDiagContainer* pContainer = (PDXDIAGCONTAINER)This; LPWSTR tmp, orig_tmp; INT tmp_len; WCHAR* cur; @@ -141,7 +141,7 @@ static HRESULT WINAPI IDxDiagContainerImpl_GetChildContainer(PDXDIAGCONTAINER if return E_INVALIDARG; }
- pContainer = (PDXDIAGCONTAINER) This; + *ppInstance = NULL;
tmp_len = strlenW(pwszContainer) + 1; orig_tmp = tmp = HeapAlloc(GetProcessHeap(), 0, tmp_len * sizeof(WCHAR)); diff --git a/dlls/dxdiagn/tests/container.c b/dlls/dxdiagn/tests/container.c index 6fbb085..ccc5dd3 100644 --- a/dlls/dxdiagn/tests/container.c +++ b/dlls/dxdiagn/tests/container.c @@ -219,11 +219,82 @@ cleanup: IDxDiagProvider_Release(pddp); }
+static void test_GetChildContainer(void) +{ + HRESULT hr; + WCHAR container[256] = {0}; + IDxDiagContainer *child; + + if (!create_root_IDxDiagContainer()) + { + skip("Unable to create the root IDxDiagContainer\n"); + return; + } + + /* Test various combinations of invalid parameters. */ + hr = IDxDiagContainer_GetChildContainer(pddc, NULL, NULL); + ok(hr == E_INVALIDARG, + "Expected IDxDiagContainer::GetChildContainer to return E_INVALIDARG, got 0x%08x\n", hr); + + child = (void*)0xdeadbeef; + hr = IDxDiagContainer_GetChildContainer(pddc, NULL, &child); + ok(hr == E_INVALIDARG, + "Expected IDxDiagContainer::GetChildContainer to return E_INVALIDARG, got 0x%08x\n", hr); + ok(child == (void*)0xdeadbeef, "Expected output pointer to be unchanged, got %p\n", child); + + hr = IDxDiagContainer_GetChildContainer(pddc, container, NULL); + ok(hr == E_INVALIDARG, + "Expected IDxDiagContainer::GetChildContainer to return E_INVALIDARG, got 0x%08x\n", hr); + + child = (void*)0xdeadbeef; + hr = IDxDiagContainer_GetChildContainer(pddc, container, &child); + ok(hr == E_INVALIDARG, + "Expected IDxDiagContainer::GetChildContainer to return E_INVALIDARG, got 0x%08x\n", hr); + ok(child == NULL, "Expected output pointer to be NULL, got %p\n", child); + + /* Get the name of a suitable child container. */ + hr = IDxDiagContainer_EnumChildContainerNames(pddc, 0, container, sizeof(container)/sizeof(WCHAR)); + ok(hr == S_OK, + "Expected IDxDiagContainer::EnumChildContainerNames to return S_OK, got 0x%08x\n", hr); + if (FAILED(hr)) + { + skip("IDxDiagContainer::EnumChildContainerNames failed\n"); + goto cleanup; + } + + child = (void*)0xdeadbeef; + hr = IDxDiagContainer_GetChildContainer(pddc, container, &child); + ok(hr == S_OK, + "Expected IDxDiagContainer::GetChildContainer to return S_OK, got 0x%08x\n", hr); + ok(child != NULL && child != (void*)0xdeadbeef, "Expected a valid output pointer, got %p\n", child); + + if (SUCCEEDED(hr)) + { + IDxDiagContainer *ptr; + + /* Show that IDxDiagContainer::GetChildContainer returns a different pointer + * for multiple calls for the same container name. */ + hr = IDxDiagContainer_GetChildContainer(pddc, container, &ptr); + ok(hr == S_OK, + "Expected IDxDiagContainer::GetChildContainer to return S_OK, got 0x%08x\n", hr); + if (SUCCEEDED(hr)) + todo_wine ok(ptr != child, "Expected the two pointers (%p vs. %p) to be unequal", child, ptr); + + IDxDiagContainer_Release(ptr); + IDxDiagContainer_Release(child); + } + +cleanup: + IDxDiagContainer_Release(pddc); + IDxDiagProvider_Release(pddp); +} + START_TEST(container) { CoInitialize(NULL); test_GetNumberOfChildContainers(); test_GetNumberOfProps(); test_EnumChildContainerNames(); + test_GetChildContainer(); CoUninitialize(); }