AutoTest: Allow grouping of test cases

Grouping of test cases can now get enabled for each
registered framework.
For now grouping happens only folder based.

Task-number: QTCREATORBUG-17979
Change-Id: Ic0e5c0ecc76998a1aedea8aa0845f6d9b53fb179
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2017-12-06 08:45:36 +01:00
parent b3e24fbfd4
commit 4eabcda3a1
18 changed files with 253 additions and 23 deletions

View File

@@ -110,6 +110,7 @@ bool TestTreeModel::setData(const QModelIndex &index, const QVariant &value, int
if (role == Qt::CheckStateRole) {
switch (item->type()) {
case TestTreeItem::Root:
case TestTreeItem::GroupNode:
case TestTreeItem::TestCase:
if (item->childCount() > 0)
emit dataChanged(index.child(0, 0), index.child(item->childCount() - 1, 0));
@@ -174,6 +175,31 @@ void TestTreeModel::syncTestFrameworks()
emit updatedActiveFrameworks(sortedIds.size());
}
void TestTreeModel::rebuild(const QList<Core::Id> &frameworkIds)
{
TestFrameworkManager *frameworkManager = TestFrameworkManager::instance();
for (const Core::Id &id : frameworkIds) {
TestTreeItem *frameworkRoot = frameworkManager->rootNodeForTestFramework(id);
const bool groupingEnabled = TestFrameworkManager::instance()->groupingEnabled(id);
for (int row = frameworkRoot->childCount() - 1; row >= 0; --row) {
auto testItem = frameworkRoot->childItem(row);
if (!groupingEnabled && testItem->type() == TestTreeItem::GroupNode) {
// do not re-insert the GroupNode, but process its children and delete it afterwards
for (int childRow = testItem->childCount() - 1; childRow >= 0; --childRow) {
// FIXME should this be done recursively until we have a non-GroupNode?
TestTreeItem *childTestItem = testItem->childItem(childRow);
takeItem(childTestItem);
insertItemInParent(childTestItem, frameworkRoot, groupingEnabled);
}
delete takeItem(testItem);
} else {
takeItem(testItem);
insertItemInParent(testItem, frameworkRoot, groupingEnabled);
}
}
}
}
void TestTreeModel::removeFiles(const QStringList &files)
{
for (const QString &file : files)
@@ -239,6 +265,24 @@ bool TestTreeModel::sweepChildren(TestTreeItem *item)
return hasChanged;
}
void TestTreeModel::insertItemInParent(TestTreeItem *item, TestTreeItem *root, bool groupingEnabled)
{
TestTreeItem *parentNode = root;
if (groupingEnabled) {
parentNode = root->findChildBy([item] (const TestTreeItem *it) {
return it->isGroupNodeFor(item);
});
if (!parentNode) {
parentNode = item->createParentGroupNode();
if (!parentNode) // we might not get a group node at all
parentNode = root;
else
root->appendChild(parentNode);
}
}
parentNode->appendChild(item);
}
void TestTreeModel::onParseResultReady(const TestParseResultPtr result)
{
TestTreeItem *rootNode
@@ -249,10 +293,19 @@ void TestTreeModel::onParseResultReady(const TestParseResultPtr result)
void TestTreeModel::handleParseResult(const TestParseResult *result, TestTreeItem *parentNode)
{
const bool groupingEnabled =
TestFrameworkManager::instance()->groupingEnabled(result->frameworkId);
// lookup existing items
if (TestTreeItem *toBeModified = parentNode->find(result)) {
// found existing item... Do not remove
toBeModified->markForRemoval(false);
// if it's a reparse we need to mark the group node as well to avoid purging it in sweep()
if (groupingEnabled) {
if (auto directParent = toBeModified->parentItem()) {
if (directParent->type() == TestTreeItem::GroupNode)
directParent->markForRemoval(false);
}
}
// modify and when content has changed inform ui
if (toBeModified->modify(result)) {
const QModelIndex &idx = indexForItem(toBeModified);
@@ -266,7 +319,8 @@ void TestTreeModel::handleParseResult(const TestParseResult *result, TestTreeIte
// if there's no matching item, add the new one
TestTreeItem *newItem = result->createTestTreeItem();
QTC_ASSERT(newItem, return);
parentNode->appendChild(newItem);
insertItemInParent(newItem, parentNode, groupingEnabled);
// new items are checked by default - revalidation of parents might be necessary
if (parentNode->checked() != Qt::Checked) {
parentNode->revalidateCheckState();