xmllite/writer: Implement WriteRawChars.

Signed-off-by: David Kahurani <k.kahurani@gmail.com>
This commit is contained in:
David Kahurani 2022-10-29 12:51:55 +03:00 committed by Alexandre Julliard
parent f3cfbef6af
commit 083211f54d
2 changed files with 143 additions and 5 deletions

View file

@ -456,6 +456,9 @@ static void test_invalid_output_encoding(IXmlWriter *writer, IUnknown *output)
hr = IXmlWriter_WriteChars(writer, L"a", 1);
ok(hr == MX_E_ENCODING, "Unexpected hr %#lx.\n", hr);
hr = IXmlWriter_WriteRawChars(writer, L"a", 1);
ok(hr == MX_E_ENCODING, "Unexpected hr %#lx.\n", hr);
hr = IXmlWriter_Flush(writer);
ok(hr == S_OK, "Failed to flush, hr %#lx.\n", hr);
@ -1906,6 +1909,118 @@ static void test_WriteCharEntity(void)
IStream_Release(stream);
}
static void test_WriteRawChars(void)
{
IXmlWriter *writer;
IStream *stream;
HRESULT hr;
static WCHAR surrogates[] = {0xd800, 0xdc00, 0};
hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
hr = IXmlWriter_WriteRawChars(writer, NULL, 0);
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
hr = IXmlWriter_WriteRawChars(writer, L"", 0);
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
hr = IXmlWriter_WriteRawChars(writer, NULL, 5);
ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
hr = IXmlWriter_WriteRawChars(writer, L"", 6);
ok(hr == E_UNEXPECTED, "Unexpected hr %#lx.\n", hr);
stream = writer_set_output(writer);
hr = IXmlWriter_WriteStartElement(writer, NULL, L"sub", NULL);
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
hr = IXmlWriter_WriteRawChars(writer, L"<rawChars>", 5);
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, "<sub><rawC");
IStream_Release(stream);
stream = writer_set_output(writer);
hr = IXmlWriter_WriteRawChars(writer, L"a", 1);
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
hr = IXmlWriter_WriteStartElement(writer, NULL, L"sub", NULL);
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
hr = IXmlWriter_WriteRawChars(writer, L"<;;>", 10);
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, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>a<sub><;;>");
IStream_Release(stream);
stream = writer_set_output(writer);
hr = IXmlWriter_WriteStartElement(writer, NULL, L"sub", NULL);
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
hr = IXmlWriter_WriteRawChars(writer, surrogates, 1);
ok(hr == WR_E_INVALIDSURROGATEPAIR, "Unexpected hr %#lx.\n", hr);
hr = IXmlWriter_WriteRawChars(writer, surrogates, 2);
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, "<sub>\U00010000");
IStream_Release(stream);
stream = writer_set_output(writer);
hr = IXmlWriter_WriteStartElement(writer, NULL, L"sub", NULL);
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
hr = IXmlWriter_WriteRawChars(writer, L"", 5);
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, "<sub>");
IStream_Release(stream);
stream = writer_set_output(writer);
hr = IXmlWriter_WriteStartElement(writer, NULL, L"sub", NULL);
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
hr = IXmlWriter_WriteRawChars(writer, L"", 0);
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, "<sub");
IStream_Release(stream);
stream = writer_set_output(writer);
/* Force document close */
hr = IXmlWriter_WriteEndElement(writer);
ok(hr == WR_E_INVALIDACTION, "Unexpected hr %#lx.\n", hr);
hr = IXmlWriter_WriteRawChars(writer, L"a", 1);
ok(hr == WR_E_INVALIDACTION, "Unexpected hr %#lx.\n", hr);
IStream_Release(stream);
IXmlWriter_Release(writer);
}
static void test_WriteString(void)
{
static const WCHAR surrogates[] = {0xd800, 0xdc00, 'x', 'y', '\0'};
@ -2787,6 +2902,7 @@ START_TEST(writer)
test_WriteFullEndElement();
test_WriteCharEntity();
test_WriteChars();
test_WriteRawChars();
test_WriteString();
test_WriteDocType();
test_WriteWhitespace();

View file

@ -1808,13 +1808,21 @@ static HRESULT WINAPI xmlwriter_WriteRaw(IXmlWriter *iface, LPCWSTR data)
return hr;
}
static HRESULT WINAPI xmlwriter_WriteRawChars(IXmlWriter *iface, const WCHAR *pwch, UINT cwch)
static HRESULT WINAPI xmlwriter_WriteRawChars(IXmlWriter *iface, const WCHAR *characters, UINT length)
{
xmlwriter *This = impl_from_IXmlWriter(iface);
xmlwriter *writer = impl_from_IXmlWriter(iface);
HRESULT hr = S_OK;
unsigned int count;
FIXME("%p %s %d\n", This, wine_dbgstr_w(pwch), cwch);
TRACE("%p, %s, %d.\n", iface, debugstr_wn(characters, length), length);
switch (This->state)
if ((characters == NULL && length != 0))
return E_INVALIDARG;
if (length == 0)
return S_OK;
switch (writer->state)
{
case XmlWriterState_Initial:
return E_UNEXPECTED;
@ -1822,11 +1830,25 @@ static HRESULT WINAPI xmlwriter_WriteRawChars(IXmlWriter *iface, const WCHAR *p
return MX_E_ENCODING;
case XmlWriterState_DocClosed:
return WR_E_INVALIDACTION;
case XmlWriterState_Ready:
write_xmldecl(writer, XmlStandalone_Omit);
break;
case XmlWriterState_ElemStarted:
writer_close_starttag(writer);
default:
;
}
return E_NOTIMPL;
while (length)
{
if (FAILED(hr = writer_get_next_write_count(characters, length, &count))) return hr;
if (FAILED(hr = write_output_buffer(writer->output, characters, count))) return hr;
characters += count;
length -= count;
}
return hr;
}
static HRESULT WINAPI xmlwriter_WriteStartDocument(IXmlWriter *iface, XmlStandalone standalone)