diff --git a/dlls/xmllite/tests/writer.c b/dlls/xmllite/tests/writer.c index 12433fa7de1..661b8379909 100644 --- a/dlls/xmllite/tests/writer.c +++ b/dlls/xmllite/tests/writer.c @@ -1217,6 +1217,47 @@ static void test_WriteFullEndElement(void) IStream_Release(stream); } +static void test_WriteCharEntity(void) +{ + static const WCHAR aW[] = {'a',0}; + IXmlWriter *writer; + IStream *stream; + HRESULT hr; + + hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL); + ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); + + /* without indentation */ + stream = writer_set_output(writer); + + hr = IXmlWriter_SetProperty(writer, XmlWriterProperty_OmitXmlDeclaration, TRUE); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit); + 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_WriteCharEntity(writer, 0x100); + 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_WriteEndDocument(writer); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_Flush(writer); + ok(hr == S_OK, "got 0x%08x\n", hr); + + CHECK_OUTPUT(stream, + "Ā"); + + IXmlWriter_Release(writer); + IStream_Release(stream); +} + START_TEST(writer) { test_writer_create(); @@ -1235,4 +1276,5 @@ START_TEST(writer) test_indentation(); test_WriteAttributeString(); test_WriteFullEndElement(); + test_WriteCharEntity(); } diff --git a/dlls/xmllite/writer.c b/dlls/xmllite/writer.c index 2e630ee4624..699095b360f 100644 --- a/dlls/xmllite/writer.c +++ b/dlls/xmllite/writer.c @@ -704,21 +704,29 @@ static HRESULT WINAPI xmlwriter_WriteCData(IXmlWriter *iface, LPCWSTR data) static HRESULT WINAPI xmlwriter_WriteCharEntity(IXmlWriter *iface, WCHAR ch) { + static const WCHAR fmtW[] = {'&','#','x','%','x',';',0}; xmlwriter *This = impl_from_IXmlWriter(iface); + WCHAR bufW[16]; - FIXME("%p %x\n", This, ch); + TRACE("%p %#x\n", This, ch); switch (This->state) { case XmlWriterState_Initial: return E_UNEXPECTED; + case XmlWriterState_ElemStarted: + writer_close_starttag(This); + break; case XmlWriterState_DocClosed: return WR_E_INVALIDACTION; default: ; } - return E_NOTIMPL; + sprintfW(bufW, fmtW, ch); + write_output_buffer(This->output, bufW, -1); + + return S_OK; } static HRESULT WINAPI xmlwriter_WriteChars(IXmlWriter *iface, const WCHAR *pwch, UINT cwch)