void readFromStreamLX(QMimeData* aData,RReadStream& aStream) { // This function both leaves and throws exceptions. There must be no destructor // dependencies between cleanup styles, and no cleanup stack dependencies on stacked objects. TCardinality mimeTypeCount; aStream >> mimeTypeCount; for (int i = 0; i< mimeTypeCount;i++) { // mime type TCardinality mimeTypeSize; aStream >> mimeTypeSize; HBufC* mimeTypeBuf = HBufC::NewLC(aStream,mimeTypeSize); QString mimeType = QString::fromUtf16(mimeTypeBuf->Des().Ptr(),mimeTypeBuf->Length()); CleanupStack::PopAndDestroy(mimeTypeBuf); // mime data TCardinality dataSize; aStream >> dataSize; QByteArray ba; ba.reserve(dataSize); aStream.ReadL(reinterpret_cast<uchar*>(ba.data_ptr()->data),dataSize); ba.data_ptr()->size = dataSize; qDebug() << "paste from clipboard mime: " << mimeType << " data: " << ba; aData->setData(mimeType,ba); } }
void test_setFromRawData() { char rawData[] = "hello world!"; QByteArray ba; QByteArray::DataPtr oldDataPtr = ba.data_ptr(); ba.setRawData(rawData, 5); QVERIFY(oldDataPtr != ba.data_ptr()); oldDataPtr = ba.data_ptr(); ba.setRawData(rawData + 6, 5); // Start using QByteArray::setRawData directly if the following QVERIFY fails. // This would mean that the QByteArray::setRawData behavior has been changed to the // desired one where switching from one raw data to another does not cause a // QByteArray data block reallocation. Qt5 maybe? QVERIFY(oldDataPtr != ba.data_ptr()); // Go ahead and do tests on our replacement setFromRawData. ba = QByteArray(); oldDataPtr = ba.data_ptr(); QVERIFY(ba.data_ptr()->ref > 1); // Should be the multi-referenced shared null. Pillow::ByteArrayHelpers::setFromRawData(ba, rawData, 0, 5); QVERIFY(ba.data_ptr() != oldDataPtr); QVERIFY(ba.data_ptr()->ref == 1); QVERIFY(rawData[5] != '\0'); QCOMPARE(ba, QByteArray("hello")); // Calling out setFromRawData on a string that is already detached should not reallocate the // QByteArray data block, as opposed to QByteArray::setRawData. oldDataPtr = ba.data_ptr(); Pillow::ByteArrayHelpers::setFromRawData(ba, rawData, 6, 5); QVERIFY(ba.data_ptr() == oldDataPtr); QVERIFY(ba.data_ptr()->ref == 1); QVERIFY(rawData[11] != '\0'); QCOMPARE(ba, QByteArray("world")); }