msxml.dll: nextNode and reset functions

Colin Pitrat colin.pitrat at bull.net
Mon Dec 18 04:20:17 CST 2006


New version of this patch, including corrections suggested by Huw 
Davies, a correction and the addition of a test case.
However, I didn't run the test case under Windows because I have a 
problem when I run make crosstest :
Undefined reference to _IID_IXMLDOMDocument
and other similar messages with _IID_IXMLDOMNode, _IID_IXMLDOMElement...

Maybe this error is related to a previous one when running make 
crosstest in top directory, occuring for advpack :
Can't find -lcabinet

Change Log:
	Add an iterator to _xmlnodemap struct
	Implement nextNode function that give nodes one by one
	Implement resetNode that reset the iterator
	Add a test case for these functions

Colin Pitrat (Bull Services Telco)
Bull,  Architect of an Open World (TM)
Tél : +33 (0)  1 30 80 72 93
www.bull.com


Colin Pitrat wrote:
> Change Log:
>     Add an iterator to _xmlnodemap struct
>     Implement nextNode function that give nodes one by one
>     Implement resetNode that reset the iterator
> 
> It's my first patch, so please tell me if something is wrong. I saw on 
> http://www.winehq.com/site/sending_patches that I should write a test 
> case, but I don't know how to do this (do I need windows ? because I 
> don't have it).
> 
> 
> ------------------------------------------------------------------------
> 
> diff --git a/dlls/msxml3/nodemap.c b/dlls/msxml3/nodemap.c
> index 0797436..ead0138 100644
> --- a/dlls/msxml3/nodemap.c
> +++ b/dlls/msxml3/nodemap.c
> @@ -44,6 +44,7 @@ typedef struct _xmlnodemap
>      const struct ISupportErrorInfoVtbl *lpSEIVtbl;
>      LONG ref;
>      IXMLDOMNode *node;
> +	long iterator;
>  } xmlnodemap;
>  
>  static inline xmlnodemap *impl_from_IXMLDOMNamedNodeMap( IXMLDOMNamedNodeMap *iface )
> @@ -297,15 +298,47 @@ static HRESULT WINAPI xmlnodemap_nextNod
>      IXMLDOMNamedNodeMap *iface,
>      IXMLDOMNode** nextItem)
>  {
> -    FIXME("\n");
> -    return E_NOTIMPL;
> +    xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
> +    xmlNodePtr node;
> +    xmlAttrPtr curr;
> +    long attrIndex;
> +
> +    TRACE("%p %ld\n", This, This->iterator);
> +
> +    *nextItem = NULL;
> +
> +    node = xmlNodePtr_from_domnode( This->node, 0 );
> +    curr = node->properties;
> +
> +    for (attrIndex = 0; attrIndex < This->iterator; attrIndex++) {
> +        if (curr->next == NULL)
> +            return S_FALSE;
> +        else
> +            curr = curr->next;
> +    }
> +
> +	if (curr->next == NULL)
> +		return S_FALSE;
> +	else
> +		curr = curr->next;
> +
> +	This->iterator++;
> +    
> +    *nextItem = create_node( (xmlNodePtr) curr );
> +
> +    return S_OK;
>  }
>  
>  static HRESULT WINAPI xmlnodemap_reset(
>      IXMLDOMNamedNodeMap *iface )
>  {
> -    FIXME("\n");
> -    return E_NOTIMPL;
> +    xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
> +
> +    TRACE("%p %ld\n", This, This->iterator);
> +
> +	This->iterator = 0;
> +
> +    return S_OK;
>  }
>  
>  static HRESULT WINAPI xmlnodemap__newEnum(
> 
-------------- next part --------------
diff --git a/dlls/msxml3/nodemap.c b/dlls/msxml3/nodemap.c
index 0797436..5458542 100644
--- a/dlls/msxml3/nodemap.c
+++ b/dlls/msxml3/nodemap.c
@@ -44,6 +44,7 @@ typedef struct _xmlnodemap
     const struct ISupportErrorInfoVtbl *lpSEIVtbl;
     LONG ref;
     IXMLDOMNode *node;
+    long iterator;
 } xmlnodemap;
 
 static inline xmlnodemap *impl_from_IXMLDOMNamedNodeMap( IXMLDOMNamedNodeMap *iface )
@@ -258,8 +259,8 @@ static HRESULT WINAPI xmlnodemap_get_len
 
     first = node->properties;
     if (first == NULL) {
-	*listLength = 0;
-	return S_OK;
+    *listLength = 0;
+    return S_OK;
     }
 
     curr = first;
@@ -297,15 +298,42 @@ static HRESULT WINAPI xmlnodemap_nextNod
     IXMLDOMNamedNodeMap *iface,
     IXMLDOMNode** nextItem)
 {
-    FIXME("\n");
-    return E_NOTIMPL;
+    xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
+    xmlNodePtr node;
+    xmlAttrPtr curr;
+    long attrIndex;
+
+    TRACE("%p %ld\n", This, This->iterator);
+
+    *nextItem = NULL;
+
+    node = xmlNodePtr_from_domnode( This->node, 0 );
+    curr = node->properties;
+
+    for (attrIndex = 0; attrIndex < This->iterator; attrIndex++) {
+        if (curr->next == NULL)
+            return S_FALSE;
+        else
+            curr = curr->next;
+    }
+
+    This->iterator++;
+    
+    *nextItem = create_node( (xmlNodePtr) curr );
+
+    return S_OK;
 }
 
 static HRESULT WINAPI xmlnodemap_reset(
     IXMLDOMNamedNodeMap *iface )
 {
-    FIXME("\n");
-    return E_NOTIMPL;
+    xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
+
+    TRACE("%p %ld\n", This, This->iterator);
+
+    This->iterator = 0;
+
+    return S_OK;
 }
 
 static HRESULT WINAPI xmlnodemap__newEnum(
@@ -389,6 +417,7 @@ IXMLDOMNamedNodeMap *create_nodemap( IXM
     nodemap->lpSEIVtbl = &support_error_vtbl;
     nodemap->node = node;
     nodemap->ref = 1;
+    nodemap->iterator = 0;
 
     IXMLDOMNode_AddRef( node );
     /* Since we AddRef a node here, we don't need to call xmldoc_add_ref() */
diff --git a/dlls/msxml3/tests/domdoc.c b/dlls/msxml3/tests/domdoc.c
index a2824fd..d8f08ac 100644
--- a/dlls/msxml3/tests/domdoc.c
+++ b/dlls/msxml3/tests/domdoc.c
@@ -114,7 +114,10 @@ static void test_domdoc( void )
     r = CoCreateInstance( &CLSID_DOMDocument, NULL, 
         CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
     if( r != S_OK )
+	{
+		printf("CoCreateInstance failed : %d\n",r);
         return;
+	}
 
     /* try some stupid things */
     r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
@@ -411,7 +414,7 @@ todo_wine
         ok( node == NULL, "getNamedItem should have returned NULL\n");
         SysFreeString( str );
 
-	/* test indexed access of attributes */
+        /* 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");
@@ -434,6 +437,23 @@ todo_wine
         r = IXMLDOMNode_get_nodeName( node, NULL );
         ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
 
+        /* test sequential access of attributes */
+        node = NULL;
+        r = IXMLDOMNamedNodeMap_nextNode( map, &node );
+        ok ( r == S_OK, "nextNode (first time) wrong code\n");
+        ok ( node != NULL, "nextNode, should be attribute\n");
+
+        r = IXMLDOMNamedNodeMap_nextNode( map, &node );
+        ok ( r != S_OK, "nextNode (second time) wrong code\n");
+        ok ( node == NULL, "nextNode, there is no attribute\n");
+
+        r = IXMLDOMNamedNodeMap_reset( map );
+        ok ( r == S_OK, "reset should return S_OK\n");
+
+        r = IXMLDOMNamedNodeMap_nextNode( map, &node );
+        ok ( r == S_OK, "nextNode (third time) wrong code\n");
+        ok ( node != NULL, "nextNode, should be attribute\n");
+
         /* content doesn't matter here */
         str = SysAllocString( szNonExistentFile );
         r = IXMLDOMNode_get_nodeName( node, &str );
-------------- next part --------------
A non-text attachment was scrubbed...
Name: colin.pitrat.vcf
Type: text/x-vcard
Size: 247 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-patches/attachments/20061218/660fec44/colin.pitrat.vcf


More information about the wine-patches mailing list