Commit 0fca344c authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

autotests: Add more tests for the engine

parent d2f634ba
......@@ -26,6 +26,8 @@ macro(knewstuff_unit_tests)
LINK_LIBRARIES Qt5::Xml Qt5::Test Qt5::Gui KF5::KIOCore KF5::NewStuffCore
TEST_NAME ${_testname}
NAME_PREFIX "knewstuff-")
MESSAGE(WARNING "${CMAKE_CURRENT_BINARY_DIR}/data/")
target_compile_definitions(${_testname} PUBLIC -DDATA_DIR="${CMAKE_CURRENT_BINARY_DIR}/data/")
set_property( TARGET ${_testname}
APPEND
PROPERTY COMPILE_DEFINITIONS KNEWSTUFF_STATIC_DEFINE KNEWSTUFFCORE_STATIC_DEFINE KNEWSTUFF_STATIC_DEFINE
......
set(DATA_DIR "${CMAKE_CURRENT_BINARY_DIR}/data/")
configure_file(data/entry.xml.in data/entry.xml)
configure_file(data/provider.xml.in data/provider.xml)
configure_file(data/installcommand.knsrc.in data/installcommand.knsrc)
knewstuff_unit_tests(
knewstuffauthortest.cpp
knewstuffenginetest.cpp
)
<?xml version="1.0" encoding="UTF-8"?>
<ocs>
<stuff category="app/media">
<name lang="en">Entry 1 (ghns excluded)</name>
<author email="some_guy@some.mail.server" im="some_guy@jabber.server">Anonymous Guy</author>
<licence licenceurl="http://server/">GPL</licence>
<version>1.0</version>
<releasedate>2005-06-17</releasedate>
<summary lang="en">This is what it is all about.</summary>
<preview lang="en">http://some.http.server/preview.png</preview>
<payload lang="en">http://some.http.server/coolstuff.tar.gz</payload>
<rating>10</rating>
<downloads>0</downloads>
<tags>ghns_excluded=1</tags>
</stuff>
<stuff category="app/media">
<name lang="en">Entry 2 (ghns included)</name>
<author email="some_guy@some.mail.server" im="some_guy@jabber.server">Anonymous Guy</author>
<licence licenceurl="http://server/">GPL</licence>
<version>2.1git2</version>
<releasedate>2018-06-05</releasedate>
<summary lang="en">A short description in English (not ghns excluded).</summary>
<preview lang="en">http://some.http.server/preview.png</preview>
<payload lang="en">http://some.http.server/coolstuff.tar.gz</payload>
<rating>10</rating>
<downloads>0</downloads>
<tags></tags>
</stuff>
<stuff category="app/media">
<name lang="en">Entry 3 (ghns excluded)</name>
<author email="some_guy@some.mail.server" im="some_guy@jabber.server">Anonymous Guy</author>
<licence licenceurl="http://server/">GPL</licence>
<version>1.0</version>
<releasedate>2005-06-17</releasedate>
<summary lang="en">This is what it is all about.</summary>
<preview lang="en">http://some.http.server/preview.png</preview>
<payload lang="en">http://some.http.server/coolstuff.tar.gz</payload>
<rating>10</rating>
<downloads>0</downloads>
<tags>ghns_excluded=1</tags>
</stuff>
<stuff category="app/media">
<name lang="en">Entry 4 (ghns included)</name>
<author email="some_guy@some.mail.server" im="some_guy@jabber.server">Anonymous Guy</author>
<licence licenceurl="http://server/">GPL</licence>
<version>2.1git2</version>
<releasedate>2018-06-05</releasedate>
<summary lang="en">A short description in English (not ghns excluded).</summary>
<preview lang="en">http://some.http.server/preview.png</preview>
<payload lang="en">http://some.http.server/coolstuff.tar.gz</payload>
<rating>10</rating>
<downloads>0</downloads>
<tags></tags>
</stuff>
</ocs>
[KNewStuff3]
Name=InstallCommands
ProvidersUrl=file://@DATA_DIR@provider.xml
Categories=KDE Wallpaper 1920x1200,KDE Wallpaper 1600x1200
UploadCategories=KDE Wallpaper 800x600
TargetDir=icons
UseLabel=UseLabelTest
AdoptionCommand=/bin/true
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<knewstuffproviders>
<provider downloadurl="file://@DATA_DIR@entry.xml"
downloadurl-latest="file://@DATA_DIR@entry.xml"
downloadurl-score="file://@DATA_DIR@entry.xml"
downloadurl-downloads="file://@DATA_DIR@entry.xml"
uploadurl="ftp://somewhere.ftp.server"
webservice="http://some.http.server/service.wsdl"
icon="someapp"
webaccess="http://some.webfrontend.server/">
<title lang="en">Some cool stuff</title>
</provider>
</knewstuffproviders>
/*
This file is part of KNewStuff2.
SPDX-FileCopyrightText: 2008 Jeremy Whiting <jpwhiting@kde.org>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include <QTest>
#include <QtGlobal>
#include <QSignalSpy>
#include "core/engine.h"
#include "core/entryinternal.h"
using namespace KNSCore;
class EngineTest: public QObject
{
Q_OBJECT
public:
Engine *engine = nullptr;
const QString dataDir = QStringLiteral(DATA_DIR);
private Q_SLOTS:
void initTestCase();
void testPropertiesReading();
void testProviderFileLoading();
};
void EngineTest::initTestCase()
{
engine = new Engine(this);
QVERIFY(engine->init(dataDir + "installcommand.knsrc"));
QCOMPARE(engine->busyState(), Engine::BusyOperation::LoadingData);
QSignalSpy providersLoaded(engine, &Engine::signalProvidersLoaded);
QVERIFY(providersLoaded.wait());
QCOMPARE(engine->busyState(), Engine::BusyState());
}
void EngineTest::testPropertiesReading()
{
QCOMPARE(engine->name(), QStringLiteral("InstallCommands"));
QCOMPARE(engine->categories(), QStringList({"KDE Wallpaper 1920x1200", "KDE Wallpaper 1600x1200"}));
QCOMPARE(engine->useLabel(), QStringLiteral("UseLabelTest"));
QVERIFY(engine->hasAdoptionCommand());
}
void EngineTest::testProviderFileLoading()
{
const QString providerId = QUrl::fromLocalFile(dataDir + "entry.xml").toString();
QSharedPointer<Provider> provider = engine->provider(providerId);
QVERIFY(provider);
QCOMPARE(engine->defaultProvider(), provider);
KNSCore::EntryInternal::List list;
connect(engine, &Engine::signalEntriesLoaded, this,
[&list](const KNSCore::EntryInternal::List &loaded){ list = loaded; }, Qt::DirectConnection);
engine->setSearchTerm(QStringLiteral("Entry 4"));
QSignalSpy spy(engine, &Engine::signalEntriesLoaded);
QVERIFY(spy.wait());
QCOMPARE(list.size(), 1);
QCOMPARE(list.constFirst().name(), QStringLiteral("Entry 4 (ghns included)"));
}
QTEST_MAIN(EngineTest)
#include "knewstuffenginetest.moc"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment