File indexing completed on 2024-09-01 03:46:49
0001 /* 0002 This file is part of KNewStuff2. 0003 SPDX-FileCopyrightText: 2008 Jeremy Whiting <jpwhiting@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.1-or-later 0006 */ 0007 0008 #include <QSignalSpy> 0009 #include <QTest> 0010 #include <QtGlobal> 0011 0012 #include "enginebase.h" 0013 #include "entry.h" 0014 #include "provider.h" 0015 #include "qtquick/quickengine.h" 0016 0017 using namespace KNSCore; 0018 0019 class EngineTest : public QObject 0020 { 0021 Q_OBJECT 0022 public: 0023 Engine *engine = nullptr; 0024 const QString dataDir = QStringLiteral(DATA_DIR); 0025 0026 private Q_SLOTS: 0027 void initTestCase(); 0028 void testPropertiesReading(); 0029 void testProviderFileLoading(); 0030 }; 0031 0032 void EngineTest::initTestCase() 0033 { 0034 engine = new Engine(this); 0035 engine->setConfigFile(dataDir + QLatin1String("enginetest.knsrc")); 0036 QVERIFY(engine->isValid()); 0037 QCOMPARE(engine->busyState(), Engine::BusyOperation::Initializing); 0038 QSignalSpy providersLoaded(engine, &Engine::signalProvidersLoaded); 0039 QVERIFY(providersLoaded.wait()); 0040 QCOMPARE(engine->busyState(), Engine::BusyState()); 0041 } 0042 0043 void EngineTest::testPropertiesReading() 0044 { 0045 QCOMPARE(engine->name(), QStringLiteral("InstallCommands")); 0046 QCOMPARE(static_cast<EngineBase *>(engine)->categories(), 0047 QStringList({QStringLiteral("KDE Wallpaper 1920x1200"), QStringLiteral("KDE Wallpaper 1600x1200")})); 0048 QCOMPARE(engine->useLabel(), QStringLiteral("UseLabelTest")); 0049 QVERIFY(engine->hasAdoptionCommand()); 0050 } 0051 0052 void EngineTest::testProviderFileLoading() 0053 { 0054 const QString providerId = QUrl::fromLocalFile(dataDir + QLatin1String("entry.xml")).toString(); 0055 QSharedPointer<Provider> provider = engine->provider(providerId); 0056 QVERIFY(provider); 0057 QCOMPARE(engine->defaultProvider(), provider); 0058 QVERIFY(engine->isValid()); 0059 0060 engine->setSearchTerm(QStringLiteral("Entry 4")); 0061 QSignalSpy spy(engine, &Engine::signalEntriesLoaded); 0062 QVERIFY(spy.wait()); 0063 const QVariantList entries = spy.last().constFirst().toList(); // From last signal emission 0064 QCOMPARE(entries.size(), 1); 0065 QCOMPARE(entries.first().value<KNSCore::Entry>().name(), QStringLiteral("Entry 4 (ghns included)")); 0066 } 0067 0068 QTEST_MAIN(EngineTest) 0069 0070 #include "knewstuffenginetest.moc"