From 4dcbf2b4b235384d860a3ebdd88f182a46dc5a6f Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Thu, 24 Mar 2016 10:41:26 +0300 Subject: [PATCH] xmllite/writer: Make it possible to use WriteRaw() multiple times. Signed-off-by: Nikolay Sivov Signed-off-by: Alexandre Julliard --- dlls/xmllite/tests/writer.c | 15 ++++++++++++++- dlls/xmllite/writer.c | 18 +++++++++++------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/dlls/xmllite/tests/writer.c b/dlls/xmllite/tests/writer.c index 7a958b36414..b4d710228af 100644 --- a/dlls/xmllite/tests/writer.c +++ b/dlls/xmllite/tests/writer.c @@ -863,6 +863,7 @@ static void test_WriteCData(void) static void test_WriteRaw(void) { static const WCHAR rawW[] = {'a','<',':',0}; + static const WCHAR aW[] = {'a',0}; IXmlWriter *writer; IStream *stream; HRESULT hr; @@ -884,6 +885,18 @@ static void test_WriteRaw(void) hr = IXmlWriter_WriteRaw(writer, rawW); ok(hr == S_OK, "got 0x%08x\n", hr); + hr = IXmlWriter_WriteRaw(writer, rawW); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteComment(writer, rawW); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteRaw(writer, rawW); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteElementString(writer, NULL, aW, NULL, aW); + ok(hr == S_OK, "got 0x%08x\n", hr); + hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes); ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr); @@ -899,7 +912,7 @@ static void test_WriteRaw(void) hr = IXmlWriter_Flush(writer); ok(hr == S_OK, "got 0x%08x\n", hr); - CHECK_OUTPUT(stream, "a<:"); + CHECK_OUTPUT(stream, "a<:a<:a<:a"); IXmlWriter_Release(writer); IStream_Release(stream); diff --git a/dlls/xmllite/writer.c b/dlls/xmllite/writer.c index 61190c6b246..65d0bccb63c 100644 --- a/dlls/xmllite/writer.c +++ b/dlls/xmllite/writer.c @@ -767,10 +767,13 @@ static HRESULT WINAPI xmlwriter_WriteElementString(IXmlWriter *iface, LPCWSTR pr case XmlWriterState_ElemStarted: writer_close_starttag(This); break; - case XmlWriterState_DocClosed: - return WR_E_INVALIDACTION; + case XmlWriterState_Ready: + case XmlWriterState_DocStarted: + case XmlWriterState_PIDocStarted: + break; default: - ; + This->state = XmlWriterState_DocClosed; + return WR_E_INVALIDACTION; } write_encoding_bom(This); @@ -1043,11 +1046,11 @@ static HRESULT WINAPI xmlwriter_WriteRaw(IXmlWriter *iface, LPCWSTR data) case XmlWriterState_PIDocStarted: break; default: + This->state = XmlWriterState_DocClosed; return WR_E_INVALIDACTION; } write_output_buffer(This->output, data, -1); - This->state = XmlWriterState_DocClosed; return S_OK; } @@ -1086,6 +1089,7 @@ static HRESULT WINAPI xmlwriter_WriteStartDocument(IXmlWriter *iface, XmlStandal case XmlWriterState_Ready: break; default: + This->state = XmlWriterState_DocClosed; return WR_E_INVALIDACTION; } @@ -1099,6 +1103,9 @@ static HRESULT WINAPI xmlwriter_WriteStartElement(IXmlWriter *iface, LPCWSTR pre TRACE("(%p)->(%s %s %s)\n", This, wine_dbgstr_w(prefix), wine_dbgstr_w(local_name), wine_dbgstr_w(uri)); + if (!local_name) + return E_INVALIDARG; + switch (This->state) { case XmlWriterState_Initial: @@ -1109,9 +1116,6 @@ static HRESULT WINAPI xmlwriter_WriteStartElement(IXmlWriter *iface, LPCWSTR pre ; } - if (!local_name) - return E_INVALIDARG; - /* close pending element */ if (This->starttagopen) write_output_buffer(This->output, gtW, ARRAY_SIZE(gtW));