diff options
author | Liang Qi <liang.qi@qt.io> | 2016-08-16 07:58:32 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-08-16 07:58:32 +0200 |
commit | 17198e03ab36e5f579a1477b09cc3e601975eb5f (patch) | |
tree | 61ba826e9edd53469abdc1e1f58b1223d0336c56 /tests/auto/corelib/tools/qstring | |
parent | a5e89005445ac8ca18ac046eaf55fe2230e47cd6 (diff) | |
parent | 2e2b32a9ab459f6618d02e4b454c75a787172def (diff) |
Merge remote-tracking branch 'origin/5.7' into dev
Conflicts:
qmake/doc/src/qmake-manual.qdoc
src/corelib/global/qglobal.cpp
src/corelib/tools/qstring.cpp
src/network/socket/qabstractsocket.cpp
src/network/socket/qnativesocketengine_unix.cpp
src/plugins/platforms/eglfs/api/qeglfsglobal.h
Change-Id: Id5dfdbd30fa996f9b4b66a0b030b7d3b8c0ef288
Diffstat (limited to 'tests/auto/corelib/tools/qstring')
-rw-r--r-- | tests/auto/corelib/tools/qstring/tst_qstring.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 7a37fdfa46..8f0f599622 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -496,6 +496,8 @@ private slots: void fromLocal8Bit(); void local8Bit_data(); void local8Bit(); + void invalidToLocal8Bit_data(); + void invalidToLocal8Bit(); void nullFromLocal8Bit(); void fromLatin1Roundtrip_data(); void fromLatin1Roundtrip(); @@ -4290,6 +4292,66 @@ void tst_QString::local8Bit() QCOMPARE(local8Bit.toLocal8Bit(), QByteArray(result)); } +void tst_QString::invalidToLocal8Bit_data() +{ + QTest::addColumn<QString>("unicode"); + QTest::addColumn<QByteArray>("expect"); // Initial validly-converted prefix + + { + const QChar malformed[] = { 'A', 0xd800, 'B', 0 }; + const char expected[] = "A"; + QTest::newRow("LoneHighSurrogate") + << QString(malformed, sizeof(malformed) / sizeof(QChar)) + // Don't include the terminating '\0' of expected: + << QByteArray(expected, sizeof(expected) / sizeof(char) - 1); + } + { + const QChar malformed[] = { 'A', 0xdc00, 'B', 0 }; + const char expected[] = "A"; + QTest::newRow("LoneLowSurrogate") + << QString(malformed, sizeof(malformed) / sizeof(QChar)) + << QByteArray(expected, sizeof(expected) / sizeof(char) - 1); + } + { + const QChar malformed[] = { 'A', 0xd800, 0xd801, 'B', 0 }; + const char expected[] = "A"; + QTest::newRow("DoubleHighSurrogate") + << QString(malformed, sizeof(malformed) / sizeof(QChar)) + << QByteArray(expected, sizeof(expected) / sizeof(char) - 1); + } + { + const QChar malformed[] = { 'A', 0xdc00, 0xdc01, 'B', 0 }; + const char expected[] = "A"; + QTest::newRow("DoubleLowSurrogate") + << QString(malformed, sizeof(malformed) / sizeof(QChar)) + << QByteArray(expected, sizeof(expected) / sizeof(char) - 1); + } + { + const QChar malformed[] = { 'A', 0xdc00, 0xd800, 'B', 0 }; + const char expected[] = "A"; + QTest::newRow("ReversedSurrogates") // low before high + << QString(malformed, sizeof(malformed) / sizeof(QChar)) + << QByteArray(expected, sizeof(expected) / sizeof(char) - 1); + } +} + +void tst_QString::invalidToLocal8Bit() +{ + QFETCH(QString, unicode); + QFETCH(QByteArray, expect); + QByteArray local = unicode.toLocal8Bit(); + /* + The main concern of this test is to check that any error-reporting that + toLocal8Bit() prompts on failure isn't dependent on outputting the data + it's converting via toLocal8Bit(), which would be apt to recurse. So the + real purpose of this QVERIFY(), for all that we should indeed check we get + the borked output that matches what we can reliably expect (despite + variation in how codecs respond to errors), is to verify that we got here + - i.e. we didn't crash in such a recursive stack over-flow. + */ + QVERIFY(local.startsWith(expect)); +} + void tst_QString::nullFromLocal8Bit() { QString a; |