/* SPDX-FileCopyrightText: 2024 (c) Jack Hill SPDX-License-Identifier: LGPL-3.0-or-later */ #include "config-upnp-qt.h" #include "models/filebrowsermodel.h" #include "models/filebrowserproxymodel.h" #include #include #include #include using namespace Qt::Literals::StringLiterals; class FileBrowserProxyModelTest : public QObject { Q_OBJECT public: FileBrowserProxyModelTest(QObject *parent = nullptr) : QObject(parent) { } private Q_SLOTS: void init() { mFileModel = std::make_unique(); mFileProxyModel = std::make_unique(); mFileProxyModel->setSourceModel(mFileModel.get()); mFileModelTester = std::make_unique(mFileModel.get()); mFileProxyModelTester = std::make_unique(mFileProxyModel.get()); mEntriesToEnqueueSpy = std::make_unique(mFileProxyModel.get(), &FileBrowserProxyModel::entriesToEnqueue); } void enqueueFromEmptyDirectory() { const auto emptyDirectory = QUrl::fromLocalFile(QStringLiteral(LOCAL_FILE_TESTS_SAMPLE_FILES_PATH) + u"/empty"_s); mFileModel->initializeByData(nullptr, nullptr, ElisaUtils::FileName, ElisaUtils::FilterByPath, {{DataTypes::FilePathRole, emptyDirectory}}); QCOMPARE(mFileModel->rowCount(), 0); QCOMPARE(mFileProxyModel->rowCount(), 0); QVERIFY(mEntriesToEnqueueSpy->isEmpty()); mFileProxyModel->enqueueAll(ElisaUtils::AppendPlayList, ElisaUtils::DoNotTriggerPlay); QCOMPARE(mEntriesToEnqueueSpy->count(), 1); QVariantList arguments = mEntriesToEnqueueSpy->takeFirst(); QCOMPARE(arguments.count(), 3); QVERIFY(arguments.at(0).toList().isEmpty()); QCOMPARE(arguments.at(1).toInt(), static_cast(ElisaUtils::AppendPlayList)); QCOMPARE(arguments.at(2).toInt(), static_cast(ElisaUtils::DoNotTriggerPlay)); mFileProxyModel->enqueueAll(ElisaUtils::ReplacePlayList, ElisaUtils::TriggerPlay); QCOMPARE(mEntriesToEnqueueSpy->count(), 1); arguments = mEntriesToEnqueueSpy->takeFirst(); QCOMPARE(arguments.count(), 3); QVERIFY(arguments.at(0).toList().isEmpty()); QCOMPARE(arguments.at(1).toInt(), static_cast(ElisaUtils::ReplacePlayList)); QCOMPARE(arguments.at(2).toInt(), static_cast(ElisaUtils::TriggerPlay)); } private: std::unique_ptr mFileModel; std::unique_ptr mFileProxyModel; std::unique_ptr mFileModelTester; std::unique_ptr mFileProxyModelTester; std::unique_ptr mEntriesToEnqueueSpy; }; QTEST_GUILESS_MAIN(FileBrowserProxyModelTest) #include "filebrowserproxymodeltest.moc"