From 8746e387586907c371503048f36d1c650983ea3d Mon Sep 17 00:00:00 2001 From: Alistair Leslie-Hughes Date: Thu, 13 Mar 2008 21:50:30 +1100 Subject: [PATCH] msxml3: Implemented IXMLDOMCDATASection_insertData. --- dlls/msxml3/cdata.c | 65 ++++++++++++++++++++++++++++++++++++-- dlls/msxml3/tests/domdoc.c | 41 ++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 2 deletions(-) diff --git a/dlls/msxml3/cdata.c b/dlls/msxml3/cdata.c index 4593257f14f..f7f36b206c2 100644 --- a/dlls/msxml3/cdata.c +++ b/dlls/msxml3/cdata.c @@ -616,8 +616,69 @@ static HRESULT WINAPI domcdata_insertData( IXMLDOMCDATASection *iface, long offset, BSTR p) { - FIXME("\n"); - return E_NOTIMPL; + domcdata *This = impl_from_IXMLDOMCDATASection( iface ); + xmlnode *pDOMNode = impl_from_IXMLDOMNode( (IXMLDOMNode*)This->element ); + xmlChar *pXmlContent; + BSTR sNewString; + HRESULT hr = S_FALSE; + long nLength = 0, nLengthP = 0; + xmlChar *str = NULL; + + TRACE("%p\n", This); + + /* If have a NULL or empty string, dont do anything. */ + if(SysStringLen(p) == 0) + return S_OK; + + if(offset < 0) + { + return E_INVALIDARG; + } + + pXmlContent = xmlNodeGetContent(pDOMNode->node); + if(pXmlContent) + { + BSTR sContent = bstr_from_xmlChar( pXmlContent ); + nLength = SysStringLen(sContent); + nLengthP = SysStringLen(p); + + if(nLength < offset) + { + SysFreeString(sContent); + xmlFree(pXmlContent); + + return E_INVALIDARG; + } + + sNewString = SysAllocStringLen(NULL, nLength + nLengthP + 1); + if(sNewString) + { + if(offset > 0) + memcpy(sNewString, sContent, offset * sizeof(WCHAR)); + + memcpy(&sNewString[offset], p, nLengthP * sizeof(WCHAR)); + + if(offset+nLengthP < nLength) + memcpy(&sNewString[offset+nLengthP], &sContent[offset], (nLength-offset) * sizeof(WCHAR)); + + sNewString[nLengthP + nLength] = 0; + + str = xmlChar_from_wchar((WCHAR*)sNewString); + if(str) + { + xmlNodeSetContent(pDOMNode->node, str); + hr = S_OK; + } + + SysFreeString(sNewString); + } + + SysFreeString(sContent); + + xmlFree(pXmlContent); + } + + return hr; } static HRESULT WINAPI domcdata_deleteData( diff --git a/dlls/msxml3/tests/domdoc.c b/dlls/msxml3/tests/domdoc.c index fef4d73d325..9e3e72d0b40 100644 --- a/dlls/msxml3/tests/domdoc.c +++ b/dlls/msxml3/tests/domdoc.c @@ -2578,6 +2578,47 @@ static void test_xmlTypes(void) ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n"); SysFreeString(str); + /* test insertData */ + str = SysAllocStringLen(NULL, 0); + hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, str); + ok(hr == S_OK, "ret %08x\n", hr ); + + hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, NULL); + ok(hr == S_OK, "ret %08x\n", hr ); + + hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, str); + ok(hr == S_OK, "ret %08x\n", hr ); + + hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, NULL); + ok(hr == S_OK, "ret %08x\n", hr ); + + hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, NULL); + ok(hr == S_OK, "ret %08x\n", hr ); + + hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, str); + ok(hr == S_OK, "ret %08x\n", hr ); + SysFreeString(str); + + hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, _bstr_("Inserting")); + ok(hr == E_INVALIDARG, "ret %08x\n", hr ); + + hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, _bstr_("Inserting")); + ok(hr == E_INVALIDARG, "ret %08x\n", hr ); + + hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("Begin ")); + ok(hr == S_OK, "ret %08x\n", hr ); + + hr = IXMLDOMCDATASection_insertData(pCDataSec, 17, _bstr_("Middle")); + ok(hr == S_OK, "ret %08x\n", hr ); + + hr = IXMLDOMCDATASection_insertData(pCDataSec, 39, _bstr_(" End")); + ok(hr == S_OK, "ret %08x\n", hr ); + + hr = IXMLDOMCDATASection_get_text(pCDataSec, &str); + ok(hr == S_OK, "ret %08x\n", hr ); + ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n"); + SysFreeString(str); + IXMLDOMCDATASection_Release(pCDataSec); }