summaryrefslogtreecommitdiffstats
path: root/tests/storagetest.cpp
diff options
context:
space:
mode:
authorAaron Seigo <aseigo@kde.org>2014-12-05 09:46:53 +0100
committerAaron Seigo <aseigo@kde.org>2014-12-05 09:46:53 +0100
commit351a66b5fb1c8659bff8ea20d60f5a6d2d3263ad (patch)
tree3ba738fdc01f2b73bc3942ed530db34ef4cc1d6e /tests/storagetest.cpp
parent0c1400c7f0cf2f545a6cd7347314c1158fbfa36f (diff)
downloadsink-351a66b5fb1c8659bff8ea20d60f5a6d2d3263ad.tar.gz
sink-351a66b5fb1c8659bff8ea20d60f5a6d2d3263ad.zip
make read return a bool on success
not happy with this API, but we need to discuss the whole read thing anyways
Diffstat (limited to 'tests/storagetest.cpp')
-rw-r--r--tests/storagetest.cpp23
1 files changed, 12 insertions, 11 deletions
diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp
index 1b105af..2b2805d 100644
--- a/tests/storagetest.cpp
+++ b/tests/storagetest.cpp
@@ -6,7 +6,7 @@
6#include <QString> 6#include <QString>
7#include <QtConcurrent/QtConcurrentRun> 7#include <QtConcurrent/QtConcurrentRun>
8 8
9#include "store/database.h" 9#include "common/storage.h"
10 10
11class StorageTest : public QObject 11class StorageTest : public QObject
12{ 12{
@@ -19,31 +19,32 @@ private:
19 19
20 void populate(int count) 20 void populate(int count)
21 { 21 {
22 Database db(testDataPath, dbName); 22 Storage storage(testDataPath, dbName);
23 for (int i = 0; i < count; i++) { 23 for (int i = 0; i < count; i++) {
24 //This should perhaps become an implementation detail of the db? 24 //This should perhaps become an implementation detail of the db?
25 if (i % 10000 == 0) { 25 if (i % 10000 == 0) {
26 if (i > 0) { 26 if (i > 0) {
27 db.commitTransaction(); 27 storage.commitTransaction();
28 } 28 }
29 db.startTransaction(); 29 storage.startTransaction();
30 } 30 }
31 db.write(keyPrefix + std::to_string(i), keyPrefix + std::to_string(i)); 31 storage.write(keyPrefix + std::to_string(i), keyPrefix + std::to_string(i));
32 } 32 }
33 db.commitTransaction(); 33 storage.commitTransaction();
34 } 34 }
35 35
36 bool verify(Database &db, int i) 36 bool verify(Storage &storage, int i)
37 { 37 {
38 bool error = false; 38 bool success = true;
39 bool keyMatch = true;
39 const auto reference = keyPrefix + std::to_string(i); 40 const auto reference = keyPrefix + std::to_string(i);
40 db.read(keyPrefix + std::to_string(i), [&error, &reference](const std::string &value) { 41 success = storage.read(keyPrefix + std::to_string(i), [&error, &reference](const std::string &value) {
41 if (value != reference) { 42 if (value != reference) {
42 qDebug() << "Mismatch while reading"; 43 qDebug() << "Mismatch while reading";
43 error = true; 44 keyMatch = false;
44 } 45 }
45 }); 46 });
46 return !error; 47 return succes && keyMatch;
47 } 48 }
48 49
49private Q_SLOTS: 50private Q_SLOTS: