Tests for parsing of channel lists in UpdateChecker
This commit is contained in:
parent
ac2721e954
commit
a02e62f17f
@ -44,7 +44,7 @@ QList<UpdateChecker::ChannelListEntry> UpdateChecker::getChannelList() const
|
|||||||
|
|
||||||
bool UpdateChecker::hasChannels() const
|
bool UpdateChecker::hasChannels() const
|
||||||
{
|
{
|
||||||
return m_channels.isEmpty();
|
return !m_channels.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateChecker::checkForUpdate()
|
void UpdateChecker::checkForUpdate()
|
||||||
|
@ -27,6 +27,9 @@ public:
|
|||||||
UpdateChecker();
|
UpdateChecker();
|
||||||
void checkForUpdate();
|
void checkForUpdate();
|
||||||
|
|
||||||
|
void setCurrentChannel(const QString &channel) { m_currentChannel = channel; }
|
||||||
|
void setChannelListUrl(const QString &url) { m_channelListUrl = url; }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Causes the update checker to download the channel list from the URL specified in config.h (generated by CMake).
|
* Causes the update checker to download the channel list from the URL specified in config.h (generated by CMake).
|
||||||
* If this isn't called before checkForUpdate(), it will automatically be called.
|
* If this isn't called before checkForUpdate(), it will automatically be called.
|
||||||
|
23
tests/data/channels.json
Normal file
23
tests/data/channels.json
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"format_version": 0,
|
||||||
|
"channels": [
|
||||||
|
{
|
||||||
|
"id": "develop",
|
||||||
|
"name": "Develop",
|
||||||
|
"description": "The channel called \"develop\"",
|
||||||
|
"url": "http://example.org/stuff"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "stable",
|
||||||
|
"name": "Stable",
|
||||||
|
"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": "https://dent.me/tea"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
5
tests/data/noChannels.json
Normal file
5
tests/data/noChannels.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"format_version": 0,
|
||||||
|
"channels": [
|
||||||
|
]
|
||||||
|
}
|
11
tests/data/oneChannel.json
Normal file
11
tests/data/oneChannel.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"format_version": 0,
|
||||||
|
"channels": [
|
||||||
|
{
|
||||||
|
"id": "develop",
|
||||||
|
"name": "Develop",
|
||||||
|
"description": "The channel called \"develop\"",
|
||||||
|
"url": "http://example.org/stuff"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -1,6 +1,18 @@
|
|||||||
#include <QTest>
|
#include <QTest>
|
||||||
|
#include <QSignalSpy>
|
||||||
|
|
||||||
#include "TestUtil.h"
|
#include "TestUtil.h"
|
||||||
|
#include "logic/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;
|
||||||
|
}
|
||||||
|
|
||||||
class UpdateCheckerTest : public QObject
|
class UpdateCheckerTest : public QObject
|
||||||
{
|
{
|
||||||
@ -15,8 +27,63 @@ slots:
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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<QList<UpdateChecker::ChannelListEntry> >("result");
|
||||||
|
|
||||||
|
QTest::newRow("no channels")
|
||||||
|
<< QString()
|
||||||
|
<< findTestDataUrl("tests/data/noChannels.json")
|
||||||
|
<< false
|
||||||
|
<< QList<UpdateChecker::ChannelListEntry>();
|
||||||
|
QTest::newRow("one channel")
|
||||||
|
<< QString("develop")
|
||||||
|
<< findTestDataUrl("tests/data/oneChannel.json")
|
||||||
|
<< 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
|
||||||
|
<< (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"}
|
||||||
|
<< 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(QList<UpdateChecker::ChannelListEntry>, result);
|
||||||
|
|
||||||
|
UpdateChecker checker;
|
||||||
|
|
||||||
|
QSignalSpy spy(&checker, SIGNAL(channelListLoaded()));
|
||||||
|
QVERIFY(spy.isValid());
|
||||||
|
|
||||||
|
checker.setCurrentChannel(channel);
|
||||||
|
checker.setChannelListUrl(channelUrl);
|
||||||
|
|
||||||
|
checker.updateChanList();
|
||||||
|
|
||||||
|
QVERIFY(spy.wait());
|
||||||
|
|
||||||
|
QCOMPARE(spy.size(), 1);
|
||||||
|
|
||||||
|
QCOMPARE(checker.hasChannels(), hasChannels);
|
||||||
|
QCOMPARE(checker.getChannelList(), result);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
QTEST_GUILESS_MAIN(UpdateCheckerTest)
|
QTEST_GUILESS_MAIN_MULTIMC(UpdateCheckerTest)
|
||||||
|
|
||||||
#include "tst_UpdateChecker.moc"
|
#include "tst_UpdateChecker.moc"
|
||||||
|
Loading…
Reference in New Issue
Block a user