From: David Kahurani k.kahurani@gmail.com
Writes a qualified name to output after validating it.
Signed-off-by: David Kahurani k.kahurani@gmail.com --- dlls/xmllite/tests/writer.c | 98 +++++++++++++++++++++++++++++++++++++ dlls/xmllite/writer.c | 31 +++++++++--- 2 files changed, 123 insertions(+), 6 deletions(-)
diff --git a/dlls/xmllite/tests/writer.c b/dlls/xmllite/tests/writer.c index 572b3a9fd67..90226b2eb4d 100644 --- a/dlls/xmllite/tests/writer.c +++ b/dlls/xmllite/tests/writer.c @@ -1785,6 +1785,103 @@ static void test_WriteAttributeString(void) IXmlWriter_Release(writer); }
+static void test_WriteName(void) +{ + IXmlWriter *writer; + IStream *stream; + HRESULT hr; + + hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteName(writer, L""); + ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteName(writer, NULL); + ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteName(writer, L"name"); + ok(hr == E_UNEXPECTED, "Unexpected hr %#lx.\n", hr); + + stream = writer_set_output(writer); + writer_set_property(writer, XmlWriterProperty_OmitXmlDeclaration); + + hr = IXmlWriter_WriteName(writer, L"name"); + ok(hr == WR_E_INVALIDACTION, "Unexpected hr %#lx.\n", hr); + + IStream_Release(stream); + stream = writer_set_output(writer); + + hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteStartElement(writer, NULL, L"a", NULL); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteName(writer, L"a:a:a"); + ok(hr == WC_E_NAMECHARACTER, "Unexpcted hr %#lx.\n", hr); + + hr = IXmlWriter_Flush(writer); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + CHECK_OUTPUT(stream, + "<a"); + + IStream_Release(stream); + stream = writer_set_output(writer); + + 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_WriteStartElement(writer, NULL, L"a", NULL); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteName(writer, L"name"); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteFullEndElement(writer); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteStartElement(writer, NULL, L"b", NULL); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteName(writer, L"ab:name"); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteEndDocument(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><a>name</a><b>ab:name</b></root>"); + + IStream_Release(stream); + stream = writer_set_output(writer); + + hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteStartElement(writer, NULL, L"a", NULL); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_WriteName(writer, L""); + ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr); + + hr = IXmlWriter_Flush(writer); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + CHECK_OUTPUT(stream, + "<a"); + + IStream_Release(stream); + IXmlWriter_Release(writer); +} + static void test_WriteFullEndElement(void) { IXmlWriter *writer; @@ -2971,4 +3068,5 @@ START_TEST(writer) test_WriteAttributes(); test_WriteNode(); test_WriteNodeShallow(); + test_WriteName(); } diff --git a/dlls/xmllite/writer.c b/dlls/xmllite/writer.c index 128d666e82c..f4d1a474232 100644 --- a/dlls/xmllite/writer.c +++ b/dlls/xmllite/writer.c @@ -1541,27 +1541,46 @@ static HRESULT WINAPI xmlwriter_WriteFullEndElement(IXmlWriter *iface) return S_OK; }
-static HRESULT WINAPI xmlwriter_WriteName(IXmlWriter *iface, LPCWSTR pwszName) +static HRESULT WINAPI xmlwriter_WriteName(IXmlWriter *iface, LPCWSTR qname) { - xmlwriter *This = impl_from_IXmlWriter(iface); + xmlwriter *writer = impl_from_IXmlWriter(iface); + const WCHAR *p = qname;
- FIXME("%p %s\n", This, wine_dbgstr_w(pwszName)); + TRACE("%p %s\n", iface, wine_dbgstr_w(qname));
- switch (This->state) + if (is_empty_string(qname)) + return E_INVALIDARG; + + while (*p && is_ncnamechar(*p)) + p++; + + if (*p && *p++ == ':') + { + while (*p && is_ncnamechar(*p)) + p++; + } + + if (*p) return WC_E_NAMECHARACTER; + + switch (writer->state) { case XmlWriterState_Initial: return E_UNEXPECTED; case XmlWriterState_Ready: case XmlWriterState_DocClosed: - This->state = XmlWriterState_DocClosed; + writer->state = XmlWriterState_DocClosed; return WR_E_INVALIDACTION; case XmlWriterState_InvalidEncoding: return MX_E_ENCODING; + case XmlWriterState_ElemStarted: + writer_close_starttag(writer); + break; default: ; }
- return E_NOTIMPL; + write_output_buffer(writer->output, qname, p - qname); + return S_OK; }
static HRESULT WINAPI xmlwriter_WriteNmToken(IXmlWriter *iface, LPCWSTR pwszNmToken)