diff options
author | Jan Arve Saether <jan-arve.saether@digia.com> | 2012-11-20 11:11:44 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-11-23 04:53:10 +0100 |
commit | 169ba759c536fcd807ee061e1831e4502a5f1416 (patch) | |
tree | 1e81cda11d7161ce1b4d2a3464e3c85cf4ae1129 /tests/auto/qxmlstream | |
parent | 96311def2466dd44de64d77a1c815b22fbf68f71 (diff) |
Fix regression in QXmlStreamWriter with codec set to UTF-16
Actually, this broke using QXmlStreamWriter with any codec
where characters in the ASCII range have a different encoding
than the ASCII standard.
This was a regression from 558fe9383ba0aecbec09cc411c0ebab132aac137
Backported from Qt 5 (035d93a6e1cbde76d34866ffd9b39633572e6236),
and changed QStringLiteral to QLatin1String
Task-number: QTBUG-23310
Change-Id: Iaaf25463737382ace1bdb83138c7dd634d825b30
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Diffstat (limited to 'tests/auto/qxmlstream')
-rw-r--r-- | tests/auto/qxmlstream/tst_qxmlstream.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/auto/qxmlstream/tst_qxmlstream.cpp b/tests/auto/qxmlstream/tst_qxmlstream.cpp index 9082a0c1c4..8ec739347f 100644 --- a/tests/auto/qxmlstream/tst_qxmlstream.cpp +++ b/tests/auto/qxmlstream/tst_qxmlstream.cpp @@ -568,6 +568,7 @@ private slots: void hasAttribute() const; void writeWithCodec() const; void writeWithUtf8Codec() const; + void writeWithUtf16Codec() const; void writeWithStandalone() const; void entitiesAndWhitespace_1() const; void entitiesAndWhitespace_2() const; @@ -1366,6 +1367,27 @@ void tst_QXmlStream::writeWithUtf8Codec() const QVERIFY(outarray.startsWith(begin)); } +void tst_QXmlStream::writeWithUtf16Codec() const +{ + QByteArray outarray; + QXmlStreamWriter writer(&outarray); + + QTextCodec *codec = QTextCodec::codecForMib(1014); // utf-16LE + QVERIFY(codec); + writer.setCodec(codec); + + writer.writeStartDocument("1.0"); + static const char begin[] = "<?xml version=\"1.0\" encoding=\"UTF-16"; // skip potential "LE" suffix + const int count = sizeof(begin) - 1; // don't include 0 terminator + QByteArray begin_UTF16; + begin_UTF16.reserve(2*(count)); + for (int i = 0; i < count; ++i) { + begin_UTF16.append(begin[i]); + begin_UTF16.append((char)'\0'); + } + QVERIFY(outarray.startsWith(begin_UTF16)); +} + void tst_QXmlStream::writeWithStandalone() const { { |