AutoTest: Free TestTreeItem from CppTools dependency

Makes TestTreeItem programming language agnostic.

By moving the "query" methods to CppTools, the cohesion within these
methods is improved, i.e. information crosses the AutoTest <-> CppTools
border fewer times. Furthermore, it allows the CppTools plugin to see
how its data is being used, allowing it to optimize its queries
behind the scenes.

Change-Id: I0a60140abaca1193d500605dfa2812b4d937d94c
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Bernhard Beschow
2021-01-01 19:19:43 +01:00
parent 3f0f289b28
commit ac61bfdc90
11 changed files with 96 additions and 76 deletions

View File

@@ -36,6 +36,8 @@
namespace Autotest {
namespace Internal {
QSet<QString> internalTargets(const QString &proFile);
TestTreeItem *QuickTestTreeItem::copyWithoutChildren()
{
QuickTestTreeItem *copied = new QuickTestTreeItem(framework());
@@ -156,7 +158,7 @@ ITestConfiguration *QuickTestTreeItem::testConfiguration() const
return nullptr;
}
if (config)
config->setInternalTargets(internalTargets());
config->setInternalTargets(internalTargets(proFile()));
return config;
}
@@ -189,7 +191,7 @@ static QList<ITestConfiguration *> testConfigurationsFor(
auto tc = new QuickTestConfiguration(treeItem->framework());
tc->setProjectFile(treeItem->proFile());
tc->setProject(ProjectExplorer::SessionManager::startupProject());
tc->setInternalTargets(treeItem->internalTargets());
tc->setInternalTargets(internalTargets(treeItem->proFile()));
it = configurationForProFiles.insert(treeItem->proFile(), tc);
}
it.value()->setTestCases(it.value()->testCases() + functions);
@@ -216,7 +218,7 @@ struct Tests {
static void addTestsForItem(Tests &tests, const TestTreeItem *item)
{
tests.testCount += item->childCount();
tests.internalTargets = item->internalTargets();
tests.internalTargets = internalTargets(item->proFile());
}
QList<ITestConfiguration *> QuickTestTreeItem::getAllTestConfigurations() const
@@ -234,7 +236,7 @@ QList<ITestConfiguration *> QuickTestTreeItem::getAllTestConfigurations() const
child->forFirstLevelChildItems([&testsForProfile](TestTreeItem *grandChild) {
const QString &proFile = grandChild->proFile();
++(testsForProfile[proFile].testCount);
testsForProfile[proFile].internalTargets = grandChild->internalTargets();
testsForProfile[proFile].internalTargets = internalTargets(grandChild->proFile());
});
return;
}
@@ -384,7 +386,7 @@ bool QuickTestTreeItem::isGroupable() const
return type() == TestCase && !name().isEmpty() && !filePath().isEmpty();
}
QSet<QString> QuickTestTreeItem::internalTargets() const
QSet<QString> internalTargets(const QString &proFile)
{
QSet<QString> result;
const auto cppMM = CppTools::CppModelManager::instance();
@@ -392,7 +394,7 @@ QSet<QString> QuickTestTreeItem::internalTargets() const
for (const CppTools::ProjectPart::Ptr &projectPart : projectInfo.projectParts()) {
if (projectPart->buildTargetType != ProjectExplorer::BuildTargetType::Executable)
continue;
if (projectPart->projectFile == proFile())
if (projectPart->projectFile == proFile)
result.insert(projectPart->buildSystemTarget);
}
return result;