diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-08-22 11:25:26 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-08-22 11:25:26 +0200 |
commit | 6746247a49f09287ae4924c5c3df791f9bf61cbc (patch) | |
tree | b9df15f1e6413a8995704cf9f0c5f425c9bb9558 /tests/storagetest.cpp | |
parent | fc3a5df884b25d5e624027b1fb017f42986980b2 (diff) | |
download | sink-6746247a49f09287ae4924c5c3df791f9bf61cbc.tar.gz sink-6746247a49f09287ae4924c5c3df791f9bf61cbc.zip |
Use named databases in storage.
This will allow us to create indexes in the same store.
Diffstat (limited to 'tests/storagetest.cpp')
-rw-r--r-- | tests/storagetest.cpp | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp index 55ec888..fe80bb7 100644 --- a/tests/storagetest.cpp +++ b/tests/storagetest.cpp | |||
@@ -211,6 +211,120 @@ private Q_SLOTS: | |||
211 | storage2.removeFromDisk(); | 211 | storage2.removeFromDisk(); |
212 | } | 212 | } |
213 | } | 213 | } |
214 | |||
215 | void testNoDuplicates() | ||
216 | { | ||
217 | bool gotResult = false; | ||
218 | bool gotError = false; | ||
219 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite, false); | ||
220 | auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); | ||
221 | auto db = transaction.openDatabase(); | ||
222 | db.write("key","value"); | ||
223 | db.write("key","value"); | ||
224 | |||
225 | int numValues = db.scan("", [&](const QByteArray &key, const QByteArray &value) -> bool { | ||
226 | gotResult = true; | ||
227 | return true; | ||
228 | }, | ||
229 | [&](const Akonadi2::Storage::Error &error) { | ||
230 | qDebug() << error.message; | ||
231 | gotError = true; | ||
232 | }); | ||
233 | |||
234 | QCOMPARE(numValues, 1); | ||
235 | QVERIFY(!gotError); | ||
236 | } | ||
237 | |||
238 | void testDuplicates() | ||
239 | { | ||
240 | bool gotResult = false; | ||
241 | bool gotError = false; | ||
242 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite, true); | ||
243 | auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); | ||
244 | auto db = transaction.openDatabase(); | ||
245 | db.write("key","value1"); | ||
246 | db.write("key","value2"); | ||
247 | int numValues = db.scan("key", [&](const QByteArray &key, const QByteArray &value) -> bool { | ||
248 | gotResult = true; | ||
249 | return true; | ||
250 | }, | ||
251 | [&](const Akonadi2::Storage::Error &error) { | ||
252 | qDebug() << error.message; | ||
253 | gotError = true; | ||
254 | }); | ||
255 | |||
256 | QCOMPARE(numValues, 2); | ||
257 | QVERIFY(!gotError); | ||
258 | } | ||
259 | |||
260 | void testNonexitingNamedDb() | ||
261 | { | ||
262 | bool gotResult = false; | ||
263 | bool gotError = false; | ||
264 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadOnly); | ||
265 | int numValues = store.createTransaction(Akonadi2::Storage::ReadOnly).openDatabase("test").scan("", [&](const QByteArray &key, const QByteArray &value) -> bool { | ||
266 | gotResult = true; | ||
267 | return false; | ||
268 | }, | ||
269 | [&](const Akonadi2::Storage::Error &error) { | ||
270 | qDebug() << error.message; | ||
271 | gotError = true; | ||
272 | }); | ||
273 | QCOMPARE(numValues, 0); | ||
274 | QVERIFY(!gotResult); | ||
275 | QVERIFY(!gotError); | ||
276 | } | ||
277 | |||
278 | void testWriteToNamedDb() | ||
279 | { | ||
280 | bool gotError = false; | ||
281 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); | ||
282 | store.createTransaction(Akonadi2::Storage::ReadWrite).openDatabase("test").write("key1", "value1", [&](const Akonadi2::Storage::Error &error) { | ||
283 | qDebug() << error.message; | ||
284 | gotError = true; | ||
285 | }); | ||
286 | QVERIFY(!gotError); | ||
287 | } | ||
288 | |||
289 | void testWriteDuplicatesToNamedDb() | ||
290 | { | ||
291 | bool gotError = false; | ||
292 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite, true); | ||
293 | store.createTransaction(Akonadi2::Storage::ReadWrite).openDatabase("test").write("key1", "value1", [&](const Akonadi2::Storage::Error &error) { | ||
294 | qDebug() << error.message; | ||
295 | gotError = true; | ||
296 | }); | ||
297 | QVERIFY(!gotError); | ||
298 | } | ||
299 | |||
300 | //By default we want only exact matches | ||
301 | void testSubstringKeys() | ||
302 | { | ||
303 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite, true); | ||
304 | auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); | ||
305 | auto db = transaction.openDatabase(); | ||
306 | db.write("sub","value1"); | ||
307 | db.write("subsub","value2"); | ||
308 | int numValues = db.scan("sub", [&](const QByteArray &key, const QByteArray &value) -> bool { | ||
309 | return true; | ||
310 | }); | ||
311 | |||
312 | QCOMPARE(numValues, 1); | ||
313 | } | ||
314 | |||
315 | //Ensure we don't retrieve a key that is greater than the current key. We only want equal keys. | ||
316 | void testKeyRange() | ||
317 | { | ||
318 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite, true); | ||
319 | auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); | ||
320 | auto db = transaction.openDatabase(); | ||
321 | db.write("sub1","value1"); | ||
322 | int numValues = db.scan("sub", [&](const QByteArray &key, const QByteArray &value) -> bool { | ||
323 | return true; | ||
324 | }); | ||
325 | |||
326 | QCOMPARE(numValues, 0); | ||
327 | } | ||
214 | }; | 328 | }; |
215 | 329 | ||
216 | QTEST_MAIN(StorageTest) | 330 | QTEST_MAIN(StorageTest) |