summaryrefslogtreecommitdiffstats
path: root/tests/storagetest.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2014-12-10 21:54:04 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2014-12-10 21:54:04 +0100
commit95801103c1fc773b074eea1b2d03820099ac09a6 (patch)
treeb55445cddc451b68ff171fceb729e4cc602b2531 /tests/storagetest.cpp
parent4911df72dbc202dfcc4c64bb0ba311d7513707ae (diff)
downloadsink-95801103c1fc773b074eea1b2d03820099ac09a6.tar.gz
sink-95801103c1fc773b074eea1b2d03820099ac09a6.zip
Storage: implemented scan
This can replace all our read calls. Note that we need a different API for databases where the value needs to be loaded first, so we can do a key scan before loading values. With this we can do key + value scans in one though.
Diffstat (limited to 'tests/storagetest.cpp')
-rw-r--r--tests/storagetest.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp
index 1974355..b3313c0 100644
--- a/tests/storagetest.cpp
+++ b/tests/storagetest.cpp
@@ -82,6 +82,44 @@ private Q_SLOTS:
82 storage.removeFromDisk(); 82 storage.removeFromDisk();
83 } 83 }
84 84
85 void testScan()
86 {
87 const int count = 100;
88 populate(count);
89
90 //ensure we can scan for values
91 {
92 int hit = 0;
93 Storage store(testDataPath, dbName);
94 store.scan("", [&](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool {
95 if (std::string(static_cast<char*>(keyValue), keySize) == "key50") {
96 hit++;
97 }
98 return true;
99 });
100 QCOMPARE(hit, 1);
101 }
102
103 //ensure we can read a single value
104 {
105 int hit = 0;
106 bool foundInvalidValue = false;
107 Storage store(testDataPath, dbName);
108 store.scan("key50", [&](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool {
109 if (std::string(static_cast<char*>(keyValue), keySize) != "key50") {
110 foundInvalidValue = true;
111 }
112 hit++;
113 return true;
114 });
115 QVERIFY(!foundInvalidValue);
116 QCOMPARE(hit, 1);
117 }
118
119 Storage storage(testDataPath, dbName);
120 storage.removeFromDisk();
121 }
122
85 void testConcurrentRead() 123 void testConcurrentRead()
86 { 124 {
87 const int count = 10000; 125 const int count = 10000;