msxml3: Fail on certain node types in insertBefore() for attributes, remove broken tests.

This commit is contained in:
Nikolay Sivov 2011-03-03 03:50:04 +03:00 committed by Alexandre Julliard
parent 873619e9bd
commit d04fd1d067
2 changed files with 172 additions and 108 deletions

View File

@ -309,13 +309,32 @@ static HRESULT WINAPI domattr_get_attributes(
static HRESULT WINAPI domattr_insertBefore( static HRESULT WINAPI domattr_insertBefore(
IXMLDOMAttribute *iface, IXMLDOMAttribute *iface,
IXMLDOMNode* newNode, VARIANT refChild, IXMLDOMNode* newNode, VARIANT refChild,
IXMLDOMNode** outOldNode) IXMLDOMNode** old_node)
{ {
domattr *This = impl_from_IXMLDOMAttribute( iface ); domattr *This = impl_from_IXMLDOMAttribute( iface );
DOMNodeType type;
HRESULT hr;
FIXME("(%p)->(%p %s %p) needs test\n", This, newNode, debugstr_variant(&refChild), outOldNode); FIXME("(%p)->(%p %s %p) needs test\n", This, newNode, debugstr_variant(&refChild), old_node);
return node_insert_before(&This->node, newNode, &refChild, outOldNode); if (!newNode) return E_INVALIDARG;
hr = IXMLDOMNode_get_nodeType(newNode, &type);
if (hr != S_OK) return hr;
TRACE("new node type %d\n", type);
switch (type)
{
case NODE_ATTRIBUTE:
case NODE_CDATA_SECTION:
case NODE_COMMENT:
case NODE_ELEMENT:
case NODE_PROCESSING_INSTRUCTION:
if (old_node) *old_node = NULL;
return E_FAIL;
default:
return node_insert_before(&This->node, newNode, &refChild, old_node);
}
} }
static HRESULT WINAPI domattr_replaceChild( static HRESULT WINAPI domattr_replaceChild(

View File

@ -2476,13 +2476,18 @@ static void test_create(void)
IXMLDOMNode_Release( unk ); IXMLDOMNode_Release( unk );
V_VT(&var) = VT_EMPTY; V_VT(&var) = VT_EMPTY;
child = NULL;
r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child ); r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
ok( r == S_OK, "returns %08x\n", r ); ok( r == S_OK, "returns %08x\n", r );
ok( unk == (IUnknown*)child, "%p %p\n", unk, child ); ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
ref = IXMLDOMNode_AddRef( unk );
todo_wine ok(ref == 5, "ref = %d\n", ref);
IXMLDOMNode_Release( unk );
IXMLDOMNode_Release( child ); IXMLDOMNode_Release( child );
IUnknown_Release( unk ); IUnknown_Release( unk );
V_VT(&var) = VT_NULL; V_VT(&var) = VT_NULL;
V_DISPATCH(&var) = (IDispatch*)node; V_DISPATCH(&var) = (IDispatch*)node;
r = IXMLDOMNode_insertBefore( root, node, var, &child ); r = IXMLDOMNode_insertBefore( root, node, var, &child );
@ -2490,7 +2495,6 @@ static void test_create(void)
ok( node == child, "%p %p\n", node, child ); ok( node == child, "%p %p\n", node, child );
IXMLDOMNode_Release( child ); IXMLDOMNode_Release( child );
V_VT(&var) = VT_NULL; V_VT(&var) = VT_NULL;
V_DISPATCH(&var) = (IDispatch*)node; V_DISPATCH(&var) = (IDispatch*)node;
r = IXMLDOMNode_insertBefore( root, node, var, NULL ); r = IXMLDOMNode_insertBefore( root, node, var, NULL );
@ -7215,6 +7219,7 @@ static void test_setAttributeNode(void)
HRESULT hr; HRESULT hr;
VARIANT v; VARIANT v;
BSTR str; BSTR str;
ULONG ref1, ref2;
doc = create_document(&IID_IXMLDOMDocument); doc = create_document(&IID_IXMLDOMDocument);
if (!doc) return; if (!doc) return;
@ -7236,11 +7241,19 @@ static void test_setAttributeNode(void)
hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr); hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
ok( hr == S_OK, "got 0x%08x\n", hr); ok( hr == S_OK, "got 0x%08x\n", hr);
ref1 = IXMLDOMElement_AddRef(elem);
IXMLDOMElement_Release(elem);
ret_attr = (void*)0xdeadbeef; ret_attr = (void*)0xdeadbeef;
hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr); hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
ok( hr == S_OK, "got 0x%08x\n", hr); ok( hr == S_OK, "got 0x%08x\n", hr);
ok( ret_attr == NULL, "got %p\n", ret_attr); ok( ret_attr == NULL, "got %p\n", ret_attr);
/* no reference added */
ref2 = IXMLDOMElement_AddRef(elem);
IXMLDOMElement_Release(elem);
ok(ref2 == ref1, "got %d, expected %d\n", ref2, ref1);
b = VARIANT_FALSE; b = VARIANT_FALSE;
hr = IXMLDOMElement_hasChildNodes(elem, &b); hr = IXMLDOMElement_hasChildNodes(elem, &b);
ok( hr == S_OK, "got 0x%08x\n", hr); ok( hr == S_OK, "got 0x%08x\n", hr);
@ -7283,137 +7296,63 @@ static void test_setAttributeNode(void)
todo_wine ok( hr == E_FAIL, "got 0x%08x\n", hr); todo_wine ok( hr == E_FAIL, "got 0x%08x\n", hr);
IXMLDOMElement_Release(elem); IXMLDOMElement_Release(elem);
IXMLDOMDocument_Release(doc2);
IXMLDOMAttribute_Release(attr); IXMLDOMAttribute_Release(attr);
IXMLDOMDocument_Release(doc);
hr = CoCreateInstance( &CLSID_DOMDocument40, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (void**)&doc ); /* create element, add attribute, see if it's copied or linked */
if (hr != S_OK) hr = IXMLDOMDocument_createElement(doc, _bstr_("test"), &elem);
{
win_skip("DOMDocument40 is not available (0x%08x)\n", hr);
return;
}
/* try attribute with xmlns name */
V_VT(&v) = VT_I4;
V_I4(&v) = NODE_ELEMENT;
hr = IXMLDOMDocument_createNode(doc, v, _bstr_("test"), _bstr_("http://winehq.org/default"), (IXMLDOMNode**)&elem);
ok( hr == S_OK, "got 0x%08x\n", hr); ok( hr == S_OK, "got 0x%08x\n", hr);
V_VT(&v) = VT_I4;
V_I4(&v) = NODE_ATTRIBUTE;
attr = NULL; attr = NULL;
hr = IXMLDOMDocument_createNode(doc, v, _bstr_("xmlns"), NULL, (IXMLDOMNode**)&attr); hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
ok(attr != NULL, "got %p\n", attr); ok(attr != NULL, "got %p\n", attr);
ref1 = IXMLDOMAttribute_AddRef(attr);
IXMLDOMAttribute_Release(attr);
V_VT(&v) = VT_BSTR; V_VT(&v) = VT_BSTR;
V_BSTR(&v) = _bstr_("http://winehq.org/default"); V_BSTR(&v) = _bstr_("attrvalue1");
hr = IXMLDOMAttribute_put_nodeValue(attr, v); hr = IXMLDOMAttribute_put_nodeValue(attr, v);
ok( hr == S_OK, "got 0x%08x\n", hr); ok( hr == S_OK, "got 0x%08x\n", hr);
ret_attr = (void*)0xdeadbeef; str = NULL;
hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr); hr = IXMLDOMAttribute_get_xml(attr, &str);
ok(hr == DISP_E_UNKNOWNNAME, "got 0x%08x\n", hr);
ok(ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
/* no child node added actually */
b = VARIANT_TRUE;
hr = IXMLDOMElement_hasChildNodes(elem, &b);
ok( hr == S_FALSE, "got 0x%08x\n", hr);
ok(b == VARIANT_FALSE, "got %d\n", b);
/* a single namespace definition as output */
hr = IXMLDOMElement_get_xml(elem, &str);
ok( hr == S_OK, "got 0x%08x\n", hr); ok( hr == S_OK, "got 0x%08x\n", hr);
ok( lstrcmpW(str, _bstr_("<test xmlns=\"http://winehq.org/default\"/>")) == 0, ok( lstrcmpW(str, _bstr_("attr=\"attrvalue1\"")) == 0,
"got %s\n", wine_dbgstr_w(str)); "got %s\n", wine_dbgstr_w(str));
SysFreeString(str); SysFreeString(str);
/* alter value isn't possible after creation? */
V_VT(&v) = VT_BSTR;
V_BSTR(&v) = _bstr_("http://winehq.org/default1");
hr = IXMLDOMAttribute_put_nodeValue(attr, v);
ok( hr == S_OK, "got 0x%08x\n", hr);
IXMLDOMElement_Release(elem);
IXMLDOMAttribute_Release(attr);
/* try to alter it with different attribute value */
V_VT(&v) = VT_I4;
V_I4(&v) = NODE_ELEMENT;
hr = IXMLDOMDocument_createNode(doc, v, _bstr_("test"), _bstr_("http://winehq.org/default"), (IXMLDOMNode**)&elem);
ok( hr == S_OK, "got 0x%08x\n", hr);
V_VT(&v) = VT_I4;
V_I4(&v) = NODE_ATTRIBUTE;
hr = IXMLDOMDocument_createNode(doc, v, _bstr_("xmlns"), NULL, (IXMLDOMNode**)&attr);
ok( hr == S_OK, "got 0x%08x\n", hr);
V_VT(&v) = VT_BSTR;
V_BSTR(&v) = _bstr_("http://winehq.org/default1");
hr = IXMLDOMAttribute_put_nodeValue(attr, v);
ok( hr == S_OK, "got 0x%08x\n", hr);
ret_attr = (void*)0xdeadbeef; ret_attr = (void*)0xdeadbeef;
hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr); hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
ok( hr == DISP_E_UNKNOWNNAME, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
ok(ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr); ok(ret_attr == NULL, "got %p\n", ret_attr);
/* no child node added actually */ /* attribute reference increased */
b = VARIANT_TRUE; ref2 = IXMLDOMAttribute_AddRef(attr);
hr = IXMLDOMElement_hasChildNodes(elem, &b); IXMLDOMAttribute_Release(attr);
ok( hr == S_FALSE, "got 0x%08x\n", hr); ok(ref1 == ref2, "got %d, expected %d\n", ref2, ref1);
ok(b == VARIANT_FALSE, "got %d\n", b);
/* initial value preserved */
hr = IXMLDOMElement_get_xml(elem, &str); hr = IXMLDOMElement_get_xml(elem, &str);
ok( hr == S_OK, "got 0x%08x\n", hr); ok( hr == S_OK, "got 0x%08x\n", hr);
ok( lstrcmpW(str, _bstr_("<test xmlns=\"http://winehq.org/default\"/>")) == 0, ok( lstrcmpW(str, _bstr_("<test attr=\"attrvalue1\"/>")) == 0,
"got %s\n", wine_dbgstr_w(str));
SysFreeString(str);
V_VT(&v) = VT_BSTR;
V_BSTR(&v) = _bstr_("attrvalue2");
hr = IXMLDOMAttribute_put_nodeValue(attr, v);
ok( hr == S_OK, "got 0x%08x\n", hr);
hr = IXMLDOMElement_get_xml(elem, &str);
ok( hr == S_OK, "got 0x%08x\n", hr);
todo_wine ok( lstrcmpW(str, _bstr_("<test attr=\"attrvalue2\"/>")) == 0,
"got %s\n", wine_dbgstr_w(str)); "got %s\n", wine_dbgstr_w(str));
SysFreeString(str); SysFreeString(str);
IXMLDOMElement_Release(elem); IXMLDOMElement_Release(elem);
IXMLDOMAttribute_Release(attr); IXMLDOMAttribute_Release(attr);
IXMLDOMDocument_Release(doc2);
/* now create without default namespace and add it as attribute */
V_VT(&v) = VT_I4;
V_I4(&v) = NODE_ELEMENT;
hr = IXMLDOMDocument_createNode(doc, v, _bstr_("test"), NULL, (IXMLDOMNode**)&elem);
ok( hr == S_OK, "got 0x%08x\n", hr);
V_VT(&v) = VT_I4;
V_I4(&v) = NODE_ATTRIBUTE;
hr = IXMLDOMDocument_createNode(doc, v, _bstr_("xmlns"), NULL, (IXMLDOMNode**)&attr);
ok( hr == S_OK, "got 0x%08x\n", hr);
V_VT(&v) = VT_BSTR;
V_BSTR(&v) = _bstr_("http://winehq.org/default");
hr = IXMLDOMAttribute_put_nodeValue(attr, v);
ok( hr == S_OK, "got 0x%08x\n", hr);
ret_attr = (void*)0xdeadbeef;
hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
ok(hr == DISP_E_UNKNOWNNAME, "got 0x%08x\n", hr);
ok(ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
/* no child node added */
b = VARIANT_TRUE;
hr = IXMLDOMElement_hasChildNodes(elem, &b);
ok( hr == S_FALSE, "got 0x%08x\n", hr);
ok(b == VARIANT_FALSE, "got %d\n", b);
IXMLDOMElement_Release(elem);
IXMLDOMAttribute_Release(attr);
IXMLDOMDocument_Release(doc); IXMLDOMDocument_Release(doc);
free_bstrs();
} }
static void test_put_dataType(void) static void test_put_dataType(void)
@ -8033,6 +7972,111 @@ todo_wine {
free_bstrs(); free_bstrs();
} }
static void test_insertBefore(void)
{
IXMLDOMDocument *doc;
IXMLDOMAttribute *attr;
IXMLDOMNode *node, *newnode;
HRESULT hr;
VARIANT v;
doc = create_document(&IID_IXMLDOMDocument);
/* insertBefore behaviour for attribute node */
V_VT(&v) = VT_I4;
V_I4(&v) = NODE_ATTRIBUTE;
attr = NULL;
hr = IXMLDOMDocument_createNode(doc, v, _bstr_("attr"), NULL, (IXMLDOMNode**)&attr);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(attr != NULL, "got %p\n", attr);
/* attribute to attribute */
V_VT(&v) = VT_I4;
V_I4(&v) = NODE_ATTRIBUTE;
newnode = NULL;
hr = IXMLDOMDocument_createNode(doc, v, _bstr_("attr2"), NULL, &newnode);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(newnode != NULL, "got %p\n", newnode);
V_VT(&v) = VT_NULL;
node = (void*)0xdeadbeef;
hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
ok(hr == E_FAIL, "got 0x%08x\n", hr);
ok(node == NULL, "got %p\n", node);
V_VT(&v) = VT_UNKNOWN;
V_UNKNOWN(&v) = (IUnknown*)attr;
node = (void*)0xdeadbeef;
hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
todo_wine ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
ok(node == NULL, "got %p\n", node);
IXMLDOMNode_Release(newnode);
/* cdata to attribute */
V_VT(&v) = VT_I4;
V_I4(&v) = NODE_CDATA_SECTION;
newnode = NULL;
hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(newnode != NULL, "got %p\n", newnode);
V_VT(&v) = VT_NULL;
node = (void*)0xdeadbeef;
hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
ok(hr == E_FAIL, "got 0x%08x\n", hr);
ok(node == NULL, "got %p\n", node);
IXMLDOMNode_Release(newnode);
/* comment to attribute */
V_VT(&v) = VT_I4;
V_I4(&v) = NODE_COMMENT;
newnode = NULL;
hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(newnode != NULL, "got %p\n", newnode);
V_VT(&v) = VT_NULL;
node = (void*)0xdeadbeef;
hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
ok(hr == E_FAIL, "got 0x%08x\n", hr);
ok(node == NULL, "got %p\n", node);
IXMLDOMNode_Release(newnode);
/* element to attribute */
V_VT(&v) = VT_I4;
V_I4(&v) = NODE_ELEMENT;
newnode = NULL;
hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(newnode != NULL, "got %p\n", newnode);
V_VT(&v) = VT_NULL;
node = (void*)0xdeadbeef;
hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
ok(hr == E_FAIL, "got 0x%08x\n", hr);
ok(node == NULL, "got %p\n", node);
IXMLDOMNode_Release(newnode);
/* pi to attribute */
V_VT(&v) = VT_I4;
V_I4(&v) = NODE_PROCESSING_INSTRUCTION;
newnode = NULL;
hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(newnode != NULL, "got %p\n", newnode);
V_VT(&v) = VT_NULL;
node = (void*)0xdeadbeef;
hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
ok(hr == E_FAIL, "got 0x%08x\n", hr);
ok(node == NULL, "got %p\n", node);
IXMLDOMNode_Release(newnode);
IXMLDOMDocument_Release(doc);
free_bstrs();
}
START_TEST(domdoc) START_TEST(domdoc)
{ {
IXMLDOMDocument *doc; IXMLDOMDocument *doc;
@ -8097,6 +8141,7 @@ START_TEST(domdoc)
test_createProcessingInstruction(); test_createProcessingInstruction();
test_put_nodeTypedValue(); test_put_nodeTypedValue();
test_get_xml(); test_get_xml();
test_insertBefore();
test_xsltemplate(); test_xsltemplate();
CoUninitialize(); CoUninitialize();