Commit f414d3cf authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

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

parent f0e88575
...@@ -1227,29 +1227,25 @@ static HRESULT WINAPI domdoc_createAttribute( ...@@ -1227,29 +1227,25 @@ static HRESULT WINAPI domdoc_createAttribute(
IXMLDOMAttribute** attribute ) IXMLDOMAttribute** attribute )
{ {
domdoc *This = impl_from_IXMLDOMDocument2( iface ); domdoc *This = impl_from_IXMLDOMDocument2( iface );
xmlNodePtr xmlnode; IXMLDOMNode *node;
xmlChar *xml_name; VARIANT type;
HRESULT hr;
TRACE("%p->(%s %p)\n", iface, debugstr_w(name), attribute);
if(!attribute)
return E_INVALIDARG;
*attribute = NULL;
xml_name = xmlChar_from_wchar(name); TRACE("%p->(%s %p)\n", This, debugstr_w(name), attribute);
xmlnode = (xmlNode *)xmlNewProp(NULL, xml_name, NULL);
heap_free(xml_name);
if(!xmlnode) if (!attribute || !name) return E_INVALIDARG;
return E_FAIL;
xmlnode->doc = get_doc( This ); V_VT(&type) = VT_I1;
xmldoc_add_orphan(xmlnode->doc, xmlnode); V_I1(&type) = NODE_ATTRIBUTE;
*attribute = (IXMLDOMAttribute*)create_attribute(xmlnode); hr = IXMLDOMDocument_createNode(iface, type, name, NULL, &node);
if (hr == S_OK)
{
IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMAttribute, (void**)attribute);
IXMLDOMNode_Release(node);
}
return S_OK; return hr;
} }
...@@ -1356,8 +1352,16 @@ static HRESULT WINAPI domdoc_createNode( ...@@ -1356,8 +1352,16 @@ static HRESULT WINAPI domdoc_createNode(
TRACE("node_type %d\n", node_type); TRACE("node_type %d\n", node_type);
if ((!name || SysStringLen(name) == 0) && (node_type == NODE_ELEMENT)) /* exit earlier for types that need name */
return E_FAIL; switch(node_type)
{
case NODE_ELEMENT:
case NODE_ATTRIBUTE:
case NODE_PROCESSING_INSTRUCTION:
if (!name || SysStringLen(name) == 0) return E_FAIL;
default:
break;
}
xml_name = xmlChar_from_wchar(name); xml_name = xmlChar_from_wchar(name);
......
...@@ -1864,6 +1864,29 @@ static void test_create(void) ...@@ -1864,6 +1864,29 @@ static void test_create(void)
ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str); ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
IXMLDOMCDATASection_Release(cdata); IXMLDOMCDATASection_Release(cdata);
/* NODE_ATTRIBUTE */
V_VT(&var) = VT_I1;
V_I1(&var) = NODE_ATTRIBUTE;
str = SysAllocString( szlc );
node = (IXMLDOMNode*)0x1;
r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
ok( r == E_FAIL, "returns %08x\n", r );
ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
V_VT(&var) = VT_I1;
V_I1(&var) = NODE_ATTRIBUTE;
node = (IXMLDOMNode*)0x1;
r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
ok( r == E_FAIL, "returns %08x\n", r );
ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
V_VT(&var) = VT_I1;
V_I1(&var) = NODE_ATTRIBUTE;
str = SysAllocString( szlc );
r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
ok( r == S_OK, "returns %08x\n", r );
if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
/* NODE_ELEMENT */ /* NODE_ELEMENT */
V_VT(&var) = VT_I1; V_VT(&var) = VT_I1;
V_I1(&var) = NODE_ELEMENT; V_I1(&var) = NODE_ELEMENT;
...@@ -2965,7 +2988,7 @@ static void test_xmlTypes(void) ...@@ -2965,7 +2988,7 @@ static void test_xmlTypes(void)
HRESULT hr; HRESULT hr;
IXMLDOMComment *pComment; IXMLDOMComment *pComment;
IXMLDOMElement *pElement; IXMLDOMElement *pElement;
IXMLDOMAttribute *pAttrubute; IXMLDOMAttribute *pAttribute;
IXMLDOMNamedNodeMap *pAttribs; IXMLDOMNamedNodeMap *pAttribs;
IXMLDOMCDATASection *pCDataSec; IXMLDOMCDATASection *pCDataSec;
IXMLDOMImplementation *pIXMLDOMImplementation = NULL; IXMLDOMImplementation *pIXMLDOMImplementation = NULL;
...@@ -3369,41 +3392,51 @@ static void test_xmlTypes(void) ...@@ -3369,41 +3392,51 @@ static void test_xmlTypes(void)
VariantClear(&v); VariantClear(&v);
/* Attribute */ /* Attribute */
pAttribute = (IXMLDOMAttribute*)0x1;
hr = IXMLDOMDocument_createAttribute(doc, NULL, &pAttribute);
ok(hr == E_INVALIDARG, "ret %08x\n", hr );
ok(pAttribute == (void*)0x1, "Expect same ptr, got %p\n", pAttribute);
pAttribute = (IXMLDOMAttribute*)0x1;
hr = IXMLDOMDocument_createAttribute(doc, _bstr_(""), &pAttribute);
ok(hr == E_FAIL, "ret %08x\n", hr );
ok(pAttribute == (void*)0x1, "Expect same ptr, got %p\n", pAttribute);
str = SysAllocString(szAttribute); str = SysAllocString(szAttribute);
hr = IXMLDOMDocument_createAttribute(doc, str, &pAttrubute); hr = IXMLDOMDocument_createAttribute(doc, str, &pAttribute);
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)
{ {
IXMLDOMNode *pNewChild = (IXMLDOMNode *)0x1; IXMLDOMNode *pNewChild = (IXMLDOMNode *)0x1;
hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, NULL); hr = IXMLDOMAttribute_get_nextSibling(pAttribute, NULL);
ok(hr == E_INVALIDARG, "ret %08x\n", hr ); ok(hr == E_INVALIDARG, "ret %08x\n", hr );
pNextChild = (IXMLDOMNode *)0x1; pNextChild = (IXMLDOMNode *)0x1;
hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, &pNextChild); hr = IXMLDOMAttribute_get_nextSibling(pAttribute, &pNextChild);
ok(hr == S_FALSE, "ret %08x\n", hr ); ok(hr == S_FALSE, "ret %08x\n", hr );
ok(pNextChild == NULL, "pNextChild not NULL\n"); ok(pNextChild == NULL, "pNextChild not NULL\n");
/* test Previous Sibling*/ /* test Previous Sibling*/
hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, NULL); hr = IXMLDOMAttribute_get_previousSibling(pAttribute, NULL);
ok(hr == E_INVALIDARG, "ret %08x\n", hr ); ok(hr == E_INVALIDARG, "ret %08x\n", hr );
pNextChild = (IXMLDOMNode *)0x1; pNextChild = (IXMLDOMNode *)0x1;
hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, &pNextChild); hr = IXMLDOMAttribute_get_previousSibling(pAttribute, &pNextChild);
ok(hr == S_FALSE, "ret %08x\n", hr ); ok(hr == S_FALSE, "ret %08x\n", hr );
ok(pNextChild == NULL, "pNextChild not NULL\n"); ok(pNextChild == NULL, "pNextChild not NULL\n");
/* test get_attributes */ /* test get_attributes */
hr = IXMLDOMAttribute_get_attributes( pAttrubute, NULL ); hr = IXMLDOMAttribute_get_attributes( pAttribute, NULL );
ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n"); ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
pAttribs = (IXMLDOMNamedNodeMap*)0x1; pAttribs = (IXMLDOMNamedNodeMap*)0x1;
hr = IXMLDOMAttribute_get_attributes( pAttrubute, &pAttribs); hr = IXMLDOMAttribute_get_attributes( pAttribute, &pAttribs);
ok(hr == S_FALSE, "ret %08x\n", hr ); ok(hr == S_FALSE, "ret %08x\n", hr );
ok( pAttribs == NULL, "pAttribs not NULL\n"); ok( pAttribs == NULL, "pAttribs not NULL\n");
hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttrubute, &pNewChild); hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttribute, &pNewChild);
ok(hr == E_FAIL, "ret %08x\n", hr ); ok(hr == E_FAIL, "ret %08x\n", hr );
ok(pNewChild == NULL, "pNewChild not NULL\n"); ok(pNewChild == NULL, "pNewChild not NULL\n");
...@@ -3411,46 +3444,46 @@ static void test_xmlTypes(void) ...@@ -3411,46 +3444,46 @@ static void test_xmlTypes(void)
ok(hr == S_OK, "ret %08x\n", hr ); ok(hr == S_OK, "ret %08x\n", hr );
if ( hr == S_OK ) if ( hr == S_OK )
{ {
hr = IXMLDOMNamedNodeMap_setNamedItem(pAttribs, (IXMLDOMNode*)pAttrubute, NULL ); hr = IXMLDOMNamedNodeMap_setNamedItem(pAttribs, (IXMLDOMNode*)pAttribute, NULL );
ok(hr == S_OK, "ret %08x\n", hr ); ok(hr == S_OK, "ret %08x\n", hr );
IXMLDOMNamedNodeMap_Release(pAttribs); IXMLDOMNamedNodeMap_Release(pAttribs);
} }
hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str); hr = IXMLDOMAttribute_get_nodeName(pAttribute, &str);
ok(hr == S_OK, "ret %08x\n", hr ); ok(hr == S_OK, "ret %08x\n", hr );
ok( !lstrcmpW( str, szAttribute ), "incorrect attribute node Name\n"); ok( !lstrcmpW( str, szAttribute ), "incorrect attribute node Name\n");
SysFreeString(str); SysFreeString(str);
/* test nodeTypeString */ /* test nodeTypeString */
hr = IXMLDOMAttribute_get_nodeTypeString(pAttrubute, &str); hr = IXMLDOMAttribute_get_nodeTypeString(pAttribute, &str);
ok(hr == S_OK, "ret %08x\n", hr ); ok(hr == S_OK, "ret %08x\n", hr );
ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n"); ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
SysFreeString(str); SysFreeString(str);
/* test nodeName */ /* test nodeName */
hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str); hr = IXMLDOMAttribute_get_nodeName(pAttribute, &str);
ok(hr == S_OK, "ret %08x\n", hr ); ok(hr == S_OK, "ret %08x\n", hr );
ok( !lstrcmpW( str, szAttribute ), "incorrect nodeName string\n"); ok( !lstrcmpW( str, szAttribute ), "incorrect nodeName string\n");
SysFreeString(str); SysFreeString(str);
/* test name property */ /* test name property */
hr = IXMLDOMAttribute_get_name(pAttrubute, &str); hr = IXMLDOMAttribute_get_name(pAttribute, &str);
ok(hr == S_OK, "ret %08x\n", hr ); ok(hr == S_OK, "ret %08x\n", hr );
ok( !lstrcmpW( str, szAttribute ), "incorrect name string\n"); ok( !lstrcmpW( str, szAttribute ), "incorrect name string\n");
SysFreeString(str); SysFreeString(str);
hr = IXMLDOMAttribute_get_xml(pAttrubute, &str); hr = IXMLDOMAttribute_get_xml(pAttribute, &str);
ok(hr == S_OK, "ret %08x\n", hr ); ok(hr == S_OK, "ret %08x\n", hr );
ok( !lstrcmpW( str, szAttributeXML ), "incorrect attribute xml\n"); ok( !lstrcmpW( str, szAttributeXML ), "incorrect attribute xml\n");
SysFreeString(str); SysFreeString(str);
hr = IXMLDOMAttribute_get_dataType(pAttrubute, &v); hr = IXMLDOMAttribute_get_dataType(pAttribute, &v);
ok(hr == S_FALSE, "ret %08x\n", hr ); ok(hr == S_FALSE, "ret %08x\n", hr );
ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n"); ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
VariantClear(&v); VariantClear(&v);
IXMLDOMAttribute_Release(pAttrubute); IXMLDOMAttribute_Release(pAttribute);
/* Check Element again with the Add Attribute*/ /* Check Element again with the Add Attribute*/
hr = IXMLDOMElement_get_xml(pElement, &str); hr = IXMLDOMElement_get_xml(pElement, &str);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment