Sweden-Number/dlls/msxml3/tests/domdoc.c

1111 lines
37 KiB
C

/*
* XML test
*
* Copyright 2005 Mike McCormack for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#define COBJMACROS
#include "windows.h"
#include "ole2.h"
#include "msxml2.h"
#include <stdio.h>
#include "wine/test.h"
const CLSID CLSID_DOMDocument2 = {0xf6d90f11, 0x9c73, 0x11d3, {0xb3, 0x2e, 0x00,0xc0, 0x4f, 0x99, 0x0b, 0xb4}};
static const WCHAR szEmpty[] = { 0 };
static const WCHAR szIncomplete[] = {
'<','?','x','m','l',' ',
'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',0
};
static const WCHAR szComplete1[] = {
'<','?','x','m','l',' ',
'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
'<','o','p','e','n','>','<','/','o','p','e','n','>','\n',0
};
static const WCHAR szComplete2[] = {
'<','?','x','m','l',' ',
'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
'<','o','>','<','/','o','>','\n',0
};
static const WCHAR szComplete3[] = {
'<','?','x','m','l',' ',
'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
'<','a','>','<','/','a','>','\n',0
};
static const WCHAR szComplete4[] = {
'<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
'<','l','c',' ','d','l','=','\'','s','t','r','1','\'','>','\n',
'<','b','s',' ','v','r','=','\'','s','t','r','2','\'',' ','s','z','=','\'','1','2','3','4','\'','>',
'f','n','1','.','t','x','t','\n',
'<','/','b','s','>','\n',
'<','p','r',' ','i','d','=','\'','s','t','r','3','\'',' ','v','r','=','\'','1','.','2','.','3','\'',' ',
'p','n','=','\'','w','i','n','e',' ','2','0','0','5','0','8','0','4','\'','>','\n',
'f','n','2','.','t','x','t','\n',
'<','/','p','r','>','\n',
'<','e','m','p','t','y','>','<','/','e','m','p','t','y','>','\n',
'<','f','o','>','\n',
'<','b','a','>','\n',
'f','1','\n',
'<','/','b','a','>','\n',
'<','/','f','o','>','\n',
'<','/','l','c','>','\n',0
};
static const WCHAR szComplete5[] = {
'<','S',':','s','e','a','r','c','h',' ','x','m','l','n','s',':','D','=','"','D','A','V',':','"',' ',
'x','m','l','n','s',':','C','=','"','u','r','n',':','s','c','h','e','m','a','s','-','m','i','c','r','o','s','o','f','t','-','c','o','m',':','o','f','f','i','c','e',':','c','l','i','p','g','a','l','l','e','r','y','"',
' ','x','m','l','n','s',':','S','=','"','u','r','n',':','s','c','h','e','m','a','s','-','m','i','c','r','o','s','o','f','t','-','c','o','m',':','o','f','f','i','c','e',':','c','l','i','p','g','a','l','l','e','r','y',':','s','e','a','r','c','h','"','>',
'<','S',':','s','c','o','p','e','>',
'<','S',':','d','e','e','p','>','/','<','/','S',':','d','e','e','p','>',
'<','/','S',':','s','c','o','p','e','>',
'<','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
'<','C',':','t','e','x','t','o','r','p','r','o','p','e','r','t','y','/','>',
'c','o','m','p','u','t','e','r',
'<','/','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
'<','/','S',':','s','e','a','r','c','h','>',0
};
static const WCHAR szNonExistentFile[] = {
'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', '.', 'x', 'm', 'l', 0
};
static const WCHAR szDocument[] = {
'#', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 0
};
static const WCHAR szOpen[] = { 'o','p','e','n',0 };
static const WCHAR szdl[] = { 'd','l',0 };
static const WCHAR szvr[] = { 'v','r',0 };
static const WCHAR szlc[] = { 'l','c',0 };
static const WCHAR szbs[] = { 'b','s',0 };
static const WCHAR szstr1[] = { 's','t','r','1',0 };
static const WCHAR szstr2[] = { 's','t','r','2',0 };
static const WCHAR szstar[] = { '*',0 };
static const WCHAR szfn1_txt[] = {'f','n','1','.','t','x','t',0};
void test_domdoc( void )
{
HRESULT r;
IXMLDOMDocument *doc = NULL;
IXMLDOMParseError *error;
IXMLDOMElement *element = NULL;
IXMLDOMNode *node;
VARIANT_BOOL b;
VARIANT var;
BSTR str;
long code;
r = CoCreateInstance( &CLSID_DOMDocument, NULL,
CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
if( r != S_OK )
return;
/* try some stupid things */
r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
ok( r == S_FALSE, "loadXML failed\n");
b = VARIANT_TRUE;
r = IXMLDOMDocument_loadXML( doc, NULL, &b );
ok( r == S_FALSE, "loadXML failed\n");
ok( b == VARIANT_FALSE, "failed to load XML string\n");
/* try to load a document from a nonexistent file */
b = VARIANT_TRUE;
str = SysAllocString( szNonExistentFile );
VariantInit(&var);
V_VT(&var) = VT_BSTR;
V_BSTR(&var) = str;
r = IXMLDOMDocument_load( doc, var, &b);
ok( r == S_FALSE, "load (from file) failed\n");
ok( b == VARIANT_FALSE, "failed to load XML file\n");
SysFreeString( str );
/* try load an empty document */
b = VARIANT_TRUE;
str = SysAllocString( szEmpty );
r = IXMLDOMDocument_loadXML( doc, str, &b );
ok( r == S_FALSE, "loadXML failed\n");
ok( b == VARIANT_FALSE, "failed to load XML string\n");
SysFreeString( str );
/* check that there's no document element */
element = NULL;
r = IXMLDOMDocument_get_documentElement( doc, &element );
ok( r == S_FALSE, "should be no document element\n");
/* try finding a node */
node = NULL;
str = SysAllocString( szstr1 );
r = IXMLDOMDocument_selectSingleNode( doc, str, &node );
ok( r == S_FALSE, "ret %08x\n", r );
SysFreeString( str );
b = VARIANT_TRUE;
str = SysAllocString( szIncomplete );
r = IXMLDOMDocument_loadXML( doc, str, &b );
ok( r == S_FALSE, "loadXML failed\n");
ok( b == VARIANT_FALSE, "failed to load XML string\n");
SysFreeString( str );
/* check that there's no document element */
element = (IXMLDOMElement*)1;
r = IXMLDOMDocument_get_documentElement( doc, &element );
ok( r == S_FALSE, "should be no document element\n");
ok( element == NULL, "Element should be NULL\n");
/* try to load something valid */
b = VARIANT_FALSE;
str = SysAllocString( szComplete1 );
r = IXMLDOMDocument_loadXML( doc, str, &b );
ok( r == S_OK, "loadXML failed\n");
ok( b == VARIANT_TRUE, "failed to load XML string\n");
SysFreeString( str );
/* try with a null out pointer - crashes */
if (0)
{
r = IXMLDOMDocument_get_documentElement( doc, NULL );
ok( r == S_OK, "should be no document element\n");
}
/* check if nodename is correct */
r = IXMLDOMDocument_get_nodeName( doc, NULL );
ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
/* content doesn't matter here */
str = SysAllocString( szNonExistentFile );
r = IXMLDOMDocument_get_nodeName( doc, &str );
ok ( r == S_OK, "get_nodeName wrong code\n");
ok ( str != NULL, "str is null\n");
ok( !lstrcmpW( str, szDocument ), "incorrect nodeName\n");
SysFreeString( str );
/* check that there's a document element */
element = NULL;
r = IXMLDOMDocument_get_documentElement( doc, &element );
ok( r == S_OK, "should be a document element\n");
if( element )
{
BSTR tag = NULL;
/* check if the tag is correct */
r = IXMLDOMElement_get_tagName( element, &tag );
ok( r == S_OK, "couldn't get tag name\n");
ok( tag != NULL, "tag was null\n");
ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
SysFreeString( tag );
/* figure out what happens if we try to reload the document */
str = SysAllocString( szComplete2 );
r = IXMLDOMDocument_loadXML( doc, str, &b );
ok( r == S_OK, "loadXML failed\n");
ok( b == VARIANT_TRUE, "failed to load XML string\n");
SysFreeString( str );
/* check if the tag is still correct */
tag = NULL;
r = IXMLDOMElement_get_tagName( element, &tag );
ok( r == S_OK, "couldn't get tag name\n");
ok( tag != NULL, "tag was null\n");
ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
SysFreeString( tag );
IXMLDOMElement_Release( element );
element = NULL;
}
/* as soon as we call loadXML again, the document element will disappear */
b = 2;
r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
ok( r == S_FALSE, "loadXML failed\n");
ok( b == 2, "variant modified\n");
r = IXMLDOMDocument_get_documentElement( doc, &element );
ok( r == S_FALSE, "should be no document element\n");
/* try to load something else simple and valid */
b = VARIANT_FALSE;
str = SysAllocString( szComplete3 );
r = IXMLDOMDocument_loadXML( doc, str, &b );
ok( r == S_OK, "loadXML failed\n");
ok( b == VARIANT_TRUE, "failed to load XML string\n");
SysFreeString( str );
/* try something a little more complicated */
b = FALSE;
str = SysAllocString( szComplete4 );
r = IXMLDOMDocument_loadXML( doc, str, &b );
ok( r == S_OK, "loadXML failed\n");
ok( b == VARIANT_TRUE, "failed to load XML string\n");
SysFreeString( str );
r = IXMLDOMDocument_get_parseError( doc, &error );
ok( r == S_OK, "returns %08x\n", r );
r = IXMLDOMParseError_get_errorCode( error, &code );
ok( r == S_FALSE, "returns %08x\n", r );
ok( code == 0, "code %ld\n", code );
IXMLDOMParseError_Release( error );
r = IXMLDOMDocument_Release( doc );
ok( r == 0, "document ref count incorrect\n");
}
void test_domnode( void )
{
HRESULT r;
IXMLDOMDocument *doc = NULL, *owner = NULL;
IXMLDOMElement *element = NULL;
IXMLDOMNamedNodeMap *map = NULL;
IXMLDOMNode *node = NULL, *next = NULL;
IXMLDOMNodeList *list = NULL;
DOMNodeType type = NODE_INVALID;
VARIANT_BOOL b;
BSTR str;
VARIANT var;
long count;
r = CoCreateInstance( &CLSID_DOMDocument, NULL,
CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
if( r != S_OK )
return;
b = FALSE;
str = SysAllocString( szComplete4 );
r = IXMLDOMDocument_loadXML( doc, str, &b );
ok( r == S_OK, "loadXML failed\n");
ok( b == VARIANT_TRUE, "failed to load XML string\n");
SysFreeString( str );
if (doc)
{
b = 1;
r = IXMLDOMNode_hasChildNodes( doc, &b );
ok( r == S_OK, "hasChildNoes bad return\n");
ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
r = IXMLDOMDocument_get_documentElement( doc, &element );
ok( r == S_OK, "should be a document element\n");
ok( element != NULL, "should be an element\n");
}
else
ok( FALSE, "no document\n");
VariantInit(&var);
ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
r = IXMLDOMNode_get_nodeValue( doc, &var );
ok( r == S_FALSE, "nextNode returned wrong code\n");
ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
if (element)
{
owner = NULL;
r = IXMLDOMNode_get_ownerDocument( element, &owner );
todo_wine {
ok( r == S_OK, "get_ownerDocument return code\n");
}
ok( owner != doc, "get_ownerDocument return\n");
type = NODE_INVALID;
r = IXMLDOMNode_get_nodeType( element, &type);
ok( r == S_OK, "getNamedItem returned wrong code\n");
ok( type == NODE_ELEMENT, "node not an element\n");
str = NULL;
r = IXMLDOMNode_get_baseName( element, &str );
ok( r == S_OK, "get_baseName returned wrong code\n");
ok( lstrcmpW(str,szlc) == 0, "basename was wrong\n");
/* check if nodename is correct */
r = IXMLDOMElement_get_nodeName( element, NULL );
ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
/* content doesn't matter here */
str = SysAllocString( szNonExistentFile );
r = IXMLDOMElement_get_nodeName( element, &str );
ok ( r == S_OK, "get_nodeName wrong code\n");
ok ( str != NULL, "str is null\n");
ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n");
SysFreeString( str );
str = SysAllocString( szNonExistentFile );
V_VT(&var) = VT_I4;
V_I4(&var) = 0x1234;
r = IXMLDOMElement_getAttribute( element, str, &var );
ok( r == E_FAIL, "getAttribute ret %08x\n", r );
ok( V_VT(&var) == VT_EMPTY, "vt = %x\n", V_VT(&var));
VariantClear(&var);
SysFreeString( str );
str = SysAllocString( szdl );
V_VT(&var) = VT_I4;
V_I4(&var) = 0x1234;
r = IXMLDOMElement_getAttribute( element, str, &var );
ok( r == S_OK, "getAttribute ret %08x\n", r );
ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var));
ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n");
VariantClear( &var );
SysFreeString( str );
r = IXMLDOMElement_get_attributes( element, &map );
ok( r == S_OK, "get_attributes returned wrong code\n");
ok( map != NULL, "should be attributes\n");
b = 1;
r = IXMLDOMNode_hasChildNodes( element, &b );
ok( r == S_OK, "hasChildNoes bad return\n");
ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
}
else
ok( FALSE, "no element\n");
if (map)
{
ISupportErrorInfo *support_error;
r = IXMLDOMNamedNodeMap_QueryInterface( map, &IID_ISupportErrorInfo, (LPVOID*)&support_error );
ok( r == S_OK, "ret %08x\n", r );
r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMNamedNodeMap );
todo_wine
{
ok( r == S_OK, "ret %08x\n", r );
}
ISupportErrorInfo_Release( support_error );
str = SysAllocString( szdl );
r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
ok( r == S_OK, "getNamedItem returned wrong code\n");
ok( node != NULL, "should be attributes\n");
IXMLDOMNode_Release(node);
SysFreeString( str );
str = SysAllocString( szdl );
r = IXMLDOMNamedNodeMap_getNamedItem( map, str, NULL );
ok( r == E_INVALIDARG, "getNamedItem should return E_INVALIDARG\n");
SysFreeString( str );
/* something that isn't in szComplete4 */
str = SysAllocString( szOpen );
node = (IXMLDOMNode *) 1;
r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
ok( r = S_FALSE, "getNamedItem found a node that wasn't there\n");
ok( node == NULL, "getNamedItem should have returned NULL\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\n");
/* 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");
if (node)
{
type = NODE_INVALID;
r = IXMLDOMNode_get_nodeType( node, &type);
ok( r == S_OK, "getNamedItem returned wrong code\n");
ok( type == NODE_ATTRIBUTE, "node not an attribute\n");
str = NULL;
r = IXMLDOMNode_get_baseName( node, NULL );
ok( r == E_INVALIDARG, "get_baseName returned wrong code\n");
str = NULL;
r = IXMLDOMNode_get_baseName( node, &str );
ok( r == S_OK, "get_baseName returned wrong code\n");
ok( lstrcmpW(str,szdl) == 0, "basename was wrong\n");
r = IXMLDOMNode_get_nodeValue( node, &var );
ok( r == S_OK, "returns %08x\n", r );
ok( V_VT(&var) == VT_BSTR, "vt %x\n", V_VT(&var));
ok( !lstrcmpW(V_BSTR(&var), szstr1), "nodeValue incorrect\n");
VariantClear(&var);
r = IXMLDOMNode_get_childNodes( node, NULL );
ok( r == E_INVALIDARG, "get_childNodes returned wrong code\n");
r = IXMLDOMNode_get_childNodes( node, &list );
ok( r == S_OK, "get_childNodes returned wrong code\n");
if (list)
{
r = IXMLDOMNodeList_nextNode( list, &next );
ok( r == S_OK, "nextNode returned wrong code\n");
}
else
ok( FALSE, "no childlist\n");
if (next)
{
b = 1;
r = IXMLDOMNode_hasChildNodes( next, &b );
ok( r == S_FALSE, "hasChildNoes bad return\n");
ok( b == VARIANT_FALSE, "hasChildNoes wrong result\n");
type = NODE_INVALID;
r = IXMLDOMNode_get_nodeType( next, &type);
ok( r == S_OK, "getNamedItem returned wrong code\n");
ok( type == NODE_TEXT, "node not text\n");
str = (BSTR) 1;
r = IXMLDOMNode_get_baseName( next, &str );
ok( r == S_FALSE, "get_baseName returned wrong code\n");
ok( str == NULL, "basename was wrong\n");
}
else
ok( FALSE, "no next\n");
if (next)
IXMLDOMNode_Release( next );
next = NULL;
if (list)
IXMLDOMNodeList_Release( list );
list = NULL;
if (node)
IXMLDOMNode_Release( node );
}
else
ok( FALSE, "no node\n");
node = NULL;
if (map)
IXMLDOMNamedNodeMap_Release( map );
/* now traverse the tree from the root node */
if (element)
{
r = IXMLDOMNode_get_childNodes( element, &list );
ok( r == S_OK, "get_childNodes returned wrong code\n");
}
else
ok( FALSE, "no element\n");
node = (void*)0xdeadbeef;
r = IXMLDOMNode_selectSingleNode( element, (BSTR)szdl, &node );
ok( r == S_FALSE, "ret %08x\n", r );
ok( node == NULL, "node %p\n", node );
r = IXMLDOMNode_selectSingleNode( element, (BSTR)szbs, &node );
ok( r == S_OK, "ret %08x\n", r );
r = IXMLDOMNode_Release( node );
ok( r == 0, "ret %08x\n", r );
if (list)
{
r = IXMLDOMNodeList_get_length( list, &count );
ok( r == S_OK, "get_length returns %08x\n", r );
ok( count == 4, "get_length got %ld\n", count );
r = IXMLDOMNodeList_nextNode( list, &node );
ok( r == S_OK, "nextNode returned wrong code\n");
}
else
ok( FALSE, "no list\n");
if (node)
{
type = NODE_INVALID;
r = IXMLDOMNode_get_nodeType( node, &type);
ok( r == S_OK, "getNamedItem returned wrong code\n");
ok( type == NODE_ELEMENT, "node not text\n");
VariantInit(&var);
ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
r = IXMLDOMNode_get_nodeValue( node, &var );
ok( r == S_FALSE, "nextNode returned wrong code\n");
ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
r = IXMLDOMNode_hasChildNodes( node, NULL );
ok( r == E_INVALIDARG, "hasChildNoes bad return\n");
b = 1;
r = IXMLDOMNode_hasChildNodes( node, &b );
ok( r == S_OK, "hasChildNoes bad return\n");
ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
str = NULL;
r = IXMLDOMNode_get_baseName( node, &str );
ok( r == S_OK, "get_baseName returned wrong code\n");
ok( lstrcmpW(str,szbs) == 0, "basename was wrong\n");
}
else
ok( FALSE, "no node\n");
if (node)
IXMLDOMNode_Release( node );
if (list)
IXMLDOMNodeList_Release( list );
if (element)
IXMLDOMElement_Release( element );
b = FALSE;
str = SysAllocString( szComplete5 );
r = IXMLDOMDocument_loadXML( doc, str, &b );
ok( r == S_OK, "loadXML failed\n");
ok( b == VARIANT_TRUE, "failed to load XML string\n");
SysFreeString( str );
b = 1;
r = IXMLDOMNode_hasChildNodes( doc, &b );
ok( r == S_OK, "hasChildNoes bad return\n");
ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
r = IXMLDOMDocument_get_documentElement( doc, &element );
ok( r == S_OK, "should be a document element\n");
ok( element != NULL, "should be an element\n");
if (element)
{
static const WCHAR szSSearch[] = {'S',':','s','e','a','r','c','h',0};
BSTR tag = NULL;
/* check if the tag is correct */
r = IXMLDOMElement_get_tagName( element, &tag );
ok( r == S_OK, "couldn't get tag name\n");
ok( tag != NULL, "tag was null\n");
ok( !lstrcmpW( tag, szSSearch ), "incorrect tag name\n");
SysFreeString( tag );
}
if (element)
IXMLDOMElement_Release( element );
if (doc)
IXMLDOMDocument_Release( doc );
}
static void test_refs(void)
{
HRESULT r;
BSTR str;
VARIANT_BOOL b;
IXMLDOMDocument *doc = NULL;
IXMLDOMElement *element = NULL;
IXMLDOMNode *node = NULL, *node2;
IXMLDOMNodeList *node_list = NULL;
LONG ref;
IUnknown *unk, *unk2;
r = CoCreateInstance( &CLSID_DOMDocument, NULL,
CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
if( r != S_OK )
return;
ref = IXMLDOMDocument_Release(doc);
ok( ref == 0, "ref %d\n", ref);
r = CoCreateInstance( &CLSID_DOMDocument, NULL,
CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
if( r != S_OK )
return;
str = SysAllocString( szComplete4 );
r = IXMLDOMDocument_loadXML( doc, str, &b );
ok( r == S_OK, "loadXML failed\n");
ok( b == VARIANT_TRUE, "failed to load XML string\n");
SysFreeString( str );
ref = IXMLDOMDocument_AddRef( doc );
ok( ref == 2, "ref %d\n", ref );
ref = IXMLDOMDocument_AddRef( doc );
ok( ref == 3, "ref %d\n", ref );
IXMLDOMDocument_Release( doc );
IXMLDOMDocument_Release( doc );
r = IXMLDOMDocument_get_documentElement( doc, &element );
ok( r == S_OK, "should be a document element\n");
ok( element != NULL, "should be an element\n");
ref = IXMLDOMDocument_AddRef( doc );
ok( ref == 2, "ref %d\n", ref );
IXMLDOMDocument_Release( doc );
r = IXMLDOMElement_get_childNodes( element, &node_list );
ok( r == S_OK, "rets %08x\n", r);
ref = IXMLDOMNodeList_AddRef( node_list );
ok( ref == 2, "ref %d\n", ref );
IXMLDOMNodeList_Release( node_list );
IXMLDOMNodeList_get_item( node_list, 0, &node );
ok( r == S_OK, "rets %08x\n", r);
IXMLDOMNodeList_get_item( node_list, 0, &node2 );
ok( r == S_OK, "rets %08x\n", r);
ref = IXMLDOMNode_AddRef( node );
ok( ref == 2, "ref %d\n", ref );
IXMLDOMNode_Release( node );
ref = IXMLDOMNode_Release( node );
ok( ref == 0, "ref %d\n", ref );
ref = IXMLDOMNode_Release( node2 );
ok( ref == 0, "ref %d\n", ref );
ref = IXMLDOMNodeList_Release( node_list );
ok( ref == 0, "ref %d\n", ref );
ok( node != node2, "node %p node2 %p\n", node, node2 );
ref = IXMLDOMDocument_Release( doc );
ok( ref == 0, "ref %d\n", ref );
ref = IXMLDOMElement_AddRef( element );
todo_wine {
ok( ref == 3, "ref %d\n", ref );
}
IXMLDOMElement_Release( element );
/* IUnknown must be unique however we obtain it */
r = IXMLDOMElement_QueryInterface( element, &IID_IUnknown, (LPVOID*)&unk );
ok( r == S_OK, "rets %08x\n", r );
r = IXMLDOMElement_QueryInterface( element, &IID_IXMLDOMNode, (LPVOID*)&node );
ok( r == S_OK, "rets %08x\n", r );
r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk2 );
ok( r == S_OK, "rets %08x\n", r );
ok( unk == unk2, "unk %p unk2 %p\n", unk, unk2 );
IUnknown_Release( unk2 );
IUnknown_Release( unk );
IXMLDOMNode_Release( node );
IXMLDOMElement_Release( element );
}
static void test_create(void)
{
HRESULT r;
VARIANT var;
BSTR str, name;
IXMLDOMDocument *doc;
IXMLDOMElement *element;
IXMLDOMNode *root, *node, *child;
IXMLDOMNamedNodeMap *attr_map;
IUnknown *unk;
LONG ref;
long num;
r = CoCreateInstance( &CLSID_DOMDocument, NULL,
CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
if( r != S_OK )
return;
V_VT(&var) = VT_I4;
V_I4(&var) = NODE_ELEMENT;
str = SysAllocString( szlc );
r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
ok( r == S_OK, "returns %08x\n", r );
r = IXMLDOMDocument_appendChild( doc, node, &root );
ok( r == S_OK, "returns %08x\n", r );
ok( node == root, "%p %p\n", node, root );
ref = IXMLDOMNode_AddRef( node );
ok(ref == 3, "ref %d\n", ref);
IXMLDOMNode_Release( node );
ref = IXMLDOMNode_Release( node );
ok(ref == 1, "ref %d\n", ref);
SysFreeString( str );
V_VT(&var) = VT_I4;
V_I4(&var) = NODE_ELEMENT;
str = SysAllocString( szbs );
r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
ok( r == S_OK, "returns %08x\n", r );
ref = IXMLDOMNode_AddRef( node );
ok(ref == 2, "ref = %d\n", ref);
IXMLDOMNode_Release( node );
r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk );
ok( r == S_OK, "returns %08x\n", r );
ref = IXMLDOMNode_AddRef( unk );
ok(ref == 3, "ref = %d\n", ref);
IXMLDOMNode_Release( unk );
V_VT(&var) = VT_EMPTY;
r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
ok( r == S_OK, "returns %08x\n", r );
ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
IXMLDOMNode_Release( child );
IUnknown_Release( unk );
V_VT(&var) = VT_NULL;
V_DISPATCH(&var) = (IDispatch*)node;
r = IXMLDOMNode_insertBefore( root, node, var, &child );
ok( r == S_OK, "returns %08x\n", r );
ok( node == child, "%p %p\n", node, child );
IXMLDOMNode_Release( child );
IXMLDOMNode_Release( node );
r = IXMLDOMNode_QueryInterface( root, &IID_IXMLDOMElement, (LPVOID*)&element );
ok( r == S_OK, "returns %08x\n", r );
r = IXMLDOMElement_get_attributes( element, &attr_map );
ok( r == S_OK, "returns %08x\n", r );
r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
ok( r == S_OK, "returns %08x\n", r );
ok( num == 0, "num %ld\n", num );
IXMLDOMNamedNodeMap_Release( attr_map );
V_VT(&var) = VT_BSTR;
V_BSTR(&var) = SysAllocString( szstr1 );
name = SysAllocString( szdl );
r = IXMLDOMElement_setAttribute( element, name, var );
ok( r == S_OK, "returns %08x\n", r );
r = IXMLDOMElement_get_attributes( element, &attr_map );
ok( r == S_OK, "returns %08x\n", r );
r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
ok( r == S_OK, "returns %08x\n", r );
ok( num == 1, "num %ld\n", num );
IXMLDOMNamedNodeMap_Release( attr_map );
VariantClear(&var);
V_VT(&var) = VT_BSTR;
V_BSTR(&var) = SysAllocString( szstr2 );
r = IXMLDOMElement_setAttribute( element, name, var );
ok( r == S_OK, "returns %08x\n", r );
r = IXMLDOMElement_get_attributes( element, &attr_map );
ok( r == S_OK, "returns %08x\n", r );
r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
ok( r == S_OK, "returns %08x\n", r );
ok( num == 1, "num %ld\n", num );
IXMLDOMNamedNodeMap_Release( attr_map );
VariantClear(&var);
r = IXMLDOMElement_getAttribute( element, name, &var );
ok( r == S_OK, "returns %08x\n", r );
ok( !lstrcmpW(V_BSTR(&var), szstr2), "wrong attr value\n");
VariantClear(&var);
SysFreeString(name);
V_VT(&var) = VT_BSTR;
V_BSTR(&var) = SysAllocString( szstr1 );
name = SysAllocString( szlc );
r = IXMLDOMElement_setAttribute( element, name, var );
ok( r == S_OK, "returns %08x\n", r );
r = IXMLDOMElement_get_attributes( element, &attr_map );
ok( r == S_OK, "returns %08x\n", r );
r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
ok( r == S_OK, "returns %08x\n", r );
ok( num == 2, "num %ld\n", num );
IXMLDOMNamedNodeMap_Release( attr_map );
VariantClear(&var);
SysFreeString(name);
V_VT(&var) = VT_I4;
V_I4(&var) = 10;
name = SysAllocString( szbs );
r = IXMLDOMElement_setAttribute( element, name, var );
ok( r == S_OK, "returns %08x\n", r );
VariantClear(&var);
r = IXMLDOMElement_getAttribute( element, name, &var );
ok( r == S_OK, "returns %08x\n", r );
ok( V_VT(&var) == VT_BSTR, "variant type %x\n", V_VT(&var));
VariantClear(&var);
SysFreeString(name);
IXMLDOMElement_Release( element );
IXMLDOMNode_Release( root );
IXMLDOMDocument_Release( doc );
}
static void test_getElementsByTagName(void)
{
HRESULT r;
BSTR str;
VARIANT_BOOL b;
IXMLDOMDocument *doc;
IXMLDOMNodeList *node_list;
long len;
r = CoCreateInstance( &CLSID_DOMDocument, NULL,
CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
if( r != S_OK )
return;
str = SysAllocString( szComplete4 );
r = IXMLDOMDocument_loadXML( doc, str, &b );
ok( r == S_OK, "loadXML failed\n");
ok( b == VARIANT_TRUE, "failed to load XML string\n");
SysFreeString( str );
str = SysAllocString( szstar );
r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
ok( r == S_OK, "ret %08x\n", r );
r = IXMLDOMNodeList_get_length( node_list, &len );
ok( r == S_OK, "ret %08x\n", r );
ok( len == 6, "len %ld\n", len );
IXMLDOMNodeList_Release( node_list );
SysFreeString( str );
str = SysAllocString( szbs );
r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
ok( r == S_OK, "ret %08x\n", r );
r = IXMLDOMNodeList_get_length( node_list, &len );
ok( r == S_OK, "ret %08x\n", r );
ok( len == 1, "len %ld\n", len );
IXMLDOMNodeList_Release( node_list );
SysFreeString( str );
str = SysAllocString( szdl );
r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
ok( r == S_OK, "ret %08x\n", r );
r = IXMLDOMNodeList_get_length( node_list, &len );
ok( r == S_OK, "ret %08x\n", r );
ok( len == 0, "len %ld\n", len );
IXMLDOMNodeList_Release( node_list );
SysFreeString( str );
str = SysAllocString( szstr1 );
r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
ok( r == S_OK, "ret %08x\n", r );
r = IXMLDOMNodeList_get_length( node_list, &len );
ok( r == S_OK, "ret %08x\n", r );
ok( len == 0, "len %ld\n", len );
IXMLDOMNodeList_Release( node_list );
SysFreeString( str );
IXMLDOMDocument_Release( doc );
}
static void test_get_text(void)
{
HRESULT r;
BSTR str;
VARIANT_BOOL b;
IXMLDOMDocument *doc;
IXMLDOMNode *node, *node2, *node3;
IXMLDOMNodeList *node_list;
IXMLDOMNamedNodeMap *node_map;
r = CoCreateInstance( &CLSID_DOMDocument, NULL,
CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
if( r != S_OK )
return;
str = SysAllocString( szComplete4 );
r = IXMLDOMDocument_loadXML( doc, str, &b );
ok( r == S_OK, "loadXML failed\n");
ok( b == VARIANT_TRUE, "failed to load XML string\n");
SysFreeString( str );
str = SysAllocString( szbs );
r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
ok( r == S_OK, "ret %08x\n", r );
SysFreeString(str);
r = IXMLDOMNodeList_get_item( node_list, 0, &node );
ok( r == S_OK, "ret %08x\n", r );
IXMLDOMNodeList_Release( node_list );
r = IXMLDOMNode_get_text( node, &str );
ok( r == S_OK, "ret %08x\n", r );
todo_wine {
ok( !memcmp(str, szfn1_txt, sizeof(szfn1_txt)), "wrong string\n" );
}
ok( !memcmp(str, szfn1_txt, sizeof(szfn1_txt)-4), "wrong string\n" );
SysFreeString(str);
r = IXMLDOMNode_get_attributes( node, &node_map );
ok( r == S_OK, "ret %08x\n", r );
str = SysAllocString( szvr );
r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
ok( r == S_OK, "ret %08x\n", r );
SysFreeString(str);
r = IXMLDOMNode_get_text( node2, &str );
ok( r == S_OK, "ret %08x\n", r );
ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
SysFreeString(str);
r = IXMLDOMNode_get_firstChild( node2, &node3 );
ok( r == S_OK, "ret %08x\n", r );
r = IXMLDOMNode_get_text( node3, &str );
ok( r == S_OK, "ret %08x\n", r );
ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
SysFreeString(str);
IXMLDOMNode_Release( node3 );
IXMLDOMNode_Release( node2 );
IXMLDOMNamedNodeMap_Release( node_map );
IXMLDOMNode_Release( node );
IXMLDOMDocument_Release( doc );
}
static void test_get_childNodes(void)
{
HRESULT r;
BSTR str;
VARIANT_BOOL b;
IXMLDOMDocument *doc;
IXMLDOMElement *element;
IXMLDOMNode *node, *node2;
IXMLDOMNodeList *node_list, *node_list2;
long len;
r = CoCreateInstance( &CLSID_DOMDocument, NULL,
CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
if( r != S_OK )
return;
str = SysAllocString( szComplete4 );
r = IXMLDOMDocument_loadXML( doc, str, &b );
ok( r == S_OK, "loadXML failed\n");
ok( b == VARIANT_TRUE, "failed to load XML string\n");
SysFreeString( str );
r = IXMLDOMDocument_get_documentElement( doc, &element );
ok( r == S_OK, "ret %08x\n", r);
r = IXMLDOMElement_get_childNodes( element, &node_list );
ok( r == S_OK, "ret %08x\n", r);
r = IXMLDOMNodeList_get_length( node_list, &len );
ok( r == S_OK, "ret %08x\n", r);
ok( len == 4, "len %ld\n", len);
r = IXMLDOMNodeList_get_item( node_list, 2, &node );
ok( r == S_OK, "ret %08x\n", r);
r = IXMLDOMNode_get_childNodes( node, &node_list2 );
ok( r == S_OK, "ret %08x\n", r);
r = IXMLDOMNodeList_get_length( node_list2, &len );
ok( r == S_OK, "ret %08x\n", r);
ok( len == 0, "len %ld\n", len);
r = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
ok( r == S_FALSE, "ret %08x\n", r);
IXMLDOMNodeList_Release( node_list2 );
IXMLDOMNode_Release( node );
IXMLDOMNodeList_Release( node_list );
IXMLDOMElement_Release( element );
IXMLDOMDocument_Release( doc );
}
static void test_removeChild(void)
{
HRESULT r;
BSTR str;
VARIANT_BOOL b;
IXMLDOMDocument *doc;
IXMLDOMElement *element;
IXMLDOMNode *node, *node2, *node3, *node4;
IXMLDOMNodeList *node_list, *node_list2;
r = CoCreateInstance( &CLSID_DOMDocument, NULL,
CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
if( r != S_OK )
return;
str = SysAllocString( szComplete4 );
r = IXMLDOMDocument_loadXML( doc, str, &b );
ok( r == S_OK, "loadXML failed\n");
ok( b == VARIANT_TRUE, "failed to load XML string\n");
SysFreeString( str );
r = IXMLDOMDocument_get_documentElement( doc, &element );
ok( r == S_OK, "ret %08x\n", r);
r = IXMLDOMElement_get_childNodes( element, &node_list );
ok( r == S_OK, "ret %08x\n", r);
r = IXMLDOMNodeList_get_item( node_list, 3, &node );
ok( r == S_OK, "ret %08x\n", r);
r = IXMLDOMNode_get_childNodes( node, &node_list2 );
ok( r == S_OK, "ret %08x\n", r);
r = IXMLDOMNodeList_get_item( node_list, 0, &node4 );
ok( r == S_OK, "ret %08x\n", r);
r = IXMLDOMElement_removeChild( element, NULL, &node2 );
ok( r == E_INVALIDARG, "ret %08x\n", r );
r = IXMLDOMElement_removeChild( element, node4, &node2 );
ok( r == S_OK, "ret %08x\n", r);
ok( node4 == node2, "node %p node2 %p\n", node4, node2 );
r = IXMLDOMNode_get_parentNode( node4, &node3 );
ok( r == S_FALSE, "ret %08x\n", r);
ok( node3 == NULL, "%p\n", node3 );
IXMLDOMNode_Release( node2 );
IXMLDOMNode_Release( node4 );
IXMLDOMNodeList_Release( node_list2 );
IXMLDOMNode_Release( node );
IXMLDOMNodeList_Release( node_list );
IXMLDOMElement_Release( element );
IXMLDOMDocument_Release( doc );
}
START_TEST(domdoc)
{
HRESULT r;
r = CoInitialize( NULL );
ok( r == S_OK, "failed to init com\n");
test_domdoc();
test_domnode();
test_refs();
test_create();
test_getElementsByTagName();
test_get_text();
test_get_childNodes();
test_removeChild();
CoUninitialize();
}