summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-08-10 17:43:12 +0200
committerLiang Qi <liang.qi@qt.io>2016-08-10 17:43:13 +0200
commit8ba384a5645aebbefe34b814828024d511171497 (patch)
tree6f6cfe1b849b6e0e02de15ee74ad0f3d5fc740b6 /tests/auto/corelib/tools
parente694ced803589b3504b6bdb2fc8bf97bc891c794 (diff)
parent25b72a63fffe800f2005b21d254b0b191d263b10 (diff)
Merge remote-tracking branch 'origin/5.6' into 5.7
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r--tests/auto/corelib/tools/qstring/tst_qstring.cpp62
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 6aeea70cbf..44b8135410 100644
--- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
@@ -500,6 +500,8 @@ private slots:
void fromLocal8Bit();
void local8Bit_data();
void local8Bit();
+ void invalidToLocal8Bit_data();
+ void invalidToLocal8Bit();
void nullFromLocal8Bit();
void fromLatin1Roundtrip_data();
void fromLatin1Roundtrip();
@@ -4298,6 +4300,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;