diff --git a/dlls/msxml3/tests/domdoc.c b/dlls/msxml3/tests/domdoc.c index 23fb1f31f2..bf4046b2ff 100644 --- a/dlls/msxml3/tests/domdoc.c +++ b/dlls/msxml3/tests/domdoc.c @@ -592,6 +592,52 @@ static void test_domdoc( void ) ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n"); SysFreeString(str); + /* test substringData */ + r = IXMLDOMText_substringData(nodetext, 0, 4, NULL); + ok(r == E_INVALIDARG, "ret %08x\n", r ); + + /* test substringData - Invalid offset */ + str = (BSTR)&szElement; + r = IXMLDOMText_substringData(nodetext, -1, 4, &str); + ok(r == E_INVALIDARG, "ret %08x\n", r ); + ok( str == NULL, "incorrect string\n"); + + /* test substringData - Invalid offset */ + str = (BSTR)&szElement; + r = IXMLDOMText_substringData(nodetext, 30, 0, &str); + ok(r == S_FALSE, "ret %08x\n", r ); + ok( str == NULL, "incorrect string\n"); + + /* test substringData - Invalid size */ + str = (BSTR)&szElement; + r = IXMLDOMText_substringData(nodetext, 0, -1, &str); + ok(r == E_INVALIDARG, "ret %08x\n", r ); + ok( str == NULL, "incorrect string\n"); + + /* test substringData - Invalid size */ + str = (BSTR)&szElement; + r = IXMLDOMText_substringData(nodetext, 2, 0, &str); + ok(r == S_FALSE, "ret %08x\n", r ); + ok( str == NULL, "incorrect string\n"); + + /* test substringData - Start of string */ + r = IXMLDOMText_substringData(nodetext, 0, 4, &str); + ok(r == S_OK, "ret %08x\n", r ); + ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n"); + SysFreeString(str); + + /* test substringData - Middle of string */ + r = IXMLDOMText_substringData(nodetext, 13, 4, &str); + ok(r == S_OK, "ret %08x\n", r ); + ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n"); + SysFreeString(str); + + /* test substringData - End of string */ + r = IXMLDOMText_substringData(nodetext, 20, 4, &str); + ok(r == S_OK, "ret %08x\n", r ); + ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n"); + SysFreeString(str); + IXMLDOMText_Release( nodetext ); } SysFreeString( str ); diff --git a/dlls/msxml3/text.c b/dlls/msxml3/text.c index af91449322..4821e63dff 100644 --- a/dlls/msxml3/text.c +++ b/dlls/msxml3/text.c @@ -539,8 +539,45 @@ static HRESULT WINAPI domtext_substringData( IXMLDOMText *iface, long offset, long count, BSTR *p) { - FIXME("\n"); - return E_NOTIMPL; + domtext *This = impl_from_IXMLDOMText( iface ); + xmlnode *pDOMNode = impl_from_IXMLDOMNode( (IXMLDOMNode*)This->element ); + xmlChar *pContent; + long nLength = 0; + HRESULT hr = S_FALSE; + + TRACE("%p\n", iface); + + if(!p) + return E_INVALIDARG; + + *p = NULL; + if(offset < 0 || count < 0) + return E_INVALIDARG; + + if(count == 0) + return hr; + + pContent = xmlNodeGetContent(pDOMNode->node); + if(pContent) + { + nLength = xmlStrlen(pContent); + + if( offset < nLength) + { + BSTR sContent = bstr_from_xmlChar(pContent); + if(offset + count > nLength) + *p = SysAllocString(&sContent[offset]); + else + *p = SysAllocStringLen(&sContent[offset], count); + + SysFreeString(sContent); + hr = S_OK; + } + + xmlFree(pContent); + } + + return hr; } static HRESULT WINAPI domtext_appendData(