Commit 9a2177ff authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

xmllite/writer: Implement OmitXmlDeclaration property.

parent e0e0af80
......@@ -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();
}
......@@ -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;
}
......
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