diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 629a095..d55bde3 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -258,6 +258,8 @@ private slots: void assignQLatin1String(); void isRightToLeft_data(); void isRightToLeft(); + void utf8bom_data(); + void utf8bom(); }; template const T &verifyZeroTermination(const T &t) { return t; } @@ -6020,6 +6022,59 @@ void tst_QString::isRightToLeft() QCOMPARE(unicode.isRightToLeft(), rtl); } +// copied from tst_QTextCodec +void tst_QString::utf8bom_data() +{ + QTest::addColumn("data"); + QTest::addColumn("result"); + + QTest::newRow("nobom") + << QByteArray("\302\240", 2) + << QString::fromLatin1("\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_QString::utf8bom() +{ + QFETCH(QByteArray, data); + QFETCH(QString, result); + + QCOMPARE(QString::fromUtf8(data), result); +} + QTEST_APPLESS_MAIN(tst_QString) #include "tst_qstring.moc"