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
62
63
64
65
|
#include <QtTest>
#include <QString>
#include <QQueue>
#include "clientapi.h"
#include "storage.h"
#include "index.h"
/**
* Test of the index implementation
*/
class IndexTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase()
{
Sink::Storage store("./testindex", "org.kde.dummy.testindex", Sink::Storage::ReadWrite);
store.removeFromDisk();
}
void cleanup()
{
Sink::Storage store("./testindex", "org.kde.dummy.testindex", Sink::Storage::ReadWrite);
store.removeFromDisk();
}
void testIndex()
{
Index index("./testindex", "org.kde.dummy.testindex", Sink::Storage::ReadWrite);
//The first key is specifically a substring of the second key
index.add("key", "value1");
index.add("keyFoo", "value2");
index.add("keyFoo", "value3");
{
QList<QByteArray> values;
index.lookup(QByteArray("key"), [&values](const QByteArray &value) {
values << value;
},
[](const Index::Error &error){ qWarning() << "Error: "; });
QCOMPARE(values.size(), 1);
}
{
QList<QByteArray> values;
index.lookup(QByteArray("keyFoo"), [&values](const QByteArray &value) {
values << value;
},
[](const Index::Error &error){ qWarning() << "Error: "; });
QCOMPARE(values.size(), 2);
}
{
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"
|