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 "store.h"
#include "storage.h"
#include "index.h"
/**
* Test of the index implementation
*/
class IndexTest : public QObject
{
Q_OBJECT
private slots:
void initTestCase()
{
Sink::Storage::DataStore store("./testindex", "sink.dummy.testindex", Sink::Storage::DataStore::ReadWrite);
store.removeFromDisk();
}
void cleanup()
{
Sink::Storage::DataStore store("./testindex", "sink.dummy.testindex", Sink::Storage::DataStore::ReadWrite);
store.removeFromDisk();
}
void testIndex()
{
Index index("./testindex", "sink.dummy.testindex", Sink::Storage::DataStore::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);
}
{
QList<QByteArray> values;
index.lookup(QByteArray("key"), [&values](const QByteArray &value) { values << value; }, [](const Index::Error &error) { qWarning() << "Error: "; }, true);
QCOMPARE(values.size(), 3);
}
}
};
QTEST_MAIN(IndexTest)
#include "indextest.moc"
|