From f9090dab0cfa835a0cc116a554d47ce011580634 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Sat, 14 Jan 2023 13:28:10 +0100 Subject: [PATCH] TestResult: Devirtualize the class - part 5 of 5 Step 5 - implement createResultHook. Change-Id: Ibe81fb93c8c1c12d1af458d0f9707d02864febd8 Reviewed-by: Christian Stenger --- src/plugins/autotest/qtest/qttestresult.cpp | 44 ++++++++++----------- src/plugins/autotest/qtest/qttestresult.h | 8 ---- src/plugins/autotest/testresult.cpp | 5 +++ src/plugins/autotest/testresult.h | 4 +- 4 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/plugins/autotest/qtest/qttestresult.cpp b/src/plugins/autotest/qtest/qttestresult.cpp index ee56d4541b3..83ea4754f3f 100644 --- a/src/plugins/autotest/qtest/qttestresult.cpp +++ b/src/plugins/autotest/qtest/qttestresult.cpp @@ -197,35 +197,33 @@ static ResultHooks::IntermediateHook intermediateHook(const FilePath &projectFil }; } +static ResultHooks::CreateResultHook createResultHook(const FilePath &projectFile, TestType type, + const QString &functionName, + const QString &dataTag) +{ + return [=](const TestResult &result) -> TestResult { + TestResult newResult = QtTestResult(result.id(), result.name(), projectFile, type, + functionName, dataTag); + // intermediates will be needed only for data tags + newResult.setDescription("Data tag: " + dataTag); + const auto correspondingItem = newResult.findTestTreeItem(); + if (correspondingItem && correspondingItem->line()) { + newResult.setFileName(correspondingItem->filePath()); + newResult.setLine(correspondingItem->line()); + } + return newResult; + }; +} + QtTestResult::QtTestResult(const QString &id, const QString &name, const FilePath &projectFile, TestType type, const QString &functionName, const QString &dataTag) : TestResult(id, name, {QVariant::fromValue(QtTestData{projectFile, type, functionName, dataTag}), outputStringHook(functionName, dataTag), findTestItemHook(projectFile, type, functionName, dataTag), directParentHook(functionName, dataTag), - intermediateHook(projectFile, functionName, dataTag)}) - , m_projectFile(projectFile) - , m_type(type) - , m_function(functionName) - , m_dataTag(dataTag) {} - -TestResult *QtTestResult::createIntermediateResultFor(const TestResult *other) const -{ - QTC_ASSERT(other, return nullptr); - const QtTestResult *qtOther = static_cast(other); - QtTestResult *intermediate = new QtTestResult(qtOther->id(), qtOther->name(), qtOther->m_projectFile, - m_type, qtOther->m_function, qtOther->m_dataTag); - intermediate->m_function = qtOther->m_function; - intermediate->m_dataTag = qtOther->m_dataTag; - // intermediates will be needed only for data tags - intermediate->setDescription("Data tag: " + qtOther->m_dataTag); - const auto correspondingItem = intermediate->findTestTreeItem(); - if (correspondingItem && correspondingItem->line()) { - intermediate->setFileName(correspondingItem->filePath()); - intermediate->setLine(correspondingItem->line()); - } - return intermediate; -} + intermediateHook(projectFile, functionName, dataTag), + createResultHook(projectFile, type, functionName, dataTag)}) +{} } // namespace Internal } // namespace Autotest diff --git a/src/plugins/autotest/qtest/qttestresult.h b/src/plugins/autotest/qtest/qttestresult.h index 0f9c3e9c9cd..39196b77a26 100644 --- a/src/plugins/autotest/qtest/qttestresult.h +++ b/src/plugins/autotest/qtest/qttestresult.h @@ -17,14 +17,6 @@ class QtTestResult : public TestResult public: QtTestResult(const QString &id, const QString &name, const Utils::FilePath &projectFile, TestType type, const QString &functionName = {}, const QString &dataTag = {}); - - TestResult *createIntermediateResultFor(const TestResult *other) const override; - -private: - Utils::FilePath m_projectFile; - TestType m_type; - QString m_function; - QString m_dataTag; }; } // namespace Internal diff --git a/src/plugins/autotest/testresult.cpp b/src/plugins/autotest/testresult.cpp index 3749b0a8acc..fc1f481dfe4 100644 --- a/src/plugins/autotest/testresult.cpp +++ b/src/plugins/autotest/testresult.cpp @@ -178,6 +178,11 @@ bool TestResult::isIntermediateFor(const TestResult *other) const TestResult *TestResult::createIntermediateResultFor(const TestResult *other) const { QTC_ASSERT(other, return nullptr); + if (other->m_hooks.createResult) { + TestResult *newResult = new TestResult; + *newResult = other->m_hooks.createResult(*other); + return newResult; + } TestResult *intermediate = new TestResult(other->m_id, other->m_name); return intermediate; } diff --git a/src/plugins/autotest/testresult.h b/src/plugins/autotest/testresult.h index 23ad1ddd248..a136d356e18 100644 --- a/src/plugins/autotest/testresult.h +++ b/src/plugins/autotest/testresult.h @@ -66,11 +66,13 @@ struct ResultHooks using FindTestItemHook = std::function; using DirectParentHook = std::function; using IntermediateHook = std::function; + using CreateResultHook = std::function; QVariant extraData; OutputStringHook outputString; FindTestItemHook findTestItem; DirectParentHook directParent; IntermediateHook intermediate = {}; + CreateResultHook createResult = {}; }; class TestResult @@ -103,7 +105,7 @@ public: bool isDirectParentOf(const TestResult *other, bool *needsIntermediate) const; bool isIntermediateFor(const TestResult *other) const; - virtual TestResult *createIntermediateResultFor(const TestResult *other) const; + TestResult *createIntermediateResultFor(const TestResult *other) const; private: QString m_id;