>From 7cc3c3a55887558d6ca2e8cfe0bf3776ddde6c38 Mon Sep 17 00:00:00 2001
From: Nikolay Sivov <nsivov@codeweavers.com>
Date: Fri, 4 Nov 2011 17:43:01 +0300
Subject: [PATCH 4/4] Fix collection index based support for IXMLDOMSelection

---
 dlls/msxml3/selection.c    |    9 +--------
 dlls/msxml3/tests/domdoc.c |   18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/dlls/msxml3/selection.c b/dlls/msxml3/selection.c
index 8500385..01689d9 100644
--- a/dlls/msxml3/selection.c
+++ b/dlls/msxml3/selection.c
@@ -185,13 +185,10 @@ static HRESULT WINAPI domselection_GetTypeInfo(
     ITypeInfo** ppTInfo )
 {
     domselection *This = impl_from_IXMLDOMSelection( iface );
-    HRESULT hr;
 
     TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
 
-    hr = get_typeinfo(IXMLDOMSelection_tid, ppTInfo);
-
-    return hr;
+    return get_typeinfo(IXMLDOMSelection_tid, ppTInfo);
 }
 
 static HRESULT WINAPI domselection_GetIDsOfNames(
@@ -606,7 +603,6 @@ static HRESULT create_enumvariant(IXMLDOMSelection *selection, BOOL own, IUnknow
 
 static HRESULT domselection_get_dispid(IUnknown *iface, BSTR name, DWORD flags, DISPID *dispid)
 {
-    domselection *This = impl_from_IXMLDOMSelection( (IXMLDOMSelection*)iface );
     WCHAR *ptr;
     int idx = 0;
 
@@ -615,9 +611,6 @@ static HRESULT domselection_get_dispid(IUnknown *iface, BSTR name, DWORD flags,
     if(*ptr)
         return DISP_E_UNKNOWNNAME;
 
-    if(idx >= xmlXPathNodeSetGetLength(This->result->nodesetval))
-        return DISP_E_UNKNOWNNAME;
-
     *dispid = DISPID_DOM_COLLECTION_BASE + idx;
     TRACE("ret %x\n", *dispid);
     return S_OK;
diff --git a/dlls/msxml3/tests/domdoc.c b/dlls/msxml3/tests/domdoc.c
index efd8ccc..a883da0 100644
--- a/dlls/msxml3/tests/domdoc.c
+++ b/dlls/msxml3/tests/domdoc.c
@@ -9999,10 +9999,12 @@ static void test_selection(void)
     IEnumVARIANT *enum1, *enum2, *enum3;
     IXMLDOMNodeList *list;
     IXMLDOMDocument *doc;
+    IDispatchEx *dispex;
     IXMLDOMNode *node;
     IDispatch *disp;
     VARIANT_BOOL b;
     HRESULT hr;
+    DISPID did;
     VARIANT v;
     BSTR name;
     ULONG ret;
@@ -10020,6 +10022,22 @@ static void test_selection(void)
     EXPECT_HR(hr, S_OK);
     IXMLDOMSelection_Release(selection);
 
+    /* collection disp id */
+    hr = IXMLDOMSelection_QueryInterface(selection, &IID_IDispatchEx, (void**)&dispex);
+    EXPECT_HR(hr, S_OK);
+    did = 0;
+    hr = IDispatchEx_GetDispID(dispex, _bstr_("0"), 0, &did);
+    EXPECT_HR(hr, S_OK);
+    ok(did == DISPID_DOM_COLLECTION_BASE, "got %d\n", did);
+    len = 0;
+    hr = IXMLDOMSelection_get_length(selection, &len);
+    EXPECT_HR(hr, S_OK);
+    ok(len == 1, "got %d\n", len);
+    hr = IDispatchEx_GetDispID(dispex, _bstr_("10"), 0, &did);
+    EXPECT_HR(hr, S_OK);
+    ok(did == DISPID_DOM_COLLECTION_BASE+10, "got %d\n", did);
+    IDispatchEx_Release(dispex);
+
     /* IEnumVARIANT tests */
     enum1 = NULL;
     hr = IXMLDOMSelection_QueryInterface(selection, &IID_IEnumVARIANT, (void**)&enum1);
-- 
1.5.6.5


