PrismLauncher/tests/tst_UpdateChecker.cpp

146 lines
4.2 KiB
C++
Raw Normal View History

2013-12-14 13:53:18 +00:00
#include <QTest>
#include <QSignalSpy>
2013-12-14 13:53:18 +00:00
#include "TestUtil.h"
2015-02-09 00:51:14 +00:00
#include "updater/UpdateChecker.h"
Q_DECLARE_METATYPE(UpdateChecker::ChannelListEntry)
bool operator==(const UpdateChecker::ChannelListEntry &e1, const UpdateChecker::ChannelListEntry &e2)
{
return e1.id == e2.id &&
e1.name == e2.name &&
e1.description == e2.description &&
e1.url == e2.url;
}
2013-12-14 13:53:18 +00:00
QDebug operator<<(QDebug dbg, const UpdateChecker::ChannelListEntry &c)
{
dbg.nospace() << "ChannelListEntry(id=" << c.id << " name=" << c.name << " description=" << c.description << " url=" << c.url << ")";
return dbg.maybeSpace();
}
2013-12-14 13:53:18 +00:00
class UpdateCheckerTest : public QObject
{
Q_OBJECT
private
slots:
void initTestCase()
{
}
void cleanupTestCase()
{
}
static QString findTestDataUrl(const char *file)
{
return QUrl::fromLocalFile(QFINDTESTDATA(file)).toString();
}
void tst_ChannelListParsing_data()
{
QTest::addColumn<QString>("channel");
QTest::addColumn<QString>("channelUrl");
QTest::addColumn<bool>("hasChannels");
QTest::addColumn<bool>("valid");
QTest::addColumn<QList<UpdateChecker::ChannelListEntry> >("result");
QTest::newRow("garbage")
<< QString()
<< findTestDataUrl("tests/data/garbageChannels.json")
<< false
<< false
<< QList<UpdateChecker::ChannelListEntry>();
QTest::newRow("errors")
<< QString()
<< findTestDataUrl("tests/data/errorChannels.json")
<< false
<< true
<< QList<UpdateChecker::ChannelListEntry>();
QTest::newRow("no channels")
<< QString()
<< findTestDataUrl("tests/data/noChannels.json")
<< false
<< true
<< QList<UpdateChecker::ChannelListEntry>();
QTest::newRow("one channel")
<< QString("develop")
<< findTestDataUrl("tests/data/oneChannel.json")
<< true
<< true
<< (QList<UpdateChecker::ChannelListEntry>() << UpdateChecker::ChannelListEntry{"develop", "Develop", "The channel called \"develop\"", "http://example.org/stuff"});
QTest::newRow("several channels")
<< QString("develop")
<< findTestDataUrl("tests/data/channels.json")
<< true
<< true
<< (QList<UpdateChecker::ChannelListEntry>()
2016-03-03 21:47:41 +00:00
<< UpdateChecker::ChannelListEntry{"develop", "Develop", "The channel called \"develop\"", MultiMC_TEST_DATA_URL}
<< UpdateChecker::ChannelListEntry{"stable", "Stable", "It's stable at least", MultiMC_TEST_DATA_URL}
<< UpdateChecker::ChannelListEntry{"42", "The Channel", "This is the channel that is going to answer all of your questions", "https://dent.me/tea"});
}
void tst_ChannelListParsing()
{
QFETCH(QString, channel);
QFETCH(QString, channelUrl);
QFETCH(bool, hasChannels);
QFETCH(bool, valid);
QFETCH(QList<UpdateChecker::ChannelListEntry>, result);
UpdateChecker checker(channelUrl, channel, 0);
QSignalSpy channelListLoadedSpy(&checker, SIGNAL(channelListLoaded()));
QVERIFY(channelListLoadedSpy.isValid());
checker.updateChanList(false);
if (valid)
{
QVERIFY(channelListLoadedSpy.wait());
QCOMPARE(channelListLoadedSpy.size(), 1);
}
else
{
channelListLoadedSpy.wait();
QCOMPARE(channelListLoadedSpy.size(), 0);
}
QCOMPARE(checker.hasChannels(), hasChannels);
QCOMPARE(checker.getChannelList(), result);
}
void tst_UpdateChecking()
{
QString channel = "develop";
QString channelUrl = findTestDataUrl("tests/data/channels.json");
int currentBuild = 2;
UpdateChecker checker(channelUrl, channel, currentBuild);
QSignalSpy updateAvailableSpy(&checker, SIGNAL(updateAvailable(GoUpdate::Status)));
QVERIFY(updateAvailableSpy.isValid());
QSignalSpy channelListLoadedSpy(&checker, SIGNAL(channelListLoaded()));
QVERIFY(channelListLoadedSpy.isValid());
checker.updateChanList(false);
QVERIFY(channelListLoadedSpy.wait());
qDebug() << "CWD:" << QDir::current().absolutePath();
checker.m_channels[0].url = findTestDataUrl("tests/data/");
checker.checkForUpdate(channel, false);
QVERIFY(updateAvailableSpy.wait());
auto status = updateAvailableSpy.first().first().value<GoUpdate::Status>();
QCOMPARE(checker.m_channels[0].url, status.newRepoUrl);
QCOMPARE(3, status.newVersionId);
QCOMPARE(currentBuild, status.currentVersionId);
}
2013-12-14 13:53:18 +00:00
};
QTEST_GUILESS_MAIN(UpdateCheckerTest)
2013-12-14 13:53:18 +00:00
#include "tst_UpdateChecker.moc"