AutoTest: Add report helper function

Adds a report() function which generates a simple string
holding the number of items per framework root node and
uses it inside the logging after a full parse.

Change-Id: Ib4be89de778aeab7e9c80b5c0522ee7f3f1bb587
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2023-08-31 09:59:49 +02:00
parent 25e1266c26
commit 792c74b47a
3 changed files with 69 additions and 0 deletions

View File

@@ -500,6 +500,40 @@ void TestTreeModel::sweep()
#endif
}
QString TestTreeModel::report(bool full) const
{
QString result;
int items = 0;
QString tree;
for (TestTreeItem *rootNode : frameworkRootNodes()) {
int itemsPerRoot = 0;
result.append("\n");
result += rootNode->name();
result.append(" > ");
if (full) {
TestTreeSortFilterModel sortFilterModel(const_cast<TestTreeModel *>(this));
sortFilterModel.setDynamicSortFilter(true);
sortFilterModel.sort(0);
tree = "\n" + sortFilterModel.report();
rootNode->forAllChildren([&itemsPerRoot](TreeItem *) {
++itemsPerRoot;
});
} else {
rootNode->forAllChildren([&itemsPerRoot](TreeItem *) {
++itemsPerRoot;
});
}
result.append(QString::number(itemsPerRoot));
items += itemsPerRoot;
}
result.append("\nItems: " + QString::number(items));
if (full)
return tree + '\n' + result;
return result;
}
/**
* @note after calling this function emit testTreeModelChanged() if it returns true
*/
@@ -891,6 +925,26 @@ TestTreeSortFilterModel::FilterMode TestTreeSortFilterModel::toFilterMode(int f)
}
}
static QString dumpIndex(const QModelIndex &idx, int level = 0)
{
QString result;
result.append(QString(level, ' '));
result.append(idx.data().toString() + '\n');
for (int row = 0, end = idx.model()->rowCount(idx); row < end; ++row)
result.append(dumpIndex(idx.model()->index(row, 0, idx), level + 1));
return result;
}
QString TestTreeSortFilterModel::report() const
{
QString result;
for (int row = 0, end = rowCount(); row < end; ++row) {
auto idx = index(row, 0);
result.append(dumpIndex(idx));
}
return result;
}
bool TestTreeSortFilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
// root items keep the intended order