summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/xml
diff options
context:
space:
mode:
authorLuca Bellonda <lbellonda@gmail.com>2016-06-01 00:06:13 +0200
committerLuca Bellonda <lbellonda@gmail.com>2016-06-08 18:50:25 +0000
commit767319a5aac2462df84431917b3724f884091036 (patch)
tree816964d5befe7923abc4eb3345855d8386e16e43 /tests/auto/corelib/xml
parent5a15545ee274a9caa33014755a3fdb7022c7ea8c (diff)
Add support for 8bit encodings not ASCII compatible in QXMLStreamWriter.
When using a 8 bit encoding to write a file, a test discovers if the encoding is really ASCII compatible by examining a letter and one of the XML reserved characters. EBCDIC, in the current base, was not well handled. [ChangeLog][QtCore][QXmlStreamWriter] Fixed a bug that prevented the generation of valid XML files when using encoding with 8 bit per character but not ASCII compatible. QXMLStreamWriter generated XML markup using always ASCII in this case. Change-Id: I9c86a122dd91b2290d50c358638442f99777d4ae Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/xml')
-rw-r--r--tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp b/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp
index 1da29ac3bd..b0fd1187f5 100644
--- a/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp
+++ b/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp
@@ -561,6 +561,7 @@ private slots:
void checkCommentIndentation() const;
void checkCommentIndentation_data() const;
void crashInXmlStreamReader() const;
+ void write8bitCodec() const;
void hasError() const;
private:
@@ -1578,5 +1579,43 @@ void tst_QXmlStream::hasError() const
}
+void tst_QXmlStream::write8bitCodec() const
+{
+ QBuffer outBuffer;
+ QVERIFY(outBuffer.open(QIODevice::WriteOnly));
+ QXmlStreamWriter writer(&outBuffer);
+ writer.setAutoFormatting(false);
+
+ QTextCodec *codec = QTextCodec::codecForName("IBM500");
+ if (!codec) {
+ QSKIP("Encoding IBM500 not available.");
+ }
+ writer.setCodec(codec);
+
+ writer.writeStartDocument();
+ writer.writeStartElement("root");
+ writer.writeAttribute("attrib", "1");
+ writer.writeEndElement();
+ writer.writeEndDocument();
+ outBuffer.close();
+
+ // test 8 bit encoding
+ QByteArray values = outBuffer.data();
+ QVERIFY(values.size() > 1);
+ // check '<'
+ QCOMPARE(values[0] & 0x00FF, 0x4c);
+ // check '?'
+ QCOMPARE(values[1] & 0x00FF, 0x6F);
+
+ // convert the start of the XML
+ const QString expected = ("<?xml version=\"1.0\" encoding=\"IBM500\"?>");
+ QTextDecoder *decoder = codec->makeDecoder();
+ QVERIFY(decoder);
+ QString decodedText = decoder->toUnicode(values);
+ delete decoder;
+ QVERIFY(decodedText.startsWith(expected));
+}
+
+
#include "tst_qxmlstream.moc"
// vim: et:ts=4:sw=4:sts=4