From 7d1d4471f064e877ba375caab94caedef4fd563c Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Wed, 4 Jan 2017 12:06:46 +0100 Subject: [PATCH] AutoTest: Introduce inherited state for Qt test tree items Preparation for later detection and displaying inherited functions for Qt tests. Task-number: QTCREATORBUG-17522 Change-Id: I2af1f758a837049ef676840b03f9cd73a2cb9873 Reviewed-by: David Schulz --- src/plugins/autotest/qtest/qttestparser.cpp | 22 ++++++++++--------- src/plugins/autotest/qtest/qttestparser.h | 4 ++++ src/plugins/autotest/qtest/qttesttreeitem.cpp | 14 ++++++++++++ src/plugins/autotest/qtest/qttesttreeitem.h | 13 +++++++++++ src/plugins/autotest/qtest/qttestvisitors.cpp | 5 +++-- src/plugins/autotest/qtest/qttestvisitors.h | 10 ++++----- 6 files changed, 51 insertions(+), 17 deletions(-) diff --git a/src/plugins/autotest/qtest/qttestparser.cpp b/src/plugins/autotest/qtest/qttestparser.cpp index 2835427d583..3a0f90f82ef 100644 --- a/src/plugins/autotest/qtest/qttestparser.cpp +++ b/src/plugins/autotest/qtest/qttestparser.cpp @@ -132,11 +132,11 @@ static CPlusPlus::Document::Ptr declaringDocument(CPlusPlus::Document::Ptr doc, } static QSet filesWithDataFunctionDefinitions( - const QMap &testFunctions) + const QMap &testFunctions) { QSet result; - QMap::ConstIterator it = testFunctions.begin(); - const QMap::ConstIterator end = testFunctions.end(); + QMap::ConstIterator it = testFunctions.begin(); + const QMap::ConstIterator end = testFunctions.end(); for ( ; it != end; ++it) { const QString &key = it.key(); @@ -146,7 +146,7 @@ static QSet filesWithDataFunctionDefinitions( return result; } -static QMap checkForDataTags(const QString &fileName, +static QMap checkForDataTags(const QString &fileName, const CPlusPlus::Snapshot &snapshot) { const QByteArray fileContent = CppParser::getFileContent(fileName); @@ -183,11 +183,11 @@ static bool handleQtTest(QFutureInterface futureInterface, if (!visitor.resultValid()) return false; - const QMap &testFunctions = visitor.privateSlots(); + const QMap &testFunctions = visitor.privateSlots(); const QSet &files = filesWithDataFunctionDefinitions(testFunctions); // TODO: change to QHash<> - QMap dataTags; + QMap dataTags; foreach (const QString &file, files) dataTags.unite(checkForDataTags(file, snapshot)); @@ -202,10 +202,10 @@ static bool handleQtTest(QFutureInterface futureInterface, if (projectParts.isEmpty()) // happens if shutting down while parsing return false; parseResult->proFile = projectParts.first()->projectFile; - QMap::ConstIterator it = testFunctions.begin(); - const QMap::ConstIterator end = testFunctions.end(); + QMap::ConstIterator it = testFunctions.begin(); + const QMap::ConstIterator end = testFunctions.end(); for ( ; it != end; ++it) { - const TestCodeLocationAndType &location = it.value(); + const QtTestCodeLocationAndType &location = it.value(); QtTestParseResult *func = new QtTestParseResult(id); func->itemType = location.m_type; func->name = testCaseName + "::" + it.key(); @@ -213,8 +213,9 @@ static bool handleQtTest(QFutureInterface futureInterface, func->fileName = location.m_name; func->line = location.m_line; func->column = location.m_column; + func->setInherited(location.m_inherited); - foreach (const TestCodeLocationAndType &tag, dataTags.value(func->name)) { + foreach (const QtTestCodeLocationAndType &tag, dataTags.value(func->name)) { QtTestParseResult *dataTag = new QtTestParseResult(id); dataTag->itemType = tag.m_type; dataTag->name = tag.m_name; @@ -222,6 +223,7 @@ static bool handleQtTest(QFutureInterface futureInterface, dataTag->fileName = testFunctions.value(it.key() + "_data").m_name; dataTag->line = tag.m_line; dataTag->column = tag.m_column; + dataTag->setInherited(tag.m_inherited); func->children.append(dataTag); } diff --git a/src/plugins/autotest/qtest/qttestparser.h b/src/plugins/autotest/qtest/qttestparser.h index a34a4b0431e..4888ed73c09 100644 --- a/src/plugins/autotest/qtest/qttestparser.h +++ b/src/plugins/autotest/qtest/qttestparser.h @@ -34,7 +34,11 @@ class QtTestParseResult : public TestParseResult { public: explicit QtTestParseResult(const Core::Id &id) : TestParseResult(id) {} + void setInherited(bool inherited) { m_inherited = inherited; } + bool inherited() const { return m_inherited; } TestTreeItem *createTestTreeItem() const override; +private: + bool m_inherited = false; }; class QtTestParser : public CppParser diff --git a/src/plugins/autotest/qtest/qttesttreeitem.cpp b/src/plugins/autotest/qtest/qttesttreeitem.cpp index 7f62bf60b03..4ebb4ee6250 100644 --- a/src/plugins/autotest/qtest/qttesttreeitem.cpp +++ b/src/plugins/autotest/qtest/qttesttreeitem.cpp @@ -43,11 +43,13 @@ QtTestTreeItem::QtTestTreeItem(const QString &name, const QString &filePath, Tes QtTestTreeItem *QtTestTreeItem::createTestItem(const TestParseResult *result) { + const QtTestParseResult *qtResult = static_cast(result); QtTestTreeItem *item = new QtTestTreeItem(result->displayName, result->fileName, result->itemType); item->setProFile(result->proFile); item->setLine(result->line); item->setColumn(result->column); + item->setInherited(qtResult->inherited()); foreach (const TestParseResult *funcParseResult, result->children) item->appendChild(createTestItem(funcParseResult)); @@ -57,6 +59,10 @@ QtTestTreeItem *QtTestTreeItem::createTestItem(const TestParseResult *result) QVariant QtTestTreeItem::data(int column, int role) const { switch (role) { + case Qt::DisplayRole: + if (type() == Root) + break; + return QVariant(name() + nameSuffix()); case Qt::CheckStateRole: switch (type()) { case Root: @@ -274,5 +280,13 @@ bool QtTestTreeItem::modify(const TestParseResult *result) } } +QString QtTestTreeItem::nameSuffix() const +{ + static QString inheritedSuffix = QLatin1String(" [") + + QCoreApplication::translate("QtTestTreeItem", "inherited") + + QLatin1String("]"); + return m_inherited ? inheritedSuffix : QString(); +} + } // namespace Internal } // namespace Autotest diff --git a/src/plugins/autotest/qtest/qttesttreeitem.h b/src/plugins/autotest/qtest/qttesttreeitem.h index 20bb94272c3..9c9d35f6f78 100644 --- a/src/plugins/autotest/qtest/qttesttreeitem.h +++ b/src/plugins/autotest/qtest/qttesttreeitem.h @@ -48,7 +48,20 @@ public: QList getSelectedTestConfigurations() const override; TestTreeItem *find(const TestParseResult *result) override; bool modify(const TestParseResult *result) override; + void setInherited(bool inherited) { m_inherited = inherited; } + bool inherited() const { return m_inherited; } +private: + QString nameSuffix() const; + bool m_inherited = false; }; +class QtTestCodeLocationAndType : public TestCodeLocationAndType +{ +public: + bool m_inherited = false; +}; + +typedef QVector QtTestCodeLocationList; + } // namespace Internal } // namespace Autotest diff --git a/src/plugins/autotest/qtest/qttestvisitors.cpp b/src/plugins/autotest/qtest/qttestvisitors.cpp index 579a4ff9740..b420f0f92ec 100644 --- a/src/plugins/autotest/qtest/qttestvisitors.cpp +++ b/src/plugins/autotest/qtest/qttestvisitors.cpp @@ -64,7 +64,7 @@ bool TestVisitor::visit(CPlusPlus::Class *symbol) if (const auto func = type->asFunctionType()) { if (func->isSlot() && member->isPrivate()) { const QString name = o.prettyName(func->name()); - TestCodeLocationAndType locationAndType; + QtTestCodeLocationAndType locationAndType; CPlusPlus::Function *functionDefinition = m_symbolFinder.findMatchingDefinition( func, m_snapshot, true); @@ -83,6 +83,7 @@ bool TestVisitor::visit(CPlusPlus::Class *symbol) locationAndType.m_type = TestTreeItem::TestDataFunction; else locationAndType.m_type = TestTreeItem::TestFunctionOrSet; + locationAndType.m_inherited = false; // for now m_privSlots.insert(name, locationAndType); } } @@ -220,7 +221,7 @@ bool TestDataFunctionVisitor::visit(CPlusPlus::CallAST *ast) unsigned column = 0; m_currentDoc->translationUnit()->getTokenStartPosition( firstToken, &line, &column); - TestCodeLocationAndType locationAndType; + QtTestCodeLocationAndType locationAndType; locationAndType.m_name = name; locationAndType.m_column = column - 1; locationAndType.m_line = line; diff --git a/src/plugins/autotest/qtest/qttestvisitors.h b/src/plugins/autotest/qtest/qttestvisitors.h index 21bfb2ba22d..adbb906c8eb 100644 --- a/src/plugins/autotest/qtest/qttestvisitors.h +++ b/src/plugins/autotest/qtest/qttestvisitors.h @@ -44,7 +44,7 @@ class TestVisitor : public CPlusPlus::SymbolVisitor public: explicit TestVisitor(const QString &fullQualifiedClassName, const CPlusPlus::Snapshot &snapshot); - QMap privateSlots() const { return m_privSlots; } + QMap privateSlots() const { return m_privSlots; } bool resultValid() const { return m_valid; } bool visit(CPlusPlus::Class *symbol); @@ -53,7 +53,7 @@ private: CppTools::SymbolFinder m_symbolFinder; QString m_className; CPlusPlus::Snapshot m_snapshot; - QMap m_privSlots; + QMap m_privSlots; bool m_valid = false; }; @@ -84,7 +84,7 @@ public: bool visit(CPlusPlus::CallAST *ast); bool preVisit(CPlusPlus::AST *ast); void postVisit(CPlusPlus::AST *ast); - QMap dataTags() const { return m_dataTags; } + QMap dataTags() const { return m_dataTags; } private: QString extractNameFromAST(CPlusPlus::StringLiteralAST *ast, bool *ok) const; @@ -93,8 +93,8 @@ private: CPlusPlus::Document::Ptr m_currentDoc; CPlusPlus::Overview m_overview; QString m_currentFunction; - QMap m_dataTags; - TestCodeLocationList m_currentTags; + QMap m_dataTags; + QtTestCodeLocationList m_currentTags; unsigned m_currentAstDepth = 0; unsigned m_insideUsingQTestDepth = 0; bool m_insideUsingQTest = false;