From: David Kahurani k.kahurani@gmail.com
Signed-off-by: David Kahurani k.kahurani@gmail.com --- dlls/xmllite/tests/writer.c | 58 +++++++++++++++++++++++++++++++++++-- dlls/xmllite/writer.c | 30 +++++++++++++++++-- 2 files changed, 83 insertions(+), 5 deletions(-)
diff --git a/dlls/xmllite/tests/writer.c b/dlls/xmllite/tests/writer.c index 377f66d2bd2..adcc33d7143 100644 --- a/dlls/xmllite/tests/writer.c +++ b/dlls/xmllite/tests/writer.c @@ -138,6 +138,8 @@ static void check_writer_state(IXmlWriter *writer, HRESULT exp_hr) { IXmlReader *reader; HRESULT hr; + WCHAR low = 0xdcef; + WCHAR high = 0xdaff;
hr = CreateXmlReader(&IID_IXmlReader, (void **)&reader, NULL); ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); @@ -217,7 +219,8 @@ static void check_writer_state(IXmlWriter *writer, HRESULT exp_hr) hr = IXmlWriter_WriteString(writer, L"a"); ok(hr == exp_hr, "Unexpected hr %#lx, expected %#lx.\n", hr, exp_hr);
- /* FIXME: add WriteSurrogateCharEntity */ + hr = IXmlWriter_WriteSurrogateCharEntity(writer, low, high); + ok(hr == exp_hr, "Unexpected hr %#lx, expected %#lx.\n", hr, exp_hr);
hr = IXmlWriter_WriteWhitespace(writer, L" "); ok(hr == exp_hr, "Unexpected hr %#lx, expected %#lx.\n", hr, exp_hr); @@ -372,6 +375,8 @@ static void test_invalid_output_encoding(IXmlWriter *writer, IUnknown *output) { IXmlReader *reader; HRESULT hr; + WCHAR low = 0xdcef; + WCHAR high = 0xdaff;
hr = CreateXmlReader(&IID_IXmlReader, (void **)&reader, NULL); ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); @@ -448,7 +453,8 @@ static void test_invalid_output_encoding(IXmlWriter *writer, IUnknown *output) hr = IXmlWriter_WriteString(writer, L"a"); ok(hr == MX_E_ENCODING, "Unexpected hr %#lx.\n", hr);
- /* TODO: WriteSurrogateCharEntity */ + hr = IXmlWriter_WriteSurrogateCharEntity(writer, low, high); + ok(hr == MX_E_ENCODING, "Unexpected hr %#lx.\n", hr);
hr = IXmlWriter_WriteWhitespace(writer, L" "); ok(hr == MX_E_ENCODING, "Unexpected hr %#lx.\n", hr); @@ -2003,6 +2009,53 @@ static void test_WriteRawChars(void) IStream_Release(stream); }
+static void test_WriteSurrogateCharEntity(void) +{ + IXmlWriter *writer; + IStream *stream; + HRESULT hr; + WCHAR low = 0xdcef; + WCHAR high = 0xdaff; + + hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteSurrogateCharEntity(writer, high, low); + ok(hr == WC_E_XMLCHARACTER, "Unexpected hr %#lx.\n", hr); + + stream = writer_set_output(writer); + + writer_set_property(writer, XmlWriterProperty_OmitXmlDeclaration); + + hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteStartElement(writer, NULL, L"root", NULL); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteSurrogateCharEntity(writer, high, low); + ok(hr == WC_E_XMLCHARACTER, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_Flush(writer); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + CHECK_OUTPUT(stream, "<root"); + + hr = IXmlWriter_WriteSurrogateCharEntity(writer, low, high); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteFullEndElement(writer); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_Flush(writer); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + CHECK_OUTPUT(stream, "<root>󏳯</root>"); + + IXmlWriter_Release(writer); + IStream_Release(stream); +} + static void test_WriteString(void) { static const WCHAR surrogates[] = {0xd800, 0xdc00, 'x', 'y', '\0'}; @@ -2877,6 +2930,7 @@ START_TEST(writer) test_WriteCharEntity(); test_WriteChars(); test_WriteRawChars(); + test_WriteSurrogateCharEntity(); test_WriteString(); test_WriteDocType(); test_WriteWhitespace(); diff --git a/dlls/xmllite/writer.c b/dlls/xmllite/writer.c index 103bfaa8c3e..5deee473866 100644 --- a/dlls/xmllite/writer.c +++ b/dlls/xmllite/writer.c @@ -1979,11 +1979,35 @@ static HRESULT WINAPI xmlwriter_WriteString(IXmlWriter *iface, const WCHAR *stri
static HRESULT WINAPI xmlwriter_WriteSurrogateCharEntity(IXmlWriter *iface, WCHAR wchLow, WCHAR wchHigh) { - xmlwriter *This = impl_from_IXmlWriter(iface); + xmlwriter *writer = impl_from_IXmlWriter(iface); + int codepoint; + WCHAR bufW[16];
- FIXME("%p %d %d\n", This, wchLow, wchHigh); + TRACE("%p, %d, %d.\n", iface, wchLow, wchHigh);
- return E_NOTIMPL; + if (!IS_SURROGATE_PAIR(wchHigh, wchLow)) + return WC_E_XMLCHARACTER; + + switch(writer->state) + { + case XmlWriterState_Initial: + return E_UNEXPECTED; + case XmlWriterState_InvalidEncoding: + return MX_E_ENCODING; + case XmlWriterState_ElemStarted: + writer_close_starttag(writer); + break; + case XmlWriterState_DocClosed: + return WR_E_INVALIDACTION; + default: + ; + } + + codepoint = ((wchHigh - 0xd800) * 0x400) + (wchLow - 0xdc00) + 0x10000; + swprintf(bufW, ARRAY_SIZE(bufW), L"&#x%X;", codepoint); + write_output_buffer(writer->output, bufW, -1); + + return S_OK; }
static HRESULT WINAPI xmlwriter_WriteWhitespace(IXmlWriter *iface, LPCWSTR text)