From: David Kahurani k.kahurani@gmail.com
Signed-off-by: David Kahurani k.kahurani@gmail.com --- dlls/xmllite/tests/writer.c | 49 +++++++++++++++++++++++++++++++++++++ dlls/xmllite/writer.c | 25 +++++++++++++++++-- 2 files changed, 72 insertions(+), 2 deletions(-)
diff --git a/dlls/xmllite/tests/writer.c b/dlls/xmllite/tests/writer.c index f26228327b0..9a767dc4cc8 100644 --- a/dlls/xmllite/tests/writer.c +++ b/dlls/xmllite/tests/writer.c @@ -1892,6 +1892,54 @@ static void test_WriteCharEntity(void) IStream_Release(stream); }
+static void test_WriteRawChars(void) +{ + IXmlWriter *writer; + IStream *stream; + HRESULT hr; + + hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + stream = writer_set_output(writer); + + writer_set_property(writer, XmlWriterProperty_OmitXmlDeclaration); + + hr = IXmlWriter_WriteRawChars(writer, NULL, 0); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteRawChars(writer, L"", 0); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteStartElement(writer, NULL, L"sub", NULL); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteRawChars(writer, L"<rawChars>", 5); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_Flush(writer); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + CHECK_OUTPUT(stream, "<sub><rawC"); + IStream_Release(stream); + + stream = writer_set_output(writer); + + hr = IXmlWriter_WriteStartElement(writer, NULL, L"sub", NULL); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteRawChars(writer, L"<;;>", 10); + ok(hr == WC_E_XMLCHARACTER, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_Flush(writer); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + CHECK_OUTPUT(stream, "<sub><;;>"); + + IXmlWriter_Release(writer); + IStream_Release(stream); +} + static void test_WriteString(void) { IXmlWriter *writer; @@ -2696,6 +2744,7 @@ START_TEST(writer) test_WriteFullEndElement(); test_WriteCharEntity(); test_WriteChars(); + test_WriteRawChars(); test_WriteString(); test_WriteDocType(); test_WriteWhitespace(); diff --git a/dlls/xmllite/writer.c b/dlls/xmllite/writer.c index bd5c649b94b..35a388ea276 100644 --- a/dlls/xmllite/writer.c +++ b/dlls/xmllite/writer.c @@ -1698,8 +1698,19 @@ static HRESULT WINAPI xmlwriter_WriteRaw(IXmlWriter *iface, LPCWSTR data) static HRESULT WINAPI xmlwriter_WriteRawChars(IXmlWriter *iface, const WCHAR *pwch, UINT cwch) { xmlwriter *This = impl_from_IXmlWriter(iface); + HRESULT hr = S_OK; + + TRACE("%p %s %d\n", This, wine_dbgstr_w(pwch), cwch); + + if ((pwch == NULL && cwch != 0)) + return WC_E_XMLCHARACTER; + else if ((pwch == NULL && cwch == 0)) + return S_OK; + else if ((is_empty_string(pwch) && cwch == 0)) + return S_OK;
- FIXME("%p %s %d\n", This, wine_dbgstr_w(pwch), cwch); + if ((pwch && cwch > (lstrlenW(pwch)))) + hr = WC_E_XMLCHARACTER;
switch (This->state) { @@ -1709,11 +1720,21 @@ static HRESULT WINAPI xmlwriter_WriteRawChars(IXmlWriter *iface, const WCHAR *p return MX_E_ENCODING; case XmlWriterState_DocClosed: return WR_E_INVALIDACTION; + case XmlWriterState_Ready: + write_xmldecl(This, XmlStandalone_Omit); + break; + case XmlWriterState_ElemStarted: + writer_close_starttag(This); default: ; }
- return E_NOTIMPL; + if (hr != S_OK) + write_output_buffer(This->output, pwch, -1); + else + write_output_buffer(This->output, pwch, cwch); + + return hr; }
static HRESULT WINAPI xmlwriter_WriteStartDocument(IXmlWriter *iface, XmlStandalone standalone)