Commit 03695384 authored by Alistair Leslie-Hughes's avatar Alistair Leslie-Hughes Committed by Alexandre Julliard

msxml3: Implemented IXMLDOMText_insertData.

parent b77af270
......@@ -653,6 +653,47 @@ static void test_domdoc( void )
ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
SysFreeString(str);
/* test insertData */
str = SysAllocStringLen(NULL, 0);
r = IXMLDOMText_insertData(nodetext, -1, str);
ok(r == S_OK, "ret %08x\n", r );
r = IXMLDOMText_insertData(nodetext, -1, NULL);
ok(r == S_OK, "ret %08x\n", r );
r = IXMLDOMText_insertData(nodetext, 1000, str);
ok(r == S_OK, "ret %08x\n", r );
r = IXMLDOMText_insertData(nodetext, 1000, NULL);
ok(r == S_OK, "ret %08x\n", r );
r = IXMLDOMText_insertData(nodetext, 0, NULL);
ok(r == S_OK, "ret %08x\n", r );
r = IXMLDOMText_insertData(nodetext, 0, str);
ok(r == S_OK, "ret %08x\n", r );
SysFreeString(str);
r = IXMLDOMText_insertData(nodetext, -1, _bstr_("Inserting"));
ok(r == E_INVALIDARG, "ret %08x\n", r );
r = IXMLDOMText_insertData(nodetext, 1000, _bstr_("Inserting"));
ok(r == E_INVALIDARG, "ret %08x\n", r );
r = IXMLDOMText_insertData(nodetext, 0, _bstr_("Begin "));
ok(r == S_OK, "ret %08x\n", r );
r = IXMLDOMText_insertData(nodetext, 17, _bstr_("Middle"));
ok(r == S_OK, "ret %08x\n", r );
r = IXMLDOMText_insertData(nodetext, 39, _bstr_(" End"));
ok(r == S_OK, "ret %08x\n", r );
r = IXMLDOMText_get_text(nodetext, &str);
ok(r == S_OK, "ret %08x\n", r );
ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
SysFreeString(str);
IXMLDOMText_Release( nodetext );
}
SysFreeString( str );
......
......@@ -2,6 +2,7 @@
* DOM text node implementation
*
* Copyright 2006 Huw Davies
* Copyright 2007-2008 Alistair Leslie-Hughes
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -617,8 +618,69 @@ static HRESULT WINAPI domtext_insertData(
IXMLDOMText *iface,
long offset, BSTR p)
{
FIXME("\n");
return E_NOTIMPL;
domtext *This = impl_from_IXMLDOMText( 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 domtext_deleteData(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment