diff options
author | hjk <hjk@qt.io> | 2020-03-13 13:54:33 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2020-03-16 12:18:29 +0000 |
commit | d3f79fcc68d667dfd000fc5d72a98cd53eb0fab7 (patch) | |
tree | 78beae5bd43f772e555a9d959c5e365819ce3de7 /src/plugins/autotest | |
parent | c1f210dd69a3fc99851544bd78c82c624a02bc20 (diff) | |
download | qt-creator-d3f79fcc68d667dfd000fc5d72a98cd53eb0fab7.tar.gz |
AutoTest: Use ITestFramework * instead of its id in some cases
Change-Id: Ic327e31185247b6479c78af8bf8156f44bb4bdfb
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/autotest')
40 files changed, 198 insertions, 252 deletions
diff --git a/src/plugins/autotest/boost/boosttestframework.cpp b/src/plugins/autotest/boost/boosttestframework.cpp index bc63215a32..fc4f76a125 100644 --- a/src/plugins/autotest/boost/boosttestframework.cpp +++ b/src/plugins/autotest/boost/boosttestframework.cpp @@ -32,9 +32,9 @@ namespace Autotest { namespace Internal { -ITestParser *BoostTestFramework::createTestParser() const +ITestParser *BoostTestFramework::createTestParser() { - return new BoostTestParser; + return new BoostTestParser(this); } TestTreeItem *BoostTestFramework::createRootNode() const diff --git a/src/plugins/autotest/boost/boosttestframework.h b/src/plugins/autotest/boost/boosttestframework.h index 8145fb3ced..ac011c422a 100644 --- a/src/plugins/autotest/boost/boosttestframework.h +++ b/src/plugins/autotest/boost/boosttestframework.h @@ -42,7 +42,7 @@ private: const char *name() const override; unsigned priority() const override; IFrameworkSettings *frameworkSettings() override { return &m_settings; } - ITestParser *createTestParser() const override; + ITestParser *createTestParser() override; TestTreeItem *createRootNode() const override; BoostTestSettings m_settings; diff --git a/src/plugins/autotest/boost/boosttestparser.cpp b/src/plugins/autotest/boost/boosttestparser.cpp index 09c216c1b6..e6f85ce2d3 100644 --- a/src/plugins/autotest/boost/boosttestparser.cpp +++ b/src/plugins/autotest/boost/boosttestparser.cpp @@ -98,10 +98,10 @@ static bool hasBoostTestMacros(const CPlusPlus::Document::Ptr &doc) } static BoostTestParseResult *createParseResult(const QString &name, const QString &filePath, - const QString &projectFile, const Core::Id &id, + const QString &projectFile, ITestFramework *framework, TestTreeItem::Type type, const BoostTestInfo &info) { - BoostTestParseResult *partialSuite = new BoostTestParseResult(id); + BoostTestParseResult *partialSuite = new BoostTestParseResult(framework); partialSuite->itemType = type; partialSuite->fileName = filePath; partialSuite->name = info.fullName; @@ -117,7 +117,7 @@ static BoostTestParseResult *createParseResult(const QString &name, const QStrin static bool handleBoostTest(QFutureInterface<TestParseResultPtr> futureInterface, const CPlusPlus::Document::Ptr &doc, const CPlusPlus::Snapshot &snapshot, - const Core::Id &id) + ITestFramework *framework) { const CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance(); const QString &filePath = doc->fileName(); @@ -139,7 +139,7 @@ static bool handleBoostTest(QFutureInterface<TestParseResultPtr> futureInterface BoostTestInfo firstSuite = suitesStates.first(); QStringList suites = firstSuite.fullName.split('/'); BoostTestParseResult *topLevelSuite = createParseResult(suites.first(), filePath, - projectFile, id, + projectFile, framework, TestTreeItem::TestSuite, firstSuite); BoostTestParseResult *currentSuite = topLevelSuite; @@ -148,7 +148,7 @@ static bool handleBoostTest(QFutureInterface<TestParseResultPtr> futureInterface firstSuite = suitesStates.first(); suites = firstSuite.fullName.split('/'); BoostTestParseResult *suiteResult = createParseResult(suites.last(), filePath, - projectFile, id, + projectFile, framework, TestTreeItem::TestSuite, firstSuite); currentSuite->children.append(suiteResult); @@ -161,7 +161,7 @@ static bool handleBoostTest(QFutureInterface<TestParseResultPtr> futureInterface locationAndType.m_suitesState.last().fullName + "::" + locationAndType.m_name, locationAndType.m_state, locationAndType.m_line}; BoostTestParseResult *funcResult = createParseResult(locationAndType.m_name, filePath, - projectFile, id, + projectFile, framework, locationAndType.m_type, tmpInfo); currentSuite->children.append(funcResult); @@ -177,7 +177,7 @@ bool BoostTestParser::processDocument(QFutureInterface<TestParseResultPtr> futur CPlusPlus::Document::Ptr doc = document(fileName); if (doc.isNull() || !includesBoostTest(doc, m_cppSnapshot) || !hasBoostTestMacros(doc)) return false; - return handleBoostTest(futureInterface, doc, m_cppSnapshot, id()); + return handleBoostTest(futureInterface, doc, m_cppSnapshot, framework()); } } // namespace Internal diff --git a/src/plugins/autotest/boost/boosttestparser.h b/src/plugins/autotest/boost/boosttestparser.h index 678b859cc9..bba9640ef2 100644 --- a/src/plugins/autotest/boost/boosttestparser.h +++ b/src/plugins/autotest/boost/boosttestparser.h @@ -34,7 +34,7 @@ namespace Internal { class BoostTestParseResult : public TestParseResult { public: - explicit BoostTestParseResult(const Core::Id &id) : TestParseResult(id) {} + explicit BoostTestParseResult(ITestFramework *framework) : TestParseResult(framework) {} TestTreeItem *createTestTreeItem() const override; // TODO special attributes/states (labeled, timeout,...?) BoostTestTreeItem::TestStates state = BoostTestTreeItem::Enabled; @@ -43,6 +43,7 @@ public: class BoostTestParser : public CppParser { public: + explicit BoostTestParser(ITestFramework *framework) : CppParser(framework) {} bool processDocument(QFutureInterface<TestParseResultPtr> futureInterface, const QString &fileName) override; }; diff --git a/src/plugins/autotest/boost/boosttesttreeitem.cpp b/src/plugins/autotest/boost/boosttesttreeitem.cpp index 995331f625..d85fa439cf 100644 --- a/src/plugins/autotest/boost/boosttesttreeitem.cpp +++ b/src/plugins/autotest/boost/boosttesttreeitem.cpp @@ -74,7 +74,7 @@ TestTreeItem *BoostTestTreeItem::find(const TestParseResult *result) switch (type()) { case Root: - if (TestFrameworkManager::instance()->groupingEnabled(result->frameworkId)) { + if (result->framework->grouping()) { const QFileInfo fileInfo(bResult->fileName); const QFileInfo base(fileInfo.absolutePath()); for (int row = 0; row < childCount(); ++row) { diff --git a/src/plugins/autotest/gtest/gtestframework.cpp b/src/plugins/autotest/gtest/gtestframework.cpp index 09668437b8..ed46d7e4b7 100644 --- a/src/plugins/autotest/gtest/gtestframework.cpp +++ b/src/plugins/autotest/gtest/gtestframework.cpp @@ -39,9 +39,9 @@ GTestFramework::GTestFramework() g_settings = &m_settings; } -ITestParser *GTestFramework::createTestParser() const +ITestParser *GTestFramework::createTestParser() { - return new GTestParser; + return new GTestParser(this); } TestTreeItem *GTestFramework::createRootNode() const diff --git a/src/plugins/autotest/gtest/gtestframework.h b/src/plugins/autotest/gtest/gtestframework.h index f9ac997440..b1f196419c 100644 --- a/src/plugins/autotest/gtest/gtestframework.h +++ b/src/plugins/autotest/gtest/gtestframework.h @@ -46,7 +46,7 @@ private: unsigned priority() const override; QString groupingToolTip() const override; IFrameworkSettings *frameworkSettings() override { return &m_settings; } - ITestParser *createTestParser() const override; + ITestParser *createTestParser() override; TestTreeItem *createRootNode() const override; GTestSettings m_settings; diff --git a/src/plugins/autotest/gtest/gtestparser.cpp b/src/plugins/autotest/gtest/gtestparser.cpp index e5eecf44ff..e60a9a7d9d 100644 --- a/src/plugins/autotest/gtest/gtestparser.cpp +++ b/src/plugins/autotest/gtest/gtestparser.cpp @@ -89,7 +89,7 @@ static bool hasGTestNames(const CPlusPlus::Document::Ptr &document) static bool handleGTest(QFutureInterface<TestParseResultPtr> futureInterface, const CPlusPlus::Document::Ptr &doc, const CPlusPlus::Snapshot &snapshot, - const Core::Id &id) + ITestFramework *framework) { const CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance(); const QString &filePath = doc->fileName(); @@ -109,7 +109,7 @@ static bool handleGTest(QFutureInterface<TestParseResultPtr> futureInterface, return false; // happens if shutting down while parsing for (const GTestCaseSpec &testSpec : result.keys()) { - GTestParseResult *parseResult = new GTestParseResult(id); + GTestParseResult *parseResult = new GTestParseResult(framework); parseResult->itemType = TestTreeItem::TestSuite; parseResult->fileName = filePath; parseResult->name = testSpec.testCaseName; @@ -119,7 +119,7 @@ static bool handleGTest(QFutureInterface<TestParseResultPtr> futureInterface, parseResult->proFile = proFile; for (const GTestCodeLocationAndType &location : result.value(testSpec)) { - GTestParseResult *testSet = new GTestParseResult(id); + GTestParseResult *testSet = new GTestParseResult(framework); testSet->name = location.m_name; testSet->fileName = filePath; testSet->line = location.m_line; @@ -142,7 +142,7 @@ bool GTestParser::processDocument(QFutureInterface<TestParseResultPtr> futureInt CPlusPlus::Document::Ptr doc = document(fileName); if (doc.isNull() || !includesGTest(doc, m_cppSnapshot) || !hasGTestNames(doc)) return false; - return handleGTest(futureInterface, doc, m_cppSnapshot, id()); + return handleGTest(futureInterface, doc, m_cppSnapshot, framework()); } } // namespace Internal diff --git a/src/plugins/autotest/gtest/gtestparser.h b/src/plugins/autotest/gtest/gtestparser.h index 67e2e074d4..781c9fe902 100644 --- a/src/plugins/autotest/gtest/gtestparser.h +++ b/src/plugins/autotest/gtest/gtestparser.h @@ -33,7 +33,7 @@ namespace Internal { class GTestParseResult : public TestParseResult { public: - explicit GTestParseResult(const Core::Id &id) : TestParseResult(id) {} + explicit GTestParseResult(ITestFramework *framework) : TestParseResult(framework) {} TestTreeItem *createTestTreeItem() const override; bool parameterized = false; bool typed = false; @@ -43,6 +43,7 @@ public: class GTestParser : public CppParser { public: + explicit GTestParser(ITestFramework *framework) : CppParser(framework) {} bool processDocument(QFutureInterface<TestParseResultPtr> futureInterface, const QString &fileName) override; }; diff --git a/src/plugins/autotest/gtest/gtestresult.cpp b/src/plugins/autotest/gtest/gtestresult.cpp index b2f3aae67b..ee3be04821 100644 --- a/src/plugins/autotest/gtest/gtestresult.cpp +++ b/src/plugins/autotest/gtest/gtestresult.cpp @@ -96,7 +96,9 @@ static QString normalizeTestName(const QString &testname) const TestTreeItem *GTestResult::findTestTreeItem() const { auto id = Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix(GTest::Constants::FRAMEWORK_NAME); - const TestTreeItem *rootNode = TestFrameworkManager::instance()->rootNodeForTestFramework(id); + ITestFramework *framework = TestFrameworkManager::frameworkForId(id); + QTC_ASSERT(framework, return nullptr); + const TestTreeItem *rootNode = framework->rootNode(); if (!rootNode) return nullptr; diff --git a/src/plugins/autotest/gtest/gtesttreeitem.cpp b/src/plugins/autotest/gtest/gtesttreeitem.cpp index fdae1fa309..49d1138b8a 100644 --- a/src/plugins/autotest/gtest/gtesttreeitem.cpp +++ b/src/plugins/autotest/gtest/gtesttreeitem.cpp @@ -331,7 +331,7 @@ TestTreeItem *GTestTreeItem::find(const TestParseResult *result) states |= GTestTreeItem::Typed; switch (type()) { case Root: - if (TestFrameworkManager::instance()->groupingEnabled(result->frameworkId)) { + if (result->framework->grouping()) { if (GTestFramework::groupMode() == GTest::Constants::Directory) { const QFileInfo fileInfo(parseResult->fileName); const QFileInfo base(fileInfo.absolutePath()); diff --git a/src/plugins/autotest/itestframework.h b/src/plugins/autotest/itestframework.h index 78ad2ae1e8..bc3e5cb386 100644 --- a/src/plugins/autotest/itestframework.h +++ b/src/plugins/autotest/itestframework.h @@ -71,7 +71,7 @@ public: // framework specific tool tip to be displayed on the general settings page virtual QString groupingToolTip() const { return QString(); } protected: - virtual ITestParser *createTestParser() const = 0; + virtual ITestParser *createTestParser() = 0; virtual TestTreeItem *createRootNode() const = 0; private: @@ -81,4 +81,6 @@ private: bool m_grouping = false; }; +using TestFrameworks = QList<ITestFramework *>; + } // namespace Autotest diff --git a/src/plugins/autotest/itestparser.cpp b/src/plugins/autotest/itestparser.cpp index 316245cdee..335c56cbab 100644 --- a/src/plugins/autotest/itestparser.cpp +++ b/src/plugins/autotest/itestparser.cpp @@ -33,7 +33,8 @@ namespace Autotest { static CppParser *s_parserInstance = nullptr; -CppParser::CppParser() +CppParser::CppParser(ITestFramework *framework) + : ITestParser(framework) { s_parserInstance = this; } diff --git a/src/plugins/autotest/itestparser.h b/src/plugins/autotest/itestparser.h index d9a8c92801..e2ea592e09 100644 --- a/src/plugins/autotest/itestparser.h +++ b/src/plugins/autotest/itestparser.h @@ -35,16 +35,18 @@ namespace Autotest { +class ITestFramework; + class TestParseResult { public: - explicit TestParseResult(const Core::Id &id) : frameworkId(id) {} + explicit TestParseResult(ITestFramework *framework) : framework(framework) {} virtual ~TestParseResult() { qDeleteAll(children); } virtual TestTreeItem *createTestTreeItem() const = 0; QVector<TestParseResult *> children; - Core::Id frameworkId; + ITestFramework *framework; TestTreeItem::Type itemType = TestTreeItem::Root; QString displayName; QString fileName; @@ -59,22 +61,23 @@ using TestParseResultPtr = QSharedPointer<TestParseResult>; class ITestParser { public: + explicit ITestParser(ITestFramework *framework) : m_framework(framework) {} virtual ~ITestParser() { } virtual void init(const QStringList &filesToParse, bool fullParse) = 0; virtual bool processDocument(QFutureInterface<TestParseResultPtr> futureInterface, const QString &fileName) = 0; virtual void release() = 0; - void setId(const Core::Id &id) { m_id = id; } - Core::Id id() const { return m_id; } + + ITestFramework *framework() const { return m_framework; } private: - Core::Id m_id; + ITestFramework *m_framework; }; class CppParser : public ITestParser { public: - CppParser(); + explicit CppParser(ITestFramework *framework); void init(const QStringList &filesToParse, bool fullParse) override; static bool selectedForBuilding(const QString &fileName); static QByteArray getFileContent(const QString &filePath); diff --git a/src/plugins/autotest/projectsettingswidget.cpp b/src/plugins/autotest/projectsettingswidget.cpp index 4fb66be7f8..dd3a80ee89 100644 --- a/src/plugins/autotest/projectsettingswidget.cpp +++ b/src/plugins/autotest/projectsettingswidget.cpp @@ -105,16 +105,14 @@ ProjectTestSettingsWidget::ProjectTestSettingsWidget(ProjectExplorer::Project *p TestTreeModel::instance(), &TestTreeModel::synchronizeTestFrameworks); } -void ProjectTestSettingsWidget::populateFrameworks(const QMap<Core::Id, bool> &frameworks) +void ProjectTestSettingsWidget::populateFrameworks(const QMap<ITestFramework *, bool> &frameworks) { - TestFrameworkManager *frameworkManager = TestFrameworkManager::instance(); auto end = frameworks.cend(); for (auto it = frameworks.cbegin(); it != end; ++it) { - auto *item = new QTreeWidgetItem(m_activeFrameworks, - QStringList(frameworkManager->frameworkNameForId(it.key()))); + auto item = new QTreeWidgetItem(m_activeFrameworks, QStringList(QLatin1String(it.key()->name()))); item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable); item->setCheckState(0, it.value() ? Qt::Checked : Qt::Unchecked); - item->setData(0, FrameworkIdRole, it.key().toSetting()); + item->setData(0, FrameworkIdRole, it.key()->id().toSetting()); } } diff --git a/src/plugins/autotest/projectsettingswidget.h b/src/plugins/autotest/projectsettingswidget.h index 66da382f02..d921d56e88 100644 --- a/src/plugins/autotest/projectsettingswidget.h +++ b/src/plugins/autotest/projectsettingswidget.h @@ -34,10 +34,12 @@ class QTreeWidget; class QTreeWidgetItem; QT_END_NAMESPACE -namespace Core { class Id; } namespace ProjectExplorer { class Project; } namespace Autotest { + +class ITestFramework; + namespace Internal { class TestProjectSettings; @@ -49,7 +51,7 @@ public: explicit ProjectTestSettingsWidget(ProjectExplorer::Project *project, QWidget *parent = nullptr); private: - void populateFrameworks(const QMap<Core::Id, bool> &frameworks); + void populateFrameworks(const QMap<Autotest::ITestFramework *, bool> &frameworks); void onActiveFrameworkChanged(QTreeWidgetItem *item, int column); TestProjectSettings *m_projectSettings; QComboBox *m_useGlobalSettings = nullptr; diff --git a/src/plugins/autotest/qtest/qttest_utils.cpp b/src/plugins/autotest/qtest/qttest_utils.cpp index ff49155a98..6cf5fd679c 100644 --- a/src/plugins/autotest/qtest/qttest_utils.cpp +++ b/src/plugins/autotest/qtest/qttest_utils.cpp @@ -46,10 +46,10 @@ bool isQTestMacro(const QByteArray ¯o) return valid.contains(macro); } -QHash<QString, QString> testCaseNamesForFiles(const Core::Id &id, const QStringList &files) +QHash<QString, QString> testCaseNamesForFiles(ITestFramework *framework, const QStringList &files) { QHash<QString, QString> result; - TestTreeItem *rootNode = TestFrameworkManager::instance()->rootNodeForTestFramework(id); + TestTreeItem *rootNode = framework->rootNode(); QTC_ASSERT(rootNode, return result); rootNode->forFirstLevelChildren([&result, &files](TestTreeItem *child) { @@ -63,10 +63,10 @@ QHash<QString, QString> testCaseNamesForFiles(const Core::Id &id, const QStringL return result; } -QMultiHash<QString, QString> alternativeFiles(const Core::Id &id, const QStringList &files) +QMultiHash<QString, QString> alternativeFiles(ITestFramework *framework, const QStringList &files) { QMultiHash<QString, QString> result; - TestTreeItem *rootNode = TestFrameworkManager::instance()->rootNodeForTestFramework(id); + TestTreeItem *rootNode = framework->rootNode(); QTC_ASSERT(rootNode, return result); rootNode->forFirstLevelChildren([&result, &files](TestTreeItem *child) { diff --git a/src/plugins/autotest/qtest/qttest_utils.h b/src/plugins/autotest/qtest/qttest_utils.h index 23820c05d9..4d13df0d1e 100644 --- a/src/plugins/autotest/qtest/qttest_utils.h +++ b/src/plugins/autotest/qtest/qttest_utils.h @@ -31,12 +31,15 @@ namespace Core { class Id; } namespace Utils { class Environment; } namespace Autotest { + +class ITestFramework; + namespace Internal { namespace QTestUtils { bool isQTestMacro(const QByteArray ¯o); -QHash<QString, QString> testCaseNamesForFiles(const Core::Id &id, const QStringList &files); -QMultiHash<QString, QString> alternativeFiles(const Core::Id &id, const QStringList &files); +QHash<QString, QString> testCaseNamesForFiles(ITestFramework *framework, const QStringList &files); +QMultiHash<QString, QString> alternativeFiles(ITestFramework *framework, const QStringList &files); QStringList filterInterfering(const QStringList &provided, QStringList *omitted, bool isQuickTest); Utils::Environment prepareBasicEnvironment(const Utils::Environment &env); diff --git a/src/plugins/autotest/qtest/qttestframework.cpp b/src/plugins/autotest/qtest/qttestframework.cpp index 8f6deb0afb..0248407967 100644 --- a/src/plugins/autotest/qtest/qttestframework.cpp +++ b/src/plugins/autotest/qtest/qttestframework.cpp @@ -31,9 +31,9 @@ namespace Autotest { namespace Internal { -ITestParser *QtTestFramework::createTestParser() const +ITestParser *QtTestFramework::createTestParser() { - return new QtTestParser; + return new QtTestParser(this); } TestTreeItem *QtTestFramework::createRootNode() const diff --git a/src/plugins/autotest/qtest/qttestframework.h b/src/plugins/autotest/qtest/qttestframework.h index 172aaaa0fd..803079f593 100644 --- a/src/plugins/autotest/qtest/qttestframework.h +++ b/src/plugins/autotest/qtest/qttestframework.h @@ -41,7 +41,7 @@ public: private: const char *name() const override; unsigned priority() const override; - ITestParser *createTestParser() const override; + ITestParser *createTestParser() override; TestTreeItem *createRootNode() const override; IFrameworkSettings *frameworkSettings() override { return &m_settings; } diff --git a/src/plugins/autotest/qtest/qttestparser.cpp b/src/plugins/autotest/qtest/qttestparser.cpp index 564be5df26..41a8463cc6 100644 --- a/src/plugins/autotest/qtest/qttestparser.cpp +++ b/src/plugins/autotest/qtest/qttestparser.cpp @@ -284,7 +284,7 @@ static bool handleQtTest(QFutureInterface<TestParseResultPtr> futureInterface, const CPlusPlus::Snapshot &snapshot, const QString &oldTestCaseName, const QStringList &alternativeFiles, - const Core::Id &id) + ITestFramework *framework) { const CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance(); const QString &fileName = document->fileName(); @@ -321,7 +321,7 @@ static bool handleQtTest(QFutureInterface<TestParseResultPtr> futureInterface, for (const QString &file : files) Utils::addToHash(&dataTags, checkForDataTags(file, snapshot)); - QtTestParseResult *parseResult = new QtTestParseResult(id); + QtTestParseResult *parseResult = new QtTestParseResult(framework); parseResult->itemType = TestTreeItem::TestCase; parseResult->fileName = declaringDoc->fileName(); parseResult->name = testCaseName; @@ -338,7 +338,7 @@ static bool handleQtTest(QFutureInterface<TestParseResultPtr> futureInterface, const QtTestCodeLocationAndType &location = it.value(); QString functionName = it.key(); functionName = functionName.mid(functionName.lastIndexOf(':') + 1); - QtTestParseResult *func = new QtTestParseResult(id); + QtTestParseResult *func = new QtTestParseResult(framework); func->itemType = location.m_type; func->name = testCaseName + "::" + functionName; func->displayName = functionName; @@ -349,7 +349,7 @@ static bool handleQtTest(QFutureInterface<TestParseResultPtr> futureInterface, const QtTestCodeLocationList &tagLocations = tagLocationsFor(func, dataTags); for (const QtTestCodeLocationAndType &tag : tagLocations) { - QtTestParseResult *dataTag = new QtTestParseResult(id); + QtTestParseResult *dataTag = new QtTestParseResult(framework); dataTag->itemType = tag.m_type; dataTag->name = tag.m_name; dataTag->displayName = tag.m_name; @@ -372,8 +372,8 @@ static bool handleQtTest(QFutureInterface<TestParseResultPtr> futureInterface, void QtTestParser::init(const QStringList &filesToParse, bool fullParse) { if (!fullParse) { // in a full parse cached information might lead to wrong results - m_testCaseNames = QTestUtils::testCaseNamesForFiles(id(), filesToParse); - m_alternativeFiles = QTestUtils::alternativeFiles(id(), filesToParse); + m_testCaseNames = QTestUtils::testCaseNamesForFiles(framework(), filesToParse); + m_alternativeFiles = QTestUtils::alternativeFiles(framework(), filesToParse); } CppParser::init(filesToParse, fullParse); } @@ -396,7 +396,7 @@ bool QtTestParser::processDocument(QFutureInterface<TestParseResultPtr> futureIn if ((!includesQtTest(doc, m_cppSnapshot) || !qtTestLibDefined(fileName)) && oldName.isEmpty()) return false; - return handleQtTest(futureInterface, doc, m_cppSnapshot, oldName, alternativeFiles, id()); + return handleQtTest(futureInterface, doc, m_cppSnapshot, oldName, alternativeFiles, framework()); } } // namespace Internal diff --git a/src/plugins/autotest/qtest/qttestparser.h b/src/plugins/autotest/qtest/qttestparser.h index 9cf0709c7d..dac8a5d094 100644 --- a/src/plugins/autotest/qtest/qttestparser.h +++ b/src/plugins/autotest/qtest/qttestparser.h @@ -33,7 +33,7 @@ namespace Internal { class QtTestParseResult : public TestParseResult { public: - explicit QtTestParseResult(const Core::Id &id) : TestParseResult(id) {} + explicit QtTestParseResult(ITestFramework *framework) : TestParseResult(framework) {} void setInherited(bool inherited) { m_inherited = inherited; } bool inherited() const { return m_inherited; } TestTreeItem *createTestTreeItem() const override; @@ -44,6 +44,8 @@ private: class QtTestParser : public CppParser { public: + explicit QtTestParser(ITestFramework *framework) : CppParser(framework) {} + void init(const QStringList &filesToParse, bool fullParse) override; void release() override; bool processDocument(QFutureInterface<TestParseResultPtr> futureInterface, diff --git a/src/plugins/autotest/qtest/qttestresult.cpp b/src/plugins/autotest/qtest/qttestresult.cpp index 65ec0c8270..38fefa171b 100644 --- a/src/plugins/autotest/qtest/qttestresult.cpp +++ b/src/plugins/autotest/qtest/qttestresult.cpp @@ -136,7 +136,9 @@ const TestTreeItem *QtTestResult::findTestTreeItem() const id = Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix(QtTest::Constants::FRAMEWORK_NAME); else id = Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix(QuickTest::Constants::FRAMEWORK_NAME); - const TestTreeItem *rootNode = TestFrameworkManager::instance()->rootNodeForTestFramework(id); + ITestFramework *framework = TestFrameworkManager::frameworkForId(id); + QTC_ASSERT(framework, return nullptr); + const TestTreeItem *rootNode = framework->rootNode(); QTC_ASSERT(rootNode, return nullptr); const auto item = rootNode->findAnyChild([this](const Utils::TreeItem *item) { diff --git a/src/plugins/autotest/qtest/qttesttreeitem.cpp b/src/plugins/autotest/qtest/qttesttreeitem.cpp index 7069e29961..df15f38558 100644 --- a/src/plugins/autotest/qtest/qttesttreeitem.cpp +++ b/src/plugins/autotest/qtest/qttesttreeitem.cpp @@ -269,7 +269,7 @@ TestTreeItem *QtTestTreeItem::find(const TestParseResult *result) switch (type()) { case Root: - if (TestFrameworkManager::instance()->groupingEnabled(result->frameworkId)) { + if (result->framework->grouping()) { const QString path = QFileInfo(result->fileName).absolutePath(); for (int row = 0; row < childCount(); ++row) { TestTreeItem *group = childAt(row); diff --git a/src/plugins/autotest/quick/quicktest_utils.cpp b/src/plugins/autotest/quick/quicktest_utils.cpp index 92a36a9a19..eab91c9324 100644 --- a/src/plugins/autotest/quick/quicktest_utils.cpp +++ b/src/plugins/autotest/quick/quicktest_utils.cpp @@ -43,10 +43,10 @@ bool isQuickTestMacro(const QByteArray ¯o) return valid.contains(macro); } -QHash<QString, QString> proFilesForQmlFiles(const Core::Id &id, const QStringList &files) +QHash<QString, QString> proFilesForQmlFiles(ITestFramework *framework, const QStringList &files) { QHash<QString, QString> result; - TestTreeItem *rootNode = TestFrameworkManager::instance()->rootNodeForTestFramework(id); + TestTreeItem *rootNode = framework->rootNode(); QTC_ASSERT(rootNode, return result); if (files.isEmpty()) diff --git a/src/plugins/autotest/quick/quicktest_utils.h b/src/plugins/autotest/quick/quicktest_utils.h index af5cfdb7bf..8eca2a2569 100644 --- a/src/plugins/autotest/quick/quicktest_utils.h +++ b/src/plugins/autotest/quick/quicktest_utils.h @@ -30,11 +30,14 @@ namespace Core { class Id; } namespace Autotest { + +class ITestFramework; + namespace Internal { namespace QuickTestUtils { bool isQuickTestMacro(const QByteArray ¯o); -QHash<QString, QString> proFilesForQmlFiles(const Core::Id &id, const QStringList &files); +QHash<QString, QString> proFilesForQmlFiles(ITestFramework *framework, const QStringList &files); } // namespace QuickTestUtils } // namespace Internal diff --git a/src/plugins/autotest/quick/quicktestframework.cpp b/src/plugins/autotest/quick/quicktestframework.cpp index 81642ae6fd..69dd5eb7c7 100644 --- a/src/plugins/autotest/quick/quicktestframework.cpp +++ b/src/plugins/autotest/quick/quicktestframework.cpp @@ -30,9 +30,9 @@ namespace Autotest { namespace Internal { -ITestParser *QuickTestFramework::createTestParser() const +ITestParser *QuickTestFramework::createTestParser() { - return new QuickTestParser; + return new QuickTestParser(this); } TestTreeItem *QuickTestFramework::createRootNode() const diff --git a/src/plugins/autotest/quick/quicktestframework.h b/src/plugins/autotest/quick/quicktestframework.h index 80befb53d1..27982e8a2a 100644 --- a/src/plugins/autotest/quick/quicktestframework.h +++ b/src/plugins/autotest/quick/quicktestframework.h @@ -46,7 +46,7 @@ public: unsigned priority() const override; protected: - ITestParser *createTestParser() const override; + ITestParser *createTestParser() override; TestTreeItem *createRootNode() const override; }; diff --git a/src/plugins/autotest/quick/quicktestparser.cpp b/src/plugins/autotest/quick/quicktestparser.cpp index 478735048c..053e9c88b1 100644 --- a/src/plugins/autotest/quick/quicktestparser.cpp +++ b/src/plugins/autotest/quick/quicktestparser.cpp @@ -179,7 +179,7 @@ QList<Document::Ptr> QuickTestParser::scanDirectoryForQuickTestQmlFiles(const QS static bool checkQmlDocumentForQuickTestCode(QFutureInterface<TestParseResultPtr> futureInterface, const Document::Ptr &qmlJSDoc, - const Core::Id &id, + ITestFramework *framework, const QString &proFile = QString()) { if (qmlJSDoc.isNull()) @@ -197,7 +197,7 @@ static bool checkQmlDocumentForQuickTestCode(QFutureInterface<TestParseResultPtr for (const QuickTestCaseSpec &testCase : testCases) { const QString testCaseName = testCase.m_caseName; - QuickTestParseResult *parseResult = new QuickTestParseResult(id); + QuickTestParseResult *parseResult = new QuickTestParseResult(framework); parseResult->proFile = proFile; parseResult->itemType = TestTreeItem::TestCase; if (!testCaseName.isEmpty()) { @@ -208,7 +208,7 @@ static bool checkQmlDocumentForQuickTestCode(QFutureInterface<TestParseResultPtr } for (auto function : testCase.m_functions) { - QuickTestParseResult *funcResult = new QuickTestParseResult(id); + QuickTestParseResult *funcResult = new QuickTestParseResult(framework); funcResult->name = function.m_functionName; funcResult->displayName = function.m_functionName; funcResult->itemType = function.m_locationAndType.m_type; @@ -227,7 +227,7 @@ static bool checkQmlDocumentForQuickTestCode(QFutureInterface<TestParseResultPtr bool QuickTestParser::handleQtQuickTest(QFutureInterface<TestParseResultPtr> futureInterface, CPlusPlus::Document::Ptr document, - const Core::Id &id) + ITestFramework *framework) { const CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance(); if (quickTestName(document, m_cppSnapshot).isEmpty()) @@ -250,7 +250,7 @@ bool QuickTestParser::handleQtQuickTest(QFutureInterface<TestParseResultPtr> fut for (const Document::Ptr &qmlJSDoc : qmlDocs) { if (futureInterface.isCanceled()) break; - result |= checkQmlDocumentForQuickTestCode(futureInterface, qmlJSDoc, id, proFile); + result |= checkQmlDocumentForQuickTestCode(futureInterface, qmlJSDoc, framework, proFile); } return result; } @@ -298,8 +298,8 @@ void QuickTestParser::doUpdateWatchPaths(const QStringList &directories) } } -QuickTestParser::QuickTestParser() - : CppParser() +QuickTestParser::QuickTestParser(ITestFramework *framework) + : CppParser(framework) { connect(ProjectExplorer::SessionManager::instance(), &ProjectExplorer::SessionManager::startupProjectChanged, [this] { @@ -319,7 +319,7 @@ void QuickTestParser::init(const QStringList &filesToParse, bool fullParse) m_qmlSnapshot = QmlJSTools::Internal::ModelManager::instance()->snapshot(); if (!fullParse) { // in a full parse we get the correct entry points by the respective main - m_proFilesForQmlFiles = QuickTestUtils::proFilesForQmlFiles(id(), filesToParse); + m_proFilesForQmlFiles = QuickTestUtils::proFilesForQmlFiles(framework(), filesToParse); // get rid of cached main cpp files that are going to get processed anyhow for (const QString &file : filesToParse) { if (m_mainCppFiles.contains(file)) { @@ -350,14 +350,14 @@ bool QuickTestParser::processDocument(QFutureInterface<TestParseResultPtr> futur if (proFile.isEmpty()) return false; Document::Ptr qmlJSDoc = m_qmlSnapshot.document(fileName); - return checkQmlDocumentForQuickTestCode(futureInterface, qmlJSDoc, id(), proFile); + return checkQmlDocumentForQuickTestCode(futureInterface, qmlJSDoc, framework(), proFile); } if (!m_cppSnapshot.contains(fileName) || !selectedForBuilding(fileName)) return false; CPlusPlus::Document::Ptr document = m_cppSnapshot.find(fileName).value(); if (!includesQtQuickTest(document, m_cppSnapshot)) return false; - return handleQtQuickTest(futureInterface, document, id()); + return handleQtQuickTest(futureInterface, document, framework()); } QString QuickTestParser::projectFileForMainCppFile(const QString &fileName) const diff --git a/src/plugins/autotest/quick/quicktestparser.h b/src/plugins/autotest/quick/quicktestparser.h index c05fa607dd..21e7667832 100644 --- a/src/plugins/autotest/quick/quicktestparser.h +++ b/src/plugins/autotest/quick/quicktestparser.h @@ -37,7 +37,7 @@ namespace Internal { class QuickTestParseResult : public TestParseResult { public: - explicit QuickTestParseResult(const Core::Id &id) : TestParseResult(id) {} + explicit QuickTestParseResult(ITestFramework *framework) : TestParseResult(framework) {} TestTreeItem *createTestTreeItem() const override; }; @@ -45,7 +45,7 @@ class QuickTestParser : public QObject, public CppParser { Q_OBJECT public: - QuickTestParser(); + explicit QuickTestParser(ITestFramework *framework); void init(const QStringList &filesToParse, bool fullParse) override; void release() override; bool processDocument(QFutureInterface<TestParseResultPtr> futureInterface, @@ -55,7 +55,7 @@ signals: void updateWatchPaths(const QStringList &directories) const; private: bool handleQtQuickTest(QFutureInterface<TestParseResultPtr> futureInterface, - CPlusPlus::Document::Ptr document, const Core::Id &id); + CPlusPlus::Document::Ptr document, ITestFramework *framework); void handleDirectoryChanged(const QString &directory); void doUpdateWatchPaths(const QStringList &directories); QList<QmlJS::Document::Ptr> scanDirectoryForQuickTestQmlFiles(const QString &srcDir) const; diff --git a/src/plugins/autotest/quick/quicktesttreeitem.cpp b/src/plugins/autotest/quick/quicktesttreeitem.cpp index bb09159af1..9675b05719 100644 --- a/src/plugins/autotest/quick/quicktesttreeitem.cpp +++ b/src/plugins/autotest/quick/quicktesttreeitem.cpp @@ -318,7 +318,7 @@ TestTreeItem *QuickTestTreeItem::find(const TestParseResult *result) case Root: if (result->name.isEmpty()) return unnamedQuickTests(); - if (TestFrameworkManager::instance()->groupingEnabled(result->frameworkId)) { + if (result->framework->grouping()) { const QString path = QFileInfo(result->fileName).absolutePath(); TestTreeItem *group = findFirstLevelChild([path](TestTreeItem *group) { return group->filePath() == path; @@ -433,11 +433,12 @@ void QuickTestTreeItem::markForRemovalRecursively(const QString &filePath) static const Core::Id id = Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix( QuickTest::Constants::FRAMEWORK_NAME); TestTreeItem::markForRemovalRecursively(filePath); - auto parser = dynamic_cast<QuickTestParser *>(TestFrameworkManager::instance() - ->testParserForTestFramework(id)); + ITestFramework *framework = TestFrameworkManager::frameworkForId(id); + QTC_ASSERT(framework, return); + auto parser = dynamic_cast<QuickTestParser *>(framework->testParser()); const QString proFile = parser->projectFileForMainCppFile(filePath); if (!proFile.isEmpty()) { - TestTreeItem *root = TestFrameworkManager::instance()->rootNodeForTestFramework(id); + TestTreeItem *root = framework->rootNode(); root->forAllChildren([proFile](TestTreeItem *it) { if (it->proFile() == proFile) it->markForRemoval(true); diff --git a/src/plugins/autotest/testcodeparser.cpp b/src/plugins/autotest/testcodeparser.cpp index deb5085ade..e5336a9bda 100644 --- a/src/plugins/autotest/testcodeparser.cpp +++ b/src/plugins/autotest/testcodeparser.cpp @@ -110,7 +110,7 @@ void TestCodeParser::setState(State state) } } -void TestCodeParser::syncTestFrameworks(const QList<Core::Id> &frameworkIds) +void TestCodeParser::syncTestFrameworks(const QList<ITestFramework *> &frameworks) { if (m_parserState != Idle) { // there's a running parse @@ -119,10 +119,9 @@ void TestCodeParser::syncTestFrameworks(const QList<Core::Id> &frameworkIds) Core::ProgressManager::instance()->cancelTasks(Constants::TASK_PARSE); } m_testCodeParsers.clear(); - TestFrameworkManager *frameworkManager = TestFrameworkManager::instance(); - qCDebug(LOG) << "Setting" << frameworkIds << "as current parsers"; - for (const Core::Id &id : frameworkIds) { - ITestParser *testParser = frameworkManager->testParserForTestFramework(id); + qCDebug(LOG) << "Setting" << frameworks << "as current parsers"; + for (ITestFramework *framework : frameworks) { + ITestParser *testParser = framework->testParser(); QTC_ASSERT(testParser, continue); m_testCodeParsers.append(testParser); } @@ -133,7 +132,7 @@ void TestCodeParser::emitUpdateTestTree(ITestParser *parser) if (m_testCodeParsers.isEmpty()) return; if (parser) - m_updateParsers.insert(parser->id()); + m_updateParsers.insert(parser->framework()); else m_updateParsers.clear(); if (m_singleShotScheduled) { @@ -146,18 +145,18 @@ void TestCodeParser::emitUpdateTestTree(ITestParser *parser) QTimer::singleShot(1000, this, [this]() { updateTestTree(m_updateParsers); }); } -void TestCodeParser::updateTestTree(const QSet<Core::Id> &frameworkIds) +void TestCodeParser::updateTestTree(const QSet<ITestFramework *> &frameworks) { m_singleShotScheduled = false; if (m_codeModelParsing) { m_fullUpdatePostponed = true; m_partialUpdatePostponed = false; m_postponedFiles.clear(); - if (frameworkIds.isEmpty()) { + if (frameworks.isEmpty()) { m_updateParsers.clear(); } else { - for (const Core::Id &id : frameworkIds) - m_updateParsers.insert(id); + for (ITestFramework *framework : frameworks) + m_updateParsers.insert(framework); } return; } @@ -167,11 +166,8 @@ void TestCodeParser::updateTestTree(const QSet<Core::Id> &frameworkIds) m_fullUpdatePostponed = false; qCDebug(LOG) << "calling scanForTests (updateTestTree)"; - QList<Core::Id> sortedFrameworks = Utils::toList(frameworkIds); - Utils::sort(sortedFrameworks, [manager = TestFrameworkManager::instance()] - (const Core::Id &lhs, const Core::Id &rhs) { - return manager->priority(lhs) < manager->priority(rhs); - }); + TestFrameworks sortedFrameworks = Utils::toList(frameworks); + Utils::sort(sortedFrameworks, &ITestFramework::priority); scanForTests(QStringList(), sortedFrameworks); } @@ -307,7 +303,7 @@ static void parseFileForTests(const QList<ITestParser *> &parsers, } } -void TestCodeParser::scanForTests(const QStringList &fileList, const QList<Core::Id> &parserIds) +void TestCodeParser::scanForTests(const QStringList &fileList, const QList<ITestFramework *> &parsers) { if (m_parserState == Shutdown || m_testCodeParsers.isEmpty()) return; @@ -341,23 +337,21 @@ void TestCodeParser::scanForTests(const QStringList &fileList, const QList<Core: } parsingHasFailed = false; - TestFrameworkManager *manager = TestFrameworkManager::instance(); if (isFullParse) { // remove qml files as they will be found automatically by the referencing cpp file list = Utils::filtered(list, [] (const QString &fn) { return !fn.endsWith(".qml"); }); - if (!parserIds.isEmpty()) { - for (const Core::Id &id : parserIds) - manager->rootNodeForTestFramework(id)->markForRemovalRecursively(true); + if (!parsers.isEmpty()) { + for (ITestFramework *framework : parsers) + framework->rootNode()->markForRemovalRecursively(true); } else { m_model->markAllForRemoval(); } - } else if (!parserIds.isEmpty()) { - for (const Core::Id &id : parserIds) { - TestTreeItem *root = manager->rootNodeForTestFramework(id); + } else if (!parsers.isEmpty()) { + for (ITestFramework *framework : parsers) { for (const QString &filePath : list) - root->markForRemovalRecursively(filePath); + framework->rootNode()->markForRemovalRecursively(filePath); } } else { for (const QString &filePath : list) @@ -368,10 +362,8 @@ void TestCodeParser::scanForTests(const QStringList &fileList, const QList<Core: // use only a single parser or all current active? const QList<ITestParser *> codeParsers - = parserIds.isEmpty() ? m_testCodeParsers - : Utils::transform(parserIds, [](const Core::Id &id) { - return TestFrameworkManager::instance()->testParserForTestFramework(id); - }); + = parsers.isEmpty() ? m_testCodeParsers + : Utils::transform(parsers, &ITestFramework::testParser); qCDebug(LOG) << QDateTime::currentDateTime().toString("hh:mm:ss.zzz") << "StartParsing"; for (ITestParser *parser : codeParsers) parser->init(list, isFullParse); diff --git a/src/plugins/autotest/testcodeparser.h b/src/plugins/autotest/testcodeparser.h index 867a6349e6..57b65f0633 100644 --- a/src/plugins/autotest/testcodeparser.h +++ b/src/plugins/autotest/testcodeparser.h @@ -43,6 +43,9 @@ class QThreadPool; QT_END_NAMESPACE namespace Autotest { + +class ITestFramework; + namespace Internal { class TestCodeParser : public QObject @@ -61,7 +64,7 @@ public: State state() const { return m_parserState; } bool isParsing() const { return m_parserState == PartialParse || m_parserState == FullParse; } void setDirty() { m_dirty = true; } - void syncTestFrameworks(const QList<Core::Id> &frameworkIds); + void syncTestFrameworks(const QList<ITestFramework *> &frameworks); #ifdef WITH_TESTS bool furtherParsingExpected() const { return m_singleShotScheduled || m_fullUpdatePostponed || m_partialUpdatePostponed; } @@ -76,7 +79,7 @@ signals: public: void emitUpdateTestTree(ITestParser *parser = nullptr); - void updateTestTree(const QSet<Core::Id> &frameworkIds = {}); + void updateTestTree(const QSet<ITestFramework *> &frameworks = {}); void onCppDocumentUpdated(const CPlusPlus::Document::Ptr &document); void onQmlDocumentUpdated(const QmlJS::Document::Ptr &document); void onStartupProjectChanged(ProjectExplorer::Project *project); @@ -86,7 +89,7 @@ public: private: bool postponed(const QStringList &fileList); void scanForTests(const QStringList &fileList = QStringList(), - const QList<Core::Id> &parserIds = {}); + const QList<ITestFramework *> &parserIds = {}); // qml files must be handled slightly different void onDocumentUpdated(const QString &fileName, bool isQmlFile = false); @@ -110,7 +113,7 @@ private: QFutureWatcher<TestParseResultPtr> m_futureWatcher; QList<ITestParser *> m_testCodeParsers; // ptrs are still owned by TestFrameworkManager QTimer m_reparseTimer; - QSet<Core::Id> m_updateParsers; + QSet<ITestFramework *> m_updateParsers; QThreadPool *m_threadPool = nullptr; }; diff --git a/src/plugins/autotest/testframeworkmanager.cpp b/src/plugins/autotest/testframeworkmanager.cpp index 63c1c62d84..87893c3bca 100644 --- a/src/plugins/autotest/testframeworkmanager.cpp +++ b/src/plugins/autotest/testframeworkmanager.cpp @@ -96,66 +96,37 @@ void TestFrameworkManager::activateFrameworksFromSettings(const Internal::TestSe } } -QString TestFrameworkManager::frameworkNameForId(const Id &id) const +TestFrameworks TestFrameworkManager::registeredFrameworks() const { - ITestFramework *framework = m_registeredFrameworks.value(id, nullptr); - return framework ? QString::fromLatin1(framework->name()) : QString(); + return m_registeredFrameworks.values(); } -QList<Id> TestFrameworkManager::registeredFrameworkIds() const +TestFrameworks TestFrameworkManager::sortedRegisteredFrameworks() const { - return m_registeredFrameworks.keys(); -} - -QList<Id> TestFrameworkManager::sortedRegisteredFrameworkIds() const -{ - QList<Id> registered = m_registeredFrameworks.keys(); - Utils::sort(registered, [this] (const Id &lhs, const Id &rhs) { - return m_registeredFrameworks[lhs]->priority() < m_registeredFrameworks[rhs]->priority(); - }); + TestFrameworks registered = m_registeredFrameworks.values(); + Utils::sort(registered, &ITestFramework::priority); qCDebug(LOG) << "Registered frameworks sorted by priority" << registered; return registered; } -QList<Id> TestFrameworkManager::activeFrameworkIds() const +TestFrameworks TestFrameworkManager::activeFrameworks() const { - QList<Id> active; - FrameworkIterator it = m_registeredFrameworks.begin(); - FrameworkIterator end = m_registeredFrameworks.end(); - for ( ; it != end; ++it) { - if (it.value()->active()) - active.append(it.key()); + TestFrameworks active; + for (ITestFramework *framework : m_registeredFrameworks) { + if (framework->active()) + active.append(framework); } return active; } -QList<Id> TestFrameworkManager::sortedActiveFrameworkIds() const +TestFrameworks TestFrameworkManager::sortedActiveFrameworks() const { - QList<Id> active = activeFrameworkIds(); - Utils::sort(active, [this] (const Id &lhs, const Id &rhs) { - return m_registeredFrameworks[lhs]->priority() < m_registeredFrameworks[rhs]->priority(); - }); + TestFrameworks active = activeFrameworks(); + Utils::sort(active, &ITestFramework::priority); qCDebug(LOG) << "Active frameworks sorted by priority" << active; return active; } -TestTreeItem *TestFrameworkManager::rootNodeForTestFramework(const Id &frameworkId) const -{ - ITestFramework *framework = m_registeredFrameworks.value(frameworkId, nullptr); - return framework ? framework->rootNode() : nullptr; -} - -ITestParser *TestFrameworkManager::testParserForTestFramework(const Id &frameworkId) const -{ - ITestFramework *framework = m_registeredFrameworks.value(frameworkId, nullptr); - if (!framework) - return nullptr; - ITestParser *testParser = framework->testParser(); - qCDebug(LOG) << "Setting" << frameworkId << "as Id for test parser"; - testParser->setId(frameworkId); - return testParser; -} - ITestFramework *TestFrameworkManager::frameworkForId(Id frameworkId) { return instance()->m_registeredFrameworks.value(frameworkId, nullptr); @@ -176,31 +147,6 @@ void TestFrameworkManager::synchronizeSettings(QSettings *s) } } -bool TestFrameworkManager::isActive(const Id &frameworkId) const -{ - ITestFramework *framework = m_registeredFrameworks.value(frameworkId); - return framework ? framework->active() : false; -} - -bool TestFrameworkManager::groupingEnabled(const Id &frameworkId) const -{ - ITestFramework *framework = m_registeredFrameworks.value(frameworkId); - return framework ? framework->grouping() : false; -} - -void TestFrameworkManager::setGroupingEnabledFor(const Id &frameworkId, bool enabled) -{ - if (ITestFramework *framework = m_registeredFrameworks.value(frameworkId)) - framework->setGrouping(enabled); -} - -QString TestFrameworkManager::groupingToolTip(const Id &frameworkId) const -{ - if (ITestFramework *framework = m_registeredFrameworks.value(frameworkId)) - return framework->groupingToolTip(); - return QString(); -} - bool TestFrameworkManager::hasActiveFrameworks() const { for (ITestFramework *framework : m_registeredFrameworks.values()) { @@ -210,13 +156,6 @@ bool TestFrameworkManager::hasActiveFrameworks() const return false; } -unsigned TestFrameworkManager::priority(const Id &frameworkId) const -{ - if (ITestFramework *framework = m_registeredFrameworks.value(frameworkId)) - return framework->priority(); - return unsigned(-1); -} - Id ITestFramework::settingsId() const { return Core::Id(Constants::SETTINGSPAGE_PREFIX) diff --git a/src/plugins/autotest/testframeworkmanager.h b/src/plugins/autotest/testframeworkmanager.h index d2af4d4684..e572c58a0f 100644 --- a/src/plugins/autotest/testframeworkmanager.h +++ b/src/plugins/autotest/testframeworkmanager.h @@ -60,23 +60,16 @@ public: bool registerTestFramework(ITestFramework *framework); void activateFrameworksFromSettings(const Internal::TestSettings *settings); - QString frameworkNameForId(const Core::Id &id) const; - QList<Core::Id> registeredFrameworkIds() const; - QList<Core::Id> sortedRegisteredFrameworkIds() const; - QList<Core::Id> sortedActiveFrameworkIds() const; + TestFrameworks registeredFrameworks() const; + TestFrameworks sortedRegisteredFrameworks() const; + TestFrameworks sortedActiveFrameworks() const; - TestTreeItem *rootNodeForTestFramework(const Core::Id &frameworkId) const; - ITestParser *testParserForTestFramework(const Core::Id &frameworkId) const; IFrameworkSettings *settingsForTestFramework(const Core::Id &frameworkId) const; void synchronizeSettings(QSettings *s); - bool isActive(const Core::Id &frameworkId) const; - bool groupingEnabled(const Core::Id &frameworkId) const; - void setGroupingEnabledFor(const Core::Id &frameworkId, bool enabled); - QString groupingToolTip(const Core::Id &frameworkId) const; bool hasActiveFrameworks() const; - unsigned priority(const Core::Id &frameworkId) const; + private: - QList<Core::Id> activeFrameworkIds() const; + TestFrameworks activeFrameworks() const; explicit TestFrameworkManager(); QHash<Core::Id, ITestFramework *> m_registeredFrameworks; QHash<Core::Id, IFrameworkSettings *> m_frameworkSettings; diff --git a/src/plugins/autotest/testprojectsettings.cpp b/src/plugins/autotest/testprojectsettings.cpp index 47f672ea0f..6aab384aaf 100644 --- a/src/plugins/autotest/testprojectsettings.cpp +++ b/src/plugins/autotest/testprojectsettings.cpp @@ -60,9 +60,7 @@ void TestProjectSettings::setUseGlobalSettings(bool useGlobal) void TestProjectSettings::activateFramework(const Core::Id &id, bool activate) { - if (m_activeTestFrameworks.value(id) != activate) { - m_activeTestFrameworks[id] = activate; - } + m_activeTestFrameworks[TestFrameworkManager::instance()->frameworkForId(id)] = activate; } void TestProjectSettings::load() @@ -71,20 +69,20 @@ void TestProjectSettings::load() m_useGlobalSettings = useGlobal.isValid() ? useGlobal.toBool() : true; TestFrameworkManager *frameworkManager = TestFrameworkManager::instance(); - const QList<Core::Id> registered = frameworkManager->sortedRegisteredFrameworkIds(); + const TestFrameworks registered = frameworkManager->sortedRegisteredFrameworks(); const QVariant activeFrameworks = m_project->namedSettings(SK_ACTIVE_FRAMEWORKS); m_activeTestFrameworks.clear(); if (activeFrameworks.isValid()) { const QMap<QString, QVariant> frameworksMap = activeFrameworks.toMap(); - for (const Core::Id &id : registered) { - const QString idStr = id.toString(); - bool active = frameworksMap.value(idStr, frameworkManager->isActive(id)).toBool(); - m_activeTestFrameworks.insert(id, active); + for (ITestFramework *framework : registered) { + const Core::Id id = framework->id(); + bool active = frameworksMap.value(id.toString(), framework->active()).toBool(); + m_activeTestFrameworks.insert(framework, active); } } else { - for (const Core::Id &id : registered) - m_activeTestFrameworks.insert(id, frameworkManager->isActive(id)); + for (ITestFramework *framework : registered) + m_activeTestFrameworks.insert(framework, framework->active()); } const QVariant runAfterBuild = m_project->namedSettings(SK_RUN_AFTER_BUILD); @@ -98,7 +96,7 @@ void TestProjectSettings::save() QVariantMap activeFrameworks; auto end = m_activeTestFrameworks.cend(); for (auto it = m_activeTestFrameworks.cbegin(); it != end; ++it) - activeFrameworks.insert(it.key().toString(), it.value()); + activeFrameworks.insert(it.key()->id().toString(), it.value()); m_project->setNamedSettings(SK_ACTIVE_FRAMEWORKS, activeFrameworks); m_project->setNamedSettings(SK_RUN_AFTER_BUILD, int(m_runAfterBuild)); } diff --git a/src/plugins/autotest/testprojectsettings.h b/src/plugins/autotest/testprojectsettings.h index 595032ff0c..d0b35d5c5f 100644 --- a/src/plugins/autotest/testprojectsettings.h +++ b/src/plugins/autotest/testprojectsettings.h @@ -30,6 +30,9 @@ #include <projectexplorer/project.h> namespace Autotest { + +class ITestFramework; + namespace Internal { class TestProjectSettings : public QObject @@ -43,9 +46,9 @@ public: bool useGlobalSettings() const { return m_useGlobalSettings; } void setRunAfterBuild(RunAfterBuildMode mode) {m_runAfterBuild = mode; } RunAfterBuildMode runAfterBuild() const { return m_runAfterBuild; } - void setActiveFrameworks(const QMap<Core::Id, bool> enabledFrameworks) + void setActiveFrameworks(const QMap<ITestFramework *, bool> enabledFrameworks) { m_activeTestFrameworks = enabledFrameworks; } - QMap<Core::Id, bool> activeFrameworks() const { return m_activeTestFrameworks; } + QMap<ITestFramework *, bool> activeFrameworks() const { return m_activeTestFrameworks; } void activateFramework(const Core::Id &id, bool activate); private: void load(); @@ -54,7 +57,7 @@ private: ProjectExplorer::Project *m_project; bool m_useGlobalSettings = true; RunAfterBuildMode m_runAfterBuild = RunAfterBuildMode::None; - QMap<Core::Id, bool> m_activeTestFrameworks; + QMap<ITestFramework *, bool> m_activeTestFrameworks; }; } // namespace Internal diff --git a/src/plugins/autotest/testsettings.cpp b/src/plugins/autotest/testsettings.cpp index b8d9571f9d..9874499daa 100644 --- a/src/plugins/autotest/testsettings.cpp +++ b/src/plugins/autotest/testsettings.cpp @@ -70,8 +70,8 @@ void TestSettings::toSettings(QSettings *s) const s->setValue(runAfterBuildKey, int(runAfterBuild)); // store frameworks and their current active and grouping state for (const Core::Id &id : frameworks.keys()) { - s->setValue(QLatin1String(id.name()), frameworks.value(id)); - s->setValue(QLatin1String(id.name().append(groupSuffix)), frameworksGrouping.value(id)); + s->setValue(id.toString(), frameworks.value(id)); + s->setValue(id.toString() + groupSuffix, frameworksGrouping.value(id)); } s->endGroup(); } @@ -93,16 +93,16 @@ void TestSettings::fromSettings(QSettings *s) int(RunAfterBuildMode::None)).toInt()); // try to get settings for registered frameworks TestFrameworkManager *frameworkManager = TestFrameworkManager::instance(); - const QList<Core::Id> ®istered = frameworkManager->registeredFrameworkIds(); + const TestFrameworks ®istered = frameworkManager->registeredFrameworks(); frameworks.clear(); frameworksGrouping.clear(); - for (const Core::Id &id : registered) { + for (const ITestFramework *framework : registered) { // get their active state - frameworks.insert(id, s->value(QLatin1String(id.name()), - frameworkManager->isActive(id)).toBool()); + const Core::Id id = framework->id(); + const QString key = id.toString(); + frameworks.insert(id, s->value(key, framework->active()).toBool()); // and whether grouping is enabled - frameworksGrouping.insert(id, s->value(QLatin1String(id.name().append(groupSuffix)), - frameworkManager->groupingEnabled(id)).toBool()); + frameworksGrouping.insert(id, s->value(key + groupSuffix, framework->grouping()).toBool()); } s->endGroup(); } diff --git a/src/plugins/autotest/testsettingspage.cpp b/src/plugins/autotest/testsettingspage.cpp index 4fdfbdf5d3..c5f95f4aec 100644 --- a/src/plugins/autotest/testsettingspage.cpp +++ b/src/plugins/autotest/testsettingspage.cpp @@ -94,19 +94,18 @@ TestSettings TestSettingsWidget::settings() const void TestSettingsWidget::populateFrameworksListWidget(const QHash<Core::Id, bool> &frameworks) { TestFrameworkManager *frameworkManager = TestFrameworkManager::instance(); - const QList<Core::Id> ®istered = frameworkManager->sortedRegisteredFrameworkIds(); + const TestFrameworks ®istered = frameworkManager->sortedRegisteredFrameworks(); m_ui.frameworkTreeWidget->clear(); - for (const Core::Id &id : registered) { - auto *item = new QTreeWidgetItem(m_ui.frameworkTreeWidget, - QStringList(frameworkManager->frameworkNameForId(id))); + for (const ITestFramework *framework : registered) { + const Core::Id id = framework->id(); + auto item = new QTreeWidgetItem(m_ui.frameworkTreeWidget, QStringList(QLatin1String(framework->name()))); item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable); item->setCheckState(0, frameworks.value(id) ? Qt::Checked : Qt::Unchecked); item->setData(0, Qt::UserRole, id.toSetting()); - item->setData(1, Qt::CheckStateRole, frameworkManager->groupingEnabled(id) ? Qt::Checked - : Qt::Unchecked); + item->setData(1, Qt::CheckStateRole, framework->grouping() ? Qt::Checked : Qt::Unchecked); item->setToolTip(0, tr("Enable or disable test frameworks to be handled by the AutoTest " "plugin.")); - QString toolTip = frameworkManager->groupingToolTip(id); + QString toolTip = framework->groupingToolTip(); if (toolTip.isEmpty()) toolTip = tr("Enable or disable grouping of test cases by folder."); item->setToolTip(1, toolTip); diff --git a/src/plugins/autotest/testtreemodel.cpp b/src/plugins/autotest/testtreemodel.cpp index b4f3e06d89..9e0b374514 100644 --- a/src/plugins/autotest/testtreemodel.cpp +++ b/src/plugins/autotest/testtreemodel.cpp @@ -205,23 +205,23 @@ QList<TestTreeItem *> TestTreeModel::testItemsByName(const QString &testName) void TestTreeModel::synchronizeTestFrameworks() { ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject(); - QList<Core::Id> sortedIds; + TestFrameworks sorted; TestFrameworkManager *manager = TestFrameworkManager::instance(); const QVariant useGlobal = project ? project->namedSettings(Constants::SK_USE_GLOBAL) : QVariant(); if (!useGlobal.isValid() || AutotestPlugin::projectSettings(project)->useGlobalSettings()) { - sortedIds = manager->sortedActiveFrameworkIds(); + sorted = manager->sortedActiveFrameworks(); } else { // we've got custom project settings const TestProjectSettings *settings = AutotestPlugin::projectSettings(project); - const QMap<Core::Id, bool> active = settings->activeFrameworks(); - sortedIds = Utils::filtered(active.keys(), [active](const Core::Id &id) { - return active.value(id); + const QMap<ITestFramework *, bool> active = settings->activeFrameworks(); + sorted = Utils::filtered(active.keys(), [active](ITestFramework *framework) { + return active.value(framework); }); } // pre-check to avoid further processing when frameworks are unchanged Utils::TreeItem *invisibleRoot = rootItem(); - QSet<Core::Id> newlyAdded; + QSet<ITestFramework *> newlyAdded; QList<Utils::TreeItem *> oldFrameworkRoots; for (Utils::TreeItem *oldFrameworkRoot : *invisibleRoot) oldFrameworkRoots.append(oldFrameworkRoot); @@ -229,19 +229,19 @@ void TestTreeModel::synchronizeTestFrameworks() for (Utils::TreeItem *oldFrameworkRoot : oldFrameworkRoots) takeItem(oldFrameworkRoot); // do NOT delete the ptr is still held by TestFrameworkManager - for (const Core::Id &id : sortedIds) { - TestTreeItem *frameworkRootNode = manager->rootNodeForTestFramework(id); + for (ITestFramework *framework : sorted) { + TestTreeItem *frameworkRootNode = framework->rootNode(); invisibleRoot->appendChild(frameworkRootNode); if (!oldFrameworkRoots.removeOne(frameworkRootNode)) - newlyAdded.insert(id); + newlyAdded.insert(framework); } for (Utils::TreeItem *oldFrameworkRoot : oldFrameworkRoots) oldFrameworkRoot->removeChildren(); - m_parser->syncTestFrameworks(sortedIds); + m_parser->syncTestFrameworks(sorted); if (!newlyAdded.isEmpty()) m_parser->updateTestTree(newlyAdded); - emit updatedActiveFrameworks(sortedIds.size()); + emit updatedActiveFrameworks(sorted.size()); } void TestTreeModel::filterAndInsert(TestTreeItem *item, TestTreeItem *root, bool groupingEnabled) @@ -257,10 +257,10 @@ void TestTreeModel::filterAndInsert(TestTreeItem *item, TestTreeItem *root, bool void TestTreeModel::rebuild(const QList<Core::Id> &frameworkIds) { - TestFrameworkManager *frameworkManager = TestFrameworkManager::instance(); for (const Core::Id &id : frameworkIds) { - TestTreeItem *frameworkRoot = frameworkManager->rootNodeForTestFramework(id); - const bool groupingEnabled = TestFrameworkManager::instance()->groupingEnabled(id); + ITestFramework *framework = TestFrameworkManager::frameworkForId(id); + TestTreeItem *frameworkRoot = framework->rootNode(); + const bool groupingEnabled = framework->grouping(); for (int row = frameworkRoot->childCount() - 1; row >= 0; --row) { auto testItem = frameworkRoot->childAt(row); if (testItem->type() == TestTreeItem::GroupNode) { @@ -450,16 +450,14 @@ void TestTreeModel::revalidateCheckState(TestTreeItem *item) void TestTreeModel::onParseResultReady(const TestParseResultPtr result) { - TestTreeItem *rootNode - = TestFrameworkManager::instance()->rootNodeForTestFramework(result->frameworkId); + TestTreeItem *rootNode = result->framework->rootNode(); QTC_ASSERT(rootNode, return); handleParseResult(result.data(), rootNode); } void TestTreeModel::handleParseResult(const TestParseResult *result, TestTreeItem *parentNode) { - const bool groupingEnabled = - TestFrameworkManager::instance()->groupingEnabled(result->frameworkId); + const bool groupingEnabled = result->framework->grouping(); // lookup existing items if (TestTreeItem *toBeModified = parentNode->find(result)) { // found existing item... Do not remove @@ -515,26 +513,26 @@ void TestTreeModel::removeTestRootNodes() // we're inside tests - so use some internal knowledge to make testing easier static TestTreeItem *qtRootNode() { - return TestFrameworkManager::instance()->rootNodeForTestFramework( - Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix("QtTest")); + auto id = Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix("QtTest"); + return TestFrameworkManager::frameworkForId(id)->rootNode(); } static TestTreeItem *quickRootNode() { - return TestFrameworkManager::instance()->rootNodeForTestFramework( - Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix("QtQuickTest")); + auto id = Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix("QtQuickTest"); + return TestFrameworkManager::frameworkForId(id)->rootNode(); } static TestTreeItem *gtestRootNode() { - return TestFrameworkManager::instance()->rootNodeForTestFramework( - Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix("GTest")); + auto id = Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix("GTest"); + return TestFrameworkManager::frameworkForId(id)->rootNode(); } static TestTreeItem *boostTestRootNode() { - return TestFrameworkManager::instance()->rootNodeForTestFramework( - Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix("Boost")); + auto id = Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix("Boost"); + return TestFrameworkManager::frameworkForId(id)->rootNode(); } int TestTreeModel::autoTestsCount() const |