From 320d419be1fe713c50eac7d53e4dc52481fad8b7 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Mon, 14 May 2012 16:46:32 +0400 Subject: [PATCH] msxml3: Support iso-8859-x encodings in writer. --- dlls/msxml3/mxwriter.c | 35 ++++++++++++++++-- dlls/msxml3/tests/saxreader.c | 70 +++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 4 deletions(-) diff --git a/dlls/msxml3/mxwriter.c b/dlls/msxml3/mxwriter.c index c5ecf372c09..81d498e80a9 100644 --- a/dlls/msxml3/mxwriter.c +++ b/dlls/msxml3/mxwriter.c @@ -46,7 +46,16 @@ static const WCHAR quotW[] = {'\"'}; /* should be ordered as encoding names are sorted */ typedef enum { - XmlEncoding_UTF16 = 0, + XmlEncoding_ISO_8859_1 = 0, + XmlEncoding_ISO_8859_13, + XmlEncoding_ISO_8859_15, + XmlEncoding_ISO_8859_2, + XmlEncoding_ISO_8859_3, + XmlEncoding_ISO_8859_4, + XmlEncoding_ISO_8859_5, + XmlEncoding_ISO_8859_7, + XmlEncoding_ISO_8859_9, + XmlEncoding_UTF16, XmlEncoding_UTF8, XmlEncoding_Unknown } xml_encoding; @@ -58,12 +67,30 @@ struct xml_encoding_data UINT cp; }; +static const WCHAR iso_8859_1W[] = {'i','s','o','-','8','8','5','9','-','1',0}; +static const WCHAR iso_8859_2W[] = {'i','s','o','-','8','8','5','9','-','2',0}; +static const WCHAR iso_8859_3W[] = {'i','s','o','-','8','8','5','9','-','3',0}; +static const WCHAR iso_8859_4W[] = {'i','s','o','-','8','8','5','9','-','4',0}; +static const WCHAR iso_8859_5W[] = {'i','s','o','-','8','8','5','9','-','5',0}; +static const WCHAR iso_8859_7W[] = {'i','s','o','-','8','8','5','9','-','7',0}; +static const WCHAR iso_8859_9W[] = {'i','s','o','-','8','8','5','9','-','9',0}; +static const WCHAR iso_8859_13W[] = {'i','s','o','-','8','8','5','9','-','1','3',0}; +static const WCHAR iso_8859_15W[] = {'i','s','o','-','8','8','5','9','-','1','5',0}; static const WCHAR utf16W[] = {'U','T','F','-','1','6',0}; static const WCHAR utf8W[] = {'U','T','F','-','8',0}; static const struct xml_encoding_data xml_encoding_map[] = { - { utf16W, XmlEncoding_UTF16, ~0 }, /* there's no codepage for this case */ - { utf8W, XmlEncoding_UTF8, CP_UTF8 } + { iso_8859_1W, XmlEncoding_ISO_8859_1, 28591 }, + { iso_8859_13W, XmlEncoding_ISO_8859_13, 28603 }, + { iso_8859_15W, XmlEncoding_ISO_8859_15, 28605 }, + { iso_8859_2W, XmlEncoding_ISO_8859_2, 28592 }, + { iso_8859_3W, XmlEncoding_ISO_8859_3, 28593 }, + { iso_8859_4W, XmlEncoding_ISO_8859_4, 28594 }, + { iso_8859_5W, XmlEncoding_ISO_8859_5, 28595 }, + { iso_8859_7W, XmlEncoding_ISO_8859_7, 28597 }, + { iso_8859_9W, XmlEncoding_ISO_8859_9, 28599 }, + { utf16W, XmlEncoding_UTF16, ~0 }, + { utf8W, XmlEncoding_UTF8, CP_UTF8 } }; typedef enum @@ -300,7 +327,7 @@ static HRESULT write_output_buffer_mode(output_buffer *buffer, output_mode mode, char *ptr; if (mode & (OutputBuffer_Encoded | OutputBuffer_Both)) { - if (buffer->code_page == CP_UTF8) + if (buffer->code_page != ~0) { length = WideCharToMultiByte(buffer->code_page, 0, data, len, NULL, 0, NULL, NULL); grow_buffer(&buffer->encoded, length); diff --git a/dlls/msxml3/tests/saxreader.c b/dlls/msxml3/tests/saxreader.c index 0a0651b77e6..1b19c3c13e3 100644 --- a/dlls/msxml3/tests/saxreader.c +++ b/dlls/msxml3/tests/saxreader.c @@ -3647,16 +3647,31 @@ static void test_mxwriter_stream(void) free_bstrs(); } +static const char *encoding_names[] = { + "iso-8859-1", + "iso-8859-2", + "iso-8859-3", + "iso-8859-4", + "iso-8859-5", + "iso-8859-7", + "iso-8859-9", + "iso-8859-13", + "iso-8859-15", + NULL +}; + static void test_mxwriter_encoding(void) { ISAXContentHandler *content; IMXWriter *writer; IStream *stream; + const char *enc; VARIANT dest; HRESULT hr; HGLOBAL g; char *ptr; BSTR s; + int i; hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER, &IID_IMXWriter, (void**)&writer); @@ -3726,6 +3741,61 @@ static void test_mxwriter_encoding(void) IStream_Release(stream); + i = 0; + enc = encoding_names[i]; + while (enc) + { + char expectedA[200]; + + hr = CreateStreamOnHGlobal(NULL, TRUE, &stream); + EXPECT_HR(hr, S_OK); + + V_VT(&dest) = VT_UNKNOWN; + V_UNKNOWN(&dest) = (IUnknown*)stream; + hr = IMXWriter_put_output(writer, dest); + EXPECT_HR(hr, S_OK); + + hr = IMXWriter_put_encoding(writer, _bstr_(enc)); + ok(hr == S_OK || broken(hr != S_OK) /* old win versions do not support certain encodings */, + "%s: encoding not accepted\n", enc); + if (hr != S_OK) + { + enc = encoding_names[i++]; + IStream_Release(stream); + continue; + } + + hr = ISAXContentHandler_startDocument(content); + EXPECT_HR(hr, S_OK); + + hr = ISAXContentHandler_endDocument(content); + EXPECT_HR(hr, S_OK); + + hr = IMXWriter_flush(writer); + EXPECT_HR(hr, S_OK); + + /* prepare expected string */ + *expectedA = 0; + strcat(expectedA, "\r\n"); + + hr = GetHGlobalFromStream(stream, &g); + EXPECT_HR(hr, S_OK); + + ptr = GlobalLock(g); + ok(!strncmp(ptr, expectedA, strlen(expectedA)), "%s: got %s, expected %.50s\n", enc, ptr, expectedA); + GlobalUnlock(g); + + V_VT(&dest) = VT_EMPTY; + hr = IMXWriter_put_output(writer, dest); + EXPECT_HR(hr, S_OK); + + IStream_Release(stream); + + enc = encoding_names[++i]; + } + ISAXContentHandler_Release(content); IMXWriter_Release(writer);