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,
|
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, {QVariant::fromValue(QtTestData{projectFile, type, functionName, dataTag}),
|
: TestResult(id, name, {QVariant::fromValue(QtTestData{projectFile, type, functionName, dataTag}),
|
||||||
outputStringHook(functionName, dataTag),
|
outputStringHook(functionName, dataTag),
|
||||||
findTestItemHook(projectFile, type, functionName, dataTag),
|
findTestItemHook(projectFile, type, functionName, dataTag),
|
||||||
directParentHook(functionName, dataTag),
|
directParentHook(functionName, dataTag),
|
||||||
intermediateHook(projectFile, functionName, dataTag)})
|
intermediateHook(projectFile, functionName, dataTag),
|
||||||
, m_projectFile(projectFile)
|
createResultHook(projectFile, type, functionName, dataTag)})
|
||||||
, 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace Autotest
|
} // namespace Autotest
|
||||||
|
@@ -17,14 +17,6 @@ class QtTestResult : public TestResult
|
|||||||
public:
|
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 = {});
|
||||||
|
|
||||||
TestResult *createIntermediateResultFor(const TestResult *other) const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Utils::FilePath m_projectFile;
|
|
||||||
TestType m_type;
|
|
||||||
QString m_function;
|
|
||||||
QString m_dataTag;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -178,6 +178,11 @@ bool TestResult::isIntermediateFor(const TestResult *other) const
|
|||||||
TestResult *TestResult::createIntermediateResultFor(const TestResult *other) const
|
TestResult *TestResult::createIntermediateResultFor(const TestResult *other) const
|
||||||
{
|
{
|
||||||
QTC_ASSERT(other, return nullptr);
|
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);
|
TestResult *intermediate = new TestResult(other->m_id, other->m_name);
|
||||||
return intermediate;
|
return intermediate;
|
||||||
}
|
}
|
||||||
|
@@ -66,11 +66,13 @@ struct ResultHooks
|
|||||||
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 &)>;
|
using IntermediateHook = std::function<bool(const TestResult &, const TestResult &)>;
|
||||||
|
using CreateResultHook = std::function<TestResult(const TestResult &)>;
|
||||||
QVariant extraData;
|
QVariant extraData;
|
||||||
OutputStringHook outputString;
|
OutputStringHook outputString;
|
||||||
FindTestItemHook findTestItem;
|
FindTestItemHook findTestItem;
|
||||||
DirectParentHook directParent;
|
DirectParentHook directParent;
|
||||||
IntermediateHook intermediate = {};
|
IntermediateHook intermediate = {};
|
||||||
|
CreateResultHook createResult = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
class TestResult
|
class TestResult
|
||||||
@@ -103,7 +105,7 @@ public:
|
|||||||
|
|
||||||
bool isDirectParentOf(const TestResult *other, bool *needsIntermediate) const;
|
bool isDirectParentOf(const TestResult *other, bool *needsIntermediate) const;
|
||||||
bool isIntermediateFor(const TestResult *other) const;
|
bool isIntermediateFor(const TestResult *other) const;
|
||||||
virtual TestResult *createIntermediateResultFor(const TestResult *other) const;
|
TestResult *createIntermediateResultFor(const TestResult *other) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_id;
|
QString m_id;
|
||||||
|
Reference in New Issue
Block a user