From: David Kahurani <k.kahurani(a)gmail.com>
Validate a name, associate it with a prefix, if present thereof
and write the qualified name to the out
Signed-off-by: David Kahurani <k.kahurani(a)gmail.com>
---
dlls/xmllite/tests/writer.c | 122 ++++++++++++++++++++++++++++++++++++
dlls/xmllite/writer.c | 36 +++++++++--
2 files changed, 152 insertions(+), 6 deletions(-)
diff --git a/dlls/xmllite/tests/writer.c b/dlls/xmllite/tests/writer.c
index 3a44af1c063..1185fc34101 100644
--- a/dlls/xmllite/tests/writer.c
+++ b/dlls/xmllite/tests/writer.c
@@ -2027,6 +2027,127 @@ static void test_WriteNmToken(void)
IXmlWriter_Release(writer);
}
+static void test_WriteQualifiedName(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_WriteQualifiedName(writer, L"", L"cd");
+ ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
+
+ hr = IXmlWriter_WriteQualifiedName(writer, NULL, L"cd");
+ ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
+
+ hr = IXmlWriter_WriteQualifiedName(writer, L"ab", L"xyz@xyz");
+ ok(hr == E_UNEXPECTED, "Unexpected hr %#lx.\n", hr);
+
+ hr = IXmlWriter_WriteQualifiedName(writer, L"ab", NULL);
+ ok(hr == E_UNEXPECTED, "Unexpected hr %#lx.\n", hr);
+
+ hr = IXmlWriter_WriteQualifiedName(writer, L"ab", L"cd");
+ ok(hr == E_UNEXPECTED, "Unexpected hr %#lx.\n", hr);
+
+ stream = writer_set_output(writer);
+
+ writer_set_property(writer, XmlWriterProperty_OmitXmlDeclaration);
+
+ hr = IXmlWriter_WriteQualifiedName(writer, L"ab", L"cd");
+ 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, L"ab", L"a",
L"cd");
+ ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
+
+ hr = IXmlWriter_WriteQualifiedName(writer, L"a@b", L"cd");
+ ok(hr == WC_E_NAMECHARACTER, "Unexpected hr %#lx.\n", hr);
+
+ hr = IXmlWriter_Flush(writer);
+ ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
+
+ CHECK_OUTPUT(stream,
+ "<ab: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, L"ab", L"a",
L"cd");
+ ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
+
+ hr = IXmlWriter_WriteQualifiedName(writer, L"ab", L"de");
+ ok(hr == WR_E_NAMESPACEUNDECLARED, "Unexpected hr %#lx.\n", hr);
+
+ hr = IXmlWriter_Flush(writer);
+ ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
+
+ CHECK_OUTPUT(stream,
+ "<ab:a xmlns:ab=\"cd\">");
+
+ IStream_Release(stream);
+ stream = writer_set_output(writer);
+
+ writer_set_property(writer, XmlWriterProperty_OmitXmlDeclaration);
+
+ hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit);
+ ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
+
+ hr = IXmlWriter_WriteStartElement(writer, NULL, L"a", L"cd");
+ ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
+
+ hr = IXmlWriter_WriteStartElement(writer, NULL, L"b", L"gh");
+ ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
+
+ hr = IXmlWriter_WriteQualifiedName(writer, L"xy", L"cd");
+ 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,
+ "<a xmlns=\"cd\"><b
xmlns=\"gh\">xy</b></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, L"ab", L"a",
L"cd");
+ ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
+
+ hr = IXmlWriter_WriteStartElement(writer, L"ef", L"b",
L"gh");
+ ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
+
+ hr = IXmlWriter_WriteQualifiedName(writer, L"xy", L"cd");
+ 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,
+ "<ab:a xmlns:ab=\"cd\"><ef:b
xmlns:ef=\"gh\">ab:xy</ef:b></ab:a>");
+
+ IStream_Release(stream);
+ IXmlWriter_Release(writer);
+}
+
static void test_WriteFullEndElement(void)
{
IXmlWriter *writer;
@@ -3216,4 +3337,5 @@ START_TEST(writer)
test_WriteName();
test_WriteEntityRef();
test_WriteNmToken();
+ test_WriteQualifiedName();
}
diff --git a/dlls/xmllite/writer.c b/dlls/xmllite/writer.c
index bb52b380ce5..d6f93d1c2dd 100644
--- a/dlls/xmllite/writer.c
+++ b/dlls/xmllite/writer.c
@@ -1804,26 +1804,50 @@ static HRESULT WINAPI
xmlwriter_WriteProcessingInstruction(IXmlWriter *iface, LP
return S_OK;
}
-static HRESULT WINAPI xmlwriter_WriteQualifiedName(IXmlWriter *iface, LPCWSTR
pwszLocalName,
- LPCWSTR pwszNamespaceUri)
+static HRESULT WINAPI xmlwriter_WriteQualifiedName(IXmlWriter *iface, LPCWSTR local,
+ LPCWSTR uri)
{
- xmlwriter *This = impl_from_IXmlWriter(iface);
+ xmlwriter *writer = impl_from_IXmlWriter(iface);
+ struct ns *ns;
+ int local_len;
- FIXME("%p %s %s\n", This, wine_dbgstr_w(pwszLocalName),
wine_dbgstr_w(pwszNamespaceUri));
+ TRACE("%p %s %s\n", iface, wine_dbgstr_w(local), wine_dbgstr_w(uri));
- switch (This->state)
+ if (is_empty_string(local))
+ return E_INVALIDARG;
+
+ if (is_valid_ncname(local, &local_len))
+ return WC_E_NAMECHARACTER;
+
+ switch (writer->state)
{
case XmlWriterState_Initial:
return E_UNEXPECTED;
case XmlWriterState_InvalidEncoding:
return MX_E_ENCODING;
+ case XmlWriterState_Ready:
case XmlWriterState_DocClosed:
return WR_E_INVALIDACTION;
+ case XmlWriterState_ElemStarted:
+ writer_close_starttag(writer);
+ break;
default:
;
}
- return E_NOTIMPL;
+ ns = writer_find_ns(writer, NULL, uri);
+
+ if (!ns)
+ return WR_E_NAMESPACEUNDECLARED;
+
+ if (ns->prefix)
+ {
+ write_output_buffer(writer->output, ns->prefix, ns->prefix_len);
+ write_output_buffer_char(writer->output, ':');
+ }
+
+ write_output_buffer(writer->output, local, local_len);
+ return S_OK;
}
static HRESULT WINAPI xmlwriter_WriteRaw(IXmlWriter *iface, LPCWSTR data)
--
GitLab
https://gitlab.winehq.org/wine/wine/-/merge_requests/2928