Commit 173c4884 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

msxml3: Implement IXMLDOMCDATASection::deleteData() with tests.

parent 0a866d0e
......@@ -684,8 +684,47 @@ static HRESULT WINAPI domcdata_deleteData(
IXMLDOMCDATASection *iface,
LONG offset, LONG count)
{
FIXME("\n");
return E_NOTIMPL;
HRESULT hr;
LONG len = -1;
BSTR str;
TRACE("%p %d %d\n", iface, offset, count);
hr = IXMLDOMCDATASection_get_length(iface, &len);
if(hr != S_OK) return hr;
if((offset < 0) || (offset > len) || (count < 0))
return E_INVALIDARG;
if(len == 0) return S_OK;
/* cutting start or end */
if((offset == 0) || ((count + offset) >= len))
{
if(offset == 0)
IXMLDOMCDATASection_substringData(iface, count, len - count, &str);
else
IXMLDOMCDATASection_substringData(iface, 0, offset, &str);
hr = IXMLDOMCDATASection_put_data(iface, str);
}
else
/* cutting from the inside */
{
BSTR str_end;
IXMLDOMCDATASection_substringData(iface, 0, offset, &str);
IXMLDOMCDATASection_substringData(iface, offset + count, len - count, &str_end);
hr = IXMLDOMCDATASection_put_data(iface, str);
if(hr == S_OK)
hr = IXMLDOMCDATASection_appendData(iface, str_end);
SysFreeString(str_end);
}
SysFreeString(str);
return hr;
}
static HRESULT WINAPI domcdata_replaceData(
......
......@@ -3340,6 +3340,77 @@ static void test_xmlTypes(void)
ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
SysFreeString(str);
/* delete data */
/* invalid arguments */
hr = IXMLDOMCDATASection_deleteData(pCDataSec, -1, 1);
ok(hr == E_INVALIDARG, "ret %08x\n", hr );
hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, 0);
ok(hr == S_OK, "ret %08x\n", hr );
hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, -1);
ok(hr == E_INVALIDARG, "ret %08x\n", hr );
hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
ok(hr == S_OK, "ret %08x\n", hr );
ok(len == 43, "expected 43 got %d\n", len);
hr = IXMLDOMCDATASection_deleteData(pCDataSec, len, 1);
ok(hr == S_OK, "ret %08x\n", hr );
hr = IXMLDOMCDATASection_deleteData(pCDataSec, len+1, 1);
ok(hr == E_INVALIDARG, "ret %08x\n", hr );
/* delete from start */
hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, 5);
ok(hr == S_OK, "ret %08x\n", hr );
hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
ok(hr == S_OK, "ret %08x\n", hr );
ok(len == 38, "expected 38 got %d\n", len);
hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
ok(hr == S_OK, "ret %08x\n", hr );
ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
SysFreeString(str);
/* delete from end */
hr = IXMLDOMCDATASection_deleteData(pCDataSec, 35, 3);
ok(hr == S_OK, "ret %08x\n", hr );
hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
ok(hr == S_OK, "ret %08x\n", hr );
ok(len == 35, "expected 35 got %d\n", len);
hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
ok(hr == S_OK, "ret %08x\n", hr );
ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append ") ), "incorrect get_text string\n");
SysFreeString(str);
/* delete from inside */
hr = IXMLDOMCDATASection_deleteData(pCDataSec, 1, 33);
ok(hr == S_OK, "ret %08x\n", hr );
hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
ok(hr == S_OK, "ret %08x\n", hr );
ok(len == 2, "expected 2 got %d\n", len);
hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
ok(hr == S_OK, "ret %08x\n", hr );
ok( !lstrcmpW( str, _bstr_(" ") ), "incorrect get_text string\n");
SysFreeString(str);
/* delete whole data ... */
hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
ok(hr == S_OK, "ret %08x\n", hr );
hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, len);
ok(hr == S_OK, "ret %08x\n", hr );
/* ... and try again with empty string */
hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, len);
ok(hr == S_OK, "ret %08x\n", hr );
IXMLDOMCDATASection_Release(pCDataSec);
}
......
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