Andrew Nguyen : dxdiagn: Fix return and output behavior of IDxDiagContainer ::EnumChildContainerNames.
Alexandre Julliard
julliard at winehq.org
Mon Mar 15 12:19:40 CDT 2010
Module: wine
Branch: master
Commit: 2c9a5900e630ffa71f5332a41dd4b2392de30807
URL: http://source.winehq.org/git/wine.git/?a=commit;h=2c9a5900e630ffa71f5332a41dd4b2392de30807
Author: Andrew Nguyen <arethusa26 at gmail.com>
Date: Sun Mar 14 11:03:58 2010 -0600
dxdiagn: Fix return and output behavior of IDxDiagContainer::EnumChildContainerNames.
---
dlls/dxdiagn/container.c | 15 +++++------
dlls/dxdiagn/tests/container.c | 49 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+), 8 deletions(-)
diff --git a/dlls/dxdiagn/container.c b/dlls/dxdiagn/container.c
index e02d1d1..e2b3af1 100644
--- a/dlls/dxdiagn/container.c
+++ b/dlls/dxdiagn/container.c
@@ -88,16 +88,13 @@ static HRESULT WINAPI IDxDiagContainerImpl_EnumChildContainerNames(PDXDIAGCONTAI
IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
IDxDiagContainerImpl_SubContainer* p = NULL;
DWORD i = 0;
-
- TRACE("(%p, %u, %s, %u)\n", iface, dwIndex, debugstr_w(pwszContainer), cchContainer);
- if (NULL == pwszContainer) {
+ TRACE("(%p, %u, %p, %u)\n", iface, dwIndex, pwszContainer, cchContainer);
+
+ if (NULL == pwszContainer || 0 == cchContainer) {
return E_INVALIDARG;
}
- if (256 > cchContainer) {
- return DXDIAG_E_INSUFFICIENT_BUFFER;
- }
-
+
p = This->subContainers;
while (NULL != p) {
if (dwIndex == i) {
@@ -109,7 +106,9 @@ static HRESULT WINAPI IDxDiagContainerImpl_EnumChildContainerNames(PDXDIAGCONTAI
}
p = p->next;
++i;
- }
+ }
+
+ *pwszContainer = '\0';
return E_INVALIDARG;
}
diff --git a/dlls/dxdiagn/tests/container.c b/dlls/dxdiagn/tests/container.c
index b2aa4fc..9ca464b 100644
--- a/dlls/dxdiagn/tests/container.c
+++ b/dlls/dxdiagn/tests/container.c
@@ -99,10 +99,59 @@ static void test_GetNumberOfProps(void)
IDxDiagProvider_Release(pddp);
}
+static void test_EnumChildContainerNames(void)
+{
+ HRESULT hr;
+ WCHAR container[256];
+ static const WCHAR testW[] = {'t','e','s','t',0};
+ static const WCHAR zerotestW[] = {0,'e','s','t',0};
+
+ if (!create_root_IDxDiagContainer())
+ {
+ skip("Unable to create the root IDxDiagContainer\n");
+ return;
+ }
+
+ /* Test various combinations of invalid parameters. */
+ hr = IDxDiagContainer_EnumChildContainerNames(pddc, 0, NULL, 0);
+ ok(hr == E_INVALIDARG,
+ "Expected IDxDiagContainer::EnumChildContainerNames to return E_INVALIDARG, got 0x%08x\n", hr);
+
+ hr = IDxDiagContainer_EnumChildContainerNames(pddc, 0, NULL, sizeof(container)/sizeof(WCHAR));
+ ok(hr == E_INVALIDARG,
+ "Expected IDxDiagContainer::EnumChildContainerNames to return E_INVALIDARG, got 0x%08x\n", hr);
+
+ /* Test the conditions in which the output buffer can be modified. */
+ memcpy(container, testW, sizeof(testW));
+ hr = IDxDiagContainer_EnumChildContainerNames(pddc, 0, container, 0);
+ ok(hr == E_INVALIDARG,
+ "Expected IDxDiagContainer::EnumChildContainerNames to return E_INVALIDARG, got 0x%08x\n", hr);
+ ok(!memcmp(container, testW, sizeof(testW)),
+ "Expected the container buffer to be untouched, got %s\n", wine_dbgstr_w(container));
+
+ memcpy(container, testW, sizeof(testW));
+ hr = IDxDiagContainer_EnumChildContainerNames(pddc, ~0, container, 0);
+ ok(hr == E_INVALIDARG,
+ "Expected IDxDiagContainer::EnumChildContainerNames to return E_INVALIDARG, got 0x%08x\n", hr);
+ ok(!memcmp(container, testW, sizeof(testW)),
+ "Expected the container buffer to be untouched, got %s\n", wine_dbgstr_w(container));
+
+ memcpy(container, testW, sizeof(testW));
+ hr = IDxDiagContainer_EnumChildContainerNames(pddc, ~0, container, sizeof(container)/sizeof(WCHAR));
+ ok(hr == E_INVALIDARG,
+ "Expected IDxDiagContainer::EnumChildContainerNames to return E_INVALIDARG, got 0x%08x\n", hr);
+ ok(!memcmp(container, zerotestW, sizeof(zerotestW)),
+ "Expected the container buffer string to be empty, got %s\n", wine_dbgstr_w(container));
+
+ IDxDiagContainer_Release(pddc);
+ IDxDiagProvider_Release(pddp);
+}
+
START_TEST(container)
{
CoInitialize(NULL);
test_GetNumberOfChildContainers();
test_GetNumberOfProps();
+ test_EnumChildContainerNames();
CoUninitialize();
}
More information about the wine-cvs
mailing list