diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/indextest.cpp | 61 |
2 files changed, 62 insertions, 0 deletions
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 ( | |||
19 | dummyresourcetest | 19 | dummyresourcetest |
20 | domainadaptortest | 20 | domainadaptortest |
21 | messagequeuetest | 21 | messagequeuetest |
22 | indextest | ||
22 | ) | 23 | ) |
23 | 24 | ||
24 | target_link_libraries(dummyresourcetest akonadi2_resource_dummy) | 25 | 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 @@ | |||
1 | #include <QtTest> | ||
2 | |||
3 | #include <QString> | ||
4 | #include <QQueue> | ||
5 | |||
6 | #include "clientapi.h" | ||
7 | #include "storage.h" | ||
8 | #include "index.h" | ||
9 | |||
10 | class IndexTest : public QObject | ||
11 | { | ||
12 | Q_OBJECT | ||
13 | private Q_SLOTS: | ||
14 | void initTestCase() | ||
15 | { | ||
16 | Akonadi2::Storage store(Akonadi2::Store::storageLocation(), "org.kde.dummy.testindex", Akonadi2::Storage::ReadWrite); | ||
17 | store.removeFromDisk(); | ||
18 | } | ||
19 | |||
20 | void cleanup() | ||
21 | { | ||
22 | Akonadi2::Storage store(Akonadi2::Store::storageLocation(), "org.kde.dummy.testindex", Akonadi2::Storage::ReadWrite); | ||
23 | store.removeFromDisk(); | ||
24 | } | ||
25 | |||
26 | void testIndex() | ||
27 | { | ||
28 | Index index(Akonadi2::Store::storageLocation(), "org.kde.dummy.testindex", Akonadi2::Storage::ReadWrite); | ||
29 | index.add("key1", "value1"); | ||
30 | index.add("key1", "value2"); | ||
31 | index.add("key2", "value3"); | ||
32 | |||
33 | { | ||
34 | QList<QByteArray> values; | ||
35 | index.lookup(QByteArray("key1"), [&values](const QByteArray &value) { | ||
36 | values << value; | ||
37 | }, | ||
38 | [](const Index::Error &error){ qWarning() << "Error: "; }); | ||
39 | QCOMPARE(values.size(), 2); | ||
40 | } | ||
41 | { | ||
42 | QList<QByteArray> values; | ||
43 | index.lookup(QByteArray("key2"), [&values](const QByteArray &value) { | ||
44 | values << value; | ||
45 | }, | ||
46 | [](const Index::Error &error){ qWarning() << "Error: "; }); | ||
47 | QCOMPARE(values.size(), 1); | ||
48 | } | ||
49 | { | ||
50 | QList<QByteArray> values; | ||
51 | index.lookup(QByteArray("key3"), [&values](const QByteArray &value) { | ||
52 | values << value; | ||
53 | }, | ||
54 | [](const Index::Error &error){ qWarning() << "Error: "; }); | ||
55 | QCOMPARE(values.size(), 0); | ||
56 | } | ||
57 | } | ||
58 | }; | ||
59 | |||
60 | QTEST_MAIN(IndexTest) | ||
61 | #include "indextest.moc" | ||