From be2512bb4b05738011bfe165e890bcdd23ae8e92 Mon Sep 17 00:00:00 2001 From: flow Date: Thu, 7 Apr 2022 18:41:32 -0300 Subject: [PATCH 1/4] fix: issue with status of non-sequencial tasks --- launcher/tasks/Task.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/tasks/Task.h b/launcher/tasks/Task.h index 47c249b3..344a024e 100644 --- a/launcher/tasks/Task.h +++ b/launcher/tasks/Task.h @@ -53,7 +53,7 @@ class Task : public QObject { virtual bool canAbort() const { return false; } 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 getTotalProgress() { return m_progressTotal; } From 167e32a69fc0b4224d10e7a3c7ce13e4cb4334c7 Mon Sep 17 00:00:00 2001 From: flow Date: Thu, 7 Apr 2022 18:56:34 -0300 Subject: [PATCH 2/4] fix: allow aborting CF modpack importing --- launcher/InstanceImportTask.cpp | 8 ++++++++ launcher/InstanceImportTask.h | 3 +++ 2 files changed, 11 insertions(+) diff --git a/launcher/InstanceImportTask.cpp b/launcher/InstanceImportTask.cpp index a825e8d4..03e942f1 100644 --- a/launcher/InstanceImportTask.cpp +++ b/launcher/InstanceImportTask.cpp @@ -40,6 +40,14 @@ InstanceImportTask::InstanceImportTask(const QUrl sourceUrl) m_sourceUrl = sourceUrl; } +bool InstanceImportTask::abort() +{ + m_filesNetJob->abort(); + m_extractFuture.cancel(); + + return false; +} + void InstanceImportTask::executeTask() { if (m_sourceUrl.isLocalFile()) diff --git a/launcher/InstanceImportTask.h b/launcher/InstanceImportTask.h index a1990647..365c3dc4 100644 --- a/launcher/InstanceImportTask.h +++ b/launcher/InstanceImportTask.h @@ -37,6 +37,9 @@ class InstanceImportTask : public InstanceTask public: explicit InstanceImportTask(const QUrl sourceUrl); + bool canAbort() const override { return true; } + bool abort() override; + protected: //! Entry point for tasks. virtual void executeTask() override; From d0cda6d6051a09826820da3cd96fe5dc36b274f0 Mon Sep 17 00:00:00 2001 From: flow Date: Thu, 7 Apr 2022 19:03:29 -0300 Subject: [PATCH 3/4] test: add basic Task unit test Only only two tests for now. We can iterate on this later :^) This is to try to avoid breaking things again! --- launcher/CMakeLists.txt | 5 +++++ launcher/tasks/Task_test.cpp | 42 ++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 launcher/tasks/Task_test.cpp diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 05af3503..42348792 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -413,6 +413,11 @@ set(TASKS_SOURCES tasks/SequentialTask.cpp ) +add_unit_test(Task + SOURCES tasks/Task_test.cpp + LIBS Launcher_logic + ) + set(SETTINGS_SOURCES # Settings settings/INIFile.cpp diff --git a/launcher/tasks/Task_test.cpp b/launcher/tasks/Task_test.cpp new file mode 100644 index 00000000..a9a28bd0 --- /dev/null +++ b/launcher/tasks/Task_test.cpp @@ -0,0 +1,42 @@ +#include +#include "TestUtil.h" + +#include "Task.h" + +/* Does nothing. Only used for testing. */ +class BasicTask : public Task { + Q_OBJECT + public: + explicit BasicTask() : Task() {}; + private: + void executeTask() override {}; +}; + +class TaskTest : public QObject { + Q_OBJECT + + private slots: + void test_SetStatus(){ + BasicTask t; + QString status {"test status"}; + + t.setStatus(status); + + QCOMPARE(t.getStatus(), 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" From eeae3eca6719a43a3dd868c37e9f31b4463f4924 Mon Sep 17 00:00:00 2001 From: flow Date: Thu, 7 Apr 2022 19:42:26 -0300 Subject: [PATCH 4/4] test: add new test to Task test Also adds one more check to setStatus test --- launcher/tasks/Task_test.cpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/launcher/tasks/Task_test.cpp b/launcher/tasks/Task_test.cpp index a9a28bd0..9b6cc2e5 100644 --- a/launcher/tasks/Task_test.cpp +++ b/launcher/tasks/Task_test.cpp @@ -6,23 +6,49 @@ /* Does nothing. Only used for testing. */ class BasicTask : public Task { Q_OBJECT - public: - explicit BasicTask() : Task() {}; + + 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(){ + 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(){