Commit 4dcbf2b4 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

xmllite/writer: Make it possible to use WriteRaw() multiple times.

parent 1cb6fa5e
...@@ -863,6 +863,7 @@ static void test_WriteCData(void) ...@@ -863,6 +863,7 @@ static void test_WriteCData(void)
static void test_WriteRaw(void) static void test_WriteRaw(void)
{ {
static const WCHAR rawW[] = {'a','<',':',0}; static const WCHAR rawW[] = {'a','<',':',0};
static const WCHAR aW[] = {'a',0};
IXmlWriter *writer; IXmlWriter *writer;
IStream *stream; IStream *stream;
HRESULT hr; HRESULT hr;
...@@ -884,6 +885,18 @@ static void test_WriteRaw(void) ...@@ -884,6 +885,18 @@ static void test_WriteRaw(void)
hr = IXmlWriter_WriteRaw(writer, rawW); hr = IXmlWriter_WriteRaw(writer, rawW);
ok(hr == S_OK, "got 0x%08x\n", hr); 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); hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr); ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
...@@ -899,7 +912,7 @@ static void test_WriteRaw(void) ...@@ -899,7 +912,7 @@ static void test_WriteRaw(void)
hr = IXmlWriter_Flush(writer); hr = IXmlWriter_Flush(writer);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
CHECK_OUTPUT(stream, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>a<:"); CHECK_OUTPUT(stream, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>a<:a<:<!--a<:-->a<:<a>a</a>");
IXmlWriter_Release(writer); IXmlWriter_Release(writer);
IStream_Release(stream); IStream_Release(stream);
......
...@@ -767,10 +767,13 @@ static HRESULT WINAPI xmlwriter_WriteElementString(IXmlWriter *iface, LPCWSTR pr ...@@ -767,10 +767,13 @@ static HRESULT WINAPI xmlwriter_WriteElementString(IXmlWriter *iface, LPCWSTR pr
case XmlWriterState_ElemStarted: case XmlWriterState_ElemStarted:
writer_close_starttag(This); writer_close_starttag(This);
break; break;
case XmlWriterState_DocClosed: case XmlWriterState_Ready:
return WR_E_INVALIDACTION; case XmlWriterState_DocStarted:
case XmlWriterState_PIDocStarted:
break;
default: default:
; This->state = XmlWriterState_DocClosed;
return WR_E_INVALIDACTION;
} }
write_encoding_bom(This); write_encoding_bom(This);
...@@ -1043,11 +1046,11 @@ static HRESULT WINAPI xmlwriter_WriteRaw(IXmlWriter *iface, LPCWSTR data) ...@@ -1043,11 +1046,11 @@ static HRESULT WINAPI xmlwriter_WriteRaw(IXmlWriter *iface, LPCWSTR data)
case XmlWriterState_PIDocStarted: case XmlWriterState_PIDocStarted:
break; break;
default: default:
This->state = XmlWriterState_DocClosed;
return WR_E_INVALIDACTION; return WR_E_INVALIDACTION;
} }
write_output_buffer(This->output, data, -1); write_output_buffer(This->output, data, -1);
This->state = XmlWriterState_DocClosed;
return S_OK; return S_OK;
} }
...@@ -1086,6 +1089,7 @@ static HRESULT WINAPI xmlwriter_WriteStartDocument(IXmlWriter *iface, XmlStandal ...@@ -1086,6 +1089,7 @@ static HRESULT WINAPI xmlwriter_WriteStartDocument(IXmlWriter *iface, XmlStandal
case XmlWriterState_Ready: case XmlWriterState_Ready:
break; break;
default: default:
This->state = XmlWriterState_DocClosed;
return WR_E_INVALIDACTION; return WR_E_INVALIDACTION;
} }
...@@ -1099,6 +1103,9 @@ static HRESULT WINAPI xmlwriter_WriteStartElement(IXmlWriter *iface, LPCWSTR pre ...@@ -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)); 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) switch (This->state)
{ {
case XmlWriterState_Initial: case XmlWriterState_Initial:
...@@ -1109,9 +1116,6 @@ static HRESULT WINAPI xmlwriter_WriteStartElement(IXmlWriter *iface, LPCWSTR pre ...@@ -1109,9 +1116,6 @@ static HRESULT WINAPI xmlwriter_WriteStartElement(IXmlWriter *iface, LPCWSTR pre
; ;
} }
if (!local_name)
return E_INVALIDARG;
/* close pending element */ /* close pending element */
if (This->starttagopen) if (This->starttagopen)
write_output_buffer(This->output, gtW, ARRAY_SIZE(gtW)); write_output_buffer(This->output, gtW, ARRAY_SIZE(gtW));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment