AutoTest: Use TypedTreeItem for test tree items

Change-Id: I739b6aefc868550b01c7421b4b304293564bb7b6
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2018-04-17 15:53:06 +02:00
parent 83d8de3366
commit 95446fb614
8 changed files with 99 additions and 168 deletions

View File

@@ -202,7 +202,7 @@ static void collectTestInfo(const GTestTreeItem *item,
QTC_ASSERT(item, return);
if (item->type() == TestTreeItem::GroupNode) {
for (int row = 0, count = item->childCount(); row < count; ++row) {
auto child = static_cast<const GTestTreeItem *>(item->childItem(row));
auto child = static_cast<const GTestTreeItem *>(item->childAt(row));
collectTestInfo(child, testCasesForProFile, ignoreCheckState);
}
return;
@@ -211,22 +211,21 @@ static void collectTestInfo(const GTestTreeItem *item,
QTC_ASSERT(childCount != 0, return);
QTC_ASSERT(item->type() == TestTreeItem::TestCase, return);
if (ignoreCheckState || item->checked() == Qt::Checked) {
const QString &projectFile = item->childItem(0)->proFile();
const QString &projectFile = item->childAt(0)->proFile();
testCasesForProFile[projectFile].filters.append(
gtestFilter(item->state()).arg(item->name()).arg('*'));
testCasesForProFile[projectFile].testSetCount += childCount - 1;
testCasesForProFile[projectFile].internalTargets.unite(item->internalTargets());
} else if (item->checked() == Qt::PartiallyChecked) {
for (int childRow = 0; childRow < childCount; ++childRow) {
const TestTreeItem *child = item->childItem(childRow);
QTC_ASSERT(child->type() == TestTreeItem::TestFunctionOrSet, continue);
item->forFirstLevelChildren([&testCasesForProFile, item](TestTreeItem *child){
QTC_ASSERT(child->type() == TestTreeItem::TestFunctionOrSet, return);
if (child->checked() == Qt::Checked) {
testCasesForProFile[child->proFile()].filters.append(
gtestFilter(item->state()).arg(item->name()).arg(child->name()));
testCasesForProFile[child->proFile()].internalTargets.unite(
child->internalTargets());
}
}
});
}
}
@@ -239,7 +238,7 @@ QList<TestConfiguration *> GTestTreeItem::getTestConfigurations(bool ignoreCheck
QHash<QString, TestCases> testCasesForProFile;
for (int row = 0, count = childCount(); row < count; ++row) {
auto child = static_cast<const GTestTreeItem *>(childItem(row));
auto child = static_cast<const GTestTreeItem *>(childAt(row));
collectTestInfo(child, testCasesForProFile, ignoreCheckState);
}
@@ -376,7 +375,7 @@ TestTreeItem *GTestTreeItem::createParentGroupNode() const
return new GTestTreeItem(base.baseName(), fileInfo.absolutePath(), TestTreeItem::GroupNode);
} else { // GTestFilter
QTC_ASSERT(childCount(), return nullptr); // paranoia
const TestTreeItem *firstChild = childItem(0);
const TestTreeItem *firstChild = childAt(0);
const QString activeFilter = GTestFramework::currentGTestFilter();
const QString fullTestName = name() + '.' + firstChild->name();
const QString groupNodeName =
@@ -404,11 +403,9 @@ TestTreeItem *GTestTreeItem::findChildByNameStateAndFile(const QString &name,
GTestTreeItem::TestStates state,
const QString &proFile) const
{
return findChildBy([name, state, proFile](const TestTreeItem *other) -> bool {
return findFirstLevelChild([name, state, proFile](const TestTreeItem *other) {
const GTestTreeItem *gtestItem = static_cast<const GTestTreeItem *>(other);
return other->proFile() == proFile
&& other->name() == name
&& gtestItem->state() == state;
return other->proFile() == proFile && other->name() == name && gtestItem->state() == state;
});
}
@@ -461,7 +458,7 @@ bool GTestTreeItem::isGroupNodeFor(const TestTreeItem *other) const
if (other->type() == TestCase) {
fullName = other->name();
if (other->childCount())
fullName += '.' + other->childItem(0)->name();
fullName += '.' + other->childAt(0)->name();
} else if (other->type() == TestFunctionOrSet) {
QTC_ASSERT(other->parentItem(), return false);
fullName = other->parentItem()->name() + '.' + other->name();
@@ -489,7 +486,7 @@ TestTreeItem *GTestTreeItem::applyFilters()
const QString gtestFilter = GTestFramework::currentGTestFilter();
TestTreeItem *filtered = nullptr;
for (int row = childCount() - 1; row >= 0; --row) {
GTestTreeItem *child = static_cast<GTestTreeItem *>(childItem(row));
GTestTreeItem *child = static_cast<GTestTreeItem *>(childAt(row));
if (!matchesFilter(gtestFilter, name() + '.' + child->name())) {
if (!filtered) {
filtered = copyWithoutChildren();

View File

@@ -50,17 +50,14 @@ QHash<QString, QString> testCaseNamesForFiles(const Core::Id &id, const QStringL
TestTreeItem *rootNode = TestFrameworkManager::instance()->rootNodeForTestFramework(id);
QTC_ASSERT(rootNode, return result);
for (int row = 0, rootCount = rootNode->childCount(); row < rootCount; ++row) {
const TestTreeItem *child = rootNode->childItem(row);
if (files.contains(child->filePath())) {
rootNode->forFirstLevelChildren([&result, &files](TestTreeItem *child) {
if (files.contains(child->filePath()))
result.insert(child->filePath(), child->name());
}
for (int childRow = 0, count = child->childCount(); childRow < count; ++childRow) {
const TestTreeItem *grandChild = child->childItem(childRow);
child->forFirstLevelChildren([&result, &files, child](TestTreeItem *grandChild) {
if (files.contains(grandChild->filePath()))
result.insert(grandChild->filePath(), child->name());
}
}
});
});
return result;
}
@@ -70,18 +67,17 @@ QMultiHash<QString, QString> alternativeFiles(const Core::Id &id, const QStringL
TestTreeItem *rootNode = TestFrameworkManager::instance()->rootNodeForTestFramework(id);
QTC_ASSERT(rootNode, return result);
for (int row = 0, rootCount = rootNode->childCount(); row < rootCount; ++row) {
const TestTreeItem *child = rootNode->childItem(row);
rootNode->forFirstLevelChildren([&result, &files](TestTreeItem *child) {
const QString &baseFilePath = child->filePath();
for (int childRow = 0, count = child->childCount(); childRow < count; ++childRow) {
auto grandChild = static_cast<const QtTestTreeItem *>(child->childItem(childRow));
auto grandChild = static_cast<const QtTestTreeItem *>(child->childAt(childRow));
const QString &filePath = grandChild->filePath();
if (grandChild->inherited() && baseFilePath != filePath && files.contains(filePath)) {
if (!result.contains(filePath, baseFilePath))
result.insert(filePath, baseFilePath);
}
}
}
});
return result;
}

View File

@@ -153,7 +153,7 @@ static void fillTestConfigurationsFromCheckState(const TestTreeItem *item,
QTC_ASSERT(item, return);
if (item->type() == TestTreeItem::GroupNode) {
for (int row = 0, count = item->childCount(); row < count; ++row)
fillTestConfigurationsFromCheckState(item->childItem(row), testConfigurations);
fillTestConfigurationsFromCheckState(item->childAt(row), testConfigurations);
return;
}
QTC_ASSERT(item->type() == TestTreeItem::TestCase, return);
@@ -168,22 +168,18 @@ static void fillTestConfigurationsFromCheckState(const TestTreeItem *item,
return;
case Qt::PartiallyChecked:
default:
int grandChildCount = item->childCount();
QStringList testCases;
for (int grandChildRow = 0; grandChildRow < grandChildCount; ++grandChildRow) {
const TestTreeItem *grandChild = item->childItem(grandChildRow);
item->forFirstLevelChildren([&testCases](TestTreeItem *grandChild) {
if (grandChild->checked() == Qt::Checked) {
testCases << grandChild->name();
} else if (grandChild->checked() == Qt::PartiallyChecked) {
const int dtCount = grandChild->childCount();
const QString funcName = grandChild->name();
for (int dtRow = 0; dtRow < dtCount; ++dtRow) {
const TestTreeItem *dataTag = grandChild->childItem(dtRow);
grandChild->forFirstLevelChildren([&testCases, &funcName](TestTreeItem *dataTag) {
if (dataTag->checked() == Qt::Checked)
testCases << funcName + ':' + dataTag->name();
});
}
}
}
});
testConfig = new QtTestConfiguration();
testConfig->setTestCases(testCases);
@@ -210,22 +206,19 @@ QList<TestConfiguration *> QtTestTreeItem::getAllTestConfigurations() const
if (!project || type() != Root)
return result;
for (int row = 0, count = childCount(); row < count; ++row) {
const TestTreeItem *child = childItem(row);
TestConfiguration *tc = nullptr;
forFirstLevelChildren([&result](TestTreeItem *child) {
if (child->type() == TestCase) {
tc = child->testConfiguration();
QTC_ASSERT(tc, continue);
TestConfiguration *tc = child->testConfiguration();
QTC_ASSERT(tc, return);
result << tc;
} else if (child->type() == GroupNode) {
const int groupChildCount = child->childCount();
for (int groupChildRow = 0; groupChildRow < groupChildCount; ++groupChildRow) {
tc = child->childItem(groupChildRow)->testConfiguration();
QTC_ASSERT(tc, continue);
child->forFirstLevelChildren([&result](TestTreeItem *groupChild) {
TestConfiguration *tc = groupChild->testConfiguration();
QTC_ASSERT(tc, return);
result << tc;
});
}
}
}
});
return result;
}
@@ -237,7 +230,7 @@ QList<TestConfiguration *> QtTestTreeItem::getSelectedTestConfigurations() const
return result;
for (int row = 0, count = childCount(); row < count; ++row)
fillTestConfigurationsFromCheckState(childItem(row), result);
fillTestConfigurationsFromCheckState(childAt(row), result);
return result;
}
@@ -251,7 +244,7 @@ TestTreeItem *QtTestTreeItem::find(const TestParseResult *result)
if (TestFrameworkManager::instance()->groupingEnabled(result->frameworkId)) {
const QString path = QFileInfo(result->fileName).absolutePath();
for (int row = 0; row < childCount(); ++row) {
TestTreeItem *group = childItem(row);
TestTreeItem *group = childAt(row);
if (group->filePath() != path)
continue;
if (auto groupChild = group->findChildByFile(result->fileName))
@@ -326,7 +319,7 @@ TestTreeItem *QtTestTreeItem::createParentGroupNode() const
TestTreeItem *QtTestTreeItem::findChildByNameAndInheritance(const QString &name, bool inherited) const
{
return findChildBy([name, inherited](const TestTreeItem *other) -> bool {
return findFirstLevelChild([name, inherited](const TestTreeItem *other) {
const QtTestTreeItem *qtOther = static_cast<const QtTestTreeItem *>(other);
return qtOther->inherited() == inherited && qtOther->name() == name;
});

View File

@@ -51,24 +51,22 @@ QHash<QString, QString> proFilesForQmlFiles(const Core::Id &id, const QStringLis
if (files.isEmpty())
return result;
for (int row = 0, rootCount = rootNode->childCount(); row < rootCount; ++row) {
const TestTreeItem *child = rootNode->childItem(row);
rootNode->forFirstLevelChildren([&result, &files](TestTreeItem *child) {
const QString &file = child->filePath();
if (!file.isEmpty() && files.contains(file)) {
const QString &proFile = child->proFile();
if (!proFile.isEmpty())
result.insert(file, proFile);
}
for (int subRow = 0, subCount = child->childCount(); subRow < subCount; ++subRow) {
const TestTreeItem *grandChild = child->childItem(subRow);
child->forFirstLevelChildren([&result, &files](TestTreeItem *grandChild) {
const QString &file = grandChild->filePath();
if (!file.isEmpty() && files.contains(file)) {
const QString &proFile = grandChild->proFile();
if (!proFile.isEmpty())
result.insert(file, proFile);
}
}
}
});
});
return result;
}

View File

@@ -130,13 +130,12 @@ TestConfiguration *QuickTestTreeItem::testConfiguration() const
QuickTestConfiguration *config = nullptr;
switch (type()) {
case TestCase: {
const QString testName = name();
QStringList testFunctions;
for (int row = 0, count = childCount(); row < count; ++row) {
const TestTreeItem *child = childItem(row);
if (child->type() == TestTreeItem::TestSpecialFunction)
continue;
testFunctions << name() + "::" + child->name();
}
forFirstLevelChildren([&testFunctions, &testName](TestTreeItem *child) {
if (child->type() == TestTreeItem::TestFunctionOrSet)
testFunctions << testName + "::" + child->name();
});
config = new QuickTestConfiguration;
config->setTestCases(testFunctions);
config->setProjectFile(proFile());
@@ -166,7 +165,7 @@ static void testConfigurationFromCheckState(const TestTreeItem *item,
QTC_ASSERT(item, return);
if (item->type() == TestTreeItem::GroupNode) {
for (int row = 0, count = item->childCount(); row < count; ++row)
testConfigurationFromCheckState(item->childItem(row), foundProFiles);
testConfigurationFromCheckState(item->childAt(row), foundProFiles);
return;
}
QTC_ASSERT(item->type() == TestTreeItem::TestCase, return);
@@ -174,14 +173,12 @@ static void testConfigurationFromCheckState(const TestTreeItem *item,
if (item->checked() == Qt::Unchecked)
return;
const QString testName = item->name();
QStringList testFunctions;
const int childCount = item->childCount();
for (int childRow = 0; childRow < childCount; ++childRow) {
const TestTreeItem *child = item->childItem(childRow);
if (child->checked() != Qt::Checked || child->type() != TestTreeItem::TestFunctionOrSet)
continue;
testFunctions << item->name() + "::" + child->name();
}
item->forFirstLevelChildren([&testFunctions, &testName](TestTreeItem *child) {
if (child->checked() == Qt::Checked && child->type() == TestTreeItem::TestFunctionOrSet)
testFunctions << testName + "::" + child->name();
});
if (foundProFiles.contains(item->proFile())) {
tc = foundProFiles[item->proFile()];
QStringList oldFunctions(tc->testCases());
@@ -225,29 +222,25 @@ QList<TestConfiguration *> QuickTestTreeItem::getAllTestConfigurations() const
return result;
QHash<QString, Tests> testsForProfile;
for (int row = 0, count = childCount(); row < count; ++row) {
const TestTreeItem *child = childItem(row);
forFirstLevelChildren([&testsForProfile](TestTreeItem *child) {
// unnamed Quick Tests must be handled separately
if (child->name().isEmpty()) {
for (int childRow = 0, ccount = child->childCount(); childRow < ccount; ++ childRow) {
const TestTreeItem *grandChild = child->childItem(childRow);
child->forFirstLevelChildren([&testsForProfile](TestTreeItem *grandChild) {
const QString &proFile = grandChild->proFile();
++(testsForProfile[proFile].testCount);
testsForProfile[proFile].internalTargets = grandChild->internalTargets();
}
continue;
});
return;
}
// named Quick Test
if (child->type() == TestCase) {
addTestsForItem(testsForProfile[child->proFile()], child);
} else if (child->type() == GroupNode) {
const int groupCount = child->childCount();
for (int groupRow = 0; groupRow < groupCount; ++groupRow) {
const TestTreeItem *grandChild = child->childItem(groupRow);
child->forFirstLevelChildren([&testsForProfile](TestTreeItem *grandChild) {
addTestsForItem(testsForProfile[grandChild->proFile()], grandChild);
});
}
}
}
});
// create TestConfiguration for each project file
for (auto it = testsForProfile.begin(), end = testsForProfile.end(); it != end; ++it) {
QuickTestConfiguration *tc = new QuickTestConfiguration;
@@ -269,15 +262,11 @@ QList<TestConfiguration *> QuickTestTreeItem::getSelectedTestConfigurations() co
QHash<QString, QuickTestConfiguration *> foundProFiles;
for (int row = 0, count = childCount(); row < count; ++row) {
const TestTreeItem *child = childItem(row);
// unnamed Quick Tests cannot get selected explicitly
if (child->name().isEmpty())
continue;
// named Quick Tests
forFirstLevelChildren([&foundProFiles](TestTreeItem *child) {
// unnamed Quick Tests cannot get selected explicitly - only handle named Quick Tests
if (!child->name().isEmpty())
testConfigurationFromCheckState(child, foundProFiles);
}
});
for (auto it = foundProFiles.begin(), end = foundProFiles.end(); it != end; ++it) {
QuickTestConfiguration *config = it.value();
@@ -300,14 +289,10 @@ TestTreeItem *QuickTestTreeItem::find(const TestParseResult *result)
return unnamedQuickTests();
if (TestFrameworkManager::instance()->groupingEnabled(result->frameworkId)) {
const QString path = QFileInfo(result->fileName).absolutePath();
for (int row = 0; row < childCount(); ++row) {
TestTreeItem *group = childItem(row);
if (group->filePath() != path)
continue;
if (auto groupChild = group->findChildByFile(result->fileName))
return groupChild;
}
return nullptr;
TestTreeItem *group = findFirstLevelChild([path](TestTreeItem *group) {
return group->filePath() == path;
});
return group ? group->findChildByFile(result->fileName) : nullptr;
}
return findChildByFile(result->fileName);
case GroupNode:
@@ -416,12 +401,7 @@ TestTreeItem *QuickTestTreeItem::unnamedQuickTests() const
if (type() != Root)
return nullptr;
for (int row = 0, count = childCount(); row < count; ++row) {
TestTreeItem *child = childItem(row);
if (child->name().isEmpty())
return child;
}
return nullptr;
return findFirstLevelChild([](TestTreeItem *child) { return child->name().isEmpty(); });
}
} // namespace Internal

View File

@@ -191,17 +191,16 @@ void TestTreeItem::markForRemovalRecursively(bool mark)
{
markForRemoval(mark);
for (int row = 0, count = childCount(); row < count; ++row)
childItem(row)->markForRemovalRecursively(mark);
childAt(row)->markForRemovalRecursively(mark);
}
void TestTreeItem::markForRemovalRecursively(const QString &filePath)
{
bool mark = m_filePath == filePath;
for (int row = 0, count = childCount(); row < count; ++row) {
TestTreeItem *child = childItem(row);
forFirstLevelChildren([&mark, &filePath](TestTreeItem *child) {
child->markForRemovalRecursively(filePath);
mark &= child->markedForRemoval();
}
});
markForRemoval(mark);
}
@@ -210,35 +209,28 @@ TestTreeItem *TestTreeItem::parentItem() const
return static_cast<TestTreeItem *>(parent());
}
TestTreeItem *TestTreeItem::childItem(int row) const
{
return static_cast<TestTreeItem *>(childAt(row));
}
TestTreeItem *TestTreeItem::findChildByName(const QString &name)
{
return findChildBy([name](const TestTreeItem *other) -> bool {
return other->name() == name;
});
return findFirstLevelChild([name](const TestTreeItem *other) { return other->name() == name; });
}
TestTreeItem *TestTreeItem::findChildByFile(const QString &filePath)
{
return findChildBy([filePath](const TestTreeItem *other) -> bool {
return findFirstLevelChild([filePath](const TestTreeItem *other) {
return other->filePath() == filePath;
});
}
TestTreeItem *TestTreeItem::findChildByFileAndType(const QString &filePath, Type tType)
{
return findChildBy([filePath, tType](const TestTreeItem *other) {
return findFirstLevelChild([filePath, tType](const TestTreeItem *other) {
return other->type() == tType && other->filePath() == filePath;
});
}
TestTreeItem *TestTreeItem::findChildByNameAndFile(const QString &name, const QString &filePath)
{
return findChildBy([name, filePath](const TestTreeItem *other) -> bool {
return findFirstLevelChild([name, filePath](const TestTreeItem *other) {
return other->filePath() == filePath && other->name() == name;
});
}
@@ -353,16 +345,6 @@ inline bool TestTreeItem::modifyName(const QString &name)
return false;
}
TestTreeItem *TestTreeItem::findChildBy(CompareFunction compare) const
{
for (int row = 0, count = childCount(); row < count; ++row) {
TestTreeItem *child = childItem(row);
if (compare(child))
return child;
}
return nullptr;
}
/*
* try to find build system target that depends on the given file - if the file is no header
* try to find the corresponding header and use this instead to find the respective target

View File

@@ -49,7 +49,7 @@ namespace Internal {
class TestParseResult;
class TestConfiguration;
enum class TestRunMode;
class TestTreeItem : public Utils::TreeItem
class TestTreeItem : public Utils::TypedTreeItem<TestTreeItem>
{
public:
@@ -100,7 +100,6 @@ public:
bool markedForRemoval() const { return m_status == MarkedForRemoval; }
bool newlyAdded() const { return m_status == NewlyAdded; }
TestTreeItem *parentItem() const;
TestTreeItem *childItem(int row) const;
TestTreeItem *findChildByName(const QString &name);
TestTreeItem *findChildByFile(const QString &filePath);
@@ -127,7 +126,6 @@ public:
protected:
void copyBasicDataFrom(const TestTreeItem *other);
typedef std::function<bool(const TestTreeItem *)> CompareFunction;
TestTreeItem *findChildBy(CompareFunction compare) const;
static QSet<QString> dependingInternalTargets(CppTools::CppModelManager *cppMM,
const QString &file);

View File

@@ -162,29 +162,22 @@ QList<TestTreeItem *> TestTreeModel::testItemsByName(TestTreeItem *root, const Q
{
QList<TestTreeItem *> result;
for (int row = 0, count = root->childCount(); row < count; ++row){
TestTreeItem *node = root->childItem(row);
root->forFirstLevelChildren([&testName, &result, this](TestTreeItem *node) {
if (node->type() == TestTreeItem::TestCase) {
if (node->name() == testName) {
result << node;
continue; // prioritize Tests over TestCases
return; // prioritize Tests over TestCases
}
TestTreeItem *testCase = node->findChildBy([testName](const TestTreeItem *it) {
TestTreeItem *testCase = node->findFirstLevelChild([&testName](TestTreeItem *it) {
QTC_ASSERT(it, return false);
return it->type() == TestTreeItem::TestFunctionOrSet && it->name() == testName;
}); // collect only actual tests, not special functions like init, cleanup etc,
if (!testCase)
continue;
}); // collect only actual tests, not special functions like init, cleanup etc.
if (testCase)
result << testCase;
} else {
result << testItemsByName(node, testName);
}
}
});
return result;
}
@@ -229,12 +222,12 @@ void TestTreeModel::rebuild(const QList<Core::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);
auto testItem = frameworkRoot->childAt(row);
if (testItem->type() == TestTreeItem::GroupNode) {
// process children of group node and delete it afterwards if necessary
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);
TestTreeItem *childTestItem = testItem->childAt(childRow);
takeItem(childTestItem);
filterAndInsert(childTestItem, frameworkRoot, groupingEnabled);
}
@@ -272,7 +265,7 @@ void TestTreeModel::markForRemoval(const QString &filePath)
for (Utils::TreeItem *frameworkRoot : *rootItem()) {
TestTreeItem *root = static_cast<TestTreeItem *>(frameworkRoot);
for (int childRow = root->childCount() - 1; childRow >= 0; --childRow) {
TestTreeItem *child = root->childItem(childRow);
TestTreeItem *child = root->childAt(childRow);
child->markForRemovalRecursively(filePath);
}
}
@@ -300,7 +293,7 @@ bool TestTreeModel::sweepChildren(TestTreeItem *item)
{
bool hasChanged = false;
for (int row = item->childCount() - 1; row >= 0; --row) {
TestTreeItem *child = item->childItem(row);
TestTreeItem *child = item->childAt(row);
if (child->type() != TestTreeItem::Root && child->markedForRemoval()) {
destroyItem(child);
@@ -324,7 +317,7 @@ static TestTreeItem *fullCopyOf(TestTreeItem *other)
QTC_ASSERT(other, return nullptr);
TestTreeItem *result = other->copyWithoutChildren();
for (int row = 0, count = other->childCount(); row < count; ++row)
result->appendChild(fullCopyOf(other->childItem(row)));
result->appendChild(fullCopyOf(other->childAt(row)));
return result;
}
@@ -346,7 +339,7 @@ void TestTreeModel::insertItemInParent(TestTreeItem *item, TestTreeItem *root, b
{
TestTreeItem *parentNode = root;
if (groupingEnabled) {
parentNode = root->findChildBy([item] (const TestTreeItem *it) {
parentNode = root->findFirstLevelChild([item] (const TestTreeItem *it) {
return it->isGroupNodeFor(item);
});
if (!parentNode) {
@@ -361,7 +354,7 @@ void TestTreeModel::insertItemInParent(TestTreeItem *item, TestTreeItem *root, b
if (auto otherItem = parentNode->findChild(item)) {
// only handle item's children and add them to the already present one
for (int row = 0, count = item->childCount(); row < count; ++row) {
TestTreeItem *child = fullCopyOf(item->childItem(row));
TestTreeItem *child = fullCopyOf(item->childAt(row));
applyParentCheckState(otherItem, child);
otherItem->appendChild(child);
}
@@ -388,7 +381,7 @@ void TestTreeModel::revalidateCheckState(TestTreeItem *item)
bool foundUnchecked = false;
bool foundPartiallyChecked = false;
for (int row = 0, count = item->childCount(); row < count; ++row) {
TestTreeItem *child = item->childItem(row);
TestTreeItem *child = item->childAt(row);
switch (child->type()) {
case TestTreeItem::TestDataFunction:
case TestTreeItem::TestSpecialFunction:
@@ -507,7 +500,7 @@ int TestTreeModel::autoTestsCount() const
bool TestTreeModel::hasUnnamedQuickTests(const TestTreeItem *rootNode) const
{
for (int row = 0, count = rootNode->childCount(); row < count; ++row) {
if (rootNode->childItem(row)->name().isEmpty())
if (rootNode->childAt(row)->name().isEmpty())
return true;
}
return false;
@@ -519,12 +512,7 @@ TestTreeItem *TestTreeModel::unnamedQuickTests() const
if (!rootNode)
return nullptr;
for (int row = 0, count = rootNode->childCount(); row < count; ++row) {
TestTreeItem *child = rootNode->childItem(row);
if (child->name().isEmpty())
return child;
}
return nullptr;
return rootNode->findFirstLevelChild([](TestTreeItem *it) { return it->name().isEmpty(); });
}
int TestTreeModel::namedQuickTestsCount() const
@@ -549,11 +537,11 @@ int TestTreeModel::dataTagsCount() const
return 0;
int dataTagCount = 0;
for (Utils::TreeItem *item : *rootNode) {
TestTreeItem *classItem = static_cast<TestTreeItem *>(item);
for (Utils::TreeItem *functionItem : *classItem)
rootNode->forFirstLevelChildren([&dataTagCount](TestTreeItem *classItem) {
classItem->forFirstLevelChildren([&dataTagCount](TestTreeItem *functionItem) {
dataTagCount += functionItem->childCount();
}
});
});
return dataTagCount;
}
@@ -568,10 +556,9 @@ QMultiMap<QString, int> TestTreeModel::gtestNamesAndSets() const
QMultiMap<QString, int> result;
if (TestTreeItem *rootNode = gtestRootNode()) {
for (int row = 0, count = rootNode->childCount(); row < count; ++row) {
const TestTreeItem *current = rootNode->childItem(row);
result.insert(current->name(), current->childCount());
}
rootNode->forFirstLevelChildren([&result](TestTreeItem *child) {
result.insert(child->name(), child->childCount());
});
}
return result;
}