forked from qt-creator/qt-creator
AutoTest: Use more specific types for test tree model
Allows to move over some static casts to the base tree model. Change-Id: I19e322714a6026771139eeb0ded4645afb45aabe Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -179,34 +179,37 @@ bool TestTreeModel::hasTests() const
|
|||||||
QList<ITestConfiguration *> TestTreeModel::getAllTestCases() const
|
QList<ITestConfiguration *> TestTreeModel::getAllTestCases() const
|
||||||
{
|
{
|
||||||
QList<ITestConfiguration *> result;
|
QList<ITestConfiguration *> result;
|
||||||
for (Utils::TreeItem *frameworkRoot : *rootItem())
|
forItemsAtLevel<1>([&result](ITestTreeItem *testRoot) {
|
||||||
result.append(static_cast<ITestTreeItem *>(frameworkRoot)->getAllTestConfigurations());
|
result.append(testRoot->getAllTestConfigurations());
|
||||||
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ITestConfiguration *> TestTreeModel::getSelectedTests() const
|
QList<ITestConfiguration *> TestTreeModel::getSelectedTests() const
|
||||||
{
|
{
|
||||||
QList<ITestConfiguration *> result;
|
QList<ITestConfiguration *> result;
|
||||||
for (Utils::TreeItem *frameworkRoot : *rootItem())
|
forItemsAtLevel<1>([&result](ITestTreeItem *testRoot) {
|
||||||
result.append(static_cast<ITestTreeItem *>(frameworkRoot)->getSelectedTestConfigurations());
|
result.append(testRoot->getSelectedTestConfigurations());
|
||||||
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ITestConfiguration *> TestTreeModel::getFailedTests() const
|
QList<ITestConfiguration *> TestTreeModel::getFailedTests() const
|
||||||
{
|
{
|
||||||
QList<ITestConfiguration *> result;
|
QList<ITestConfiguration *> result;
|
||||||
for (Utils::TreeItem *frameworkRoot : *rootItem())
|
forItemsAtLevel<1>([&result](ITestTreeItem *testRoot) {
|
||||||
result.append(static_cast<ITestTreeItem *>(frameworkRoot)->getFailedTestConfigurations());
|
result.append(testRoot->getFailedTestConfigurations());
|
||||||
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ITestConfiguration *> TestTreeModel::getTestsForFile(const Utils::FilePath &fileName) const
|
QList<ITestConfiguration *> TestTreeModel::getTestsForFile(const Utils::FilePath &fileName) const
|
||||||
{
|
{
|
||||||
QList<ITestConfiguration *> result;
|
QList<ITestConfiguration *> result;
|
||||||
for (Utils::TreeItem *frameworkRoot : *rootItem()) {
|
forItemsAtLevel<1>([&result, &fileName](ITestTreeItem *testRoot) {
|
||||||
if (static_cast<ITestTreeItem *>(frameworkRoot)->testBase()->type() == ITestBase::Framework)
|
if (testRoot->testBase()->type() == ITestBase::Framework)
|
||||||
result.append(static_cast<TestTreeItem *>(frameworkRoot)->getTestConfigurationsForFile(fileName));
|
result.append(static_cast<TestTreeItem *>(testRoot)->getTestConfigurationsForFile(fileName));
|
||||||
}
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,14 +274,31 @@ void TestTreeModel::onBuildSystemTestsUpdated()
|
|||||||
revalidateCheckState(rootNode);
|
revalidateCheckState(rootNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QList<TestTreeItem *> TestTreeModel::frameworkRootNodes() const
|
||||||
|
{
|
||||||
|
QList<TestTreeItem *> result;
|
||||||
|
forItemsAtLevel<1>([&result](ITestTreeItem *rootNode) {
|
||||||
|
if (auto framework = rootNode->testBase()->asFramework())
|
||||||
|
result.append(framework->rootNode());
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QList<ITestTreeItem *> TestTreeModel::testToolRootNodes() const
|
||||||
|
{
|
||||||
|
QList<ITestTreeItem *> result;
|
||||||
|
forItemsAtLevel<1>([&result](ITestTreeItem *rootNode) {
|
||||||
|
if (auto testTool = rootNode->testBase()->asTestTool())
|
||||||
|
result.append(testTool->rootNode());
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
QList<TestTreeItem *> TestTreeModel::testItemsByName(const QString &testName)
|
QList<TestTreeItem *> TestTreeModel::testItemsByName(const QString &testName)
|
||||||
{
|
{
|
||||||
QList<TestTreeItem *> result;
|
QList<TestTreeItem *> result;
|
||||||
for (Utils::TreeItem *frameworkRoot : *rootItem()) {
|
for (TestTreeItem *frameworkRoot : frameworkRootNodes())
|
||||||
ITestTreeItem *root = static_cast<ITestTreeItem *>(frameworkRoot);
|
result << testItemsByName(frameworkRoot, testName);
|
||||||
if (root->testBase()->type() == ITestBase::Framework)
|
|
||||||
result << testItemsByName(static_cast<TestTreeItem *>(root), testName);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -423,10 +443,8 @@ void TestTreeModel::updateCheckStateCache()
|
|||||||
{
|
{
|
||||||
m_checkStateCache->evolve(ITestBase::Framework);
|
m_checkStateCache->evolve(ITestBase::Framework);
|
||||||
|
|
||||||
for (Utils::TreeItem *rootNode : *rootItem()) {
|
for (TestTreeItem *rootNode : frameworkRootNodes()) {
|
||||||
// FIXME limit to framework items
|
rootNode->forAllChildItems([this](TestTreeItem *childItem) {
|
||||||
rootNode->forAllChildren([this](Utils::TreeItem *child) {
|
|
||||||
auto childItem = static_cast<ITestTreeItem *>(child);
|
|
||||||
m_checkStateCache->insert(childItem, childItem->checked());
|
m_checkStateCache->insert(childItem, childItem->checked());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -459,12 +477,10 @@ void TestTreeModel::removeFiles(const QStringList &files)
|
|||||||
|
|
||||||
void TestTreeModel::markAllFrameworkItemsForRemoval()
|
void TestTreeModel::markAllFrameworkItemsForRemoval()
|
||||||
{
|
{
|
||||||
for (Utils::TreeItem *frameworkRoot : *rootItem()) {
|
for (TestTreeItem *frameworkRoot : frameworkRootNodes()) {
|
||||||
// skip buildsystem based frameworks
|
frameworkRoot->forFirstLevelChildItems([](TestTreeItem *child) {
|
||||||
if (static_cast<ITestTreeItem *>(frameworkRoot)->testBase()->asTestTool())
|
child->markForRemovalRecursively(true);
|
||||||
continue;
|
});
|
||||||
for (Utils::TreeItem *item : *frameworkRoot)
|
|
||||||
static_cast<TestTreeItem *>(item)->markForRemovalRecursively(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -473,12 +489,9 @@ void TestTreeModel::markForRemoval(const QString &filePath)
|
|||||||
if (filePath.isEmpty())
|
if (filePath.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (Utils::TreeItem *frameworkRoot : *rootItem()) {
|
for (TestTreeItem *frameworkRoot : frameworkRootNodes()) {
|
||||||
ITestTreeItem *root = static_cast<ITestTreeItem *>(frameworkRoot);
|
for (int childRow = frameworkRoot->childCount() - 1; childRow >= 0; --childRow) {
|
||||||
if (root->testBase()->asTestTool())
|
TestTreeItem *child = frameworkRoot->childItem(childRow);
|
||||||
continue;
|
|
||||||
for (int childRow = root->childCount() - 1; childRow >= 0; --childRow) {
|
|
||||||
TestTreeItem *child = static_cast<TestTreeItem *>(root->childAt(childRow));
|
|
||||||
child->markForRemovalRecursively(filePath);
|
child->markForRemovalRecursively(filePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -486,13 +499,9 @@ void TestTreeModel::markForRemoval(const QString &filePath)
|
|||||||
|
|
||||||
void TestTreeModel::sweep()
|
void TestTreeModel::sweep()
|
||||||
{
|
{
|
||||||
for (Utils::TreeItem *frameworkRoot : *rootItem()) {
|
for (TestTreeItem *frameworkRoot : frameworkRootNodes()) {
|
||||||
ITestTreeItem *root = static_cast<ITestTreeItem *>(frameworkRoot);
|
sweepChildren(frameworkRoot);
|
||||||
if (root->testBase()->asTestTool())
|
revalidateCheckState(frameworkRoot);
|
||||||
continue;
|
|
||||||
TestTreeItem *ttRoot = static_cast<TestTreeItem *>(root);
|
|
||||||
sweepChildren(ttRoot);
|
|
||||||
revalidateCheckState(ttRoot);
|
|
||||||
}
|
}
|
||||||
// even if nothing has changed by the sweeping we might had parse which added or modified items
|
// even if nothing has changed by the sweeping we might had parse which added or modified items
|
||||||
emit testTreeModelChanged();
|
emit testTreeModelChanged();
|
||||||
@@ -712,10 +721,7 @@ void TestTreeModel::handleParseResult(const TestParseResult *result, TestTreeIte
|
|||||||
|
|
||||||
void TestTreeModel::removeAllTestItems()
|
void TestTreeModel::removeAllTestItems()
|
||||||
{
|
{
|
||||||
for (Utils::TreeItem *it : *rootItem()) {
|
for (TestTreeItem *item : frameworkRootNodes()) {
|
||||||
ITestTreeItem *item = static_cast<ITestTreeItem *>(it);
|
|
||||||
if (item->testBase()->asTestTool())
|
|
||||||
continue;
|
|
||||||
item->removeChildren();
|
item->removeChildren();
|
||||||
if (item->checked() == Qt::PartiallyChecked)
|
if (item->checked() == Qt::PartiallyChecked)
|
||||||
item->setData(0, Qt::Checked, Qt::CheckStateRole);
|
item->setData(0, Qt::Checked, Qt::CheckStateRole);
|
||||||
@@ -725,10 +731,7 @@ void TestTreeModel::removeAllTestItems()
|
|||||||
|
|
||||||
void TestTreeModel::removeAllTestToolItems()
|
void TestTreeModel::removeAllTestToolItems()
|
||||||
{
|
{
|
||||||
for (Utils::TreeItem *it : *rootItem()) {
|
for (ITestTreeItem *item : testToolRootNodes()) {
|
||||||
ITestTreeItem * item = static_cast<ITestTreeItem *>(it);
|
|
||||||
if (item->testBase()->type() == ITestBase::Framework)
|
|
||||||
continue;
|
|
||||||
item->removeChildren();
|
item->removeChildren();
|
||||||
if (item->checked() == Qt::PartiallyChecked)
|
if (item->checked() == Qt::PartiallyChecked)
|
||||||
item->setData(0, Qt::Checked, Qt::CheckStateRole);
|
item->setData(0, Qt::Checked, Qt::CheckStateRole);
|
||||||
|
@@ -46,7 +46,7 @@ class TestCodeParser;
|
|||||||
class TestParseResult;
|
class TestParseResult;
|
||||||
using TestParseResultPtr = QSharedPointer<TestParseResult>;
|
using TestParseResultPtr = QSharedPointer<TestParseResult>;
|
||||||
|
|
||||||
class AUTOTESTSHARED_EXPORT TestTreeModel : public Utils::TreeModel<>
|
class AUTOTESTSHARED_EXPORT TestTreeModel : public Utils::TreeModel<Utils::TreeItem, ITestTreeItem>
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -114,6 +114,8 @@ private:
|
|||||||
QList<TestTreeItem *> testItemsByName(TestTreeItem *root, const QString &testName);
|
QList<TestTreeItem *> testItemsByName(TestTreeItem *root, const QString &testName);
|
||||||
void onTargetChanged(ProjectExplorer::Target *target);
|
void onTargetChanged(ProjectExplorer::Target *target);
|
||||||
void onBuildSystemTestsUpdated();
|
void onBuildSystemTestsUpdated();
|
||||||
|
const QList<TestTreeItem *> frameworkRootNodes() const;
|
||||||
|
const QList<ITestTreeItem *> testToolRootNodes() const;
|
||||||
|
|
||||||
Internal::TestCodeParser *m_parser = nullptr;
|
Internal::TestCodeParser *m_parser = nullptr;
|
||||||
Internal::ItemDataCache<Qt::CheckState> *m_checkStateCache = nullptr; // not owned
|
Internal::ItemDataCache<Qt::CheckState> *m_checkStateCache = nullptr; // not owned
|
||||||
|
Reference in New Issue
Block a user