2013-12-14 13:53:18 +00:00
# include <QTest>
2013-12-14 15:02:51 +00:00
# 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"
2013-12-14 15:02:51 +00:00
Q_DECLARE_METATYPE ( UpdateChecker : : ChannelListEntry )
bool operator = = ( const UpdateChecker : : ChannelListEntry & e1 , const UpdateChecker : : ChannelListEntry & e2 )
{
2016-04-12 23:24:55 +00:00
qDebug ( ) < < e1 . url < < " vs " < < e2 . url ;
2013-12-14 15:02:51 +00:00
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
2013-12-16 19:10:11 +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 ( )
{
}
2013-12-14 15:02:51 +00:00
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 " ) ;
2013-12-14 18:19:14 +00:00
QTest : : addColumn < bool > ( " valid " ) ;
2013-12-14 15:02:51 +00:00
QTest : : addColumn < QList < UpdateChecker : : ChannelListEntry > > ( " result " ) ;
2013-12-14 18:19:14 +00:00
QTest : : newRow ( " garbage " )
< < QString ( )
2016-04-13 23:23:54 +00:00
< < findTestDataUrl ( " data/garbageChannels.json " )
2013-12-14 18:19:14 +00:00
< < false
< < false
< < QList < UpdateChecker : : ChannelListEntry > ( ) ;
QTest : : newRow ( " errors " )
< < QString ( )
2016-04-13 23:23:54 +00:00
< < findTestDataUrl ( " data/errorChannels.json " )
2013-12-14 18:19:14 +00:00
< < false
< < true
< < QList < UpdateChecker : : ChannelListEntry > ( ) ;
2013-12-14 15:02:51 +00:00
QTest : : newRow ( " no channels " )
< < QString ( )
2016-04-13 23:23:54 +00:00
< < findTestDataUrl ( " data/noChannels.json " )
2013-12-14 15:02:51 +00:00
< < false
2013-12-14 18:19:14 +00:00
< < true
2013-12-14 15:02:51 +00:00
< < QList < UpdateChecker : : ChannelListEntry > ( ) ;
QTest : : newRow ( " one channel " )
< < QString ( " develop " )
2016-04-13 23:23:54 +00:00
< < findTestDataUrl ( " data/oneChannel.json " )
2013-12-14 15:02:51 +00:00
< < true
2013-12-14 18:19:14 +00:00
< < true
2013-12-14 15:02:51 +00:00
< < ( QList < UpdateChecker : : ChannelListEntry > ( ) < < UpdateChecker : : ChannelListEntry { " develop " , " Develop " , " The channel called \" develop \" " , " http://example.org/stuff " } ) ;
QTest : : newRow ( " several channels " )
< < QString ( " develop " )
2016-04-13 23:23:54 +00:00
< < findTestDataUrl ( " data/channels.json " )
2013-12-14 15:02:51 +00:00
< < true
2013-12-14 18:19:14 +00:00
< < true
2013-12-14 15:02:51 +00:00
< < ( QList < UpdateChecker : : ChannelListEntry > ( )
2016-04-13 23:23:54 +00:00
< < UpdateChecker : : ChannelListEntry { " develop " , " Develop " , " The channel called \" develop \" " , findTestDataUrl ( " data " ) }
< < UpdateChecker : : ChannelListEntry { " stable " , " Stable " , " It's stable at least " , findTestDataUrl ( " data " ) }
2013-12-14 15:02:51 +00:00
< < 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 ( )
{
2014-01-05 22:24:05 +00:00
2013-12-14 15:02:51 +00:00
QFETCH ( QString , channel ) ;
QFETCH ( QString , channelUrl ) ;
QFETCH ( bool , hasChannels ) ;
2013-12-14 18:19:14 +00:00
QFETCH ( bool , valid ) ;
2013-12-14 15:02:51 +00:00
QFETCH ( QList < UpdateChecker : : ChannelListEntry > , result ) ;
2015-02-08 16:56:14 +00:00
UpdateChecker checker ( channelUrl , channel , 0 ) ;
2013-12-14 15:02:51 +00:00
2013-12-14 18:19:14 +00:00
QSignalSpy channelListLoadedSpy ( & checker , SIGNAL ( channelListLoaded ( ) ) ) ;
QVERIFY ( channelListLoadedSpy . isValid ( ) ) ;
2013-12-14 15:02:51 +00:00
2014-07-13 22:57:54 +00:00
checker . updateChanList ( false ) ;
2013-12-14 15:02:51 +00:00
2013-12-14 18:19:14 +00:00
if ( valid )
{
QVERIFY ( channelListLoadedSpy . wait ( ) ) ;
QCOMPARE ( channelListLoadedSpy . size ( ) , 1 ) ;
}
else
{
channelListLoadedSpy . wait ( ) ;
QCOMPARE ( channelListLoadedSpy . size ( ) , 0 ) ;
}
2013-12-14 15:02:51 +00:00
QCOMPARE ( checker . hasChannels ( ) , hasChannels ) ;
QCOMPARE ( checker . getChannelList ( ) , result ) ;
}
2014-01-05 22:24:05 +00:00
2013-12-14 18:19:14 +00:00
void tst_UpdateChecking ( )
{
2015-02-08 16:56:14 +00:00
QString channel = " develop " ;
2016-04-13 23:23:54 +00:00
QString channelUrl = findTestDataUrl ( " data/channels.json " ) ;
2015-02-08 16:56:14 +00:00
int currentBuild = 2 ;
2013-12-14 18:19:14 +00:00
2015-02-08 16:56:14 +00:00
UpdateChecker checker ( channelUrl , channel , currentBuild ) ;
2013-12-14 18:19:14 +00:00
2015-02-08 16:56:14 +00:00
QSignalSpy updateAvailableSpy ( & checker , SIGNAL ( updateAvailable ( GoUpdate : : Status ) ) ) ;
2013-12-14 18:19:14 +00:00
QVERIFY ( updateAvailableSpy . isValid ( ) ) ;
QSignalSpy channelListLoadedSpy ( & checker , SIGNAL ( channelListLoaded ( ) ) ) ;
QVERIFY ( channelListLoadedSpy . isValid ( ) ) ;
2014-07-13 22:57:54 +00:00
checker . updateChanList ( false ) ;
2013-12-14 18:19:14 +00:00
QVERIFY ( channelListLoadedSpy . wait ( ) ) ;
2015-01-31 18:21:47 +00:00
qDebug ( ) < < " CWD: " < < QDir : : current ( ) . absolutePath ( ) ;
2016-04-13 23:23:54 +00:00
checker . m_channels [ 0 ] . url = findTestDataUrl ( " data/ " ) ;
2015-01-31 15:59:03 +00:00
checker . checkForUpdate ( channel , false ) ;
2013-12-14 18:19:14 +00:00
QVERIFY ( updateAvailableSpy . wait ( ) ) ;
2015-02-08 16:56:14 +00:00
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 18:19:14 +00:00
}
2013-12-14 13:53:18 +00:00
} ;
2015-01-31 18:21:47 +00:00
QTEST_GUILESS_MAIN ( UpdateCheckerTest )
2013-12-14 13:53:18 +00:00
2016-04-13 23:23:54 +00:00
# include "UpdateChecker_test.moc"