Add some node tests.

This commit is contained in:
Mike McCormack 2005-08-23 09:37:42 +00:00 committed by Alexandre Julliard
parent f49f36f9eb
commit 3b7e1ed1ea
1 changed files with 260 additions and 43 deletions

View File

@ -29,57 +29,58 @@
#include "wine/test.h"
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','\'','?','>',
'<','l','c',' ','d','l','=','\'','s','t','r','1','\'','>',
'<','b','s',' ','v','r','=','\'','s','t','r','2','\'',' ',
's','z','=','\'','1','2','3','4','\'','>','f','n','1','.','t','x','t','<','/','b','s','>',
'<','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','\'','>',
'f','n','2','.','t','x','t','<','/','p','r','>',
'<','/','l','c','>','\n',0
};
static const WCHAR szOpen[] = { 'o','p','e','n',0 };
static const WCHAR szdl[] = { 'd','l',0 };
static const WCHAR szlc[] = { 'l','c',0 };
static const WCHAR szbs[] = { 'b','s',0 };
const GUID CLSID_DOMDocument =
{ 0x2933BF90, 0x7B36, 0x11d2, {0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
const GUID IID_IXMLDOMDocument =
{ 0x2933BF81, 0x7B36, 0x11d2, {0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
void test_domdoc( void )
{
HRESULT r;
IXMLDOMDocument *doc = NULL;
IXMLDOMElement *element = NULL;
static const GUID CLSID_DOMDocument =
{ 0x2933BF90, 0x7B36, 0x11d2, {0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
static const GUID IID_IXMLDOMDocument =
{ 0x2933BF81, 0x7B36, 0x11d2, {0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
VARIANT_BOOL b;
BSTR str;
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','\'','?','>',
'<','l','c',' ','d','l','=','\'','s','t','r','1','\'','>',
'<','b','s',' ','v','r','=','\'','s','t','r','2','\'',' ',
's','z','=','\'','1','2','3','4','\'','>','f','n','1','.','t','x','t','<','/','b','s','>',
'<','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','\'','>',
'f','n','2','.','t','x','t','<','/','p','r','>',
'<','/','l','c','>','\n',0
};
static const WCHAR szOpen[] = { 'o','p','e','n',0 };
r = CoInitialize( NULL );
ok( r == S_OK, "failed to init com\n");
r = CoCreateInstance( &CLSID_DOMDocument, NULL,
CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
/* ok( r == S_OK, "failed to create an xml dom doc\n" ); */
if( r != S_OK )
return;
@ -194,11 +195,227 @@ void test_domdoc( void )
r = IXMLDocument_Release( doc );
ok( r == 0, "document ref count incorrect\n");
CoUninitialize();
ok( r == S_OK, "failed to uninit com\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;
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");
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)
{
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");
}
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_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");
if (list)
{
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 );
if (doc)
IXMLDocument_Release( doc );
}
START_TEST(domdoc)
{
HRESULT r;
r = CoInitialize( NULL );
ok( r == S_OK, "failed to init com\n");
test_domdoc();
test_domnode();
CoUninitialize();
}