From b36ae2d0e0b0ee9865fdc7e628374853d160b55a Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 21 Jan 2015 10:52:02 +0100 Subject: An index implementation. --- tests/CMakeLists.txt | 1 + tests/indextest.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 tests/indextest.cpp (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 183b1bf..7ef4113 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,6 +19,7 @@ manual_tests ( dummyresourcetest domainadaptortest messagequeuetest + indextest ) target_link_libraries(dummyresourcetest akonadi2_resource_dummy) diff --git a/tests/indextest.cpp b/tests/indextest.cpp new file mode 100644 index 0000000..24f90c8 --- /dev/null +++ b/tests/indextest.cpp @@ -0,0 +1,61 @@ +#include + +#include +#include + +#include "clientapi.h" +#include "storage.h" +#include "index.h" + +class IndexTest : public QObject +{ + Q_OBJECT +private Q_SLOTS: + void initTestCase() + { + Akonadi2::Storage store(Akonadi2::Store::storageLocation(), "org.kde.dummy.testindex", Akonadi2::Storage::ReadWrite); + store.removeFromDisk(); + } + + void cleanup() + { + Akonadi2::Storage store(Akonadi2::Store::storageLocation(), "org.kde.dummy.testindex", Akonadi2::Storage::ReadWrite); + store.removeFromDisk(); + } + + void testIndex() + { + Index index(Akonadi2::Store::storageLocation(), "org.kde.dummy.testindex", Akonadi2::Storage::ReadWrite); + index.add("key1", "value1"); + index.add("key1", "value2"); + index.add("key2", "value3"); + + { + QList values; + index.lookup(QByteArray("key1"), [&values](const QByteArray &value) { + values << value; + }, + [](const Index::Error &error){ qWarning() << "Error: "; }); + QCOMPARE(values.size(), 2); + } + { + QList values; + index.lookup(QByteArray("key2"), [&values](const QByteArray &value) { + values << value; + }, + [](const Index::Error &error){ qWarning() << "Error: "; }); + QCOMPARE(values.size(), 1); + } + { + QList values; + index.lookup(QByteArray("key3"), [&values](const QByteArray &value) { + values << value; + }, + [](const Index::Error &error){ qWarning() << "Error: "; }); + QCOMPARE(values.size(), 0); + } + } +}; + +QTEST_MAIN(IndexTest) +#include "indextest.moc" -- cgit v1.2.3