msxml3: Implemented IXMLDOMCDATASection_insertData.

This commit is contained in:
Alistair Leslie-Hughes 2008-03-13 21:50:30 +11:00 committed by Alexandre Julliard
parent 9b3234eb35
commit 8746e38758
2 changed files with 104 additions and 2 deletions

View File

@ -616,8 +616,69 @@ static HRESULT WINAPI domcdata_insertData(
IXMLDOMCDATASection *iface, IXMLDOMCDATASection *iface,
long offset, BSTR p) long offset, BSTR p)
{ {
FIXME("\n"); domcdata *This = impl_from_IXMLDOMCDATASection( iface );
return E_NOTIMPL; 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( static HRESULT WINAPI domcdata_deleteData(

View File

@ -2578,6 +2578,47 @@ static void test_xmlTypes(void)
ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n"); ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
SysFreeString(str); 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); IXMLDOMCDATASection_Release(pCDataSec);
} }