Nikolay Sivov : xmllite/writer: Implement Flush() method.
Alexandre Julliard
julliard at winehq.org
Thu May 15 15:14:30 CDT 2014
Module: wine
Branch: master
Commit: caeecfa223013941f44e9974a51f9bb3bd2b2a89
URL: http://source.winehq.org/git/wine.git/?a=commit;h=caeecfa223013941f44e9974a51f9bb3bd2b2a89
Author: Nikolay Sivov <nsivov at codeweavers.com>
Date: Thu May 15 18:50:31 2014 +0400
xmllite/writer: Implement Flush() method.
---
dlls/xmllite/tests/writer.c | 14 +++++++-------
dlls/xmllite/writer.c | 38 ++++++++++++++++++++++++++++++++++++--
2 files changed, 43 insertions(+), 9 deletions(-)
diff --git a/dlls/xmllite/tests/writer.c b/dlls/xmllite/tests/writer.c
index 2fcd5f2..b6b8fe3 100644
--- a/dlls/xmllite/tests/writer.c
+++ b/dlls/xmllite/tests/writer.c
@@ -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);
diff --git a/dlls/xmllite/writer.c b/dlls/xmllite/writer.c
index 745da79..0a1d361 100644
--- a/dlls/xmllite/writer.c
+++ b/dlls/xmllite/writer.c
@@ -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);
More information about the wine-cvs
mailing list