forked from qt-creator/qt-creator
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:
@@ -67,6 +67,8 @@ private slots:
|
||||
void validConstructs(); // compile test
|
||||
void testTree_data();
|
||||
void testTree();
|
||||
void storageIO_data();
|
||||
void storageIO();
|
||||
void storageOperators();
|
||||
void storageDestructor();
|
||||
};
|
||||
@@ -2257,6 +2259,52 @@ void tst_Tasking::testTree()
|
||||
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()
|
||||
{
|
||||
TreeStorageBase storage1 = TreeStorage<CustomStorage>();
|
||||
|
Reference in New Issue
Block a user