summaryrefslogtreecommitdiffstats
path: root/tests/auto/qstringbuilder1
diff options
context:
space:
mode:
authorDenis Dzyubenko <denis.dzyubenko@nokia.com>2011-03-02 17:21:12 +0100
committerDenis Dzyubenko <denis.dzyubenko@nokia.com>2011-03-03 15:20:43 +0100
commit47e8fc1c237adb9742140f834226e9da9f60c2f2 (patch)
tree77e2d796664f763f8c4f4dc50aac027c21602bb5 /tests/auto/qstringbuilder1
parent61dfa74bb542f495eb5ff25e3f91b9065eb1cfdd (diff)
Improve handling QByteArray with QStringBuilder
Instead of relying on the old behavior of the deprecated QString(QByteArray) constructor which stops copying the byte array at the null termination character if there is one embedded in the array, we copy the whole provided QByteArray object into the QString when QStringBuilder is used. Reviewed-by: Harald Fernengel
Diffstat (limited to 'tests/auto/qstringbuilder1')
-rw-r--r--tests/auto/qstringbuilder1/stringbuilder.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/tests/auto/qstringbuilder1/stringbuilder.cpp b/tests/auto/qstringbuilder1/stringbuilder.cpp
index 6faff356f9..f3c0ea97dc 100644
--- a/tests/auto/qstringbuilder1/stringbuilder.cpp
+++ b/tests/auto/qstringbuilder1/stringbuilder.cpp
@@ -40,9 +40,13 @@
****************************************************************************/
#define LITERAL "some literal"
+#define LITERAL_LEN (sizeof(LITERAL)-1)
+#define LITERAL_EXTRA "some literal" "EXTRA"
// "some literal", but replacing all vocals by their umlauted UTF-8 string :)
#define UTF8_LITERAL "s\xc3\xb6m\xc3\xab l\xc3\xaft\xc3\xabr\xc3\xa4l"
+#define UTF8_LITERAL_LEN (sizeof(UTF8_LITERAL)-1)
+#define UTF8_LITERAL_EXTRA "s\xc3\xb6m\xc3\xab l\xc3\xaft\xc3\xabr\xc3\xa4l" "EXTRA"
//fix for gcc4.0: if the operator+ does not exist without QT_USE_FAST_OPERATOR_PLUS
@@ -65,7 +69,6 @@ void runScenario()
QLatin1Char achar('c');
QString r2(QLatin1String(LITERAL LITERAL));
QString r;
- QByteArray ba(LITERAL);
r = l1literal Q l1literal;
QCOMPARE(r, r2);
@@ -86,6 +89,15 @@ void runScenario()
QCOMPARE(r, r2);
r = LITERAL P string;
QCOMPARE(r, r2);
+
+ QByteArray ba = QByteArray(LITERAL);
+ r = ba P string;
+ QCOMPARE(r, r2);
+ r = string P ba;
+ QCOMPARE(r, r2);
+
+ static const char badata[] = LITERAL_EXTRA;
+ ba = QByteArray::fromRawData(badata, LITERAL_LEN);
r = ba P string;
QCOMPARE(r, r2);
r = string P ba;
@@ -109,6 +121,18 @@ void runScenario()
QCOMPARE(r, r2);
r = string P ba;
QCOMPARE(r, r2);
+
+ ba = QByteArray::fromRawData(UTF8_LITERAL_EXTRA, UTF8_LITERAL_LEN);
+ r = ba P string;
+ QCOMPARE(r, r2);
+ r = string P ba;
+ QCOMPARE(r, r2);
+
+ ba = QByteArray(); // empty
+ r = ba P string;
+ QCOMPARE(r, string);
+ r = string P ba;
+ QCOMPARE(r, string);
#endif
string = QString::fromLatin1(LITERAL);