TestResult: Devirtualize the class - part 4 of 5

Step 4 - implement intermediateHook.

Change-Id: I2a0d921cc16b109fd6f72c3831d0564c761bb006
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Jarek Kobus
2023-01-14 13:03:19 +01:00
parent 01828cfd8e
commit 2b99ba1db7
8 changed files with 33 additions and 28 deletions

View File

@@ -130,10 +130,10 @@ static ResultHooks::DirectParentHook directParentHook(const QString &testCaseNam
BoostTestResult::BoostTestResult(const QString &id, const QString &name, BoostTestResult::BoostTestResult(const QString &id, const QString &name,
const FilePath &projectFile, const QString &testCaseName, const FilePath &projectFile, const QString &testCaseName,
const QString &testSuiteName) const QString &testSuiteName)
: TestResult(id, name, {outputStringHook(testCaseName), : TestResult(id, name, {QVariant::fromValue(BoostTestData{testCaseName, testSuiteName}),
outputStringHook(testCaseName),
findTestItemHook(projectFile, testCaseName, testSuiteName), findTestItemHook(projectFile, testCaseName, testSuiteName),
directParentHook(testCaseName, testSuiteName), directParentHook(testCaseName, testSuiteName)})
QVariant::fromValue(BoostTestData{testCaseName, testSuiteName})})
{} {}
} // namespace Internal } // namespace Internal

View File

@@ -68,8 +68,8 @@ static ResultHooks::DirectParentHook directParentHook(int depth)
} }
CatchResult::CatchResult(const QString &id, const QString &name, int depth) CatchResult::CatchResult(const QString &id, const QString &name, int depth)
: TestResult(id, name, {{}, findTestItemHook(), directParentHook(depth), : TestResult(id, name, {QVariant::fromValue(CatchData{depth}),
QVariant::fromValue(CatchData{depth})}) {}, findTestItemHook(), directParentHook(depth)})
{} {}
} // namespace Internal } // namespace Internal

View File

@@ -48,7 +48,7 @@ class CTestResult : public TestResult
{ {
public: public:
CTestResult(const QString &id, const QString &project, const QString &testCaseName) CTestResult(const QString &id, const QString &project, const QString &testCaseName)
: TestResult(id, project, {{}, findTestItemHook(testCaseName), directParentHook(), {}}) : TestResult(id, project, {{}, {}, findTestItemHook(testCaseName), directParentHook()})
{} {}
}; };

View File

@@ -125,10 +125,10 @@ static ResultHooks::DirectParentHook directParentHook(const QString &testCaseNam
GTestResult::GTestResult(const QString &id, const QString &name, const FilePath &projectFile, GTestResult::GTestResult(const QString &id, const QString &name, const FilePath &projectFile,
const QString &testCaseName, int iteration) const QString &testCaseName, int iteration)
: TestResult(id, name, {outputStringHook(testCaseName), : TestResult(id, name, {QVariant::fromValue(GTestData{testCaseName, iteration}),
outputStringHook(testCaseName),
findTestItemHook(projectFile, testCaseName), findTestItemHook(projectFile, testCaseName),
directParentHook(testCaseName, iteration), directParentHook(testCaseName, iteration)})
QVariant::fromValue(GTestData{testCaseName, iteration})})
{} {}
} // namespace Internal } // namespace Internal

View File

@@ -183,32 +183,38 @@ static ResultHooks::DirectParentHook directParentHook(const QString &functionNam
}; };
} }
static ResultHooks::IntermediateHook intermediateHook(const FilePath &projectFile,
const QString &functionName,
const QString &dataTag)
{
return [=](const TestResult &result, const TestResult &other) -> bool {
if (!other.extraData().canConvert<QtTestData>())
return false;
const QtTestData otherData = other.extraData().value<QtTestData>();
return dataTag == otherData.m_dataTag && functionName == otherData.m_function
&& result.name() == other.name() && result.id() == other.id()
&& projectFile == otherData.m_projectFile;
};
}
QtTestResult::QtTestResult(const QString &id, const QString &name, const FilePath &projectFile, QtTestResult::QtTestResult(const QString &id, const QString &name, const FilePath &projectFile,
TestType type, const QString &functionName, const QString &dataTag) TestType type, const QString &functionName, const QString &dataTag)
: TestResult(id, name, {outputStringHook(functionName, dataTag), : TestResult(id, name, {QVariant::fromValue(QtTestData{projectFile, type, functionName, dataTag}),
outputStringHook(functionName, dataTag),
findTestItemHook(projectFile, type, functionName, dataTag), findTestItemHook(projectFile, type, functionName, dataTag),
directParentHook(functionName, dataTag), directParentHook(functionName, dataTag),
QVariant::fromValue(QtTestData{projectFile, type, functionName, dataTag})}) intermediateHook(projectFile, functionName, dataTag)})
, m_projectFile(projectFile) , m_projectFile(projectFile)
, m_type(type) , m_type(type)
, m_function(functionName) , m_function(functionName)
, m_dataTag(dataTag) {} , m_dataTag(dataTag) {}
bool QtTestResult::isIntermediateFor(const TestResult *other) const
{
QTC_ASSERT(other, return false);
const QtTestResult *qtOther = static_cast<const QtTestResult *>(other);
return m_dataTag == qtOther->m_dataTag && m_function == qtOther->m_function
&& name() == qtOther->name() && id() == qtOther->id()
&& m_projectFile == qtOther->m_projectFile;
}
TestResult *QtTestResult::createIntermediateResultFor(const TestResult *other) const TestResult *QtTestResult::createIntermediateResultFor(const TestResult *other) const
{ {
QTC_ASSERT(other, return nullptr); QTC_ASSERT(other, return nullptr);
const QtTestResult *qtOther = static_cast<const QtTestResult *>(other); const QtTestResult *qtOther = static_cast<const QtTestResult *>(other);
QtTestResult *intermediate = new QtTestResult(qtOther->id(), qtOther->name(), qtOther->m_projectFile, QtTestResult *intermediate = new QtTestResult(qtOther->id(), qtOther->name(), qtOther->m_projectFile,
m_type); m_type, qtOther->m_function, qtOther->m_dataTag);
intermediate->m_function = qtOther->m_function; intermediate->m_function = qtOther->m_function;
intermediate->m_dataTag = qtOther->m_dataTag; intermediate->m_dataTag = qtOther->m_dataTag;
// intermediates will be needed only for data tags // intermediates will be needed only for data tags

View File

@@ -18,14 +18,9 @@ public:
QtTestResult(const QString &id, const QString &name, const Utils::FilePath &projectFile, QtTestResult(const QString &id, const QString &name, const Utils::FilePath &projectFile,
TestType type, const QString &functionName = {}, const QString &dataTag = {}); TestType type, const QString &functionName = {}, const QString &dataTag = {});
bool isIntermediateFor(const TestResult *other) const override;
TestResult *createIntermediateResultFor(const TestResult *other) const override; TestResult *createIntermediateResultFor(const TestResult *other) const override;
private: 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(); }
Utils::FilePath m_projectFile; Utils::FilePath m_projectFile;
TestType m_type; TestType m_type;
QString m_function; QString m_function;

View File

@@ -170,6 +170,8 @@ bool TestResult::isDirectParentOf(const TestResult *other, bool *needsIntermedia
bool TestResult::isIntermediateFor(const TestResult *other) const bool TestResult::isIntermediateFor(const TestResult *other) const
{ {
QTC_ASSERT(other, return false); QTC_ASSERT(other, return false);
if (m_hooks.intermediate)
return m_hooks.intermediate(*this, *other);
return !m_id.isEmpty() && m_id == other->m_id && m_name == other->m_name; return !m_id.isEmpty() && m_id == other->m_id && m_name == other->m_name;
} }

View File

@@ -65,10 +65,12 @@ struct ResultHooks
using OutputStringHook = std::function<QString(const TestResult &, bool)>; using OutputStringHook = std::function<QString(const TestResult &, bool)>;
using FindTestItemHook = std::function<ITestTreeItem *(const TestResult &)>; using FindTestItemHook = std::function<ITestTreeItem *(const TestResult &)>;
using DirectParentHook = std::function<bool(const TestResult &, const TestResult &, bool *)>; using DirectParentHook = std::function<bool(const TestResult &, const TestResult &, bool *)>;
using IntermediateHook = std::function<bool(const TestResult &, const TestResult &)>;
QVariant extraData;
OutputStringHook outputString; OutputStringHook outputString;
FindTestItemHook findTestItem; FindTestItemHook findTestItem;
DirectParentHook directParent; DirectParentHook directParent;
QVariant extraData; IntermediateHook intermediate = {};
}; };
class TestResult class TestResult
@@ -100,7 +102,7 @@ public:
static QColor colorForType(const ResultType type); static QColor colorForType(const ResultType type);
bool isDirectParentOf(const TestResult *other, bool *needsIntermediate) const; bool isDirectParentOf(const TestResult *other, bool *needsIntermediate) const;
virtual bool isIntermediateFor(const TestResult *other) const; bool isIntermediateFor(const TestResult *other) const;
virtual TestResult *createIntermediateResultFor(const TestResult *other) const; virtual TestResult *createIntermediateResultFor(const TestResult *other) const;
private: private: