DEFINE_GUID(IID_IXmlReaderInput, 0x0b3ccc9b, 0x9214, 0x428b, 0xa2, 0xae, 0xef, 0x3a, 0xa8, 0x71, 0xaf, 0xda);
-static HRESULT (WINAPI *pCreateXmlReader)(REFIID riid, void **ppvObject, IMalloc *pMalloc);
-static HRESULT (WINAPI *pCreateXmlReaderInputWithEncodingName)(IUnknown *stream,
- IMalloc *pMalloc,
- LPCWSTR encoding,
- BOOL hint,
- LPCWSTR base_uri,
- IXmlReaderInput **ppInput);
-
static WCHAR *a2w(const char *str)
{
int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
teststream_Write
};
-static BOOL init_pointers(void)
+static HRESULT WINAPI resolver_QI(IXmlResolver *iface, REFIID riid, void **obj)
{
- /* don't free module here, it's to be unloaded on exit */
- HMODULE mod = LoadLibraryA("xmllite.dll");
+ ok(0, "unexpected call, riid %s\n", wine_dbgstr_guid(riid));
- if (!mod)
+ if (IsEqualIID(riid, &IID_IXmlResolver) || IsEqualIID(riid, &IID_IUnknown))
{
- win_skip("xmllite library not available\n");
- return FALSE;
+ *obj = iface;
+ IXmlResolver_AddRef(iface);
+ return S_OK;
}
-#define MAKEFUNC(f) if (!(p##f = (void*)GetProcAddress(mod, #f))) return FALSE;
- MAKEFUNC(CreateXmlReader);
- MAKEFUNC(CreateXmlReaderInputWithEncodingName);
-#undef MAKEFUNC
+ *obj = NULL;
+ return E_NOINTERFACE;
+}
+
+static ULONG WINAPI resolver_AddRef(IXmlResolver *iface)
+{
+ return 2;
+}
+
+static ULONG WINAPI resolver_Release(IXmlResolver *iface)
+{
+ return 1;
+}
- return TRUE;
+static HRESULT WINAPI resolver_ResolveUri(IXmlResolver *iface, const WCHAR *base_uri,
+ const WCHAR *public_id, const WCHAR *system_id, IUnknown **input)
+{
+ ok(0, "unexpected call\n");
+ return E_NOTIMPL;
}
+static const IXmlResolverVtbl resolvervtbl =
+{
+ resolver_QI,
+ resolver_AddRef,
+ resolver_Release,
+ resolver_ResolveUri
+};
+
+static IXmlResolver testresolver = { &resolvervtbl };
+
static void test_reader_create(void)
{
+ IXmlResolver *resolver;
HRESULT hr;
IXmlReader *reader;
IUnknown *input;
/* crashes native */
if (0)
{
- pCreateXmlReader(&IID_IXmlReader, NULL, NULL);
- pCreateXmlReader(NULL, (void**)&reader, NULL);
+ CreateXmlReader(&IID_IXmlReader, NULL, NULL);
+ CreateXmlReader(NULL, (void**)&reader, NULL);
}
- hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
+ hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
test_read_state(reader, XmlReadState_Closed, -1, FALSE);
ok(hr == S_FALSE, "got %08x\n", hr);
ok(nodetype == XmlNodeType_None, "got %d\n", nodetype);
+ resolver = (void*)0xdeadbeef;
+ hr = IXmlReader_GetProperty(reader, XmlReaderProperty_XmlResolver, (LONG_PTR*)&resolver);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ ok(resolver == NULL, "got %p\n", resolver);
+
+ hr = IXmlReader_SetProperty(reader, XmlReaderProperty_XmlResolver, 0);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+
+ hr = IXmlReader_SetProperty(reader, XmlReaderProperty_XmlResolver, (LONG_PTR)&testresolver);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+
+ resolver = NULL;
+ hr = IXmlReader_GetProperty(reader, XmlReaderProperty_XmlResolver, (LONG_PTR*)&resolver);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ ok(resolver == &testresolver, "got %p\n", resolver);
+ IXmlResolver_Release(resolver);
+
+ hr = IXmlReader_SetProperty(reader, XmlReaderProperty_XmlResolver, 0);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+
dtd = 2;
hr = IXmlReader_GetProperty(reader, XmlReaderProperty_DtdProcessing, (LONG_PTR*)&dtd);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
HRESULT hr;
LONG ref;
- hr = pCreateXmlReaderInputWithEncodingName(NULL, NULL, NULL, FALSE, NULL, NULL);
+ hr = CreateXmlReaderInputWithEncodingName(NULL, NULL, NULL, FALSE, NULL, NULL);
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
- hr = pCreateXmlReaderInputWithEncodingName(NULL, NULL, NULL, FALSE, NULL, &reader_input);
+ hr = CreateXmlReaderInputWithEncodingName(NULL, NULL, NULL, FALSE, NULL, &reader_input);
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
ref = IStream_AddRef(stream);
ok(ref == 2, "Expected 2, got %d\n", ref);
IStream_Release(stream);
- hr = pCreateXmlReaderInputWithEncodingName((IUnknown*)stream, NULL, NULL, FALSE, NULL, &reader_input);
+ hr = CreateXmlReaderInputWithEncodingName((IUnknown*)stream, NULL, NULL, FALSE, NULL, &reader_input);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
hr = IUnknown_QueryInterface(reader_input, &IID_IStream, (void**)&stream2);
IStream_Release(stream);
/* try ::SetInput() with valid IXmlReaderInput */
- hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
+ hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ref = IUnknown_AddRef(reader_input);
ref = IUnknown_AddRef(input);
ok(ref == 2, "Expected 2, got %d\n", ref);
IUnknown_Release(input);
- hr = pCreateXmlReaderInputWithEncodingName(input, NULL, NULL, FALSE, NULL, &reader_input);
+ hr = CreateXmlReaderInputWithEncodingName(input, NULL, NULL, FALSE, NULL, &reader_input);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok_iids(&input_iids, empty_seq, NULL, FALSE);
/* IXmlReaderInput stores stream interface as IUnknown */
ok(ref == 3, "Expected 3, got %d\n", ref);
IUnknown_Release(input);
- hr = pCreateXmlReader(&IID_IXmlReader, (LPVOID*)&reader, NULL);
+ hr = CreateXmlReader(&IID_IXmlReader, (LPVOID*)&reader, NULL);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
input_iids.count = 0;
ok_iids(&input_iids, setinput_readerinput, NULL, FALSE);
/* another reader */
- hr = pCreateXmlReader(&IID_IXmlReader, (LPVOID*)&reader2, NULL);
+ hr = CreateXmlReader(&IID_IXmlReader, (LPVOID*)&reader2, NULL);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
/* resolving from IXmlReaderInput to IStream/ISequentialStream is done at
XmlNodeType nodetype;
HRESULT hr;
- hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
+ hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
/* invalid arguments */
BOOL ret;
const WCHAR *val;
- hr = pCreateXmlReader(&IID_IXmlReader, (LPVOID*)&reader, NULL);
+ hr = CreateXmlReader(&IID_IXmlReader, (LPVOID*)&reader, NULL);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
/* position methods with Null args */
IXmlReader *reader;
HRESULT hr;
- hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
+ hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
ok(hr == S_OK, "S_OK, got %08x\n", hr);
while (test->xml)
IXmlReader *reader;
HRESULT hr;
- hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
+ hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
ok(hr == S_OK, "S_OK, got %08x\n", hr);
while (test->xml)
HRESULT hr;
int i;
- hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
+ hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
ok(hr == S_OK, "S_OK, got %08x\n", hr);
stream = create_stream_on_data(test->xml, strlen(test->xml)+1);
UINT len, count;
HRESULT hr;
- hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
+ hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
ok(hr == S_OK, "S_OK, got %08x\n", hr);
hr = IXmlReader_SetProperty(reader, XmlReaderProperty_DtdProcessing, DtdProcessing_Parse);
UINT depth;
HRESULT hr;
- hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
+ hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
ok(hr == S_OK, "S_OK, got %08x\n", hr);
while (test->xml)
HRESULT hr;
int c;
- hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
+ hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
ok(hr == S_OK, "S_OK, got 0x%08x\n", hr);
hr = IXmlReader_SetInput(reader, (IUnknown*)&teststream);
HRESULT hr;
UINT c;
- hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
+ hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
ok(hr == S_OK, "S_OK, got %08x\n", hr);
stream = create_stream_on_data(testA, sizeof(testA));
IXmlReader *reader;
HRESULT hr;
- hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
+ hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
ok(hr == S_OK, "S_OK, got %08x\n", hr);
while (test->xml)
IXmlReader *reader;
HRESULT hr;
- hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
+ hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
ok(hr == S_OK, "S_OK, got %08x\n", hr);
while (test->xml)
IXmlReader *reader;
HRESULT hr;
- hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
+ hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
ok(hr == S_OK, "S_OK, got %08x\n", hr);
while (test->xml)
IXmlReader *reader;
HRESULT hr;
- hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
+ hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
ok(hr == S_OK, "S_OK, got %08x\n", hr);
while (test->xml)
START_TEST(reader)
{
- if (!init_pointers())
- return;
-
test_reader_create();
test_readerinput();
test_reader_state();
#include <initguid.h>
DEFINE_GUID(IID_IXmlWriterOutput, 0xc1131708, 0x0f59, 0x477f, 0x93, 0x59, 0x7d, 0x33, 0x24, 0x51, 0xbc, 0x1a);
-static HRESULT (WINAPI *pCreateXmlWriter)(REFIID riid, void **ppvObject, IMalloc *pMalloc);
-static HRESULT (WINAPI *pCreateXmlWriterOutputWithEncodingName)(IUnknown *stream,
- IMalloc *imalloc,
- LPCWSTR encoding_name,
- IXmlWriterOutput **output);
-static HRESULT (WINAPI *pCreateXmlWriterOutputWithEncodingCodePage)(IUnknown *stream,
- IMalloc *imalloc,
- UINT codepage,
- IXmlWriterOutput **output);
+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__)
+
+/* 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);
+
+ /* 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);
+
+ /* FIXME: add WriteSurrogateCharEntity */
+ /* FIXME: add WriteWhitespace */
+}
+
+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)
{
/* crashes native */
if (0)
{
- pCreateXmlWriter(&IID_IXmlWriter, NULL, NULL);
- pCreateXmlWriter(NULL, (void**)&writer, NULL);
+ CreateXmlWriter(&IID_IXmlWriter, NULL, NULL);
+ CreateXmlWriter(NULL, (void**)&writer, NULL);
}
- hr = pCreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
+ hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
/* check default properties values */
IXmlWriter_Release(writer);
}
-static BOOL init_pointers(void)
-{
- /* don't free module here, it's to be unloaded on exit */
- HMODULE mod = LoadLibraryA("xmllite.dll");
-
- if (!mod)
- {
- win_skip("xmllite library not available\n");
- return FALSE;
- }
-
-#define MAKEFUNC(f) if (!(p##f = (void*)GetProcAddress(mod, #f))) return FALSE;
- MAKEFUNC(CreateXmlWriter);
- MAKEFUNC(CreateXmlWriterOutputWithEncodingName);
- MAKEFUNC(CreateXmlWriterOutputWithEncodingCodePage);
-#undef MAKEFUNC
-
- return TRUE;
-}
-
static void test_writeroutput(void)
{
static const WCHAR utf16W[] = {'u','t','f','-','1','6',0};
HRESULT hr;
output = NULL;
- hr = pCreateXmlWriterOutputWithEncodingName(&testoutput, NULL, NULL, &output);
+ hr = CreateXmlWriterOutputWithEncodingName(&testoutput, NULL, NULL, &output);
ok(hr == S_OK, "got %08x\n", hr);
IUnknown_Release(output);
- hr = pCreateXmlWriterOutputWithEncodingName(&testoutput, NULL, utf16W, &output);
+ hr = CreateXmlWriterOutputWithEncodingName(&testoutput, NULL, utf16W, &output);
ok(hr == S_OK, "got %08x\n", hr);
unk = NULL;
hr = IUnknown_QueryInterface(output, &IID_IXmlWriterOutput, (void**)&unk);
IUnknown_Release(output);
output = NULL;
- hr = pCreateXmlWriterOutputWithEncodingCodePage(&testoutput, NULL, ~0u, &output);
+ hr = CreateXmlWriterOutputWithEncodingCodePage(&testoutput, NULL, ~0u, &output);
ok(hr == S_OK, "got %08x\n", hr);
IUnknown_Release(output);
- hr = pCreateXmlWriterOutputWithEncodingCodePage(&testoutput, NULL, CP_UTF8, &output);
+ hr = CreateXmlWriterOutputWithEncodingCodePage(&testoutput, NULL, CP_UTF8, &output);
ok(hr == S_OK, "got %08x\n", hr);
unk = NULL;
hr = IUnknown_QueryInterface(output, &IID_IXmlWriterOutput, (void**)&unk);
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;
- hr = pCreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
+ hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
/* output not set */
hr = IXmlWriter_Flush(writer);
ok(hr == S_OK, "got 0x%08x\n", 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);
+ stream = writer_set_output(writer);
/* nothing written yet */
hr = IXmlWriter_Flush(writer);
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(!strncmp(ptr, fullprolog, strlen(fullprolog)), "got %s, expected %s\n", ptr, fullprolog);
- GlobalUnlock(hglobal);
+ CHECK_OUTPUT(stream, fullprolog);
/* one more time */
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
IStream_Release(stream);
/* now add PI manually, and try to start a document */
- 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);
+ stream = writer_set_output(writer);
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(!strncmp(ptr, prologversion, strlen(prologversion)), "got %s\n", ptr);
- GlobalUnlock(hglobal);
+ CHECK_OUTPUT(stream, prologversion);
IStream_Release(stream);
IXmlWriter_Release(writer);
IXmlWriter *writer;
HRESULT hr;
- hr = pCreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
+ hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
hr = IXmlWriter_SetOutput(writer, (IUnknown*)&teststream);
HRESULT hr;
char *ptr;
- hr = pCreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
+ hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
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_SetOutput(writer, (IUnknown*)stream);
- ok(hr == S_OK, "got 0x%08x\n", hr);
+ stream = writer_set_output(writer);
hr = IXmlWriter_SetProperty(writer, XmlWriterProperty_OmitXmlDeclaration, TRUE);
ok(hr == S_OK, "got 0x%08x\n", hr);
IStream_Release(stream);
/* now add PI manually, and try to start a document */
- 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);
+ stream = writer_set_output(writer);
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(!strncmp(ptr, prologversion, strlen(prologversion)), "got %s\n", ptr);
- GlobalUnlock(hglobal);
+ CHECK_OUTPUT(stream, prologversion);
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);
- ptr = GlobalLock(hglobal);
- ok(!strncmp(ptr, prologversion, strlen(prologversion)), "got %s\n", ptr);
- GlobalUnlock(hglobal);
+ CHECK_OUTPUT(stream, prologversion);
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);
- ptr = GlobalLock(hglobal);
- ok(!strncmp(ptr, prologversion, strlen(prologversion)), "got %s\n", ptr);
- GlobalUnlock(hglobal);
+ CHECK_OUTPUT(stream, prologversion);
/* another attempt to add 'xml' PI */
hr = IXmlWriter_WriteProcessingInstruction(writer, xmlW, versionW);
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
- hr = pCreateXmlWriterOutputWithEncodingName((IUnknown*)stream, NULL, utf16W, &output);
+ hr = CreateXmlWriterOutputWithEncodingName((IUnknown*)stream, NULL, utf16W, &output);
ok(hr == S_OK, "got %08x\n", hr);
- hr = pCreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
+ hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
hr = IXmlWriter_SetProperty(writer, XmlWriterProperty_OmitXmlDeclaration, TRUE);
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
- hr = pCreateXmlWriterOutputWithEncodingName((IUnknown*)stream, NULL, utf16W, &output);
+ hr = CreateXmlWriterOutputWithEncodingName((IUnknown*)stream, NULL, utf16W, &output);
ok(hr == S_OK, "got %08x\n", hr);
hr = IXmlWriter_SetOutput(writer, output);
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
- hr = pCreateXmlWriterOutputWithEncodingName((IUnknown*)stream, NULL, utf16W, &output);
+ hr = CreateXmlWriterOutputWithEncodingName((IUnknown*)stream, NULL, utf16W, &output);
ok(hr == S_OK, "got %08x\n", hr);
hr = IXmlWriter_SetOutput(writer, output);
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
- hr = pCreateXmlWriterOutputWithEncodingName((IUnknown*)stream, NULL, utf16W, &output);
+ hr = CreateXmlWriterOutputWithEncodingName((IUnknown*)stream, NULL, utf16W, &output);
ok(hr == S_OK, "got %08x\n", hr);
hr = IXmlWriter_SetOutput(writer, output);
static const char *str = "<a><b>value</b>";
static const WCHAR aW[] = {'a',0};
static const WCHAR bW[] = {'b',0};
- char *ptr;
IXmlWriter *writer;
IStream *stream;
- HGLOBAL hglobal;
HRESULT hr;
- hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
- ok(hr == S_OK, "got 0x%08x\n", hr);
-
- hr = pCreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
+ hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
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);
- hr = IXmlWriter_SetOutput(writer, (IUnknown*)stream);
- ok(hr == S_OK, "got 0x%08x\n", hr);
+ stream = writer_set_output(writer);
hr = IXmlWriter_WriteStartElement(writer, aW, NULL, NULL);
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 = GetHGlobalFromStream(stream, &hglobal);
- 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);
- ptr = GlobalLock(hglobal);
- ok(!strncmp(ptr, "<a", 2), "got %s\n", ptr);
- GlobalUnlock(hglobal);
+ CHECK_OUTPUT(stream, "<a");
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes);
ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr);
IXmlWriter_Release(writer);
/* WriteElementString */
- hr = pCreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
+ hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
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);
ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
- hr = IXmlWriter_SetOutput(writer, (IUnknown*)stream);
- ok(hr == S_OK, "got 0x%08x\n", hr);
+ stream = writer_set_output(writer);
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(!strncmp(ptr, str, strlen(str)), "got %s\n", ptr);
- GlobalUnlock(hglobal);
+ CHECK_OUTPUT(stream, str);
IStream_Release(stream);
IXmlWriter_Release(writer);
{
static const WCHAR aW[] = {'a',0};
static const WCHAR bW[] = {'b',0};
- char *ptr;
IXmlWriter *writer;
IStream *stream;
- HGLOBAL hglobal;
HRESULT hr;
- hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
- ok(hr == S_OK, "got 0x%08x\n", hr);
-
- hr = pCreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
+ hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
- hr = IXmlWriter_SetOutput(writer, (IUnknown*)stream);
- ok(hr == S_OK, "got 0x%08x\n", hr);
+ stream = writer_set_output(writer);
hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXmlWriter_WriteEndElement(writer);
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);
ok(hr == S_OK, "got 0x%08x\n", hr);
- ptr = GlobalLock(hglobal);
- ok(!strncmp(ptr, "<a><b /></a>", 12), "got %s\n", ptr);
- GlobalUnlock(hglobal);
+ CHECK_OUTPUT(stream, "<a><b /></a>");
IXmlWriter_Release(writer);
IStream_Release(stream);
HRESULT hr;
char *ptr;
- hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
- ok(hr == S_OK, "got 0x%08x\n", hr);
-
- hr = pCreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
+ hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
hr = IXmlWriter_WriteEndDocument(writer);
ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
- hr = IXmlWriter_SetOutput(writer, (IUnknown*)stream);
- ok(hr == S_OK, "got 0x%08x\n", hr);
+ stream = writer_set_output(writer);
/* WriteEndDocument resets it to initial state */
hr = IXmlWriter_WriteEndDocument(writer);
hr = IXmlWriter_Flush(writer);
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>", 12), "got %s\n", ptr);
- GlobalUnlock(hglobal);
+ CHECK_OUTPUT(stream, "<a><b /></a>");
IXmlWriter_Release(writer);
IStream_Release(stream);
}
-START_TEST(writer)
+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;
+
+ hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
+ 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);
+
+ stream = writer_set_output(writer);
+
+ 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);
+
+ CHECK_OUTPUT(stream, "<!--a--><b><!--a--><!----><!--- ->-->");
+
+ IXmlWriter_Release(writer);
+ IStream_Release(stream);
+}
+
+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;
+
+ hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL);
+ 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);
+
+ stream = writer_set_output(writer);
+
+ 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);
+
+ CHECK_OUTPUT(stream,
+ "<b>"
+ "<![CDATA[a]]>"
+ "<![CDATA[]]>"
+ "<![CDATA[]]]]>"
+ "<![CDATA[>]]>"
+ "<![CDATA[a]]]]>"
+ "<![CDATA[>b]]>");
+
+ IXmlWriter_Release(writer);
+ IStream_Release(stream);
+}
+
+static void test_WriteRaw(void)
+{
+ static const WCHAR rawW[] = {'a','<',':',0};
+ 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);
+
+ 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);
+
+ stream = writer_set_output(writer);
+
+ 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);
+
+ 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);
+
+ 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);
+
+ CHECK_OUTPUT(stream, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>a<:a<:<!--a<:-->a<:<a>a</a>");
+
+ IXmlWriter_Release(writer);
+ IStream_Release(stream);
+}
+
+static void test_writer_state(void)
{
- if (!init_pointers())
- return;
+ 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);
+
+ /* initial state */
+ check_writer_state(writer, E_UNEXPECTED);
+
+ /* set output and call 'wrong' method, WriteEndElement */
+ 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);
+ /* WriteAttributeString */
+ 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);
+ 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);
+
+ /* 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);
+ IStream_Release(stream);
+
+ IXmlWriter_Release(writer);
+}
+
+START_TEST(writer)
+{
test_writer_create();
+ test_writer_state();
test_writeroutput();
test_writestartdocument();
test_writestartelement();
test_omitxmldeclaration();
test_bom();
test_writeenddocument();
+ test_WriteComment();
+ test_WriteCData();
+ test_WriteRaw();
}