diff --git a/autotests/configtest.cpp b/autotests/configtest.cpp index 011e710..48e626c 100644 --- a/autotests/configtest.cpp +++ b/autotests/configtest.cpp @@ -1,58 +1,58 @@ /* This file is part of KDE. Copyright (c) 2018 Ralf Habacker This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ -#include +#include #include using namespace Attica; class ConfigTest : public QObject { Q_OBJECT private Q_SLOTS: void testParsing(); }; void ConfigTest::testParsing() { Config::Parser parser; QString validData (QLatin1String("" "" "1.7" "store.kde.org" "api.kde-look.org" "contact@opendesktop.org" "true" "")); Config config = parser.parse(validData); QVERIFY(config.isValid()); QString invalidData = QLatin1String(""); config = parser.parse(invalidData); QVERIFY(!config.isValid()); } QTEST_GUILESS_MAIN(ConfigTest) #include "configtest.moc" diff --git a/autotests/persontest.cpp b/autotests/persontest.cpp index 6d8f271..9019865 100644 --- a/autotests/persontest.cpp +++ b/autotests/persontest.cpp @@ -1,64 +1,64 @@ /* This file is part of KDE. Copyright (c) 2010 Martin Sandsmark This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ -#include +#include #include using namespace Attica; class PersonTest : public QObject { Q_OBJECT private Q_SLOTS: void testParsing(); }; void PersonTest::testParsing() { Person::Parser parser; QString validData(QLatin1String("" "" "10" "Ola" "Nordmann" "http://kde.org/" "http://techbase.kde.org/skins/oxygen/top-kde.png" "1" "2010-06-21" "Oslo" "Norway" "59.56" "10.41" "")); Person person = parser.parse(validData); QVERIFY(person.isValid()); QString invalidData = QLatin1String(""); person = parser.parse(invalidData); QVERIFY(!person.isValid()); } QTEST_MAIN(PersonTest) #include "persontest.moc" diff --git a/autotests/privatedatatest.cpp b/autotests/privatedatatest.cpp index 8b579d5..9913c17 100644 --- a/autotests/privatedatatest.cpp +++ b/autotests/privatedatatest.cpp @@ -1,61 +1,61 @@ /* This file is part of KDE. Copyright (c) 2010 Martin Sandsmark This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ -#include +#include #include "../privatedata.h" #include "../privatedataparser.h" using namespace Attica; class PersonTest : public QObject { Q_OBJECT private slots: void testParsing(); void testMergeType(); }; void PersonTest::testParsing() { PrivateData::Parser parser; QString validData("" "keyfoo" "valuebar" "01.01.1998" ""); PrivateData attributes = parser.parse(validData); QVERIFY(attributes.attributeChanged("keyfoo").isValid()); QVERIFY(!attributes.attribute("keyfoo").isNull()); } void PersonTest::testMergeType() { PrivateData a; a.setMergeType(PrivateData::OverwriteLocal); QVERIFY(a.mergeType() == PrivateData::OverwriteLocal); } QTEST_MAIN(PersonTest); #include "moc_persontest.cxx" diff --git a/autotests/providertest.cpp b/autotests/providertest.cpp index 99222e5..42ec71e 100644 --- a/autotests/providertest.cpp +++ b/autotests/providertest.cpp @@ -1,150 +1,151 @@ /* This file is part of KDE. Copyright (c) 2018 Ralf Habacker This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ -#include +#include +#include #include #include #include #include using namespace Attica; class ProviderTest : public QObject { Q_OBJECT public: ProviderTest(); virtual ~ProviderTest(); private: void initProvider(const QUrl &url); private Q_SLOTS: void testFetchValidProvider(); void testFetchInvalidProvider(); protected Q_SLOTS: void providerAdded(Attica::Provider p); void slotDefaultProvidersLoaded(); void slotConfigResult(Attica::BaseJob *j); void slotTimeout(); private: Attica::ProviderManager *m_manager; QEventLoop *m_eventloop; QTimer m_timer; bool m_errorReceived = false; }; ProviderTest::ProviderTest() : m_manager(nullptr), m_eventloop(new QEventLoop) { QLoggingCategory::setFilterRules(QStringLiteral("org.kde.attica.debug=true")); } ProviderTest::~ProviderTest() { delete m_manager; delete m_eventloop; } void ProviderTest::slotDefaultProvidersLoaded() { qDebug() << "default providers loaded"; m_eventloop->exit(); } void ProviderTest::providerAdded(Attica::Provider p) { qDebug() << "got provider" << p.name(); m_eventloop->exit(); } void ProviderTest::initProvider(const QUrl &url) { m_errorReceived = false; delete m_manager; m_manager = new Attica::ProviderManager; m_manager->setAuthenticationSuppressed(true); connect(m_manager, &ProviderManager::defaultProvidersLoaded, this, &ProviderTest::slotDefaultProvidersLoaded); connect(m_manager, &ProviderManager::providerAdded, this, &ProviderTest::providerAdded); m_manager->addProviderFile(url); connect(m_manager, &Attica::ProviderManager::failedToLoad, this, [this]() { m_errorReceived = true; m_eventloop->quit(); }); m_timer.singleShot(5000, this, &ProviderTest::slotTimeout); m_eventloop->exec(); } void ProviderTest::testFetchValidProvider() { initProvider(QUrl(QLatin1String("https://autoconfig.kde.org/ocs/providers.xml"))); Attica::Provider provider = m_manager->providers().at(0); ItemJob* job = provider.requestConfig(); QVERIFY(job); connect(job, &BaseJob::finished, this, &ProviderTest::slotConfigResult); job->start(); m_eventloop->exec(); } void ProviderTest::slotConfigResult(Attica::BaseJob* j) { if (j->metadata().error() == Metadata::NoError) { Attica::ItemJob *itemJob = static_cast *>( j ); Attica::Config p = itemJob->result(); qDebug() << QLatin1String("Config loaded - Server has version") << p.version(); } else if (j->metadata().error() == Metadata::OcsError) { qDebug() << QString(QLatin1String("OCS Error: %1")).arg(j->metadata().message()); } else if (j->metadata().error() == Metadata::NetworkError) { qDebug() << QString(QLatin1String("Network Error: %1")).arg(j->metadata().message()); } else { qDebug() << QString(QLatin1String("Unknown Error: %1")).arg(j->metadata().message()); } m_eventloop->exit(); m_timer.stop(); QVERIFY(j->metadata().error() == Metadata::NoError); } void ProviderTest::slotTimeout() { QVERIFY(m_eventloop->isRunning()); m_eventloop->exit(); QFAIL("Timeout fetching provider"); } void ProviderTest::testFetchInvalidProvider() { initProvider(QUrl(QLatin1String("https://invalid-url.org/ocs/providers.xml"))); QVERIFY(m_manager->providers().size() == 0); QVERIFY(m_errorReceived); } QTEST_GUILESS_MAIN(ProviderTest) #include "providertest.moc"