2016-05-11 13:02:42 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2016-05-31 14:24:42 +02:00
|
|
|
#include "qttesttreeitem.h"
|
2016-05-11 13:02:42 +02:00
|
|
|
#include "qttestconfiguration.h"
|
|
|
|
|
#include "qttestparser.h"
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/session.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
namespace Autotest {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2016-10-11 16:00:05 +02:00
|
|
|
QtTestTreeItem::QtTestTreeItem(const QString &name, const QString &filePath, TestTreeItem::Type type)
|
|
|
|
|
: TestTreeItem(name, filePath, type)
|
|
|
|
|
{
|
|
|
|
|
if (type == TestDataTag)
|
|
|
|
|
setChecked(Qt::Checked);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-31 14:24:42 +02:00
|
|
|
QVariant QtTestTreeItem::data(int column, int role) const
|
2016-05-11 13:02:42 +02:00
|
|
|
{
|
|
|
|
|
switch (role) {
|
2017-01-04 12:06:46 +01:00
|
|
|
case Qt::DisplayRole:
|
|
|
|
|
if (type() == Root)
|
|
|
|
|
break;
|
|
|
|
|
return QVariant(name() + nameSuffix());
|
2016-05-11 13:02:42 +02:00
|
|
|
case Qt::CheckStateRole:
|
|
|
|
|
switch (type()) {
|
|
|
|
|
case TestDataFunction:
|
|
|
|
|
case TestSpecialFunction:
|
|
|
|
|
return QVariant();
|
|
|
|
|
default:
|
|
|
|
|
return checked();
|
|
|
|
|
}
|
|
|
|
|
case ItalicRole:
|
|
|
|
|
switch (type()) {
|
|
|
|
|
case TestDataFunction:
|
|
|
|
|
case TestSpecialFunction:
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return TestTreeItem::data(column, role);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-11 16:00:05 +02:00
|
|
|
Qt::ItemFlags QtTestTreeItem::flags(int column) const
|
|
|
|
|
{
|
|
|
|
|
static const Qt::ItemFlags defaultFlags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
|
|
|
|
switch (type()) {
|
|
|
|
|
case TestDataTag:
|
|
|
|
|
return defaultFlags | Qt::ItemIsUserCheckable;
|
|
|
|
|
case TestFunctionOrSet:
|
|
|
|
|
return defaultFlags | Qt::ItemIsAutoTristate | Qt::ItemIsUserCheckable;
|
|
|
|
|
default:
|
|
|
|
|
return TestTreeItem::flags(column);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-31 14:24:42 +02:00
|
|
|
bool QtTestTreeItem::canProvideTestConfiguration() const
|
2016-05-11 13:02:42 +02:00
|
|
|
{
|
|
|
|
|
switch (type()) {
|
|
|
|
|
case TestCase:
|
|
|
|
|
case TestFunctionOrSet:
|
|
|
|
|
case TestDataTag:
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-15 12:29:24 +02:00
|
|
|
bool QtTestTreeItem::canProvideDebugConfiguration() const
|
|
|
|
|
{
|
|
|
|
|
return canProvideTestConfiguration();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-31 14:24:42 +02:00
|
|
|
TestConfiguration *QtTestTreeItem::testConfiguration() const
|
2016-05-11 13:02:42 +02:00
|
|
|
{
|
|
|
|
|
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
2017-02-13 10:05:06 +01:00
|
|
|
QTC_ASSERT(project, return nullptr);
|
2016-05-11 13:02:42 +02:00
|
|
|
|
2017-02-13 10:05:06 +01:00
|
|
|
QtTestConfiguration *config = nullptr;
|
2016-05-11 13:02:42 +02:00
|
|
|
switch (type()) {
|
|
|
|
|
case TestCase:
|
|
|
|
|
config = new QtTestConfiguration;
|
|
|
|
|
config->setTestCaseCount(childCount());
|
2017-02-21 14:53:58 +01:00
|
|
|
config->setProjectFile(proFile());
|
2016-05-11 13:02:42 +02:00
|
|
|
config->setProject(project);
|
|
|
|
|
break;
|
|
|
|
|
case TestFunctionOrSet: {
|
|
|
|
|
TestTreeItem *parent = parentItem();
|
|
|
|
|
config = new QtTestConfiguration();
|
|
|
|
|
config->setTestCases(QStringList(name()));
|
2017-02-21 14:53:58 +01:00
|
|
|
config->setProjectFile(parent->proFile());
|
2016-05-11 13:02:42 +02:00
|
|
|
config->setProject(project);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-05-31 14:24:42 +02:00
|
|
|
case TestDataTag: {
|
2016-05-11 13:02:42 +02:00
|
|
|
const TestTreeItem *function = parentItem();
|
2017-02-13 10:05:06 +01:00
|
|
|
const TestTreeItem *parent = function ? function->parentItem() : nullptr;
|
2016-05-11 13:02:42 +02:00
|
|
|
if (!parent)
|
2017-02-13 10:05:06 +01:00
|
|
|
return nullptr;
|
2016-09-29 12:15:43 +02:00
|
|
|
const QString functionWithTag = function->name() + ':' + name();
|
2016-05-11 13:02:42 +02:00
|
|
|
config = new QtTestConfiguration();
|
|
|
|
|
config->setTestCases(QStringList(functionWithTag));
|
2017-02-21 14:53:58 +01:00
|
|
|
config->setProjectFile(parent->proFile());
|
2016-05-11 13:02:42 +02:00
|
|
|
config->setProject(project);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
2017-02-13 10:05:06 +01:00
|
|
|
return nullptr;
|
2016-05-11 13:02:42 +02:00
|
|
|
}
|
2017-06-09 09:30:21 +02:00
|
|
|
if (config)
|
|
|
|
|
config->setInternalTargets(internalTargets());
|
2016-05-11 13:02:42 +02:00
|
|
|
return config;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-15 12:29:24 +02:00
|
|
|
TestConfiguration *QtTestTreeItem::debugConfiguration() const
|
|
|
|
|
{
|
|
|
|
|
QtTestConfiguration *config = static_cast<QtTestConfiguration *>(testConfiguration());
|
2016-08-12 09:07:38 +02:00
|
|
|
if (config)
|
|
|
|
|
config->setRunMode(DebuggableTestConfiguration::Debug);
|
2016-06-15 12:29:24 +02:00
|
|
|
return config;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-31 14:24:42 +02:00
|
|
|
QList<TestConfiguration *> QtTestTreeItem::getAllTestConfigurations() const
|
2016-05-11 13:02:42 +02:00
|
|
|
{
|
|
|
|
|
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 QtTestConfiguration();
|
|
|
|
|
tc->setTestCaseCount(child->childCount());
|
2017-02-21 14:53:58 +01:00
|
|
|
tc->setProjectFile(child->proFile());
|
2016-05-11 13:02:42 +02:00
|
|
|
tc->setProject(project);
|
2017-06-09 09:30:21 +02:00
|
|
|
tc->setInternalTargets(child->internalTargets());
|
2016-05-11 13:02:42 +02:00
|
|
|
result << tc;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-31 14:24:42 +02:00
|
|
|
QList<TestConfiguration *> QtTestTreeItem::getSelectedTestConfigurations() const
|
2016-05-11 13:02:42 +02:00
|
|
|
{
|
|
|
|
|
QList<TestConfiguration *> result;
|
|
|
|
|
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
|
|
|
|
if (!project || type() != Root)
|
|
|
|
|
return result;
|
|
|
|
|
|
2017-02-13 10:05:06 +01:00
|
|
|
QtTestConfiguration *testConfiguration = nullptr;
|
2016-05-11 13:02:42 +02:00
|
|
|
|
|
|
|
|
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 QtTestConfiguration();
|
|
|
|
|
testConfiguration->setTestCaseCount(child->childCount());
|
2017-02-21 14:53:58 +01:00
|
|
|
testConfiguration->setProjectFile(child->proFile());
|
2016-05-11 13:02:42 +02:00
|
|
|
testConfiguration->setProject(project);
|
2017-06-09 09:30:21 +02:00
|
|
|
testConfiguration->setInternalTargets(child->internalTargets());
|
2016-05-11 13:02:42 +02:00
|
|
|
result << testConfiguration;
|
|
|
|
|
continue;
|
|
|
|
|
case Qt::PartiallyChecked:
|
|
|
|
|
default:
|
|
|
|
|
int grandChildCount = child->childCount();
|
|
|
|
|
QStringList testCases;
|
|
|
|
|
for (int grandChildRow = 0; grandChildRow < grandChildCount; ++grandChildRow) {
|
|
|
|
|
const TestTreeItem *grandChild = child->childItem(grandChildRow);
|
2016-10-11 16:00:05 +02:00
|
|
|
if (grandChild->checked() == Qt::Checked) {
|
2016-05-11 13:02:42 +02:00
|
|
|
testCases << grandChild->name();
|
2016-10-11 16:00:05 +02:00
|
|
|
} 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);
|
|
|
|
|
if (dataTag->checked() == Qt::Checked)
|
|
|
|
|
testCases << funcName + ':' + dataTag->name();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-11 13:02:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
testConfiguration = new QtTestConfiguration();
|
|
|
|
|
testConfiguration->setTestCases(testCases);
|
2017-02-21 14:53:58 +01:00
|
|
|
testConfiguration->setProjectFile(child->proFile());
|
2016-05-11 13:02:42 +02:00
|
|
|
testConfiguration->setProject(project);
|
2017-06-09 09:30:21 +02:00
|
|
|
testConfiguration->setInternalTargets(child->internalTargets());
|
2016-05-11 13:02:42 +02:00
|
|
|
result << testConfiguration;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-31 14:24:42 +02:00
|
|
|
TestTreeItem *QtTestTreeItem::find(const TestParseResult *result)
|
2016-05-11 13:02:42 +02:00
|
|
|
{
|
2017-02-13 10:05:06 +01:00
|
|
|
QTC_ASSERT(result, return nullptr);
|
2016-05-11 13:02:42 +02:00
|
|
|
|
|
|
|
|
switch (type()) {
|
|
|
|
|
case Root:
|
|
|
|
|
return findChildByFile(result->fileName);
|
2017-01-04 12:15:39 +01:00
|
|
|
case TestCase: {
|
|
|
|
|
const QtTestParseResult *qtResult = static_cast<const QtTestParseResult *>(result);
|
|
|
|
|
return findChildByNameAndInheritance(qtResult->displayName, qtResult->inherited());
|
|
|
|
|
}
|
2016-05-11 13:02:42 +02:00
|
|
|
case TestFunctionOrSet:
|
|
|
|
|
case TestDataFunction:
|
|
|
|
|
case TestSpecialFunction:
|
|
|
|
|
return findChildByName(result->name);
|
|
|
|
|
default:
|
2017-02-13 10:05:06 +01:00
|
|
|
return nullptr;
|
2016-05-11 13:02:42 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-31 14:24:42 +02:00
|
|
|
bool QtTestTreeItem::modify(const TestParseResult *result)
|
2016-05-11 13:02:42 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(result, return false);
|
|
|
|
|
|
|
|
|
|
switch (type()) {
|
|
|
|
|
case TestCase:
|
2017-05-10 13:42:44 +02:00
|
|
|
return modifyTestCaseContent(result);
|
2016-05-11 13:02:42 +02:00
|
|
|
case TestFunctionOrSet:
|
|
|
|
|
case TestDataFunction:
|
|
|
|
|
case TestSpecialFunction:
|
|
|
|
|
return modifyTestFunctionContent(result);
|
|
|
|
|
case TestDataTag:
|
2017-05-10 13:42:44 +02:00
|
|
|
return modifyDataTagContent(result);
|
2016-05-11 13:02:42 +02:00
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-04 12:15:39 +01:00
|
|
|
TestTreeItem *QtTestTreeItem::findChildByNameAndInheritance(const QString &name, bool inherited) const
|
|
|
|
|
{
|
|
|
|
|
return findChildBy([name, inherited](const TestTreeItem *other) -> bool {
|
|
|
|
|
const QtTestTreeItem *qtOther = static_cast<const QtTestTreeItem *>(other);
|
|
|
|
|
return qtOther->inherited() == inherited && qtOther->name() == name;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-04 12:06:46 +01:00
|
|
|
QString QtTestTreeItem::nameSuffix() const
|
|
|
|
|
{
|
2017-02-13 10:05:06 +01:00
|
|
|
static QString inheritedSuffix = QString(" [")
|
2017-01-04 12:06:46 +01:00
|
|
|
+ QCoreApplication::translate("QtTestTreeItem", "inherited")
|
2017-02-13 10:05:06 +01:00
|
|
|
+ QString("]");
|
2017-01-04 12:06:46 +01:00
|
|
|
return m_inherited ? inheritedSuffix : QString();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-11 13:02:42 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Autotest
|