TaskTree: Add a test for Storage input/output

StorageIO struct serves for an input/output interface to the recipe.
This makes the recipe even more universal and reusable.

Change-Id: Ifbd27452d2838e890eadb5e72e7e7c934c4ba840
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2023-08-31 20:10:31 +02:00
parent b8bd57adb7
commit 6f50addc1c

View File

@@ -67,6 +67,8 @@ private slots:
void validConstructs(); // compile test void validConstructs(); // compile test
void testTree_data(); void testTree_data();
void testTree(); void testTree();
void storageIO_data();
void storageIO();
void storageOperators(); void storageOperators();
void storageDestructor(); void storageDestructor();
}; };
@@ -2257,6 +2259,52 @@ void tst_Tasking::testTree()
QCOMPARE(result, testData.onDone); QCOMPARE(result, testData.onDone);
} }
struct StorageIO
{
int value = 0;
};
static Group inputOutputRecipe(const TreeStorage<StorageIO> &storage)
{
return Group {
Storage(storage),
onGroupSetup([storage] { ++storage->value; }),
onGroupDone([storage] { storage->value *= 2; })
};
}
void tst_Tasking::storageIO_data()
{
QTest::addColumn<int>("input");
QTest::addColumn<int>("output");
QTest::newRow("-1 -> 0") << -1 << 0;
QTest::newRow("0 -> 2") << 0 << 2;
QTest::newRow("1 -> 4") << 1 << 4;
QTest::newRow("2 -> 6") << 2 << 6;
}
void tst_Tasking::storageIO()
{
QFETCH(int, input);
QFETCH(int, output);
int actualOutput = 0;
const TreeStorage<StorageIO> storage;
TaskTree taskTree(inputOutputRecipe(storage));
const auto setInput = [input](StorageIO &storage) { storage.value = input; };
const auto getOutput = [&actualOutput](const StorageIO &storage) { actualOutput = storage.value; };
taskTree.onStorageSetup(storage, setInput);
taskTree.onStorageDone(storage, getOutput);
taskTree.runBlocking();
QCOMPARE(taskTree.isRunning(), false);
QCOMPARE(actualOutput, output);
}
void tst_Tasking::storageOperators() void tst_Tasking::storageOperators()
{ {
TreeStorageBase storage1 = TreeStorage<CustomStorage>(); TreeStorageBase storage1 = TreeStorage<CustomStorage>();