Commit d1658260 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

xmllite: Implement CreateXmlWriterOutputWithEncodingCodePage.

parent afb98a38
......@@ -160,6 +160,16 @@ const WCHAR *get_encoding_name(xml_encoding encoding)
return xml_encoding_map[encoding].name;
}
xml_encoding get_encoding_from_codepage(UINT codepage)
{
int i;
for (i = 0; i < sizeof(xml_encoding_map)/sizeof(xml_encoding_map[0]); i++)
{
if (xml_encoding_map[i].cp == codepage) return xml_encoding_map[i].enc;
}
return XmlEncoding_Unknown;
}
typedef struct
{
char *data;
......
......@@ -36,6 +36,10 @@ 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 HRESULT WINAPI testoutput_QueryInterface(IUnknown *iface, REFIID riid, void **obj)
{
......@@ -168,6 +172,7 @@ static BOOL init_pointers(void)
#define MAKEFUNC(f) if (!(p##f = (void*)GetProcAddress(mod, #f))) return FALSE;
MAKEFUNC(CreateXmlWriter);
MAKEFUNC(CreateXmlWriterOutputWithEncodingName);
MAKEFUNC(CreateXmlWriterOutputWithEncodingCodePage);
#undef MAKEFUNC
return TRUE;
......@@ -193,6 +198,20 @@ static void test_writeroutput(void)
ok(unk != NULL, "got %p\n", unk);
/* releasing 'unk' crashes on native */
IUnknown_Release(output);
output = NULL;
hr = pCreateXmlWriterOutputWithEncodingCodePage(&testoutput, NULL, ~0u, &output);
ok(hr == S_OK, "got %08x\n", hr);
IUnknown_Release(output);
hr = pCreateXmlWriterOutputWithEncodingCodePage(&testoutput, NULL, CP_UTF8, &output);
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);
/* releasing 'unk' crashes on native */
IUnknown_Release(output);
}
static void test_writestartdocument(void)
......
......@@ -1085,19 +1085,12 @@ HRESULT WINAPI CreateXmlWriter(REFIID riid, void **obj, IMalloc *imalloc)
return S_OK;
}
HRESULT WINAPI CreateXmlWriterOutputWithEncodingName(IUnknown *stream,
IMalloc *imalloc,
LPCWSTR encoding,
IXmlWriterOutput **output)
static HRESULT create_writer(IUnknown *stream, IMalloc *imalloc, xml_encoding encoding,
IXmlWriterOutput **output)
{
static const WCHAR utf8W[] = {'U','T','F','-','8',0};
xmlwriteroutput *writeroutput;
HRESULT hr;
TRACE("%p %p %s %p\n", stream, imalloc, debugstr_w(encoding), output);
if (!stream || !output) return E_INVALIDARG;
*output = NULL;
if (imalloc)
......@@ -1110,7 +1103,7 @@ HRESULT WINAPI CreateXmlWriterOutputWithEncodingName(IUnknown *stream,
writeroutput->ref = 1;
writeroutput->imalloc = imalloc;
if (imalloc) IMalloc_AddRef(imalloc);
writeroutput->encoding = parse_encoding_name(encoding ? encoding : utf8W, -1);
writeroutput->encoding = encoding;
writeroutput->stream = NULL;
hr = init_output_buffer(writeroutput);
if (FAILED(hr)) {
......@@ -1126,3 +1119,34 @@ HRESULT WINAPI CreateXmlWriterOutputWithEncodingName(IUnknown *stream,
return S_OK;
}
HRESULT WINAPI CreateXmlWriterOutputWithEncodingName(IUnknown *stream,
IMalloc *imalloc,
LPCWSTR encoding,
IXmlWriterOutput **output)
{
static const WCHAR utf8W[] = {'U','T','F','-','8',0};
xml_encoding xml_enc;
TRACE("%p %p %s %p\n", stream, imalloc, debugstr_w(encoding), output);
if (!stream || !output) return E_INVALIDARG;
xml_enc = parse_encoding_name(encoding ? encoding : utf8W, -1);
return create_writer(stream, imalloc, xml_enc, output);
}
HRESULT WINAPI CreateXmlWriterOutputWithEncodingCodePage(IUnknown *stream,
IMalloc *imalloc,
UINT codepage,
IXmlWriterOutput **output)
{
xml_encoding xml_enc;
TRACE("%p %p %u %p\n", stream, imalloc, codepage, output);
if (!stream || !output) return E_INVALIDARG;
xml_enc = get_encoding_from_codepage(codepage);
return create_writer(stream, imalloc, xml_enc, output);
}
......@@ -2,5 +2,5 @@
@ stub CreateXmlReaderInputWithEncodingCodePage
@ stdcall CreateXmlReaderInputWithEncodingName(ptr ptr ptr long ptr ptr)
@ stdcall CreateXmlWriter(ptr ptr ptr)
@ stub CreateXmlWriterOutputWithEncodingCodePage
@ stdcall CreateXmlWriterOutputWithEncodingCodePage(ptr ptr long ptr)
@ stdcall CreateXmlWriterOutputWithEncodingName(ptr ptr wstr ptr)
......@@ -71,5 +71,6 @@ typedef enum
xml_encoding parse_encoding_name(const WCHAR*,int) DECLSPEC_HIDDEN;
HRESULT get_code_page(xml_encoding,UINT*) DECLSPEC_HIDDEN;
const WCHAR *get_encoding_name(xml_encoding) DECLSPEC_HIDDEN;
xml_encoding get_encoding_from_codepage(UINT) DECLSPEC_HIDDEN;
#endif /* __XMLLITE_PRIVATE__ */
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