From c8c79c409f3398a5e8b145d711f62b3c35ab11e0 Mon Sep 17 00:00:00 2001
From: Christian Stenger <christian.stenger@theqtcompany.com>
Date: Mon, 14 Dec 2015 10:19:37 +0100
Subject: [PATCH] Make test result distinguishable more easily

This additionally fixes the output of the gtest related test cases.

Change-Id: Ia9e19604ffe387752b08db4a4ad9a9e255d210a3
Reviewed-by: Niels Weber <niels.weber@theqtcompany.com>
---
 plugins/autotest/testoutputreader.cpp   | 28 ++++++++++++-------------
 plugins/autotest/testresult.cpp         | 12 +++++++++++
 plugins/autotest/testresult.h           | 21 +++++++++++++++++++
 plugins/autotest/testresultdelegate.cpp |  5 ++++-
 4 files changed, 51 insertions(+), 15 deletions(-)

diff --git a/plugins/autotest/testoutputreader.cpp b/plugins/autotest/testoutputreader.cpp
index 5dacfeee618..0b77f71c63b 100644
--- a/plugins/autotest/testoutputreader.cpp
+++ b/plugins/autotest/testoutputreader.cpp
@@ -183,14 +183,14 @@ void TestOutputReader::processOutput()
                 if (currentTag == QStringLiteral("TestCase")) {
                     className = xmlReader.attributes().value(QStringLiteral("name")).toString();
                     QTC_ASSERT(!className.isEmpty(), continue);
-                    auto testResult = new TestResult(className);
+                    auto testResult = new QTestResult(className);
                     testResult->setResult(Result::MessageTestCaseStart);
                     testResult->setDescription(tr("Executing test case %1").arg(className));
                     testResultCreated(testResult);
                 } else if (currentTag == QStringLiteral("TestFunction")) {
                     testCase = xmlReader.attributes().value(QStringLiteral("name")).toString();
                     QTC_ASSERT(!testCase.isEmpty(), continue);
-                    auto testResult = new TestResult();
+                    auto testResult = new QTestResult();
                     testResult->setResult(Result::MessageCurrentTest);
                     testResult->setDescription(tr("Entering test function %1::%2").arg(className,
                                                                                        testCase));
@@ -274,7 +274,7 @@ void TestOutputReader::processOutput()
                 const QStringRef currentTag = xmlReader.name();
                 if (currentTag == QStringLiteral("TestFunction")) {
                     if (!duration.isEmpty()) {
-                        auto testResult = new TestResult(className);
+                        auto testResult = new QTestResult(className);
                         testResult->setTestCase(testCase);
                         testResult->setResult(Result::MessageInternal);
                         testResult->setDescription(tr("Execution took %1 ms.").arg(duration));
@@ -282,14 +282,14 @@ void TestOutputReader::processOutput()
                     }
                     emit increaseProgress();
                 } else if (currentTag == QStringLiteral("TestCase")) {
-                    auto testResult = new TestResult(className);
+                    auto testResult = new QTestResult(className);
                     testResult->setResult(Result::MessageTestCaseEnd);
                     testResult->setDescription(
                             duration.isEmpty() ? tr("Test finished.")
                                                : tr("Test execution took %1 ms.").arg(duration));
                     testResultCreated(testResult);
                 } else if (validEndTags.contains(currentTag.toString())) {
-                    auto testResult = new TestResult(className);
+                    auto testResult = new QTestResult(className);
                     testResult->setTestCase(testCase);
                     testResult->setDataTag(dataTag);
                     testResult->setResult(result);
@@ -337,13 +337,13 @@ void TestOutputReader::processGTestOutput()
         if (!line.startsWith(QLatin1Char('['))) {
             description.append(line).append(QLatin1Char('\n'));
             if (line.startsWith(QStringLiteral("Note:"))) {
-                auto testResult = new TestResult();
+                auto testResult = new GTestResult();
                 testResult->setResult(Result::MessageInternal);
                 testResult->setDescription(line);
                 testResultCreated(testResult);
                 description.clear();
             } else if (disabledTests.exactMatch(line)) {
-                auto testResult = new TestResult();
+                auto testResult = new GTestResult();
                 testResult->setResult(Result::MessageInternal);
                 int disabled = disabledTests.cap(1).toInt();
                 testResult->setDescription(tr("You have %n disabled test(s).", 0, disabled));
@@ -354,7 +354,7 @@ void TestOutputReader::processGTestOutput()
         }
 
         if (testEnds.exactMatch(line)) {
-            auto testResult = new TestResult(currentTestName);
+            auto testResult = new GTestResult(currentTestName);
             testResult->setTestCase(currentTestSet);
             testResult->setResult(Result::MessageTestCaseEnd);
             testResult->setDescription(tr("Test execution took %1").arg(testEnds.cap(2)));
@@ -363,29 +363,29 @@ void TestOutputReader::processGTestOutput()
             currentTestSet.clear();
         } else if (newTestStarts.exactMatch(line)) {
             currentTestName = newTestStarts.cap(1);
-            auto testResult = new TestResult(currentTestName);
+            auto testResult = new GTestResult(currentTestName);
             testResult->setResult(Result::MessageTestCaseStart);
             testResult->setDescription(tr("Executing test case %1").arg(currentTestName));
             testResultCreated(testResult);
         } else if (newTestSetStarts.exactMatch(line)) {
             currentTestSet = newTestSetStarts.cap(1);
-            auto testResult = new TestResult();
+            auto testResult = new GTestResult();
             testResult->setResult(Result::MessageCurrentTest);
             testResult->setDescription(tr("Entering test set %1").arg(currentTestSet));
             testResultCreated(testResult);
         } else if (testSetSuccess.exactMatch(line)) {
-            auto testResult = new TestResult(currentTestName);
+            auto testResult = new GTestResult(currentTestName);
             testResult->setTestCase(currentTestSet);
             testResult->setResult(Result::Pass);
             testResultCreated(testResult);
-            testResult = new TestResult(currentTestName);
+            testResult = new GTestResult(currentTestName);
             testResult->setTestCase(currentTestSet);
             testResult->setResult(Result::MessageInternal);
             testResult->setDescription(tr("Execution took %1.").arg(testSetSuccess.cap(2)));
             testResultCreated(testResult);
             emit increaseProgress();
         } else if (testSetFail.exactMatch(line)) {
-            auto testResult = new TestResult(currentTestName);
+            auto testResult = new GTestResult(currentTestName);
             testResult->setTestCase(currentTestSet);
             testResult->setResult(Result::Fail);
             description.chop(1);
@@ -402,7 +402,7 @@ void TestOutputReader::processGTestOutput()
             }
             testResultCreated(testResult);
             description.clear();
-            testResult = new TestResult(currentTestName);
+            testResult = new GTestResult(currentTestName);
             testResult->setTestCase(currentTestSet);
             testResult->setResult(Result::MessageInternal);
             testResult->setDescription(tr("Execution took %1.").arg(testSetFail.cap(2)));
diff --git a/plugins/autotest/testresult.cpp b/plugins/autotest/testresult.cpp
index 37929f00f4f..5885c1c400a 100644
--- a/plugins/autotest/testresult.cpp
+++ b/plugins/autotest/testresult.cpp
@@ -37,6 +37,7 @@ TestResult::TestResult(const QString &className)
     : m_class(className)
     , m_result(Result::Invalid)
     , m_line(0)
+    , m_type(Qt)
 {
 }
 
@@ -146,5 +147,16 @@ bool operator==(const TestResult &t1, const TestResult &t2)
             && t1.result() == t2.result();
 }
 
+QTestResult::QTestResult(const QString &className)
+    : TestResult(className)
+{
+}
+
+GTestResult::GTestResult(const QString &className)
+    : TestResult(className)
+{
+    setTestType(GTest);
+}
+
 } // namespace Internal
 } // namespace Autotest
diff --git a/plugins/autotest/testresult.h b/plugins/autotest/testresult.h
index d28255aad0d..35158050303 100644
--- a/plugins/autotest/testresult.h
+++ b/plugins/autotest/testresult.h
@@ -57,6 +57,12 @@ enum Type {
 class TestResult
 {
 public:
+    enum TestType
+    {
+        Qt,
+        GTest
+    };
+
     TestResult();
     TestResult(const QString &className);
 
@@ -67,6 +73,7 @@ public:
     QString description() const { return m_description; }
     QString fileName() const { return m_file; }
     int line() const { return m_line; }
+    TestType type() const { return m_type; }
 
     void setDescription(const QString &description) { m_description = description; }
     void setFileName(const QString &fileName) { m_file = fileName; }
@@ -74,6 +81,7 @@ public:
     void setResult(Result::Type type) { m_result = type; }
     void setTestCase(const QString &testCase) { m_case = testCase; }
     void setDataTag(const QString &dataTag) { m_dataTag = dataTag; }
+    void setTestType(TestType type) { m_type = type; }
 
     static Result::Type resultFromString(const QString &resultString);
     static Result::Type toResultType(int rt);
@@ -88,6 +96,7 @@ private:
     QString m_description;
     QString m_file;
     int m_line;
+    TestType m_type;
     // environment?
 };
 
@@ -97,6 +106,18 @@ public:
     FaultyTestResult(Result::Type result, const QString &description);
 };
 
+class QTestResult : public TestResult
+{
+public:
+    QTestResult(const QString &className = QString());
+};
+
+class GTestResult : public TestResult
+{
+public:
+    GTestResult(const QString &className = QString());
+};
+
 bool operator==(const TestResult &t1, const TestResult &t2);
 
 } // namespace Internal
diff --git a/plugins/autotest/testresultdelegate.cpp b/plugins/autotest/testresultdelegate.cpp
index 87559465a22..a1ca6f9fe43 100644
--- a/plugins/autotest/testresultdelegate.cpp
+++ b/plugins/autotest/testresultdelegate.cpp
@@ -48,7 +48,10 @@ QString TestResultDelegate::outputString(const TestResult &testResult, bool sele
     case Result::UnexpectedPass:
     case Result::BlacklistedFail:
     case Result::BlacklistedPass:
-        output = testResult.className() + QLatin1String("::") + testResult.testCase();
+        if (testResult.type() == TestResult::Qt)
+            output = testResult.className() + QLatin1String("::") + testResult.testCase();
+        else // TestResult::GTest
+            output = testResult.testCase();
         if (!testResult.dataTag().isEmpty())
             output.append(QString::fromLatin1(" (%1)").arg(testResult.dataTag()));
         if (selected && !desc.isEmpty()) {
-- 
GitLab