forked from qt-creator/qt-creator
TaskTree: Make it possible to pass the init data to the Storage
Add a storage c'tor taking the StorageData data as an argument. Later, when the StorageData is created by the running task tree, this data is used to initialize the newly created storage. Add a test for it. Change-Id: I05ce7831df7b378035b44b2d1053b5b25fb910d3 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -181,6 +181,8 @@ class Storage final : public StorageBase
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Storage() : StorageBase(Storage::ctor(), Storage::dtor()) {}
|
Storage() : StorageBase(Storage::ctor(), Storage::dtor()) {}
|
||||||
|
Storage(const StorageStruct &data)
|
||||||
|
: StorageBase([data] { return new StorageStruct(data); }, Storage::dtor()) {}
|
||||||
StorageStruct &operator*() const noexcept { return *activeStorage(); }
|
StorageStruct &operator*() const noexcept { return *activeStorage(); }
|
||||||
StorageStruct *operator->() const noexcept { return activeStorage(); }
|
StorageStruct *operator->() const noexcept { return activeStorage(); }
|
||||||
StorageStruct *activeStorage() const {
|
StorageStruct *activeStorage() const {
|
||||||
|
@@ -120,6 +120,7 @@ private slots:
|
|||||||
void storageOperators();
|
void storageOperators();
|
||||||
void storageDestructor();
|
void storageDestructor();
|
||||||
void storageZeroInitialization();
|
void storageZeroInitialization();
|
||||||
|
void storageDataInitialization();
|
||||||
void nestedBrokenStorage();
|
void nestedBrokenStorage();
|
||||||
void restart();
|
void restart();
|
||||||
void destructorOfTaskEmittingDone();
|
void destructorOfTaskEmittingDone();
|
||||||
@@ -4114,7 +4115,22 @@ void tst_Tasking::storageZeroInitialization()
|
|||||||
taskTree.runBlocking();
|
taskTree.runBlocking();
|
||||||
|
|
||||||
QVERIFY(defaultValue);
|
QVERIFY(defaultValue);
|
||||||
QCOMPARE(defaultValue, 0);
|
QCOMPARE(*defaultValue, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This test ensures that the storage c'tor with data is initialized properly.
|
||||||
|
void tst_Tasking::storageDataInitialization()
|
||||||
|
{
|
||||||
|
const Storage<int> storage(42);
|
||||||
|
std::optional<int> defaultValue;
|
||||||
|
|
||||||
|
const auto onSetup = [storage, &defaultValue] { defaultValue = *storage; };
|
||||||
|
|
||||||
|
TaskTree taskTree({ storage, onGroupSetup(onSetup) });
|
||||||
|
taskTree.runBlocking();
|
||||||
|
|
||||||
|
QVERIFY(defaultValue);
|
||||||
|
QCOMPARE(*defaultValue, 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This test ensures that when a missing storage object inside the nested task tree is accessed
|
// This test ensures that when a missing storage object inside the nested task tree is accessed
|
||||||
|
Reference in New Issue
Block a user