Add indexed access to attributes (nodemap) and childNodes
(nodelist), with some testcases.
This commit is contained in:
parent
92032e6e35
commit
5834740231
|
@ -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(
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue