msxml3: Reimplement IXMLDOMDocument::createComment() on top of ::createNode().

This commit is contained in:
Nikolay Sivov 2010-02-12 21:26:50 +03:00 committed by Alexandre Julliard
parent dd40448707
commit 760f7ba724
3 changed files with 89 additions and 18 deletions

View File

@ -1105,29 +1105,28 @@ static HRESULT WINAPI domdoc_createComment(
IXMLDOMComment** comment ) IXMLDOMComment** comment )
{ {
domdoc *This = impl_from_IXMLDOMDocument2( iface ); domdoc *This = impl_from_IXMLDOMDocument2( iface );
xmlNodePtr xmlnode; VARIANT type;
xmlChar *xml_content; HRESULT hr;
IXMLDOMNode *node;
TRACE("%p->(%s %p)\n", iface, debugstr_w(data), comment); TRACE("%p->(%s %p)\n", This, debugstr_w(data), comment);
if(!comment) if (!comment) return E_INVALIDARG;
return E_INVALIDARG;
*comment = NULL; *comment = NULL;
xml_content = xmlChar_from_wchar(data); V_VT(&type) = VT_I1;
xmlnode = xmlNewComment(xml_content); V_I1(&type) = NODE_COMMENT;
heap_free(xml_content);
if(!xmlnode) hr = IXMLDOMDocument2_createNode(iface, type, NULL, NULL, &node);
return E_FAIL; if (hr == S_OK)
{
IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)comment);
IXMLDOMNode_Release(node);
hr = IXMLDOMComment_put_data(*comment, data);
}
xmlnode->doc = get_doc( This ); return hr;
xmldoc_add_orphan(xmlnode->doc, xmlnode);
*comment = (IXMLDOMComment*)create_comment(xmlnode);
return S_OK;
} }

View File

@ -174,6 +174,8 @@ static inline BSTR bstr_from_xmlChar(const xmlChar *str)
if(ret) if(ret)
MultiByteToWideChar( CP_UTF8, 0, (LPCSTR)str, -1, ret, len); MultiByteToWideChar( CP_UTF8, 0, (LPCSTR)str, -1, ret, len);
} }
else
ret = SysAllocStringLen(NULL, 0);
return ret; return ret;
} }

View File

@ -969,6 +969,27 @@ static void test_domdoc( void )
/* test Create Comment */ /* test Create Comment */
r = IXMLDOMDocument_createComment(doc, NULL, NULL); r = IXMLDOMDocument_createComment(doc, NULL, NULL);
ok( r == E_INVALIDARG, "returns %08x\n", r ); ok( r == E_INVALIDARG, "returns %08x\n", r );
node_comment = (IXMLDOMComment*)0x1;
/* empty comment */
r = IXMLDOMDocument_createComment(doc, _bstr_(""), &node_comment);
ok( r == S_OK, "returns %08x\n", r );
str = (BSTR)0x1;
r = IXMLDOMComment_get_data(node_comment, &str);
ok( r == S_OK, "returns %08x\n", r );
ok( str && SysStringLen(str) == 0, "expected empty string data\n");
IXMLDOMComment_Release(node_comment);
SysFreeString(str);
r = IXMLDOMDocument_createComment(doc, NULL, &node_comment);
ok( r == S_OK, "returns %08x\n", r );
str = (BSTR)0x1;
r = IXMLDOMComment_get_data(node_comment, &str);
ok( r == S_OK, "returns %08x\n", r );
ok( str && (SysStringLen(str) == 0), "expected empty string data\n");
IXMLDOMComment_Release(node_comment);
SysFreeString(str);
str = SysAllocString(szComment); str = SysAllocString(szComment);
r = IXMLDOMDocument_createComment(doc, str, &node_comment); r = IXMLDOMDocument_createComment(doc, str, &node_comment);
SysFreeString(str); SysFreeString(str);
@ -1655,6 +1676,7 @@ static void test_create(void)
BSTR str, name; BSTR str, name;
IXMLDOMDocument *doc; IXMLDOMDocument *doc;
IXMLDOMElement *element; IXMLDOMElement *element;
IXMLDOMComment *comment;
IXMLDOMNode *root, *node, *child; IXMLDOMNode *root, *node, *child;
IXMLDOMNamedNodeMap *attr_map; IXMLDOMNamedNodeMap *attr_map;
IUnknown *unk; IUnknown *unk;
@ -1695,6 +1717,54 @@ static void test_create(void)
ok( r == E_INVALIDARG, "returns %08x\n", r ); ok( r == E_INVALIDARG, "returns %08x\n", r );
ok( node == (void*)0x1, "expected same ptr, got %p\n", node); ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
/* NODE_COMMENT */
V_VT(&var) = VT_I1;
V_I1(&var) = NODE_COMMENT;
node = NULL;
r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
ok( r == S_OK, "returns %08x\n", r );
ok( node != NULL, "\n");
r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
ok( r == S_OK, "returns %08x\n", r );
IXMLDOMNode_Release(node);
str = NULL;
r = IXMLDOMComment_get_data(comment, &str);
ok( r == S_OK, "returns %08x\n", r );
ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
IXMLDOMComment_Release(comment);
SysFreeString(str);
node = (IXMLDOMNode*)0x1;
r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
ok( r == S_OK, "returns %08x\n", r );
r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
ok( r == S_OK, "returns %08x\n", r );
IXMLDOMNode_Release(node);
str = NULL;
r = IXMLDOMComment_get_data(comment, &str);
ok( r == S_OK, "returns %08x\n", r );
ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
IXMLDOMComment_Release(comment);
node = (IXMLDOMNode*)0x1;
r = IXMLDOMDocument_createNode( doc, var, _bstr_("blah"), NULL, &node );
ok( r == S_OK, "returns %08x\n", r );
r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
ok( r == S_OK, "returns %08x\n", r );
IXMLDOMNode_Release(node);
str = NULL;
r = IXMLDOMComment_get_data(comment, &str);
ok( r == S_OK, "returns %08x\n", r );
ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
IXMLDOMComment_Release(comment);
/* NODE_ELEMENT */
V_VT(&var) = VT_I1; V_VT(&var) = VT_I1;
V_I1(&var) = NODE_ELEMENT; V_I1(&var) = NODE_ELEMENT;
str = SysAllocString( szlc ); str = SysAllocString( szlc );
@ -2920,7 +2990,7 @@ static void test_xmlTypes(void)
{ {
/* Comment */ /* Comment */
str = SysAllocString(szComment); str = SysAllocString(szComment);
hr = IXMLDOMDocument_createComment(doc, szComment, &pComment); hr = IXMLDOMDocument_createComment(doc, str, &pComment);
SysFreeString(str); SysFreeString(str);
ok(hr == S_OK, "ret %08x\n", hr ); ok(hr == S_OK, "ret %08x\n", hr );
if(hr == S_OK) if(hr == S_OK)
@ -3200,7 +3270,7 @@ static void test_xmlTypes(void)
/* Attribute */ /* Attribute */
str = SysAllocString(szAttribute); str = SysAllocString(szAttribute);
hr = IXMLDOMDocument_createAttribute(doc, szAttribute, &pAttrubute); hr = IXMLDOMDocument_createAttribute(doc, str, &pAttrubute);
SysFreeString(str); SysFreeString(str);
ok(hr == S_OK, "ret %08x\n", hr ); ok(hr == S_OK, "ret %08x\n", hr );
if(hr == S_OK) if(hr == S_OK)