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

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2016-03-24 10:41:26 +03:00 committed by Alexandre Julliard
parent 1cb6fa5e84
commit 4dcbf2b4b2
2 changed files with 25 additions and 8 deletions

View File

@ -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, "<?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);
IStream_Release(stream);

View File

@ -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));