Commit 450a343f authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

xmllite/tests: Add a helper to create/set writer output.

parent 1a681934
...@@ -54,6 +54,20 @@ static void check_output(IStream *stream, const char *expected, int line) ...@@ -54,6 +54,20 @@ static void check_output(IStream *stream, const char *expected, int line)
} }
#define CHECK_OUTPUT(stream, expected) check_output(stream, expected, __LINE__) #define CHECK_OUTPUT(stream, expected) check_output(stream, expected, __LINE__)
static IStream *writer_set_output(IXmlWriter *writer)
{
IStream *stream;
HRESULT hr;
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_SetOutput(writer, (IUnknown*)stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
return stream;
}
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)) {
...@@ -230,11 +244,7 @@ static void test_writestartdocument(void) ...@@ -230,11 +244,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 = CreateStreamOnHGlobal(NULL, TRUE, &stream); stream = writer_set_output(writer);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_SetOutput(writer, (IUnknown*)stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
/* nothing written yet */ /* nothing written yet */
hr = IXmlWriter_Flush(writer); hr = IXmlWriter_Flush(writer);
...@@ -254,11 +264,7 @@ static void test_writestartdocument(void) ...@@ -254,11 +264,7 @@ static void test_writestartdocument(void)
IStream_Release(stream); IStream_Release(stream);
/* now add PI manually, and try to start a document */ /* now add PI manually, and try to start a document */
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream); stream = writer_set_output(writer);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_SetOutput(writer, (IUnknown*)stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_WriteProcessingInstruction(writer, xmlW, versionW); hr = IXmlWriter_WriteProcessingInstruction(writer, xmlW, versionW);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
...@@ -326,11 +332,7 @@ static void test_omitxmldeclaration(void) ...@@ -326,11 +332,7 @@ static void test_omitxmldeclaration(void)
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);
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream); stream = writer_set_output(writer);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_SetOutput(writer, (IUnknown*)stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_SetProperty(writer, XmlWriterProperty_OmitXmlDeclaration, TRUE); hr = IXmlWriter_SetProperty(writer, XmlWriterProperty_OmitXmlDeclaration, TRUE);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
...@@ -355,11 +357,7 @@ static void test_omitxmldeclaration(void) ...@@ -355,11 +357,7 @@ static void test_omitxmldeclaration(void)
IStream_Release(stream); IStream_Release(stream);
/* now add PI manually, and try to start a document */ /* now add PI manually, and try to start a document */
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream); stream = writer_set_output(writer);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_SetOutput(writer, (IUnknown*)stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_WriteProcessingInstruction(writer, xmlW, versionW); hr = IXmlWriter_WriteProcessingInstruction(writer, xmlW, versionW);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
...@@ -532,17 +530,13 @@ static void test_writestartelement(void) ...@@ -532,17 +530,13 @@ static void test_writestartelement(void)
IStream *stream; IStream *stream;
HRESULT hr; HRESULT hr;
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
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);
hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL); hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL);
ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr); ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
hr = IXmlWriter_SetOutput(writer, (IUnknown*)stream); stream = writer_set_output(writer);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_WriteStartElement(writer, aW, NULL, NULL); hr = IXmlWriter_WriteStartElement(writer, aW, NULL, NULL);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
...@@ -580,14 +574,10 @@ static void test_writestartelement(void) ...@@ -580,14 +574,10 @@ static void test_writestartelement(void)
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);
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_WriteElementString(writer, NULL, bW, NULL, valueW); hr = IXmlWriter_WriteElementString(writer, NULL, bW, NULL, valueW);
ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr); ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
hr = IXmlWriter_SetOutput(writer, (IUnknown*)stream); stream = writer_set_output(writer);
ok(hr == S_OK, "got 0x%08x\n", hr);
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);
...@@ -612,14 +602,10 @@ static void test_writeendelement(void) ...@@ -612,14 +602,10 @@ static void test_writeendelement(void)
IStream *stream; IStream *stream;
HRESULT hr; HRESULT hr;
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
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);
hr = IXmlWriter_SetOutput(writer, (IUnknown*)stream); stream = writer_set_output(writer);
ok(hr == S_OK, "got 0x%08x\n", hr);
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);
...@@ -652,17 +638,13 @@ static void test_writeenddocument(void) ...@@ -652,17 +638,13 @@ static void test_writeenddocument(void)
HRESULT hr; HRESULT hr;
char *ptr; char *ptr;
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
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);
hr = IXmlWriter_WriteEndDocument(writer); hr = IXmlWriter_WriteEndDocument(writer);
ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr); ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
hr = IXmlWriter_SetOutput(writer, (IUnknown*)stream); stream = writer_set_output(writer);
ok(hr == S_OK, "got 0x%08x\n", hr);
/* WriteEndDocument resets it to initial state */ /* WriteEndDocument resets it to initial state */
hr = IXmlWriter_WriteEndDocument(writer); hr = IXmlWriter_WriteEndDocument(writer);
...@@ -714,9 +696,6 @@ static void test_WriteComment(void) ...@@ -714,9 +696,6 @@ static void test_WriteComment(void)
IStream *stream; IStream *stream;
HRESULT hr; HRESULT hr;
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
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);
...@@ -726,8 +705,7 @@ static void test_WriteComment(void) ...@@ -726,8 +705,7 @@ static void test_WriteComment(void)
hr = IXmlWriter_WriteComment(writer, aW); hr = IXmlWriter_WriteComment(writer, aW);
ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr); ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
hr = IXmlWriter_SetOutput(writer, (IUnknown*)stream); stream = writer_set_output(writer);
ok(hr == S_OK, "got 0x%08x\n", hr);
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);
...@@ -766,9 +744,6 @@ static void test_WriteCData(void) ...@@ -766,9 +744,6 @@ static void test_WriteCData(void)
IStream *stream; IStream *stream;
HRESULT hr; HRESULT hr;
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
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);
...@@ -778,8 +753,7 @@ static void test_WriteCData(void) ...@@ -778,8 +753,7 @@ static void test_WriteCData(void)
hr = IXmlWriter_WriteCData(writer, aW); hr = IXmlWriter_WriteCData(writer, aW);
ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr); ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
hr = IXmlWriter_SetOutput(writer, (IUnknown*)stream); stream = writer_set_output(writer);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_WriteStartElement(writer, NULL, bW, NULL); hr = IXmlWriter_WriteStartElement(writer, NULL, bW, NULL);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
...@@ -819,9 +793,6 @@ static void test_WriteRaw(void) ...@@ -819,9 +793,6 @@ static void test_WriteRaw(void)
IStream *stream; IStream *stream;
HRESULT hr; HRESULT hr;
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
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);
...@@ -831,8 +802,7 @@ static void test_WriteRaw(void) ...@@ -831,8 +802,7 @@ static void test_WriteRaw(void)
hr = IXmlWriter_WriteRaw(writer, rawW); hr = IXmlWriter_WriteRaw(writer, rawW);
ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr); ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
hr = IXmlWriter_SetOutput(writer, (IUnknown*)stream); stream = writer_set_output(writer);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_WriteRaw(writer, NULL); hr = IXmlWriter_WriteRaw(writer, NULL);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
......
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