Commit b48ff390 authored by Volker Krause's avatar Volker Krause
Browse files

Add survey selection unit test

Prepares us for testing system-wide coordination of survey requests.
parent 11edb4d1
......@@ -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)
......
/*
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"
......@@ -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&))
};
}
......
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