From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/xmllite/reader.c | 5 ---- dlls/xmllite/tests/writer.c | 51 ++++++++++++++++++++++++++++------ dlls/xmllite/writer.c | 31 ++++++++++++++++++--- dlls/xmllite/xmllite_private.h | 5 ++++ 4 files changed, 74 insertions(+), 18 deletions(-)
diff --git a/dlls/xmllite/reader.c b/dlls/xmllite/reader.c index 6e5e08734bc..d747e36e623 100644 --- a/dlls/xmllite/reader.c +++ b/dlls/xmllite/reader.c @@ -1159,11 +1159,6 @@ static void reader_skipn(xmlreader *reader, int n) } }
-static inline BOOL is_wchar_space(WCHAR ch) -{ - return ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n'; -} - /* [3] S ::= (#x20 | #x9 | #xD | #xA)+ */ static int reader_skipspaces(xmlreader *reader) { diff --git a/dlls/xmllite/tests/writer.c b/dlls/xmllite/tests/writer.c index 3e1c362664e..a000bde6d80 100644 --- a/dlls/xmllite/tests/writer.c +++ b/dlls/xmllite/tests/writer.c @@ -148,28 +148,30 @@ static void check_writer_state(IXmlWriter *writer, HRESULT exp_hr) /* FIXME: add WriteNodeShallow */
hr = IXmlWriter_WriteProcessingInstruction(writer, L"a", 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);
hr = IXmlWriter_WriteQualifiedName(writer, L"a", NULL); - 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);
hr = IXmlWriter_WriteRaw(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);
hr = IXmlWriter_WriteRawChars(writer, L"a", 1); - 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);
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit); - 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);
hr = IXmlWriter_WriteStartElement(writer, NULL, L"a", NULL); - 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);
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 */ - /* FIXME: add WriteWhitespace */ + + hr = IXmlWriter_WriteWhitespace(writer, L" "); + ok(hr == exp_hr, "Unexpected hr %#lx, expected %#lx.\n", hr, exp_hr); }
static IStream *writer_set_output(IXmlWriter *writer) @@ -388,7 +390,9 @@ static void test_invalid_output_encoding(IXmlWriter *writer, IUnknown *output) ok(hr == MX_E_ENCODING, "Unexpected hr %#lx.\n", hr);
/* TODO: WriteSurrogateCharEntity */ - /* TODO: WriteWhitespace */ + + hr = IXmlWriter_WriteWhitespace(writer, L" "); + 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); @@ -2063,6 +2067,34 @@ static void test_WriteDocType(void) IXmlWriter_Release(writer); }
+static void test_WriteWhitespace(void) +{ + IXmlWriter *writer; + IStream *stream; + HRESULT hr; + + hr = CreateXmlWriter(&IID_IXmlWriter, (void **)&writer, NULL); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + stream = writer_set_output(writer); + + hr = IXmlWriter_WriteWhitespace(writer, L" "); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + hr = IXmlWriter_WriteWhitespace(writer, L"ab"); + ok(hr == WR_E_NONWHITESPACE, "Unexpected hr %#lx.\n", hr); + hr = IXmlWriter_WriteStartElement(writer, NULL, L"w", NULL); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + hr = IXmlWriter_WriteWhitespace(writer, L"\t"); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_Flush(writer); + ok(hr == S_OK, "Failed to flush, hr %#lx.\n", hr); + CHECK_OUTPUT(stream, " <w>\t"); + IStream_Release(stream); + + IXmlWriter_Release(writer); +} + START_TEST(writer) { test_writer_create(); @@ -2085,4 +2117,5 @@ START_TEST(writer) test_WriteCharEntity(); test_WriteString(); test_WriteDocType(); + test_WriteWhitespace(); } diff --git a/dlls/xmllite/writer.c b/dlls/xmllite/writer.c index 6f455ffcb19..0a3717d426e 100644 --- a/dlls/xmllite/writer.c +++ b/dlls/xmllite/writer.c @@ -1752,13 +1752,36 @@ static HRESULT WINAPI xmlwriter_WriteSurrogateCharEntity(IXmlWriter *iface, WCHA return E_NOTIMPL; }
-static HRESULT WINAPI xmlwriter_WriteWhitespace(IXmlWriter *iface, LPCWSTR pwszWhitespace) +static HRESULT WINAPI xmlwriter_WriteWhitespace(IXmlWriter *iface, LPCWSTR text) { - xmlwriter *This = impl_from_IXmlWriter(iface); + xmlwriter *writer = impl_from_IXmlWriter(iface); + size_t length = 0;
- FIXME("%p %s\n", This, wine_dbgstr_w(pwszWhitespace)); + TRACE("%p, %s.\n", iface, wine_dbgstr_w(text));
- return E_NOTIMPL; + switch (writer->state) + { + case XmlWriterState_Initial: + return E_UNEXPECTED; + case XmlWriterState_ElemStarted: + writer_close_starttag(writer); + break; + case XmlWriterState_InvalidEncoding: + return MX_E_ENCODING; + case XmlWriterState_Ready: + break; + default: + return WR_E_INVALIDACTION; + } + + while (text[length]) + { + if (!is_wchar_space(text[length])) return WR_E_NONWHITESPACE; + length++; + } + + write_output_buffer(writer->output, text, length); + return S_OK; }
static HRESULT WINAPI xmlwriter_Flush(IXmlWriter *iface) diff --git a/dlls/xmllite/xmllite_private.h b/dlls/xmllite/xmllite_private.h index 03653bbe371..bd53fca575f 100644 --- a/dlls/xmllite/xmllite_private.h +++ b/dlls/xmllite/xmllite_private.h @@ -63,4 +63,9 @@ BOOL is_pubchar(WCHAR ch) DECLSPEC_HIDDEN; BOOL is_namestartchar(WCHAR ch) DECLSPEC_HIDDEN; BOOL is_namechar(WCHAR ch) DECLSPEC_HIDDEN;
+static inline BOOL is_wchar_space(WCHAR ch) +{ + return ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n'; +} + #endif /* __XMLLITE_PRIVATE__ */