diff --git a/src/plugins/autotest/boost/boosttestresult.cpp b/src/plugins/autotest/boost/boosttestresult.cpp index aa7a991eb56..9e9b111df90 100644 --- a/src/plugins/autotest/boost/boosttestresult.cpp +++ b/src/plugins/autotest/boost/boosttestresult.cpp @@ -11,6 +11,8 @@ #include +using namespace Utils; + namespace Autotest { namespace Internal { @@ -35,15 +37,65 @@ static ResultHooks::OutputStringHook outputStringHook(const QString &testCaseNam }; } +static bool matches(const FilePath &fileName, const FilePath &projectFile, const QString &testCaseName, + const QString &testSuiteName, const BoostTestTreeItem *item) +{ + // due to lacking information on the result side and a not fully appropriate tree we + // might end up here with a differing set of tests, but it's the best we can do + if (!item) + return false; + if (testCaseName.isEmpty()) // a top level module node + return item->proFile() == projectFile; + if (item->proFile() != projectFile) + return false; + if (!fileName.isEmpty() && fileName != item->filePath()) + return false; + + QString fullName = "::" + testCaseName; + fullName.prepend(testSuiteName.isEmpty() ? QString(BoostTest::Constants::BOOST_MASTER_SUITE) + : testSuiteName); + + BoostTestTreeItem::TestStates states = item->state(); + if (states & BoostTestTreeItem::Templated) { + const QRegularExpression regex( + QRegularExpression::wildcardToRegularExpression(item->fullName() + "<*>")); + return regex.match(fullName).hasMatch(); + } else if (states & BoostTestTreeItem::Parameterized) { + const QRegularExpression regex( + QRegularExpression::anchoredPattern(item->fullName() + "_\\d+")); + return regex.isValid() && regex.match(fullName).hasMatch(); + } + return item->fullName() == fullName; +} + +static ResultHooks::FindTestItemHook findTestItemHook(const FilePath &projectFile, + const QString &testCaseName, + const QString &testSuiteName) +{ + return [=](const TestResult &result) -> ITestTreeItem * { + const Id id = Id(Constants::FRAMEWORK_PREFIX).withSuffix(BoostTest::Constants::FRAMEWORK_NAME); + ITestFramework *framework = TestFrameworkManager::frameworkForId(id); + QTC_ASSERT(framework, return nullptr); + const TestTreeItem *rootNode = framework->rootNode(); + if (!rootNode) + return nullptr; + + return rootNode->findAnyChild([&](const TreeItem *item) { + const auto testTreeItem = static_cast(item); + return testTreeItem && matches(result.fileName(), projectFile, testCaseName, + testSuiteName, testTreeItem); + }); + }; +} + BoostTestResult::BoostTestResult(const QString &id, const QString &name, - const Utils::FilePath &projectFile, - const QString &testCaseName, const QString &testSuiteName) - : TestResult(id, name, {outputStringHook(testCaseName)}) + const FilePath &projectFile, const QString &testCaseName, + const QString &testSuiteName) + : TestResult(id, name, {outputStringHook(testCaseName), + findTestItemHook(projectFile, testCaseName, testSuiteName)}) , m_projectFile(projectFile) , m_testCaseName(testCaseName) - , m_testSuiteName(testSuiteName) -{ -} + , m_testSuiteName(testSuiteName) {} bool BoostTestResult::isDirectParentOf(const TestResult *other, bool *needsIntermediate) const { @@ -75,50 +127,6 @@ bool BoostTestResult::isDirectParentOf(const TestResult *other, bool *needsInter return false; } -const ITestTreeItem *BoostTestResult::findTestTreeItem() const -{ - auto id = Utils::Id(Constants::FRAMEWORK_PREFIX).withSuffix(BoostTest::Constants::FRAMEWORK_NAME); - ITestFramework *framework = TestFrameworkManager::frameworkForId(id); - QTC_ASSERT(framework, return nullptr); - const TestTreeItem *rootNode = framework->rootNode(); - if (!rootNode) - return nullptr; - - return rootNode->findAnyChild([this](const Utils::TreeItem *item) { - return matches(static_cast(item)); - }); -} - -bool BoostTestResult::matches(const BoostTestTreeItem *item) const -{ - // due to lacking information on the result side and a not fully appropriate tree we - // might end up here with a differing set of tests, but it's the best we can do - if (!item) - return false; - if (m_testCaseName.isEmpty()) // a top level module node - return item->proFile() == m_projectFile; - if (item->proFile() != m_projectFile) - return false; - if (!fileName().isEmpty() && fileName() != item->filePath()) - return false; - - QString fullName = "::" + m_testCaseName; - fullName.prepend(m_testSuiteName.isEmpty() ? QString(BoostTest::Constants::BOOST_MASTER_SUITE) - : m_testSuiteName); - - BoostTestTreeItem::TestStates states = item->state(); - if (states & BoostTestTreeItem::Templated) { - const QRegularExpression regex( - QRegularExpression::wildcardToRegularExpression(item->fullName() + "<*>")); - return regex.match(fullName).hasMatch(); - } else if (states & BoostTestTreeItem::Parameterized) { - const QRegularExpression regex( - QRegularExpression::anchoredPattern(item->fullName() + "_\\d+")); - return regex.isValid() && regex.match(fullName).hasMatch(); - } - return item->fullName() == fullName; -} - } // namespace Internal } // namespace Autotest diff --git a/src/plugins/autotest/boost/boosttestresult.h b/src/plugins/autotest/boost/boosttestresult.h index 7ea2be62dd8..b994b0c4646 100644 --- a/src/plugins/autotest/boost/boosttestresult.h +++ b/src/plugins/autotest/boost/boosttestresult.h @@ -17,9 +17,7 @@ public: const QString &testCaseName = {}, const QString &testSuiteName = {}); bool isDirectParentOf(const TestResult *other, bool *needsIntermediate) const override; - const ITestTreeItem * findTestTreeItem() const override; private: - bool matches(const BoostTestTreeItem *item) const; Utils::FilePath m_projectFile; QString m_testCaseName; diff --git a/src/plugins/autotest/catch/catchresult.cpp b/src/plugins/autotest/catch/catchresult.cpp index 13b1dc8172b..3020b6a9d1c 100644 --- a/src/plugins/autotest/catch/catchresult.cpp +++ b/src/plugins/autotest/catch/catchresult.cpp @@ -9,15 +9,36 @@ #include #include +using namespace Utils; + namespace Autotest { namespace Internal { -CatchResult::CatchResult(const QString &id, const QString &name, int depth) - : TestResult(id, name) - , m_sectionDepth(depth) +static ResultHooks::FindTestItemHook findTestItemHook() { + return [=](const TestResult &result) -> ITestTreeItem * { + const Id id = Id(Constants::FRAMEWORK_PREFIX).withSuffix("Catch"); + ITestFramework *framework = TestFrameworkManager::frameworkForId(id); + QTC_ASSERT(framework, return nullptr); + const TestTreeItem *rootNode = framework->rootNode(); + if (!rootNode) + return nullptr; + + return rootNode->findAnyChild([&](const TreeItem *item) { + const auto treeItem = static_cast(item); + if (!treeItem || treeItem->filePath() != result.fileName()) + return false; + const bool parameterized = treeItem->states() & CatchTreeItem::Parameterized; + return parameterized ? result.name().startsWith(treeItem->name() + " - ") + : result.name() == treeItem->name(); + }); + }; } +CatchResult::CatchResult(const QString &id, const QString &name, int depth) + : TestResult(id, name, {{}, findTestItemHook()}) + , m_sectionDepth(depth) {} + bool CatchResult::isDirectParentOf(const TestResult *other, bool *needsIntermediate) const { if (!TestResult::isDirectParentOf(other, needsIntermediate)) @@ -43,26 +64,5 @@ bool CatchResult::isDirectParentOf(const TestResult *other, bool *needsIntermedi return name() == catchOther->name(); } -const ITestTreeItem *CatchResult::findTestTreeItem() const -{ - auto id = Utils::Id(Constants::FRAMEWORK_PREFIX).withSuffix("Catch"); - ITestFramework *framework = TestFrameworkManager::frameworkForId(id); - QTC_ASSERT(framework, return nullptr); - const TestTreeItem *rootNode = framework->rootNode(); - if (!rootNode) - return nullptr; - - const QString tcName = name(); - const Utils::FilePath tcFilePath = fileName(); - return rootNode->findAnyChild([&tcName, &tcFilePath](const Utils::TreeItem *item) { - const auto treeItem = static_cast(item); - if (!treeItem || treeItem->filePath() != tcFilePath) - return false; - const bool parameterized = treeItem->states() & CatchTreeItem::Parameterized; - return parameterized ? tcName.startsWith(treeItem->name() + " - ") - : tcName == treeItem->name(); - }); -} - } // namespace Internal } // namespace Autotest diff --git a/src/plugins/autotest/catch/catchresult.h b/src/plugins/autotest/catch/catchresult.h index e8c2cbd1457..19264e9e4cc 100644 --- a/src/plugins/autotest/catch/catchresult.h +++ b/src/plugins/autotest/catch/catchresult.h @@ -14,7 +14,6 @@ public: CatchResult(const QString &id, const QString &name, int depth); bool isDirectParentOf(const TestResult *other, bool *needsIntermediate) const override; - const ITestTreeItem *findTestTreeItem() const override; private: int sectionDepth() const { return m_sectionDepth; } diff --git a/src/plugins/autotest/ctest/ctestoutputreader.cpp b/src/plugins/autotest/ctest/ctestoutputreader.cpp index f774ef77999..585fbd2b2b3 100644 --- a/src/plugins/autotest/ctest/ctestoutputreader.cpp +++ b/src/plugins/autotest/ctest/ctestoutputreader.cpp @@ -3,26 +3,45 @@ #include "ctestoutputreader.h" -#include "ctesttreeitem.h" #include "../autotesttr.h" #include "../testframeworkmanager.h" #include "../testresult.h" +#include "../testtreeitem.h" #include #include +#include #include +using namespace Utils; + namespace Autotest { namespace Internal { +static ResultHooks::FindTestItemHook findTestItemHook(const QString &testCaseName) +{ + return [=](const TestResult &result) -> ITestTreeItem * { + Q_UNUSED(result) + ITestTool *testTool = TestFrameworkManager::testToolForBuildSystemId( + CMakeProjectManager::Constants::CMAKE_PROJECT_ID); + QTC_ASSERT(testTool, return nullptr); + const ITestTreeItem *rootNode = testTool->rootNode(); + if (!rootNode) + return nullptr; + + return rootNode->findFirstLevelChild([&](const ITestTreeItem *item) { + return item && item->name() == testCaseName; + }); + }; +} + class CTestResult : public TestResult { public: - CTestResult(const QString &id, const QString &project, const QString &testCase) - : TestResult(id, project) - , m_testCase(testCase) + CTestResult(const QString &id, const QString &project, const QString &testCaseName) + : TestResult(id, project, {{}, findTestItemHook(testCaseName)}) {} bool isDirectParentOf(const TestResult *other, bool *needsIntermediate) const override @@ -31,23 +50,6 @@ public: return false; return result() == ResultType::TestStart; } - - const ITestTreeItem *findTestTreeItem() const override - { - ITestTool *testTool = TestFrameworkManager::testToolForBuildSystemId( - CMakeProjectManager::Constants::CMAKE_PROJECT_ID); - QTC_ASSERT(testTool, return nullptr); - const ITestTreeItem *rootNode = testTool->rootNode(); - if (!rootNode) - return nullptr; - - return rootNode->findFirstLevelChild([this](const ITestTreeItem *item) { - return item && item->name() == m_testCase; - }); - } - -private: - QString m_testCase; }; CTestOutputReader::CTestOutputReader(const QFutureInterface &futureInterface, diff --git a/src/plugins/autotest/gtest/gtestresult.cpp b/src/plugins/autotest/gtest/gtestresult.cpp index a83462ae144..90fbf78551d 100644 --- a/src/plugins/autotest/gtest/gtestresult.cpp +++ b/src/plugins/autotest/gtest/gtestresult.cpp @@ -11,6 +11,8 @@ #include +using namespace Utils; + namespace Autotest { namespace Internal { @@ -35,15 +37,74 @@ static ResultHooks::OutputStringHook outputStringHook(const QString &testCaseNam }; } -GTestResult::GTestResult(const QString &id, const QString &name, const Utils::FilePath &projectFile, - const QString &testCaseName, int iteration) - : TestResult(id, name, {outputStringHook(testCaseName)}) - , m_projectFile(projectFile) - , m_testCaseName(testCaseName) - , m_iteration(iteration) +static QString normalizeName(const QString &name) { + static QRegularExpression parameterIndex("/\\d+"); + + QString nameWithoutParameterIndices = name; + nameWithoutParameterIndices.remove(parameterIndex); + + return nameWithoutParameterIndices.split('/').last(); } +static QString normalizeTestName(const QString &testname) +{ + return normalizeName(testname.split(',').first()); +} + +static bool matchesTestCase(const QString &testCaseName, const TestTreeItem *treeItem) +{ + if (treeItem->type() != TestTreeItem::TestCase) + return false; + + const QString testItemTestCase = treeItem->parentItem()->name() + '.' + treeItem->name(); + return testItemTestCase == normalizeName(testCaseName); +} + +static bool matchesTestSuite(const QString &name, const TestTreeItem *treeItem) +{ + if (treeItem->type() != TestTreeItem::TestSuite) + return false; + + return treeItem->name() == normalizeTestName(name); +} + +static bool matches(const QString &name, const FilePath &projectFile, + const QString &testCaseName, const TestTreeItem *treeItem) +{ + if (treeItem->proFile() != projectFile) + return false; + + if (!testCaseName.isEmpty()) + return matchesTestCase(testCaseName, treeItem); + return matchesTestSuite(name, treeItem); +} + +static ResultHooks::FindTestItemHook findTestItemHook(const FilePath &projectFile, + const QString &testCaseName) +{ + return [=](const TestResult &result) -> ITestTreeItem * { + const Id id = Id(Constants::FRAMEWORK_PREFIX).withSuffix(GTest::Constants::FRAMEWORK_NAME); + ITestFramework *framework = TestFrameworkManager::frameworkForId(id); + QTC_ASSERT(framework, return nullptr); + const TestTreeItem *rootNode = framework->rootNode(); + if (!rootNode) + return nullptr; + + return rootNode->findAnyChild([&](const TreeItem *item) { + const auto testTreeItem = static_cast(item); + return testTreeItem && matches(result.name(), projectFile, testCaseName, testTreeItem); + }); + }; +} + +GTestResult::GTestResult(const QString &id, const QString &name, const FilePath &projectFile, + const QString &testCaseName, int iteration) + : TestResult(id, name, {outputStringHook(testCaseName), + findTestItemHook(projectFile, testCaseName)}) + , m_testCaseName(testCaseName) + , m_iteration(iteration) {} + bool GTestResult::isDirectParentOf(const TestResult *other, bool *needsIntermediate) const { if (!TestResult::isDirectParentOf(other, needsIntermediate)) @@ -60,65 +121,5 @@ bool GTestResult::isDirectParentOf(const TestResult *other, bool *needsIntermedi return isTestSuite() && gtOther->isTestCase(); } -static QString normalizeName(const QString &name) -{ - static QRegularExpression parameterIndex("/\\d+"); - - QString nameWithoutParameterIndices = name; - nameWithoutParameterIndices.remove(parameterIndex); - - return nameWithoutParameterIndices.split('/').last(); -} - -static QString normalizeTestName(const QString &testname) -{ - QString nameWithoutTypeParam = testname.split(',').first(); - - return normalizeName(nameWithoutTypeParam); -} - -const ITestTreeItem *GTestResult::findTestTreeItem() const -{ - auto id = Utils::Id(Constants::FRAMEWORK_PREFIX).withSuffix(GTest::Constants::FRAMEWORK_NAME); - ITestFramework *framework = TestFrameworkManager::frameworkForId(id); - QTC_ASSERT(framework, return nullptr); - const TestTreeItem *rootNode = framework->rootNode(); - if (!rootNode) - return nullptr; - - return rootNode->findAnyChild([this](const Utils::TreeItem *item) { - const auto treeItem = static_cast(item); - return treeItem && matches(treeItem); - }); -} - -bool GTestResult::matches(const TestTreeItem *treeItem) const -{ - if (treeItem->proFile() != m_projectFile) - return false; - - if (isTestSuite()) - return matchesTestSuite(treeItem); - - return matchesTestCase(treeItem); -} - -bool GTestResult::matchesTestCase(const TestTreeItem *treeItem) const -{ - if (treeItem->type() != TestTreeItem::TestCase) - return false; - - const QString testItemTestCase = treeItem->parentItem()->name() + '.' + treeItem->name(); - return testItemTestCase == normalizeName(m_testCaseName); -} - -bool GTestResult::matchesTestSuite(const TestTreeItem *treeItem) const -{ - if (treeItem->type() != TestTreeItem::TestSuite) - return false; - - return treeItem->name() == normalizeTestName(name()); -} - } // namespace Internal } // namespace Autotest diff --git a/src/plugins/autotest/gtest/gtestresult.h b/src/plugins/autotest/gtest/gtestresult.h index 5ce8255855d..8b66db1dee6 100644 --- a/src/plugins/autotest/gtest/gtestresult.h +++ b/src/plugins/autotest/gtest/gtestresult.h @@ -18,17 +18,11 @@ public: const QString &testCaseName = {}, int iteration = 1); bool isDirectParentOf(const TestResult *other, bool *needsIntermediate) const override; - virtual const ITestTreeItem *findTestTreeItem() const override; private: bool isTestSuite() const { return m_testCaseName.isEmpty(); } bool isTestCase() const { return !m_testCaseName.isEmpty(); } - bool matches(const TestTreeItem *item) const; - bool matchesTestCase(const TestTreeItem *treeItem) const; - bool matchesTestSuite(const TestTreeItem *treeItem) const; - - Utils::FilePath m_projectFile; QString m_testCaseName; int m_iteration = 1; }; diff --git a/src/plugins/autotest/qtest/qttestresult.cpp b/src/plugins/autotest/qtest/qttestresult.cpp index 6fcffe8f0cf..ad4b5ca6124 100644 --- a/src/plugins/autotest/qtest/qttestresult.cpp +++ b/src/plugins/autotest/qtest/qttestresult.cpp @@ -9,12 +9,14 @@ #include #include +using namespace Utils; + namespace Autotest { namespace Internal { static ResultHooks::OutputStringHook outputStringHook(const QString &function, const QString &dataTag) { - return [function, dataTag](const TestResult &result, bool selected) { + return [=](const TestResult &result, bool selected) { const QString &desc = result.description(); const QString &className = result.name(); QString output; @@ -56,10 +58,97 @@ static ResultHooks::OutputStringHook outputStringHook(const QString &function, c }; } -QtTestResult::QtTestResult(const QString &id, const QString &name, - const Utils::FilePath &projectFile, TestType type, - const QString &functionName, const QString &dataTag) - : TestResult(id, name, {outputStringHook(functionName, dataTag)}) +static bool matchesTestCase(const QString &name, const TestTreeItem *item) +{ + // FIXME this will never work for Quick Tests + return item->name() == name; +} + +static bool matchesTestFunction(const QString &name, TestType testType, const QString &functionName, + const QString &dataTag, const TestTreeItem *item) +{ + TestTreeItem *parentItem = item->parentItem(); + const TestTreeItem::Type type = item->type(); + if (testType == TestType::QuickTest) { // Quick tests have slightly different layout // BAD/WRONG! + const QStringList tmp = functionName.split("::"); + return tmp.size() == 2 && item->name() == tmp.last() && parentItem->name() == tmp.first(); + } + if (type == TestTreeItem::TestDataTag) { + TestTreeItem *grandParentItem = parentItem->parentItem(); + return parentItem->name() == functionName && grandParentItem->name() == name + && item->name() == dataTag; + } + return item->name() == functionName && parentItem->name() == name; +} + +static bool matches(const QString &name, const FilePath &projectFile, TestType testType, + const QString &functionName, const QString &dataTag, const TestTreeItem *item) +{ + const auto isTestCase = [&] { return functionName.isEmpty() && dataTag.isEmpty(); }; + const auto isTestFunction = [&] { return !functionName.isEmpty() && dataTag.isEmpty(); }; + const auto isDataTag = [&] { return !functionName.isEmpty() && !dataTag.isEmpty(); }; + + QTC_ASSERT(item, return false); + TestTreeItem *parentItem = item->parentItem(); + QTC_ASSERT(parentItem, return false); + + TestTreeItem::Type type = item->type(); + switch (type) { + case TestTreeItem::TestCase: + if (!isTestCase()) + return false; + if (item->proFile() != projectFile) + return false; + return matchesTestCase(name, item); + case TestTreeItem::TestFunction: + case TestTreeItem::TestSpecialFunction: + // QuickTest data tags have no dedicated TestTreeItem, so treat these results as function + if (!isTestFunction() && !(testType == TestType::QuickTest && isDataTag())) + return false; + if (parentItem->proFile() != projectFile) + return false; + return matchesTestFunction(name, testType, functionName, dataTag, item); + case TestTreeItem::TestDataTag: { + if (!isDataTag()) + return false; + TestTreeItem *grandParentItem = parentItem->parentItem(); + QTC_ASSERT(grandParentItem, return false); + if (grandParentItem->proFile() != projectFile) + return false; + return matchesTestFunction(name, testType, functionName, dataTag, item); + } + default: + break; + } + + return false; +} + +static ResultHooks::FindTestItemHook findTestItemHook(const FilePath &projectFile, TestType type, + const QString &functionName, + const QString &dataTag) +{ + return [=](const TestResult &result) -> ITestTreeItem * { + const Id id = type == TestType::QtTest + ? Id(Constants::FRAMEWORK_PREFIX).withSuffix(QtTest::Constants::FRAMEWORK_NAME) + : Id(Constants::FRAMEWORK_PREFIX).withSuffix(QuickTest::Constants::FRAMEWORK_NAME); + ITestFramework *framework = TestFrameworkManager::frameworkForId(id); + QTC_ASSERT(framework, return nullptr); + const TestTreeItem *rootNode = framework->rootNode(); + QTC_ASSERT(rootNode, return nullptr); + + return rootNode->findAnyChild([&](const TreeItem *item) { + const TestTreeItem *testTreeItem = static_cast(item); + return testTreeItem && matches(result.name(), projectFile, type, functionName, dataTag, + testTreeItem); + }); + }; +} + +QtTestResult::QtTestResult(const QString &id, const QString &name, const FilePath &projectFile, + TestType type, const QString &functionName, const QString &dataTag) + : TestResult(id, name, {outputStringHook(functionName, dataTag), + findTestItemHook(projectFile, type, functionName, dataTag)}) , m_projectFile(projectFile) , m_type(type) , m_function(functionName) @@ -116,85 +205,5 @@ TestResult *QtTestResult::createIntermediateResultFor(const TestResult *other) c return intermediate; } -const ITestTreeItem *QtTestResult::findTestTreeItem() const -{ - Utils::Id id; - if (m_type == TestType::QtTest) - id = Utils::Id(Constants::FRAMEWORK_PREFIX).withSuffix(QtTest::Constants::FRAMEWORK_NAME); - else - id = Utils::Id(Constants::FRAMEWORK_PREFIX).withSuffix(QuickTest::Constants::FRAMEWORK_NAME); - ITestFramework *framework = TestFrameworkManager::frameworkForId(id); - QTC_ASSERT(framework, return nullptr); - const TestTreeItem *rootNode = framework->rootNode(); - QTC_ASSERT(rootNode, return nullptr); - - return rootNode->findAnyChild([this](const Utils::TreeItem *item) { - const TestTreeItem *treeItem = static_cast(item); - return treeItem && matches(treeItem); - }); -} - -bool QtTestResult::matches(const TestTreeItem *item) const -{ - QTC_ASSERT(item, return false); - TestTreeItem *parentItem = item->parentItem(); - QTC_ASSERT(parentItem, return false); - - TestTreeItem::Type type = item->type(); - switch (type) { - case TestTreeItem::TestCase: - if (!isTestCase()) - return false; - if (item->proFile() != m_projectFile) - return false; - return matchesTestCase(item); - case TestTreeItem::TestFunction: - case TestTreeItem::TestSpecialFunction: - // QuickTest data tags have no dedicated TestTreeItem, so treat these results as function - if (!isTestFunction() && !(m_type == TestType::QuickTest && isDataTag())) - return false; - if (parentItem->proFile() != m_projectFile) - return false; - return matchesTestFunction(item); - case TestTreeItem::TestDataTag: { - if (!isDataTag()) - return false; - TestTreeItem *grandParentItem = parentItem->parentItem(); - QTC_ASSERT(grandParentItem, return false); - if (grandParentItem->proFile() != m_projectFile) - return false; - return matchesTestFunction(item); - } - default: - break; - } - - return false; -} - -bool QtTestResult::matchesTestCase(const TestTreeItem *item) const -{ - // FIXME this will never work for Quick Tests - if (item->name() == name()) - return true; - return false; -} - -bool QtTestResult::matchesTestFunction(const TestTreeItem *item) const -{ - TestTreeItem *parentItem = item->parentItem(); - TestTreeItem::Type type = item->type(); - if (m_type == TestType::QuickTest) { // Quick tests have slightly different layout // BAD/WRONG! - const QStringList tmp = m_function.split("::"); - return tmp.size() == 2 && item->name() == tmp.last() && parentItem->name() == tmp.first(); - } - if (type == TestTreeItem::TestDataTag) { - TestTreeItem *grandParentItem = parentItem->parentItem(); - return parentItem->name() == m_function && grandParentItem->name() == name() - && item->name() == m_dataTag; - } - return item->name() == m_function && parentItem->name() == name(); -} - } // namespace Internal } // namespace Autotest diff --git a/src/plugins/autotest/qtest/qttestresult.h b/src/plugins/autotest/qtest/qttestresult.h index 9cd17ddce2d..382649b5d0c 100644 --- a/src/plugins/autotest/qtest/qttestresult.h +++ b/src/plugins/autotest/qtest/qttestresult.h @@ -21,16 +21,12 @@ public: bool isDirectParentOf(const TestResult *other, bool *needsIntermediate) const override; bool isIntermediateFor(const TestResult *other) const override; TestResult *createIntermediateResultFor(const TestResult *other) const override; - const ITestTreeItem *findTestTreeItem() const override; + private: bool isTestCase() const { return m_function.isEmpty() && m_dataTag.isEmpty(); } bool isTestFunction() const { return !m_function.isEmpty() && m_dataTag.isEmpty(); } bool isDataTag() const { return !m_function.isEmpty() && !m_dataTag.isEmpty(); } - bool matches(const TestTreeItem *item) const; - bool matchesTestCase(const TestTreeItem *item) const; - bool matchesTestFunction(const TestTreeItem *item) const; - Utils::FilePath m_projectFile; TestType m_type; QString m_function; diff --git a/src/plugins/autotest/testresult.cpp b/src/plugins/autotest/testresult.cpp index f275669a78b..ae42e28231d 100644 --- a/src/plugins/autotest/testresult.cpp +++ b/src/plugins/autotest/testresult.cpp @@ -27,6 +27,8 @@ const QString TestResult::outputString(bool selected) const const ITestTreeItem *TestResult::findTestTreeItem() const { + if (m_hooks.findTestItem) + return m_hooks.findTestItem(*this); return nullptr; } diff --git a/src/plugins/autotest/testresult.h b/src/plugins/autotest/testresult.h index 62e5d36f098..556802da3c5 100644 --- a/src/plugins/autotest/testresult.h +++ b/src/plugins/autotest/testresult.h @@ -63,7 +63,9 @@ class TestResult; struct ResultHooks { using OutputStringHook = std::function; + using FindTestItemHook = std::function; OutputStringHook outputString; + FindTestItemHook findTestItem; }; class TestResult @@ -74,7 +76,7 @@ public: virtual ~TestResult() {} const QString outputString(bool selected) const; - virtual const ITestTreeItem *findTestTreeItem() const; + const ITestTreeItem *findTestTreeItem() const; QString id() const { return m_id; } QString name() const { return m_name; }