xmllite/tests: Add another test for WriteAttributeString().

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2018-09-12 16:25:51 +03:00 committed by Alexandre Julliard
parent 7090d74750
commit 9730971e8e
1 changed files with 33 additions and 29 deletions

View File

@ -1572,6 +1572,27 @@ static void test_indentation(void)
IXmlWriter_Release(writer); IXmlWriter_Release(writer);
} }
static HRESULT write_attribute_string(IXmlWriter *writer, const char *prefix, const char *local,
const char *uri, const char *value)
{
WCHAR *prefixW, *localW, *uriW, *valueW;
HRESULT hr;
prefixW = strdupAtoW(prefix);
localW = strdupAtoW(local);
uriW = strdupAtoW(uri);
valueW = strdupAtoW(value);
hr = IXmlWriter_WriteAttributeString(writer, prefixW, localW, uriW, valueW);
heap_free(prefixW);
heap_free(localW);
heap_free(uriW);
heap_free(valueW);
return hr;
}
static void test_WriteAttributeString(void) static void test_WriteAttributeString(void)
{ {
static const struct static const struct
@ -1589,6 +1610,7 @@ static void test_WriteAttributeString(void)
{ NULL, "a", NULL, "b", "<e a=\"b\" />", "<e a=\"b\"" }, { NULL, "a", NULL, "b", "<e a=\"b\" />", "<e a=\"b\"" },
{ "prefix", "local", "uri", "b", "<e prefix:local=\"b\" xmlns:prefix=\"uri\" />", "<e prefix:local=\"b\"" }, { "prefix", "local", "uri", "b", "<e prefix:local=\"b\" xmlns:prefix=\"uri\" />", "<e prefix:local=\"b\"" },
{ NULL, "a", "http://www.w3.org/2000/xmlns/", "defuri", "<e xmlns:a=\"defuri\" />", "<e xmlns:a=\"defuri\"" }, { NULL, "a", "http://www.w3.org/2000/xmlns/", "defuri", "<e xmlns:a=\"defuri\" />", "<e xmlns:a=\"defuri\"" },
{ "xmlns", "a", NULL, "uri", "<e xmlns:a=\"uri\" />", "<e xmlns:a=\"uri\"" },
/* Autogenerated prefix names. */ /* Autogenerated prefix names. */
{ NULL, "a", "defuri", NULL, "<e p1:a=\"\" xmlns:p1=\"defuri\" />", "<e p1:a=\"\"" }, { NULL, "a", "defuri", NULL, "<e p1:a=\"\" xmlns:p1=\"defuri\" />", "<e p1:a=\"\"" },
@ -1606,12 +1628,6 @@ static void test_WriteAttributeString(void)
{ "prefix", "a", "http://www.w3.org/2000/xmlns/", "defuri", "<e />", "<e", WR_E_XMLNSURIDECLARATION }, { "prefix", "a", "http://www.w3.org/2000/xmlns/", "defuri", "<e />", "<e", WR_E_XMLNSURIDECLARATION },
}; };
static const WCHAR prefixW[] = {'p','r','e','f','i','x',0};
static const WCHAR localW[] = {'l','o','c','a','l',0};
static const WCHAR uriW[] = {'u','r','i',0};
static const WCHAR elementW[] = {'e',0};
static const WCHAR aW[] = {'a',0};
static const WCHAR bW[] = {'b',0};
IXmlWriter *writer; IXmlWriter *writer;
IStream *stream; IStream *stream;
unsigned int i; unsigned int i;
@ -1624,22 +1640,16 @@ static void test_WriteAttributeString(void)
for (i = 0; i < ARRAY_SIZE(attribute_tests); ++i) for (i = 0; i < ARRAY_SIZE(attribute_tests); ++i)
{ {
WCHAR *prefixW, *localW, *uriW, *valueW;
stream = writer_set_output(writer); stream = writer_set_output(writer);
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit); hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit);
ok(hr == S_OK, "Failed to start document, hr %#x.\n", hr); ok(hr == S_OK, "Failed to start document, hr %#x.\n", hr);
hr = IXmlWriter_WriteStartElement(writer, NULL, elementW, NULL); hr = write_start_element(writer, NULL, "e", NULL);
ok(hr == S_OK, "Failed to start element, hr %#x.\n", hr); ok(hr == S_OK, "Failed to start element, hr %#x.\n", hr);
prefixW = strdupAtoW(attribute_tests[i].prefix); hr = write_attribute_string(writer, attribute_tests[i].prefix, attribute_tests[i].local,
localW = strdupAtoW(attribute_tests[i].local); attribute_tests[i].uri, attribute_tests[i].value);
uriW = strdupAtoW(attribute_tests[i].uri);
valueW = strdupAtoW(attribute_tests[i].value);
hr = IXmlWriter_WriteAttributeString(writer, prefixW, localW, uriW, valueW);
todo_wine_if(i != 0) todo_wine_if(i != 0)
ok(hr == attribute_tests[i].hr, "%u: unexpected hr %#x.\n", i, hr); ok(hr == attribute_tests[i].hr, "%u: unexpected hr %#x.\n", i, hr);
@ -1654,11 +1664,6 @@ static void test_WriteAttributeString(void)
hr = IXmlWriter_Flush(writer); hr = IXmlWriter_Flush(writer);
ok(hr == S_OK, "Failed to flush, hr %#x.\n", hr); ok(hr == S_OK, "Failed to flush, hr %#x.\n", hr);
heap_free(prefixW);
heap_free(localW);
heap_free(uriW);
heap_free(valueW);
check_output(stream, attribute_tests[i].output, i == 1 || i == 2 || i == 3 || i == 4, __LINE__); check_output(stream, attribute_tests[i].output, i == 1 || i == 2 || i == 3 || i == 4, __LINE__);
IStream_Release(stream); IStream_Release(stream);
} }
@ -1669,21 +1674,20 @@ static void test_WriteAttributeString(void)
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit); hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL); hr = write_start_element(writer, "p", "a", "outeruri");
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_WriteAttributeString(writer, aW, NULL, NULL, bW); hr = write_attribute_string(writer, "prefix", "local", "uri", "b");
todo_wine
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
hr = IXmlWriter_WriteAttributeString(writer, prefixW, localW, uriW, bW);
todo_wine todo_wine
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_WriteAttributeString(writer, NULL, aW, NULL, bW); hr = write_attribute_string(writer, NULL, "a", NULL, "b");
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_WriteAttributeString(writer, prefixW, localW, NULL, bW); hr = write_attribute_string(writer, "p", "attr", NULL, "value");
ok(hr == S_OK, "Failed to write attribute string, hr %#x.\n", hr);
hr = write_attribute_string(writer, "prefix", "local", NULL, "b");
todo_wine todo_wine
ok(hr == WR_E_DUPLICATEATTRIBUTE, "got 0x%08x\n", hr); ok(hr == WR_E_DUPLICATEATTRIBUTE, "got 0x%08x\n", hr);
@ -1694,7 +1698,7 @@ todo_wine
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
CHECK_OUTPUT_TODO(stream, CHECK_OUTPUT_TODO(stream,
"<a prefix:local=\"b\" a=\"b\" xmlns:prefix=\"uri\" />"); "<p:a prefix:local=\"b\" a=\"b\" p:attr=\"value\" xmlns:prefix=\"uri\" xmlns:p=\"outeruri\" />");
IXmlWriter_Release(writer); IXmlWriter_Release(writer);
IStream_Release(stream); IStream_Release(stream);