xmllite: Implement CreateXmlWriterOutputWithEncodingCodePage.

This commit is contained in:
Hans Leidekker 2015-08-05 17:13:57 +02:00 committed by Alexandre Julliard
parent afb98a38ae
commit d1658260a2
5 changed files with 65 additions and 11 deletions

View File

@ -160,6 +160,16 @@ const WCHAR *get_encoding_name(xml_encoding encoding)
return xml_encoding_map[encoding].name; 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 typedef struct
{ {
char *data; char *data;

View File

@ -36,6 +36,10 @@ static HRESULT (WINAPI *pCreateXmlWriterOutputWithEncodingName)(IUnknown *stream
IMalloc *imalloc, IMalloc *imalloc,
LPCWSTR encoding_name, LPCWSTR encoding_name,
IXmlWriterOutput **output); 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) 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; #define MAKEFUNC(f) if (!(p##f = (void*)GetProcAddress(mod, #f))) return FALSE;
MAKEFUNC(CreateXmlWriter); MAKEFUNC(CreateXmlWriter);
MAKEFUNC(CreateXmlWriterOutputWithEncodingName); MAKEFUNC(CreateXmlWriterOutputWithEncodingName);
MAKEFUNC(CreateXmlWriterOutputWithEncodingCodePage);
#undef MAKEFUNC #undef MAKEFUNC
return TRUE; return TRUE;
@ -193,6 +198,20 @@ static void test_writeroutput(void)
ok(unk != NULL, "got %p\n", unk); ok(unk != NULL, "got %p\n", unk);
/* releasing 'unk' crashes on native */ /* releasing 'unk' crashes on native */
IUnknown_Release(output); 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) static void test_writestartdocument(void)

View File

@ -1085,19 +1085,12 @@ HRESULT WINAPI CreateXmlWriter(REFIID riid, void **obj, IMalloc *imalloc)
return S_OK; return S_OK;
} }
HRESULT WINAPI CreateXmlWriterOutputWithEncodingName(IUnknown *stream, static HRESULT create_writer(IUnknown *stream, IMalloc *imalloc, xml_encoding encoding,
IMalloc *imalloc, IXmlWriterOutput **output)
LPCWSTR encoding,
IXmlWriterOutput **output)
{ {
static const WCHAR utf8W[] = {'U','T','F','-','8',0};
xmlwriteroutput *writeroutput; xmlwriteroutput *writeroutput;
HRESULT hr; HRESULT hr;
TRACE("%p %p %s %p\n", stream, imalloc, debugstr_w(encoding), output);
if (!stream || !output) return E_INVALIDARG;
*output = NULL; *output = NULL;
if (imalloc) if (imalloc)
@ -1110,7 +1103,7 @@ HRESULT WINAPI CreateXmlWriterOutputWithEncodingName(IUnknown *stream,
writeroutput->ref = 1; writeroutput->ref = 1;
writeroutput->imalloc = imalloc; writeroutput->imalloc = imalloc;
if (imalloc) IMalloc_AddRef(imalloc); if (imalloc) IMalloc_AddRef(imalloc);
writeroutput->encoding = parse_encoding_name(encoding ? encoding : utf8W, -1); writeroutput->encoding = encoding;
writeroutput->stream = NULL; writeroutput->stream = NULL;
hr = init_output_buffer(writeroutput); hr = init_output_buffer(writeroutput);
if (FAILED(hr)) { if (FAILED(hr)) {
@ -1126,3 +1119,34 @@ HRESULT WINAPI CreateXmlWriterOutputWithEncodingName(IUnknown *stream,
return S_OK; 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);
}

View File

@ -2,5 +2,5 @@
@ stub CreateXmlReaderInputWithEncodingCodePage @ stub CreateXmlReaderInputWithEncodingCodePage
@ stdcall CreateXmlReaderInputWithEncodingName(ptr ptr ptr long ptr ptr) @ stdcall CreateXmlReaderInputWithEncodingName(ptr ptr ptr long ptr ptr)
@ stdcall CreateXmlWriter(ptr ptr ptr) @ stdcall CreateXmlWriter(ptr ptr ptr)
@ stub CreateXmlWriterOutputWithEncodingCodePage @ stdcall CreateXmlWriterOutputWithEncodingCodePage(ptr ptr long ptr)
@ stdcall CreateXmlWriterOutputWithEncodingName(ptr ptr wstr ptr) @ stdcall CreateXmlWriterOutputWithEncodingName(ptr ptr wstr ptr)

View File

@ -71,5 +71,6 @@ typedef enum
xml_encoding parse_encoding_name(const WCHAR*,int) DECLSPEC_HIDDEN; xml_encoding parse_encoding_name(const WCHAR*,int) DECLSPEC_HIDDEN;
HRESULT get_code_page(xml_encoding,UINT*) DECLSPEC_HIDDEN; HRESULT get_code_page(xml_encoding,UINT*) DECLSPEC_HIDDEN;
const WCHAR *get_encoding_name(xml_encoding) DECLSPEC_HIDDEN; const WCHAR *get_encoding_name(xml_encoding) DECLSPEC_HIDDEN;
xml_encoding get_encoding_from_codepage(UINT) DECLSPEC_HIDDEN;
#endif /* __XMLLITE_PRIVATE__ */ #endif /* __XMLLITE_PRIVATE__ */