summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-10-25 18:59:53 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-10-25 18:59:53 (GMT)
commit667d94f6ab824a9b56c28943f02054467741e070 (patch)
tree0c35a4ab5d78b1e5c6ba46e9ed2572937c9ecac3 /tests/auto
parentc7afbc97d4cb60ed11996d0bcbbddaac2b18d18c (diff)
parent7eb4eb076531c3190af0452c865b928c60b225bb (diff)
downloadQt-667d94f6ab824a9b56c28943f02054467741e070.zip
Qt-667d94f6ab824a9b56c28943f02054467741e070.tar.gz
Qt-667d94f6ab824a9b56c28943f02054467741e070.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-1: add autotest for QString::setRawData()
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qstring/tst_qstring.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/auto/qstring/tst_qstring.cpp b/tests/auto/qstring/tst_qstring.cpp
index ef82769..9df2a4d 100644
--- a/tests/auto/qstring/tst_qstring.cpp
+++ b/tests/auto/qstring/tst_qstring.cpp
@@ -76,6 +76,7 @@ private slots:
void check_QTextStream();
void check_QDataStream();
void fromRawData();
+ void setRawData();
void endsWith();
void startsWith();
void setNum();
@@ -2999,7 +3000,9 @@ void tst_QString::fromRawData()
{
const QChar ptr[] = { 0x1234, 0x0000 };
QString cstr = QString::fromRawData(ptr, 1);
+ QVERIFY(cstr.isDetached());
QVERIFY(cstr.constData() == ptr);
+ QVERIFY(cstr == QString(ptr, 1));
cstr.squeeze();
QVERIFY(cstr.constData() == ptr);
cstr.detach();
@@ -3010,6 +3013,41 @@ void tst_QString::fromRawData()
QVERIFY(cstr.constData()[1] == QChar(0x0000));
}
+void tst_QString::setRawData()
+{
+ const QChar ptr[] = { 0x1234, 0x0000 };
+ const QChar ptr2[] = { 0x4321, 0x0000 };
+ QString cstr;
+
+ // This just tests the fromRawData() fallback
+ QVERIFY(!cstr.isDetached());
+ cstr.setRawData(ptr, 1);
+ QVERIFY(cstr.isDetached());
+ QVERIFY(cstr.constData() == ptr);
+ QVERIFY(cstr == QString(ptr, 1));
+
+ // This actually tests the recycling of the shared data object
+ QString::DataPtr csd = cstr.data_ptr();
+ cstr.setRawData(ptr2, 1);
+ QVERIFY(cstr.isDetached());
+ QVERIFY(cstr.constData() == ptr2);
+ QVERIFY(cstr == QString(ptr2, 1));
+ QVERIFY(cstr.data_ptr() == csd);
+
+ // This tests the discarding of the shared data object
+ cstr = "foo";
+ QVERIFY(cstr.isDetached());
+ QVERIFY(cstr.constData() != ptr2);
+
+ // Another test of the fallback
+ csd = cstr.data_ptr();
+ cstr.setRawData(ptr2, 1);
+ QVERIFY(cstr.isDetached());
+ QVERIFY(cstr.constData() == ptr2);
+ QVERIFY(cstr == QString(ptr2, 1));
+ QVERIFY(cstr.data_ptr() != csd);
+}
+
void tst_QString::fromStdString()
{
#ifdef Q_CC_HPACC