mirror of
git://source.winehq.org/git/wine.git
synced 2024-09-01 12:43:38 +00:00
xmllite/writer: Implement WriteWhitespace().
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
parent
31aac84ad0
commit
225e7b34a9
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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__ */
|
||||
|
|
Loading…
Reference in a new issue