Nikolay Sivov : xmllite/writer: Implement OmitXmlDeclaration property.
Alexandre Julliard
julliard at winehq.org
Tue May 20 14:36:24 CDT 2014
Module: wine
Branch: master
Commit: 9a2177ff538977d046fd998de03f1188b8669145
URL: http://source.winehq.org/git/wine.git/?a=commit;h=9a2177ff538977d046fd998de03f1188b8669145
Author: Nikolay Sivov <nsivov at codeweavers.com>
Date: Tue May 20 00:27:16 2014 +0400
xmllite/writer: Implement OmitXmlDeclaration property.
---
dlls/xmllite/tests/writer.c | 94 +++++++++++++++++++++++++++++++++++++++++++
dlls/xmllite/writer.c | 20 +++++++--
2 files changed, 110 insertions(+), 4 deletions(-)
diff --git a/dlls/xmllite/tests/writer.c b/dlls/xmllite/tests/writer.c
index d7cfe44..d617c43 100644
--- a/dlls/xmllite/tests/writer.c
+++ b/dlls/xmllite/tests/writer.c
@@ -312,6 +312,99 @@ static void test_flush(void)
ok(g_write_len == 0, "got %d\n", g_write_len);
}
+static void test_omitxmldeclaration(void)
+{
+ static const char prologversion[] = "<?xml version=\"1.0\"?>";
+ static const WCHAR versionW[] = {'v','e','r','s','i','o','n','=','"','1','.','0','"',0};
+ static const WCHAR xmlW[] = {'x','m','l',0};
+ IXmlWriter *writer;
+ HGLOBAL hglobal;
+ IStream *stream;
+ HRESULT hr;
+ char *ptr;
+
+ hr = pCreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
+ ok(hr == S_OK, "Expected S_OK, got %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);
+
+ hr = IXmlWriter_SetProperty(writer, XmlWriterProperty_OmitXmlDeclaration, TRUE);
+ 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);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+
+ hr = GetHGlobalFromStream(stream, &hglobal);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+
+ ptr = GlobalLock(hglobal);
+ ok(!ptr, "got %p\n", ptr);
+ GlobalUnlock(hglobal);
+
+ /* one more time */
+ hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
+ ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
+
+ IStream_Release(stream);
+
+ /* now add PI manually, and try to start a document */
+ 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);
+
+ hr = IXmlWriter_WriteProcessingInstruction(writer, xmlW, versionW);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+
+ hr = IXmlWriter_Flush(writer);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+
+ hr = GetHGlobalFromStream(stream, &hglobal);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+
+ ptr = GlobalLock(hglobal);
+ ok(!strncmp(ptr, prologversion, strlen(prologversion)), "got %s\n", ptr);
+ GlobalUnlock(hglobal);
+
+ hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+
+ hr = IXmlWriter_Flush(writer);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+
+ ptr = GlobalLock(hglobal);
+ ok(!strncmp(ptr, prologversion, strlen(prologversion)), "got %s\n", ptr);
+ GlobalUnlock(hglobal);
+
+ hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
+ ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
+
+ hr = IXmlWriter_Flush(writer);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+
+ ptr = GlobalLock(hglobal);
+ ok(!strncmp(ptr, prologversion, strlen(prologversion)), "got %s\n", ptr);
+ GlobalUnlock(hglobal);
+
+ /* another attempt to add 'xml' PI */
+ hr = IXmlWriter_WriteProcessingInstruction(writer, xmlW, versionW);
+ ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
+
+ hr = IXmlWriter_Flush(writer);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+
+ IStream_Release(stream);
+ IXmlWriter_Release(writer);
+}
+
START_TEST(writer)
{
if (!init_pointers())
@@ -321,4 +414,5 @@ START_TEST(writer)
test_writeroutput();
test_writestartdocument();
test_flush();
+ test_omitxmldeclaration();
}
diff --git a/dlls/xmllite/writer.c b/dlls/xmllite/writer.c
index de5f755..d1834b8 100644
--- a/dlls/xmllite/writer.c
+++ b/dlls/xmllite/writer.c
@@ -392,13 +392,23 @@ static HRESULT WINAPI xmlwriter_GetProperty(IXmlWriter *iface, UINT property, LO
return S_OK;
}
-static HRESULT WINAPI xmlwriter_SetProperty(IXmlWriter *iface, UINT nProperty, LONG_PTR pValue)
+static HRESULT WINAPI xmlwriter_SetProperty(IXmlWriter *iface, UINT property, LONG_PTR value)
{
xmlwriter *This = impl_from_IXmlWriter(iface);
- FIXME("%p %u %lu\n", This, nProperty, pValue);
+ TRACE("(%p)->(%s %lu)\n", This, debugstr_writer_prop(property), value);
- return E_NOTIMPL;
+ switch (property)
+ {
+ case XmlWriterProperty_OmitXmlDeclaration:
+ This->omitxmldecl = !!value;
+ break;
+ default:
+ FIXME("Unimplemented property (%u)\n", property);
+ return E_NOTIMPL;
+ }
+
+ return S_OK;
}
static HRESULT WINAPI xmlwriter_WriteAttributes(IXmlWriter *iface, IXmlReader *pReader,
@@ -625,6 +635,9 @@ static HRESULT WINAPI xmlwriter_WriteStartDocument(IXmlWriter *iface, XmlStandal
;
}
+ This->state = XmlWriterState_DocStarted;
+ if (This->omitxmldecl) return S_OK;
+
/* version */
write_output_buffer(This->output, versionW, sizeof(versionW)/sizeof(WCHAR));
@@ -647,7 +660,6 @@ static HRESULT WINAPI xmlwriter_WriteStartDocument(IXmlWriter *iface, XmlStandal
write_output_buffer(This->output, noW, sizeof(noW)/sizeof(WCHAR));
}
- This->state = XmlWriterState_DocStarted;
return S_OK;
}
More information about the wine-cvs
mailing list