More tests for the UpdateChecker class. It should be done for now.
This commit is contained in:
parent
a02e62f17f
commit
f273334212
@ -124,6 +124,8 @@ private:
|
||||
void initTranslations();
|
||||
|
||||
private:
|
||||
friend class UpdateCheckerTest;
|
||||
|
||||
std::shared_ptr<QTranslator> m_qt_translator;
|
||||
std::shared_ptr<QTranslator> m_mmc_translator;
|
||||
std::shared_ptr<SettingsObject> m_settings;
|
||||
|
@ -73,6 +73,8 @@ private slots:
|
||||
void chanListDownloadFailed();
|
||||
|
||||
private:
|
||||
friend class UpdateCheckerTest;
|
||||
|
||||
NetJobPtr indexJob;
|
||||
NetJobPtr chanListJob;
|
||||
|
||||
|
23
tests/data/errorChannels.json
Normal file
23
tests/data/errorChannels.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"format_version": 0,
|
||||
"channels": [
|
||||
{
|
||||
"id": "",
|
||||
"name": "Develop",
|
||||
"description": "The channel called \"develop\"",
|
||||
"url": "http://example.org/stuff"
|
||||
},
|
||||
{
|
||||
"id": "stable",
|
||||
"name": "",
|
||||
"description": "It's stable at least",
|
||||
"url": "ftp://username@host/path/to/stuff"
|
||||
},
|
||||
{
|
||||
"id": "42",
|
||||
"name": "The Channel",
|
||||
"description": "This is the channel that is going to answer all of your questions",
|
||||
"url": ""
|
||||
}
|
||||
]
|
||||
}
|
22
tests/data/garbageChannels.json
Normal file
22
tests/data/garbageChannels.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"format_version": 0,
|
||||
"channels": [
|
||||
{
|
||||
"id": "develop",
|
||||
"name": "Develop",
|
||||
"description": "The channel called \"develop\"",
|
||||
aa "url": "http://example.org/stuff"
|
||||
},
|
||||
a "id": "stable",
|
||||
"name": "Stable",
|
||||
"description": "It's stable at least",
|
||||
"url": "ftp://username@host/path/to/stuff"
|
||||
},
|
||||
{
|
||||
"id": "42"f
|
||||
"name": "The Channel",
|
||||
"description": "This is the channel that is going to answer all of your questions",
|
||||
"url": "https://dent.me/tea"
|
||||
}
|
||||
]
|
||||
}
|
9
tests/data/index.json
Normal file
9
tests/data/index.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"ApiVersion": 0,
|
||||
"Versions": [
|
||||
{ "Id": 0, "Name": "1.0.0" },
|
||||
{ "Id": 1, "Name": "1.0.1" },
|
||||
{ "Id": 2, "Name": "1.0.2" },
|
||||
{ "Id": 3, "Name": "1.0.3" }
|
||||
]
|
||||
}
|
@ -37,22 +37,38 @@ slots:
|
||||
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>()
|
||||
<< UpdateChecker::ChannelListEntry{"develop", "Develop", "The channel called \"develop\"", "http://example.org/stuff"}
|
||||
<< UpdateChecker::ChannelListEntry{"stable", "Stable", "It's stable at least", "ftp://username@host/path/to/stuff"}
|
||||
@ -63,25 +79,78 @@ slots:
|
||||
QFETCH(QString, channel);
|
||||
QFETCH(QString, channelUrl);
|
||||
QFETCH(bool, hasChannels);
|
||||
QFETCH(bool, valid);
|
||||
QFETCH(QList<UpdateChecker::ChannelListEntry>, result);
|
||||
|
||||
UpdateChecker checker;
|
||||
|
||||
QSignalSpy spy(&checker, SIGNAL(channelListLoaded()));
|
||||
QVERIFY(spy.isValid());
|
||||
QSignalSpy channelListLoadedSpy(&checker, SIGNAL(channelListLoaded()));
|
||||
QVERIFY(channelListLoadedSpy.isValid());
|
||||
|
||||
checker.setCurrentChannel(channel);
|
||||
checker.setChannelListUrl(channelUrl);
|
||||
|
||||
checker.updateChanList();
|
||||
|
||||
QVERIFY(spy.wait());
|
||||
if (valid)
|
||||
{
|
||||
QVERIFY(channelListLoadedSpy.wait());
|
||||
QCOMPARE(channelListLoadedSpy.size(), 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
channelListLoadedSpy.wait();
|
||||
QCOMPARE(channelListLoadedSpy.size(), 0);
|
||||
}
|
||||
|
||||
QCOMPARE(spy.size(), 1);
|
||||
|
||||
QCOMPARE(checker.hasChannels(), hasChannels);
|
||||
QCOMPARE(checker.getChannelList(), result);
|
||||
}
|
||||
|
||||
void tst_UpdateChecking_data()
|
||||
{
|
||||
QTest::addColumn<QString>("channel");
|
||||
QTest::addColumn<QString>("channelUrl");
|
||||
QTest::addColumn<int>("currentBuild");
|
||||
QTest::addColumn<QList<QVariant> >("result");
|
||||
|
||||
QTest::newRow("valid channel")
|
||||
<< "develop" << findTestDataUrl("tests/data/channels.json")
|
||||
<< 2
|
||||
<< (QList<QVariant>() << QString() << "1.0.3" << 3);
|
||||
}
|
||||
|
||||
void tst_UpdateChecking()
|
||||
{
|
||||
QFETCH(QString, channel);
|
||||
QFETCH(QString, channelUrl);
|
||||
QFETCH(int, currentBuild);
|
||||
QFETCH(QList<QVariant>, result);
|
||||
|
||||
MMC->m_version.build = currentBuild;
|
||||
|
||||
UpdateChecker checker;
|
||||
checker.setCurrentChannel(channel);
|
||||
checker.setChannelListUrl(channelUrl);
|
||||
|
||||
QSignalSpy updateAvailableSpy(&checker, SIGNAL(updateAvailable(QString,QString,int)));
|
||||
QVERIFY(updateAvailableSpy.isValid());
|
||||
QSignalSpy channelListLoadedSpy(&checker, SIGNAL(channelListLoaded()));
|
||||
QVERIFY(channelListLoadedSpy.isValid());
|
||||
|
||||
checker.updateChanList();
|
||||
QVERIFY(channelListLoadedSpy.wait());
|
||||
|
||||
checker.m_channels[0].url = QUrl::fromLocalFile(QDir::current().absoluteFilePath("tests/data/")).toString();
|
||||
|
||||
checker.checkForUpdate();
|
||||
|
||||
QVERIFY(updateAvailableSpy.wait());
|
||||
QList<QVariant> res = result;
|
||||
res[0] = checker.m_channels[0].url;
|
||||
QCOMPARE(updateAvailableSpy.first(), res);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN_MULTIMC(UpdateCheckerTest)
|
||||
|
Loading…
Reference in New Issue
Block a user