summaryrefslogtreecommitdiff
path: root/src/plugins/qmlprofiler/tests/qmlprofileranimationsmodel_test.cpp
blob: 3881ad399d5e0785da1a895838e614835e37d253 (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
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "qmlprofileranimationsmodel_test.h"
#include "../qmlprofilertr.h"
#include <tracing/timelineformattime.h>
#include <QtTest>

namespace QmlProfiler {
namespace Internal {

QmlProfilerAnimationsModelTest::QmlProfilerAnimationsModelTest(QObject *parent) :
    QObject(parent), model(&manager, &aggregator)
{
}

static int frameRate(int i)
{
    return i * 7 - 2;
}

void QmlProfilerAnimationsModelTest::initTestCase()
{
    manager.initialize();

    QmlEvent event;
    event.setTypeIndex(manager.appendEventType(
                           QmlEventType(Event, UndefinedRangeType, AnimationFrame)));

    for (int i = 0; i < 10; ++i) {
        event.setTimestamp(i);
        event.setNumbers<int>({frameRate(i), 9 - i, (i % 2) ? RenderThread : GuiThread});
        manager.appendEvent(QmlEvent(event));
    }
    manager.finalize();
}

void QmlProfilerAnimationsModelTest::testRowMaxValue()
{
    QCOMPARE(model.rowMaxValue(0), 0);
    QCOMPARE(model.rowMaxValue(1), 9);
    QCOMPARE(model.rowMaxValue(2), 8);
}

void QmlProfilerAnimationsModelTest::testRowNumbers()
{
    for (int i = 0; i < 10; ++i) {
        QCOMPARE(model.expandedRow(i), (i % 2) ? 2 : 1);
        QCOMPARE(model.collapsedRow(i), model.expandedRow(i));
    }
}

void QmlProfilerAnimationsModelTest::testTypeId()
{
    for (int i = 0; i < 10; ++i)
        QCOMPARE(model.typeId(i), 0);
}

void QmlProfilerAnimationsModelTest::testColor()
{
    QColor last = QColor::fromHsl(0, 0, 0);
    for (int i = 0; i < 10; ++i) {
        QColor next = model.color(i);
        QVERIFY(next.hue() > last.hue());
        last = next;
    }
}

void QmlProfilerAnimationsModelTest::testRelativeHeight()
{
    float last = 1;
    for (int i = 0; i < 10; ++i) {
        float next = model.relativeHeight(i);
        QVERIFY(next <= last);
        last = next;
    }
}

void QmlProfilerAnimationsModelTest::testLabels()
{
    QVariantList labels = model.labels();
    QCOMPARE(labels.length(), 2);

    QVariantMap label0 = labels[0].toMap();
    QCOMPARE(label0["displayName"].toString(), Tr::tr("Animations"));
    QCOMPARE(label0["description"].toString(), Tr::tr("GUI Thread"));
    QCOMPARE(label0["id"].toInt(), static_cast<int>(GuiThread));

    QVariantMap label1 = labels[1].toMap();
    QCOMPARE(label1["displayName"].toString(), Tr::tr("Animations"));
    QCOMPARE(label1["description"].toString(), Tr::tr("Render Thread"));
    QCOMPARE(label1["id"].toInt(), static_cast<int>(RenderThread));
}

void QmlProfilerAnimationsModelTest::testDetails()
{
    for (int i = 0; i < 10; ++i) {
        QVariantMap details = model.details(i);
        QCOMPARE(details["displayName"].toString(), model.displayName());
        QCOMPARE(details[Tr::tr("Duration")].toString(),
                Timeline::formatTime(1));
        QCOMPARE(details[Tr::tr("Framerate")].toString(),
                QString::fromLatin1("%1 FPS").arg(frameRate(i)));
        QCOMPARE(details[Tr::tr("Animations")].toString(),
                QString::number(9 - i));
        QCOMPARE(details[Tr::tr("Context")].toString(), i % 2 ?
                    Tr::tr("Render Thread") :
                    Tr::tr("GUI Thread"));
    }
}

void QmlProfilerAnimationsModelTest::cleanupTestCase()
{
    model.clear();
    QCOMPARE(model.count(), 0);
    QCOMPARE(model.expandedRowCount(), 1);
    QCOMPARE(model.collapsedRowCount(), 1);
}

} // namespace Internal
} // namespace QmlProfiler