File indexing completed on 2024-05-19 07:40:32
0001 /* 0002 This file is part of the KDE Baloo project. 0003 SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.1-or-later 0006 */ 0007 0008 #include "positiondb.h" 0009 #include "positioninfo.h" 0010 #include "vectorpositioninfoiterator.h" 0011 #include "singledbtest.h" 0012 0013 using namespace Baloo; 0014 0015 class PositionDBTest : public SingleDBTest 0016 { 0017 Q_OBJECT 0018 private Q_SLOTS: 0019 void test() { 0020 PositionDB db(PositionDB::create(m_txn), m_txn); 0021 0022 QByteArray word("fire"); 0023 PositionInfo pos1; 0024 pos1.docId = 1; 0025 pos1.positions = QVector<uint>() << 1 << 5 << 6; 0026 0027 PositionInfo pos2; 0028 pos2.docId = 5; 0029 pos2.positions = QVector<uint>() << 41 << 96 << 116; 0030 0031 QVector<PositionInfo> list = {pos1, pos2}; 0032 0033 db.put(word, list); 0034 QVector<PositionInfo> res = db.get(word); 0035 QCOMPARE(res, list); 0036 } 0037 0038 void testIter() { 0039 PositionDB db(PositionDB::create(m_txn), m_txn); 0040 0041 QByteArray word("fire"); 0042 PositionInfo pos1; 0043 pos1.docId = 1; 0044 pos1.positions = QVector<uint>() << 1 << 5 << 6; 0045 0046 PositionInfo pos2; 0047 pos2.docId = 5; 0048 pos2.positions = QVector<uint>() << 41 << 96 << 116; 0049 0050 QVector<PositionInfo> list = {pos1, pos2}; 0051 0052 db.put(word, list); 0053 0054 std::unique_ptr<VectorPositionInfoIterator> it{db.iter(word)}; 0055 QCOMPARE(it->docId(), static_cast<quint64>(0)); 0056 QVERIFY(it->positions().isEmpty()); 0057 0058 QCOMPARE(it->next(), static_cast<quint64>(1)); 0059 QCOMPARE(it->docId(), static_cast<quint64>(1)); 0060 QCOMPARE(it->positions(), pos1.positions); 0061 0062 QCOMPARE(it->next(), static_cast<quint64>(5)); 0063 QCOMPARE(it->docId(), static_cast<quint64>(5)); 0064 QCOMPARE(it->positions(), pos2.positions); 0065 0066 QCOMPARE(it->next(), static_cast<quint64>(0)); 0067 QCOMPARE(it->docId(), static_cast<quint64>(0)); 0068 QVERIFY(it->positions().isEmpty()); 0069 } 0070 }; 0071 0072 QTEST_MAIN(PositionDBTest) 0073 0074 #include "positiondbtest.moc"