Merge pull request #409 from flowln/tasks
This commit is contained in:
commit
ab8d897bd7
@ -413,6 +413,11 @@ set(TASKS_SOURCES
|
|||||||
tasks/SequentialTask.cpp
|
tasks/SequentialTask.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_unit_test(Task
|
||||||
|
SOURCES tasks/Task_test.cpp
|
||||||
|
LIBS Launcher_logic
|
||||||
|
)
|
||||||
|
|
||||||
set(SETTINGS_SOURCES
|
set(SETTINGS_SOURCES
|
||||||
# Settings
|
# Settings
|
||||||
settings/INIFile.cpp
|
settings/INIFile.cpp
|
||||||
|
@ -40,6 +40,14 @@ InstanceImportTask::InstanceImportTask(const QUrl sourceUrl)
|
|||||||
m_sourceUrl = sourceUrl;
|
m_sourceUrl = sourceUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool InstanceImportTask::abort()
|
||||||
|
{
|
||||||
|
m_filesNetJob->abort();
|
||||||
|
m_extractFuture.cancel();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void InstanceImportTask::executeTask()
|
void InstanceImportTask::executeTask()
|
||||||
{
|
{
|
||||||
if (m_sourceUrl.isLocalFile())
|
if (m_sourceUrl.isLocalFile())
|
||||||
|
@ -37,6 +37,9 @@ class InstanceImportTask : public InstanceTask
|
|||||||
public:
|
public:
|
||||||
explicit InstanceImportTask(const QUrl sourceUrl);
|
explicit InstanceImportTask(const QUrl sourceUrl);
|
||||||
|
|
||||||
|
bool canAbort() const override { return true; }
|
||||||
|
bool abort() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Entry point for tasks.
|
//! Entry point for tasks.
|
||||||
virtual void executeTask() override;
|
virtual void executeTask() override;
|
||||||
|
@ -53,7 +53,7 @@ class Task : public QObject {
|
|||||||
virtual bool canAbort() const { return false; }
|
virtual bool canAbort() const { return false; }
|
||||||
|
|
||||||
QString getStatus() { return m_status; }
|
QString getStatus() { return m_status; }
|
||||||
virtual auto getStepStatus() const -> QString { return {}; }
|
virtual auto getStepStatus() const -> QString { return m_status; }
|
||||||
|
|
||||||
qint64 getProgress() { return m_progress; }
|
qint64 getProgress() { return m_progress; }
|
||||||
qint64 getTotalProgress() { return m_progressTotal; }
|
qint64 getTotalProgress() { return m_progressTotal; }
|
||||||
|
68
launcher/tasks/Task_test.cpp
Normal file
68
launcher/tasks/Task_test.cpp
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#include <QTest>
|
||||||
|
#include "TestUtil.h"
|
||||||
|
|
||||||
|
#include "Task.h"
|
||||||
|
|
||||||
|
/* Does nothing. Only used for testing. */
|
||||||
|
class BasicTask : public Task {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
friend class TaskTest;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void executeTask() override {};
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Does nothing. Only used for testing. */
|
||||||
|
class BasicTask_MultiStep : public Task {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
friend class TaskTest;
|
||||||
|
|
||||||
|
private:
|
||||||
|
auto isMultiStep() const -> bool override { return true; }
|
||||||
|
|
||||||
|
void executeTask() override {};
|
||||||
|
};
|
||||||
|
|
||||||
|
class TaskTest : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void test_SetStatus_NoMultiStep(){
|
||||||
|
BasicTask t;
|
||||||
|
QString status {"test status"};
|
||||||
|
|
||||||
|
t.setStatus(status);
|
||||||
|
|
||||||
|
QCOMPARE(t.getStatus(), status);
|
||||||
|
QCOMPARE(t.getStepStatus(), status);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_SetStatus_MultiStep(){
|
||||||
|
BasicTask_MultiStep t;
|
||||||
|
QString status {"test status"};
|
||||||
|
|
||||||
|
t.setStatus(status);
|
||||||
|
|
||||||
|
QCOMPARE(t.getStatus(), status);
|
||||||
|
// Even though it is multi step, it does not override the getStepStatus method,
|
||||||
|
// so it should remain the same.
|
||||||
|
QCOMPARE(t.getStepStatus(), status);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_SetProgress(){
|
||||||
|
BasicTask t;
|
||||||
|
int current = 42;
|
||||||
|
int total = 207;
|
||||||
|
|
||||||
|
t.setProgress(current, total);
|
||||||
|
|
||||||
|
QCOMPARE(t.getProgress(), current);
|
||||||
|
QCOMPARE(t.getTotalProgress(), total);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
QTEST_GUILESS_MAIN(TaskTest)
|
||||||
|
|
||||||
|
#include "Task_test.moc"
|
Loading…
Reference in New Issue
Block a user