blob: 9c616944b499102ae528a8d6614bfa0aa79e68a1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
// Copyright (C) 2019 Jochen Seemann
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "catchresult.h"
#include "catchtreeitem.h"
#include "../testframeworkmanager.h"
#include <utils/id.h>
#include <utils/qtcassert.h>
using namespace Utils;
namespace Autotest {
namespace Internal {
static ResultHooks::FindTestItemHook findTestItemHook()
{
return [=](const TestResult &result) -> ITestTreeItem * {
const Id id = Id(Constants::FRAMEWORK_PREFIX).withSuffix("Catch");
ITestFramework *framework = TestFrameworkManager::frameworkForId(id);
QTC_ASSERT(framework, return nullptr);
const TestTreeItem *rootNode = framework->rootNode();
if (!rootNode)
return nullptr;
return rootNode->findAnyChild([&](const TreeItem *item) {
const auto treeItem = static_cast<const CatchTreeItem *>(item);
if (!treeItem || treeItem->filePath() != result.fileName())
return false;
const bool parameterized = treeItem->states() & CatchTreeItem::Parameterized;
return parameterized ? result.name().startsWith(treeItem->name() + " - ")
: result.name() == treeItem->name();
});
};
}
struct CatchData
{
int m_sectionDepth = 0;
};
static ResultHooks::DirectParentHook directParentHook(int depth)
{
return [=](const TestResult &result, const TestResult &other, bool *) -> bool {
if (!other.extraData().canConvert<CatchData>())
return false;
const CatchData otherData = other.extraData().value<CatchData>();
if (result.result() != ResultType::TestStart)
return false;
if (other.result() == ResultType::TestStart) {
if (result.fileName() != other.fileName())
return false;
return depth + 1 == otherData.m_sectionDepth;
}
if (depth <= otherData.m_sectionDepth && other.result() == ResultType::Pass)
return true;
if (result.fileName() != other.fileName() || depth > otherData.m_sectionDepth)
return false;
return result.name() == other.name();
};
}
CatchResult::CatchResult(const QString &id, const QString &name, int depth)
: TestResult(id, name, {QVariant::fromValue(CatchData{depth}),
{}, findTestItemHook(), directParentHook(depth)})
{}
} // namespace Internal
} // namespace Autotest
Q_DECLARE_METATYPE(Autotest::Internal::CatchData);
|