From 4f0758d660b8387af2bdcc5c80bd8f377cb721f0 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Fri, 13 Sep 2024 23:11:38 +0200 Subject: [PATCH] TaskTree: Refactor initialization tests Use test data for zero and data initialization tests. Change-Id: Ice3a810845c442b418b374225b9434c2a2925430 Reviewed-by: hjk --- tests/auto/solutions/tasking/tst_tasking.cpp | 37 +++++++++----------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/tests/auto/solutions/tasking/tst_tasking.cpp b/tests/auto/solutions/tasking/tst_tasking.cpp index 960e10b9cb8..b40dd39e82f 100644 --- a/tests/auto/solutions/tasking/tst_tasking.cpp +++ b/tests/auto/solutions/tasking/tst_tasking.cpp @@ -119,8 +119,8 @@ private slots: void storageIO(); void storageOperators(); void storageDestructor(); - void storageZeroInitialization(); - void storageDataInitialization(); + void storageInitialization_data(); + void storageInitialization(); void nestedBrokenStorage(); void restart(); void destructorOfTaskEmittingDone(); @@ -4088,34 +4088,31 @@ void tst_Tasking::storageDestructor() QVERIFY(!doneCalled); } -// This test ensures that the storage data is zero-initialized. -void tst_Tasking::storageZeroInitialization() +void tst_Tasking::storageInitialization_data() { - const Storage storage; - std::optional defaultValue; + QTest::addColumn>("storage"); + QTest::addColumn("initValue"); - const auto onSetup = [storage, &defaultValue] { defaultValue = *storage; }; - - TaskTree taskTree({ storage, onGroupSetup(onSetup) }); - taskTree.runBlocking(); - - QVERIFY(defaultValue); - QCOMPARE(*defaultValue, 0); + // This test ensures that the storage data is zero-initialized. + QTest::newRow("zero initialization") << Storage() << 0; + // This test ensures that the storage c'tor with data is initialized properly. + QTest::newRow("data initialization") << Storage(42) << 42; } -// This test ensures that the storage c'tor with data is initialized properly. -void tst_Tasking::storageDataInitialization() +void tst_Tasking::storageInitialization() { - const Storage storage(42); - std::optional defaultValue; + QFETCH(Storage, storage); + QFETCH(int, initValue); - const auto onSetup = [storage, &defaultValue] { defaultValue = *storage; }; + std::optional storageValue; + + const auto onSetup = [storage, &storageValue] { storageValue = *storage; }; TaskTree taskTree({ storage, onGroupSetup(onSetup) }); taskTree.runBlocking(); - QVERIFY(defaultValue); - QCOMPARE(*defaultValue, 42); + QVERIFY(storageValue); + QCOMPARE(*storageValue, initValue); } // This test ensures that when a missing storage object inside the nested task tree is accessed