aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/autotest/catch
diff options
context:
space:
mode:
authorJarek Kobus <[email protected]>2023-01-13 19:01:38 +0100
committerJarek Kobus <[email protected]>2023-01-20 14:18:32 +0000
commit01faf0843dd7b1641159b2b0a669ac80a6065558 (patch)
tree18d7be4d8c6a36ddff3de3fe3e274e5351abb898 /src/plugins/autotest/catch
parent6eb14c66c718245fb13c06a051c311ca451c3811 (diff)
TestResult: Devirtualize the class - part 2 of 5
Step 2 - implement findTestItemHook. Change-Id: Iabc843740343e549f79b02f74f94f5b1b4713af3 Reviewed-by: Christian Stenger <[email protected]>
Diffstat (limited to 'src/plugins/autotest/catch')
-rw-r--r--src/plugins/autotest/catch/catchresult.cpp48
-rw-r--r--src/plugins/autotest/catch/catchresult.h1
2 files changed, 24 insertions, 25 deletions
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 <utils/id.h>
#include <utils/qtcassert.h>
+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<const CatchTreeItem *>(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<const CatchTreeItem *>(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; }