From c1464f8ab9dadf41196dab6a40a24142f9ab3929 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Sat, 13 Feb 2010 02:25:08 +0300 Subject: [PATCH] msxml3: Fix return value for IXMLDOMNode_put_nodeValue() for unsupported types. --- dlls/msxml3/node.c | 35 ++++++++++---------- dlls/msxml3/tests/domdoc.c | 68 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 17 deletions(-) diff --git a/dlls/msxml3/node.c b/dlls/msxml3/node.c index 5691c5225f..54782f95f7 100644 --- a/dlls/msxml3/node.c +++ b/dlls/msxml3/node.c @@ -327,23 +327,11 @@ static HRESULT WINAPI xmlnode_put_nodeValue( { xmlnode *This = impl_from_IXMLDOMNode( iface ); HRESULT hr; - xmlChar *str = NULL; - VARIANT string_value; TRACE("%p type(%d)\n", This, This->node->type); - VariantInit(&string_value); - hr = VariantChangeType(&string_value, &value, 0, VT_BSTR); - if(FAILED(hr)) - { - VariantClear(&string_value); - WARN("Couldn't convert to VT_BSTR\n"); - return hr; - } - - hr = S_FALSE; /* Document, Document Fragment, Document Type, Element, - Entity, Entity Reference, Notation aren't supported. */ + Entity, Entity Reference, Notation aren't supported. */ switch ( This->node->type ) { case XML_ATTRIBUTE_NODE: @@ -351,20 +339,33 @@ static HRESULT WINAPI xmlnode_put_nodeValue( case XML_COMMENT_NODE: case XML_PI_NODE: case XML_TEXT_NODE: - { + { + VARIANT string_value; + xmlChar *str; + + VariantInit(&string_value); + hr = VariantChangeType(&string_value, &value, 0, VT_BSTR); + if(FAILED(hr)) + { + VariantClear(&string_value); + WARN("Couldn't convert to VT_BSTR\n"); + return hr; + } + str = xmlChar_from_wchar(V_BSTR(&string_value)); + VariantClear(&string_value); + xmlNodeSetContent(This->node, str); heap_free(str); hr = S_OK; break; - } + } default: /* Do nothing for unsupported types. */ + hr = E_FAIL; break; } - VariantClear(&string_value); - return hr; } diff --git a/dlls/msxml3/tests/domdoc.c b/dlls/msxml3/tests/domdoc.c index c6937e6dd3..dc86881cf1 100644 --- a/dlls/msxml3/tests/domdoc.c +++ b/dlls/msxml3/tests/domdoc.c @@ -5000,6 +5000,73 @@ static void test_TransformWithLoadingLocalFile(void) free_bstrs(); } +static void test_put_nodeValue(void) +{ + IXMLDOMDocument *doc; + IXMLDOMEntityReference *entityref; + IXMLDOMNode *node; + HRESULT hr; + VARIANT data, type; + + hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc ); + if( hr != S_OK ) + return; + + /* test for unsupported types */ + /* NODE_DOCUMENT */ + hr = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (void**)&node); + ok(hr == S_OK, "ret %08x\n", hr ); + V_VT(&data) = VT_BSTR; + V_BSTR(&data) = _bstr_("one two three"); + hr = IXMLDOMNode_put_nodeValue(node, data); + ok(hr == E_FAIL, "ret %08x\n", hr ); + IXMLDOMNode_Release(node); + + /* NODE_DOCUMENT_FRAGMENT */ + V_VT(&type) = VT_I1; + V_I1(&type) = NODE_DOCUMENT_FRAGMENT; + hr = IXMLDOMDocument_createNode(doc, type, _bstr_("test"), NULL, &node); + ok(hr == S_OK, "ret %08x\n", hr ); + V_VT(&data) = VT_BSTR; + V_BSTR(&data) = _bstr_("one two three"); + hr = IXMLDOMNode_put_nodeValue(node, data); + ok(hr == E_FAIL, "ret %08x\n", hr ); + IXMLDOMNode_Release(node); + + /* NODE_ELEMENT */ + V_VT(&type) = VT_I1; + V_I1(&type) = NODE_ELEMENT; + hr = IXMLDOMDocument_createNode(doc, type, _bstr_("test"), NULL, &node); + ok(hr == S_OK, "ret %08x\n", hr ); + V_VT(&data) = VT_BSTR; + V_BSTR(&data) = _bstr_("one two three"); + hr = IXMLDOMNode_put_nodeValue(node, data); + ok(hr == E_FAIL, "ret %08x\n", hr ); + IXMLDOMNode_Release(node); + + /* NODE_ENTITY_REFERENCE */ + hr = IXMLDOMDocument_createEntityReference(doc, _bstr_("ref"), &entityref); + ok(hr == S_OK, "ret %08x\n", hr ); + + V_VT(&data) = VT_BSTR; + V_BSTR(&data) = _bstr_("one two three"); + hr = IXMLDOMEntityReference_put_nodeValue(node, data); + ok(hr == E_FAIL, "ret %08x\n", hr ); + + hr = IXMLDOMEntityReference_QueryInterface(entityref, &IID_IXMLDOMNode, (void**)&node); + ok(hr == S_OK, "ret %08x\n", hr ); + V_VT(&data) = VT_BSTR; + V_BSTR(&data) = _bstr_("one two three"); + hr = IXMLDOMNode_put_nodeValue(node, data); + ok(hr == E_FAIL, "ret %08x\n", hr ); + IXMLDOMNode_Release(node); + IXMLDOMEntityReference_Release(entityref); + + free_bstrs(); + + IXMLDOMDocument_Release(doc); +} + START_TEST(domdoc) { HRESULT r; @@ -5030,6 +5097,7 @@ START_TEST(domdoc) test_FormattingXML(); test_NodeTypeValue(); test_TransformWithLoadingLocalFile(); + test_put_nodeValue(); CoUninitialize(); }