Commit 1a681934 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

xmllite/tests: Add a helper to test writer output.

parent b9b2dafb
...@@ -31,6 +31,29 @@ ...@@ -31,6 +31,29 @@
#include "initguid.h" #include "initguid.h"
DEFINE_GUID(IID_IXmlWriterOutput, 0xc1131708, 0x0f59, 0x477f, 0x93, 0x59, 0x7d, 0x33, 0x24, 0x51, 0xbc, 0x1a); 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)
{
HGLOBAL hglobal;
int len = strlen(expected), size;
char *ptr;
HRESULT hr;
hr = GetHGlobalFromStream(stream, &hglobal);
ok_(__FILE__, line)(hr == S_OK, "got 0x%08x\n", hr);
size = GlobalSize(hglobal);
ptr = GlobalLock(hglobal);
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);
GlobalUnlock(hglobal);
}
#define CHECK_OUTPUT(stream, expected) check_output(stream, expected, __LINE__)
static HRESULT WINAPI testoutput_QueryInterface(IUnknown *iface, REFIID riid, void **obj) static HRESULT WINAPI testoutput_QueryInterface(IUnknown *iface, REFIID riid, void **obj)
{ {
if (IsEqualGUID(riid, &IID_IUnknown)) { if (IsEqualGUID(riid, &IID_IUnknown)) {
...@@ -191,10 +214,8 @@ static void test_writestartdocument(void) ...@@ -191,10 +214,8 @@ static void test_writestartdocument(void)
static const WCHAR versionW[] = {'v','e','r','s','i','o','n','=','"','1','.','0','"',0}; static const WCHAR versionW[] = {'v','e','r','s','i','o','n','=','"','1','.','0','"',0};
static const WCHAR xmlW[] = {'x','m','l',0}; static const WCHAR xmlW[] = {'x','m','l',0};
IXmlWriter *writer; IXmlWriter *writer;
HGLOBAL hglobal;
IStream *stream; IStream *stream;
HRESULT hr; HRESULT hr;
char *ptr;
hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL); hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
...@@ -225,12 +246,7 @@ static void test_writestartdocument(void) ...@@ -225,12 +246,7 @@ static void test_writestartdocument(void)
hr = IXmlWriter_Flush(writer); hr = IXmlWriter_Flush(writer);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
hr = GetHGlobalFromStream(stream, &hglobal); CHECK_OUTPUT(stream, fullprolog);
ok(hr == S_OK, "got 0x%08x\n", hr);
ptr = GlobalLock(hglobal);
ok(!strncmp(ptr, fullprolog, strlen(fullprolog)), "got %s, expected %s\n", ptr, fullprolog);
GlobalUnlock(hglobal);
/* one more time */ /* one more time */
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes); hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
...@@ -260,12 +276,7 @@ static void test_writestartdocument(void) ...@@ -260,12 +276,7 @@ static void test_writestartdocument(void)
hr = IXmlWriter_Flush(writer); hr = IXmlWriter_Flush(writer);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
hr = GetHGlobalFromStream(stream, &hglobal); CHECK_OUTPUT(stream, prologversion);
ok(hr == S_OK, "got 0x%08x\n", hr);
ptr = GlobalLock(hglobal);
ok(!strncmp(ptr, prologversion, strlen(prologversion)), "got %s\n", ptr);
GlobalUnlock(hglobal);
IStream_Release(stream); IStream_Release(stream);
IXmlWriter_Release(writer); IXmlWriter_Release(writer);
...@@ -356,12 +367,7 @@ static void test_omitxmldeclaration(void) ...@@ -356,12 +367,7 @@ static void test_omitxmldeclaration(void)
hr = IXmlWriter_Flush(writer); hr = IXmlWriter_Flush(writer);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
hr = GetHGlobalFromStream(stream, &hglobal); CHECK_OUTPUT(stream, prologversion);
ok(hr == S_OK, "got 0x%08x\n", hr);
ptr = GlobalLock(hglobal);
ok(!strncmp(ptr, prologversion, strlen(prologversion)), "got %s\n", ptr);
GlobalUnlock(hglobal);
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes); hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
...@@ -369,9 +375,7 @@ static void test_omitxmldeclaration(void) ...@@ -369,9 +375,7 @@ static void test_omitxmldeclaration(void)
hr = IXmlWriter_Flush(writer); hr = IXmlWriter_Flush(writer);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
ptr = GlobalLock(hglobal); CHECK_OUTPUT(stream, prologversion);
ok(!strncmp(ptr, prologversion, strlen(prologversion)), "got %s\n", ptr);
GlobalUnlock(hglobal);
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes); hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr); ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
...@@ -379,9 +383,7 @@ static void test_omitxmldeclaration(void) ...@@ -379,9 +383,7 @@ static void test_omitxmldeclaration(void)
hr = IXmlWriter_Flush(writer); hr = IXmlWriter_Flush(writer);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
ptr = GlobalLock(hglobal); CHECK_OUTPUT(stream, prologversion);
ok(!strncmp(ptr, prologversion, strlen(prologversion)), "got %s\n", ptr);
GlobalUnlock(hglobal);
/* another attempt to add 'xml' PI */ /* another attempt to add 'xml' PI */
hr = IXmlWriter_WriteProcessingInstruction(writer, xmlW, versionW); hr = IXmlWriter_WriteProcessingInstruction(writer, xmlW, versionW);
...@@ -526,10 +528,8 @@ static void test_writestartelement(void) ...@@ -526,10 +528,8 @@ static void test_writestartelement(void)
static const char *str = "<a><b>value</b>"; static const char *str = "<a><b>value</b>";
static const WCHAR aW[] = {'a',0}; static const WCHAR aW[] = {'a',0};
static const WCHAR bW[] = {'b',0}; static const WCHAR bW[] = {'b',0};
char *ptr;
IXmlWriter *writer; IXmlWriter *writer;
IStream *stream; IStream *stream;
HGLOBAL hglobal;
HRESULT hr; HRESULT hr;
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream); hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
...@@ -556,18 +556,13 @@ static void test_writestartelement(void) ...@@ -556,18 +556,13 @@ static void test_writestartelement(void)
hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL); hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
hr = GetHGlobalFromStream(stream, &hglobal);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes); hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr); ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
hr = IXmlWriter_Flush(writer); hr = IXmlWriter_Flush(writer);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
ptr = GlobalLock(hglobal); CHECK_OUTPUT(stream, "<a");
ok(!strncmp(ptr, "<a", 2), "got %s\n", ptr);
GlobalUnlock(hglobal);
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes); hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr); ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
...@@ -603,12 +598,7 @@ static void test_writestartelement(void) ...@@ -603,12 +598,7 @@ static void test_writestartelement(void)
hr = IXmlWriter_Flush(writer); hr = IXmlWriter_Flush(writer);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
hr = GetHGlobalFromStream(stream, &hglobal); CHECK_OUTPUT(stream, str);
ok(hr == S_OK, "got 0x%08x\n", hr);
ptr = GlobalLock(hglobal);
ok(!strncmp(ptr, str, strlen(str)), "got %s\n", ptr);
GlobalUnlock(hglobal);
IStream_Release(stream); IStream_Release(stream);
IXmlWriter_Release(writer); IXmlWriter_Release(writer);
...@@ -618,10 +608,8 @@ static void test_writeendelement(void) ...@@ -618,10 +608,8 @@ static void test_writeendelement(void)
{ {
static const WCHAR aW[] = {'a',0}; static const WCHAR aW[] = {'a',0};
static const WCHAR bW[] = {'b',0}; static const WCHAR bW[] = {'b',0};
char *ptr;
IXmlWriter *writer; IXmlWriter *writer;
IStream *stream; IStream *stream;
HGLOBAL hglobal;
HRESULT hr; HRESULT hr;
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream); hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
...@@ -645,15 +633,10 @@ static void test_writeendelement(void) ...@@ -645,15 +633,10 @@ static void test_writeendelement(void)
hr = IXmlWriter_WriteEndElement(writer); hr = IXmlWriter_WriteEndElement(writer);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
hr = GetHGlobalFromStream(stream, &hglobal);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_Flush(writer); hr = IXmlWriter_Flush(writer);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
ptr = GlobalLock(hglobal); CHECK_OUTPUT(stream, "<a><b /></a>");
ok(!strncmp(ptr, "<a><b /></a>", 12), "got %s\n", ptr);
GlobalUnlock(hglobal);
IXmlWriter_Release(writer); IXmlWriter_Release(writer);
IStream_Release(stream); IStream_Release(stream);
...@@ -716,10 +699,7 @@ static void test_writeenddocument(void) ...@@ -716,10 +699,7 @@ static void test_writeenddocument(void)
hr = IXmlWriter_Flush(writer); hr = IXmlWriter_Flush(writer);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
ptr = GlobalLock(hglobal); CHECK_OUTPUT(stream, "<a><b /></a>");
ok(ptr != NULL, "got %p\n", ptr);
ok(!strncmp(ptr, "<a><b /></a>", 12), "got %s\n", ptr);
GlobalUnlock(hglobal);
IXmlWriter_Release(writer); IXmlWriter_Release(writer);
IStream_Release(stream); IStream_Release(stream);
...@@ -732,9 +712,7 @@ static void test_WriteComment(void) ...@@ -732,9 +712,7 @@ static void test_WriteComment(void)
static const WCHAR bW[] = {'b',0}; static const WCHAR bW[] = {'b',0};
IXmlWriter *writer; IXmlWriter *writer;
IStream *stream; IStream *stream;
HGLOBAL hglobal;
HRESULT hr; HRESULT hr;
char *ptr;
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream); hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
...@@ -772,13 +750,7 @@ static void test_WriteComment(void) ...@@ -772,13 +750,7 @@ static void test_WriteComment(void)
hr = IXmlWriter_Flush(writer); hr = IXmlWriter_Flush(writer);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
hr = GetHGlobalFromStream(stream, &hglobal); CHECK_OUTPUT(stream, "<!--a--><b><!--a--><!----><!--- ->-->");
ok(hr == S_OK, "got 0x%08x\n", hr);
ptr = GlobalLock(hglobal);
ok(ptr != NULL, "got %p\n", ptr);
ok(!strncmp(ptr, "<!--a--><b><!--a--><!----><!--- ->-->", 37), "got %s\n", ptr);
GlobalUnlock(hglobal);
IXmlWriter_Release(writer); IXmlWriter_Release(writer);
IStream_Release(stream); IStream_Release(stream);
...@@ -792,9 +764,7 @@ static void test_WriteCData(void) ...@@ -792,9 +764,7 @@ static void test_WriteCData(void)
static const WCHAR bW[] = {'b',0}; static const WCHAR bW[] = {'b',0};
IXmlWriter *writer; IXmlWriter *writer;
IStream *stream; IStream *stream;
HGLOBAL hglobal;
HRESULT hr; HRESULT hr;
char *ptr;
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream); hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
...@@ -829,22 +799,14 @@ static void test_WriteCData(void) ...@@ -829,22 +799,14 @@ static void test_WriteCData(void)
hr = IXmlWriter_Flush(writer); hr = IXmlWriter_Flush(writer);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
hr = GetHGlobalFromStream(stream, &hglobal); CHECK_OUTPUT(stream,
ok(hr == S_OK, "got 0x%08x\n", hr);
ptr = GlobalLock(hglobal);
ok(ptr != NULL, "got %p\n", ptr);
ok(!strncmp(ptr,
"<b>" "<b>"
"<![CDATA[a]]>" "<![CDATA[a]]>"
"<![CDATA[]]>" "<![CDATA[]]>"
"<![CDATA[]]]]>" "<![CDATA[]]]]>"
"<![CDATA[>]]>" "<![CDATA[>]]>"
"<![CDATA[a]]]]>" "<![CDATA[a]]]]>"
"<![CDATA[>b]]>", 84), "got %s\n", ptr); "<![CDATA[>b]]>");
GlobalUnlock(hglobal);
IXmlWriter_Release(writer); IXmlWriter_Release(writer);
IStream_Release(stream); IStream_Release(stream);
...@@ -855,9 +817,7 @@ static void test_WriteRaw(void) ...@@ -855,9 +817,7 @@ static void test_WriteRaw(void)
static const WCHAR rawW[] = {'a','<',':',0}; static const WCHAR rawW[] = {'a','<',':',0};
IXmlWriter *writer; IXmlWriter *writer;
IStream *stream; IStream *stream;
HGLOBAL hglobal;
HRESULT hr; HRESULT hr;
char *ptr;
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream); hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
...@@ -895,17 +855,7 @@ static void test_WriteRaw(void) ...@@ -895,17 +855,7 @@ static void test_WriteRaw(void)
hr = IXmlWriter_Flush(writer); hr = IXmlWriter_Flush(writer);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
hr = GetHGlobalFromStream(stream, &hglobal); CHECK_OUTPUT(stream, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>a<:");
ok(hr == S_OK, "got 0x%08x\n", hr);
ptr = GlobalLock(hglobal);
ok(ptr != NULL, "got %p\n", ptr);
ok(!strncmp(ptr,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"a<:", 41), "got %s\n", ptr);
GlobalUnlock(hglobal);
IXmlWriter_Release(writer); IXmlWriter_Release(writer);
IStream_Release(stream); IStream_Release(stream);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment