File indexing completed on 2024-04-28 05:48:12

0001 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0002 // SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
0003 
0004 #include <QDebug>
0005 #include <QSignalSpy>
0006 #include <QTest>
0007 
0008 #include "fileTree.h"
0009 #include "scan.h"
0010 
0011 Q_DECLARE_METATYPE(std::shared_ptr<Folder>)
0012 
0013 class ScanManagerTest : public QObject
0014 {
0015     Q_OBJECT
0016     const QString m_tree = QFINDTESTDATA("iterator-tree");
0017 private Q_SLOTS:
0018     void testRun()
0019     {
0020         qRegisterMetaType<std::shared_ptr<File>>("std::shared_ptr<File>");
0021         qRegisterMetaType<std::shared_ptr<Folder>>("std::shared_ptr<Folder>");
0022 
0023         Filelight::ScanManager manager(nullptr);
0024 
0025         {
0026             QSignalSpy spy(&manager, &Filelight::ScanManager::completed);
0027             manager.start(QUrl(QStringLiteral("file://") + m_tree));
0028             spy.wait();
0029         }
0030 
0031         {
0032             // rescan to make sure the cache doesn't blow up
0033             QSignalSpy spy(&manager, &Filelight::ScanManager::completed);
0034             manager.start(QUrl(QStringLiteral("file://") + m_tree));
0035             spy.wait();
0036         }
0037 
0038         {
0039             // invalidate part of the tree and make sure the scanner doesn't blow up
0040             manager.invalidateCacheFor(QUrl(QStringLiteral("file://") + m_tree + QStringLiteral("/foo")));
0041             QSignalSpy spy(&manager, &Filelight::ScanManager::completed);
0042             manager.start(QUrl(QStringLiteral("file://") + m_tree));
0043             spy.wait();
0044         }
0045     }
0046 };
0047 
0048 QTEST_MAIN(ScanManagerTest)
0049 
0050 #include "scanManagerTest.moc"