forked from qt-creator/qt-creator
TestResult: Devirtualize the class - part 5 of 5
Step 5 - implement createResultHook. Change-Id: Ibe81fb93c8c1c12d1af458d0f9707d02864febd8 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -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<const QtTestResult *>(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
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -66,11 +66,13 @@ struct ResultHooks
|
||||
using FindTestItemHook = std::function<ITestTreeItem *(const TestResult &)>;
|
||||
using DirectParentHook = std::function<bool(const TestResult &, const TestResult &, bool *)>;
|
||||
using IntermediateHook = std::function<bool(const TestResult &, const TestResult &)>;
|
||||
using CreateResultHook = std::function<TestResult(const TestResult &)>;
|
||||
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;
|
||||
|
Reference in New Issue
Block a user