NOISSUE continue refactoring things to make tests pass
This commit is contained in:
@ -26,8 +26,12 @@
|
||||
namespace GoUpdate
|
||||
{
|
||||
|
||||
DownloadTask::DownloadTask(Status status, QString target, QObject *parent)
|
||||
: Task(parent), m_updateFilesDir(target)
|
||||
DownloadTask::DownloadTask(
|
||||
shared_qobject_ptr<QNetworkAccessManager> network,
|
||||
Status status,
|
||||
QString target,
|
||||
QObject *parent
|
||||
) : Task(parent), m_updateFilesDir(target), m_network(network)
|
||||
{
|
||||
m_status = status;
|
||||
|
||||
@ -63,7 +67,7 @@ void DownloadTask::loadVersionInfo()
|
||||
connect(netJob, &NetJob::succeeded, this, &DownloadTask::processDownloadedVersionInfo);
|
||||
connect(netJob, &NetJob::failed, this, &DownloadTask::vinfoDownloadFailed);
|
||||
m_vinfoNetJob.reset(netJob);
|
||||
netJob->start();
|
||||
netJob->start(m_network);
|
||||
}
|
||||
|
||||
void DownloadTask::vinfoDownloadFailed()
|
||||
@ -117,7 +121,7 @@ void DownloadTask::processDownloadedVersionInfo()
|
||||
setStatus(tr("Processing file lists - figuring out how to install the update..."));
|
||||
|
||||
// make a new netjob for the actual update files
|
||||
NetJobPtr netJob (new NetJob("Update Files"));
|
||||
NetJob::Ptr netJob (new NetJob("Update Files"));
|
||||
|
||||
// fill netJob and operationList
|
||||
if (!processFileLists(m_currentVersionFileList, m_newVersionFileList, m_status.rootPath, m_updateFilesDir.path(), netJob, m_operations))
|
||||
@ -141,7 +145,7 @@ void DownloadTask::processDownloadedVersionInfo()
|
||||
}
|
||||
qDebug() << "Begin downloading update files to" << m_updateFilesDir.path();
|
||||
m_filesNetJob = netJob;
|
||||
m_filesNetJob->start();
|
||||
m_filesNetJob->start(m_network);
|
||||
}
|
||||
|
||||
void DownloadTask::fileDownloadFinished()
|
||||
|
@ -35,7 +35,7 @@ public:
|
||||
*
|
||||
* target is a template - XXXXXX at the end will be replaced with a random generated string, ensuring uniqueness
|
||||
*/
|
||||
explicit DownloadTask(Status status, QString target, QObject* parent = 0);
|
||||
explicit DownloadTask(shared_qobject_ptr<QNetworkAccessManager> network, Status status, QString target, QObject* parent = 0);
|
||||
virtual ~DownloadTask() {};
|
||||
|
||||
/// Get the directory that will contain the update files.
|
||||
@ -62,13 +62,13 @@ protected:
|
||||
*/
|
||||
void loadVersionInfo();
|
||||
|
||||
NetJobPtr m_vinfoNetJob;
|
||||
NetJob::Ptr m_vinfoNetJob;
|
||||
QByteArray currentVersionFileListData;
|
||||
QByteArray newVersionFileListData;
|
||||
Net::Download::Ptr m_currentVersionFileListDownload;
|
||||
Net::Download::Ptr m_newVersionFileListDownload;
|
||||
|
||||
NetJobPtr m_filesNetJob;
|
||||
NetJob::Ptr m_filesNetJob;
|
||||
|
||||
Status m_status;
|
||||
|
||||
@ -91,6 +91,9 @@ protected slots:
|
||||
void fileDownloadFinished();
|
||||
void fileDownloadFailed(QString reason);
|
||||
void fileDownloadProgressChanged(qint64 current, qint64 total);
|
||||
|
||||
private:
|
||||
shared_qobject_ptr<QNetworkAccessManager> m_network;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ bool processFileLists
|
||||
const VersionFileList &newVersion,
|
||||
const QString &rootPath,
|
||||
const QString &tempPath,
|
||||
NetJobPtr job,
|
||||
NetJob::Ptr job,
|
||||
OperationList &ops
|
||||
)
|
||||
{
|
||||
|
@ -117,7 +117,7 @@ bool processFileLists
|
||||
const VersionFileList &newVersion,
|
||||
const QString &rootPath,
|
||||
const QString &tempPath,
|
||||
NetJobPtr job,
|
||||
NetJob::Ptr job,
|
||||
OperationList &ops
|
||||
);
|
||||
|
||||
|
@ -26,8 +26,9 @@
|
||||
#include "BuildConfig.h"
|
||||
#include "sys.h"
|
||||
|
||||
UpdateChecker::UpdateChecker(QString channelUrl, QString currentChannel, int currentBuild)
|
||||
UpdateChecker::UpdateChecker(shared_qobject_ptr<QNetworkAccessManager> nam, QString channelUrl, QString currentChannel, int currentBuild)
|
||||
{
|
||||
m_network = nam;
|
||||
m_channelUrl = channelUrl;
|
||||
m_currentChannel = currentChannel;
|
||||
m_currentBuild = currentBuild;
|
||||
@ -103,12 +104,11 @@ void UpdateChecker::checkForUpdate(QString updateChannel, bool notifyNoUpdate)
|
||||
|
||||
QUrl indexUrl = QUrl(m_newRepoUrl).resolved(QUrl("index.json"));
|
||||
|
||||
auto job = new NetJob("GoUpdate Repository Index");
|
||||
job->addNetAction(Net::Download::makeByteArray(indexUrl, &indexData));
|
||||
connect(job, &NetJob::succeeded, [this, notifyNoUpdate](){ updateCheckFinished(notifyNoUpdate); });
|
||||
connect(job, &NetJob::failed, this, &UpdateChecker::updateCheckFailed);
|
||||
indexJob.reset(job);
|
||||
job->start();
|
||||
indexJob = new NetJob("GoUpdate Repository Index");
|
||||
indexJob->addNetAction(Net::Download::makeByteArray(indexUrl, &indexData));
|
||||
connect(indexJob.get(), &NetJob::succeeded, [this, notifyNoUpdate](){ updateCheckFinished(notifyNoUpdate); });
|
||||
connect(indexJob.get(), &NetJob::failed, this, &UpdateChecker::updateCheckFailed);
|
||||
indexJob->start(m_network);
|
||||
}
|
||||
|
||||
void UpdateChecker::updateCheckFinished(bool notifyNoUpdate)
|
||||
@ -191,12 +191,11 @@ void UpdateChecker::updateChanList(bool notifyNoUpdate)
|
||||
}
|
||||
|
||||
m_chanListLoading = true;
|
||||
NetJob *job = new NetJob("Update System Channel List");
|
||||
job->addNetAction(Net::Download::makeByteArray(QUrl(m_channelUrl), &chanlistData));
|
||||
connect(job, &NetJob::succeeded, [this, notifyNoUpdate]() { chanListDownloadFinished(notifyNoUpdate); });
|
||||
QObject::connect(job, &NetJob::failed, this, &UpdateChecker::chanListDownloadFailed);
|
||||
chanListJob.reset(job);
|
||||
job->start();
|
||||
chanListJob = new NetJob("Update System Channel List");
|
||||
chanListJob->addNetAction(Net::Download::makeByteArray(QUrl(m_channelUrl), &chanlistData));
|
||||
connect(chanListJob.get(), &NetJob::succeeded, [this, notifyNoUpdate]() { chanListDownloadFinished(notifyNoUpdate); });
|
||||
connect(chanListJob.get(), &NetJob::failed, this, &UpdateChecker::chanListDownloadFailed);
|
||||
chanListJob->start(m_network);
|
||||
}
|
||||
|
||||
void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate)
|
||||
@ -233,10 +232,12 @@ void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate)
|
||||
for (QJsonValue chanVal : channelArray)
|
||||
{
|
||||
QJsonObject channelObj = chanVal.toObject();
|
||||
ChannelListEntry entry{channelObj.value("id").toVariant().toString(),
|
||||
channelObj.value("name").toVariant().toString(),
|
||||
channelObj.value("description").toVariant().toString(),
|
||||
channelObj.value("url").toVariant().toString()};
|
||||
ChannelListEntry entry {
|
||||
channelObj.value("id").toVariant().toString(),
|
||||
channelObj.value("name").toVariant().toString(),
|
||||
channelObj.value("description").toVariant().toString(),
|
||||
channelObj.value("url").toVariant().toString()
|
||||
};
|
||||
if (entry.id.isEmpty() || entry.name.isEmpty() || entry.url.isEmpty())
|
||||
{
|
||||
qCritical() << "Channel list entry with empty ID, name, or URL. Skipping.";
|
||||
@ -253,8 +254,9 @@ void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate)
|
||||
qDebug() << "Successfully loaded UpdateChecker channel list.";
|
||||
|
||||
// If we're waiting to check for updates, do that now.
|
||||
if (m_checkUpdateWaiting)
|
||||
if (m_checkUpdateWaiting) {
|
||||
checkForUpdate(m_deferredUpdateChannel, notifyNoUpdate);
|
||||
}
|
||||
|
||||
emit channelListLoaded();
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ class UpdateChecker : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UpdateChecker(QString channelUrl, QString currentChannel, int currentBuild);
|
||||
UpdateChecker(shared_qobject_ptr<QNetworkAccessManager> nam, QString channelUrl, QString currentChannel, int currentBuild);
|
||||
void checkForUpdate(QString updateChannel, bool notifyNoUpdate);
|
||||
|
||||
/*!
|
||||
@ -73,9 +73,11 @@ private slots:
|
||||
private:
|
||||
friend class UpdateCheckerTest;
|
||||
|
||||
NetJobPtr indexJob;
|
||||
shared_qobject_ptr<QNetworkAccessManager> m_network;
|
||||
|
||||
NetJob::Ptr indexJob;
|
||||
QByteArray indexData;
|
||||
NetJobPtr chanListJob;
|
||||
NetJob::Ptr chanListJob;
|
||||
QByteArray chanlistData;
|
||||
|
||||
QString m_channelUrl;
|
||||
|
@ -91,7 +91,8 @@ slots:
|
||||
QFETCH(bool, valid);
|
||||
QFETCH(QList<UpdateChecker::ChannelListEntry>, result);
|
||||
|
||||
UpdateChecker checker(channelUrl, channel, 0);
|
||||
shared_qobject_ptr<QNetworkAccessManager> nam = new QNetworkAccessManager();
|
||||
UpdateChecker checker(nam, channelUrl, channel, 0);
|
||||
|
||||
QSignalSpy channelListLoadedSpy(&checker, SIGNAL(channelListLoaded()));
|
||||
QVERIFY(channelListLoadedSpy.isValid());
|
||||
@ -119,7 +120,8 @@ slots:
|
||||
QString channelUrl = findTestDataUrl("data/channels.json");
|
||||
int currentBuild = 2;
|
||||
|
||||
UpdateChecker checker(channelUrl, channel, currentBuild);
|
||||
shared_qobject_ptr<QNetworkAccessManager> nam = new QNetworkAccessManager();
|
||||
UpdateChecker checker(nam, channelUrl, channel, currentBuild);
|
||||
|
||||
QSignalSpy updateAvailableSpy(&checker, SIGNAL(updateAvailable(GoUpdate::Status)));
|
||||
QVERIFY(updateAvailableSpy.isValid());
|
||||
|
Reference in New Issue
Block a user