2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2014-10-07 15:51:02 +02:00
|
|
|
|
|
|
|
|
#include "testresult.h"
|
|
|
|
|
|
2016-10-31 13:11:52 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2016-03-02 16:23:45 +01:00
|
|
|
#include <utils/theme/theme.h>
|
|
|
|
|
|
2014-10-07 15:51:02 +02:00
|
|
|
namespace Autotest {
|
|
|
|
|
|
2023-01-13 17:31:35 +01:00
|
|
|
TestResult::TestResult(const QString &id, const QString &name, const ResultHooks &hooks)
|
2018-05-09 10:48:23 +02:00
|
|
|
: m_id(id)
|
2017-06-27 15:15:43 +02:00
|
|
|
, m_name(name)
|
2023-01-13 17:31:35 +01:00
|
|
|
, m_hooks(hooks)
|
2017-06-27 15:15:43 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-13 10:20:17 +02:00
|
|
|
const QString TestResult::outputString(bool selected) const
|
|
|
|
|
{
|
2023-01-13 17:31:35 +01:00
|
|
|
if (m_hooks.outputString)
|
|
|
|
|
return m_hooks.outputString(*this, selected);
|
|
|
|
|
|
2019-02-06 14:11:19 +01:00
|
|
|
if (m_result == ResultType::Application)
|
2019-02-01 12:24:56 +01:00
|
|
|
return m_id;
|
2016-09-29 12:15:43 +02:00
|
|
|
return selected ? m_description : m_description.split('\n').first();
|
2016-04-13 10:20:17 +02:00
|
|
|
}
|
|
|
|
|
|
2020-10-13 11:37:37 +02:00
|
|
|
const ITestTreeItem *TestResult::findTestTreeItem() const
|
2017-09-09 16:46:43 +02:00
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 14:11:19 +01:00
|
|
|
ResultType TestResult::resultFromString(const QString &resultString)
|
2014-10-07 15:51:02 +02:00
|
|
|
{
|
2016-09-29 12:15:43 +02:00
|
|
|
if (resultString == "pass")
|
2019-02-06 14:11:19 +01:00
|
|
|
return ResultType::Pass;
|
2017-06-19 15:58:21 +02:00
|
|
|
if (resultString == "fail" || resultString == "fail!")
|
2019-02-06 14:11:19 +01:00
|
|
|
return ResultType::Fail;
|
2016-09-29 12:15:43 +02:00
|
|
|
if (resultString == "xfail")
|
2019-02-06 14:11:19 +01:00
|
|
|
return ResultType::ExpectedFail;
|
2016-09-29 12:15:43 +02:00
|
|
|
if (resultString == "xpass")
|
2019-02-06 14:11:19 +01:00
|
|
|
return ResultType::UnexpectedPass;
|
2016-09-29 12:15:43 +02:00
|
|
|
if (resultString == "skip")
|
2019-02-06 14:11:19 +01:00
|
|
|
return ResultType::Skip;
|
2017-06-19 15:58:21 +02:00
|
|
|
if (resultString == "result")
|
2019-02-06 14:11:19 +01:00
|
|
|
return ResultType::Benchmark;
|
2016-09-29 12:15:43 +02:00
|
|
|
if (resultString == "qdebug")
|
2019-02-06 14:11:19 +01:00
|
|
|
return ResultType::MessageDebug;
|
2017-06-19 15:58:21 +02:00
|
|
|
if (resultString == "qinfo" || resultString == "info")
|
2019-02-06 14:11:19 +01:00
|
|
|
return ResultType::MessageInfo;
|
2017-06-19 15:58:21 +02:00
|
|
|
if (resultString == "warn" || resultString == "qwarn" || resultString == "warning")
|
2019-02-06 14:11:19 +01:00
|
|
|
return ResultType::MessageWarn;
|
2016-09-29 12:15:43 +02:00
|
|
|
if (resultString == "qfatal")
|
2019-02-06 14:11:19 +01:00
|
|
|
return ResultType::MessageFatal;
|
2018-02-13 10:49:46 +01:00
|
|
|
if ((resultString == "system") || (resultString == "qsystem"))
|
2019-02-06 14:11:19 +01:00
|
|
|
return ResultType::MessageSystem;
|
2016-09-29 12:15:43 +02:00
|
|
|
if (resultString == "bpass")
|
2019-02-06 14:11:19 +01:00
|
|
|
return ResultType::BlacklistedPass;
|
2016-09-29 12:15:43 +02:00
|
|
|
if (resultString == "bfail")
|
2019-02-06 14:11:19 +01:00
|
|
|
return ResultType::BlacklistedFail;
|
2019-01-24 08:53:31 +01:00
|
|
|
if (resultString == "bxpass")
|
2019-02-06 14:11:19 +01:00
|
|
|
return ResultType::BlacklistedXPass;
|
2019-01-24 08:53:31 +01:00
|
|
|
if (resultString == "bxfail")
|
2019-02-06 14:11:19 +01:00
|
|
|
return ResultType::BlacklistedXFail;
|
2015-02-05 07:51:51 +01:00
|
|
|
qDebug("Unexpected test result: %s", qPrintable(resultString));
|
2019-02-06 14:11:19 +01:00
|
|
|
return ResultType::Invalid;
|
2014-10-07 15:51:02 +02:00
|
|
|
}
|
|
|
|
|
|
2019-02-06 14:11:19 +01:00
|
|
|
ResultType TestResult::toResultType(int rt)
|
2014-11-11 17:30:34 +01:00
|
|
|
{
|
2019-02-06 14:11:19 +01:00
|
|
|
if (rt < int(ResultType::FIRST_TYPE) || rt > int(ResultType::LAST_TYPE))
|
|
|
|
|
return ResultType::Invalid;
|
2015-09-23 07:14:25 +02:00
|
|
|
|
2019-02-06 14:11:19 +01:00
|
|
|
return ResultType(rt);
|
2014-11-11 17:30:34 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-06 14:11:19 +01:00
|
|
|
QString TestResult::resultToString(const ResultType type)
|
2014-10-07 15:51:02 +02:00
|
|
|
{
|
2015-09-23 07:14:25 +02:00
|
|
|
switch (type) {
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::Pass:
|
2017-02-13 10:05:06 +01:00
|
|
|
return QString("PASS");
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::Fail:
|
2017-02-13 10:05:06 +01:00
|
|
|
return QString("FAIL");
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::ExpectedFail:
|
2017-02-13 10:05:06 +01:00
|
|
|
return QString("XFAIL");
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::UnexpectedPass:
|
2017-02-13 10:05:06 +01:00
|
|
|
return QString("XPASS");
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::Skip:
|
2017-02-13 10:05:06 +01:00
|
|
|
return QString("SKIP");
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::Benchmark:
|
2017-02-13 10:05:06 +01:00
|
|
|
return QString("BENCH");
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::MessageDebug:
|
2017-02-13 10:05:06 +01:00
|
|
|
return QString("DEBUG");
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::MessageInfo:
|
2017-02-13 10:05:06 +01:00
|
|
|
return QString("INFO");
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::MessageWarn:
|
2017-02-13 10:05:06 +01:00
|
|
|
return QString("WARN");
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::MessageFatal:
|
2017-02-13 10:05:06 +01:00
|
|
|
return QString("FATAL");
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::MessageSystem:
|
2017-02-13 10:05:06 +01:00
|
|
|
return QString("SYSTEM");
|
2019-12-11 11:28:06 +01:00
|
|
|
case ResultType::MessageError:
|
|
|
|
|
return QString("ERROR");
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::BlacklistedPass:
|
2017-02-13 10:05:06 +01:00
|
|
|
return QString("BPASS");
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::BlacklistedFail:
|
2017-02-13 10:05:06 +01:00
|
|
|
return QString("BFAIL");
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::BlacklistedXPass:
|
2019-01-24 08:53:31 +01:00
|
|
|
return QString("BXPASS");
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::BlacklistedXFail:
|
2019-01-24 08:53:31 +01:00
|
|
|
return QString("BXFAIL");
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::MessageLocation:
|
|
|
|
|
case ResultType::Application:
|
2018-08-18 21:48:34 +03:00
|
|
|
return QString();
|
2014-10-07 15:51:02 +02:00
|
|
|
default:
|
2019-02-06 14:11:19 +01:00
|
|
|
if (type >= ResultType::INTERNAL_MESSAGES_BEGIN && type <= ResultType::INTERNAL_MESSAGES_END)
|
2016-12-14 14:42:28 +01:00
|
|
|
return QString();
|
2017-02-13 10:05:06 +01:00
|
|
|
return QString("UNKNOWN");
|
2014-10-07 15:51:02 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 14:11:19 +01:00
|
|
|
QColor TestResult::colorForType(const ResultType type)
|
2014-10-07 15:51:02 +02:00
|
|
|
{
|
2019-02-06 14:11:19 +01:00
|
|
|
if (type >= ResultType::INTERNAL_MESSAGES_BEGIN && type <= ResultType::INTERNAL_MESSAGES_END)
|
2015-09-23 07:14:25 +02:00
|
|
|
return QColor("transparent");
|
|
|
|
|
|
2016-03-02 16:23:45 +01:00
|
|
|
Utils::Theme *creatorTheme = Utils::creatorTheme();
|
2015-09-23 07:14:25 +02:00
|
|
|
switch (type) {
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::Pass:
|
2016-03-02 16:23:45 +01:00
|
|
|
return creatorTheme->color(Utils::Theme::OutputPanes_TestPassTextColor);
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::Fail:
|
2016-03-02 16:23:45 +01:00
|
|
|
return creatorTheme->color(Utils::Theme::OutputPanes_TestFailTextColor);
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::ExpectedFail:
|
2016-03-02 16:23:45 +01:00
|
|
|
return creatorTheme->color(Utils::Theme::OutputPanes_TestXFailTextColor);
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::UnexpectedPass:
|
2016-03-02 16:23:45 +01:00
|
|
|
return creatorTheme->color(Utils::Theme::OutputPanes_TestXPassTextColor);
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::Skip:
|
2016-03-02 16:23:45 +01:00
|
|
|
return creatorTheme->color(Utils::Theme::OutputPanes_TestSkipTextColor);
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::MessageDebug:
|
|
|
|
|
case ResultType::MessageInfo:
|
2016-03-02 16:23:45 +01:00
|
|
|
return creatorTheme->color(Utils::Theme::OutputPanes_TestDebugTextColor);
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::MessageWarn:
|
2016-03-02 16:23:45 +01:00
|
|
|
return creatorTheme->color(Utils::Theme::OutputPanes_TestWarnTextColor);
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::MessageFatal:
|
|
|
|
|
case ResultType::MessageSystem:
|
2019-12-11 11:28:06 +01:00
|
|
|
case ResultType::MessageError:
|
2016-03-02 16:23:45 +01:00
|
|
|
return creatorTheme->color(Utils::Theme::OutputPanes_TestFatalTextColor);
|
2019-02-06 14:11:19 +01:00
|
|
|
case ResultType::BlacklistedPass:
|
|
|
|
|
case ResultType::BlacklistedFail:
|
|
|
|
|
case ResultType::BlacklistedXPass:
|
|
|
|
|
case ResultType::BlacklistedXFail:
|
2014-10-07 15:51:02 +02:00
|
|
|
default:
|
2016-03-02 16:23:45 +01:00
|
|
|
return creatorTheme->color(Utils::Theme::OutputPanes_StdOutTextColor);
|
2014-10-07 15:51:02 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-31 13:11:52 +01:00
|
|
|
bool TestResult::isDirectParentOf(const TestResult *other, bool * /*needsIntermediate*/) const
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(other, return false);
|
2018-05-09 10:48:23 +02:00
|
|
|
return !m_id.isEmpty() && m_id == other->m_id && m_name == other->m_name;
|
2016-10-31 13:11:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TestResult::isIntermediateFor(const TestResult *other) const
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(other, return false);
|
2018-05-09 10:48:23 +02:00
|
|
|
return !m_id.isEmpty() && m_id == other->m_id && m_name == other->m_name;
|
2016-10-31 13:11:52 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-13 17:42:35 +01:00
|
|
|
TestResult *TestResult::createIntermediateResultFor(const TestResult *other) const
|
2016-10-31 13:11:52 +01:00
|
|
|
{
|
2017-02-13 10:05:06 +01:00
|
|
|
QTC_ASSERT(other, return nullptr);
|
2018-05-09 10:48:23 +02:00
|
|
|
TestResult *intermediate = new TestResult(other->m_id, other->m_name);
|
2016-10-31 13:11:52 +01:00
|
|
|
return intermediate;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-07 15:51:02 +02:00
|
|
|
} // namespace Autotest
|