2011-06-22 21:05:01 +02:00
|
|
|
/*
|
|
|
|
* XMLLite IXmlWriter tests
|
|
|
|
*
|
|
|
|
* Copyright 2011 (C) Alistair Leslie-Hughes
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "ole2.h"
|
|
|
|
#include "xmllite.h"
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2014-03-21 06:56:23 +01:00
|
|
|
#include "initguid.h"
|
|
|
|
DEFINE_GUID(IID_IXmlWriterOutput, 0xc1131708, 0x0f59, 0x477f, 0x93, 0x59, 0x7d, 0x33, 0x24, 0x51, 0xbc, 0x1a);
|
|
|
|
|
2016-03-22 08:10:38 +01:00
|
|
|
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__)
|
|
|
|
|
2016-03-23 11:07:26 +01:00
|
|
|
/* used to test all Write* methods for consistent error state */
|
|
|
|
static void check_writer_state(IXmlWriter *writer, HRESULT exp_hr)
|
|
|
|
{
|
|
|
|
static const WCHAR aW[] = {'a',0};
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
/* FIXME: add WriteAttributes */
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteAttributeString(writer, NULL, aW, NULL, aW);
|
|
|
|
ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteCData(writer, aW);
|
|
|
|
ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteCharEntity(writer, aW[0]);
|
|
|
|
ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteChars(writer, aW, 1);
|
|
|
|
ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteComment(writer, aW);
|
|
|
|
ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr);
|
|
|
|
|
|
|
|
/* FIXME: add WriteDocType */
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteElementString(writer, NULL, aW, NULL, aW);
|
|
|
|
ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteEndDocument(writer);
|
|
|
|
ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteEndElement(writer);
|
|
|
|
ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteEntityRef(writer, aW);
|
|
|
|
ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteFullEndElement(writer);
|
|
|
|
ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteName(writer, aW);
|
|
|
|
ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteNmToken(writer, aW);
|
|
|
|
ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr);
|
2016-03-24 08:41:23 +01:00
|
|
|
|
2016-03-23 11:07:26 +01:00
|
|
|
/* FIXME: add WriteNode */
|
|
|
|
/* FIXME: add WriteNodeShallow */
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteProcessingInstruction(writer, aW, aW);
|
|
|
|
ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteQualifiedName(writer, aW, NULL);
|
|
|
|
ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteRaw(writer, aW);
|
|
|
|
ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteRawChars(writer, aW, 1);
|
|
|
|
ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit);
|
|
|
|
ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL);
|
|
|
|
ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteString(writer, aW);
|
|
|
|
ok(hr == exp_hr, "got 0x%08x, expected 0x%08x\n", hr, exp_hr);
|
2016-03-23 11:07:27 +01:00
|
|
|
|
2016-03-23 11:07:26 +01:00
|
|
|
/* FIXME: add WriteSurrogateCharEntity */
|
|
|
|
/* FIXME: add WriteWhitespace */
|
|
|
|
}
|
|
|
|
|
2016-03-22 08:10:39 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-03-21 06:56:23 +01:00
|
|
|
static HRESULT WINAPI testoutput_QueryInterface(IUnknown *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown)) {
|
|
|
|
*obj = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ok(0, "unknown riid=%s\n", wine_dbgstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI testoutput_AddRef(IUnknown *iface)
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI testoutput_Release(IUnknown *iface)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IUnknownVtbl testoutputvtbl = {
|
|
|
|
testoutput_QueryInterface,
|
|
|
|
testoutput_AddRef,
|
|
|
|
testoutput_Release
|
|
|
|
};
|
|
|
|
|
|
|
|
static IUnknown testoutput = { &testoutputvtbl };
|
2011-06-22 21:05:01 +02:00
|
|
|
|
2014-05-16 10:42:52 +02:00
|
|
|
static HRESULT WINAPI teststream_QueryInterface(ISequentialStream *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_ISequentialStream))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI teststream_AddRef(ISequentialStream *iface)
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI teststream_Release(ISequentialStream *iface)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI teststream_Read(ISequentialStream *iface, void *pv, ULONG cb, ULONG *pread)
|
|
|
|
{
|
|
|
|
ok(0, "unexpected call\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG g_write_len;
|
|
|
|
static HRESULT WINAPI teststream_Write(ISequentialStream *iface, const void *pv, ULONG cb, ULONG *written)
|
|
|
|
{
|
|
|
|
g_write_len = cb;
|
|
|
|
*written = cb;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const ISequentialStreamVtbl teststreamvtbl =
|
|
|
|
{
|
|
|
|
teststream_QueryInterface,
|
|
|
|
teststream_AddRef,
|
|
|
|
teststream_Release,
|
|
|
|
teststream_Read,
|
|
|
|
teststream_Write
|
|
|
|
};
|
|
|
|
|
|
|
|
static ISequentialStream teststream = { &teststreamvtbl };
|
|
|
|
|
2011-06-22 21:05:01 +02:00
|
|
|
static void test_writer_create(void)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IXmlWriter *writer;
|
2014-05-14 09:52:13 +02:00
|
|
|
LONG_PTR value;
|
2011-06-22 21:05:01 +02:00
|
|
|
|
|
|
|
/* crashes native */
|
|
|
|
if (0)
|
|
|
|
{
|
2016-03-22 08:10:37 +01:00
|
|
|
CreateXmlWriter(&IID_IXmlWriter, NULL, NULL);
|
|
|
|
CreateXmlWriter(NULL, (void**)&writer, NULL);
|
2011-06-22 21:05:01 +02:00
|
|
|
}
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
|
2011-06-22 21:05:01 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2014-05-14 09:52:13 +02:00
|
|
|
|
|
|
|
/* check default properties values */
|
|
|
|
value = 0;
|
|
|
|
hr = IXmlWriter_GetProperty(writer, XmlWriterProperty_ByteOrderMark, &value);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(value == TRUE, "got %ld\n", value);
|
|
|
|
|
|
|
|
value = TRUE;
|
|
|
|
hr = IXmlWriter_GetProperty(writer, XmlWriterProperty_Indent, &value);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(value == FALSE, "got %ld\n", value);
|
|
|
|
|
|
|
|
value = TRUE;
|
|
|
|
hr = IXmlWriter_GetProperty(writer, XmlWriterProperty_OmitXmlDeclaration, &value);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(value == FALSE, "got %ld\n", value);
|
|
|
|
|
|
|
|
value = XmlConformanceLevel_Auto;
|
|
|
|
hr = IXmlWriter_GetProperty(writer, XmlWriterProperty_ConformanceLevel, &value);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(value == XmlConformanceLevel_Document, "got %ld\n", value);
|
|
|
|
|
2014-03-21 06:56:23 +01:00
|
|
|
IXmlWriter_Release(writer);
|
2011-06-22 21:05:01 +02:00
|
|
|
}
|
|
|
|
|
2014-03-21 06:56:23 +01:00
|
|
|
static void test_writeroutput(void)
|
|
|
|
{
|
|
|
|
static const WCHAR utf16W[] = {'u','t','f','-','1','6',0};
|
|
|
|
IXmlWriterOutput *output;
|
|
|
|
IUnknown *unk;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2014-05-15 16:49:37 +02:00
|
|
|
output = NULL;
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlWriterOutputWithEncodingName(&testoutput, NULL, NULL, &output);
|
2014-05-15 16:49:37 +02:00
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
IUnknown_Release(output);
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlWriterOutputWithEncodingName(&testoutput, NULL, utf16W, &output);
|
2014-03-21 06:56:23 +01:00
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
unk = NULL;
|
|
|
|
hr = IUnknown_QueryInterface(output, &IID_IXmlWriterOutput, (void**)&unk);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(unk != NULL, "got %p\n", unk);
|
2015-08-05 17:13:57 +02:00
|
|
|
/* releasing 'unk' crashes on native */
|
|
|
|
IUnknown_Release(output);
|
|
|
|
|
|
|
|
output = NULL;
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlWriterOutputWithEncodingCodePage(&testoutput, NULL, ~0u, &output);
|
2015-08-05 17:13:57 +02:00
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
IUnknown_Release(output);
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlWriterOutputWithEncodingCodePage(&testoutput, NULL, CP_UTF8, &output);
|
2015-08-05 17:13:57 +02:00
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
unk = NULL;
|
|
|
|
hr = IUnknown_QueryInterface(output, &IID_IXmlWriterOutput, (void**)&unk);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(unk != NULL, "got %p\n", unk);
|
2014-03-21 06:56:23 +01:00
|
|
|
/* releasing 'unk' crashes on native */
|
|
|
|
IUnknown_Release(output);
|
|
|
|
}
|
|
|
|
|
2014-05-15 16:47:26 +02:00
|
|
|
static void test_writestartdocument(void)
|
|
|
|
{
|
|
|
|
static const char fullprolog[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
|
|
|
|
static const char prologversion[] = "<?xml version=\"1.0\"?>";
|
|
|
|
static const WCHAR versionW[] = {'v','e','r','s','i','o','n','=','"','1','.','0','"',0};
|
|
|
|
static const WCHAR xmlW[] = {'x','m','l',0};
|
|
|
|
IXmlWriter *writer;
|
|
|
|
IStream *stream;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
|
2014-05-15 16:47:26 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
/* output not set */
|
|
|
|
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
|
|
|
|
ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
|
2014-05-15 16:49:37 +02:00
|
|
|
|
|
|
|
hr = IXmlWriter_WriteProcessingInstruction(writer, xmlW, versionW);
|
|
|
|
ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
|
2014-05-15 16:47:26 +02:00
|
|
|
|
2014-05-15 16:50:31 +02:00
|
|
|
hr = IXmlWriter_Flush(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:39 +01:00
|
|
|
stream = writer_set_output(writer);
|
2014-05-15 16:47:26 +02:00
|
|
|
|
2014-05-15 16:50:31 +02:00
|
|
|
/* nothing written yet */
|
|
|
|
hr = IXmlWriter_Flush(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2014-05-15 16:47:26 +02:00
|
|
|
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_Flush(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:38 +01:00
|
|
|
CHECK_OUTPUT(stream, fullprolog);
|
2014-05-15 16:47:26 +02:00
|
|
|
|
|
|
|
/* one more time */
|
|
|
|
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
IStream_Release(stream);
|
|
|
|
|
|
|
|
/* now add PI manually, and try to start a document */
|
2016-03-22 08:10:39 +01:00
|
|
|
stream = writer_set_output(writer);
|
2014-05-15 16:47:26 +02:00
|
|
|
|
|
|
|
hr = IXmlWriter_WriteProcessingInstruction(writer, xmlW, versionW);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
/* another attempt to add 'xml' PI */
|
|
|
|
hr = IXmlWriter_WriteProcessingInstruction(writer, xmlW, versionW);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_Flush(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:38 +01:00
|
|
|
CHECK_OUTPUT(stream, prologversion);
|
2014-05-15 16:47:26 +02:00
|
|
|
|
|
|
|
IStream_Release(stream);
|
|
|
|
IXmlWriter_Release(writer);
|
|
|
|
}
|
|
|
|
|
2014-05-16 10:42:52 +02:00
|
|
|
static void test_flush(void)
|
|
|
|
{
|
|
|
|
IXmlWriter *writer;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
|
2014-05-16 10:42:52 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_SetOutput(writer, (IUnknown*)&teststream);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
g_write_len = 0;
|
|
|
|
hr = IXmlWriter_Flush(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ok(g_write_len > 0, "got %d\n", g_write_len);
|
|
|
|
|
|
|
|
g_write_len = 1;
|
|
|
|
hr = IXmlWriter_Flush(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ok(g_write_len == 0, "got %d\n", g_write_len);
|
|
|
|
|
|
|
|
/* Release() flushes too */
|
|
|
|
g_write_len = 1;
|
|
|
|
IXmlWriter_Release(writer);
|
|
|
|
ok(g_write_len == 0, "got %d\n", g_write_len);
|
|
|
|
}
|
|
|
|
|
2014-05-19 22:27:16 +02:00
|
|
|
static void test_omitxmldeclaration(void)
|
|
|
|
{
|
|
|
|
static const char prologversion[] = "<?xml version=\"1.0\"?>";
|
|
|
|
static const WCHAR versionW[] = {'v','e','r','s','i','o','n','=','"','1','.','0','"',0};
|
|
|
|
static const WCHAR xmlW[] = {'x','m','l',0};
|
|
|
|
IXmlWriter *writer;
|
|
|
|
HGLOBAL hglobal;
|
|
|
|
IStream *stream;
|
|
|
|
HRESULT hr;
|
|
|
|
char *ptr;
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
|
2014-05-19 22:27:16 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:39 +01:00
|
|
|
stream = writer_set_output(writer);
|
2014-05-19 22:27:16 +02:00
|
|
|
|
|
|
|
hr = IXmlWriter_SetProperty(writer, XmlWriterProperty_OmitXmlDeclaration, TRUE);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_Flush(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = GetHGlobalFromStream(stream, &hglobal);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
ptr = GlobalLock(hglobal);
|
|
|
|
ok(!ptr, "got %p\n", ptr);
|
|
|
|
GlobalUnlock(hglobal);
|
|
|
|
|
|
|
|
/* one more time */
|
|
|
|
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
IStream_Release(stream);
|
|
|
|
|
|
|
|
/* now add PI manually, and try to start a document */
|
2016-03-22 08:10:39 +01:00
|
|
|
stream = writer_set_output(writer);
|
2014-05-19 22:27:16 +02:00
|
|
|
|
|
|
|
hr = IXmlWriter_WriteProcessingInstruction(writer, xmlW, versionW);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_Flush(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:38 +01:00
|
|
|
CHECK_OUTPUT(stream, prologversion);
|
2014-05-19 22:27:16 +02:00
|
|
|
|
|
|
|
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_Flush(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:38 +01:00
|
|
|
CHECK_OUTPUT(stream, prologversion);
|
2014-05-19 22:27:16 +02:00
|
|
|
|
|
|
|
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_Flush(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:38 +01:00
|
|
|
CHECK_OUTPUT(stream, prologversion);
|
2014-05-19 22:27:16 +02:00
|
|
|
|
|
|
|
/* another attempt to add 'xml' PI */
|
|
|
|
hr = IXmlWriter_WriteProcessingInstruction(writer, xmlW, versionW);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_Flush(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
IStream_Release(stream);
|
|
|
|
IXmlWriter_Release(writer);
|
|
|
|
}
|
|
|
|
|
2014-05-19 23:37:14 +02:00
|
|
|
static void test_bom(void)
|
|
|
|
{
|
|
|
|
static const WCHAR versionW[] = {'v','e','r','s','i','o','n','=','"','1','.','0','"',0};
|
|
|
|
static const WCHAR utf16W[] = {'u','t','f','-','1','6',0};
|
|
|
|
static const WCHAR xmlW[] = {'x','m','l',0};
|
2014-05-20 22:24:49 +02:00
|
|
|
static const WCHAR aW[] = {'a',0};
|
2014-05-19 23:37:14 +02:00
|
|
|
IXmlWriterOutput *output;
|
|
|
|
unsigned char *ptr;
|
|
|
|
IXmlWriter *writer;
|
|
|
|
IStream *stream;
|
|
|
|
HGLOBAL hglobal;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlWriterOutputWithEncodingName((IUnknown*)stream, NULL, utf16W, &output);
|
2014-05-19 23:37:14 +02:00
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
|
2014-05-19 23:37:14 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_SetProperty(writer, XmlWriterProperty_OmitXmlDeclaration, TRUE);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_SetOutput(writer, output);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
/* BOM is on by default */
|
|
|
|
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_Flush(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = GetHGlobalFromStream(stream, &hglobal);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
ptr = GlobalLock(hglobal);
|
|
|
|
ok(ptr[0] == 0xff && ptr[1] == 0xfe, "got %x,%x\n", ptr[0], ptr[1]);
|
|
|
|
GlobalUnlock(hglobal);
|
|
|
|
|
|
|
|
IStream_Release(stream);
|
|
|
|
IUnknown_Release(output);
|
|
|
|
|
|
|
|
/* start with PI */
|
|
|
|
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlWriterOutputWithEncodingName((IUnknown*)stream, NULL, utf16W, &output);
|
2014-05-19 23:37:14 +02:00
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_SetOutput(writer, output);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteProcessingInstruction(writer, xmlW, versionW);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_Flush(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = GetHGlobalFromStream(stream, &hglobal);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
ptr = GlobalLock(hglobal);
|
|
|
|
ok(ptr[0] == 0xff && ptr[1] == 0xfe, "got %x,%x\n", ptr[0], ptr[1]);
|
|
|
|
GlobalUnlock(hglobal);
|
|
|
|
|
|
|
|
IUnknown_Release(output);
|
2014-05-20 22:24:49 +02:00
|
|
|
IStream_Release(stream);
|
|
|
|
|
|
|
|
/* start with element */
|
|
|
|
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlWriterOutputWithEncodingName((IUnknown*)stream, NULL, utf16W, &output);
|
2014-05-20 22:24:49 +02:00
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_SetOutput(writer, output);
|
|
|
|
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_Flush(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = GetHGlobalFromStream(stream, &hglobal);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
ptr = GlobalLock(hglobal);
|
|
|
|
ok(ptr[0] == 0xff && ptr[1] == 0xfe, "got %x,%x\n", ptr[0], ptr[1]);
|
|
|
|
GlobalUnlock(hglobal);
|
|
|
|
|
|
|
|
IUnknown_Release(output);
|
|
|
|
IStream_Release(stream);
|
|
|
|
|
2014-05-21 06:59:36 +02:00
|
|
|
/* WriteElementString */
|
|
|
|
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlWriterOutputWithEncodingName((IUnknown*)stream, NULL, utf16W, &output);
|
2014-05-21 06:59:36 +02:00
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_SetOutput(writer, output);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteElementString(writer, NULL, aW, NULL, NULL);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_Flush(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = GetHGlobalFromStream(stream, &hglobal);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
ptr = GlobalLock(hglobal);
|
|
|
|
ok(ptr[0] == 0xff && ptr[1] == 0xfe, "got %x,%x\n", ptr[0], ptr[1]);
|
|
|
|
GlobalUnlock(hglobal);
|
|
|
|
|
|
|
|
IUnknown_Release(output);
|
|
|
|
IStream_Release(stream);
|
|
|
|
|
2014-05-19 23:37:14 +02:00
|
|
|
IXmlWriter_Release(writer);
|
2014-05-20 22:24:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_writestartelement(void)
|
|
|
|
{
|
2014-05-21 06:59:36 +02:00
|
|
|
static const WCHAR valueW[] = {'v','a','l','u','e',0};
|
|
|
|
static const char *str = "<a><b>value</b>";
|
2014-05-20 22:24:49 +02:00
|
|
|
static const WCHAR aW[] = {'a',0};
|
2014-05-21 06:59:36 +02:00
|
|
|
static const WCHAR bW[] = {'b',0};
|
2014-05-20 22:24:49 +02:00
|
|
|
IXmlWriter *writer;
|
|
|
|
IStream *stream;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
|
2014-05-20 22:24:49 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL);
|
|
|
|
ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:39 +01:00
|
|
|
stream = writer_set_output(writer);
|
2014-05-20 22:24:49 +02:00
|
|
|
|
|
|
|
hr = IXmlWriter_WriteStartElement(writer, aW, NULL, NULL);
|
|
|
|
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteStartElement(writer, NULL, NULL, NULL);
|
|
|
|
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteStartElement(writer, NULL, NULL, aW);
|
|
|
|
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_Flush(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:38 +01:00
|
|
|
CHECK_OUTPUT(stream, "<a");
|
2014-05-20 22:24:49 +02:00
|
|
|
|
|
|
|
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteStartElement(writer, NULL, NULL, NULL);
|
|
|
|
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteProcessingInstruction(writer, aW, aW);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
2014-05-19 23:37:14 +02:00
|
|
|
IStream_Release(stream);
|
2014-05-20 22:24:49 +02:00
|
|
|
IXmlWriter_Release(writer);
|
2014-05-21 06:59:36 +02:00
|
|
|
|
|
|
|
/* WriteElementString */
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
|
2014-05-21 06:59:36 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteElementString(writer, NULL, bW, NULL, valueW);
|
|
|
|
ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:39 +01:00
|
|
|
stream = writer_set_output(writer);
|
2014-05-21 06:59:36 +02:00
|
|
|
|
|
|
|
hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteElementString(writer, NULL, bW, NULL, valueW);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_Flush(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:38 +01:00
|
|
|
CHECK_OUTPUT(stream, str);
|
2014-05-21 06:59:36 +02:00
|
|
|
|
|
|
|
IStream_Release(stream);
|
|
|
|
IXmlWriter_Release(writer);
|
2014-05-19 23:37:14 +02:00
|
|
|
}
|
|
|
|
|
2014-06-14 20:46:09 +02:00
|
|
|
static void test_writeendelement(void)
|
|
|
|
{
|
|
|
|
static const WCHAR aW[] = {'a',0};
|
|
|
|
static const WCHAR bW[] = {'b',0};
|
|
|
|
IXmlWriter *writer;
|
|
|
|
IStream *stream;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
|
2014-06-14 20:46:09 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:39 +01:00
|
|
|
stream = writer_set_output(writer);
|
2014-06-14 20:46:09 +02:00
|
|
|
|
|
|
|
hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL);
|
|
|
|
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_WriteEndElement(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteEndElement(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_Flush(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:38 +01:00
|
|
|
CHECK_OUTPUT(stream, "<a><b /></a>");
|
2014-06-14 20:46:09 +02:00
|
|
|
|
|
|
|
IXmlWriter_Release(writer);
|
|
|
|
IStream_Release(stream);
|
|
|
|
}
|
|
|
|
|
2015-05-19 20:59:59 +02:00
|
|
|
static void test_writeenddocument(void)
|
|
|
|
{
|
|
|
|
static const WCHAR aW[] = {'a',0};
|
|
|
|
static const WCHAR bW[] = {'b',0};
|
|
|
|
IXmlWriter *writer;
|
|
|
|
IStream *stream;
|
|
|
|
HGLOBAL hglobal;
|
|
|
|
HRESULT hr;
|
|
|
|
char *ptr;
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
|
2015-05-19 20:59:59 +02:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteEndDocument(writer);
|
|
|
|
ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:39 +01:00
|
|
|
stream = writer_set_output(writer);
|
2015-05-19 20:59:59 +02:00
|
|
|
|
|
|
|
/* WriteEndDocument resets it to initial state */
|
|
|
|
hr = IXmlWriter_WriteEndDocument(writer);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteEndDocument(writer);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_SetOutput(writer, (IUnknown*)stream);
|
|
|
|
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, 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 = GetHGlobalFromStream(stream, &hglobal);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
ptr = GlobalLock(hglobal);
|
|
|
|
ok(ptr == NULL, "got %p\n", ptr);
|
|
|
|
|
|
|
|
/* we still need to flush manually, WriteEndDocument doesn't do that */
|
|
|
|
hr = IXmlWriter_Flush(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:38 +01:00
|
|
|
CHECK_OUTPUT(stream, "<a><b /></a>");
|
2015-05-19 20:59:59 +02:00
|
|
|
|
|
|
|
IXmlWriter_Release(writer);
|
|
|
|
IStream_Release(stream);
|
|
|
|
}
|
|
|
|
|
2016-03-14 21:27:17 +01:00
|
|
|
static void test_WriteComment(void)
|
|
|
|
{
|
|
|
|
static const WCHAR closeW[] = {'-','-','>',0};
|
|
|
|
static const WCHAR aW[] = {'a',0};
|
|
|
|
static const WCHAR bW[] = {'b',0};
|
|
|
|
IXmlWriter *writer;
|
|
|
|
IStream *stream;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
|
2016-03-14 21:27:17 +01:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_SetProperty(writer, XmlWriterProperty_OmitXmlDeclaration, TRUE);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteComment(writer, aW);
|
|
|
|
ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:39 +01:00
|
|
|
stream = writer_set_output(writer);
|
2016-03-14 21:27:17 +01:00
|
|
|
|
|
|
|
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteComment(writer, aW);
|
|
|
|
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_WriteComment(writer, aW);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteComment(writer, NULL);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteComment(writer, closeW);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_Flush(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:38 +01:00
|
|
|
CHECK_OUTPUT(stream, "<!--a--><b><!--a--><!----><!--- ->-->");
|
2016-03-14 21:27:17 +01:00
|
|
|
|
|
|
|
IXmlWriter_Release(writer);
|
|
|
|
IStream_Release(stream);
|
|
|
|
}
|
|
|
|
|
2016-03-15 17:54:46 +01:00
|
|
|
static void test_WriteCData(void)
|
|
|
|
{
|
|
|
|
static const WCHAR closeW[] = {']',']','>',0};
|
|
|
|
static const WCHAR close2W[] = {'a',']',']','>','b',0};
|
|
|
|
static const WCHAR aW[] = {'a',0};
|
|
|
|
static const WCHAR bW[] = {'b',0};
|
|
|
|
IXmlWriter *writer;
|
|
|
|
IStream *stream;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
|
2016-03-15 17:54:46 +01:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_SetProperty(writer, XmlWriterProperty_OmitXmlDeclaration, TRUE);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteCData(writer, aW);
|
|
|
|
ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:39 +01:00
|
|
|
stream = writer_set_output(writer);
|
2016-03-15 17:54:46 +01:00
|
|
|
|
|
|
|
hr = IXmlWriter_WriteStartElement(writer, NULL, bW, NULL);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteCData(writer, aW);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteCData(writer, NULL);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteCData(writer, closeW);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteCData(writer, close2W);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_Flush(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:38 +01:00
|
|
|
CHECK_OUTPUT(stream,
|
2016-03-15 17:54:46 +01:00
|
|
|
"<b>"
|
|
|
|
"<![CDATA[a]]>"
|
|
|
|
"<![CDATA[]]>"
|
|
|
|
"<![CDATA[]]]]>"
|
|
|
|
"<![CDATA[>]]>"
|
|
|
|
"<![CDATA[a]]]]>"
|
2016-03-22 08:10:38 +01:00
|
|
|
"<![CDATA[>b]]>");
|
2016-03-15 17:54:46 +01:00
|
|
|
|
|
|
|
IXmlWriter_Release(writer);
|
|
|
|
IStream_Release(stream);
|
|
|
|
}
|
|
|
|
|
2016-03-22 08:10:36 +01:00
|
|
|
static void test_WriteRaw(void)
|
|
|
|
{
|
|
|
|
static const WCHAR rawW[] = {'a','<',':',0};
|
2016-03-24 08:41:26 +01:00
|
|
|
static const WCHAR aW[] = {'a',0};
|
2016-03-22 08:10:36 +01:00
|
|
|
IXmlWriter *writer;
|
|
|
|
IStream *stream;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
|
2016-03-22 08:10:36 +01:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteRaw(writer, NULL);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteRaw(writer, rawW);
|
|
|
|
ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:39 +01:00
|
|
|
stream = writer_set_output(writer);
|
2016-03-22 08:10:36 +01:00
|
|
|
|
|
|
|
hr = IXmlWriter_WriteRaw(writer, NULL);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteRaw(writer, rawW);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-24 08:41:26 +01:00
|
|
|
hr = IXmlWriter_WriteRaw(writer, rawW);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteComment(writer, rawW);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteRaw(writer, rawW);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteElementString(writer, NULL, aW, NULL, aW);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-22 08:10:36 +01:00
|
|
|
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteComment(writer, rawW);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteEndDocument(writer);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteRaw(writer, rawW);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlWriter_Flush(writer);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2016-03-24 08:41:26 +01:00
|
|
|
CHECK_OUTPUT(stream, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>a<:a<:<!--a<:-->a<:<a>a</a>");
|
2016-03-22 08:10:36 +01:00
|
|
|
|
|
|
|
IXmlWriter_Release(writer);
|
|
|
|
IStream_Release(stream);
|
|
|
|
}
|
|
|
|
|
2016-03-23 11:07:26 +01:00
|
|
|
static void test_writer_state(void)
|
|
|
|
{
|
2016-03-24 08:41:24 +01:00
|
|
|
static const WCHAR aW[] = {'a',0};
|
2016-03-23 11:07:26 +01:00
|
|
|
IXmlWriter *writer;
|
2016-03-23 11:07:29 +01:00
|
|
|
IStream *stream;
|
2016-03-23 11:07:26 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
2016-03-23 11:07:29 +01:00
|
|
|
/* initial state */
|
2016-03-23 11:07:26 +01:00
|
|
|
check_writer_state(writer, E_UNEXPECTED);
|
|
|
|
|
2016-03-24 08:41:25 +01:00
|
|
|
/* set output and call 'wrong' method, WriteEndElement */
|
2016-03-23 11:07:29 +01:00
|
|
|
stream = writer_set_output(writer);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteEndElement(writer);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
check_writer_state(writer, WR_E_INVALIDACTION);
|
|
|
|
IStream_Release(stream);
|
|
|
|
|
2016-03-24 08:41:25 +01:00
|
|
|
/* WriteAttributeString */
|
2016-03-24 08:41:24 +01:00
|
|
|
stream = writer_set_output(writer);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteAttributeString(writer, NULL, aW, NULL, aW);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
check_writer_state(writer, WR_E_INVALIDACTION);
|
2016-03-24 08:41:25 +01:00
|
|
|
IStream_Release(stream);
|
|
|
|
|
|
|
|
/* WriteEndDocument */
|
|
|
|
stream = writer_set_output(writer);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteEndDocument(writer);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
check_writer_state(writer, WR_E_INVALIDACTION);
|
|
|
|
IStream_Release(stream);
|
|
|
|
|
|
|
|
/* WriteFullEndElement */
|
|
|
|
stream = writer_set_output(writer);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteFullEndElement(writer);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
check_writer_state(writer, WR_E_INVALIDACTION);
|
|
|
|
IStream_Release(stream);
|
|
|
|
|
|
|
|
/* WriteCData */
|
|
|
|
stream = writer_set_output(writer);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteCData(writer, aW);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
check_writer_state(writer, WR_E_INVALIDACTION);
|
|
|
|
IStream_Release(stream);
|
|
|
|
|
|
|
|
/* WriteName */
|
|
|
|
stream = writer_set_output(writer);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteName(writer, aW);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
check_writer_state(writer, WR_E_INVALIDACTION);
|
|
|
|
IStream_Release(stream);
|
|
|
|
|
|
|
|
/* WriteNmToken */
|
|
|
|
stream = writer_set_output(writer);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteNmToken(writer, aW);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
check_writer_state(writer, WR_E_INVALIDACTION);
|
|
|
|
IStream_Release(stream);
|
2016-03-24 08:41:24 +01:00
|
|
|
|
2016-03-24 08:41:25 +01:00
|
|
|
/* WriteString */
|
|
|
|
stream = writer_set_output(writer);
|
|
|
|
|
|
|
|
hr = IXmlWriter_WriteString(writer, aW);
|
|
|
|
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
check_writer_state(writer, WR_E_INVALIDACTION);
|
2016-03-24 08:41:24 +01:00
|
|
|
IStream_Release(stream);
|
|
|
|
|
2016-03-23 11:07:26 +01:00
|
|
|
IXmlWriter_Release(writer);
|
|
|
|
}
|
|
|
|
|
2011-06-22 21:05:01 +02:00
|
|
|
START_TEST(writer)
|
|
|
|
{
|
|
|
|
test_writer_create();
|
2016-03-23 11:07:26 +01:00
|
|
|
test_writer_state();
|
2014-03-21 06:56:23 +01:00
|
|
|
test_writeroutput();
|
2014-05-15 16:47:26 +02:00
|
|
|
test_writestartdocument();
|
2014-05-20 22:24:49 +02:00
|
|
|
test_writestartelement();
|
2014-06-14 20:46:09 +02:00
|
|
|
test_writeendelement();
|
2014-05-16 10:42:52 +02:00
|
|
|
test_flush();
|
2014-05-19 22:27:16 +02:00
|
|
|
test_omitxmldeclaration();
|
2014-05-19 23:37:14 +02:00
|
|
|
test_bom();
|
2015-05-19 20:59:59 +02:00
|
|
|
test_writeenddocument();
|
2016-03-14 21:27:17 +01:00
|
|
|
test_WriteComment();
|
2016-03-15 17:54:46 +01:00
|
|
|
test_WriteCData();
|
2016-03-22 08:10:36 +01:00
|
|
|
test_WriteRaw();
|
2011-06-22 21:05:01 +02:00
|
|
|
}
|