diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index fb359eef01c7d19a1920577cc9a3510efec21a79..1743909b6b26607a67c24a5d2b32149c3382b537 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -23,6 +23,7 @@ uf_add_test(datasourcetest KUserFeedbackCore Qt5::Gui) # needs Gui for ScreenInf uf_add_test(openglinfosourcetest.cpp KUserFeedbackCore Qt5::Gui) uf_add_test(providertest KUserFeedbackCore Qt5::Gui) uf_add_test(selectionratiosourcetest.cpp KUserFeedbackCore Qt5::Gui) +uf_add_test(surveyprovidertest.cpp KUserFeedbackCore) uf_add_test(feedbackconfigtest KUserFeedbackWidgets) diff --git a/autotests/surveyprovidertest.cpp b/autotests/surveyprovidertest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f966c488f118b7a5b48a28fb5fc576673de769f2 --- /dev/null +++ b/autotests/surveyprovidertest.cpp @@ -0,0 +1,87 @@ +/* + Copyright (C) 2017 Volker Krause <vkrause@kde.org> + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This program 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 Library General Public + License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <provider.h> +#include <surveyinfo.h> + +#include <QDebug> +#include <QtTest/qtest.h> +#include <QObject> +#include <QSettings> +#include <QSignalSpy> +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) +#include <QStandardPaths> +#endif + +using namespace KUserFeedback; + +class SurveyProviderTest : public QObject +{ + Q_OBJECT +private slots: + void initTestCase() + { + qRegisterMetaType<KUserFeedback::SurveyInfo>(); + + QCoreApplication::setOrganizationName(QStringLiteral("KDE")); + QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org")); + QCoreApplication::setApplicationName(QStringLiteral("surveyprovidertest")); +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + QStandardPaths::setTestModeEnabled(true); +#endif + } + + void testSurveySelect() + { + { + QSettings s(QCoreApplication::organizationName(), QStringLiteral("UserFeedback.org.kde.providertest"));; + s.beginGroup(QLatin1String("UserFeedback")); + s.remove(QLatin1String("LastSurvey")); + s.remove(QLatin1String("CompletedSurveys")); + } + + SurveyInfo s1; + s1.setUuid(QUuid::createUuid()); + s1.setUrl(QUrl(QStringLiteral("https://www.kde.org"))); + QVERIFY(s1.isValid()); + + Provider p; + QSignalSpy spy(&p, SIGNAL(surveyAvailable(KUserFeedback::SurveyInfo))); + QVERIFY(spy.isValid()); + + bool rv = false; + QMetaObject::invokeMethod(&p, "selectSurvey", Q_RETURN_ARG(bool, rv), Q_ARG(KUserFeedback::SurveyInfo, s1)); + QVERIFY(rv); + QCOMPARE(spy.size(), 1); + + // again, not completed yet + QMetaObject::invokeMethod(&p, "selectSurvey", Q_RETURN_ARG(bool, rv), Q_ARG(KUserFeedback::SurveyInfo, s1)); + QVERIFY(rv); + QCOMPARE(spy.size(), 2); + spy.clear(); + + // survey completed, should no longer be accepted + p.surveyCompleted(s1); + QMetaObject::invokeMethod(&p, "selectSurvey", Q_RETURN_ARG(bool, rv), Q_ARG(KUserFeedback::SurveyInfo, s1)); + QVERIFY(!rv); + QVERIFY(spy.isEmpty()); + } +}; + +QTEST_MAIN(SurveyProviderTest) + +#include "surveyprovidertest.moc" diff --git a/src/provider/core/provider.h b/src/provider/core/provider.h index d043ef0c964d3963bf4a68d659527485b5833b4e..4c06c167d10346ac5b170a40867641e2772980aa 100644 --- a/src/provider/core/provider.h +++ b/src/provider/core/provider.h @@ -258,6 +258,7 @@ private: // for testing Q_PRIVATE_SLOT(d, void load()) Q_PRIVATE_SLOT(d, void store()) + Q_PRIVATE_SLOT(d, bool selectSurvey(const KUserFeedback::SurveyInfo&)) }; }