2014-10-07 12:30:54 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-10-07 12:30:54 +02:00
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** This file is part of Qt Creator.
|
2014-10-07 12:30:54 +02:00
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
2014-10-07 12:30:54 +02:00
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-22 10:37:55 +01:00
|
|
|
** 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.
|
2014-10-07 12:30:54 +02:00
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** 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.
|
2014-10-07 12:30:54 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2015-09-10 10:57:15 +02:00
|
|
|
#include "autotestconstants.h"
|
2016-05-11 13:02:42 +02:00
|
|
|
#include "itestparser.h"
|
2016-04-08 14:58:23 +02:00
|
|
|
#include "testconfiguration.h"
|
2014-10-07 12:30:54 +02:00
|
|
|
#include "testtreeitem.h"
|
|
|
|
|
|
2016-04-08 14:58:23 +02:00
|
|
|
#include <cplusplus/Icons.h>
|
2017-06-09 09:30:21 +02:00
|
|
|
#include <cpptools/cppmodelmanager.h>
|
2016-04-08 14:58:23 +02:00
|
|
|
#include <texteditor/texteditor.h>
|
2015-09-04 11:02:14 +02:00
|
|
|
|
2015-09-10 10:57:15 +02:00
|
|
|
#include <QIcon>
|
|
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
namespace Autotest {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2015-09-04 11:02:14 +02:00
|
|
|
TestTreeItem::TestTreeItem(const QString &name, const QString &filePath, Type type)
|
2016-06-10 10:37:49 +02:00
|
|
|
: m_name(name),
|
2014-10-07 12:30:54 +02:00
|
|
|
m_filePath(filePath),
|
2016-09-29 12:15:43 +02:00
|
|
|
m_type(type)
|
2014-10-07 12:30:54 +02:00
|
|
|
{
|
2017-02-02 15:05:32 +01:00
|
|
|
m_checked = (m_type == TestCase || m_type == TestFunctionOrSet || m_type == Root)
|
|
|
|
|
? Qt::Checked : Qt::Unchecked;
|
2014-10-07 12:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-10 10:57:15 +02:00
|
|
|
static QIcon testTreeIcon(TestTreeItem::Type type)
|
|
|
|
|
{
|
|
|
|
|
static QIcon icons[] = {
|
|
|
|
|
QIcon(),
|
2016-04-06 23:18:59 +02:00
|
|
|
CPlusPlus::Icons::iconForType(CPlusPlus::Icons::ClassIconType),
|
|
|
|
|
CPlusPlus::Icons::iconForType(CPlusPlus::Icons::SlotPrivateIconType),
|
2017-02-13 10:05:06 +01:00
|
|
|
QIcon(":/images/data.png")
|
2015-09-10 10:57:15 +02:00
|
|
|
};
|
2015-12-07 15:15:00 +01:00
|
|
|
|
2015-10-23 17:33:40 +02:00
|
|
|
if (int(type) >= int(sizeof icons / sizeof *icons))
|
2015-09-10 10:57:15 +02:00
|
|
|
return icons[2];
|
|
|
|
|
return icons[type];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant TestTreeItem::data(int /*column*/, int role) const
|
|
|
|
|
{
|
|
|
|
|
switch (role) {
|
|
|
|
|
case Qt::DisplayRole:
|
2015-12-07 08:26:54 +01:00
|
|
|
if (m_type == Root && childCount() == 0)
|
2016-08-30 11:54:23 +02:00
|
|
|
return QCoreApplication::translate("TestTreeItem", "%1 (none)").arg(m_name);
|
2015-09-10 10:57:15 +02:00
|
|
|
else
|
|
|
|
|
return m_name;
|
|
|
|
|
case Qt::ToolTipRole:
|
|
|
|
|
return m_filePath;
|
|
|
|
|
case Qt::DecorationRole:
|
|
|
|
|
return testTreeIcon(m_type);
|
|
|
|
|
case Qt::CheckStateRole:
|
2016-04-08 14:58:23 +02:00
|
|
|
return QVariant();
|
2015-09-10 10:57:15 +02:00
|
|
|
case LinkRole: {
|
|
|
|
|
QVariant itemLink;
|
|
|
|
|
itemLink.setValue(TextEditor::TextEditorWidget::Link(m_filePath, m_line, m_column));
|
|
|
|
|
return itemLink;
|
|
|
|
|
}
|
|
|
|
|
case ItalicRole:
|
2016-04-08 14:58:23 +02:00
|
|
|
return false;
|
2015-09-10 10:57:15 +02:00
|
|
|
case TypeRole:
|
|
|
|
|
return m_type;
|
2016-04-29 11:15:14 +02:00
|
|
|
case EnabledRole:
|
|
|
|
|
return true;
|
2015-09-10 10:57:15 +02:00
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TestTreeItem::setData(int /*column*/, const QVariant &data, int role)
|
|
|
|
|
{
|
|
|
|
|
if (role == Qt::CheckStateRole) {
|
|
|
|
|
Qt::CheckState old = checked();
|
|
|
|
|
setChecked((Qt::CheckState)data.toInt());
|
|
|
|
|
return checked() != old;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2014-10-07 12:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-28 16:42:14 +02:00
|
|
|
Qt::ItemFlags TestTreeItem::flags(int /*column*/) const
|
|
|
|
|
{
|
|
|
|
|
static const Qt::ItemFlags defaultFlags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
|
|
|
|
switch (m_type) {
|
|
|
|
|
case Root:
|
2017-02-02 15:05:32 +01:00
|
|
|
return Qt::ItemIsEnabled | Qt::ItemIsAutoTristate | Qt::ItemIsUserCheckable;
|
2016-04-28 16:42:14 +02:00
|
|
|
case TestCase:
|
2016-08-03 23:33:32 +03:00
|
|
|
return defaultFlags | Qt::ItemIsAutoTristate | Qt::ItemIsUserCheckable;
|
2016-04-28 16:42:14 +02:00
|
|
|
case TestFunctionOrSet:
|
|
|
|
|
return defaultFlags | Qt::ItemIsUserCheckable;
|
|
|
|
|
case TestDataFunction:
|
|
|
|
|
case TestSpecialFunction:
|
|
|
|
|
case TestDataTag:
|
|
|
|
|
default:
|
|
|
|
|
return defaultFlags;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-10 13:42:44 +02:00
|
|
|
bool TestTreeItem::modifyTestCaseContent(const TestParseResult *result)
|
2014-10-07 12:30:54 +02:00
|
|
|
{
|
2017-05-10 13:42:44 +02:00
|
|
|
bool hasBeenModified = modifyName(result->name);
|
|
|
|
|
hasBeenModified |= modifyLineAndColumn(result);
|
2016-02-08 15:56:07 +01:00
|
|
|
return hasBeenModified;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-03 13:03:03 +02:00
|
|
|
bool TestTreeItem::modifyTestFunctionContent(const TestParseResult *result)
|
2016-02-08 15:56:07 +01:00
|
|
|
{
|
2016-05-03 13:03:03 +02:00
|
|
|
bool hasBeenModified = modifyFilePath(result->fileName);
|
2017-05-10 13:42:44 +02:00
|
|
|
hasBeenModified |= modifyLineAndColumn(result);
|
2016-02-08 15:56:07 +01:00
|
|
|
return hasBeenModified;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-10 13:42:44 +02:00
|
|
|
bool TestTreeItem::modifyDataTagContent(const TestParseResult *result)
|
2016-02-08 15:56:07 +01:00
|
|
|
{
|
2017-05-10 13:42:44 +02:00
|
|
|
|
|
|
|
|
bool hasBeenModified = modifyTestFunctionContent(result);
|
|
|
|
|
hasBeenModified |= modifyName(result->name);
|
2016-02-08 15:56:07 +01:00
|
|
|
return hasBeenModified;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-10 13:42:44 +02:00
|
|
|
bool TestTreeItem::modifyLineAndColumn(const TestParseResult *result)
|
2016-02-08 15:56:07 +01:00
|
|
|
{
|
|
|
|
|
bool hasBeenModified = false;
|
2017-05-10 13:42:44 +02:00
|
|
|
if (m_line != result->line) {
|
|
|
|
|
m_line = result->line;
|
2015-02-16 12:19:26 +01:00
|
|
|
hasBeenModified = true;
|
|
|
|
|
}
|
2017-05-10 13:42:44 +02:00
|
|
|
if (m_column != result->column) {
|
|
|
|
|
m_column = result->column;
|
2016-01-15 07:21:38 +01:00
|
|
|
hasBeenModified = true;
|
|
|
|
|
}
|
2014-10-07 12:30:54 +02:00
|
|
|
return hasBeenModified;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestTreeItem::setChecked(const Qt::CheckState checkState)
|
|
|
|
|
{
|
|
|
|
|
switch (m_type) {
|
2016-10-11 16:00:05 +02:00
|
|
|
case TestDataTag: {
|
2014-10-07 12:30:54 +02:00
|
|
|
m_checked = (checkState == Qt::Unchecked ? Qt::Unchecked : Qt::Checked);
|
2016-10-11 16:00:05 +02:00
|
|
|
if (auto parent = parentItem())
|
|
|
|
|
parent->revalidateCheckState();
|
2014-10-07 12:30:54 +02:00
|
|
|
break;
|
2014-11-13 12:31:58 +01:00
|
|
|
}
|
2017-02-02 15:05:32 +01:00
|
|
|
case Root:
|
2016-10-11 16:00:05 +02:00
|
|
|
case TestFunctionOrSet:
|
2016-02-23 15:56:52 +01:00
|
|
|
case TestCase: {
|
2014-10-07 12:30:54 +02:00
|
|
|
Qt::CheckState usedState = (checkState == Qt::Unchecked ? Qt::Unchecked : Qt::Checked);
|
2015-09-10 15:32:12 +02:00
|
|
|
for (int row = 0, count = childCount(); row < count; ++row)
|
|
|
|
|
childItem(row)->setChecked(usedState);
|
2014-10-07 12:30:54 +02:00
|
|
|
m_checked = usedState;
|
2017-02-02 15:05:32 +01:00
|
|
|
if (m_type != Root) {
|
2016-10-11 16:00:05 +02:00
|
|
|
if (auto parent = parentItem())
|
|
|
|
|
parent->revalidateCheckState();
|
|
|
|
|
}
|
|
|
|
|
break;
|
2014-10-07 12:30:54 +02:00
|
|
|
}
|
2014-11-13 12:31:58 +01:00
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt::CheckState TestTreeItem::checked() const
|
|
|
|
|
{
|
|
|
|
|
switch (m_type) {
|
2017-02-02 15:05:32 +01:00
|
|
|
case Root:
|
2016-02-23 15:56:52 +01:00
|
|
|
case TestCase:
|
|
|
|
|
case TestFunctionOrSet:
|
2016-10-11 16:00:05 +02:00
|
|
|
case TestDataTag:
|
2014-11-13 12:31:58 +01:00
|
|
|
return m_checked;
|
|
|
|
|
default:
|
2016-04-08 14:58:23 +02:00
|
|
|
return Qt::Unchecked;
|
2014-11-13 12:31:58 +01:00
|
|
|
}
|
2014-10-07 12:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2016-01-26 13:52:45 +01:00
|
|
|
void TestTreeItem::markForRemoval(bool mark)
|
|
|
|
|
{
|
2016-03-04 11:56:56 +01:00
|
|
|
m_status = mark ? MarkedForRemoval : Cleared;
|
2016-01-26 13:52:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestTreeItem::markForRemovalRecursively(bool mark)
|
|
|
|
|
{
|
2016-03-04 11:56:56 +01:00
|
|
|
markForRemoval(mark);
|
2016-01-26 13:52:45 +01:00
|
|
|
for (int row = 0, count = childCount(); row < count; ++row)
|
|
|
|
|
childItem(row)->markForRemovalRecursively(mark);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-28 16:42:14 +02:00
|
|
|
void TestTreeItem::markForRemovalRecursively(const QString &filePath)
|
|
|
|
|
{
|
2017-08-08 13:46:33 +02:00
|
|
|
if (m_filePath == filePath)
|
|
|
|
|
markForRemoval(true);
|
|
|
|
|
for (int row = 0, count = childCount(); row < count; ++row) {
|
|
|
|
|
TestTreeItem *child = childItem(row);
|
|
|
|
|
child->markForRemovalRecursively(filePath);
|
2016-04-28 16:42:14 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-10 15:32:12 +02:00
|
|
|
TestTreeItem *TestTreeItem::parentItem() const
|
|
|
|
|
{
|
|
|
|
|
return static_cast<TestTreeItem *>(parent());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestTreeItem *TestTreeItem::childItem(int row) const
|
|
|
|
|
{
|
2016-07-06 13:38:00 +02:00
|
|
|
return static_cast<TestTreeItem *>(childAt(row));
|
2015-09-10 15:32:12 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-08 15:56:07 +01:00
|
|
|
TestTreeItem *TestTreeItem::findChildByName(const QString &name)
|
|
|
|
|
{
|
|
|
|
|
return findChildBy([name](const TestTreeItem *other) -> bool {
|
|
|
|
|
return other->name() == name;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-23 15:56:52 +01:00
|
|
|
TestTreeItem *TestTreeItem::findChildByFile(const QString &filePath)
|
2016-02-08 15:56:07 +01:00
|
|
|
{
|
2016-02-23 15:56:52 +01:00
|
|
|
return findChildBy([filePath](const TestTreeItem *other) -> bool {
|
|
|
|
|
return other->filePath() == filePath;
|
2016-02-08 15:56:07 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestTreeItem *TestTreeItem::findChildByNameAndFile(const QString &name, const QString &filePath)
|
|
|
|
|
{
|
|
|
|
|
return findChildBy([name, filePath](const TestTreeItem *other) -> bool {
|
|
|
|
|
return other->filePath() == filePath && other->name() == name;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-08 14:58:23 +02:00
|
|
|
QList<TestConfiguration *> TestTreeItem::getAllTestConfigurations() const
|
|
|
|
|
{
|
|
|
|
|
return QList<TestConfiguration *>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<TestConfiguration *> TestTreeItem::getSelectedTestConfigurations() const
|
|
|
|
|
{
|
|
|
|
|
return QList<TestConfiguration *>();
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-28 16:42:14 +02:00
|
|
|
bool TestTreeItem::lessThan(const TestTreeItem *other, SortMode mode) const
|
|
|
|
|
{
|
|
|
|
|
const QString &lhs = data(0, Qt::DisplayRole).toString();
|
|
|
|
|
const QString &rhs = other->data(0, Qt::DisplayRole).toString();
|
|
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
|
case Alphabetically:
|
|
|
|
|
if (lhs == rhs)
|
|
|
|
|
return index().row() > other->index().row();
|
|
|
|
|
return lhs > rhs;
|
|
|
|
|
case Naturally: {
|
|
|
|
|
const TextEditor::TextEditorWidget::Link &leftLink =
|
|
|
|
|
data(0, LinkRole).value<TextEditor::TextEditorWidget::Link>();
|
|
|
|
|
const TextEditor::TextEditorWidget::Link &rightLink =
|
|
|
|
|
other->data(0, LinkRole).value<TextEditor::TextEditorWidget::Link>();
|
|
|
|
|
if (leftLink.targetFileName == rightLink.targetFileName) {
|
|
|
|
|
return leftLink.targetLine == rightLink.targetLine
|
|
|
|
|
? leftLink.targetColumn > rightLink.targetColumn
|
|
|
|
|
: leftLink.targetLine > rightLink.targetLine;
|
|
|
|
|
}
|
|
|
|
|
return leftLink.targetFileName > rightLink.targetFileName;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-09 09:30:21 +02:00
|
|
|
QSet<QString> TestTreeItem::internalTargets() const
|
|
|
|
|
{
|
|
|
|
|
auto cppMM = CppTools::CppModelManager::instance();
|
|
|
|
|
const QList<CppTools::ProjectPart::Ptr> projectParts = cppMM->projectPart(filePath());
|
|
|
|
|
QSet<QString> targets;
|
2017-08-29 12:11:27 +02:00
|
|
|
for (const CppTools::ProjectPart::Ptr part : projectParts) {
|
|
|
|
|
if (part->buildTargetType != CppTools::ProjectPart::Executable)
|
|
|
|
|
continue;
|
2017-07-12 15:53:31 +02:00
|
|
|
targets.insert(part->buildSystemTarget + '|' + part->projectFile);
|
2017-08-29 12:11:27 +02:00
|
|
|
}
|
2017-06-09 09:30:21 +02:00
|
|
|
return targets;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
void TestTreeItem::revalidateCheckState()
|
|
|
|
|
{
|
2016-10-11 16:00:05 +02:00
|
|
|
const Type ttiType = type();
|
2017-02-02 15:05:32 +01:00
|
|
|
if (ttiType != TestCase && ttiType != TestFunctionOrSet && ttiType != Root)
|
2016-10-11 16:00:05 +02:00
|
|
|
return;
|
|
|
|
|
if (childCount() == 0) // can this happen? (we're calling revalidateCS() on parentItem()
|
2014-10-07 12:30:54 +02:00
|
|
|
return;
|
|
|
|
|
bool foundChecked = false;
|
|
|
|
|
bool foundUnchecked = false;
|
2016-10-11 16:00:05 +02:00
|
|
|
bool foundPartiallyChecked = false;
|
2015-09-10 15:32:12 +02:00
|
|
|
for (int row = 0, count = childCount(); row < count; ++row) {
|
|
|
|
|
TestTreeItem *child = childItem(row);
|
2014-11-13 12:31:58 +01:00
|
|
|
switch (child->type()) {
|
2015-12-07 08:26:54 +01:00
|
|
|
case TestDataFunction:
|
|
|
|
|
case TestSpecialFunction:
|
2014-11-13 12:31:58 +01:00
|
|
|
continue;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-11 16:00:05 +02:00
|
|
|
foundChecked |= (child->checked() == Qt::Checked);
|
2014-11-13 12:31:58 +01:00
|
|
|
foundUnchecked |= (child->checked() == Qt::Unchecked);
|
2016-10-11 16:00:05 +02:00
|
|
|
foundPartiallyChecked |= (child->checked() == Qt::PartiallyChecked);
|
|
|
|
|
if (foundPartiallyChecked || (foundChecked && foundUnchecked)) {
|
2014-10-07 12:30:54 +02:00
|
|
|
m_checked = Qt::PartiallyChecked;
|
2017-02-02 15:05:32 +01:00
|
|
|
if (ttiType == TestFunctionOrSet || ttiType == TestCase)
|
2016-10-11 16:00:05 +02:00
|
|
|
parentItem()->revalidateCheckState();
|
2014-10-07 12:30:54 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_checked = (foundUnchecked ? Qt::Unchecked : Qt::Checked);
|
2017-02-02 15:05:32 +01:00
|
|
|
if (ttiType == TestFunctionOrSet || ttiType == TestCase)
|
2016-10-11 16:00:05 +02:00
|
|
|
parentItem()->revalidateCheckState();
|
2014-10-07 12:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-08 15:56:07 +01:00
|
|
|
inline bool TestTreeItem::modifyFilePath(const QString &filePath)
|
|
|
|
|
{
|
|
|
|
|
if (m_filePath != filePath) {
|
|
|
|
|
m_filePath = filePath;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool TestTreeItem::modifyName(const QString &name)
|
|
|
|
|
{
|
|
|
|
|
if (m_name != name) {
|
|
|
|
|
m_name = name;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-09 10:27:47 +02:00
|
|
|
TestTreeItem *TestTreeItem::findChildBy(CompareFunction compare) const
|
2016-02-08 15:56:07 +01:00
|
|
|
{
|
|
|
|
|
for (int row = 0, count = childCount(); row < count; ++row) {
|
|
|
|
|
TestTreeItem *child = childItem(row);
|
|
|
|
|
if (compare(child))
|
|
|
|
|
return child;
|
|
|
|
|
}
|
2017-02-13 10:05:06 +01:00
|
|
|
return nullptr;
|
2016-02-08 15:56:07 +01:00
|
|
|
}
|
|
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Autotest
|