Commit 5f72a885 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

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

parent dfc4f8e5
......@@ -541,7 +541,7 @@ static HRESULT WINAPI domcomment_substringData(
LONG nLength = 0;
HRESULT hr = S_FALSE;
TRACE("%p\n", iface);
TRACE("%p %d %d %p\n", iface, offset, count, p);
if(!p)
return E_INVALIDARG;
......@@ -551,7 +551,7 @@ static HRESULT WINAPI domcomment_substringData(
return E_INVALIDARG;
if(count == 0)
return hr;
return S_FALSE;
pContent = xmlNodeGetContent(This->node.node);
if(pContent)
......@@ -630,7 +630,7 @@ static HRESULT WINAPI domcomment_insertData(
LONG nLength = 0, nLengthP = 0;
xmlChar *str = NULL;
TRACE("%p\n", This);
TRACE("%p %d %p\n", iface, offset, p);
/* If have a NULL or empty string, don't do anything. */
if(SysStringLen(p) == 0)
......@@ -692,8 +692,47 @@ static HRESULT WINAPI domcomment_deleteData(
IXMLDOMComment *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 = IXMLDOMComment_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)
IXMLDOMComment_substringData(iface, count, len - count, &str);
else
IXMLDOMComment_substringData(iface, 0, offset, &str);
hr = IXMLDOMComment_put_data(iface, str);
}
else
/* cutting from the inside */
{
BSTR str_end;
IXMLDOMComment_substringData(iface, 0, offset, &str);
IXMLDOMComment_substringData(iface, offset + count, len - count, &str_end);
hr = IXMLDOMComment_put_data(iface, str);
if(hr == S_OK)
hr = IXMLDOMComment_appendData(iface, str_end);
SysFreeString(str_end);
}
SysFreeString(str);
return hr;
}
static HRESULT WINAPI domcomment_replaceData(
......
......@@ -2927,6 +2927,76 @@ 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 = IXMLDOMComment_deleteData(pComment, -1, 1);
ok(hr == E_INVALIDARG, "ret %08x\n", hr );
hr = IXMLDOMComment_deleteData(pComment, 0, 0);
ok(hr == S_OK, "ret %08x\n", hr );
hr = IXMLDOMComment_deleteData(pComment, 0, -1);
ok(hr == E_INVALIDARG, "ret %08x\n", hr );
hr = IXMLDOMComment_get_length(pComment, &len);
ok(hr == S_OK, "ret %08x\n", hr );
ok(len == 43, "expected 43 got %d\n", len);
hr = IXMLDOMComment_deleteData(pComment, len, 1);
ok(hr == S_OK, "ret %08x\n", hr );
hr = IXMLDOMComment_deleteData(pComment, len+1, 1);
ok(hr == E_INVALIDARG, "ret %08x\n", hr );
/* delete from start */
hr = IXMLDOMComment_deleteData(pComment, 0, 5);
ok(hr == S_OK, "ret %08x\n", hr );
hr = IXMLDOMComment_get_length(pComment, &len);
ok(hr == S_OK, "ret %08x\n", hr );
ok(len == 38, "expected 38 got %d\n", len);
hr = IXMLDOMComment_get_text(pComment, &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 = IXMLDOMComment_deleteData(pComment, 35, 3);
ok(hr == S_OK, "ret %08x\n", hr );
hr = IXMLDOMComment_get_length(pComment, &len);
ok(hr == S_OK, "ret %08x\n", hr );
ok(len == 35, "expected 35 got %d\n", len);
hr = IXMLDOMComment_get_text(pComment, &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 = IXMLDOMComment_deleteData(pComment, 1, 33);
ok(hr == S_OK, "ret %08x\n", hr );
hr = IXMLDOMComment_get_length(pComment, &len);
ok(hr == S_OK, "ret %08x\n", hr );
ok(len == 2, "expected 2 got %d\n", len);
hr = IXMLDOMComment_get_text(pComment, &str);
ok(hr == S_OK, "ret %08x\n", hr );
ok( !lstrcmpW( str, _bstr_(" ") ), "incorrect get_text string\n");
SysFreeString(str);
/* delete whole data ... */
hr = IXMLDOMComment_get_length(pComment, &len);
ok(hr == S_OK, "ret %08x\n", hr );
hr = IXMLDOMComment_deleteData(pComment, 0, len);
ok(hr == S_OK, "ret %08x\n", hr );
/* ... and try again with empty string */
hr = IXMLDOMComment_deleteData(pComment, 0, len);
ok(hr == S_OK, "ret %08x\n", hr );
IXMLDOMComment_Release(pComment);
}
......
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