summaryrefslogtreecommitdiff
path: root/src/plugins/qmlprofiler/tests/qmlprofilerbindingloopsrenderpass_test.cpp
blob: c1dfa9638681aa5a8a02da69440f444b82cbe81a (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/


#include "qmlprofilerbindingloopsrenderpass_test.h"

#include <qmlprofiler/qmlprofilerbindingloopsrenderpass.h>
#include <qmlprofiler/qmlprofilerrangemodel.h>
#include <tracing/timelineabstractrenderer.h>
#include <tracing/runscenegraphtest.h>
#include <QtTest>

namespace QmlProfiler {
namespace Internal {

class DummyModel : public QmlProfilerRangeModel {
public:
    DummyModel(QmlProfilerModelManager *manager, Timeline::TimelineModelAggregator *aggregator);
    void loadData();
};

DummyModel::DummyModel(QmlProfilerModelManager *manager,
                       Timeline::TimelineModelAggregator *aggregator) :
    QmlProfilerRangeModel(manager, Binding, aggregator)
{
}

void DummyModel::loadData()
{
    QmlEventType type(UndefinedMessage, Binding);
    const int typeIndex = modelManager()->appendEventType(QmlEventType(type));
    QCOMPARE(typeIndex, 0);

    for (int i = 0; i < 10; ++i) {
        QmlEvent event(i, typeIndex, {});
        event.setRangeStage(RangeStart);
        loadEvent(event, type);
    }

    for (int i = 10; i < 20; ++i) {
        QmlEvent event(i, typeIndex, {});
        event.setRangeStage(RangeEnd);
        loadEvent(event, type);
    }

    finalize();
}

QmlProfilerBindingLoopsRenderPassTest::QmlProfilerBindingLoopsRenderPassTest(QObject *parent) :
    QObject(parent)
{
}

void QmlProfilerBindingLoopsRenderPassTest::testInstance()
{
    const QmlProfilerBindingLoopsRenderPass *inst = QmlProfilerBindingLoopsRenderPass::instance();
    const QmlProfilerBindingLoopsRenderPass *inst2 = QmlProfilerBindingLoopsRenderPass::instance();
    QCOMPARE(inst, inst2);
    QVERIFY(inst != nullptr);
}

void QmlProfilerBindingLoopsRenderPassTest::testUpdate()
{
    const QmlProfilerBindingLoopsRenderPass *inst = QmlProfilerBindingLoopsRenderPass::instance();
    Timeline::TimelineAbstractRenderer renderer;
    Timeline::TimelineRenderState parentState(0, 8, 1, 1);
    Timeline::TimelineRenderPass::State *nullState = nullptr;
    QSGNode *nullNode = nullptr;
    Timeline::TimelineRenderPass::State *result =
            inst->update(&renderer, &parentState, nullptr, 0, 0, true, 1);
    QCOMPARE(result, nullState);

    QmlProfilerModelManager manager;
    Timeline::TimelineModelAggregator aggregator;
    DummyModel model(&manager, &aggregator);
    renderer.setModel(&model);
    result = inst->update(&renderer, &parentState, nullptr, 0, 0, true, 1);
    QCOMPARE(result, nullState);

    model.loadData();
    result = inst->update(&renderer, &parentState, nullptr, 0, 0, true, 1);
    QCOMPARE(result, nullState);

    result = inst->update(&renderer, &parentState, nullptr, 2, 9, true, 1);
    QVERIFY(result != nullState);
    QCOMPARE(result->expandedOverlay(), nullNode);
    QVERIFY(result->collapsedOverlay() != nullNode);
    QCOMPARE(result->expandedRows().count(), 2);  // all the loops are in one row
    QCOMPARE(result->collapsedRows().count(), 0); // it's an overlay
    QCOMPARE(result->expandedRows()[1]->childCount(), 1);
    auto node = static_cast<const QSGGeometryNode *>(result->expandedRows()[1]->firstChild());
    QSGMaterial *material1 = node->material();
    QVERIFY(material1 != nullptr);
    QCOMPARE(node->geometry()->vertexCount(), 7 * 4);
    node = static_cast<QSGGeometryNode *>(result->collapsedOverlay()->firstChild());
    QSGMaterial *material2 = node->material();
    QCOMPARE(node->geometry()->vertexCount(), 7 * 18);
    QVERIFY(material2 != nullptr);
    QCOMPARE(material1->type(), material2->type());
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    QSGMaterialShader *shader1 = material1->createShader();
    QVERIFY(shader1 != nullptr);
    QSGMaterialShader *shader2 = material2->createShader();
    QVERIFY(shader2 != nullptr);
    QCOMPARE(shader1->attributeNames(), shader2->attributeNames());
#else // < Qt 6
    QSGMaterialShader *shader1 = material1->createShader(QSGRendererInterface::RenderMode2D);
    QVERIFY(shader1 != 0);
    QSGMaterialShader *shader2 = material2->createShader(QSGRendererInterface::RenderMode2D);
    QVERIFY(shader2 != 0);
#endif // < Qt 6

    delete shader1;
    delete shader2;

    result = inst->update(&renderer, &parentState, result, 0, 10, true, 1);
    QVERIFY(result != nullState);
    QCOMPARE(result->expandedOverlay(), nullNode);
    QVERIFY(result->collapsedOverlay() != nullNode);
    QCOMPARE(result->expandedRows().count(), 2);
    QCOMPARE(result->collapsedRows().count(), 0);

    QCOMPARE(result->expandedRows()[1]->childCount(), 2);
    QCOMPARE(result->collapsedOverlay()->childCount(), 2);

    node = static_cast<QSGGeometryNode *>(result->expandedRows()[1]->childAtIndex(1));
    QCOMPARE(node->geometry()->vertexCount(), 4);
    node = static_cast<QSGGeometryNode *>(result->collapsedOverlay()->childAtIndex(1));
    QCOMPARE(node->geometry()->vertexCount(), 18);

    model.setExpanded(true);
    result = inst->update(&renderer, &parentState, result, 0, 10, true, 1);
    QVERIFY(result != nullState);
    QCOMPARE(result->expandedOverlay(), nullNode);
    QVERIFY(result->collapsedOverlay() != nullNode);
    QCOMPARE(result->expandedRows().count(), 2);
    QCOMPARE(result->collapsedRows().count(), 0);

    parentState.setPassState(0, result);
    parentState.assembleNodeTree(&model, 1, 1);

    Timeline::runSceneGraphTest(parentState.collapsedOverlayRoot());
    Timeline::runSceneGraphTest(parentState.expandedRowRoot());
}

} // namespace Internal
} // namespace QmlProfiler