diff options
Diffstat (limited to 'tests/auto/qstring/tst_qstring.cpp')
-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 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 |