From 083211f54df628896b1afed5e131571e0b375be1 Mon Sep 17 00:00:00 2001 From: David Kahurani Date: Sat, 29 Oct 2022 12:51:55 +0300 Subject: [PATCH] xmllite/writer: Implement WriteRawChars. Signed-off-by: David Kahurani --- dlls/xmllite/tests/writer.c | 116 ++++++++++++++++++++++++++++++++++++ dlls/xmllite/writer.c | 32 ++++++++-- 2 files changed, 143 insertions(+), 5 deletions(-) diff --git a/dlls/xmllite/tests/writer.c b/dlls/xmllite/tests/writer.c index 25257624f50..53f3297597e 100644 --- a/dlls/xmllite/tests/writer.c +++ b/dlls/xmllite/tests/writer.c @@ -456,6 +456,9 @@ static void test_invalid_output_encoding(IXmlWriter *writer, IUnknown *output) hr = IXmlWriter_WriteChars(writer, L"a", 1); ok(hr == MX_E_ENCODING, "Unexpected hr %#lx.\n", hr); + hr = IXmlWriter_WriteRawChars(writer, L"a", 1); + ok(hr == MX_E_ENCODING, "Unexpected hr %#lx.\n", hr); + hr = IXmlWriter_Flush(writer); ok(hr == S_OK, "Failed to flush, hr %#lx.\n", hr); @@ -1906,6 +1909,118 @@ 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); + + 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_WriteRawChars(writer, NULL, 5); + ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteRawChars(writer, L"", 6); + ok(hr == E_UNEXPECTED, "Unexpected hr %#lx.\n", hr); + + 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 == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_Flush(writer); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + CHECK_OUTPUT(stream, "", 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, "a<;;>"); + 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, "\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, ""); + 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, "state) + if ((characters == NULL && length != 0)) + return E_INVALIDARG; + + if (length == 0) + return S_OK; + + switch (writer->state) { case XmlWriterState_Initial: return E_UNEXPECTED; @@ -1822,11 +1830,25 @@ 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 (length) + { + if (FAILED(hr = writer_get_next_write_count(characters, length, &count))) return hr; + if (FAILED(hr = write_output_buffer(writer->output, characters, count))) return hr; + + characters += count; + length -= count; + } + + return hr; } static HRESULT WINAPI xmlwriter_WriteStartDocument(IXmlWriter *iface, XmlStandalone standalone)