forked from qt-creator/qt-creator
TaskTree: Add static asserts to onStorage{Setup,Done} handlers
Require const reference for onStorageDone() handler. Change-Id: Iad333c04a78962a3361635900027bd4d41abc319 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -413,11 +413,21 @@ public:
|
||||
|
||||
template <typename StorageStruct, typename StorageHandler>
|
||||
void onStorageSetup(const TreeStorage<StorageStruct> &storage, StorageHandler &&handler) {
|
||||
constexpr bool isInvokable = std::is_invocable_v<std::decay_t<StorageHandler>,
|
||||
StorageStruct &>;
|
||||
static_assert(isInvokable,
|
||||
"Storage setup handler needs to take (Storage &) as an argument. "
|
||||
"The passed handler doesn't fulfill these requirements.");
|
||||
setupStorageHandler(storage,
|
||||
wrapHandler<StorageStruct>(std::forward<StorageHandler>(handler)), {});
|
||||
}
|
||||
template <typename StorageStruct, typename StorageHandler>
|
||||
void onStorageDone(const TreeStorage<StorageStruct> &storage, StorageHandler &&handler) {
|
||||
constexpr bool isInvokable = std::is_invocable_v<std::decay_t<StorageHandler>,
|
||||
const StorageStruct &>;
|
||||
static_assert(isInvokable,
|
||||
"Storage done handler needs to take (const Storage &) as an argument. "
|
||||
"The passed handler doesn't fulfill these requirements.");
|
||||
setupStorageHandler(storage,
|
||||
{}, wrapHandler<StorageStruct>(std::forward<StorageHandler>(handler)));
|
||||
}
|
||||
|
@@ -550,7 +550,7 @@ void tst_Tasking::testTree_data()
|
||||
};
|
||||
taskTree.setRecipe(nestedRoot);
|
||||
CustomStorage *activeStorage = storage.activeStorage();
|
||||
const auto collectSubLog = [activeStorage](CustomStorage &subTreeStorage){
|
||||
const auto collectSubLog = [activeStorage](const CustomStorage &subTreeStorage){
|
||||
activeStorage->m_log += subTreeStorage.m_log;
|
||||
};
|
||||
taskTree.onStorageDone(storage, collectSubLog);
|
||||
@@ -2244,7 +2244,9 @@ void tst_Tasking::testTree()
|
||||
TaskTree taskTree({testData.root.withTimeout(1000ms)});
|
||||
QCOMPARE(taskTree.taskCount() - 1, testData.taskCount); // -1 for the timeout task above
|
||||
Log actualLog;
|
||||
const auto collectLog = [&actualLog](CustomStorage &storage) { actualLog = storage.m_log; };
|
||||
const auto collectLog = [&actualLog](const CustomStorage &storage) {
|
||||
actualLog = storage.m_log;
|
||||
};
|
||||
taskTree.onStorageDone(testData.storage, collectLog);
|
||||
const OnDone result = taskTree.runBlocking() ? OnDone::Success : OnDone::Failure;
|
||||
QCOMPARE(taskTree.isRunning(), false);
|
||||
@@ -2278,7 +2280,7 @@ void tst_Tasking::storageDestructor()
|
||||
setupCalled = true;
|
||||
};
|
||||
bool doneCalled = false;
|
||||
const auto doneHandler = [&doneCalled](CustomStorage &) {
|
||||
const auto doneHandler = [&doneCalled](const CustomStorage &) {
|
||||
doneCalled = true;
|
||||
};
|
||||
QCOMPARE(CustomStorage::instanceCount(), 0);
|
||||
|
Reference in New Issue
Block a user