AutoTest: Move function into framework related class

TestTreeModel::testCaseNamesForFiles() is a helper that is currently
needed only for handling the Qt test framework.
Move it down into Qt framework's helper class and make it static.

Change-Id: I03c377a76402593584870cbbdaa4621d19278443
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
Christian Stenger
2016-06-07 13:26:08 +02:00
parent 5ef85949a8
commit e4ff33e622
4 changed files with 26 additions and 24 deletions

View File

@@ -25,6 +25,10 @@
#pragma once #pragma once
#include "../testframeworkmanager.h"
#include <utils/qtcassert.h>
#include <QByteArrayList> #include <QByteArrayList>
namespace Autotest { namespace Autotest {
@@ -38,6 +42,27 @@ public:
static QByteArrayList valid = {"QTEST_MAIN", "QTEST_APPLESS_MAIN", "QTEST_GUILESS_MAIN"}; static QByteArrayList valid = {"QTEST_MAIN", "QTEST_APPLESS_MAIN", "QTEST_GUILESS_MAIN"};
return valid.contains(macro); return valid.contains(macro);
} }
static QHash<QString, QString> testCaseNamesForFiles(const Core::Id &id,
const QStringList &files)
{
QHash<QString, QString> result;
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())) {
result.insert(child->filePath(), child->name());
}
for (int childRow = 0, count = child->childCount(); childRow < count; ++childRow) {
const TestTreeItem *grandChild = child->childItem(childRow);
if (files.contains(grandChild->filePath()))
result.insert(grandChild->filePath(), child->name());
}
}
return result;
}
}; };
} // namespace Internal } // namespace Internal

View File

@@ -234,7 +234,7 @@ static bool handleQtTest(QFutureInterface<TestParseResultPtr> futureInterface,
void QtTestParser::init(const QStringList &filesToParse) void QtTestParser::init(const QStringList &filesToParse)
{ {
m_testCaseNames = TestTreeModel::instance()->testCaseNamesForFiles(id(), filesToParse); m_testCaseNames = QTestUtils::testCaseNamesForFiles(id(), filesToParse);
CppParser::init(filesToParse); CppParser::init(filesToParse);
} }

View File

@@ -244,28 +244,6 @@ void TestTreeModel::sweep()
#endif #endif
} }
// TODO move this function to qtest framework folder as it's only necessary there
QHash<QString, QString> TestTreeModel::testCaseNamesForFiles(const Core::Id &id,
const QStringList &files)
{
QHash<QString, QString> result;
TestTreeItem *rootNode = TestFrameworkManager::instance()->rootNodeForTestFramework(id);
QTC_ASSERT(rootNode, return result);
for (int row = 0, count = rootNode->childCount(); row < count; ++row) {
const TestTreeItem *child = rootNode->childItem(row);
if (files.contains(child->filePath())) {
result.insert(child->filePath(), child->name());
}
for (int childRow = 0, children = child->childCount(); childRow < children; ++childRow) {
const TestTreeItem *grandChild = child->childItem(childRow);
if (files.contains(grandChild->filePath()))
result.insert(grandChild->filePath(), child->name());
}
}
return result;
}
/** /**
* @note after calling this function emit testTreeModelChanged() if it returns true * @note after calling this function emit testTreeModelChanged() if it returns true
*/ */

View File

@@ -76,7 +76,6 @@ public:
void markAllForRemoval(); void markAllForRemoval();
void markForRemoval(const QString &filePath); void markForRemoval(const QString &filePath);
void sweep(); void sweep();
QHash<QString, QString> testCaseNamesForFiles(const Core::Id &id, const QStringList &files);
signals: signals:
void testTreeModelChanged(); void testTreeModelChanged();