From 583474023154ef2f75c3459f822f18f6cd1043f8 Mon Sep 17 00:00:00 2001 From: Stefan Huehner Date: Thu, 3 Nov 2005 12:04:52 +0000 Subject: [PATCH] Add indexed access to attributes (nodemap) and childNodes (nodelist), with some testcases. --- dlls/msxml3/nodelist.c | 48 ++++++++++++++++++++++++++++++++++---- dlls/msxml3/nodemap.c | 57 ++++++++++++++++++++++++++++++++++++++++++---- dlls/msxml3/tests/domdoc.c | 33 +++++++++++++++++++++++++++ 3 files changed, 130 insertions(+), 8 deletions(-) diff --git a/dlls/msxml3/nodelist.c b/dlls/msxml3/nodelist.c index 8ef4a460729..7630f05126d 100644 --- a/dlls/msxml3/nodelist.c +++ b/dlls/msxml3/nodelist.c @@ -251,16 +251,56 @@ static HRESULT WINAPI xmlnodelist_get_item( long index, IXMLDOMNode** listItem) { - FIXME("\n"); - return E_NOTIMPL; + xmlnodelist *This = impl_from_IXMLDOMNodeList( iface ); + xmlNodePtr curr; + long nodeIndex = 0; + + TRACE("%p %ld\n", This, index); + + *listItem = NULL; + + if (index < 0) + return S_FALSE; + + curr = This->node; + + for (nodeIndex = 0; nodeIndex < index; nodeIndex++) { + if (curr->next == NULL) + return S_FALSE; + else + curr = curr->next; + } + + *listItem = create_node( curr ); + + return S_OK; } static HRESULT WINAPI xmlnodelist_get_length( IXMLDOMNodeList* iface, long* listLength) { - FIXME("\n"); - return E_NOTIMPL; + + xmlNodePtr curr; + long nodeCount = 0; + + xmlnodelist *This = impl_from_IXMLDOMNodeList( iface ); + + TRACE("%p\n", This); + + if (This->node == NULL) { + *listLength = 0; + return S_OK; + } + + curr = This->node; + nodeCount = 1; + while (curr->next != NULL) { + nodeCount++; + curr = curr->next; + } + *listLength = nodeCount; + return S_OK; } static HRESULT WINAPI xmlnodelist_nextNode( diff --git a/dlls/msxml3/nodemap.c b/dlls/msxml3/nodemap.c index d8f87ec8e90..da7eebafc96 100644 --- a/dlls/msxml3/nodemap.c +++ b/dlls/msxml3/nodemap.c @@ -196,16 +196,65 @@ static HRESULT WINAPI xmlnodemap_get_item( long index, IXMLDOMNode** listItem) { - FIXME("\n"); - return E_NOTIMPL; + xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface ); + xmlNodePtr node; + xmlAttrPtr curr; + long attrIndex; + + TRACE("%p %ld\n", This, index); + + *listItem = NULL; + + if (index < 0) + return S_FALSE; + + node = xmlNodePtr_from_domnode( This->node, 0 ); + curr = node->properties; + + for (attrIndex = 0; attrIndex < index; attrIndex++) { + if (curr->next == NULL) + return S_FALSE; + else + curr = curr->next; + } + + *listItem = create_node( (xmlNodePtr) curr ); + + return S_OK; } static HRESULT WINAPI xmlnodemap_get_length( IXMLDOMNamedNodeMap *iface, long* listLength) { - FIXME("\n"); - return E_NOTIMPL; + xmlNodePtr node; + xmlAttrPtr first; + xmlAttrPtr curr; + long attrCount; + + xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface ); + + TRACE("%p\n", This); + + node = xmlNodePtr_from_domnode( This->node, 0 ); + if ( !node ) + return E_FAIL; + + first = node->properties; + if (first == NULL) { + *listLength = 0; + return S_OK; + } + + curr = first; + attrCount = 1; + while (curr->next != NULL) { + attrCount++; + curr = curr->next; + } + *listLength = attrCount; + + return S_OK; } static HRESULT WINAPI xmlnodemap_getQualifiedItem( diff --git a/dlls/msxml3/tests/domdoc.c b/dlls/msxml3/tests/domdoc.c index 5eb704d2026..71919de6502 100644 --- a/dlls/msxml3/tests/domdoc.c +++ b/dlls/msxml3/tests/domdoc.c @@ -242,6 +242,7 @@ void test_domnode( void ) VARIANT_BOOL b; BSTR str; VARIANT var; + long count; r = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc ); @@ -325,6 +326,38 @@ void test_domnode( void ) r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node ); ok( r == S_OK, "getNamedItem returned wrong code\n"); ok( node != NULL, "should be attributes\n"); + SysFreeString( str ); + + /* test indexed access of attributes */ + r = IXMLDOMNamedNodeMap_get_length( map, &count ); + ok ( r == S_OK, "get_length wrong code\n"); + ok ( count == 1, "get_length != 1\n"); + + node = NULL; + r = IXMLDOMNamedNodeMap_get_item( map, -1, &node); + ok ( r == S_FALSE, "get_item (-1) wrong code\n"); + ok ( node == NULL, "there is no node\n"); + + node = NULL; + r = IXMLDOMNamedNodeMap_get_item( map, 1, &node); + ok ( r == S_FALSE, "get_item (1) wrong code\n"); + ok ( node == NULL, "there is no attribute\n"); + + node = NULL; + r = IXMLDOMNamedNodeMap_get_item( map, 0, &node); + ok ( r == S_OK, "get_item (0) wrong code\n"); + ok ( node != NULL, "should be attribute\n"); + + r = IXMLDOMNode_get_nodeName( node, NULL ); + ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code"); + + /* content doesn't matter here */ + str = SysAllocString( szNonExistentFile ); + r = IXMLDOMNode_get_nodeName( node, &str ); + ok ( r == S_OK, "get_nodeName wrong code\n"); + ok ( str != NULL, "str is null\n"); + ok( !lstrcmpW( str, szdl ), "incorrect node name\n"); + SysFreeString( str ); } else ok( FALSE, "no map\n"); -- 2.11.4.GIT