forked from qt-creator/qt-creator
AutoTest: Move functionality from model to item classes
Another preparation for having a consistent interface later on. Change-Id: I573e45101016048de916f4d321b326a24efbe4ee Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
committed by
Christian Stenger
parent
cdf16ced62
commit
842ab2a551
@@ -25,6 +25,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
#include <cpptools/projectpart.h>
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
namespace Autotest {
|
||||
@@ -63,6 +66,20 @@ public:
|
||||
static const QByteArrayList valid = {"QUICK_TEST_MAIN", "QUICK_TEST_OPENGL_MAIN"};
|
||||
return valid.contains(macro);
|
||||
}
|
||||
|
||||
static QString getCMakeDisplayNameIfNecessary(const QString &filePath, const QString &proFile)
|
||||
{
|
||||
static const QString CMAKE_LISTS = QLatin1String("CMakeLists.txt");
|
||||
if (!proFile.endsWith(CMAKE_LISTS))
|
||||
return QString();
|
||||
|
||||
const QList<CppTools::ProjectPart::Ptr> &projectParts
|
||||
= CppTools::CppModelManager::instance()->projectPart(filePath);
|
||||
if (projectParts.size())
|
||||
return projectParts.first()->displayName;
|
||||
|
||||
return QString();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -107,12 +107,9 @@ void TestNavigationWidget::contextMenuEvent(QContextMenuEvent *event)
|
||||
const QModelIndex index = list.first();
|
||||
QRect rect(m_view->visualRect(index));
|
||||
if (rect.contains(event->pos())) {
|
||||
// do not provide this menu entry for unnamed Quick Tests as it makes no sense
|
||||
int type = index.data(TypeRole).toInt();
|
||||
const QString &unnamed = tr(Constants::UNNAMED_QUICKTESTS);
|
||||
if ((type == TestTreeItem::TestFunctionOrSet && index.parent().data().toString() != unnamed)
|
||||
|| (type == TestTreeItem::TestCase && index.data().toString() != unnamed)
|
||||
|| (type == TestTreeItem::TestDataTag)) {
|
||||
TestTreeItem *item = static_cast<TestTreeItem *>(
|
||||
m_model->itemForIndex(m_sortFilterModel->mapToSource(index)));
|
||||
if (item->canProvideTestConfiguration()) {
|
||||
runThisTest = new QAction(tr("Run This Test"), &menu);
|
||||
runThisTest->setEnabled(enabled);
|
||||
connect(runThisTest, &QAction::triggered,
|
||||
@@ -256,13 +253,10 @@ void TestNavigationWidget::onRunThisTestTriggered()
|
||||
return;
|
||||
|
||||
TestTreeItem *item = static_cast<TestTreeItem *>(sourceIndex.internalPointer());
|
||||
if (item->type() == TestTreeItem::TestCase || item->type() == TestTreeItem::TestFunctionOrSet
|
||||
|| item->type() == TestTreeItem::TestDataTag) {
|
||||
if (TestConfiguration *configuration = m_model->getTestConfiguration(item)) {
|
||||
TestRunner *runner = TestRunner::instance();
|
||||
runner->setSelectedTests( {configuration} );
|
||||
runner->prepareToRunTests();
|
||||
}
|
||||
if (TestConfiguration *configuration = m_model->getTestConfiguration(item)) {
|
||||
TestRunner *runner = TestRunner::instance();
|
||||
runner->setSelectedTests( {configuration} );
|
||||
runner->prepareToRunTests();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,17 +24,18 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "autotestconstants.h"
|
||||
#include "autotest_utils.h"
|
||||
#include "testconfiguration.h"
|
||||
#include "testtreeitem.h"
|
||||
#include "testtreemodel.h"
|
||||
|
||||
#include <cplusplus/Icons.h>
|
||||
#include <projectexplorer/session.h>
|
||||
#include <texteditor/texteditor.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QIcon>
|
||||
|
||||
#include <texteditor/texteditor.h>
|
||||
|
||||
#include <cplusplus/Icons.h>
|
||||
|
||||
namespace Autotest {
|
||||
namespace Internal {
|
||||
|
||||
@@ -69,51 +70,21 @@ QVariant TestTreeItem::data(int /*column*/, int role) const
|
||||
case Qt::DisplayRole:
|
||||
if (m_type == Root && childCount() == 0)
|
||||
return QString(m_name + QCoreApplication::translate("TestTreeItem", " (none)"));
|
||||
else if (m_name.isEmpty())
|
||||
return QCoreApplication::translate("TestTreeItem", Constants::UNNAMED_QUICKTESTS);
|
||||
else
|
||||
return m_name;
|
||||
case Qt::ToolTipRole:
|
||||
if (m_type == TestCase && m_name.isEmpty()) {
|
||||
return QCoreApplication::translate("TestTreeItem","<p>Give all test cases a name to ensure correct behavior "
|
||||
"when running test cases and to be able to select them.</p>");
|
||||
}
|
||||
return m_filePath;
|
||||
case Qt::DecorationRole:
|
||||
return testTreeIcon(m_type);
|
||||
case Qt::CheckStateRole:
|
||||
switch (m_type) {
|
||||
case Root:
|
||||
case TestDataFunction:
|
||||
case TestSpecialFunction:
|
||||
case TestDataTag:
|
||||
return QVariant();
|
||||
case TestCase:
|
||||
return m_name.isEmpty() ? QVariant() : checked();
|
||||
case TestFunctionOrSet:
|
||||
if (parentItem() && parentItem()->name().isEmpty())
|
||||
return QVariant();
|
||||
return checked();
|
||||
default:
|
||||
return checked();
|
||||
}
|
||||
return QVariant();
|
||||
case LinkRole: {
|
||||
QVariant itemLink;
|
||||
itemLink.setValue(TextEditor::TextEditorWidget::Link(m_filePath, m_line, m_column));
|
||||
return itemLink;
|
||||
}
|
||||
case ItalicRole:
|
||||
switch (m_type) {
|
||||
case TestDataFunction:
|
||||
case TestSpecialFunction:
|
||||
return true;
|
||||
case TestCase:
|
||||
return m_name.isEmpty();
|
||||
case TestFunctionOrSet:
|
||||
return parentItem() ? parentItem()->name().isEmpty() : false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
case TypeRole:
|
||||
return m_type;
|
||||
}
|
||||
@@ -197,14 +168,9 @@ Qt::CheckState TestTreeItem::checked() const
|
||||
case TestCase:
|
||||
case TestFunctionOrSet:
|
||||
return m_checked;
|
||||
case TestDataFunction:
|
||||
case TestSpecialFunction:
|
||||
return Qt::Unchecked;
|
||||
default:
|
||||
if (parent())
|
||||
return parentItem()->m_checked;
|
||||
return Qt::Unchecked;
|
||||
}
|
||||
return Qt::Unchecked;
|
||||
}
|
||||
|
||||
void TestTreeItem::markForRemoval(bool mark)
|
||||
@@ -250,6 +216,16 @@ TestTreeItem *TestTreeItem::findChildByNameAndFile(const QString &name, const QS
|
||||
});
|
||||
}
|
||||
|
||||
QList<TestConfiguration *> TestTreeItem::getAllTestConfigurations() const
|
||||
{
|
||||
return QList<TestConfiguration *>();
|
||||
}
|
||||
|
||||
QList<TestConfiguration *> TestTreeItem::getSelectedTestConfigurations() const
|
||||
{
|
||||
return QList<TestConfiguration *>();
|
||||
}
|
||||
|
||||
void TestTreeItem::revalidateCheckState()
|
||||
{
|
||||
if (childCount() == 0)
|
||||
@@ -343,6 +319,152 @@ AutoTestTreeItem *AutoTestTreeItem::createDataTagItem(const QString &fileName,
|
||||
return tagItem;
|
||||
}
|
||||
|
||||
QVariant AutoTestTreeItem::data(int column, int role) const
|
||||
{
|
||||
switch (role) {
|
||||
case Qt::CheckStateRole:
|
||||
switch (type()) {
|
||||
case Root:
|
||||
case TestDataFunction:
|
||||
case TestSpecialFunction:
|
||||
case TestDataTag:
|
||||
return QVariant();
|
||||
default:
|
||||
return checked();
|
||||
}
|
||||
case ItalicRole:
|
||||
switch (type()) {
|
||||
case TestDataFunction:
|
||||
case TestSpecialFunction:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return TestTreeItem::data(column, role);
|
||||
}
|
||||
|
||||
bool AutoTestTreeItem::canProvideTestConfiguration() const
|
||||
{
|
||||
switch (type()) {
|
||||
case TestCase:
|
||||
case TestFunctionOrSet:
|
||||
case TestDataTag:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
TestConfiguration *AutoTestTreeItem::testConfiguration() const
|
||||
{
|
||||
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
||||
QTC_ASSERT(project, return 0);
|
||||
|
||||
TestConfiguration *config = 0;
|
||||
switch (type()) {
|
||||
case TestCase:
|
||||
config = new TestConfiguration(name(), QStringList(), childCount());
|
||||
config->setProFile(proFile());
|
||||
config->setProject(project);
|
||||
config->setDisplayName(TestUtils::getCMakeDisplayNameIfNecessary(filePath(), proFile()));
|
||||
break;
|
||||
case TestFunctionOrSet: {
|
||||
TestTreeItem *parent = parentItem();
|
||||
config = new TestConfiguration(parent->name(), QStringList() << name());
|
||||
config->setProFile(parent->proFile());
|
||||
config->setProject(project);
|
||||
config->setDisplayName(
|
||||
TestUtils::getCMakeDisplayNameIfNecessary(filePath(), parent->proFile()));
|
||||
break;
|
||||
}
|
||||
case TestDataTag:{
|
||||
const TestTreeItem *function = parentItem();
|
||||
const TestTreeItem *parent = function ? function->parentItem() : 0;
|
||||
if (!parent)
|
||||
return 0;
|
||||
const QString functionWithTag = function->name() + QLatin1Char(':') + name();
|
||||
config = new TestConfiguration(parent->name(), QStringList() << functionWithTag);
|
||||
config->setProFile(parent->proFile());
|
||||
config->setProject(project);
|
||||
config->setDisplayName(TestUtils::getCMakeDisplayNameIfNecessary(filePath(),
|
||||
parent->proFile()));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
QList<TestConfiguration *> AutoTestTreeItem::getAllTestConfigurations() const
|
||||
{
|
||||
QList<TestConfiguration *> result;
|
||||
|
||||
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
||||
if (!project || type() != Root)
|
||||
return result;
|
||||
|
||||
for (int row = 0, count = childCount(); row < count; ++row) {
|
||||
const TestTreeItem *child = childItem(row);
|
||||
|
||||
TestConfiguration *tc = new TestConfiguration(child->name(), QStringList(),
|
||||
child->childCount());
|
||||
tc->setProFile(child->proFile());
|
||||
tc->setProject(project);
|
||||
tc->setDisplayName(TestUtils::getCMakeDisplayNameIfNecessary(child->filePath(),
|
||||
child->proFile()));
|
||||
result << tc;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QList<TestConfiguration *> AutoTestTreeItem::getSelectedTestConfigurations() const
|
||||
{
|
||||
QList<TestConfiguration *> result;
|
||||
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
||||
if (!project || type() != Root)
|
||||
return result;
|
||||
|
||||
TestConfiguration *testConfiguration = 0;
|
||||
|
||||
for (int row = 0, count = childCount(); row < count; ++row) {
|
||||
const TestTreeItem *child = childItem(row);
|
||||
|
||||
switch (child->checked()) {
|
||||
case Qt::Unchecked:
|
||||
continue;
|
||||
case Qt::Checked:
|
||||
testConfiguration = new TestConfiguration(child->name(), QStringList(), child->childCount());
|
||||
testConfiguration->setProFile(child->proFile());
|
||||
testConfiguration->setProject(project);
|
||||
testConfiguration->setDisplayName(
|
||||
TestUtils::getCMakeDisplayNameIfNecessary(child->filePath(), child->proFile()));
|
||||
result << testConfiguration;
|
||||
continue;
|
||||
case Qt::PartiallyChecked:
|
||||
default:
|
||||
const QString childName = child->name();
|
||||
int grandChildCount = child->childCount();
|
||||
QStringList testCases;
|
||||
for (int grandChildRow = 0; grandChildRow < grandChildCount; ++grandChildRow) {
|
||||
const TestTreeItem *grandChild = child->childItem(grandChildRow);
|
||||
if (grandChild->checked() == Qt::Checked)
|
||||
testCases << grandChild->name();
|
||||
}
|
||||
|
||||
testConfiguration = new TestConfiguration(childName, testCases);
|
||||
testConfiguration->setProFile(child->proFile());
|
||||
testConfiguration->setProject(project);
|
||||
testConfiguration->setDisplayName(
|
||||
TestUtils::getCMakeDisplayNameIfNecessary(child->filePath(), child->proFile()));
|
||||
result << testConfiguration;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QuickTestTreeItem *QuickTestTreeItem::createTestItem(const TestParseResult &result)
|
||||
{
|
||||
QuickTestTreeItem *item = new QuickTestTreeItem(result.testCaseName, result.fileName, TestCase);
|
||||
@@ -382,6 +504,238 @@ QuickTestTreeItem *QuickTestTreeItem::createUnnamedQuickFunctionItem(const QStri
|
||||
return item;
|
||||
}
|
||||
|
||||
QVariant QuickTestTreeItem::data(int column, int role) const
|
||||
{
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
if (type() == TestCase && name().isEmpty())
|
||||
return QObject::tr(Constants::UNNAMED_QUICKTESTS);
|
||||
break;
|
||||
case Qt::ToolTipRole:
|
||||
if (type() == TestCase && name().isEmpty())
|
||||
return QObject::tr("<p>Give all test cases a name to ensure correct behavior "
|
||||
"when running test cases and to be able to select them.</p>");
|
||||
break;
|
||||
case Qt::CheckStateRole:
|
||||
switch (type()) {
|
||||
case Root:
|
||||
case TestDataFunction:
|
||||
case TestSpecialFunction:
|
||||
case TestDataTag:
|
||||
return QVariant();
|
||||
case TestCase:
|
||||
return name().isEmpty() ? QVariant() : checked();
|
||||
case TestFunctionOrSet:
|
||||
return (parentItem() && !parentItem()->name().isEmpty()) ? checked() : QVariant();
|
||||
default:
|
||||
return checked();
|
||||
}
|
||||
|
||||
case ItalicRole:
|
||||
switch (type()) {
|
||||
case TestDataFunction:
|
||||
case TestSpecialFunction:
|
||||
return true;
|
||||
case TestCase:
|
||||
return name().isEmpty();
|
||||
case TestFunctionOrSet:
|
||||
return parentItem() ? parentItem()->name().isEmpty() : false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return TestTreeItem::data(column, role);
|
||||
}
|
||||
|
||||
bool QuickTestTreeItem::canProvideTestConfiguration() const
|
||||
{
|
||||
switch (type()) {
|
||||
case TestCase:
|
||||
return !name().isEmpty();
|
||||
case TestFunctionOrSet:
|
||||
return !parentItem()->name().isEmpty();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
TestConfiguration *QuickTestTreeItem::testConfiguration() const
|
||||
{
|
||||
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
||||
QTC_ASSERT(project, return 0);
|
||||
|
||||
TestConfiguration *config = 0;
|
||||
switch (type()) {
|
||||
case TestCase: {
|
||||
QStringList testFunctions;
|
||||
for (int row = 0, count = childCount(); row < count; ++row)
|
||||
testFunctions << name() + QLatin1String("::") + childItem(row)->name();
|
||||
config = new TestConfiguration(QString(), testFunctions);
|
||||
config->setProFile(proFile());
|
||||
config->setProject(project);
|
||||
break;
|
||||
}
|
||||
case TestFunctionOrSet: {
|
||||
TestTreeItem *parent = parentItem();
|
||||
QStringList testFunction(parent->name() + QLatin1String("::") + name());
|
||||
config = new TestConfiguration(QString(), testFunction);
|
||||
config->setProFile(parent->proFile());
|
||||
config->setProject(project);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
QList<TestConfiguration *> QuickTestTreeItem::getAllTestConfigurations() const
|
||||
{
|
||||
QList<TestConfiguration *> result;
|
||||
|
||||
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
||||
if (!project || type() != Root)
|
||||
return result;
|
||||
|
||||
QHash<QString, int> foundProFiles;
|
||||
for (int row = 0, count = childCount(); row < count; ++row) {
|
||||
const TestTreeItem *child = childItem(row);
|
||||
// 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);
|
||||
const QString &proFile = grandChild->proFile();
|
||||
foundProFiles.insert(proFile, foundProFiles[proFile] + 1);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// named Quick Test
|
||||
const QString &proFile = child->proFile();
|
||||
foundProFiles.insert(proFile, foundProFiles[proFile] + child->childCount());
|
||||
}
|
||||
// create TestConfiguration for each project file
|
||||
QHash<QString, int>::ConstIterator it = foundProFiles.begin();
|
||||
QHash<QString, int>::ConstIterator end = foundProFiles.end();
|
||||
for ( ; it != end; ++it) {
|
||||
TestConfiguration *tc = new TestConfiguration(QString(), QStringList(), it.value());
|
||||
tc->setProFile(it.key());
|
||||
tc->setProject(project);
|
||||
result << tc;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QList<TestConfiguration *> QuickTestTreeItem::getSelectedTestConfigurations() const
|
||||
{
|
||||
QList<TestConfiguration *> result;
|
||||
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
||||
if (!project || type() != Root)
|
||||
return result;
|
||||
|
||||
TestConfiguration *tc = 0;
|
||||
QHash<QString, TestConfiguration *> foundProFiles;
|
||||
// unnamed Quick Tests must be handled first
|
||||
if (TestTreeItem *unnamed = unnamedQuickTests()) {
|
||||
for (int childRow = 0, ccount = unnamed->childCount(); childRow < ccount; ++ childRow) {
|
||||
const TestTreeItem *grandChild = unnamed->childItem(childRow);
|
||||
const QString &proFile = grandChild->proFile();
|
||||
if (foundProFiles.contains(proFile)) {
|
||||
QTC_ASSERT(tc,
|
||||
qWarning() << "Illegal state (unnamed Quick Test listed as named)";
|
||||
return QList<TestConfiguration *>());
|
||||
foundProFiles[proFile]->setTestCaseCount(tc->testCaseCount() + 1);
|
||||
} else {
|
||||
tc = new TestConfiguration(QString(), QStringList());
|
||||
tc->setTestCaseCount(1);
|
||||
tc->setUnnamedOnly(true);
|
||||
tc->setProFile(proFile);
|
||||
tc->setProject(project);
|
||||
foundProFiles.insert(proFile, tc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int row = 0, count = childCount(); row < count; ++row) {
|
||||
const TestTreeItem *child = childItem(row);
|
||||
// unnamed Quick Tests have been handled separately already
|
||||
if (child->name().isEmpty())
|
||||
continue;
|
||||
|
||||
// named Quick Tests
|
||||
switch (child->checked()) {
|
||||
case Qt::Unchecked:
|
||||
continue;
|
||||
case Qt::Checked:
|
||||
case Qt::PartiallyChecked:
|
||||
default:
|
||||
QStringList testFunctions;
|
||||
int grandChildCount = child->childCount();
|
||||
for (int grandChildRow = 0; grandChildRow < grandChildCount; ++grandChildRow) {
|
||||
const TestTreeItem *grandChild = child->childItem(grandChildRow);
|
||||
if (grandChild->type() != TestFunctionOrSet)
|
||||
continue;
|
||||
testFunctions << child->name() + QLatin1String("::") + grandChild->name();
|
||||
}
|
||||
if (foundProFiles.contains(child->proFile())) {
|
||||
tc = foundProFiles[child->proFile()];
|
||||
QStringList oldFunctions(tc->testCases());
|
||||
// if oldFunctions.size() is 0 this test configuration is used for at least one
|
||||
// unnamed test case
|
||||
if (oldFunctions.size() == 0) {
|
||||
tc->setTestCaseCount(tc->testCaseCount() + testFunctions.size());
|
||||
tc->setUnnamedOnly(false);
|
||||
} else {
|
||||
oldFunctions << testFunctions;
|
||||
tc->setTestCases(oldFunctions);
|
||||
}
|
||||
} else {
|
||||
tc = new TestConfiguration(QString(), testFunctions);
|
||||
tc->setProFile(child->proFile());
|
||||
tc->setProject(project);
|
||||
foundProFiles.insert(child->proFile(), tc);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
QHash<QString, TestConfiguration *>::ConstIterator it = foundProFiles.begin();
|
||||
QHash<QString, TestConfiguration *>::ConstIterator end = foundProFiles.end();
|
||||
for ( ; it != end; ++it) {
|
||||
TestConfiguration *config = it.value();
|
||||
if (!config->unnamedOnly())
|
||||
result << config;
|
||||
else
|
||||
delete config;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
TestTreeItem *QuickTestTreeItem::unnamedQuickTests() const
|
||||
{
|
||||
if (type() != Root)
|
||||
return 0;
|
||||
|
||||
for (int row = 0, count = childCount(); row < count; ++row) {
|
||||
TestTreeItem *child = childItem(row);
|
||||
if (child->name().isEmpty())
|
||||
return child;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static QString gtestFilter(GoogleTestTreeItem::TestStates states)
|
||||
{
|
||||
if ((states & GoogleTestTreeItem::Parameterized) && (states & GoogleTestTreeItem::Typed))
|
||||
return QLatin1String("*/%1/*.%2");
|
||||
if (states & GoogleTestTreeItem::Parameterized)
|
||||
return QLatin1String("*/%1.%2/*");
|
||||
if (states & GoogleTestTreeItem::Typed)
|
||||
return QLatin1String("%1/*.%2");
|
||||
return QLatin1String("%1.%2");
|
||||
}
|
||||
|
||||
GoogleTestTreeItem *GoogleTestTreeItem::createTestItem(const TestParseResult &result)
|
||||
{
|
||||
GoogleTestTreeItem *item = new GoogleTestTreeItem(result.testCaseName, QString(), TestCase);
|
||||
@@ -414,12 +768,22 @@ QVariant GoogleTestTreeItem::data(int column, int role) const
|
||||
switch (role) {
|
||||
case Qt::DisplayRole: {
|
||||
if (type() == TestTreeItem::Root)
|
||||
return TestTreeItem::data(column, role);
|
||||
break;
|
||||
|
||||
const QString &displayName = (m_state & GoogleTestTreeItem::Disabled)
|
||||
? name().mid(9) : name();
|
||||
return QVariant(displayName + nameSuffix());
|
||||
}
|
||||
case Qt::CheckStateRole:
|
||||
switch (type()) {
|
||||
case TestCase:
|
||||
case TestFunctionOrSet:
|
||||
return checked();
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
case ItalicRole:
|
||||
return false;
|
||||
case StateRole:
|
||||
return (int)m_state;
|
||||
default:
|
||||
@@ -428,6 +792,156 @@ QVariant GoogleTestTreeItem::data(int column, int role) const
|
||||
return TestTreeItem::data(column, role);
|
||||
}
|
||||
|
||||
TestConfiguration *GoogleTestTreeItem::testConfiguration() const
|
||||
{
|
||||
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
||||
QTC_ASSERT(project, return 0);
|
||||
|
||||
TestConfiguration *config = 0;
|
||||
switch (type()) {
|
||||
case TestCase: {
|
||||
const QString &testSpecifier = gtestFilter(state()).arg(name()).arg(QLatin1Char('*'));
|
||||
if (int count = childCount()) {
|
||||
config = new TestConfiguration(QString(), QStringList(testSpecifier));
|
||||
config->setTestCaseCount(count);
|
||||
config->setProFile(proFile());
|
||||
config->setProject(project);
|
||||
// item has no filePath set - so take it of the first children
|
||||
config->setDisplayName(
|
||||
TestUtils::getCMakeDisplayNameIfNecessary(childItem(0)->filePath(), proFile()));
|
||||
config->setTestType(TestTypeGTest);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TestFunctionOrSet: {
|
||||
GoogleTestTreeItem *parent = static_cast<GoogleTestTreeItem *>(parentItem());
|
||||
if (parent)
|
||||
return 0;
|
||||
const QString &testSpecifier = gtestFilter(parent->state()).arg(parent->name()).arg(name());
|
||||
config = new TestConfiguration(QString(), QStringList(testSpecifier));
|
||||
config->setProFile(proFile());
|
||||
config->setProject(project);
|
||||
config->setDisplayName(
|
||||
TestUtils::getCMakeDisplayNameIfNecessary(filePath(), parent->proFile()));
|
||||
config->setTestType(TestTypeGTest);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
// used as key inside getAllTestCases()/getSelectedTestCases() for Google Tests
|
||||
class ProFileWithDisplayName
|
||||
{
|
||||
public:
|
||||
ProFileWithDisplayName(const QString &file, const QString &name)
|
||||
: proFile(file), displayName(name) {}
|
||||
QString proFile;
|
||||
QString displayName;
|
||||
|
||||
bool operator==(const ProFileWithDisplayName &rhs) const
|
||||
{
|
||||
return proFile == rhs.proFile && displayName == rhs.displayName;
|
||||
}
|
||||
};
|
||||
|
||||
// needed as ProFileWithDisplayName is used as key inside a QHash
|
||||
bool operator<(const ProFileWithDisplayName &lhs, const ProFileWithDisplayName &rhs)
|
||||
{
|
||||
return lhs.proFile == rhs.proFile ? lhs.displayName < rhs.displayName
|
||||
: lhs.proFile < rhs.proFile;
|
||||
}
|
||||
|
||||
// needed as ProFileWithDisplayName is used as a key inside a QHash
|
||||
uint qHash(const ProFileWithDisplayName &lhs)
|
||||
{
|
||||
return ::qHash(lhs.proFile) ^ ::qHash(lhs.displayName);
|
||||
}
|
||||
|
||||
QList<TestConfiguration *> GoogleTestTreeItem::getAllTestConfigurations() const
|
||||
{
|
||||
QList<TestConfiguration *> result;
|
||||
|
||||
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
||||
if (!project || type() != Root)
|
||||
return result;
|
||||
|
||||
QHash<ProFileWithDisplayName, int> proFilesWithTestSets;
|
||||
for (int row = 0, count = childCount(); row < count; ++row) {
|
||||
const GoogleTestTreeItem *child = static_cast<const GoogleTestTreeItem *>(childItem(row));
|
||||
|
||||
const int grandChildCount = child->childCount();
|
||||
for (int grandChildRow = 0; grandChildRow < grandChildCount; ++grandChildRow) {
|
||||
const TestTreeItem *grandChild = child->childItem(grandChildRow);
|
||||
if (grandChild->checked() == Qt::Checked) {
|
||||
ProFileWithDisplayName key(grandChild->proFile(),
|
||||
TestUtils::getCMakeDisplayNameIfNecessary(grandChild->filePath(),
|
||||
grandChild->proFile()));
|
||||
|
||||
proFilesWithTestSets.insert(key, proFilesWithTestSets[key] + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QHash<ProFileWithDisplayName, int>::ConstIterator it = proFilesWithTestSets.begin();
|
||||
QHash<ProFileWithDisplayName, int>::ConstIterator end = proFilesWithTestSets.end();
|
||||
for ( ; it != end; ++it) {
|
||||
const ProFileWithDisplayName &key = it.key();
|
||||
TestConfiguration *tc = new TestConfiguration(QString(), QStringList(), it.value());
|
||||
tc->setTestType(TestTypeGTest);
|
||||
tc->setProFile(key.proFile);
|
||||
tc->setDisplayName(key.displayName);
|
||||
tc->setProject(project);
|
||||
result << tc;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QList<TestConfiguration *> GoogleTestTreeItem::getSelectedTestConfigurations() const
|
||||
{
|
||||
QList<TestConfiguration *> result;
|
||||
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
||||
if (!project || type() != Root)
|
||||
return result;
|
||||
|
||||
QHash<ProFileWithDisplayName, QStringList> proFilesWithCheckedTestSets;
|
||||
for (int row = 0, count = childCount(); row < count; ++row) {
|
||||
const GoogleTestTreeItem *child = static_cast<const GoogleTestTreeItem *>(childItem(row));
|
||||
if (child->checked() == Qt::Unchecked)
|
||||
continue;
|
||||
|
||||
int grandChildCount = child->childCount();
|
||||
for (int grandChildRow = 0; grandChildRow < grandChildCount; ++grandChildRow) {
|
||||
const TestTreeItem *grandChild = child->childItem(grandChildRow);
|
||||
if (grandChild->checked() == Qt::Checked) {
|
||||
ProFileWithDisplayName key(grandChild->proFile(),
|
||||
TestUtils::getCMakeDisplayNameIfNecessary(grandChild->filePath(),
|
||||
grandChild->proFile()));
|
||||
|
||||
proFilesWithCheckedTestSets[key].append(
|
||||
gtestFilter(child->state()).arg(child->name()).arg(grandChild->name()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QHash<ProFileWithDisplayName, QStringList>::ConstIterator it = proFilesWithCheckedTestSets.begin();
|
||||
QHash<ProFileWithDisplayName, QStringList>::ConstIterator end = proFilesWithCheckedTestSets.end();
|
||||
for ( ; it != end; ++it) {
|
||||
const ProFileWithDisplayName &key = it.key();
|
||||
TestConfiguration *tc = new TestConfiguration(QString(), it.value());
|
||||
tc->setTestType(TestTypeGTest);
|
||||
tc->setProFile(key.proFile);
|
||||
tc->setDisplayName(key.displayName);
|
||||
tc->setProject(project);
|
||||
result << tc;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool GoogleTestTreeItem::modifyTestSetContent(const QString &fileName,
|
||||
const TestCodeLocationAndType &location)
|
||||
{
|
||||
@@ -445,7 +959,7 @@ TestTreeItem *GoogleTestTreeItem::findChildByNameStateAndFile(const QString &nam
|
||||
const QString &proFile)
|
||||
{
|
||||
return findChildBy([name, state, proFile](const TestTreeItem *other) -> bool {
|
||||
GoogleTestTreeItem *gtestItem = const_cast<TestTreeItem *>(other)->asGoogleTestTreeItem();
|
||||
const GoogleTestTreeItem *gtestItem = static_cast<const GoogleTestTreeItem *>(other);
|
||||
return other->proFile() == proFile
|
||||
&& other->name() == name
|
||||
&& gtestItem->state() == state;
|
||||
|
||||
@@ -48,6 +48,7 @@ class AutoTestTreeItem;
|
||||
class QuickTestTreeItem;
|
||||
class GoogleTestTreeItem;
|
||||
struct TestParseResult;
|
||||
class TestConfiguration;
|
||||
|
||||
class TestTreeItem : public Utils::TreeItem
|
||||
{
|
||||
@@ -84,8 +85,8 @@ public:
|
||||
unsigned column() const { return m_column; }
|
||||
QString proFile() const { return m_proFile; }
|
||||
void setProFile(const QString &proFile) { m_proFile = proFile; }
|
||||
void setChecked(const Qt::CheckState checked);
|
||||
Qt::CheckState checked() const;
|
||||
virtual void setChecked(const Qt::CheckState checked);
|
||||
virtual Qt::CheckState checked() const;
|
||||
Type type() const { return m_type; }
|
||||
void markForRemoval(bool mark);
|
||||
void markForRemovalRecursively(bool mark);
|
||||
@@ -98,12 +99,10 @@ public:
|
||||
TestTreeItem *findChildByFile(const QString &filePath);
|
||||
TestTreeItem *findChildByNameAndFile(const QString &name, const QString &filePath);
|
||||
|
||||
virtual AutoTestTreeItem *asAutoTestTreeItem() { return 0; }
|
||||
virtual QuickTestTreeItem *asQuickTestTreeItem() { return 0; }
|
||||
virtual GoogleTestTreeItem *asGoogleTestTreeItem() { return 0; }
|
||||
virtual const AutoTestTreeItem *asAutoTestTreeItem() const { return 0; }
|
||||
virtual const QuickTestTreeItem *asQuickTestTreeItem() const { return 0; }
|
||||
virtual const GoogleTestTreeItem *asGoogleTestTreeItem() const { return 0; }
|
||||
virtual bool canProvideTestConfiguration() const { return false; }
|
||||
virtual TestConfiguration *testConfiguration() const { return 0; }
|
||||
virtual QList<TestConfiguration *> getAllTestConfigurations() const;
|
||||
virtual QList<TestConfiguration *> getSelectedTestConfigurations() const;
|
||||
|
||||
protected:
|
||||
bool modifyFilePath(const QString &filePath);
|
||||
@@ -139,15 +138,18 @@ public:
|
||||
AutoTestTreeItem(const QString &name = QString(), const QString &filePath = QString(),
|
||||
Type type = Root) : TestTreeItem(name, filePath, type) {}
|
||||
|
||||
virtual AutoTestTreeItem *asAutoTestTreeItem() override { return this; }
|
||||
virtual const AutoTestTreeItem *asAutoTestTreeItem() const override { return this; }
|
||||
|
||||
static AutoTestTreeItem *createTestItem(const TestParseResult &result);
|
||||
static AutoTestTreeItem *createFunctionItem(const QString &functionName,
|
||||
const TestCodeLocationAndType &location,
|
||||
const TestCodeLocationList &dataTags);
|
||||
static AutoTestTreeItem *createDataTagItem(const QString &fileName,
|
||||
const TestCodeLocationAndType &location);
|
||||
|
||||
QVariant data(int column, int role) const override;
|
||||
bool canProvideTestConfiguration() const override;
|
||||
TestConfiguration *testConfiguration() const override;
|
||||
QList<TestConfiguration *> getAllTestConfigurations() const override;
|
||||
QList<TestConfiguration *> getSelectedTestConfigurations() const override;
|
||||
};
|
||||
|
||||
class QuickTestTreeItem : public TestTreeItem
|
||||
@@ -156,15 +158,21 @@ public:
|
||||
QuickTestTreeItem(const QString &name = QString(), const QString &filePath = QString(),
|
||||
Type type = Root) : TestTreeItem(name, filePath, type) {}
|
||||
|
||||
virtual QuickTestTreeItem *asQuickTestTreeItem() override { return this; }
|
||||
virtual const QuickTestTreeItem *asQuickTestTreeItem() const override { return this; }
|
||||
|
||||
static QuickTestTreeItem *createTestItem(const TestParseResult &result);
|
||||
static QuickTestTreeItem *createFunctionItem(const QString &functionName,
|
||||
const TestCodeLocationAndType &location);
|
||||
static QuickTestTreeItem *createUnnamedQuickTestItem(const TestParseResult &result);
|
||||
static QuickTestTreeItem *createUnnamedQuickFunctionItem(const QString &functionName,
|
||||
const TestParseResult &result);
|
||||
|
||||
QVariant data(int column, int role) const override;
|
||||
bool canProvideTestConfiguration() const override;
|
||||
TestConfiguration *testConfiguration() const override;
|
||||
QList<TestConfiguration *> getAllTestConfigurations() const override;
|
||||
QList<TestConfiguration *> getSelectedTestConfigurations() const override;
|
||||
|
||||
private:
|
||||
TestTreeItem *unnamedQuickTests() const;
|
||||
};
|
||||
|
||||
class GoogleTestTreeItem : public TestTreeItem
|
||||
@@ -184,14 +192,15 @@ public:
|
||||
GoogleTestTreeItem(const QString &name = QString(), const QString &filePath = QString(),
|
||||
Type type = Root) : TestTreeItem(name, filePath, type), m_state(Enabled) {}
|
||||
|
||||
virtual GoogleTestTreeItem *asGoogleTestTreeItem() override { return this; }
|
||||
virtual const GoogleTestTreeItem *asGoogleTestTreeItem() const override { return this; }
|
||||
|
||||
static GoogleTestTreeItem *createTestItem(const TestParseResult &result);
|
||||
static GoogleTestTreeItem *createTestSetItem(const TestParseResult &result,
|
||||
const TestCodeLocationAndType &location);
|
||||
|
||||
QVariant data(int column, int role) const override;
|
||||
bool canProvideTestConfiguration() const override { return type() != Root; }
|
||||
TestConfiguration *testConfiguration() const override;
|
||||
QList<TestConfiguration *> getAllTestConfigurations() const override;
|
||||
QList<TestConfiguration *> getSelectedTestConfigurations() const override;
|
||||
|
||||
void setStates(TestStates states) { m_state = states; }
|
||||
void setState(TestState state) { m_state |= state; }
|
||||
|
||||
@@ -31,15 +31,10 @@
|
||||
#include "testtreemodel.h"
|
||||
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
#include <cpptools/projectpart.h>
|
||||
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/session.h>
|
||||
|
||||
#include <qmljs/qmljsmodelmanagerinterface.h>
|
||||
|
||||
#include <texteditor/texteditor.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
namespace Autotest {
|
||||
@@ -190,396 +185,29 @@ bool TestTreeModel::hasTests() const
|
||||
|| m_googleTestRootItem->childCount() > 0;
|
||||
}
|
||||
|
||||
static QString getCMakeDisplayNameIfNecessary(const QString &filePath, const QString &proFile)
|
||||
{
|
||||
static const QString CMAKE_LISTS = QLatin1String("CMakeLists.txt");
|
||||
if (!proFile.endsWith(CMAKE_LISTS))
|
||||
return QString();
|
||||
|
||||
const QList<CppTools::ProjectPart::Ptr> &projectParts
|
||||
= CppTools::CppModelManager::instance()->projectPart(filePath);
|
||||
if (projectParts.size())
|
||||
return projectParts.first()->displayName;
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
// used as key inside getAllTestCases()/getSelectedTestCases() for Google Tests
|
||||
class ProFileWithDisplayName
|
||||
{
|
||||
public:
|
||||
ProFileWithDisplayName(const QString &file, const QString &name)
|
||||
: proFile(file), displayName(name) {}
|
||||
QString proFile;
|
||||
QString displayName;
|
||||
|
||||
bool operator==(const ProFileWithDisplayName &rhs) const
|
||||
{
|
||||
return proFile == rhs.proFile && displayName == rhs.displayName;
|
||||
}
|
||||
};
|
||||
|
||||
// needed as ProFileWithDisplayName is used as key inside a QHash
|
||||
bool operator<(const ProFileWithDisplayName &lhs, const ProFileWithDisplayName &rhs)
|
||||
{
|
||||
return lhs.proFile == rhs.proFile ? lhs.displayName < rhs.displayName
|
||||
: lhs.proFile < rhs.proFile;
|
||||
}
|
||||
|
||||
// needed as ProFileWithDisplayName is used as a key inside a QHash
|
||||
uint qHash(const ProFileWithDisplayName &lhs)
|
||||
{
|
||||
return ::qHash(lhs.proFile) ^ ::qHash(lhs.displayName);
|
||||
}
|
||||
|
||||
QList<TestConfiguration *> TestTreeModel::getAllTestCases() const
|
||||
{
|
||||
QList<TestConfiguration *> result;
|
||||
|
||||
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
||||
if (!project)
|
||||
return result;
|
||||
|
||||
// get all Auto Tests
|
||||
for (int row = 0, count = m_autoTestRootItem->childCount(); row < count; ++row) {
|
||||
const TestTreeItem *child = m_autoTestRootItem->childItem(row);
|
||||
|
||||
TestConfiguration *tc = new TestConfiguration(child->name(), QStringList(),
|
||||
child->childCount());
|
||||
tc->setProFile(child->proFile());
|
||||
tc->setProject(project);
|
||||
tc->setDisplayName(getCMakeDisplayNameIfNecessary(child->filePath(), child->proFile()));
|
||||
result << tc;
|
||||
}
|
||||
|
||||
// get all Quick Tests
|
||||
QHash<QString, int> foundProFiles;
|
||||
for (int row = 0, count = m_quickTestRootItem->childCount(); row < count; ++row) {
|
||||
const TestTreeItem *child = m_quickTestRootItem->childItem(row);
|
||||
// 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);
|
||||
const QString &proFile = grandChild->proFile();
|
||||
foundProFiles.insert(proFile, foundProFiles[proFile] + 1);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// named Quick Test
|
||||
const QString &proFile = child->proFile();
|
||||
foundProFiles.insert(proFile, foundProFiles[proFile] + child->childCount());
|
||||
}
|
||||
// create TestConfiguration for each project file
|
||||
{
|
||||
QHash<QString, int>::ConstIterator it = foundProFiles.begin();
|
||||
QHash<QString, int>::ConstIterator end = foundProFiles.end();
|
||||
for ( ; it != end; ++it) {
|
||||
TestConfiguration *tc = new TestConfiguration(QString(), QStringList(), it.value());
|
||||
tc->setProFile(it.key());
|
||||
tc->setProject(project);
|
||||
result << tc;
|
||||
}
|
||||
}
|
||||
|
||||
foundProFiles.clear();
|
||||
|
||||
// get all Google Tests
|
||||
QHash<ProFileWithDisplayName, int> proFilesWithTestSets;
|
||||
for (int row = 0, count = m_googleTestRootItem->childCount(); row < count; ++row) {
|
||||
const GoogleTestTreeItem *child = m_googleTestRootItem->childItem(row)->asGoogleTestTreeItem();
|
||||
|
||||
const int grandChildCount = child->childCount();
|
||||
for (int grandChildRow = 0; grandChildRow < grandChildCount; ++grandChildRow) {
|
||||
const TestTreeItem *grandChild = child->childItem(grandChildRow);
|
||||
if (grandChild->checked() == Qt::Checked) {
|
||||
ProFileWithDisplayName key(grandChild->proFile(),
|
||||
getCMakeDisplayNameIfNecessary(grandChild->filePath(),
|
||||
grandChild->proFile()));
|
||||
|
||||
proFilesWithTestSets.insert(key, proFilesWithTestSets[key] + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
QHash<ProFileWithDisplayName, int>::ConstIterator it = proFilesWithTestSets.begin();
|
||||
QHash<ProFileWithDisplayName, int>::ConstIterator end = proFilesWithTestSets.end();
|
||||
for ( ; it != end; ++it) {
|
||||
const ProFileWithDisplayName &key = it.key();
|
||||
TestConfiguration *tc = new TestConfiguration(QString(), QStringList(), it.value());
|
||||
tc->setTestType(TestTypeGTest);
|
||||
tc->setProFile(key.proFile);
|
||||
tc->setDisplayName(key.displayName);
|
||||
tc->setProject(project);
|
||||
result << tc;
|
||||
}
|
||||
}
|
||||
|
||||
result.append(m_autoTestRootItem->getAllTestConfigurations());
|
||||
result.append(m_quickTestRootItem->getAllTestConfigurations());
|
||||
result.append(m_googleTestRootItem->getAllTestConfigurations());
|
||||
return result;
|
||||
}
|
||||
|
||||
static QString gtestFilter(GoogleTestTreeItem::TestStates states)
|
||||
{
|
||||
if ((states & GoogleTestTreeItem::Parameterized) && (states & GoogleTestTreeItem::Typed))
|
||||
return QLatin1String("*/%1/*.%2");
|
||||
if (states & GoogleTestTreeItem::Parameterized)
|
||||
return QLatin1String("*/%1.%2/*");
|
||||
if (states & GoogleTestTreeItem::Typed)
|
||||
return QLatin1String("%1/*.%2");
|
||||
return QLatin1String("%1.%2");
|
||||
}
|
||||
|
||||
QList<TestConfiguration *> TestTreeModel::getSelectedTests() const
|
||||
{
|
||||
QList<TestConfiguration *> result;
|
||||
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
||||
if (!project)
|
||||
return result;
|
||||
|
||||
TestConfiguration *testConfiguration = 0;
|
||||
|
||||
for (int row = 0, count = m_autoTestRootItem->childCount(); row < count; ++row) {
|
||||
const TestTreeItem *child = m_autoTestRootItem->childItem(row);
|
||||
|
||||
switch (child->checked()) {
|
||||
case Qt::Unchecked:
|
||||
continue;
|
||||
case Qt::Checked:
|
||||
testConfiguration = new TestConfiguration(child->name(), QStringList(), child->childCount());
|
||||
testConfiguration->setProFile(child->proFile());
|
||||
testConfiguration->setProject(project);
|
||||
testConfiguration->setDisplayName(getCMakeDisplayNameIfNecessary(child->filePath(),
|
||||
child->proFile()));
|
||||
result << testConfiguration;
|
||||
continue;
|
||||
case Qt::PartiallyChecked:
|
||||
default:
|
||||
const QString childName = child->name();
|
||||
int grandChildCount = child->childCount();
|
||||
QStringList testCases;
|
||||
for (int grandChildRow = 0; grandChildRow < grandChildCount; ++grandChildRow) {
|
||||
const TestTreeItem *grandChild = child->childItem(grandChildRow);
|
||||
if (grandChild->checked() == Qt::Checked)
|
||||
testCases << grandChild->name();
|
||||
}
|
||||
|
||||
testConfiguration = new TestConfiguration(childName, testCases);
|
||||
testConfiguration->setProFile(child->proFile());
|
||||
testConfiguration->setProject(project);
|
||||
testConfiguration->setDisplayName(getCMakeDisplayNameIfNecessary(child->filePath(),
|
||||
child->proFile()));
|
||||
result << testConfiguration;
|
||||
}
|
||||
}
|
||||
// Quick Tests must be handled differently - need the calling cpp file to use this in
|
||||
// addProjectInformation() - additionally this must be unique to not execute the same executable
|
||||
// on and on and on...
|
||||
// TODO: do this later on for Auto Tests as well to support strange setups? or redo the model
|
||||
|
||||
QHash<QString, TestConfiguration *> foundProFiles;
|
||||
|
||||
if (TestTreeItem *unnamed = unnamedQuickTests()) {
|
||||
for (int childRow = 0, ccount = unnamed->childCount(); childRow < ccount; ++ childRow) {
|
||||
const TestTreeItem *grandChild = unnamed->childItem(childRow);
|
||||
const QString &proFile = grandChild->proFile();
|
||||
if (foundProFiles.contains(proFile)) {
|
||||
QTC_ASSERT(testConfiguration,
|
||||
qWarning() << "Illegal state (unnamed Quick Test listed as named)";
|
||||
return QList<TestConfiguration *>());
|
||||
foundProFiles[proFile]->setTestCaseCount(testConfiguration->testCaseCount() + 1);
|
||||
} else {
|
||||
testConfiguration = new TestConfiguration(QString(), QStringList());
|
||||
testConfiguration->setTestCaseCount(1);
|
||||
testConfiguration->setUnnamedOnly(true);
|
||||
testConfiguration->setProFile(proFile);
|
||||
testConfiguration->setProject(project);
|
||||
foundProFiles.insert(proFile, testConfiguration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int row = 0, count = m_quickTestRootItem->childCount(); row < count; ++row) {
|
||||
const TestTreeItem *child = m_quickTestRootItem->childItem(row);
|
||||
// unnamed Quick Tests have been handled separately already
|
||||
if (child->name().isEmpty())
|
||||
continue;
|
||||
|
||||
// named Quick Tests
|
||||
switch (child->checked()) {
|
||||
case Qt::Unchecked:
|
||||
continue;
|
||||
case Qt::Checked:
|
||||
case Qt::PartiallyChecked:
|
||||
default:
|
||||
QStringList testFunctions;
|
||||
int grandChildCount = child->childCount();
|
||||
for (int grandChildRow = 0; grandChildRow < grandChildCount; ++grandChildRow) {
|
||||
const TestTreeItem *grandChild = child->childItem(grandChildRow);
|
||||
if (grandChild->type() != TestTreeItem::TestFunctionOrSet)
|
||||
continue;
|
||||
testFunctions << child->name() + QLatin1String("::") + grandChild->name();
|
||||
}
|
||||
TestConfiguration *tc;
|
||||
if (foundProFiles.contains(child->proFile())) {
|
||||
tc = foundProFiles[child->proFile()];
|
||||
QStringList oldFunctions(tc->testCases());
|
||||
// if oldFunctions.size() is 0 this test configuration is used for at least one
|
||||
// unnamed test case
|
||||
if (oldFunctions.size() == 0) {
|
||||
tc->setTestCaseCount(tc->testCaseCount() + testFunctions.size());
|
||||
tc->setUnnamedOnly(false);
|
||||
} else {
|
||||
oldFunctions << testFunctions;
|
||||
tc->setTestCases(oldFunctions);
|
||||
}
|
||||
} else {
|
||||
tc = new TestConfiguration(QString(), testFunctions);
|
||||
tc->setProFile(child->proFile());
|
||||
tc->setProject(project);
|
||||
foundProFiles.insert(child->proFile(), tc);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
QHash<QString, TestConfiguration *>::ConstIterator it = foundProFiles.begin();
|
||||
QHash<QString, TestConfiguration *>::ConstIterator end = foundProFiles.end();
|
||||
for ( ; it != end; ++it) {
|
||||
TestConfiguration *config = it.value();
|
||||
if (!config->unnamedOnly())
|
||||
result << config;
|
||||
else
|
||||
delete config;
|
||||
}
|
||||
}
|
||||
|
||||
// get selected Google Tests
|
||||
QHash<ProFileWithDisplayName, QStringList> proFilesWithCheckedTestSets;
|
||||
for (int row = 0, count = m_googleTestRootItem->childCount(); row < count; ++row) {
|
||||
const auto child = m_googleTestRootItem->childItem(row)->asGoogleTestTreeItem();
|
||||
if (child->checked() == Qt::Unchecked)
|
||||
continue;
|
||||
|
||||
int grandChildCount = child->childCount();
|
||||
for (int grandChildRow = 0; grandChildRow < grandChildCount; ++grandChildRow) {
|
||||
const TestTreeItem *grandChild = child->childItem(grandChildRow);
|
||||
if (grandChild->checked() == Qt::Checked) {
|
||||
ProFileWithDisplayName key(grandChild->proFile(),
|
||||
getCMakeDisplayNameIfNecessary(grandChild->filePath(),
|
||||
grandChild->proFile()));
|
||||
|
||||
proFilesWithCheckedTestSets[key].append(
|
||||
gtestFilter(child->state()).arg(child->name()).arg(grandChild->name()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
QHash<ProFileWithDisplayName, QStringList>::ConstIterator it = proFilesWithCheckedTestSets.begin();
|
||||
QHash<ProFileWithDisplayName, QStringList>::ConstIterator end = proFilesWithCheckedTestSets.end();
|
||||
for ( ; it != end; ++it) {
|
||||
const ProFileWithDisplayName &key = it.key();
|
||||
TestConfiguration *tc = new TestConfiguration(QString(), it.value());
|
||||
tc->setTestType(TestTypeGTest);
|
||||
tc->setProFile(key.proFile);
|
||||
tc->setDisplayName(key.displayName);
|
||||
tc->setProject(project);
|
||||
result << tc;
|
||||
}
|
||||
}
|
||||
|
||||
result.append(m_autoTestRootItem->getSelectedTestConfigurations());
|
||||
result.append(m_quickTestRootItem->getSelectedTestConfigurations());
|
||||
result.append(m_googleTestRootItem->getSelectedTestConfigurations());
|
||||
return result;
|
||||
}
|
||||
|
||||
TestConfiguration *TestTreeModel::getTestConfiguration(const TestTreeItem *item) const
|
||||
{
|
||||
QTC_ASSERT(item != 0, return 0);
|
||||
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
||||
QTC_ASSERT(project, return 0);
|
||||
|
||||
TestConfiguration *config = 0;
|
||||
switch (item->type()) {
|
||||
case TestTreeItem::TestCase: {
|
||||
if (item->asQuickTestTreeItem()) {
|
||||
// Quick Test TestCase
|
||||
QStringList testFunctions;
|
||||
for (int row = 0, count = item->childCount(); row < count; ++row) {
|
||||
testFunctions << item->name() + QLatin1String("::")
|
||||
+ item->childItem(row)->name();
|
||||
}
|
||||
config = new TestConfiguration(QString(), testFunctions);
|
||||
config->setProFile(item->proFile());
|
||||
config->setProject(project);
|
||||
} else if (item->asAutoTestTreeItem()) {
|
||||
// normal auto test
|
||||
config = new TestConfiguration(item->name(), QStringList(), item->childCount());
|
||||
config->setProFile(item->proFile());
|
||||
config->setProject(project);
|
||||
config->setDisplayName(getCMakeDisplayNameIfNecessary(item->filePath(),
|
||||
item->proFile()));
|
||||
} else if (auto gtestItem = item->asGoogleTestTreeItem()) {
|
||||
const QString &testSpecifier
|
||||
= gtestFilter(gtestItem->state()).arg(item->name()).arg(QLatin1Char('*'));
|
||||
|
||||
if (int childCount = item->childCount()) {
|
||||
config = new TestConfiguration(QString(), QStringList(testSpecifier));
|
||||
config->setTestCaseCount(childCount);
|
||||
config->setProFile(item->proFile());
|
||||
config->setProject(project);
|
||||
// item has no filePath set - so take it of the first children
|
||||
config->setDisplayName(getCMakeDisplayNameIfNecessary(
|
||||
item->childItem(0)->filePath(), item->proFile()));
|
||||
config->setTestType(TestTypeGTest);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TestTreeItem::TestFunctionOrSet: {
|
||||
TestTreeItem *parent = item->parentItem();
|
||||
if (parent->asQuickTestTreeItem()) {
|
||||
// it's a Quick Test function of a named TestCase
|
||||
QStringList testFunction(parent->name() + QLatin1String("::") + item->name());
|
||||
config = new TestConfiguration(QString(), testFunction);
|
||||
config->setProFile(parent->proFile());
|
||||
config->setProject(project);
|
||||
} else if (parent->asAutoTestTreeItem()){
|
||||
// normal auto test
|
||||
config = new TestConfiguration(parent->name(), QStringList() << item->name());
|
||||
config->setProFile(parent->proFile());
|
||||
config->setProject(project);
|
||||
config->setDisplayName(getCMakeDisplayNameIfNecessary(item->filePath(),
|
||||
parent->proFile()));
|
||||
} else if (auto gtestParent = parent->asGoogleTestTreeItem()) {
|
||||
const QString &testSpecifier
|
||||
= gtestFilter(gtestParent->state()).arg(parent->name()).arg(item->name());
|
||||
|
||||
config = new TestConfiguration(QString(), QStringList(testSpecifier));
|
||||
config->setProFile(item->proFile());
|
||||
config->setProject(project);
|
||||
config->setDisplayName(getCMakeDisplayNameIfNecessary(item->filePath(),
|
||||
parent->proFile()));
|
||||
config->setTestType(TestTypeGTest);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TestTreeItem::TestDataTag: {
|
||||
const TestTreeItem *function = item->parentItem();
|
||||
const TestTreeItem *parent = function ? function->parentItem() : 0;
|
||||
if (!parent)
|
||||
return 0;
|
||||
const QString functionWithTag = function->name() + QLatin1Char(':') + item->name();
|
||||
config = new TestConfiguration(parent->name(), QStringList() << functionWithTag);
|
||||
config->setProFile(parent->proFile());
|
||||
config->setProject(project);
|
||||
config->setDisplayName(getCMakeDisplayNameIfNecessary(item->filePath(), parent->proFile()));
|
||||
break;
|
||||
}
|
||||
// not supported items
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return config;
|
||||
return item->testConfiguration();
|
||||
}
|
||||
|
||||
bool TestTreeModel::hasUnnamedQuickTests() const
|
||||
@@ -841,7 +469,7 @@ void TestTreeModel::handleGTestParseResult(const TestParseResult &result)
|
||||
toBeModified->appendChild(GoogleTestTreeItem::createTestSetItem(result, location));
|
||||
continue;
|
||||
}
|
||||
bool changed = testSetItem->asGoogleTestTreeItem()->modifyTestSetContent(
|
||||
bool changed = static_cast<GoogleTestTreeItem *>(testSetItem)->modifyTestSetContent(
|
||||
result.fileName, location);
|
||||
testSetItem->markForRemoval(false);
|
||||
if (changed)
|
||||
|
||||
Reference in New Issue
Block a user