Commit a68e51ce authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

xmllite/writer: Preserve original encoding name spelling in writer output.

parent ef023c3f
......@@ -324,9 +324,12 @@ todo_wine
static void test_writestartdocument(void)
{
static const char fullprolog[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
static const char *prologversion2 = "<?xml version=\"1.0\" encoding=\"uS-asCii\"?>";
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 usasciiW[] = {'u','S','-','a','s','C','i','i',0};
static const WCHAR xmlW[] = {'x','m','l',0};
IXmlWriterOutput *output;
IXmlWriter *writer;
IStream *stream;
HRESULT hr;
......@@ -386,6 +389,32 @@ static void test_writestartdocument(void)
IStream_Release(stream);
IXmlWriter_Release(writer);
/* create with us-ascii */
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
output = NULL;
hr = CreateXmlWriterOutputWithEncodingName((IUnknown *)stream, NULL, usasciiW, &output);
ok(hr == S_OK, "got %08x\n", hr);
hr = CreateXmlWriter(&IID_IXmlWriter, (void **)&writer, NULL);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
hr = IXmlWriter_SetOutput(writer, output);
ok(hr == S_OK, "got %08x\n", hr);
hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit);
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, prologversion2);
IStream_Release(stream);
IXmlWriter_Release(writer);
IUnknown_Release(output);
}
static void test_flush(void)
......
......@@ -73,6 +73,7 @@ typedef struct
ISequentialStream *stream;
IMalloc *imalloc;
xml_encoding encoding;
WCHAR *encoding_name; /* exactly as specified on output creation */
struct output_buffer buffer;
} xmlwriteroutput;
......@@ -373,6 +374,14 @@ static HRESULT write_encoding_bom(xmlwriter *writer)
return S_OK;
}
static const WCHAR *get_output_encoding_name(xmlwriteroutput *output)
{
if (output->encoding_name)
return output->encoding_name;
return get_encoding_name(output->encoding);
}
static HRESULT write_xmldecl(xmlwriter *writer, XmlStandalone standalone)
{
static const WCHAR versionW[] = {'<','?','x','m','l',' ','v','e','r','s','i','o','n','=','"','1','.','0','"'};
......@@ -387,7 +396,7 @@ static HRESULT write_xmldecl(xmlwriter *writer, XmlStandalone standalone)
/* encoding */
write_output_buffer(writer->output, encodingW, ARRAY_SIZE(encodingW));
write_output_buffer_quoted(writer->output, get_encoding_name(writer->output->encoding), -1);
write_output_buffer_quoted(writer->output, get_output_encoding_name(writer->output), -1);
/* standalone */
if (standalone == XmlStandalone_Omit)
......@@ -1366,6 +1375,7 @@ static ULONG WINAPI xmlwriteroutput_Release(IXmlWriterOutput *iface)
if (This->output) IUnknown_Release(This->output);
if (This->stream) ISequentialStream_Release(This->stream);
free_output_buffer(This);
writeroutput_free(This, This->encoding_name);
writeroutput_free(This, This);
if (imalloc) IMalloc_Release(imalloc);
}
......@@ -1420,8 +1430,8 @@ HRESULT WINAPI CreateXmlWriter(REFIID riid, void **obj, IMalloc *imalloc)
return S_OK;
}
static HRESULT create_writer(IUnknown *stream, IMalloc *imalloc, xml_encoding encoding,
IXmlWriterOutput **output)
static HRESULT create_writer_output(IUnknown *stream, IMalloc *imalloc, xml_encoding encoding,
const WCHAR *encoding_name, IXmlWriterOutput **output)
{
xmlwriteroutput *writeroutput;
HRESULT hr;
......@@ -1432,12 +1442,14 @@ static HRESULT create_writer(IUnknown *stream, IMalloc *imalloc, xml_encoding en
writeroutput = IMalloc_Alloc(imalloc, sizeof(*writeroutput));
else
writeroutput = heap_alloc(sizeof(*writeroutput));
if(!writeroutput) return E_OUTOFMEMORY;
if (!writeroutput)
return E_OUTOFMEMORY;
writeroutput->IXmlWriterOutput_iface.lpVtbl = &xmlwriteroutputvtbl;
writeroutput->ref = 1;
writeroutput->imalloc = imalloc;
if (imalloc) IMalloc_AddRef(imalloc);
if (imalloc)
IMalloc_AddRef(imalloc);
writeroutput->encoding = encoding;
writeroutput->stream = NULL;
hr = init_output_buffer(writeroutput);
......@@ -1446,6 +1458,14 @@ static HRESULT create_writer(IUnknown *stream, IMalloc *imalloc, xml_encoding en
return hr;
}
if (encoding_name) {
unsigned int size = (strlenW(encoding_name) + 1) * sizeof(WCHAR);
writeroutput->encoding_name = writeroutput_alloc(writeroutput, size);
memcpy(writeroutput->encoding_name, encoding_name, size);
}
else
writeroutput->encoding_name = NULL;
IUnknown_QueryInterface(stream, &IID_IUnknown, (void**)&writeroutput->output);
*output = &writeroutput->IXmlWriterOutput_iface;
......@@ -1468,7 +1488,7 @@ HRESULT WINAPI CreateXmlWriterOutputWithEncodingName(IUnknown *stream,
if (!stream || !output) return E_INVALIDARG;
xml_enc = parse_encoding_name(encoding ? encoding : utf8W, -1);
return create_writer(stream, imalloc, xml_enc, output);
return create_writer_output(stream, imalloc, xml_enc, encoding, output);
}
HRESULT WINAPI CreateXmlWriterOutputWithEncodingCodePage(IUnknown *stream,
......@@ -1483,5 +1503,5 @@ HRESULT WINAPI CreateXmlWriterOutputWithEncodingCodePage(IUnknown *stream,
if (!stream || !output) return E_INVALIDARG;
xml_enc = get_encoding_from_codepage(codepage);
return create_writer(stream, imalloc, xml_enc, output);
return create_writer_output(stream, imalloc, xml_enc, NULL, output);
}
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