| 31 | }; |
| 32 | |
| 33 | class TaskTest : public QObject { |
| 34 | Q_OBJECT |
| 35 | |
| 36 | private slots: |
| 37 | void test_SetStatus_NoMultiStep(){ |
| 38 | BasicTask t; |
| 39 | QString status {"test status"}; |
| 40 | |
| 41 | t.setStatus(status); |
| 42 | |
| 43 | QCOMPARE(t.getStatus(), status); |
| 44 | QCOMPARE(t.getStepStatus(), status); |
| 45 | } |
| 46 | |
| 47 | void test_SetStatus_MultiStep(){ |
| 48 | BasicTask_MultiStep t; |
| 49 | QString status {"test status"}; |
| 50 | |
| 51 | t.setStatus(status); |
| 52 | |
| 53 | QCOMPARE(t.getStatus(), status); |
| 54 | // Even though it is multi step, it does not override the getStepStatus method, |
| 55 | // so it should remain the same. |
| 56 | QCOMPARE(t.getStepStatus(), status); |
| 57 | } |
| 58 | |
| 59 | void test_SetProgress(){ |
| 60 | BasicTask t; |
| 61 | int current = 42; |
| 62 | int total = 207; |
| 63 | |
| 64 | t.setProgress(current, total); |
| 65 | |
| 66 | QCOMPARE(t.getProgress(), current); |
| 67 | QCOMPARE(t.getTotalProgress(), total); |
| 68 | } |
| 69 | |
| 70 | void test_basicRun(){ |
| 71 | BasicTask t; |
| 72 | QObject::connect(&t, &Task::finished, [&]{ QVERIFY2(t.wasSuccessful(), "Task finished but was not successful when it should have been."); }); |
| 73 | t.start(); |
| 74 | |
| 75 | QVERIFY2(QTest::qWaitFor([&]() { |
| 76 | return t.isFinished(); |
| 77 | }, 1000), "Task didn't finish as it should."); |
| 78 | } |
| 79 | |
| 80 | void test_basicConcurrentRun(){ |
| 81 | BasicTask t1; |
| 82 | BasicTask t2; |
| 83 | BasicTask t3; |
| 84 | |
| 85 | ConcurrentTask t; |
| 86 | |
| 87 | t.addTask(&t1); |
| 88 | t.addTask(&t2); |
| 89 | t.addTask(&t3); |
| 90 |
nothing calls this directly
no test coverage detected