Andrew Nguyen : dxdiagn: Fix dot parsing in IDxDiagContainer:: GetChildContainer for the case of a lone dot terminator.
Alexandre Julliard
julliard at winehq.org
Mon Mar 15 12:19:40 CDT 2010
Module: wine
Branch: master
Commit: af1bcf7768c2c960fca88dcdfd753c171f6c8f0e
URL: http://source.winehq.org/git/wine.git/?a=commit;h=af1bcf7768c2c960fca88dcdfd753c171f6c8f0e
Author: Andrew Nguyen <arethusa26 at gmail.com>
Date: Sun Mar 14 16:36:38 2010 -0600
dxdiagn: Fix dot parsing in IDxDiagContainer::GetChildContainer for the case of a lone dot terminator.
---
dlls/dxdiagn/container.c | 4 ++
dlls/dxdiagn/tests/container.c | 99 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 103 insertions(+), 0 deletions(-)
diff --git a/dlls/dxdiagn/container.c b/dlls/dxdiagn/container.c
index 94d2774..c684e97 100644
--- a/dlls/dxdiagn/container.c
+++ b/dlls/dxdiagn/container.c
@@ -151,6 +151,8 @@ static HRESULT WINAPI IDxDiagContainerImpl_GetChildContainer(PDXDIAGCONTAINER if
cur = strchrW(tmp, '.');
while (NULL != cur) {
*cur = '\0'; /* cut tmp string to '.' */
+ if (!*(cur + 1)) break; /* Account for a lone terminating period, as in "cont1.cont2.". */
+ TRACE("Trying to get parent container %s\n", debugstr_w(tmp));
hr = IDxDiagContainerImpl_GetChildContainerInternal(pContainer, tmp, &pContainer);
if (FAILED(hr) || NULL == pContainer)
goto on_error;
@@ -159,8 +161,10 @@ static HRESULT WINAPI IDxDiagContainerImpl_GetChildContainer(PDXDIAGCONTAINER if
cur = strchrW(tmp, '.');
}
+ TRACE("Trying to get container %s\n", debugstr_w(tmp));
hr = IDxDiagContainerImpl_GetChildContainerInternal(pContainer, tmp, ppInstance);
if (SUCCEEDED(hr)) {
+ TRACE("Succeeded in getting the container instance\n");
IDxDiagContainerImpl_AddRef(*ppInstance);
}
diff --git a/dlls/dxdiagn/tests/container.c b/dlls/dxdiagn/tests/container.c
index ccc5dd3..d2ed43f 100644
--- a/dlls/dxdiagn/tests/container.c
+++ b/dlls/dxdiagn/tests/container.c
@@ -20,6 +20,7 @@
#define COBJMACROS
+#include <stdio.h>
#include "dxdiag.h"
#include "wine/test.h"
@@ -289,6 +290,103 @@ cleanup:
IDxDiagProvider_Release(pddp);
}
+static void test_dot_parsing(void)
+{
+ HRESULT hr;
+ WCHAR containerbufW[256] = {0}, childbufW[256] = {0};
+ DWORD count, index;
+ size_t i;
+ static const struct
+ {
+ const char *format;
+ const HRESULT expect;
+ } test_strings[] = {
+ { "%s.%s", S_OK },
+ { "%s.%s.", S_OK },
+ { ".%s.%s", E_INVALIDARG },
+ { "%s.%s..", E_INVALIDARG },
+ { ".%s.%s.", E_INVALIDARG },
+ { "..%s.%s", E_INVALIDARG },
+ };
+
+ if (!create_root_IDxDiagContainer())
+ {
+ skip("Unable to create the root IDxDiagContainer\n");
+ return;
+ }
+
+ /* Find a container with a child container of its own. */
+ hr = IDxDiagContainer_GetNumberOfChildContainers(pddc, &count);
+ ok(hr == S_OK, "Expected IDxDiagContainer::GetNumberOfChildContainers to return S_OK, got 0x%08x\n", hr);
+ if (FAILED(hr))
+ {
+ skip("IDxDiagContainer::GetNumberOfChildContainers failed\n");
+ goto cleanup;
+ }
+
+ for (index = 0; index < count; index++)
+ {
+ IDxDiagContainer *child;
+
+ hr = IDxDiagContainer_EnumChildContainerNames(pddc, index, containerbufW, sizeof(containerbufW)/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;
+ }
+
+ hr = IDxDiagContainer_GetChildContainer(pddc, containerbufW, &child);
+ ok(hr == S_OK, "Expected IDxDiagContainer::GetChildContainer to return S_OK, got 0x%08x\n", hr);
+
+ if (SUCCEEDED(hr))
+ {
+ hr = IDxDiagContainer_EnumChildContainerNames(child, 0, childbufW, sizeof(childbufW)/sizeof(WCHAR));
+ ok(hr == S_OK || hr == E_INVALIDARG,
+ "Expected IDxDiagContainer::EnumChildContainerNames to return S_OK or E_INVALIDARG, got 0x%08x\n", hr);
+ IDxDiagContainer_Release(child);
+
+ if (SUCCEEDED(hr))
+ break;
+ }
+ }
+
+ if (!*containerbufW || !*childbufW)
+ {
+ skip("Unable to find a suitable container\n");
+ goto cleanup;
+ }
+
+ trace("Testing IDxDiagContainer::GetChildContainer dot parsing with container %s and child container %s.\n",
+ wine_dbgstr_w(containerbufW), wine_dbgstr_w(childbufW));
+
+ for (i = 0; i < sizeof(test_strings)/sizeof(test_strings[0]); i++)
+ {
+ IDxDiagContainer *child;
+ char containerbufA[256];
+ char childbufA[256];
+ char dotbufferA[255 + 255 + 3 + 1];
+ WCHAR dotbufferW[255 + 255 + 3 + 1]; /* containerbuf + childbuf + dots + null terminator */
+
+ WideCharToMultiByte(CP_ACP, 0, containerbufW, -1, containerbufA, sizeof(containerbufA), NULL, NULL);
+ WideCharToMultiByte(CP_ACP, 0, childbufW, -1, childbufA, sizeof(childbufA), NULL, NULL);
+ sprintf(dotbufferA, test_strings[i].format, containerbufA, childbufA);
+ MultiByteToWideChar(CP_ACP, 0, dotbufferA, -1, dotbufferW, sizeof(dotbufferW)/sizeof(WCHAR));
+
+ trace("Trying container name %s\n", wine_dbgstr_w(dotbufferW));
+ hr = IDxDiagContainer_GetChildContainer(pddc, dotbufferW, &child);
+ ok(hr == test_strings[i].expect,
+ "Expected IDxDiagContainer::GetChildContainer to return 0x%08x for %s, got 0x%08x\n",
+ test_strings[i].expect, wine_dbgstr_w(dotbufferW), hr);
+ if (SUCCEEDED(hr))
+ IDxDiagContainer_Release(child);
+ }
+
+cleanup:
+ IDxDiagContainer_Release(pddc);
+ IDxDiagProvider_Release(pddp);
+}
+
START_TEST(container)
{
CoInitialize(NULL);
@@ -296,5 +394,6 @@ START_TEST(container)
test_GetNumberOfProps();
test_EnumChildContainerNames();
test_GetChildContainer();
+ test_dot_parsing();
CoUninitialize();
}
More information about the wine-cvs
mailing list