summaryrefslogtreecommitdiffstats
path: root/tests/auto/qtextcodec/tst_qtextcodec.cpp
diff options
context:
space:
mode:
authorDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-06-11 12:59:23 (GMT)
committerDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-06-11 19:04:15 (GMT)
commitf6aa5d8cfbec4f4ffacf20a94a1653c1a8ee2134 (patch)
tree2ac49d8f20eb83067932bb655939d6bb044a0fb0 /tests/auto/qtextcodec/tst_qtextcodec.cpp
parent52392292c8fa096e3b0bb692dedce66924ab3305 (diff)
downloadQt-f6aa5d8cfbec4f4ffacf20a94a1653c1a8ee2134.zip
Qt-f6aa5d8cfbec4f4ffacf20a94a1653c1a8ee2134.tar.gz
Qt-f6aa5d8cfbec4f4ffacf20a94a1653c1a8ee2134.tar.bz2
UTF-8 text codec should be able to convert data when fed one by one byte.
When the input data is fed to utf-8 by one byte it couldn't parse the BOM correctly. So we wait until the BOM is composed into a code point and check it afterwards. Reviewed-by: Olivier Goffart
Diffstat (limited to 'tests/auto/qtextcodec/tst_qtextcodec.cpp')
-rw-r--r--tests/auto/qtextcodec/tst_qtextcodec.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/auto/qtextcodec/tst_qtextcodec.cpp b/tests/auto/qtextcodec/tst_qtextcodec.cpp
index 97c409b..88dbaf7 100644
--- a/tests/auto/qtextcodec/tst_qtextcodec.cpp
+++ b/tests/auto/qtextcodec/tst_qtextcodec.cpp
@@ -74,6 +74,9 @@ private slots:
void utf8Codec_data();
void utf8Codec();
+ void utf8bom_data();
+ void utf8bom();
+
void utfHeaders_data();
void utfHeaders();
@@ -1513,6 +1516,63 @@ void tst_QTextCodec::utf8Codec()
QCOMPARE(str, res);
}
+void tst_QTextCodec::utf8bom_data()
+{
+ QTest::addColumn<QByteArray>("data");
+ QTest::addColumn<QString>("result");
+
+ QTest::newRow("nobom")
+ << QByteArray("\302\240", 2)
+ << QString("\240");
+
+ {
+ static const ushort data[] = { 0x201d };
+ QTest::newRow("nobom 2")
+ << QByteArray("\342\200\235", 3)
+ << QString::fromUtf16(data, sizeof(data)/sizeof(short));
+ }
+
+ {
+ static const ushort data[] = { 0xf000 };
+ QTest::newRow("bom1")
+ << QByteArray("\357\200\200", 3)
+ << QString::fromUtf16(data, sizeof(data)/sizeof(short));
+ }
+
+ {
+ static const ushort data[] = { 0xfec0 };
+ QTest::newRow("bom2")
+ << QByteArray("\357\273\200", 3)
+ << QString::fromUtf16(data, sizeof(data)/sizeof(short));
+ }
+
+ {
+ QTest::newRow("normal-bom")
+ << QByteArray("\357\273\277a", 4)
+ << QString("a");
+ }
+
+ {
+ static const ushort data[] = { 0x61, 0xfeff, 0x62 };
+ QTest::newRow("middle-bom")
+ << QByteArray("a\357\273\277b", 5)
+ << QString::fromUtf16(data, sizeof(data)/sizeof(short));
+ }
+}
+
+void tst_QTextCodec::utf8bom()
+{
+ QFETCH(QByteArray, data);
+ QFETCH(QString, result);
+
+ QTextCodec *const codec = QTextCodec::codecForMib(106); // UTF-8
+ Q_ASSERT(codec);
+
+ QCOMPARE(codec->toUnicode(data.constData(), data.length(), 0), result);
+
+ QTextCodec::ConverterState state;
+ QCOMPARE(codec->toUnicode(data.constData(), data.length(), &state), result);
+}
void tst_QTextCodec::utfHeaders_data()
{