forked from qt-creator/qt-creator
TaskTree: Refactor initialization tests
Use test data for zero and data initialization tests. Change-Id: Ice3a810845c442b418b374225b9434c2a2925430 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -119,8 +119,8 @@ private slots:
|
|||||||
void storageIO();
|
void storageIO();
|
||||||
void storageOperators();
|
void storageOperators();
|
||||||
void storageDestructor();
|
void storageDestructor();
|
||||||
void storageZeroInitialization();
|
void storageInitialization_data();
|
||||||
void storageDataInitialization();
|
void storageInitialization();
|
||||||
void nestedBrokenStorage();
|
void nestedBrokenStorage();
|
||||||
void restart();
|
void restart();
|
||||||
void destructorOfTaskEmittingDone();
|
void destructorOfTaskEmittingDone();
|
||||||
@@ -4088,34 +4088,31 @@ void tst_Tasking::storageDestructor()
|
|||||||
QVERIFY(!doneCalled);
|
QVERIFY(!doneCalled);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This test ensures that the storage data is zero-initialized.
|
void tst_Tasking::storageInitialization_data()
|
||||||
void tst_Tasking::storageZeroInitialization()
|
|
||||||
{
|
{
|
||||||
const Storage<int> storage;
|
QTest::addColumn<Storage<int>>("storage");
|
||||||
std::optional<int> defaultValue;
|
QTest::addColumn<int>("initValue");
|
||||||
|
|
||||||
const auto onSetup = [storage, &defaultValue] { defaultValue = *storage; };
|
// This test ensures that the storage data is zero-initialized.
|
||||||
|
QTest::newRow("zero initialization") << Storage<int>() << 0;
|
||||||
TaskTree taskTree({ storage, onGroupSetup(onSetup) });
|
// This test ensures that the storage c'tor with data is initialized properly.
|
||||||
taskTree.runBlocking();
|
QTest::newRow("data initialization") << Storage<int>(42) << 42;
|
||||||
|
|
||||||
QVERIFY(defaultValue);
|
|
||||||
QCOMPARE(*defaultValue, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This test ensures that the storage c'tor with data is initialized properly.
|
void tst_Tasking::storageInitialization()
|
||||||
void tst_Tasking::storageDataInitialization()
|
|
||||||
{
|
{
|
||||||
const Storage<int> storage(42);
|
QFETCH(Storage<int>, storage);
|
||||||
std::optional<int> defaultValue;
|
QFETCH(int, initValue);
|
||||||
|
|
||||||
const auto onSetup = [storage, &defaultValue] { defaultValue = *storage; };
|
std::optional<int> storageValue;
|
||||||
|
|
||||||
|
const auto onSetup = [storage, &storageValue] { storageValue = *storage; };
|
||||||
|
|
||||||
TaskTree taskTree({ storage, onGroupSetup(onSetup) });
|
TaskTree taskTree({ storage, onGroupSetup(onSetup) });
|
||||||
taskTree.runBlocking();
|
taskTree.runBlocking();
|
||||||
|
|
||||||
QVERIFY(defaultValue);
|
QVERIFY(storageValue);
|
||||||
QCOMPARE(*defaultValue, 42);
|
QCOMPARE(*storageValue, initValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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