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-04-08 14:58:23 +02:00
|
|
|
#include "autotest_utils.h"
|
2016-04-11 14:50:04 +02:00
|
|
|
#include "testcodeparser.h"
|
2016-04-08 14:58:23 +02:00
|
|
|
#include "testconfiguration.h"
|
2014-10-07 12:30:54 +02:00
|
|
|
#include "testtreeitem.h"
|
2016-02-23 15:49:24 +01:00
|
|
|
#include "testtreemodel.h"
|
2014-10-07 12:30:54 +02:00
|
|
|
|
2016-04-08 14:58:23 +02:00
|
|
|
#include <cplusplus/Icons.h>
|
|
|
|
|
#include <projectexplorer/session.h>
|
|
|
|
|
#include <texteditor/texteditor.h>
|
2015-09-04 11:02:14 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
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)
|
2015-09-10 15:32:12 +02:00
|
|
|
: TreeItem( { name } ),
|
|
|
|
|
m_name(name),
|
2014-10-07 12:30:54 +02:00
|
|
|
m_filePath(filePath),
|
|
|
|
|
m_type(type),
|
2016-01-15 07:21:38 +01:00
|
|
|
m_line(0),
|
2016-03-04 11:56:56 +01:00
|
|
|
m_status(NewlyAdded)
|
2014-10-07 12:30:54 +02:00
|
|
|
{
|
2016-02-23 15:56:52 +01:00
|
|
|
m_checked = (m_type == TestCase || m_type == TestFunctionOrSet) ? 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),
|
2015-09-10 10:57:15 +02:00
|
|
|
QIcon(QLatin1String(":/images/data.png"))
|
|
|
|
|
};
|
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-04-26 15:01:35 +09:00
|
|
|
return QString(m_name + QCoreApplication::translate("TestTreeItem", " (none)"));
|
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;
|
|
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
|
return Qt::ItemIsEnabled;
|
|
|
|
|
case TestCase:
|
|
|
|
|
return defaultFlags | Qt::ItemIsTristate | Qt::ItemIsUserCheckable;
|
|
|
|
|
case TestFunctionOrSet:
|
|
|
|
|
return defaultFlags | Qt::ItemIsUserCheckable;
|
|
|
|
|
case TestDataFunction:
|
|
|
|
|
case TestSpecialFunction:
|
|
|
|
|
case TestDataTag:
|
|
|
|
|
default:
|
|
|
|
|
return defaultFlags;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-08 15:56:07 +01:00
|
|
|
bool TestTreeItem::modifyTestCaseContent(const QString &name, unsigned line, unsigned column)
|
2014-10-07 12:30:54 +02:00
|
|
|
{
|
2016-02-08 15:56:07 +01:00
|
|
|
bool hasBeenModified = modifyName(name);
|
|
|
|
|
hasBeenModified |= modifyLineAndColumn(line, column);
|
|
|
|
|
return hasBeenModified;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TestTreeItem::modifyTestFunctionContent(const TestCodeLocationAndType &location)
|
|
|
|
|
{
|
|
|
|
|
bool hasBeenModified = modifyFilePath(location.m_name);
|
2016-02-26 09:05:55 +01:00
|
|
|
hasBeenModified |= modifyLineAndColumn(location);
|
2016-02-08 15:56:07 +01:00
|
|
|
return hasBeenModified;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TestTreeItem::modifyDataTagContent(const QString &fileName,
|
|
|
|
|
const TestCodeLocationAndType &location)
|
|
|
|
|
{
|
|
|
|
|
bool hasBeenModified = modifyFilePath(fileName);
|
|
|
|
|
hasBeenModified |= modifyName(location.m_name);
|
2016-02-26 09:05:55 +01:00
|
|
|
hasBeenModified |= modifyLineAndColumn(location);
|
2016-02-08 15:56:07 +01:00
|
|
|
return hasBeenModified;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-26 09:05:55 +01:00
|
|
|
bool TestTreeItem::modifyLineAndColumn(const TestCodeLocationAndType &location)
|
|
|
|
|
{
|
|
|
|
|
return modifyLineAndColumn(location.m_line, location.m_column);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-08 15:56:07 +01:00
|
|
|
bool TestTreeItem::modifyLineAndColumn(unsigned line, unsigned column)
|
|
|
|
|
{
|
|
|
|
|
bool hasBeenModified = false;
|
|
|
|
|
if (m_line != line) {
|
|
|
|
|
m_line = line;
|
2015-02-16 12:19:26 +01:00
|
|
|
hasBeenModified = true;
|
|
|
|
|
}
|
2016-02-08 15:56:07 +01:00
|
|
|
if (m_column != column) {
|
|
|
|
|
m_column = 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-02-23 15:56:52 +01:00
|
|
|
case TestFunctionOrSet: {
|
2014-10-07 12:30:54 +02:00
|
|
|
m_checked = (checkState == Qt::Unchecked ? Qt::Unchecked : Qt::Checked);
|
2015-09-10 15:32:12 +02:00
|
|
|
parentItem()->revalidateCheckState();
|
2014-10-07 12:30:54 +02:00
|
|
|
break;
|
2014-11-13 12:31:58 +01:00
|
|
|
}
|
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;
|
|
|
|
|
}
|
2014-11-13 12:31:58 +01:00
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt::CheckState TestTreeItem::checked() const
|
|
|
|
|
{
|
|
|
|
|
switch (m_type) {
|
2016-02-23 15:56:52 +01:00
|
|
|
case TestCase:
|
|
|
|
|
case TestFunctionOrSet:
|
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)
|
|
|
|
|
{
|
|
|
|
|
if (m_filePath == filePath) {
|
|
|
|
|
markForRemovalRecursively(true);
|
|
|
|
|
} else {
|
|
|
|
|
for (int row = 0, count = childCount(); row < count; ++row) {
|
|
|
|
|
TestTreeItem *child = childItem(row);
|
|
|
|
|
child->markForRemovalRecursively(filePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-10 15:32:12 +02:00
|
|
|
TestTreeItem *TestTreeItem::parentItem() const
|
|
|
|
|
{
|
|
|
|
|
return static_cast<TestTreeItem *>(parent());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestTreeItem *TestTreeItem::childItem(int row) const
|
|
|
|
|
{
|
|
|
|
|
return static_cast<TestTreeItem *>(child(row));
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
void TestTreeItem::revalidateCheckState()
|
|
|
|
|
{
|
2015-09-10 15:32:12 +02:00
|
|
|
if (childCount() == 0)
|
2014-10-07 12:30:54 +02:00
|
|
|
return;
|
|
|
|
|
bool foundChecked = false;
|
|
|
|
|
bool foundUnchecked = 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foundChecked |= (child->checked() != Qt::Unchecked);
|
|
|
|
|
foundUnchecked |= (child->checked() == Qt::Unchecked);
|
2014-10-07 12:30:54 +02:00
|
|
|
if (foundChecked && foundUnchecked) {
|
|
|
|
|
m_checked = Qt::PartiallyChecked;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_checked = (foundUnchecked ? Qt::Unchecked : Qt::Checked);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestTreeItem *TestTreeItem::findChildBy(CompareFunction compare)
|
|
|
|
|
{
|
|
|
|
|
for (int row = 0, count = childCount(); row < count; ++row) {
|
|
|
|
|
TestTreeItem *child = childItem(row);
|
|
|
|
|
if (compare(child))
|
|
|
|
|
return child;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-23 15:49:24 +01:00
|
|
|
AutoTestTreeItem *AutoTestTreeItem::createTestItem(const TestParseResult &result)
|
|
|
|
|
{
|
2016-04-11 14:50:04 +02:00
|
|
|
const QtTestParseResult &parseResult = static_cast<const QtTestParseResult &>(result);
|
2016-02-23 15:56:52 +01:00
|
|
|
AutoTestTreeItem *item = new AutoTestTreeItem(result.testCaseName, result.fileName, TestCase);
|
2016-04-11 14:50:04 +02:00
|
|
|
item->setProFile(parseResult.proFile);
|
|
|
|
|
item->setLine(parseResult.line);
|
|
|
|
|
item->setColumn(parseResult.column);
|
2016-02-23 15:49:24 +01:00
|
|
|
|
2016-04-11 14:50:04 +02:00
|
|
|
foreach (const QString &functionName, parseResult.functions.keys()) {
|
|
|
|
|
const TestCodeLocationAndType &locationAndType = parseResult.functions.value(functionName);
|
2016-02-23 15:49:24 +01:00
|
|
|
const QString qualifiedName = result.testCaseName + QLatin1String("::") + functionName;
|
|
|
|
|
item->appendChild(createFunctionItem(functionName, locationAndType,
|
2016-04-11 14:50:04 +02:00
|
|
|
parseResult.dataTags.value(qualifiedName)));
|
2016-02-23 15:49:24 +01:00
|
|
|
}
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AutoTestTreeItem *AutoTestTreeItem::createFunctionItem(const QString &functionName,
|
|
|
|
|
const TestCodeLocationAndType &location,
|
|
|
|
|
const TestCodeLocationList &dataTags)
|
|
|
|
|
{
|
|
|
|
|
AutoTestTreeItem *item = new AutoTestTreeItem(functionName, location.m_name, location.m_type);
|
|
|
|
|
item->setLine(location.m_line);
|
|
|
|
|
item->setColumn(location.m_column);
|
|
|
|
|
|
|
|
|
|
// if there are any data tags for this function add them
|
|
|
|
|
foreach (const TestCodeLocationAndType &tagLocation, dataTags)
|
|
|
|
|
item->appendChild(createDataTagItem(location.m_name, tagLocation));
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AutoTestTreeItem *AutoTestTreeItem::createDataTagItem(const QString &fileName,
|
|
|
|
|
const TestCodeLocationAndType &location)
|
|
|
|
|
{
|
|
|
|
|
AutoTestTreeItem *tagItem = new AutoTestTreeItem(location.m_name, fileName, location.m_type);
|
|
|
|
|
tagItem->setLine(location.m_line);
|
|
|
|
|
tagItem->setColumn(location.m_column);
|
|
|
|
|
return tagItem;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-08 14:58:23 +02:00
|
|
|
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);
|
|
|
|
|
|
2016-04-29 10:13:35 +02:00
|
|
|
QtTestConfiguration *config = 0;
|
2016-04-08 14:58:23 +02:00
|
|
|
switch (type()) {
|
|
|
|
|
case TestCase:
|
2016-04-29 10:13:35 +02:00
|
|
|
config = new QtTestConfiguration;
|
|
|
|
|
config->setTestCaseCount(childCount());
|
2016-04-08 14:58:23 +02:00
|
|
|
config->setProFile(proFile());
|
|
|
|
|
config->setProject(project);
|
|
|
|
|
config->setDisplayName(TestUtils::getCMakeDisplayNameIfNecessary(filePath(), proFile()));
|
|
|
|
|
break;
|
|
|
|
|
case TestFunctionOrSet: {
|
|
|
|
|
TestTreeItem *parent = parentItem();
|
2016-04-29 10:13:35 +02:00
|
|
|
config = new QtTestConfiguration();
|
|
|
|
|
config->setTestCases(QStringList(name()));
|
2016-04-08 14:58:23 +02:00
|
|
|
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();
|
2016-04-29 10:13:35 +02:00
|
|
|
config = new QtTestConfiguration();
|
|
|
|
|
config->setTestCases(QStringList(functionWithTag));
|
2016-04-08 14:58:23 +02:00
|
|
|
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);
|
|
|
|
|
|
2016-04-29 10:13:35 +02:00
|
|
|
TestConfiguration *tc = new QtTestConfiguration();
|
|
|
|
|
tc->setTestCaseCount(child->childCount());
|
2016-04-08 14:58:23 +02:00
|
|
|
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;
|
|
|
|
|
|
2016-04-29 10:13:35 +02:00
|
|
|
QtTestConfiguration *testConfiguration = 0;
|
2016-04-08 14:58:23 +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:
|
2016-04-29 10:13:35 +02:00
|
|
|
testConfiguration = new QtTestConfiguration();
|
|
|
|
|
testConfiguration->setTestCaseCount(child->childCount());
|
2016-04-08 14:58:23 +02:00
|
|
|
testConfiguration->setProFile(child->proFile());
|
|
|
|
|
testConfiguration->setProject(project);
|
|
|
|
|
testConfiguration->setDisplayName(
|
|
|
|
|
TestUtils::getCMakeDisplayNameIfNecessary(child->filePath(), child->proFile()));
|
|
|
|
|
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);
|
|
|
|
|
if (grandChild->checked() == Qt::Checked)
|
|
|
|
|
testCases << grandChild->name();
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-29 10:13:35 +02:00
|
|
|
testConfiguration = new QtTestConfiguration();
|
|
|
|
|
testConfiguration->setTestCases(testCases);
|
2016-04-08 14:58:23 +02:00
|
|
|
testConfiguration->setProFile(child->proFile());
|
|
|
|
|
testConfiguration->setProject(project);
|
|
|
|
|
testConfiguration->setDisplayName(
|
|
|
|
|
TestUtils::getCMakeDisplayNameIfNecessary(child->filePath(), child->proFile()));
|
|
|
|
|
result << testConfiguration;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-23 15:49:24 +01:00
|
|
|
QuickTestTreeItem *QuickTestTreeItem::createTestItem(const TestParseResult &result)
|
|
|
|
|
{
|
2016-04-11 14:50:04 +02:00
|
|
|
const QuickTestParseResult &parseResult = static_cast<const QuickTestParseResult &>(result);
|
|
|
|
|
QuickTestTreeItem *item = new QuickTestTreeItem(parseResult.testCaseName, parseResult.fileName,
|
|
|
|
|
TestCase);
|
2016-02-23 15:56:52 +01:00
|
|
|
item->setProFile(result.proFile);
|
2016-02-23 15:49:24 +01:00
|
|
|
item->setLine(result.line);
|
|
|
|
|
item->setColumn(result.column);
|
2016-04-11 14:50:04 +02:00
|
|
|
foreach (const QString &functionName, parseResult.functions.keys())
|
|
|
|
|
item->appendChild(createFunctionItem(functionName, parseResult.functions.value(functionName)));
|
2016-02-23 15:49:24 +01:00
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QuickTestTreeItem *QuickTestTreeItem::createFunctionItem(const QString &functionName,
|
|
|
|
|
const TestCodeLocationAndType &location)
|
|
|
|
|
{
|
|
|
|
|
QuickTestTreeItem *item = new QuickTestTreeItem(functionName, location.m_name, location.m_type);
|
|
|
|
|
item->setLine(location.m_line);
|
|
|
|
|
item->setColumn(location.m_column);
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QuickTestTreeItem *QuickTestTreeItem::createUnnamedQuickTestItem(const TestParseResult &result)
|
|
|
|
|
{
|
2016-04-11 14:50:04 +02:00
|
|
|
const QuickTestParseResult &parseResult = static_cast<const QuickTestParseResult &>(result);
|
2016-02-23 15:56:52 +01:00
|
|
|
QuickTestTreeItem *item = new QuickTestTreeItem(QString(), QString(), TestCase);
|
2016-04-11 14:50:04 +02:00
|
|
|
foreach (const QString &functionName, parseResult.functions.keys())
|
|
|
|
|
item->appendChild(createUnnamedQuickFunctionItem(functionName, parseResult));
|
2016-02-23 15:49:24 +01:00
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QuickTestTreeItem *QuickTestTreeItem::createUnnamedQuickFunctionItem(const QString &functionName,
|
|
|
|
|
const TestParseResult &result)
|
|
|
|
|
{
|
2016-04-11 14:50:04 +02:00
|
|
|
const QuickTestParseResult &parseResult = static_cast<const QuickTestParseResult &>(result);
|
|
|
|
|
const TestCodeLocationAndType &location = parseResult.functions.value(functionName);
|
2016-02-23 15:49:24 +01:00
|
|
|
QuickTestTreeItem *item = new QuickTestTreeItem(functionName, location.m_name, location.m_type);
|
|
|
|
|
item->setLine(location.m_line);
|
|
|
|
|
item->setColumn(location.m_column);
|
2016-04-11 14:50:04 +02:00
|
|
|
item->setProFile(parseResult.proFile);
|
2016-02-23 15:49:24 +01:00
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-08 14:58:23 +02:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-28 16:42:14 +02:00
|
|
|
Qt::ItemFlags QuickTestTreeItem::flags(int column) const
|
|
|
|
|
{
|
|
|
|
|
// handle unnamed quick tests and their functions
|
|
|
|
|
switch (type()) {
|
|
|
|
|
case TestCase:
|
|
|
|
|
if (name().isEmpty())
|
|
|
|
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
|
|
|
|
break;
|
|
|
|
|
case TestFunctionOrSet:
|
|
|
|
|
if (parentItem()->name().isEmpty())
|
|
|
|
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
|
|
|
|
break;
|
|
|
|
|
default: {} // avoid warning regarding unhandled enum values
|
|
|
|
|
}
|
|
|
|
|
return TestTreeItem::flags(column);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-08 14:58:23 +02:00
|
|
|
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);
|
|
|
|
|
|
2016-04-29 10:13:35 +02:00
|
|
|
QuickTestConfiguration *config = 0;
|
2016-04-08 14:58:23 +02:00
|
|
|
switch (type()) {
|
|
|
|
|
case TestCase: {
|
|
|
|
|
QStringList testFunctions;
|
|
|
|
|
for (int row = 0, count = childCount(); row < count; ++row)
|
|
|
|
|
testFunctions << name() + QLatin1String("::") + childItem(row)->name();
|
2016-04-29 10:13:35 +02:00
|
|
|
config = new QuickTestConfiguration;
|
|
|
|
|
config->setTestCases(testFunctions);
|
2016-04-08 14:58:23 +02:00
|
|
|
config->setProFile(proFile());
|
|
|
|
|
config->setProject(project);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case TestFunctionOrSet: {
|
|
|
|
|
TestTreeItem *parent = parentItem();
|
|
|
|
|
QStringList testFunction(parent->name() + QLatin1String("::") + name());
|
2016-04-29 10:13:35 +02:00
|
|
|
config = new QuickTestConfiguration;
|
|
|
|
|
config->setTestCases(testFunction);
|
2016-04-08 14:58:23 +02:00
|
|
|
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) {
|
2016-04-29 10:13:35 +02:00
|
|
|
QuickTestConfiguration *tc = new QuickTestConfiguration;
|
|
|
|
|
tc->setTestCaseCount(it.value());
|
2016-04-08 14:58:23 +02:00
|
|
|
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;
|
|
|
|
|
|
2016-04-29 10:13:35 +02:00
|
|
|
QuickTestConfiguration *tc = 0;
|
|
|
|
|
QHash<QString, QuickTestConfiguration *> foundProFiles;
|
2016-04-08 14:58:23 +02:00
|
|
|
// 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 {
|
2016-04-29 10:13:35 +02:00
|
|
|
tc = new QuickTestConfiguration;
|
2016-04-08 14:58:23 +02:00
|
|
|
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 {
|
2016-04-29 10:13:35 +02:00
|
|
|
tc = new QuickTestConfiguration;
|
|
|
|
|
tc->setTestCases(testFunctions);
|
2016-04-08 14:58:23 +02:00
|
|
|
tc->setProFile(child->proFile());
|
|
|
|
|
tc->setProject(project);
|
|
|
|
|
foundProFiles.insert(child->proFile(), tc);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-04-29 10:13:35 +02:00
|
|
|
QHash<QString, QuickTestConfiguration *>::ConstIterator it = foundProFiles.begin();
|
|
|
|
|
QHash<QString, QuickTestConfiguration *>::ConstIterator end = foundProFiles.end();
|
2016-04-08 14:58:23 +02:00
|
|
|
for ( ; it != end; ++it) {
|
2016-04-29 10:13:35 +02:00
|
|
|
QuickTestConfiguration *config = it.value();
|
2016-04-08 14:58:23 +02:00
|
|
|
if (!config->unnamedOnly())
|
|
|
|
|
result << config;
|
|
|
|
|
else
|
|
|
|
|
delete config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-28 16:42:14 +02:00
|
|
|
bool QuickTestTreeItem::lessThan(const TestTreeItem *other, TestTreeItem::SortMode mode) const
|
|
|
|
|
{
|
|
|
|
|
// handle special item (<unnamed>)
|
|
|
|
|
if (name().isEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
if (other->name().isEmpty())
|
|
|
|
|
return true;
|
|
|
|
|
return TestTreeItem::lessThan(other, mode);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-08 14:58:23 +02:00
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-23 15:49:24 +01:00
|
|
|
GoogleTestTreeItem *GoogleTestTreeItem::createTestItem(const TestParseResult &result)
|
|
|
|
|
{
|
2016-04-11 14:50:04 +02:00
|
|
|
const GoogleTestParseResult &parseResult = static_cast<const GoogleTestParseResult &>(result);
|
|
|
|
|
GoogleTestTreeItem *item = new GoogleTestTreeItem(parseResult.testCaseName, QString(), TestCase);
|
|
|
|
|
item->setProFile(parseResult.proFile);
|
|
|
|
|
if (parseResult.parameterized)
|
2016-02-23 15:56:52 +01:00
|
|
|
item->setState(Parameterized);
|
2016-04-11 14:50:04 +02:00
|
|
|
if (parseResult.typed)
|
2016-02-22 11:23:53 +01:00
|
|
|
item->setState(Typed);
|
2016-04-11 14:50:04 +02:00
|
|
|
if (parseResult.disabled)
|
2016-02-23 17:40:10 +01:00
|
|
|
item->setState(Disabled);
|
2016-04-11 14:50:04 +02:00
|
|
|
foreach (const TestCodeLocationAndType &location, parseResult.testSets)
|
2016-02-23 15:49:24 +01:00
|
|
|
item->appendChild(createTestSetItem(result, location));
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GoogleTestTreeItem *GoogleTestTreeItem::createTestSetItem(const TestParseResult &result,
|
|
|
|
|
const TestCodeLocationAndType &location)
|
|
|
|
|
{
|
|
|
|
|
GoogleTestTreeItem *item = new GoogleTestTreeItem(location.m_name, result.fileName,
|
|
|
|
|
location.m_type);
|
2016-02-23 15:56:52 +01:00
|
|
|
item->setStates(location.m_state);
|
2016-02-23 15:49:24 +01:00
|
|
|
item->setLine(location.m_line);
|
|
|
|
|
item->setColumn(location.m_column);
|
2016-02-23 15:56:52 +01:00
|
|
|
item->setProFile(result.proFile);
|
2016-02-23 15:49:24 +01:00
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-23 15:56:52 +01:00
|
|
|
QVariant GoogleTestTreeItem::data(int column, int role) const
|
|
|
|
|
{
|
|
|
|
|
switch (role) {
|
2016-02-23 17:40:10 +01:00
|
|
|
case Qt::DisplayRole: {
|
|
|
|
|
if (type() == TestTreeItem::Root)
|
2016-04-08 14:58:23 +02:00
|
|
|
break;
|
2016-02-23 17:40:10 +01:00
|
|
|
|
|
|
|
|
const QString &displayName = (m_state & GoogleTestTreeItem::Disabled)
|
|
|
|
|
? name().mid(9) : name();
|
|
|
|
|
return QVariant(displayName + nameSuffix());
|
|
|
|
|
}
|
2016-04-08 14:58:23 +02:00
|
|
|
case Qt::CheckStateRole:
|
|
|
|
|
switch (type()) {
|
|
|
|
|
case TestCase:
|
|
|
|
|
case TestFunctionOrSet:
|
|
|
|
|
return checked();
|
|
|
|
|
default:
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
case ItalicRole:
|
|
|
|
|
return false;
|
2016-02-23 15:56:52 +01:00
|
|
|
case StateRole:
|
|
|
|
|
return (int)m_state;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return TestTreeItem::data(column, role);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-08 14:58:23 +02:00
|
|
|
TestConfiguration *GoogleTestTreeItem::testConfiguration() const
|
|
|
|
|
{
|
|
|
|
|
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
|
|
|
|
QTC_ASSERT(project, return 0);
|
|
|
|
|
|
2016-04-29 10:13:35 +02:00
|
|
|
GoogleTestConfiguration *config = 0;
|
2016-04-08 14:58:23 +02:00
|
|
|
switch (type()) {
|
|
|
|
|
case TestCase: {
|
|
|
|
|
const QString &testSpecifier = gtestFilter(state()).arg(name()).arg(QLatin1Char('*'));
|
|
|
|
|
if (int count = childCount()) {
|
2016-04-29 10:13:35 +02:00
|
|
|
config = new GoogleTestConfiguration;
|
|
|
|
|
config->setTestCases(QStringList(testSpecifier));
|
2016-04-08 14:58:23 +02:00
|
|
|
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()));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case TestFunctionOrSet: {
|
|
|
|
|
GoogleTestTreeItem *parent = static_cast<GoogleTestTreeItem *>(parentItem());
|
|
|
|
|
if (parent)
|
|
|
|
|
return 0;
|
|
|
|
|
const QString &testSpecifier = gtestFilter(parent->state()).arg(parent->name()).arg(name());
|
2016-04-29 10:13:35 +02:00
|
|
|
config = new GoogleTestConfiguration;
|
|
|
|
|
config->setTestCases(QStringList(testSpecifier));
|
2016-04-08 14:58:23 +02:00
|
|
|
config->setProFile(proFile());
|
|
|
|
|
config->setProject(project);
|
|
|
|
|
config->setDisplayName(
|
|
|
|
|
TestUtils::getCMakeDisplayNameIfNecessary(filePath(), parent->proFile()));
|
|
|
|
|
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();
|
2016-04-29 10:13:35 +02:00
|
|
|
GoogleTestConfiguration *tc = new GoogleTestConfiguration;
|
|
|
|
|
tc->setTestCaseCount(it.value());
|
2016-04-08 14:58:23 +02:00
|
|
|
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();
|
2016-04-29 10:13:35 +02:00
|
|
|
GoogleTestConfiguration *tc = new GoogleTestConfiguration;
|
|
|
|
|
tc->setTestCases(it.value());
|
2016-04-08 14:58:23 +02:00
|
|
|
tc->setProFile(key.proFile);
|
|
|
|
|
tc->setDisplayName(key.displayName);
|
|
|
|
|
tc->setProject(project);
|
|
|
|
|
result << tc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-23 15:56:52 +01:00
|
|
|
bool GoogleTestTreeItem::modifyTestSetContent(const QString &fileName,
|
|
|
|
|
const TestCodeLocationAndType &location)
|
|
|
|
|
{
|
|
|
|
|
bool hasBeenModified = modifyFilePath(fileName);
|
2016-02-26 09:05:55 +01:00
|
|
|
hasBeenModified |= modifyLineAndColumn(location);
|
2016-02-23 15:56:52 +01:00
|
|
|
if (m_state != location.m_state) {
|
|
|
|
|
m_state = location.m_state;
|
|
|
|
|
hasBeenModified = true;
|
|
|
|
|
}
|
|
|
|
|
return hasBeenModified;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestTreeItem *GoogleTestTreeItem::findChildByNameStateAndFile(const QString &name,
|
|
|
|
|
GoogleTestTreeItem::TestStates state,
|
2016-02-26 10:58:14 +01:00
|
|
|
const QString &proFile)
|
2016-02-23 15:56:52 +01:00
|
|
|
{
|
2016-02-26 10:58:14 +01:00
|
|
|
return findChildBy([name, state, proFile](const TestTreeItem *other) -> bool {
|
2016-04-08 14:58:23 +02:00
|
|
|
const GoogleTestTreeItem *gtestItem = static_cast<const GoogleTestTreeItem *>(other);
|
2016-02-26 10:58:14 +01:00
|
|
|
return other->proFile() == proFile
|
2016-02-23 15:56:52 +01:00
|
|
|
&& other->name() == name
|
|
|
|
|
&& gtestItem->state() == state;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 11:23:53 +01:00
|
|
|
QString GoogleTestTreeItem::nameSuffix() const
|
|
|
|
|
{
|
2016-04-26 15:01:35 +09:00
|
|
|
static QString markups[] = { QCoreApplication::translate("GoogleTestTreeItem", "parameterized"),
|
|
|
|
|
QCoreApplication::translate("GoogleTestTreeItem", "typed") };
|
2016-02-22 11:23:53 +01:00
|
|
|
QString suffix;
|
|
|
|
|
if (m_state & Parameterized)
|
|
|
|
|
suffix = QLatin1String(" [") + markups[0];
|
|
|
|
|
if (m_state & Typed)
|
|
|
|
|
suffix += (suffix.isEmpty() ? QLatin1String(" [") : QLatin1String(", ")) + markups[1];
|
|
|
|
|
if (!suffix.isEmpty())
|
|
|
|
|
suffix += QLatin1Char(']');
|
|
|
|
|
return suffix;
|
|
|
|
|
}
|
2016-02-23 15:56:52 +01:00
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Autotest
|