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