diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-09-11 09:31:24 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-09-11 09:31:24 +0200 |
commit | 50f737b8549fb1b380c753d36be3fafe0ec4a768 (patch) | |
tree | 63dc679d19382bba8e9100d20822d0c502e3dcc7 /tests/storagetest.cpp | |
parent | 2554645a86359ec4cf805c8dee0e347b802776e0 (diff) | |
download | sink-50f737b8549fb1b380c753d36be3fafe0ec4a768.tar.gz sink-50f737b8549fb1b380c753d36be3fafe0ec4a768.zip |
Storage: substring search and findLatest
Diffstat (limited to 'tests/storagetest.cpp')
-rw-r--r-- | tests/storagetest.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp index 7060ef2..8d5ee00 100644 --- a/tests/storagetest.cpp +++ b/tests/storagetest.cpp | |||
@@ -317,6 +317,41 @@ private Q_SLOTS: | |||
317 | QCOMPARE(numValues, 1); | 317 | QCOMPARE(numValues, 1); |
318 | } | 318 | } |
319 | 319 | ||
320 | void testFindSubstringKeys() | ||
321 | { | ||
322 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); | ||
323 | auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); | ||
324 | auto db = transaction.openDatabase("test", nullptr, false); | ||
325 | db.write("sub","value1"); | ||
326 | db.write("subsub","value2"); | ||
327 | db.write("wubsub","value3"); | ||
328 | int numValues = db.scan("sub", [&](const QByteArray &key, const QByteArray &value) -> bool { | ||
329 | return true; | ||
330 | }, nullptr, true); | ||
331 | |||
332 | QCOMPARE(numValues, 2); | ||
333 | } | ||
334 | |||
335 | void testKeySorting() | ||
336 | { | ||
337 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); | ||
338 | auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); | ||
339 | auto db = transaction.openDatabase("test", nullptr, false); | ||
340 | db.write("sub_2","value2"); | ||
341 | db.write("sub_1","value1"); | ||
342 | db.write("sub_3","value3"); | ||
343 | QList<QByteArray> results; | ||
344 | int numValues = db.scan("sub", [&](const QByteArray &key, const QByteArray &value) -> bool { | ||
345 | results << value; | ||
346 | return true; | ||
347 | }, nullptr, true); | ||
348 | |||
349 | QCOMPARE(numValues, 3); | ||
350 | QCOMPARE(results.at(0), QByteArray("value1")); | ||
351 | QCOMPARE(results.at(1), QByteArray("value2")); | ||
352 | QCOMPARE(results.at(2), QByteArray("value3")); | ||
353 | } | ||
354 | |||
320 | //Ensure we don't retrieve a key that is greater than the current key. We only want equal keys. | 355 | //Ensure we don't retrieve a key that is greater than the current key. We only want equal keys. |
321 | void testKeyRange() | 356 | void testKeyRange() |
322 | { | 357 | { |
@@ -330,6 +365,22 @@ private Q_SLOTS: | |||
330 | 365 | ||
331 | QCOMPARE(numValues, 0); | 366 | QCOMPARE(numValues, 0); |
332 | } | 367 | } |
368 | |||
369 | void testFindLatest() | ||
370 | { | ||
371 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); | ||
372 | auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); | ||
373 | auto db = transaction.openDatabase("test", nullptr, false); | ||
374 | db.write("sub1","value1"); | ||
375 | db.write("sub2","value2"); | ||
376 | db.write("wub3","value3"); | ||
377 | QByteArray result; | ||
378 | db.findLatest("sub", [&](const QByteArray &key, const QByteArray &value) { | ||
379 | result = value; | ||
380 | }); | ||
381 | |||
382 | QCOMPARE(result, QByteArray("value2")); | ||
383 | } | ||
333 | }; | 384 | }; |
334 | 385 | ||
335 | QTEST_MAIN(StorageTest) | 386 | QTEST_MAIN(StorageTest) |