From: David Kahurani k.kahurani@gmail.com
Signed-off-by: David Kahurani k.kahurani@gmail.com --- dlls/xmllite/tests/writer.c | 111 ++++++++++++++++++++++++++++++++++++ dlls/xmllite/writer.c | 56 +++++++++++------- 2 files changed, 145 insertions(+), 22 deletions(-)
diff --git a/dlls/xmllite/tests/writer.c b/dlls/xmllite/tests/writer.c index d15fe8b64df..b607acd9edb 100644 --- a/dlls/xmllite/tests/writer.c +++ b/dlls/xmllite/tests/writer.c @@ -1497,6 +1497,15 @@ static void test_writer_state(void) check_writer_state(writer, WR_E_INVALIDACTION); IStream_Release(stream);
+ /* WriteChars */ + stream = writer_set_output(writer); + + hr = IXmlWriter_WriteChars(writer, L"a", 1); + ok(hr == WR_E_INVALIDACTION, "Unexpected hr %#lx.\n", hr); + + check_writer_state(writer, WR_E_INVALIDACTION); + + IStream_Release(stream); IXmlWriter_Release(writer); }
@@ -2123,6 +2132,107 @@ static void test_WriteString(void) IStream_Release(stream); }
+static void test_WriteChars(void) +{ + IXmlWriter *writer; + IStream *stream; + HRESULT hr; + static WCHAR raw[] = {'s', 'a', 'm', 0xd800, 0xdc00, 'p', 'l', 'e', 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_WriteStartElement(writer, NULL, L"chars", NULL); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteChars(writer, L"<chars>", 20); + ok(hr == WC_E_XMLCHARACTER, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteChars(writer, L"<chars>", 7); + 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, + "<chars><chars><chars>"); + IStream_Release(stream); + + stream = writer_set_output(writer); + + hr = IXmlWriter_WriteStartElement(writer, NULL, L"chars", NULL); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteChars(writer, raw, 8); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + raw[3] = 0xdc00; + raw[4] = 0xd800; + hr = IXmlWriter_WriteChars(writer, raw, 8); + ok(hr == WR_E_INVALIDSURROGATEPAIR, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_Flush(writer); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + CHECK_OUTPUT(stream, "<chars>sam\U00010000plesam"); + IStream_Release(stream); + + stream = writer_set_output(writer); + + hr = IXmlWriter_WriteStartElement(writer, NULL, L"chars", NULL); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteChars(writer, NULL, 0); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteFullEndElement(writer); + 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, + "<chars></chars>"); + IStream_Release(stream); + + stream = writer_set_output(writer); + + hr = IXmlWriter_WriteStartElement(writer, NULL, L"chars", NULL); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteChars(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, + "<chars"); + + IStream_Release(stream); + + stream = writer_set_output(writer); + + hr = IXmlWriter_WriteStartElement(writer, NULL, L"c", NULL); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteChars(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, + "<c>"); + + IXmlWriter_Release(writer); + IStream_Release(stream); +} + static void test_WriteDocType(void) { static const struct @@ -2650,6 +2760,7 @@ START_TEST(writer) test_WriteAttributeString(); test_WriteFullEndElement(); test_WriteCharEntity(); + test_WriteChars(); test_WriteString(); test_WriteDocType(); test_WriteWhitespace(); diff --git a/dlls/xmllite/writer.c b/dlls/xmllite/writer.c index def165656ef..c29cfd279f1 100644 --- a/dlls/xmllite/writer.c +++ b/dlls/xmllite/writer.c @@ -1104,28 +1104,6 @@ static HRESULT WINAPI xmlwriter_WriteCharEntity(IXmlWriter *iface, WCHAR ch) return S_OK; }
-static HRESULT WINAPI xmlwriter_WriteChars(IXmlWriter *iface, const WCHAR *pwch, UINT cwch) -{ - xmlwriter *This = impl_from_IXmlWriter(iface); - - FIXME("%p %s %d\n", This, wine_dbgstr_w(pwch), cwch); - - switch (This->state) - { - case XmlWriterState_Initial: - return E_UNEXPECTED; - case XmlWriterState_InvalidEncoding: - return MX_E_ENCODING; - case XmlWriterState_DocClosed: - return WR_E_INVALIDACTION; - default: - ; - } - - return E_NOTIMPL; -} - - static HRESULT WINAPI xmlwriter_WriteComment(IXmlWriter *iface, LPCWSTR comment) { xmlwriter *This = impl_from_IXmlWriter(iface); @@ -1944,6 +1922,40 @@ static HRESULT WINAPI xmlwriter_WriteString(IXmlWriter *iface, const WCHAR *stri return write_escaped_string(This, string, ~0u); }
+static HRESULT WINAPI xmlwriter_WriteChars(IXmlWriter *iface, const WCHAR *pwch, UINT cwch) +{ + xmlwriter *writer = impl_from_IXmlWriter(iface); + + TRACE("%p, %s, %d\n", writer, 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; + + switch (writer->state) + { + case XmlWriterState_Initial: + return E_UNEXPECTED; + case XmlWriterState_InvalidEncoding: + return MX_E_ENCODING; + case XmlWriterState_ElemStarted: + writer_close_starttag(writer); + break; + case XmlWriterState_Ready: + case XmlWriterState_DocClosed: + writer->state = XmlWriterState_DocClosed; + return WR_E_INVALIDACTION; + default: + ; + } + + writer->textnode = 1; + return write_escaped_string(writer, pwch, cwch); +} + static HRESULT WINAPI xmlwriter_WriteSurrogateCharEntity(IXmlWriter *iface, WCHAR wchLow, WCHAR wchHigh) { xmlwriter *This = impl_from_IXmlWriter(iface);