From: David Kahurani k.kahurani@gmail.com
Signed-off-by: David Kahurani k.kahurani@gmail.com --- dlls/xmllite/tests/writer.c | 95 +++++++++++++++++++++++++++++++++++++ dlls/xmllite/writer.c | 33 +++++++++++-- 2 files changed, 124 insertions(+), 4 deletions(-)
diff --git a/dlls/xmllite/tests/writer.c b/dlls/xmllite/tests/writer.c index b607acd9edb..1a83246982c 100644 --- a/dlls/xmllite/tests/writer.c +++ b/dlls/xmllite/tests/writer.c @@ -1903,6 +1903,100 @@ static void test_WriteCharEntity(void) IStream_Release(stream); }
+static void test_WriteRawChars(void) +{ + IXmlWriter *writer; + IStream *stream; + HRESULT hr; + static WCHAR surrogates[] = {0xd800, 0xdc00, 0}; + + 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><;;>"); + 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, surrogates, 1); + ok(hr == WR_E_INVALIDSURROGATEPAIR, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteRawChars(writer, surrogates, 2); + 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>\U00010000"); + 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"", 5); + 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>"); + 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"", 0); + 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"); + + IXmlWriter_Release(writer); + IStream_Release(stream); +} + static void test_WriteString(void) { static const WCHAR surrogates[] = {0xd800, 0xdc00, 'x', 'y', '\0'}; @@ -2761,6 +2855,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 b7e53b5d3c1..095fdccef63 100644 --- a/dlls/xmllite/writer.c +++ b/dlls/xmllite/writer.c @@ -1725,11 +1725,20 @@ 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); + xmlwriter *writer = impl_from_IXmlWriter(iface); + HRESULT hr = S_OK; + unsigned int count;
- FIXME("%p %s %d\n", This, wine_dbgstr_w(pwch), cwch); + TRACE("%p, %s, %d\n", writer, debugstr_wn(pwch, cwch), cwch);
- switch (This->state) + 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; + + switch (writer->state) { case XmlWriterState_Initial: return E_UNEXPECTED; @@ -1737,11 +1746,27 @@ 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(writer, XmlStandalone_Omit); + break; + case XmlWriterState_ElemStarted: + writer_close_starttag(writer); default: ; }
- return E_NOTIMPL; + while (*pwch && cwch) + { + if (FAILED(hr = writer_get_next_write_count(pwch, cwch, &count))) return hr; + if (FAILED(hr = write_output_buffer(writer->output, pwch, count))) return hr; + + pwch += count; + cwch -= count; + } + + if (cwch) return WC_E_XMLCHARACTER; + + return hr; }
static HRESULT WINAPI xmlwriter_WriteStartDocument(IXmlWriter *iface, XmlStandalone standalone)