Commit 842ab2a5 authored by Christian Stenger's avatar Christian Stenger Committed by Christian Stenger

AutoTest: Move functionality from model to item classes

Another preparation for having a consistent interface later on.

Change-Id: I573e45101016048de916f4d321b326a24efbe4ee
Reviewed-by: default avatarDavid Schulz <david.schulz@theqtcompany.com>
parent cdf16ced
......@@ -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();
}
}
......
This diff is collapsed.
......@@ -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; }
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment