msxml3: Implement IXMLDOMComment insertData.
This commit is contained in:
parent
f4a797e90b
commit
ad1f05f961
|
@ -634,8 +634,69 @@ static HRESULT WINAPI domcomment_insertData(
|
|||
IXMLDOMComment *iface,
|
||||
long offset, BSTR p)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
domcomment *This = impl_from_IXMLDOMComment( iface );
|
||||
xmlnode *pDOMNode = impl_from_IXMLDOMNode( This->node );
|
||||
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, don't 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 domcomment_deleteData(
|
||||
|
|
|
@ -2339,6 +2339,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 = IXMLDOMComment_insertData(pComment, -1, str);
|
||||
ok(hr == S_OK, "ret %08x\n", hr );
|
||||
|
||||
hr = IXMLDOMComment_insertData(pComment, -1, NULL);
|
||||
ok(hr == S_OK, "ret %08x\n", hr );
|
||||
|
||||
hr = IXMLDOMComment_insertData(pComment, 1000, str);
|
||||
ok(hr == S_OK, "ret %08x\n", hr );
|
||||
|
||||
hr = IXMLDOMComment_insertData(pComment, 1000, NULL);
|
||||
ok(hr == S_OK, "ret %08x\n", hr );
|
||||
|
||||
hr = IXMLDOMComment_insertData(pComment, 0, NULL);
|
||||
ok(hr == S_OK, "ret %08x\n", hr );
|
||||
|
||||
hr = IXMLDOMComment_insertData(pComment, 0, str);
|
||||
ok(hr == S_OK, "ret %08x\n", hr );
|
||||
SysFreeString(str);
|
||||
|
||||
hr = IXMLDOMComment_insertData(pComment, -1, _bstr_("Inserting"));
|
||||
ok(hr == E_INVALIDARG, "ret %08x\n", hr );
|
||||
|
||||
hr = IXMLDOMComment_insertData(pComment, 1000, _bstr_("Inserting"));
|
||||
ok(hr == E_INVALIDARG, "ret %08x\n", hr );
|
||||
|
||||
hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("Begin "));
|
||||
ok(hr == S_OK, "ret %08x\n", hr );
|
||||
|
||||
hr = IXMLDOMComment_insertData(pComment, 17, _bstr_("Middle"));
|
||||
ok(hr == S_OK, "ret %08x\n", hr );
|
||||
|
||||
hr = IXMLDOMComment_insertData(pComment, 39, _bstr_(" End"));
|
||||
ok(hr == S_OK, "ret %08x\n", hr );
|
||||
|
||||
hr = IXMLDOMComment_get_text(pComment, &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);
|
||||
|
||||
IXMLDOMComment_Release(pComment);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue