File indexing completed on 2024-04-28 03:51:39
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 "andpostingiterator.h" 0009 #include "orpostingiterator.h" 0010 #include "vectorpostingiterator.h" 0011 0012 #include <QTest> 0013 0014 using namespace Baloo; 0015 0016 class PostingIteratorTest : public QObject 0017 { 0018 Q_OBJECT 0019 private Q_SLOTS: 0020 void test(); 0021 void test2(); 0022 }; 0023 0024 void PostingIteratorTest::test() 0025 { 0026 QVector<quint64> l1 = {1, 3, 5, 7}; 0027 QVector<quint64> l2 = {2, 3, 4, 9, 11}; 0028 QVector<quint64> l3 = {4, 7}; 0029 0030 VectorPostingIterator* it1 = new VectorPostingIterator(l1); 0031 VectorPostingIterator* it2 = new VectorPostingIterator(l2); 0032 VectorPostingIterator* it3 = new VectorPostingIterator(l3); 0033 0034 QVector<PostingIterator*> orvec = {it2, it3}; 0035 OrPostingIterator* orit = new OrPostingIterator(orvec); 0036 QVector<PostingIterator*> andvec = {it1, orit}; 0037 AndPostingIterator it(andvec); 0038 QCOMPARE(it.docId(), static_cast<quint64>(0)); 0039 0040 QVector<quint64> result = {3, 7}; 0041 for (quint64 val : result) { 0042 QCOMPARE(it.next(), static_cast<quint64>(val)); 0043 QCOMPARE(it.docId(), static_cast<quint64>(val)); 0044 } 0045 QCOMPARE(it.next(), static_cast<quint64>(0)); 0046 QCOMPARE(it.docId(), static_cast<quint64>(0)); 0047 } 0048 0049 void PostingIteratorTest::test2() 0050 { 0051 QVector<quint64> l1 = {1, 3, 5, 7}; 0052 QVector<quint64> l2 = {2, 3, 4, 9, 11}; 0053 QVector<quint64> l3 = {3, 7}; 0054 0055 VectorPostingIterator* it1 = new VectorPostingIterator(l1); 0056 VectorPostingIterator* it2 = new VectorPostingIterator(l2); 0057 VectorPostingIterator* it3 = new VectorPostingIterator(l3); 0058 0059 QVector<PostingIterator*> orvec = {new OrPostingIterator({it2}), new OrPostingIterator({it3}) }; 0060 OrPostingIterator* orit = new OrPostingIterator(orvec); 0061 QVector<PostingIterator*> andvec = {it1, orit}; 0062 AndPostingIterator it(andvec); 0063 QCOMPARE(it.docId(), static_cast<quint64>(0)); 0064 0065 QVector<quint64> result = {3, 7}; 0066 for (quint64 val : result) { 0067 QCOMPARE(it.next(), static_cast<quint64>(val)); 0068 QCOMPARE(it.docId(), static_cast<quint64>(val)); 0069 } 0070 QCOMPARE(it.next(), static_cast<quint64>(0)); 0071 QCOMPARE(it.docId(), static_cast<quint64>(0)); 0072 } 0073 0074 QTEST_MAIN(PostingIteratorTest) 0075 0076 #include "postingiteratortest.moc"