From 42f32ea5865c95028c577000e15e8a8631d16e74 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 30 Mar 2015 23:38:45 +0200 Subject: Storage: API cleanup/use QByteArray instead of std::string --- tests/hawd/dataset.cpp | 4 ++-- tests/storagebenchmark.cpp | 10 +++++----- tests/storagetest.cpp | 20 +++++++++++--------- 3 files changed, 18 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/tests/hawd/dataset.cpp b/tests/hawd/dataset.cpp index e1f9700..9f1d307 100644 --- a/tests/hawd/dataset.cpp +++ b/tests/hawd/dataset.cpp @@ -253,7 +253,7 @@ void Dataset::eachRow(const std::function &resultHandler) } Row row(*this); - m_storage.scan(nullptr, 0, + m_storage.scan("", [&](void *key, int keySize, void *data, int dataSize) -> bool { if (keySize != sizeof(qint64)) { return true; @@ -277,7 +277,7 @@ Dataset::Row Dataset::row(qint64 key) } Row row(*this, key); - m_storage.scan((const char *)&key, sizeof(qint64), + m_storage.scan(QByteArray::fromRawData((const char *)&key, sizeof(qint64)), [&row](void *keyPtr, int keyLength, void *valuePtr, int valueSize) -> bool { QByteArray array((const char*)valuePtr, valueSize); row.fromBinary(array); diff --git a/tests/storagebenchmark.cpp b/tests/storagebenchmark.cpp index 9cf9a71..0233466 100644 --- a/tests/storagebenchmark.cpp +++ b/tests/storagebenchmark.cpp @@ -15,7 +15,7 @@ using namespace Calendar; using namespace flatbuffers; -static std::string createEvent() +static QByteArray createEvent() { static const size_t attachmentSize = 1024*2; // 2KB static uint8_t rawData[attachmentSize]; @@ -33,7 +33,7 @@ static std::string createEvent() memcpy((void*)Calendar::GetEvent(fbb.GetBufferPointer())->attachment()->Data(), rawData, attachmentSize); } - return std::string(reinterpret_cast(fbb.GetBufferPointer()), fbb.GetSize()); + return QByteArray::fromRawData(reinterpret_cast(fbb.GetBufferPointer()), fbb.GetSize()); } // static void readEvent(const std::string &data) @@ -103,9 +103,9 @@ private Q_SLOTS: store->startTransaction(); } - store->write(keyPrefix + std::to_string(i), event); + store->write(keyPrefix + QByteArray::number(i), event); } else { - myfile << event; + myfile << event.toStdString(); } } @@ -122,7 +122,7 @@ private Q_SLOTS: { for (int i = 0; i < count; i++) { if (store) { - store->read(keyPrefix + std::to_string(i), [](std::string value) -> bool { return true; }); + store->scan(keyPrefix + QByteArray::number(i), [](const QByteArray &value) -> bool { return true; }); } } } diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp index 5b4a0ba..e339c87 100644 --- a/tests/storagetest.cpp +++ b/tests/storagetest.cpp @@ -28,7 +28,7 @@ private: } storage.startTransaction(); } - storage.write(keyPrefix + std::to_string(i), keyPrefix + std::to_string(i)); + storage.write(keyPrefix + QByteArray::number(i), keyPrefix + QByteArray::number(i)); } storage.commitTransaction(); } @@ -37,9 +37,9 @@ private: { bool success = true; bool keyMatch = true; - const auto reference = keyPrefix + std::to_string(i); - storage.read(keyPrefix + std::to_string(i), - [&keyMatch, &reference](const std::string &value) -> bool { + const auto reference = keyPrefix + QByteArray::number(i); + storage.scan(keyPrefix + QByteArray::number(i), + [&keyMatch, &reference](const QByteArray &value) -> bool { if (value != reference) { qDebug() << "Mismatch while reading"; keyMatch = false; @@ -47,7 +47,7 @@ private: return keyMatch; }, [&success](const Akonadi2::Storage::Error &error) { - qDebug() << QString::fromStdString(error.message); + qDebug() << error.message; success = false; } ); @@ -133,7 +133,7 @@ private Q_SLOTS: populate(3); Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); store.scan("key1", [&](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool { - store.remove(keyValue, keySize, [](const Akonadi2::Storage::Error &) { + store.remove(QByteArray::fromRawData(static_cast(keyValue), keySize), [](const Akonadi2::Storage::Error &) { QVERIFY(false); }); return false; @@ -144,14 +144,16 @@ private Q_SLOTS: { bool gotResult = false; bool gotError = false; - Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadOnly); - store.scan(0, 0, [&](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool { + Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); + int numValues = store.scan("", [&](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool { gotResult = true; return false; }, - [&](Akonadi2::Storage::Error) { + [&](const Akonadi2::Storage::Error &error) { + qDebug() << error.message; gotError = true; }); + QCOMPARE(numValues, 0); QVERIFY(!gotResult); QVERIFY(!gotError); } -- cgit v1.2.3