1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
/*
This software is in the public domain, furnished "as is", without technical
support, and with no warranty, express or implied, as to its usefulness for
any purpose.
*/
#include <QtTest>
#include "updater/updater.h"
#include "updater/ocupdater.h"
namespace OCC {
class TestUpdater : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testDownload_data()
{
QTest::addColumn<QString>("url");
QTest::addColumn<OCUpdater::DownloadState>("result");
// a redirect to attic
QTest::newRow("redirect") << "https://download.owncloud.com/desktop/stable/ownCloud-2.2.4.6408-setup.exe" << OCUpdater::DownloadComplete;
QTest::newRow("broken url") << "https://&" << OCUpdater::DownloadFailed;
}
void testDownload()
{
QFETCH(QString, url);
QFETCH(OCUpdater::DownloadState, result);
UpdateInfo info;
info.setDownloadUrl(url);
info.setVersionString(QStringLiteral("ownCloud 2.2.4 (build 6408)"));
// esnure we do the update
info.setVersion(QStringLiteral("100.2.4.6408"));
auto *updater = new WindowsUpdater({});
QSignalSpy downloadSpy(updater, &WindowsUpdater::downloadStateChanged);
updater->versionInfoArrived(info);
// we might have multiple state changes allow them to happen
for (int i = 0; i <= OCUpdater::UpdateOnlyAvailableThroughSystem; ++i) {
// wait up to a minute, we are actually downloading a file
if (!downloadSpy.wait(60000)) {
// we timed out
break;
}
if (updater->downloadState() == result) {
break;
}
}
QCOMPARE(updater->downloadState(), result);
updater->deleteLater();
}
};
}
QTEST_MAIN(OCC::TestUpdater)
#include "testupdater.moc"
|