Commit 36f6a558 authored by Christian Stenger's avatar Christian Stenger

AutoTest: Unify handling of test tree items...

...and let specialized items handle its specialization by itself.

Change-Id: I988ce3c610bef68933b9102bb39ae4723add3a99
Reviewed-by: default avatarDavid Schulz <david.schulz@theqtcompany.com>
parent 009eef4e
This diff is collapsed.
......@@ -63,25 +63,7 @@ TestConfiguration::~TestConfiguration()
m_testCases.clear();
}
void basicProjectInformation(Project *project, const QString &mainFilePath, QString *proFile,
QString *displayName, Project **targetProject)
{
CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
QList<CppTools::ProjectPart::Ptr> projParts = cppMM->projectInfo(project).projectParts();
foreach (const CppTools::ProjectPart::Ptr &part, projParts) {
foreach (const CppTools::ProjectFile currentFile, part->files) {
if (currentFile.path == mainFilePath) {
*proFile = part->projectFile;
*displayName = part->displayName;
*targetProject = part->project;
return;
}
}
}
}
void basicProjectInformation(Project *project, const QString &proFile, QString *displayName,
void completeBasicProjectInformation(Project *project, const QString &proFile, QString *displayName,
Project **targetProject)
{
CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
......@@ -105,7 +87,7 @@ static bool isLocal(RunConfiguration *runConfiguration)
void TestConfiguration::completeTestInformation()
{
QTC_ASSERT(!m_mainFilePath.isEmpty() || !m_proFile.isEmpty(), return);
QTC_ASSERT(!m_proFile.isEmpty(), return);
Project *project = SessionManager::startupProject();
if (!project)
......@@ -114,7 +96,6 @@ void TestConfiguration::completeTestInformation()
QString targetFile;
QString targetName;
QString workDir;
QString proFile = m_proFile;
QString displayName;
QString buildDir;
Project *targetProject = 0;
......@@ -123,10 +104,7 @@ void TestConfiguration::completeTestInformation()
bool guessedRunConfiguration = false;
setProject(0);
if (m_proFile.isEmpty())
basicProjectInformation(project, m_mainFilePath, &proFile, &displayName, &targetProject);
else
basicProjectInformation(project, proFile, &displayName, &targetProject);
completeBasicProjectInformation(project, m_proFile, &displayName, &targetProject);
Target *target = project->activeTarget();
if (!target)
......@@ -135,7 +113,7 @@ void TestConfiguration::completeTestInformation()
BuildTargetInfoList appTargets = target->applicationTargets();
foreach (const BuildTargetInfo &bti, appTargets.list) {
// some project manager store line/column information as well inside ProjectPart
if (bti.isValid() && proFile.startsWith(bti.projectFilePath.toString())) {
if (bti.isValid() && m_proFile.startsWith(bti.projectFilePath.toString())) {
targetFile = Utils::HostOsInfo::withExecutableSuffix(bti.targetFilePath.toString());
targetName = bti.targetName;
break;
......@@ -146,8 +124,8 @@ void TestConfiguration::completeTestInformation()
if (auto buildConfig = target->activeBuildConfiguration()) {
const QString buildBase = buildConfig->buildDirectory().toString();
const QString projBase = targetProject->projectDirectory().toString();
if (proFile.startsWith(projBase))
buildDir = QFileInfo(buildBase + proFile.mid(projBase.length())).absolutePath();
if (m_proFile.startsWith(projBase))
buildDir = QFileInfo(buildBase + m_proFile.mid(projBase.length())).absolutePath();
}
}
......@@ -180,7 +158,6 @@ void TestConfiguration::completeTestInformation()
}
}
setProFile(proFile);
setDisplayName(displayName);
if (hasDesktopTarget) {
......@@ -215,11 +192,6 @@ void TestConfiguration::setTestCaseCount(int count)
m_testCaseCount = count;
}
void TestConfiguration::setMainFilePath(const QString &mainFile)
{
m_mainFilePath = mainFile;
}
void TestConfiguration::setTargetFile(const QString &targetFile)
{
m_targetFile = targetFile;
......
......@@ -51,7 +51,6 @@ public:
void setTestCases(const QStringList &testCases);
void setTestCaseCount(int count);
void setMainFilePath(const QString &mainFile);
void setTargetFile(const QString &targetFile);
void setTargetName(const QString &targetName);
void setProFile(const QString &proFile);
......
......@@ -110,12 +110,9 @@ void TestNavigationWidget::contextMenuEvent(QContextMenuEvent *event)
// 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::TestFunction && index.parent().data().toString() != unnamed)
|| (type == TestTreeItem::TestClass && index.data().toString() != unnamed)
|| (type == TestTreeItem::TestDataTag)
|| (type == TestTreeItem::GTestCase)
|| (type == TestTreeItem::GTestCaseParameterized)
|| (type == TestTreeItem::GTestName)) {
if ((type == TestTreeItem::TestFunctionOrSet && index.parent().data().toString() != unnamed)
|| (type == TestTreeItem::TestCase && index.data().toString() != unnamed)
|| (type == TestTreeItem::TestDataTag)) {
runThisTest = new QAction(tr("Run This Test"), &menu);
runThisTest->setEnabled(enabled);
connect(runThisTest, &QAction::triggered,
......@@ -259,11 +256,8 @@ void TestNavigationWidget::onRunThisTestTriggered()
return;
TestTreeItem *item = static_cast<TestTreeItem *>(sourceIndex.internalPointer());
if (item->type() == TestTreeItem::TestClass || item->type() == TestTreeItem::TestFunction
|| item->type() == TestTreeItem::TestDataTag
|| item->type() == TestTreeItem::GTestCase
|| item->type() == TestTreeItem::GTestCaseParameterized
|| item->type() == TestTreeItem::GTestName) {
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} );
......
This diff is collapsed.
......@@ -57,25 +57,13 @@ public:
enum Type
{
Root,
TestClass,
TestFunction,
TestCase,
TestFunctionOrSet,
TestDataTag,
TestDataFunction,
TestSpecialFunction,
GTestCase,
GTestCaseParameterized,
GTestName
TestSpecialFunction
};
enum TestState
{
Enabled = 0x00,
Disabled = 0x01,
};
Q_FLAGS(TestState)
Q_DECLARE_FLAGS(TestStates, TestState)
TestTreeItem(const QString &name = QString(), const QString &filePath = QString(),
Type type = Root);
......@@ -84,8 +72,6 @@ public:
bool modifyTestCaseContent(const QString &name, unsigned line, unsigned column);
bool modifyTestFunctionContent(const TestCodeLocationAndType &location);
bool modifyDataTagContent(const QString &fileName, const TestCodeLocationAndType &location);
bool modifyGTestSetContent(const QString &fileName, const QString &referencingFile,
const TestCodeLocationAndType &location);
bool modifyLineAndColumn(unsigned line, unsigned column);
const QString name() const { return m_name; }
......@@ -96,13 +82,11 @@ public:
unsigned line() const { return m_line; }
void setColumn(unsigned column) { m_column = column; }
unsigned column() const { return m_column; }
QString referencingFile() const { return m_referencingFile; }
void setReferencingFile(const QString &referencingFile) { m_referencingFile = referencingFile; }
QString proFile() const { return m_proFile; }
void setProFile(const QString &proFile) { m_proFile = proFile; }
void setChecked(const Qt::CheckState checked);
Qt::CheckState checked() const;
Type type() const { return m_type; }
void setState(TestStates states) { m_state = states; }
TestStates state() const { return m_state; }
void markForRemoval(bool mark);
void markForRemovalRecursively(bool mark);
bool markedForRemoval() const { return m_markedForRemoval; }
......@@ -110,48 +94,35 @@ public:
TestTreeItem *childItem(int row) const;
TestTreeItem *findChildByName(const QString &name);
TestTreeItem *findChildByFiles(const QString &filePath, const QString &referencingFile);
TestTreeItem *findChildByFile(const QString &filePath);
TestTreeItem *findChildByNameAndFile(const QString &name, const QString &filePath);
TestTreeItem *findChildByNameTypeAndFile(const QString &name,
TestTreeItem::Type type, const QString &referencingFile);
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; }
private:
void revalidateCheckState();
protected:
bool modifyFilePath(const QString &filePath);
bool modifyName(const QString &name);
typedef std::function<bool(const TestTreeItem *)> CompareFunction;
TestTreeItem *findChildBy(CompareFunction compare);
private:
void revalidateCheckState();
bool modifyName(const QString &name);
QString m_name;
QString m_filePath;
Qt::CheckState m_checked;
Type m_type;
unsigned m_line;
unsigned m_column;
QString m_referencingFile;
TestStates m_state;
QString m_proFile;
bool m_markedForRemoval;
};
struct TestCodeLocationAndType {
QString m_name; // tag name for m_type == TEST_DATATAG, file name for other values
unsigned m_line;
unsigned m_column;
TestTreeItem::Type m_type;
TestTreeItem::TestStates m_state;
};
struct GTestCaseSpec
{
QString testCaseName;
bool parameterized;
};
typedef QVector<TestCodeLocationAndType> TestCodeLocationList;
class AutoTestTreeItem : public TestTreeItem
......@@ -161,6 +132,7 @@ public:
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,
......@@ -177,6 +149,7 @@ public:
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,
......@@ -189,15 +162,52 @@ public:
class GoogleTestTreeItem : public TestTreeItem
{
public:
enum TestState
{
Enabled = 0x00,
Disabled = 0x01,
Parameterized = 0x02,
};
Q_FLAGS(TestState)
Q_DECLARE_FLAGS(TestStates, TestState)
GoogleTestTreeItem(const QString &name = QString(), const QString &filePath = QString(),
Type type = Root) : TestTreeItem(name, filePath, type) {}
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;
void setStates(TestStates states) { m_state = states; }
void setState(TestState state) { m_state |= state; }
TestStates state() const { return m_state; }
bool modifyTestSetContent(const QString &fileName, const TestCodeLocationAndType &location);
TestTreeItem *findChildByNameStateAndFile(const QString &name,
GoogleTestTreeItem::TestStates state,
const QString &proFile);
private:
GoogleTestTreeItem::TestStates m_state;
};
struct TestCodeLocationAndType {
QString m_name; // tag name for m_type == TEST_DATATAG, file name for other values
unsigned m_line;
unsigned m_column;
TestTreeItem::Type m_type;
GoogleTestTreeItem::TestStates m_state;
};
struct GTestCaseSpec
{
QString testCaseName;
bool parameterized;
};
} // namespace Internal
......
......@@ -71,7 +71,7 @@ void TestTreeItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
}
// paint disabled googletests in gray
if (index.data(StateRole).toInt() & TestTreeItem::Disabled)
if (index.data(StateRole).toInt() & GoogleTestTreeItem::Disabled)
opt.palette.setColor(QPalette::Text, QColor(0xa0, 0xa0, 0xa0));
QStyledItemDelegate::paint(painter, opt, index);
......
This diff is collapsed.
......@@ -81,7 +81,7 @@ public:
void markAllForRemoval();
void markForRemoval(const QString &filePath);
void sweep();
QMap<QString, QString> referencingFiles() const;
QMap<QString, QString> testCaseNamesForFiles(QStringList files);
signals:
void testTreeModelChanged();
......@@ -104,9 +104,9 @@ private:
explicit TestTreeModel(QObject *parent = 0);
void setupParsingConnections();
TestTreeItem *m_autoTestRootItem;
TestTreeItem *m_quickTestRootItem;
TestTreeItem *m_googleTestRootItem;
AutoTestTreeItem *m_autoTestRootItem;
QuickTestTreeItem *m_quickTestRootItem;
GoogleTestTreeItem *m_googleTestRootItem;
TestCodeParser *m_parser;
bool m_connectionsInitialized;
QAtomicInt m_refCounter;
......@@ -151,7 +151,7 @@ struct TestParseResult
TestTreeModel::Type type;
QString fileName;
QString referencingFile;
QString proFile;
QString testCaseName;
unsigned line = 0;
unsigned column = 0;
......
......@@ -94,8 +94,7 @@ bool TestVisitor::visit(CPlusPlus::Class *symbol)
else if (name.endsWith(QLatin1String("_data")))
locationAndType.m_type = TestTreeItem::TestDataFunction;
else
locationAndType.m_type = TestTreeItem::TestFunction;
locationAndType.m_state = TestTreeItem::Enabled;
locationAndType.m_type = TestTreeItem::TestFunctionOrSet;
m_privSlots.insert(name, locationAndType);
}
}
......@@ -225,7 +224,6 @@ bool TestDataFunctionVisitor::visit(CPlusPlus::CallAST *ast)
locationAndType.m_column = column - 1;
locationAndType.m_line = line;
locationAndType.m_type = TestTreeItem::TestDataTag;
locationAndType.m_state = TestTreeItem::Enabled;
m_currentTags.append(locationAndType);
}
}
......@@ -302,7 +300,7 @@ bool TestQmlVisitor::visit(QmlJS::AST::UiObjectDefinition *ast)
m_testCaseLocation.m_name = m_currentDoc->fileName();
m_testCaseLocation.m_line = sourceLocation.startLine;
m_testCaseLocation.m_column = sourceLocation.startColumn - 1;
m_testCaseLocation.m_type = TestTreeItem::TestClass;
m_testCaseLocation.m_type = TestTreeItem::TestCase;
return true;
}
......@@ -335,9 +333,8 @@ bool TestQmlVisitor::visit(QmlJS::AST::FunctionDeclaration *ast)
else if (name.endsWith(QLatin1String("_data")))
locationAndType.m_type = TestTreeItem::TestDataFunction;
else
locationAndType.m_type = TestTreeItem::TestFunction;
locationAndType.m_type = TestTreeItem::TestFunctionOrSet;
locationAndType.m_state = TestTreeItem::Enabled;
m_testFunctions.insert(name.toString(), locationAndType);
}
return false;
......@@ -389,9 +386,9 @@ bool GTestVisitor::visit(CPlusPlus::FunctionDefinitionAST *ast)
locationAndType.m_name = disabled ? testName.mid(9) : testName;
locationAndType.m_line = line;
locationAndType.m_column = column - 1;
locationAndType.m_type = TestTreeItem::GTestName;
locationAndType.m_state = (disabled || disabledCase) ? TestTreeItem::Disabled
: TestTreeItem::Enabled;
locationAndType.m_type = TestTreeItem::TestFunctionOrSet;
locationAndType.m_state = (disabled || disabledCase) ? GoogleTestTreeItem::Disabled
: GoogleTestTreeItem::Enabled;
GTestCaseSpec spec;
spec.testCaseName = disabledCase ? testCaseName.mid(9) : testCaseName;
spec.parameterized = TestUtils::isGTestParameterized(prettyName);
......
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