From b36e38a2a36854eb36dfb228c4b00648a815398d Mon Sep 17 00:00:00 2001 From: Amine Khaldi Date: Thu, 18 Aug 2016 10:55:43 +0000 Subject: [PATCH] [XMLLITE_WINETEST] Sync with Wine Staging 1.9.16. CORE-11866 svn path=/trunk/; revision=72318 --- rostests/winetests/xmllite/writer.c | 270 +++++++++++++++++++++++++++- 1 file changed, 263 insertions(+), 7 deletions(-) diff --git a/rostests/winetests/xmllite/writer.c b/rostests/winetests/xmllite/writer.c index 3eb67314e75..effb2e3e975 100644 --- a/rostests/winetests/xmllite/writer.c +++ b/rostests/winetests/xmllite/writer.c @@ -39,7 +39,7 @@ #include DEFINE_GUID(IID_IXmlWriterOutput, 0xc1131708, 0x0f59, 0x477f, 0x93, 0x59, 0x7d, 0x33, 0x24, 0x51, 0xbc, 0x1a); -static void check_output(IStream *stream, const char *expected, int line) +static void check_output(IStream *stream, const char *expected, BOOL todo, int line) { HGLOBAL hglobal; int len = strlen(expected), size; @@ -51,16 +51,20 @@ static void check_output(IStream *stream, const char *expected, int line) size = GlobalSize(hglobal); ptr = GlobalLock(hglobal); - if (size != len) + todo_wine_if(todo) { - ok_(__FILE__, line)(0, "data size mismatch, expected %u, got %u\n", len, size); - ok_(__FILE__, line)(0, "got %s, expected %s\n", ptr, expected); + if (size != len) + { + ok_(__FILE__, line)(0, "data size mismatch, expected %u, got %u\n", len, size); + ok_(__FILE__, line)(0, "got %s, expected %s\n", ptr, expected); + } + else + ok_(__FILE__, line)(!strncmp(ptr, expected, len), "got %s, expected %s\n", ptr, expected); } - else - ok_(__FILE__, line)(!strncmp(ptr, expected, len), "got %s, expected %s\n", ptr, expected); GlobalUnlock(hglobal); } -#define CHECK_OUTPUT(stream, expected) check_output(stream, expected, __LINE__) +#define CHECK_OUTPUT(stream, expected) check_output(stream, expected, FALSE, __LINE__) +#define CHECK_OUTPUT_TODO(stream, expected) check_output(stream, expected, TRUE, __LINE__) /* used to test all Write* methods for consistent error state */ static void check_writer_state(IXmlWriter *writer, HRESULT exp_hr) @@ -1014,6 +1018,254 @@ static void test_writer_state(void) IXmlWriter_Release(writer); } +static void test_indentation(void) +{ + static const WCHAR commentW[] = {'c','o','m','m','e','n','t',0}; + static const WCHAR aW[] = {'a',0}; + static const WCHAR bW[] = {'b',0}; + IXmlWriter *writer; + IStream *stream; + HRESULT hr; + + hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL); + ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); + + stream = writer_set_output(writer); + + hr = IXmlWriter_SetProperty(writer, XmlWriterProperty_OmitXmlDeclaration, TRUE); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_SetProperty(writer, XmlWriterProperty_Indent, TRUE); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteComment(writer, commentW); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteStartElement(writer, NULL, bW, NULL); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteEndDocument(writer); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_Flush(writer); + ok(hr == S_OK, "got 0x%08x\n", hr); + + CHECK_OUTPUT(stream, + "\r\n" + " \r\n" + " \r\n" + ""); + + IXmlWriter_Release(writer); + IStream_Release(stream); +} + +static void test_WriteAttributeString(void) +{ + 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 uri2W[] = {'u','r','i','2',0}; + static const WCHAR xmlnsW[] = {'x','m','l','n','s',0}; + static const WCHAR aW[] = {'a',0}; + static const WCHAR bW[] = {'b',0}; + IXmlWriter *writer; + IStream *stream; + HRESULT hr; + + hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL); + ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); + + stream = writer_set_output(writer); + + hr = IXmlWriter_SetProperty(writer, XmlWriterProperty_OmitXmlDeclaration, TRUE); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteAttributeString(writer, NULL, aW, NULL, bW); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteEndDocument(writer); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_Flush(writer); + ok(hr == S_OK, "got 0x%08x\n", hr); + + CHECK_OUTPUT(stream, + ""); + IStream_Release(stream); + + /* with namespaces */ + stream = writer_set_output(writer); + + hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteAttributeString(writer, aW, NULL, NULL, bW); +todo_wine + ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteAttributeString(writer, prefixW, localW, uriW, bW); +todo_wine + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteAttributeString(writer, NULL, aW, NULL, bW); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteAttributeString(writer, NULL, xmlnsW, uri2W, NULL); +todo_wine + ok(hr == WR_E_XMLNSPREFIXDECLARATION, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteAttributeString(writer, NULL, xmlnsW, NULL, uri2W); +todo_wine + ok(hr == WR_E_NSPREFIXDECLARED, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteAttributeString(writer, prefixW, localW, NULL, bW); +todo_wine + ok(hr == WR_E_DUPLICATEATTRIBUTE, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteEndDocument(writer); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_Flush(writer); + ok(hr == S_OK, "got 0x%08x\n", hr); + + CHECK_OUTPUT_TODO(stream, + ""); + + IXmlWriter_Release(writer); + IStream_Release(stream); +} + +static void test_WriteFullEndElement(void) +{ + static const WCHAR aW[] = {'a',0}; + IXmlWriter *writer; + IStream *stream; + HRESULT hr; + + hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL); + ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); + + /* standalone element */ + stream = writer_set_output(writer); + + hr = IXmlWriter_SetProperty(writer, XmlWriterProperty_OmitXmlDeclaration, TRUE); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_SetProperty(writer, XmlWriterProperty_Indent, TRUE); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteFullEndElement(writer); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteEndDocument(writer); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_Flush(writer); + ok(hr == S_OK, "got 0x%08x\n", hr); + + CHECK_OUTPUT(stream, + ""); + IStream_Release(stream); + + /* nested elements */ + stream = writer_set_output(writer); + + hr = IXmlWriter_SetProperty(writer, XmlWriterProperty_OmitXmlDeclaration, TRUE); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_SetProperty(writer, XmlWriterProperty_Indent, TRUE); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteFullEndElement(writer); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteEndDocument(writer); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_Flush(writer); + ok(hr == S_OK, "got 0x%08x\n", hr); + + CHECK_OUTPUT(stream, + "\r\n" + " \r\n" + ""); + + IXmlWriter_Release(writer); + IStream_Release(stream); +} + +static void test_WriteCharEntity(void) +{ + static const WCHAR aW[] = {'a',0}; + IXmlWriter *writer; + IStream *stream; + HRESULT hr; + + hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL); + ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); + + /* without indentation */ + stream = writer_set_output(writer); + + hr = IXmlWriter_SetProperty(writer, XmlWriterProperty_OmitXmlDeclaration, TRUE); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteCharEntity(writer, 0x100); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_WriteEndDocument(writer); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IXmlWriter_Flush(writer); + ok(hr == S_OK, "got 0x%08x\n", hr); + + CHECK_OUTPUT(stream, + "Ā"); + + IXmlWriter_Release(writer); + IStream_Release(stream); +} + START_TEST(writer) { test_writer_create(); @@ -1029,4 +1281,8 @@ START_TEST(writer) test_WriteComment(); test_WriteCData(); test_WriteRaw(); + test_indentation(); + test_WriteAttributeString(); + test_WriteFullEndElement(); + test_WriteCharEntity(); } -- 2.17.1