diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-10-25 22:10:28 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-10-25 22:10:28 (GMT) |
commit | a2cede57d2ff5358148a25d6a41de777144a5fe7 (patch) | |
tree | cf47721a9370a8eefd74aa23ed220b7bf44aa72b /tests/auto/qstring | |
parent | 2b78291003543d45d176424d6d9624d0c02c273c (diff) | |
parent | 667d94f6ab824a9b56c28943f02054467741e070 (diff) | |
download | Qt-a2cede57d2ff5358148a25d6a41de777144a5fe7.zip Qt-a2cede57d2ff5358148a25d6a41de777144a5fe7.tar.gz Qt-a2cede57d2ff5358148a25d6a41de777144a5fe7.tar.bz2 |
Merge branch 4.7 into qt-master-from-4.7
Diffstat (limited to 'tests/auto/qstring')
-rw-r--r-- | tests/auto/qstring/tst_qstring.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/auto/qstring/tst_qstring.cpp b/tests/auto/qstring/tst_qstring.cpp index af6b371..003332c 100644 --- a/tests/auto/qstring/tst_qstring.cpp +++ b/tests/auto/qstring/tst_qstring.cpp @@ -80,6 +80,7 @@ private slots: void check_QTextStream(); void check_QDataStream(); void fromRawData(); + void setRawData(); void endsWith(); void startsWith(); void setNum(); @@ -3077,7 +3078,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(); @@ -3088,6 +3091,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 |