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

xmllite/writer: Implement WriteEndDocument().

parent c9c5cecc
...@@ -670,6 +670,72 @@ static void test_writeendelement(void) ...@@ -670,6 +670,72 @@ static void test_writeendelement(void)
IStream_Release(stream); IStream_Release(stream);
} }
static void test_writeenddocument(void)
{
static const WCHAR aW[] = {'a',0};
static const WCHAR bW[] = {'b',0};
IXmlWriter *writer;
IStream *stream;
HGLOBAL hglobal;
HRESULT hr;
char *ptr;
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = pCreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
hr = IXmlWriter_WriteEndDocument(writer);
ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
hr = IXmlWriter_SetOutput(writer, (IUnknown*)stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
/* WriteEndDocument resets it to initial state */
hr = IXmlWriter_WriteEndDocument(writer);
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
hr = IXmlWriter_WriteEndDocument(writer);
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit);
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL);
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
hr = IXmlWriter_SetOutput(writer, (IUnknown*)stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_WriteStartElement(writer, NULL, bW, NULL);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_WriteEndDocument(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 == NULL, "got %p\n", ptr);
/* we still need to flush manually, WriteEndDocument doesn't do that */
hr = IXmlWriter_Flush(writer);
ok(hr == S_OK, "got 0x%08x\n", hr);
ptr = GlobalLock(hglobal);
ok(ptr != NULL, "got %p\n", ptr);
ok(!strncmp(ptr, "<a><b /></a>", 12), "got %s\n", ptr);
GlobalUnlock(hglobal);
IXmlWriter_Release(writer);
IStream_Release(stream);
}
START_TEST(writer) START_TEST(writer)
{ {
if (!init_pointers()) if (!init_pointers())
...@@ -683,4 +749,5 @@ START_TEST(writer) ...@@ -683,4 +749,5 @@ START_TEST(writer)
test_flush(); test_flush();
test_omitxmldeclaration(); test_omitxmldeclaration();
test_bom(); test_bom();
test_writeenddocument();
} }
...@@ -59,7 +59,8 @@ typedef enum ...@@ -59,7 +59,8 @@ typedef enum
XmlWriterState_PIDocStarted, /* document was started with manually added 'xml' PI */ XmlWriterState_PIDocStarted, /* document was started with manually added 'xml' PI */
XmlWriterState_DocStarted, /* document was started with WriteStartDocument() */ XmlWriterState_DocStarted, /* document was started with WriteStartDocument() */
XmlWriterState_ElemStarted, /* writing element */ XmlWriterState_ElemStarted, /* writing element */
XmlWriterState_Content /* content is accepted at this point */ XmlWriterState_Content, /* content is accepted at this point */
XmlWriterState_DocClosed /* WriteEndDocument was called */
} XmlWriterState; } XmlWriterState;
typedef struct typedef struct
...@@ -608,6 +609,8 @@ static HRESULT WINAPI xmlwriter_WriteElementString(IXmlWriter *iface, LPCWSTR pr ...@@ -608,6 +609,8 @@ static HRESULT WINAPI xmlwriter_WriteElementString(IXmlWriter *iface, LPCWSTR pr
case XmlWriterState_ElemStarted: case XmlWriterState_ElemStarted:
writer_close_starttag(This); writer_close_starttag(This);
break; break;
case XmlWriterState_DocClosed:
return WR_E_INVALIDACTION;
default: default:
; ;
} }
...@@ -631,10 +634,34 @@ static HRESULT WINAPI xmlwriter_WriteElementString(IXmlWriter *iface, LPCWSTR pr ...@@ -631,10 +634,34 @@ static HRESULT WINAPI xmlwriter_WriteElementString(IXmlWriter *iface, LPCWSTR pr
static HRESULT WINAPI xmlwriter_WriteEndDocument(IXmlWriter *iface) static HRESULT WINAPI xmlwriter_WriteEndDocument(IXmlWriter *iface)
{ {
xmlwriter *This = impl_from_IXmlWriter(iface); xmlwriter *This = impl_from_IXmlWriter(iface);
HRESULT hr = S_OK;
FIXME("%p\n", This); TRACE("%p\n", This);
return E_NOTIMPL; switch (This->state)
{
case XmlWriterState_Initial:
hr = E_UNEXPECTED;
break;
case XmlWriterState_Ready:
case XmlWriterState_DocClosed:
hr = WR_E_INVALIDACTION;
break;
default:
;
}
if (FAILED(hr)) {
This->state = XmlWriterState_DocClosed;
return hr;
}
/* empty element stack */
while (IXmlWriter_WriteEndElement(iface) == S_OK)
;
This->state = XmlWriterState_DocClosed;
return S_OK;
} }
static HRESULT WINAPI xmlwriter_WriteEndElement(IXmlWriter *iface) static HRESULT WINAPI xmlwriter_WriteEndElement(IXmlWriter *iface)
...@@ -749,6 +776,7 @@ static HRESULT WINAPI xmlwriter_WriteProcessingInstruction(IXmlWriter *iface, LP ...@@ -749,6 +776,7 @@ static HRESULT WINAPI xmlwriter_WriteProcessingInstruction(IXmlWriter *iface, LP
return WR_E_INVALIDACTION; return WR_E_INVALIDACTION;
break; break;
case XmlWriterState_ElemStarted: case XmlWriterState_ElemStarted:
case XmlWriterState_DocClosed:
return WR_E_INVALIDACTION; return WR_E_INVALIDACTION;
default: default:
; ;
...@@ -812,6 +840,7 @@ static HRESULT WINAPI xmlwriter_WriteStartDocument(IXmlWriter *iface, XmlStandal ...@@ -812,6 +840,7 @@ static HRESULT WINAPI xmlwriter_WriteStartDocument(IXmlWriter *iface, XmlStandal
return S_OK; return S_OK;
case XmlWriterState_DocStarted: case XmlWriterState_DocStarted:
case XmlWriterState_ElemStarted: case XmlWriterState_ElemStarted:
case XmlWriterState_DocClosed:
return WR_E_INVALIDACTION; return WR_E_INVALIDACTION;
default: default:
; ;
...@@ -853,8 +882,15 @@ static HRESULT WINAPI xmlwriter_WriteStartElement(IXmlWriter *iface, LPCWSTR pre ...@@ -853,8 +882,15 @@ 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)); TRACE("(%p)->(%s %s %s)\n", This, wine_dbgstr_w(prefix), wine_dbgstr_w(local_name), wine_dbgstr_w(uri));
if (This->state == XmlWriterState_Initial) switch (This->state)
{
case XmlWriterState_Initial:
return E_UNEXPECTED; return E_UNEXPECTED;
case XmlWriterState_DocClosed:
return WR_E_INVALIDACTION;
default:
;
}
if (!local_name) if (!local_name)
return E_INVALIDARG; return E_INVALIDARG;
......
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