本文整理汇总了C++中QBuffer::reset方法的典型用法代码示例。如果您正苦于以下问题:C++ QBuffer::reset方法的具体用法?C++ QBuffer::reset怎么用?C++ QBuffer::reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QBuffer
的用法示例。
在下文中一共展示了QBuffer::reset方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testCreateFileKey
void TestKeys::testCreateFileKey()
{
const QString dbName("testCreateFileKey database");
QBuffer keyBuffer;
keyBuffer.open(QBuffer::ReadWrite);
FileKey::create(&keyBuffer);
keyBuffer.reset();
FileKey fileKey;
QVERIFY(fileKey.load(&keyBuffer));
CompositeKey compositeKey;
compositeKey.addKey(fileKey);
Database* dbOrg = new Database();
dbOrg->setKey(compositeKey);
dbOrg->metadata()->setName(dbName);
QBuffer dbBuffer;
dbBuffer.open(QBuffer::ReadWrite);
KeePass2Writer writer;
writer.writeDatabase(&dbBuffer, dbOrg);
dbBuffer.reset();
delete dbOrg;
KeePass2Reader reader;
Database* dbRead = reader.readDatabase(&dbBuffer, compositeKey);
QVERIFY(dbRead);
QVERIFY(!reader.hasError());
QCOMPARE(dbRead->metadata()->name(), dbName);
delete dbRead;
}
示例2: cipher
void TestSymmetricCipher::testAes256CbcEncryption()
{
// http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
QByteArray key = QByteArray::fromHex("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4");
QByteArray iv = QByteArray::fromHex("000102030405060708090a0b0c0d0e0f");
QByteArray plainText = QByteArray::fromHex("6bc1bee22e409f96e93d7e117393172a");
plainText.append(QByteArray::fromHex("ae2d8a571e03ac9c9eb76fac45af8e51"));
QByteArray cipherText = QByteArray::fromHex("f58c4c04d6e5f1ba779eabfb5f7bfbd6");
cipherText.append(QByteArray::fromHex("9cfc4e967edb808d679f777bc6702c7d"));
bool ok;
SymmetricCipher cipher(SymmetricCipher::Aes256, SymmetricCipher::Cbc, SymmetricCipher::Encrypt);
QVERIFY(cipher.init(key, iv));
QCOMPARE(cipher.blockSize(), 16);
QCOMPARE(cipher.process(plainText, &ok),
cipherText);
QVERIFY(ok);
QBuffer buffer;
SymmetricCipherStream stream(&buffer, SymmetricCipher::Aes256, SymmetricCipher::Cbc,
SymmetricCipher::Encrypt);
QVERIFY(stream.init(key, iv));
buffer.open(QIODevice::WriteOnly);
QVERIFY(stream.open(QIODevice::WriteOnly));
QVERIFY(stream.reset());
buffer.reset();
buffer.buffer().clear();
QCOMPARE(stream.write(plainText.left(16)), qint64(16));
QCOMPARE(buffer.data(), cipherText.left(16));
QVERIFY(stream.reset());
// make sure padding is written
QCOMPARE(buffer.data().size(), 32);
buffer.reset();
buffer.buffer().clear();
QCOMPARE(stream.write(plainText.left(10)), qint64(10));
QVERIFY(buffer.data().isEmpty());
QVERIFY(stream.reset());
buffer.reset();
buffer.buffer().clear();
QCOMPARE(stream.write(plainText.left(10)), qint64(10));
stream.close();
QCOMPARE(buffer.data().size(), 16);
}
示例3: readPointerAtPositionWriteRead
void tst_QRingBuffer::readPointerAtPositionWriteRead()
{
//create some data
QBuffer inData;
inData.open(QIODevice::ReadWrite);
inData.putChar(0x42);
inData.putChar(0x23);
inData.write("Qt rocks!");
for (int i = 0; i < 5000; i++)
inData.write(QString("Number %1").arg(i).toUtf8());
inData.reset();
QVERIFY(inData.size() > 0);
//put the inData in the QRingBuffer
QRingBuffer ringBuffer;
qint64 remaining = inData.size();
while (remaining > 0) {
// write in chunks of 50 bytes
// this ensures there will be multiple QByteArrays inside the QRingBuffer
// since QRingBuffer is then only using individual arrays of around 4000 bytes
qint64 thisWrite = qMin(remaining, qint64(50));
char *pos = ringBuffer.reserve(thisWrite);
inData.read(pos, thisWrite);
remaining -= thisWrite;
}
// was data put into it?
QVERIFY(ringBuffer.size() > 0);
QCOMPARE(qint64(ringBuffer.size()), inData.size());
//read from the QRingBuffer in loop, put back into another QBuffer
QBuffer outData;
outData.open(QIODevice::ReadWrite);
remaining = ringBuffer.size();
while (remaining > 0) {
qint64 thisRead;
// always try to read as much as possible
const char *buf = ringBuffer.readPointerAtPosition(ringBuffer.size() - remaining, thisRead);
outData.write(buf, thisRead);
remaining -= thisRead;
}
outData.reset();
QVERIFY(outData.size() > 0);
// was the data read from the QRingBuffer the same as the one written into it?
QCOMPARE(outData.size(), inData.size());
QVERIFY(outData.buffer().startsWith(inData.buffer()));
}
示例4: testPadding
void TestSymmetricCipher::testPadding()
{
QByteArray key = QByteArray::fromHex("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4");
QByteArray iv = QByteArray::fromHex("000102030405060708090a0b0c0d0e0f");
QByteArray plainText = QByteArray::fromHex("6bc1bee22e409f96e93d");
QBuffer buffer;
buffer.open(QIODevice::ReadWrite);
SymmetricCipherStream streamEnc(&buffer, SymmetricCipher::Aes256, SymmetricCipher::Cbc,
SymmetricCipher::Encrypt);
QVERIFY(streamEnc.init(key, iv));
streamEnc.open(QIODevice::WriteOnly);
streamEnc.write(plainText);
streamEnc.close();
buffer.reset();
// make sure padding is written
QCOMPARE(buffer.buffer().size(), 16);
SymmetricCipherStream streamDec(&buffer, SymmetricCipher::Aes256, SymmetricCipher::Cbc,
SymmetricCipher::Decrypt);
QVERIFY(streamDec.init(key, iv));
streamDec.open(QIODevice::ReadOnly);
QByteArray decrypted = streamDec.readAll();
QCOMPARE(decrypted, plainText);
}
示例5: jpegDecodingQtWebkitStyle
void tst_jpeg::jpegDecodingQtWebkitStyle()
{
// QtWebkit currently calls size() to get the image size for layouting purposes.
// Then when it is in the viewport (we assume that here) it actually gets decoded.
QString testFile = QFINDTESTDATA("n900.jpeg");
QVERIFY2(!testFile.isEmpty(), "cannot find test file n900.jpeg!");
QFile inputJpeg(testFile);
QVERIFY(inputJpeg.exists());
inputJpeg.open(QIODevice::ReadOnly);
QByteArray imageData = inputJpeg.readAll();
QBuffer buffer;
buffer.setData(imageData);
buffer.open(QBuffer::ReadOnly);
QCOMPARE(buffer.size(), qint64(19016));
QBENCHMARK{
for (int i = 0; i < 50; i++) {
QImageReader reader(&buffer, "jpeg");
QSize size = reader.size();
QVERIFY(!size.isNull());
QByteArray format = reader.format();
QVERIFY(!format.isEmpty());
QImage img = reader.read();
QVERIFY(!img.isNull());
buffer.reset();
}
}
}
示例6: t
QWidget * FLManagerModules::createUI( const QString & n, QObject * connector,
QWidget * parent, const char *name ) {
QBuffer b;
b.open( IO_ReadWrite );
QTextStream t( &b );
t.setEncoding( QTextStream::Latin1 );
t << contentCached( n );
b.reset();
QWidget * w = QWidgetFactory::create( &b, connector, parent, name );
return w;
}
示例7: putch
void tst_QIODevice::putch()
{
#ifdef QT3_SUPPORT
QBuffer buffer;
buffer.open(QBuffer::ReadWrite);
buffer.putch(0xff);
buffer.putch(0x7f);
buffer.putch(0x80);
buffer.putch(0x00);
buffer.reset();
QCOMPARE(buffer.getch(), 0xff);
QCOMPARE(buffer.getch(), 0x7f);
QCOMPARE(buffer.getch(), 0x80);
QCOMPARE(buffer.getch(), 0x00);
#endif
}
示例8: getch
void tst_QIODevice::getch()
{
#ifdef QT3_SUPPORT
QBuffer buffer;
buffer.open(QBuffer::ReadWrite);
buffer.write("\xff\x7f\x80\x00", 4);
buffer.reset();
QCOMPARE(buffer.getch(), 0xff);
QCOMPARE(buffer.getch(), 0x7f);
QCOMPARE(buffer.getch(), 0x80);
QCOMPARE(buffer.getch(), 0x00);
buffer.ungetch(0x00);
buffer.ungetch(0x80);
buffer.ungetch(0x7f);
buffer.ungetch(0xff);
QCOMPARE(buffer.getch(), 0xff);
QCOMPARE(buffer.getch(), 0x7f);
QCOMPARE(buffer.getch(), 0x80);
QCOMPARE(buffer.getch(), 0x00);
#endif
}
示例9: testWriteRead
void TestHashedBlockStream::testWriteRead()
{
QByteArray data = QByteArray::fromHex("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4");
QBuffer buffer;
buffer.open(QIODevice::ReadWrite);
HashedBlockStream writer(&buffer, 16);
writer.open(QIODevice::WriteOnly);
HashedBlockStream reader(&buffer);
reader.open(QIODevice::ReadOnly);
writer.write(data.left(16));
QVERIFY(writer.reset());
buffer.reset();
QCOMPARE(reader.read(17), data.left(16));
QVERIFY(reader.reset());
buffer.reset();
buffer.buffer().clear();
writer.write(data.left(10));
QVERIFY(writer.reset());
buffer.reset();
QCOMPARE(reader.read(5), data.left(5));
QCOMPARE(reader.read(5), data.mid(5, 5));
QCOMPARE(reader.read(1).size(), 0);
QVERIFY(reader.reset());
buffer.reset();
buffer.buffer().clear();
writer.write(data.left(20));
QVERIFY(writer.reset());
buffer.reset();
QCOMPARE(reader.read(20), data.left(20));
QCOMPARE(reader.read(1).size(), 0);
QVERIFY(reader.reset());
buffer.reset();
buffer.buffer().clear();
}
示例10: transformToString
bool XSLTProcessor::transformToString(Node* sourceNode, String&, String& resultString, String&)
{
bool success = false;
RefPtr<XSLStyleSheet> stylesheet = m_stylesheet;
if (!stylesheet && m_stylesheetRootNode) {
Node* node = m_stylesheetRootNode.get();
stylesheet = XSLStyleSheet::createForXSLTProcessor(node->parent() ? node->parent() : node,
node->document()->url().string(),
node->document()->url()); // FIXME: Should we use baseURL here?
// According to Mozilla documentation, the node must be a Document node, an xsl:stylesheet or xsl:transform element.
// But we just use text content regardless of node type.
stylesheet->parseString(createMarkup(node));
}
if (!stylesheet || stylesheet->sheetString().isEmpty())
return success;
RefPtr<Document> ownerDocument = sourceNode->document();
bool sourceIsDocument = (sourceNode == ownerDocument.get());
QXmlQuery query(QXmlQuery::XSLT20);
XSLTMessageHandler messageHandler(ownerDocument.get());
XSLTUriResolver uriResolver(ownerDocument.get());
query.setMessageHandler(&messageHandler);
XSLTProcessor::ParameterMap::iterator end = m_parameters.end();
for (XSLTProcessor::ParameterMap::iterator it = m_parameters.begin(); it != end; ++it)
query.bindVariable(QString(it->first), QXmlItem(QVariant(it->second)));
QString source;
if (sourceIsDocument && ownerDocument->transformSource())
source = ownerDocument->transformSource()->platformSource();
if (!sourceIsDocument || source.isEmpty())
source = createMarkup(sourceNode);
QBuffer inputBuffer;
QBuffer styleSheetBuffer;
QBuffer outputBuffer;
inputBuffer.setData(source.toUtf8());
styleSheetBuffer.setData(QString(stylesheet->sheetString()).toUtf8());
inputBuffer.open(QIODevice::ReadOnly);
styleSheetBuffer.open(QIODevice::ReadOnly);
outputBuffer.open(QIODevice::ReadWrite);
query.setFocus(&inputBuffer);
query.setQuery(&styleSheetBuffer, QUrl(stylesheet->href()));
query.setUriResolver(&uriResolver);
success = query.evaluateTo(&outputBuffer);
outputBuffer.reset();
resultString = QString::fromUtf8(outputBuffer.readAll()).trimmed();
if (m_stylesheet) {
m_stylesheet->clearDocuments();
m_stylesheet = 0;
}
return success;
}
示例11: callCalback
void HttpTaskRunnable::callCalback()
{
Server::CallBackType& callback = m_errorCallback ;
if (m_isSuccessful &&
!m_calbacks[m_request->method()].isEmpty())
{
QString path = m_request->url().path();
for (auto iter = m_calbacks[m_request->method()].begin();
iter != m_calbacks[m_request->method()].end();
++iter)
{
if (path == iter.key())
{
callback = iter.value();
break;
}
}
}
QBuffer outBuff;
outBuff.open(QIODevice::ReadWrite);
QTextStream outStream(&outBuff);
Response response(outStream);
bool isExcept = false;
try
{
callback(*m_request.get(), response);
} catch (const std::exception& exc)
{
qDebug() << "Caught std::exception:" << exc.what();
outBuff.reset();
outStream.seek(0);
isExcept = true;
printStdException(*m_request.get(), response, exc);
} catch (...)
{
isExcept = true;
printUnknownException(*m_request.get(), response);
qDebug() << "Caught unknown exception";
}
outStream.flush();
outBuff.seek(0);
QByteArray outData;
if (response.type() == Response::Text)
{
outData = outBuff.readAll();
}
else
{
outData = isExcept ? QByteArray() : response.outBinaryDat();
}
{
QTextStream stream(m_tcpSocket.get());
stream << "HTTP/1.1 " << response.status() << " OK" << "\r\n";
stream<<response.header();
if (outData.size())
{
stream << "Content-Length: " << outData.size() << "\r\n";
}
stream << "\r\n";
}
if (outData.size())
{
m_tcpSocket->write(outData);
}
m_tcpSocket->waitForBytesWritten();
}