summaryrefslogtreecommitdiffstats
path: root/tests/indextest.cpp
blob: 24f90c843d0d5db88cfed377c6ff20c1fbc270ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <QtTest>

#include <QString>
#include <QQueue>

#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<QByteArray> values;
            index.lookup(QByteArray("key1"), [&values](const QByteArray &value) {
                values << value;
            },
            [](const Index::Error &error){ qWarning() << "Error: "; });
            QCOMPARE(values.size(), 2);
        }
        {
            QList<QByteArray> values;
            index.lookup(QByteArray("key2"), [&values](const QByteArray &value) {
                values << value;
            },
            [](const Index::Error &error){ qWarning() << "Error: "; });
            QCOMPARE(values.size(), 1);
        }
        {
            QList<QByteArray> 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"