aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmlprofiler/tests/qmleventtype_test.cpp
blob: 3c70fe4d8ebc3acb422ed180d905a8647d82ae3b (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
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#include "qmleventtype_test.h"
#include <qmlprofiler/qmleventtype.h>

#include <QtTest>

namespace QmlProfiler {
namespace Internal {

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

void QmlEventTypeTest::testAccessors()
{
    QmlEventType type;
    QCOMPARE(type.message(), MaximumMessage);
    QCOMPARE(type.rangeType(), MaximumRangeType);
    QCOMPARE(type.detailType(), -1);
    QVERIFY(!type.location().isValid());
    QVERIFY(type.data().isEmpty());
    QVERIFY(type.displayName().isEmpty());
    QCOMPARE(static_cast<ProfileFeature>(type.feature()), MaximumProfileFeature);

    type.setLocation(QmlEventLocation("blah.js", 12, 13));
    QCOMPARE(type.location().filename(), QString("blah.js"));
    QCOMPARE(type.location().line(), 12);
    QCOMPARE(type.location().column(), 13);

    type.setData("dadada");
    QCOMPARE(type.data(), QString("dadada"));

    type.setDisplayName("disdis");
    QCOMPARE(type.displayName(), QString("disdis"));

    QmlEventType type2(MaximumMessage, Javascript, 12, QmlEventLocation("lala.js", 2, 3), "nehhh",
                       "brbr");
    QCOMPARE(type2.message(), MaximumMessage);
    QCOMPARE(type2.rangeType(), Javascript);
    QCOMPARE(type2.detailType(), 12);
    QCOMPARE(type2.location(), QmlEventLocation("lala.js", 2, 3));
    QCOMPARE(type2.data(), QString("nehhh"));
    QCOMPARE(type2.displayName(), QString("brbr"));
    QCOMPARE(static_cast<ProfileFeature>(type2.feature()), ProfileJavaScript);
}

void QmlEventTypeTest::testFeature()
{
    const quint8 features[][MaximumEventType] = {
        // Event
        {MaximumProfileFeature, ProfileInputEvents, ProfileInputEvents,
         ProfileAnimations, MaximumProfileFeature, MaximumProfileFeature},
        // RangeStart
        {MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature,
         MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature},
        // RangeData
        {MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature,
         MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature},
        // RangeLocation
        {MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature,
         MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature},
        // RangeEnd
        {MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature,
         MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature},
        // Complete
        {MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature,
         MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature},
        // PixmapCacheEvent
        {ProfilePixmapCache, ProfilePixmapCache, ProfilePixmapCache,
         ProfilePixmapCache, ProfilePixmapCache, ProfilePixmapCache},
        // SceneGraphFrame
        {ProfileSceneGraph, ProfileSceneGraph, ProfileSceneGraph,
         ProfileSceneGraph, ProfileSceneGraph, ProfileSceneGraph},
        // MemoryAllocation
        {ProfileMemory, ProfileMemory, ProfileMemory,
         ProfileMemory, ProfileMemory, ProfileMemory},
        // DebugMessage
        {ProfileDebugMessages, ProfileDebugMessages, ProfileDebugMessages,
         ProfileDebugMessages, ProfileDebugMessages, ProfileDebugMessages},
        // ProfileQuick3D
        {ProfileQuick3D, ProfileQuick3D, ProfileQuick3D,
         ProfileQuick3D, ProfileQuick3D, ProfileQuick3D}
    };

    for (int i = 0; i < MaximumMessage; ++i) {
        for (int j = 0; j < MaximumEventType; ++j) {
            QmlEventType type(static_cast<Message>(i), MaximumRangeType, j);
            QCOMPARE(type.feature(), features[i][j]);
        }
    }

    for (int i = 0; i < MaximumRangeType; ++i) {
        QmlEventType type(MaximumMessage, static_cast<RangeType>(i));
        QCOMPARE(static_cast<ProfileFeature>(type.feature()),
                 featureFromRangeType(static_cast<RangeType>(i)));
    }
}

void QmlEventTypeTest::testStreamOps()
{
    QmlEventType type(MaximumMessage, Javascript, -1, QmlEventLocation("socken.js", 12, 13),
                      "lalala", "lelele");

    QBuffer wbuffer;
    wbuffer.open(QIODevice::WriteOnly);
    QDataStream wstream(&wbuffer);
    wstream << type;

    QBuffer rbuffer;
    rbuffer.setData(wbuffer.data());
    rbuffer.open(QIODevice::ReadOnly);
    QDataStream rstream(&rbuffer);

    QmlEventType type2;
    QVERIFY(type.rangeType() != type2.rangeType());

    rstream >> type2;

    QCOMPARE(type.feature(), type2.feature());
    QCOMPARE(type.message(), type2.message());
    QCOMPARE(type.rangeType(), type2.rangeType());
    QCOMPARE(type.detailType(), type2.detailType());
    QCOMPARE(type.location(), type2.location());
}

} // namespace Internal
} // namespace QmlProfiler