forked from qt-creator/qt-creator
AutoTest: generalize create default result
Add a pure virtual function to TestOutputReader returning a pointer to a default constructed result. Change-Id: Icd8090346f2c5115a7c548da7ba69ea54fe39fc4 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -92,15 +92,15 @@ void GTestOutputReader::processOutput(const QByteArray &outputLine)
|
||||
}
|
||||
|
||||
if (testEnds.exactMatch(line)) {
|
||||
GTestResult *testResult = createDefaultResult();
|
||||
TestResultPtr testResult = createDefaultResult();
|
||||
testResult->setResult(Result::MessageTestCaseEnd);
|
||||
testResult->setDescription(tr("Test execution took %1").arg(testEnds.cap(2)));
|
||||
reportResult(TestResultPtr(testResult));
|
||||
reportResult(testResult);
|
||||
m_currentTestName.clear();
|
||||
m_currentTestSet.clear();
|
||||
} else if (newTestStarts.exactMatch(line)) {
|
||||
setCurrentTestName(newTestStarts.cap(1));
|
||||
TestResultPtr testResult = TestResultPtr(createDefaultResult());
|
||||
TestResultPtr testResult = createDefaultResult();
|
||||
testResult->setResult(Result::MessageTestCaseStart);
|
||||
if (m_iteration > 1) {
|
||||
testResult->setDescription(tr("Repeating test case %1 (iteration %2)")
|
||||
@@ -117,18 +117,18 @@ void GTestOutputReader::processOutput(const QByteArray &outputLine)
|
||||
reportResult(testResult);
|
||||
m_description.clear();
|
||||
} else if (testSetSuccess.exactMatch(line)) {
|
||||
GTestResult *testResult = createDefaultResult();
|
||||
TestResultPtr testResult = createDefaultResult();
|
||||
testResult->setResult(Result::Pass);
|
||||
testResult->setDescription(m_description);
|
||||
reportResult(TestResultPtr(testResult));
|
||||
reportResult(testResult);
|
||||
m_description.clear();
|
||||
testResult = createDefaultResult();
|
||||
testResult->setResult(Result::MessageInternal);
|
||||
testResult->setDescription(tr("Execution took %1.").arg(testSetSuccess.cap(2)));
|
||||
reportResult(TestResultPtr(testResult));
|
||||
reportResult(testResult);
|
||||
m_futureInterface.setProgressValue(m_futureInterface.progressValue() + 1);
|
||||
} else if (testSetFail.exactMatch(line)) {
|
||||
GTestResult *testResult = createDefaultResult();
|
||||
TestResultPtr testResult = createDefaultResult();
|
||||
testResult->setResult(Result::Fail);
|
||||
m_description.chop(1);
|
||||
testResult->setDescription(m_description);
|
||||
@@ -149,27 +149,17 @@ void GTestOutputReader::processOutput(const QByteArray &outputLine)
|
||||
}
|
||||
}
|
||||
}
|
||||
reportResult(TestResultPtr(testResult));
|
||||
reportResult(testResult);
|
||||
m_description.clear();
|
||||
testResult = createDefaultResult();
|
||||
testResult->setResult(Result::MessageInternal);
|
||||
testResult->setDescription(tr("Execution took %1.").arg(testSetFail.cap(2)));
|
||||
reportResult(TestResultPtr(testResult));
|
||||
reportResult(testResult);
|
||||
m_futureInterface.setProgressValue(m_futureInterface.progressValue() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
void GTestOutputReader::setCurrentTestSet(const QString &testSet)
|
||||
{
|
||||
m_currentTestSet = testSet;
|
||||
}
|
||||
|
||||
void GTestOutputReader::setCurrentTestName(const QString &testName)
|
||||
{
|
||||
m_currentTestName = testName;
|
||||
}
|
||||
|
||||
GTestResult *GTestOutputReader::createDefaultResult() const
|
||||
TestResultPtr GTestOutputReader::createDefaultResult() const
|
||||
{
|
||||
GTestResult *result = new GTestResult(m_executable, m_projectFile, m_currentTestName);
|
||||
result->setTestSetName(m_currentTestSet);
|
||||
@@ -182,7 +172,17 @@ GTestResult *GTestOutputReader::createDefaultResult() const
|
||||
result->setLine(static_cast<int>(testItem->line()));
|
||||
}
|
||||
|
||||
return result;
|
||||
return TestResultPtr(result);
|
||||
}
|
||||
|
||||
void GTestOutputReader::setCurrentTestSet(const QString &testSet)
|
||||
{
|
||||
m_currentTestSet = testSet;
|
||||
}
|
||||
|
||||
void GTestOutputReader::setCurrentTestName(const QString &testName)
|
||||
{
|
||||
m_currentTestName = testName;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -43,14 +43,13 @@ public:
|
||||
GTestOutputReader(const QFutureInterface<TestResultPtr> &futureInterface,
|
||||
QProcess *testApplication, const QString &buildDirectory,
|
||||
const QString &projectFile);
|
||||
|
||||
protected:
|
||||
void processOutput(const QByteArray &outputLine) override;
|
||||
TestResultPtr createDefaultResult() const override;
|
||||
|
||||
private:
|
||||
void setCurrentTestSet(const QString &testSet);
|
||||
void setCurrentTestName(const QString &testName);
|
||||
GTestResult *createDefaultResult() const;
|
||||
|
||||
QString m_executable;
|
||||
QString m_projectFile;
|
||||
|
||||
@@ -152,6 +152,14 @@ void QtTestOutputReader::processOutput(const QByteArray &outputLine)
|
||||
}
|
||||
}
|
||||
|
||||
TestResultPtr QtTestOutputReader::createDefaultResult() const
|
||||
{
|
||||
QtTestResult *result = new QtTestResult(m_executable, m_projectFile, m_testType, m_className);
|
||||
result->setFunctionName(m_testCase);
|
||||
result->setDataTag(m_dataTag);
|
||||
return TestResultPtr(result);
|
||||
}
|
||||
|
||||
void QtTestOutputReader::processXMLOutput(const QByteArray &outputLine)
|
||||
{
|
||||
static QStringList validEndTags = {QStringLiteral("Incident"),
|
||||
@@ -416,17 +424,9 @@ void QtTestOutputReader::processSummaryFinishOutput()
|
||||
m_lineNumber = 0;
|
||||
}
|
||||
|
||||
QtTestResult *QtTestOutputReader::createDefaultResult() const
|
||||
{
|
||||
QtTestResult *result = new QtTestResult(m_executable, m_projectFile, m_testType, m_className);
|
||||
result->setFunctionName(m_testCase);
|
||||
result->setDataTag(m_dataTag);
|
||||
return result;
|
||||
}
|
||||
|
||||
void QtTestOutputReader::sendCompleteInformation()
|
||||
{
|
||||
TestResultPtr testResult = TestResultPtr(createDefaultResult());
|
||||
TestResultPtr testResult = createDefaultResult();
|
||||
testResult->setResult(m_result);
|
||||
|
||||
if (m_lineNumber) {
|
||||
@@ -453,7 +453,7 @@ void QtTestOutputReader::sendMessageCurrentTest()
|
||||
|
||||
void QtTestOutputReader::sendStartMessage(bool isFunction)
|
||||
{
|
||||
TestResultPtr testResult = TestResultPtr(createDefaultResult());
|
||||
TestResultPtr testResult = createDefaultResult();
|
||||
testResult->setResult(Result::MessageTestCaseStart);
|
||||
testResult->setDescription(isFunction ? tr("Executing test function %1").arg(m_testCase)
|
||||
: tr("Executing test case %1").arg(m_className));
|
||||
@@ -467,7 +467,7 @@ void QtTestOutputReader::sendStartMessage(bool isFunction)
|
||||
|
||||
void QtTestOutputReader::sendFinishMessage(bool isFunction)
|
||||
{
|
||||
TestResultPtr testResult = TestResultPtr(createDefaultResult());
|
||||
TestResultPtr testResult = createDefaultResult();
|
||||
testResult->setResult(Result::MessageTestCaseEnd);
|
||||
if (!m_duration.isEmpty()) {
|
||||
testResult->setDescription(isFunction ? tr("Execution took %1 ms.").arg(m_duration)
|
||||
@@ -482,18 +482,18 @@ void QtTestOutputReader::sendFinishMessage(bool isFunction)
|
||||
// TODO factor out tr() strings to avoid duplication (see XML processing of Characters)
|
||||
void QtTestOutputReader::handleAndSendConfigMessage(const QRegExp &config)
|
||||
{
|
||||
QtTestResult *testResult = createDefaultResult();
|
||||
TestResultPtr testResult = createDefaultResult();
|
||||
testResult->setResult(Result::MessageInternal);
|
||||
testResult->setDescription(tr("Qt version: %1").arg(config.cap(3)));
|
||||
reportResult(TestResultPtr(testResult));
|
||||
reportResult(testResult);
|
||||
testResult = createDefaultResult();
|
||||
testResult->setResult(Result::MessageInternal);
|
||||
testResult->setDescription(tr("Qt build: %1").arg(config.cap(2)));
|
||||
reportResult(TestResultPtr(testResult));
|
||||
reportResult(testResult);
|
||||
testResult = createDefaultResult();
|
||||
testResult->setResult(Result::MessageInternal);
|
||||
testResult->setDescription(tr("QTest version: %1").arg(config.cap(1)));
|
||||
reportResult(TestResultPtr(testResult));
|
||||
reportResult(testResult);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -50,9 +50,9 @@ public:
|
||||
QtTestOutputReader(const QFutureInterface<TestResultPtr> &futureInterface,
|
||||
QProcess *testApplication, const QString &buildDirectory,
|
||||
const QString &projectFile, OutputMode mode, TestType type);
|
||||
|
||||
protected:
|
||||
void processOutput(const QByteArray &outputLine) override;
|
||||
TestResultPtr createDefaultResult() const override;
|
||||
|
||||
private:
|
||||
void processXMLOutput(const QByteArray &outputLine);
|
||||
@@ -61,7 +61,6 @@ private:
|
||||
void processLocationOutput(const QString &fileWithLine);
|
||||
void processSummaryFinishOutput();
|
||||
// helper functions
|
||||
QtTestResult *createDefaultResult() const;
|
||||
void sendCompleteInformation();
|
||||
void sendMessageCurrentTest();
|
||||
void sendStartMessage(bool isFunction);
|
||||
|
||||
@@ -49,6 +49,8 @@ public:
|
||||
signals:
|
||||
void newOutputAvailable(const QByteArray &output);
|
||||
protected:
|
||||
virtual TestResultPtr createDefaultResult() const = 0;
|
||||
|
||||
void reportResult(const TestResultPtr &result);
|
||||
QFutureInterface<TestResultPtr> m_futureInterface;
|
||||
QProcess *m_testApplication; // not owned
|
||||
|
||||
Reference in New Issue
Block a user