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 66 67 68 69 70 71 72 73 74
|
/*
This file is part of the KDE Baloo project.
SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "positiondb.h"
#include "positioninfo.h"
#include "vectorpositioninfoiterator.h"
#include "singledbtest.h"
using namespace Baloo;
class PositionDBTest : public SingleDBTest
{
Q_OBJECT
private Q_SLOTS:
void test() {
PositionDB db(PositionDB::create(m_txn), m_txn);
QByteArray word("fire");
PositionInfo pos1;
pos1.docId = 1;
pos1.positions = QVector<uint>() << 1 << 5 << 6;
PositionInfo pos2;
pos2.docId = 5;
pos2.positions = QVector<uint>() << 41 << 96 << 116;
QVector<PositionInfo> list = {pos1, pos2};
db.put(word, list);
QVector<PositionInfo> res = db.get(word);
QCOMPARE(res, list);
}
void testIter() {
PositionDB db(PositionDB::create(m_txn), m_txn);
QByteArray word("fire");
PositionInfo pos1;
pos1.docId = 1;
pos1.positions = QVector<uint>() << 1 << 5 << 6;
PositionInfo pos2;
pos2.docId = 5;
pos2.positions = QVector<uint>() << 41 << 96 << 116;
QVector<PositionInfo> list = {pos1, pos2};
db.put(word, list);
QScopedPointer<VectorPositionInfoIterator> it{db.iter(word)};
QCOMPARE(it->docId(), static_cast<quint64>(0));
QVERIFY(it->positions().isEmpty());
QCOMPARE(it->next(), static_cast<quint64>(1));
QCOMPARE(it->docId(), static_cast<quint64>(1));
QCOMPARE(it->positions(), pos1.positions);
QCOMPARE(it->next(), static_cast<quint64>(5));
QCOMPARE(it->docId(), static_cast<quint64>(5));
QCOMPARE(it->positions(), pos2.positions);
QCOMPARE(it->next(), static_cast<quint64>(0));
QCOMPARE(it->docId(), static_cast<quint64>(0));
QVERIFY(it->positions().isEmpty());
}
};
QTEST_MAIN(PositionDBTest)
#include "positiondbtest.moc"
|