File indexing completed on 2024-04-28 03:51:40

0001 /*
0002     This file is part of the KDE Baloo Project
0003     SPDX-FileCopyrightText: 2021 Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #include "extractorprocess.h"
0009 #include "testsconfig.h"
0010 
0011 #include <QSignalSpy>
0012 #include <QStandardPaths>
0013 #include <QTest>
0014 
0015 namespace Baloo {
0016 namespace Test {
0017 
0018 namespace {
0019 QString getWorkerPath()
0020 {
0021     return QStandardPaths::findExecutable(QStringLiteral("extractorprocess_fake"),
0022                                   {QStringLiteral(EXTRACTOR_TESTS_HELPER_PATH)});
0023 }
0024 } // <anonymous> namespace
0025 
0026 class ExtractorProcessTest : public QObject
0027 {
0028     Q_OBJECT
0029 public:
0030     ExtractorProcessTest()
0031         : m_workerPath(getWorkerPath())
0032     {}
0033 
0034 private Q_SLOTS:
0035     void initTestCase();
0036 
0037     void testSignals();
0038     void testSignals2();
0039     void testExit();
0040 
0041 private:
0042     QString m_workerPath;
0043 };
0044 
0045 void ExtractorProcessTest::initTestCase()
0046 {
0047     QVERIFY(!m_workerPath.isEmpty());
0048 }
0049 
0050 void ExtractorProcessTest::testSignals()
0051 {
0052     Baloo::ExtractorProcess extractor{m_workerPath};
0053     QSignalSpy spyS(&extractor, &ExtractorProcess::startedIndexingFile);
0054     QSignalSpy spyF(&extractor, &ExtractorProcess::finishedIndexingFile);
0055     QSignalSpy spyD(&extractor, &ExtractorProcess::done);
0056 
0057     extractor.index({123, 125});
0058     QVERIFY(spyD.wait());
0059 
0060     extractor.index({127, 129});
0061     QVERIFY(spyD.wait());
0062     QCOMPARE(spyF.size(), 4);
0063 }
0064 
0065 void ExtractorProcessTest::testSignals2()
0066 {
0067     Baloo::ExtractorProcess extractor{m_workerPath};
0068     QSignalSpy spyS(&extractor, &ExtractorProcess::startedIndexingFile);
0069     QSignalSpy spyF(&extractor, &ExtractorProcess::finishedIndexingFile);
0070     QSignalSpy spyD(&extractor, &ExtractorProcess::done);
0071 
0072     extractor.index({123, 23});
0073     QVERIFY(spyD.wait());
0074     QCOMPARE(spyS.size(), 2);
0075     QCOMPARE(spyF.size(), 2);
0076 }
0077 
0078 void ExtractorProcessTest::testExit()
0079 {
0080     Baloo::ExtractorProcess extractor{m_workerPath};
0081     QSignalSpy spyS(&extractor, &ExtractorProcess::startedIndexingFile);
0082     QSignalSpy spyF(&extractor, &ExtractorProcess::finishedIndexingFile);
0083     QSignalSpy spyD(&extractor, &ExtractorProcess::done);
0084     QSignalSpy spyX(&extractor, &ExtractorProcess::failed);
0085 
0086     extractor.index({123, 0, 23});
0087     QVERIFY(spyX.wait());
0088     QCOMPARE(spyS.size(), 2);
0089     QCOMPARE(spyF.size(), 1);
0090     QCOMPARE(spyD.size(), 0);
0091 }
0092 
0093 } // namespace Test
0094 } // namespace Baloo
0095 
0096 using namespace Baloo::Test;
0097 
0098 QTEST_GUILESS_MAIN(ExtractorProcessTest)
0099 
0100 #include "extractorprocesstest.moc"