Commit caeecfa2 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

xmllite/writer: Implement Flush() method.

parent a0f67c36
......@@ -170,24 +170,24 @@ static void test_writestartdocument(void)
hr = IXmlWriter_WriteProcessingInstruction(writer, xmlW, versionW);
ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
hr = IXmlWriter_Flush(writer);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_SetOutput(writer, (IUnknown*)stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
/* nothing written yet */
hr = IXmlWriter_Flush(writer);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_Flush(writer);
todo_wine
ok(hr == S_OK, "got 0x%08x\n", hr);
if (hr == E_NOTIMPL)
{
IStream_Release(stream);
IXmlWriter_Release(writer);
return;
}
hr = GetHGlobalFromStream(stream, &hglobal);
ok(hr == S_OK, "got 0x%08x\n", hr);
......
......@@ -2,6 +2,7 @@
* IXmlWriter implementation
*
* Copyright 2011 Alistair Leslie-Hughes
* Copyright 2014 Nikolay Sivov for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -62,6 +63,7 @@ typedef struct
IMalloc *imalloc;
xml_encoding encoding;
struct output_buffer buffer;
ULONG stream_written;
} xmlwriteroutput;
static const struct IUnknownVtbl xmlwriteroutputvtbl;
......@@ -223,6 +225,11 @@ static HRESULT write_output_buffer_quoted(xmlwriteroutput *output, const WCHAR *
return S_OK;
}
static inline void reset_output_buffer(xmlwriteroutput *output)
{
output->stream_written = 0;
}
static void writeroutput_release_stream(xmlwriteroutput *writeroutput)
{
if (writeroutput->stream) {
......@@ -243,6 +250,31 @@ static inline HRESULT writeroutput_query_for_stream(xmlwriteroutput *writeroutpu
return hr;
}
static HRESULT writeroutput_flush_stream(xmlwriteroutput *output)
{
struct output_buffer *buffer;
ULONG written = 0, len;
HRESULT hr;
if (!output || !output->stream)
return S_OK;
buffer = &output->buffer;
len = buffer->written - output->stream_written;
if (!len)
return S_OK;
hr = ISequentialStream_Write(output->stream, buffer->data + output->stream_written, len, &written);
if (FAILED(hr)) {
WARN("write to stream failed (0x%08x)\n", hr);
return hr;
}
output->stream_written += written;
return S_OK;
}
static HRESULT WINAPI xmlwriter_QueryInterface(IXmlWriter *iface, REFIID riid, void **ppvObject)
{
xmlwriter *This = impl_from_IXmlWriter(iface);
......@@ -295,6 +327,7 @@ static HRESULT WINAPI xmlwriter_SetOutput(IXmlWriter *iface, IUnknown *output)
TRACE("(%p)->(%p)\n", This, output);
if (This->output) {
reset_output_buffer(This->output);
writeroutput_release_stream(This->output);
IUnknown_Release(&This->output->IXmlWriterOutput_iface);
This->output = NULL;
......@@ -662,9 +695,9 @@ static HRESULT WINAPI xmlwriter_Flush(IXmlWriter *iface)
{
xmlwriter *This = impl_from_IXmlWriter(iface);
FIXME("%p\n", This);
TRACE("%p\n", This);
return E_NOTIMPL;
return writeroutput_flush_stream(This->output);
}
static const struct IXmlWriterVtbl xmlwriter_vtbl =
......@@ -825,6 +858,7 @@ HRESULT WINAPI CreateXmlWriterOutputWithEncodingName(IUnknown *stream,
if (imalloc) IMalloc_AddRef(imalloc);
writeroutput->encoding = parse_encoding_name(encoding ? encoding : utf8W, -1);
writeroutput->stream = NULL;
writeroutput->stream_written = 0;
hr = init_output_buffer(writeroutput);
if (FAILED(hr)) {
IUnknown_Release(&writeroutput->IXmlWriterOutput_iface);
......
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