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
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2014-10-07 15:51:02 +02:00
|
|
|
|
2016-01-12 13:52:21 +01:00
|
|
|
#include "autotestconstants.h"
|
|
|
|
|
|
2023-01-14 16:25:51 +01:00
|
|
|
#include <utils/filepath.h>
|
2021-05-26 15:50:03 +02:00
|
|
|
|
2014-10-07 15:51:02 +02:00
|
|
|
#include <QColor>
|
|
|
|
|
|
2023-02-15 16:25:16 +01:00
|
|
|
#include <optional>
|
|
|
|
|
|
2014-10-07 15:51:02 +02:00
|
|
|
namespace Autotest {
|
|
|
|
|
|
2020-10-13 11:37:37 +02:00
|
|
|
class ITestTreeItem;
|
2017-09-09 16:46:43 +02:00
|
|
|
|
2019-02-06 14:11:19 +01:00
|
|
|
enum class ResultType {
|
|
|
|
|
// result types (have icon, color, short text)
|
2015-12-07 08:26:54 +01:00
|
|
|
Pass, FIRST_TYPE = Pass,
|
|
|
|
|
Fail,
|
|
|
|
|
ExpectedFail,
|
|
|
|
|
UnexpectedPass,
|
|
|
|
|
Skip,
|
|
|
|
|
BlacklistedPass,
|
|
|
|
|
BlacklistedFail,
|
2019-01-24 08:53:31 +01:00
|
|
|
BlacklistedXPass,
|
|
|
|
|
BlacklistedXFail,
|
2019-02-06 14:11:19 +01:00
|
|
|
|
|
|
|
|
// special (message) types (have icon, color, short text)
|
2015-12-07 08:26:54 +01:00
|
|
|
Benchmark,
|
|
|
|
|
MessageDebug,
|
2016-07-11 10:55:43 +02:00
|
|
|
MessageInfo,
|
2015-12-07 08:26:54 +01:00
|
|
|
MessageWarn,
|
|
|
|
|
MessageFatal,
|
2016-07-11 15:13:52 +02:00
|
|
|
MessageSystem,
|
2019-12-11 11:28:06 +01:00
|
|
|
MessageError,
|
2015-09-23 07:14:25 +02:00
|
|
|
|
2019-02-06 14:11:19 +01:00
|
|
|
// special message - get's icon (but no color/short text) from parent
|
|
|
|
|
MessageLocation,
|
|
|
|
|
// anything below is an internal message (or a pure message without icon)
|
2015-12-07 08:26:54 +01:00
|
|
|
MessageInternal, INTERNAL_MESSAGES_BEGIN = MessageInternal,
|
2019-04-15 16:08:10 +02:00
|
|
|
// start item (get icon/short text depending on children)
|
2019-02-06 14:11:19 +01:00
|
|
|
TestStart,
|
|
|
|
|
// usually no icon/short text - more or less an indicator (and can contain test duration)
|
|
|
|
|
TestEnd,
|
|
|
|
|
// special global (temporary) message
|
2015-12-07 08:26:54 +01:00
|
|
|
MessageCurrentTest, INTERNAL_MESSAGES_END = MessageCurrentTest,
|
2015-09-23 07:14:25 +02:00
|
|
|
|
2019-02-06 14:11:19 +01:00
|
|
|
Application, // special.. not to be used outside of testresultmodel
|
|
|
|
|
Invalid, // indicator for unknown result items
|
2015-12-07 08:26:54 +01:00
|
|
|
LAST_TYPE = Invalid
|
2014-10-07 15:51:02 +02:00
|
|
|
};
|
2019-02-06 14:11:19 +01:00
|
|
|
|
2021-07-07 17:32:53 +02:00
|
|
|
inline auto qHash(const ResultType &result)
|
2019-02-06 14:11:19 +01:00
|
|
|
{
|
|
|
|
|
return QT_PREPEND_NAMESPACE(qHash(int(result)));
|
2015-01-08 13:46:28 +01:00
|
|
|
}
|
2014-10-07 15:51:02 +02:00
|
|
|
|
2023-01-13 17:31:35 +01:00
|
|
|
class TestResult;
|
|
|
|
|
|
|
|
|
|
struct ResultHooks
|
|
|
|
|
{
|
|
|
|
|
using OutputStringHook = std::function<QString(const TestResult &, bool)>;
|
2023-01-13 19:01:38 +01:00
|
|
|
using FindTestItemHook = std::function<ITestTreeItem *(const TestResult &)>;
|
2023-01-14 11:31:15 +01:00
|
|
|
using DirectParentHook = std::function<bool(const TestResult &, const TestResult &, bool *)>;
|
2023-01-14 13:03:19 +01:00
|
|
|
using IntermediateHook = std::function<bool(const TestResult &, const TestResult &)>;
|
2023-01-14 13:28:10 +01:00
|
|
|
using CreateResultHook = std::function<TestResult(const TestResult &)>;
|
2023-01-14 13:03:19 +01:00
|
|
|
QVariant extraData;
|
2023-02-15 16:25:16 +01:00
|
|
|
OutputStringHook outputString = {};
|
|
|
|
|
FindTestItemHook findTestItem = {};
|
|
|
|
|
DirectParentHook directParent = {};
|
2023-01-14 13:03:19 +01:00
|
|
|
IntermediateHook intermediate = {};
|
2023-01-14 13:28:10 +01:00
|
|
|
CreateResultHook createResult = {};
|
2023-01-13 17:31:35 +01:00
|
|
|
};
|
|
|
|
|
|
2014-10-07 15:51:02 +02:00
|
|
|
class TestResult
|
|
|
|
|
{
|
|
|
|
|
public:
|
2019-02-06 14:11:19 +01:00
|
|
|
TestResult() = default;
|
2023-01-13 17:31:35 +01:00
|
|
|
TestResult(const QString &id, const QString &name, const ResultHooks &hooks = {});
|
2016-04-13 10:20:17 +02:00
|
|
|
virtual ~TestResult() {}
|
2014-10-07 15:51:02 +02:00
|
|
|
|
2023-01-14 16:25:51 +01:00
|
|
|
bool isValid() const;
|
2023-01-13 17:31:35 +01:00
|
|
|
const QString outputString(bool selected) const;
|
2023-01-13 19:01:38 +01:00
|
|
|
const ITestTreeItem *findTestTreeItem() const;
|
2016-04-13 10:20:17 +02:00
|
|
|
|
2023-02-15 16:25:16 +01:00
|
|
|
QString id() const { return m_id.value_or(QString()); }
|
2016-04-13 10:20:17 +02:00
|
|
|
QString name() const { return m_name; }
|
2019-02-06 14:11:19 +01:00
|
|
|
ResultType result() const { return m_result; }
|
2014-10-07 15:51:02 +02:00
|
|
|
QString description() const { return m_description; }
|
2021-05-26 15:50:03 +02:00
|
|
|
Utils::FilePath fileName() const { return m_file; }
|
2014-10-07 15:51:02 +02:00
|
|
|
int line() const { return m_line; }
|
2023-01-14 11:31:15 +01:00
|
|
|
QVariant extraData() const { return m_hooks.extraData; }
|
2014-10-07 15:51:02 +02:00
|
|
|
|
2015-01-08 12:51:01 +01:00
|
|
|
void setDescription(const QString &description) { m_description = description; }
|
2021-05-26 15:50:03 +02:00
|
|
|
void setFileName(const Utils::FilePath &fileName) { m_file = fileName; }
|
2014-10-07 15:51:02 +02:00
|
|
|
void setLine(int line) { m_line = line; }
|
2019-02-06 14:11:19 +01:00
|
|
|
void setResult(ResultType type) { m_result = type; }
|
2014-10-07 15:51:02 +02:00
|
|
|
|
2019-02-06 14:11:19 +01:00
|
|
|
static ResultType resultFromString(const QString &resultString);
|
|
|
|
|
static ResultType toResultType(int rt);
|
|
|
|
|
static QString resultToString(const ResultType type);
|
|
|
|
|
static QColor colorForType(const ResultType type);
|
2014-10-07 15:51:02 +02:00
|
|
|
|
2023-01-14 16:25:51 +01:00
|
|
|
bool isDirectParentOf(const TestResult &other, bool *needsIntermediate) const;
|
|
|
|
|
bool isIntermediateFor(const TestResult &other) const;
|
|
|
|
|
TestResult intermediateResult() const;
|
2023-01-14 11:31:15 +01:00
|
|
|
|
2014-10-07 15:51:02 +02:00
|
|
|
private:
|
2023-02-15 16:25:16 +01:00
|
|
|
std::optional<QString> m_id = {};
|
2016-04-13 10:20:17 +02:00
|
|
|
QString m_name;
|
2019-02-06 14:11:19 +01:00
|
|
|
ResultType m_result = ResultType::Invalid; // the real result..
|
2014-10-07 15:51:02 +02:00
|
|
|
QString m_description;
|
2021-05-26 15:50:03 +02:00
|
|
|
Utils::FilePath m_file;
|
2016-04-13 10:20:17 +02:00
|
|
|
int m_line = 0;
|
2023-02-15 16:25:16 +01:00
|
|
|
ResultHooks m_hooks = {};
|
2014-10-07 15:51:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Autotest
|
|
|
|
|
|
2019-08-19 10:55:32 +02:00
|
|
|
Q_DECLARE_METATYPE(Autotest::TestResult)
|
|
|
|
|
Q_DECLARE_METATYPE(Autotest::ResultType)
|