summaryrefslogtreecommitdiffstats
path: root/tests/auto/qstringbuilder1/stringbuilder.cpp
diff options
context:
space:
mode:
authorOlivier Goffart <olivier.goffart@nokia.com>2011-04-06 13:01:48 +0200
committerOlivier Goffart <olivier.goffart@nokia.com>2011-04-06 14:29:37 +0200
commit0a4f6af142c57929bd743f3e95e25ada8642e9e4 (patch)
tree496b274cc44f6fe821a557e5f26d96cbf6837668 /tests/auto/qstringbuilder1/stringbuilder.cpp
parent3c400bdd727af5feebd1f514b2509f40250acd34 (diff)
QStringBuilder: add operator += for QString and QByteArray
Optimize cases when we have. string += someString + someOtherString Avoid the allocation of one temporary string. Behaviour change: byteArray += someString + QByteArray("foo\0bar", 7) before, the array would end at foo because of the conversion to string Reviewed-by: hjk
Diffstat (limited to 'tests/auto/qstringbuilder1/stringbuilder.cpp')
-rw-r--r--tests/auto/qstringbuilder1/stringbuilder.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/auto/qstringbuilder1/stringbuilder.cpp b/tests/auto/qstringbuilder1/stringbuilder.cpp
index 3c8ddc2a97..035a1f4e19 100644
--- a/tests/auto/qstringbuilder1/stringbuilder.cpp
+++ b/tests/auto/qstringbuilder1/stringbuilder.cpp
@@ -163,4 +163,37 @@ void runScenario()
QCOMPARE(r, r2);
}
+ //operator QString +=
+ {
+ QString str = QString::fromUtf8(UTF8_LITERAL);
+ str += QLatin1String(LITERAL) P str;
+ QCOMPARE(str, QString::fromUtf8(UTF8_LITERAL LITERAL UTF8_LITERAL));
+#ifndef QT_NO_CAST_FROM_ASCII
+ str = (QString::fromUtf8(UTF8_LITERAL) += QLatin1String(LITERAL) P UTF8_LITERAL);
+ QCOMPARE(str, QString::fromUtf8(UTF8_LITERAL LITERAL UTF8_LITERAL));
+#endif
+ }
+
+ //operator QByteArray +=
+ {
+ QByteArray ba = UTF8_LITERAL;
+ ba += QByteArray(LITERAL) P UTF8_LITERAL;
+ QCOMPARE(ba, QByteArray(UTF8_LITERAL LITERAL UTF8_LITERAL));
+ ba += LITERAL P QByteArray::fromRawData(UTF8_LITERAL_EXTRA, UTF8_LITERAL_LEN);
+ QCOMPARE(ba, QByteArray(UTF8_LITERAL LITERAL UTF8_LITERAL LITERAL UTF8_LITERAL));
+ QByteArray withZero = QByteArray(LITERAL "\0" LITERAL, LITERAL_LEN*2+1);
+ QByteArray ba2 = withZero;
+ ba2 += ba2 P withZero;
+ QCOMPARE(ba2, QByteArray(withZero + withZero + withZero));
+#ifndef QT_NO_CAST_TO_ASCII
+ ba = UTF8_LITERAL;
+ ba2 = (ba += QLatin1String(LITERAL) + QString::fromUtf8(UTF8_LITERAL));
+ QCOMPARE(ba2, ba);
+ QCOMPARE(ba, QByteArray(UTF8_LITERAL LITERAL UTF8_LITERAL));
+ ba = UTF8_LITERAL;
+ ba += QLatin1String(LITERAL) P withZero;
+ QCOMPARE(ba, QByteArray(UTF8_LITERAL LITERAL + withZero));
+#endif
+ }
+
}