msxml3: Fail to insert a node of unsupported type to a document.

This commit is contained in:
Nikolay Sivov 2013-02-24 18:04:02 +04:00 committed by Alexandre Julliard
parent 6c05460061
commit de9250537d
2 changed files with 58 additions and 4 deletions

View File

@ -1115,12 +1115,26 @@ static HRESULT WINAPI domdoc_insertBefore(
IXMLDOMNode** outNewChild )
{
domdoc *This = impl_from_IXMLDOMDocument3( iface );
DOMNodeType type;
HRESULT hr;
TRACE("(%p)->(%p %s %p)\n", This, newChild, debugstr_variant(&refChild), outNewChild);
return node_insert_before(&This->node, newChild, &refChild, outNewChild);
}
hr = IXMLDOMNode_get_nodeType(newChild, &type);
if (hr != S_OK) return hr;
TRACE("new node type %d\n", type);
switch (type)
{
case NODE_ATTRIBUTE:
case NODE_DOCUMENT:
case NODE_CDATA_SECTION:
if (outNewChild) *outNewChild = NULL;
return E_FAIL;
default:
return node_insert_before(&This->node, newChild, &refChild, outNewChild);
}
}
static HRESULT WINAPI domdoc_replaceChild(
IXMLDOMDocument3 *iface,

View File

@ -8270,15 +8270,30 @@ todo_wine {
static void test_insertBefore(void)
{
IXMLDOMDocument *doc, *doc2;
IXMLDOMDocument *doc, *doc2, *doc3;
IXMLDOMAttribute *attr;
IXMLDOMElement *elem1, *elem2, *elem3, *elem4, *elem5;
IXMLDOMNode *node, *newnode;
IXMLDOMNode *node, *newnode, *cdata;
HRESULT hr;
VARIANT v;
BSTR p;
doc = create_document(&IID_IXMLDOMDocument);
doc3 = create_document(&IID_IXMLDOMDocument);
/* document to document */
V_VT(&v) = VT_NULL;
node = (void*)0xdeadbeef;
hr = IXMLDOMDocument_insertBefore(doc, (IXMLDOMNode*)doc3, v, &node);
ok(hr == E_FAIL, "got 0x%08x\n", hr);
ok(node == NULL, "got %p\n", node);
/* document to itself */
V_VT(&v) = VT_NULL;
node = (void*)0xdeadbeef;
hr = IXMLDOMDocument_insertBefore(doc, (IXMLDOMNode*)doc, v, &node);
ok(hr == E_FAIL, "got 0x%08x\n", hr);
ok(node == NULL, "got %p\n", node);
/* insertBefore behaviour for attribute node */
V_VT(&v) = VT_I4;
@ -8289,6 +8304,31 @@ static void test_insertBefore(void)
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(attr != NULL, "got %p\n", attr);
/* attribute to document */
V_VT(&v) = VT_NULL;
node = (void*)0xdeadbeef;
hr = IXMLDOMDocument_insertBefore(doc3, (IXMLDOMNode*)attr, v, &node);
ok(hr == E_FAIL, "got 0x%08x\n", hr);
ok(node == NULL, "got %p\n", node);
/* cdata to document */
V_VT(&v) = VT_I4;
V_I4(&v) = NODE_CDATA_SECTION;
cdata = NULL;
hr = IXMLDOMDocument_createNode(doc3, v, _bstr_("cdata"), NULL, &cdata);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(cdata != NULL, "got %p\n", cdata);
V_VT(&v) = VT_NULL;
node = (void*)0xdeadbeef;
hr = IXMLDOMDocument_insertBefore(doc3, cdata, v, &node);
ok(hr == E_FAIL, "got 0x%08x\n", hr);
ok(node == NULL, "got %p\n", node);
IXMLDOMNode_Release(cdata);
IXMLDOMDocument_Release(doc3);
/* attribute to attribute */
V_VT(&v) = VT_I4;
V_I4(&v) = NODE_ATTRIBUTE;