summaryrefslogtreecommitdiffstats
path: root/tests/indextest.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-01-21 10:52:02 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-01-21 10:52:02 +0100
commitb36ae2d0e0b0ee9865fdc7e628374853d160b55a (patch)
treede8328191a63b54f748648611a67c4e24be265a1 /tests/indextest.cpp
parentcf91df49d0eadfdc7dec23fd82da9e7b9a964ea6 (diff)
downloadsink-b36ae2d0e0b0ee9865fdc7e628374853d160b55a.tar.gz
sink-b36ae2d0e0b0ee9865fdc7e628374853d160b55a.zip
An index implementation.
Diffstat (limited to 'tests/indextest.cpp')
-rw-r--r--tests/indextest.cpp61
1 files changed, 61 insertions, 0 deletions
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
10class IndexTest : public QObject
11{
12 Q_OBJECT
13private 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
60QTEST_MAIN(IndexTest)
61#include "indextest.moc"