Commit 05db7cf0 authored by David Kahurani's avatar David Kahurani Committed by Alexandre Julliard

xmllite/writer: Implement WriteSurrogateCharEntity.

parent 083211f5
...@@ -138,6 +138,8 @@ static void check_writer_state(IXmlWriter *writer, HRESULT exp_hr) ...@@ -138,6 +138,8 @@ static void check_writer_state(IXmlWriter *writer, HRESULT exp_hr)
{ {
IXmlReader *reader; IXmlReader *reader;
HRESULT hr; HRESULT hr;
WCHAR low = 0xdcef;
WCHAR high = 0xdaff;
hr = CreateXmlReader(&IID_IXmlReader, (void **)&reader, NULL); hr = CreateXmlReader(&IID_IXmlReader, (void **)&reader, NULL);
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
...@@ -217,7 +219,8 @@ static void check_writer_state(IXmlWriter *writer, HRESULT exp_hr) ...@@ -217,7 +219,8 @@ static void check_writer_state(IXmlWriter *writer, HRESULT exp_hr)
hr = IXmlWriter_WriteString(writer, L"a"); hr = IXmlWriter_WriteString(writer, L"a");
ok(hr == exp_hr, "Unexpected hr %#lx, expected %#lx.\n", hr, exp_hr); 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" "); hr = IXmlWriter_WriteWhitespace(writer, L" ");
ok(hr == exp_hr, "Unexpected hr %#lx, expected %#lx.\n", hr, exp_hr); 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) ...@@ -372,6 +375,8 @@ static void test_invalid_output_encoding(IXmlWriter *writer, IUnknown *output)
{ {
IXmlReader *reader; IXmlReader *reader;
HRESULT hr; HRESULT hr;
WCHAR low = 0xdcef;
WCHAR high = 0xdaff;
hr = CreateXmlReader(&IID_IXmlReader, (void **)&reader, NULL); hr = CreateXmlReader(&IID_IXmlReader, (void **)&reader, NULL);
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
...@@ -448,7 +453,8 @@ static void test_invalid_output_encoding(IXmlWriter *writer, IUnknown *output) ...@@ -448,7 +453,8 @@ static void test_invalid_output_encoding(IXmlWriter *writer, IUnknown *output)
hr = IXmlWriter_WriteString(writer, L"a"); hr = IXmlWriter_WriteString(writer, L"a");
ok(hr == MX_E_ENCODING, "Unexpected hr %#lx.\n", hr); 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" "); hr = IXmlWriter_WriteWhitespace(writer, L" ");
ok(hr == MX_E_ENCODING, "Unexpected hr %#lx.\n", hr); ok(hr == MX_E_ENCODING, "Unexpected hr %#lx.\n", hr);
...@@ -2021,6 +2027,60 @@ static void test_WriteRawChars(void) ...@@ -2021,6 +2027,60 @@ static void test_WriteRawChars(void)
IXmlWriter_Release(writer); IXmlWriter_Release(writer);
} }
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);
hr = IXmlWriter_WriteSurrogateCharEntity(writer, low, high);
ok(hr == E_UNEXPECTED, "Unexpected hr %#lx.\n", hr);
stream = writer_set_output(writer);
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>&#xCFCEF;</root>");
IStream_Release(stream);
stream = writer_set_output(writer);
hr = IXmlWriter_WriteEndElement(writer);
ok(hr == WR_E_INVALIDACTION, "Unexpected hr %#lx.\n", hr);
hr = IXmlWriter_WriteSurrogateCharEntity(writer, low, high);
ok(hr == WR_E_INVALIDACTION, "Unexpected hr %#lx.\n", hr);
IXmlWriter_Release(writer);
IStream_Release(stream);
}
static void test_WriteString(void) static void test_WriteString(void)
{ {
static const WCHAR surrogates[] = {0xd800, 0xdc00, 'x', 'y', '\0'}; static const WCHAR surrogates[] = {0xd800, 0xdc00, 'x', 'y', '\0'};
...@@ -2903,6 +2963,7 @@ START_TEST(writer) ...@@ -2903,6 +2963,7 @@ START_TEST(writer)
test_WriteCharEntity(); test_WriteCharEntity();
test_WriteChars(); test_WriteChars();
test_WriteRawChars(); test_WriteRawChars();
test_WriteSurrogateCharEntity();
test_WriteString(); test_WriteString();
test_WriteDocType(); test_WriteDocType();
test_WriteWhitespace(); test_WriteWhitespace();
......
...@@ -1979,11 +1979,35 @@ static HRESULT WINAPI xmlwriter_WriteString(IXmlWriter *iface, const WCHAR *stri ...@@ -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) 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) static HRESULT WINAPI xmlwriter_WriteWhitespace(IXmlWriter *iface, LPCWSTR text)
......
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