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 "vectorpostingiterator.h"
0010 
0011 #include <QTest>
0012 
0013 using namespace Baloo;
0014 
0015 class AndPostingIteratorTest : public QObject
0016 {
0017     Q_OBJECT
0018 private Q_SLOTS:
0019     void test();
0020     void testNullIterators();
0021 };
0022 
0023 void AndPostingIteratorTest::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     AndPostingIterator it(vec);
0035     QCOMPARE(it.docId(), static_cast<quint64>(0));
0036 
0037     QVector<quint64> result = {3, 7};
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 AndPostingIteratorTest::testNullIterators()
0047 {
0048     QVector<quint64> l1 = {1, 3, 5, 7};
0049     QVector<quint64> l2 = {3, 4, 5, 7, 9, 11};
0050 
0051     VectorPostingIterator* it1 = new VectorPostingIterator(l1);
0052     VectorPostingIterator* it2 = new VectorPostingIterator(l2);
0053 
0054     QVector<PostingIterator*> vec = {it1, nullptr, it2};
0055 
0056     AndPostingIterator it(vec);
0057     QCOMPARE(it.docId(), static_cast<quint64>(0));
0058     QCOMPARE(it.next(), static_cast<quint64>(0));
0059     QCOMPARE(it.docId(), static_cast<quint64>(0));
0060 }
0061 
0062 QTEST_MAIN(AndPostingIteratorTest)
0063 
0064 #include "andpostingiteratortest.moc"