forked from qt-creator/qt-creator
TaskTree: Introduce a bit of logic (NOT)
Introduce ExecutableItem operator!(const ExecutableItem &item). This operator returns a copy of this executable item with DoneResult tweaked by negation. If this item reports DoneResult::Success, the returned item reports DoneResult::Error. If this item reports DoneResult::Error, the returned item reports DoneResult::Success. Change-Id: Ie609938e92bbc38ddcc66f5bc3244f864e3e59c7 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -1510,6 +1510,14 @@ ExecutableItem ExecutableItem::withLog(const QString &logName) const
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExecutableItem operator!(const ExecutableItem &item)
|
||||||
|
{
|
||||||
|
return Group {
|
||||||
|
item,
|
||||||
|
onGroupDone([](DoneWith doneWith) { return toDoneResult(doneWith == DoneWith::Error); })
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
ExecutableItem ExecutableItem::withCancelImpl(
|
ExecutableItem ExecutableItem::withCancelImpl(
|
||||||
const std::function<void(QObject *, const std::function<void()> &)> &connectWrapper) const
|
const std::function<void(QObject *, const std::function<void()> &)> &connectWrapper) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -308,10 +308,14 @@ protected:
|
|||||||
ExecutableItem(const TaskHandler &handler) : GroupItem(handler) {}
|
ExecutableItem(const TaskHandler &handler) : GroupItem(handler) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend ExecutableItem operator!(const ExecutableItem &item);
|
||||||
|
|
||||||
ExecutableItem withCancelImpl(
|
ExecutableItem withCancelImpl(
|
||||||
const std::function<void(QObject *, const std::function<void()> &)> &connectWrapper) const;
|
const std::function<void(QObject *, const std::function<void()> &)> &connectWrapper) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TASKING_EXPORT ExecutableItem operator!(const ExecutableItem &item);
|
||||||
|
|
||||||
class TASKING_EXPORT Group : public ExecutableItem
|
class TASKING_EXPORT Group : public ExecutableItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -3213,6 +3213,53 @@ void tst_Tasking::testTree_data()
|
|||||||
<< TestData{storage, taskError, {{0, Handler::GroupError}}, 1, DoneWith::Error, 1};
|
<< TestData{storage, taskError, {{0, Handler::GroupError}}, 1, DoneWith::Error, 1};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// This test check if ExecutableItem's negation works OK
|
||||||
|
|
||||||
|
const Group negateSuccessTask {
|
||||||
|
storage,
|
||||||
|
!createSuccessTask(0)
|
||||||
|
};
|
||||||
|
|
||||||
|
const Group negateErrorTask {
|
||||||
|
storage,
|
||||||
|
!createFailingTask(0)
|
||||||
|
};
|
||||||
|
|
||||||
|
const Group negateSuccessGroup {
|
||||||
|
storage,
|
||||||
|
!Group {
|
||||||
|
createSuccessTask(0)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const Group negateErrorGroup {
|
||||||
|
storage,
|
||||||
|
!Group {
|
||||||
|
createFailingTask(0)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const Group doubleNegation {
|
||||||
|
storage,
|
||||||
|
!!createSuccessTask(0)
|
||||||
|
};
|
||||||
|
|
||||||
|
const Log successLog {{0, Handler::Setup}, {0, Handler::Success}};
|
||||||
|
const Log errorLog {{0, Handler::Setup}, {0, Handler::Error}};
|
||||||
|
|
||||||
|
QTest::newRow("NegateSuccessTask")
|
||||||
|
<< TestData{storage, negateSuccessTask, successLog, 1, DoneWith::Error, 1};
|
||||||
|
QTest::newRow("NegateErrorTask")
|
||||||
|
<< TestData{storage, negateErrorTask, errorLog, 1, DoneWith::Success, 1};
|
||||||
|
QTest::newRow("NegateSuccessGroup")
|
||||||
|
<< TestData{storage, negateSuccessGroup, successLog, 1, DoneWith::Error, 1};
|
||||||
|
QTest::newRow("NegateErrorGroup")
|
||||||
|
<< TestData{storage, negateErrorGroup, errorLog, 1, DoneWith::Success, 1};
|
||||||
|
QTest::newRow("DoubleNegation")
|
||||||
|
<< TestData{storage, doubleNegation, successLog, 1, DoneWith::Success, 1};
|
||||||
|
}
|
||||||
|
|
||||||
// This test checks if storage shadowing works OK.
|
// This test checks if storage shadowing works OK.
|
||||||
QTest::newRow("StorageShadowing") << storageShadowingData();
|
QTest::newRow("StorageShadowing") << storageShadowingData();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user