aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmlprofiler/tests
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2016-06-06 19:54:54 +0200
committerUlf Hermann <ulf.hermann@qt.io>2016-06-10 12:43:14 +0000
commitf9dcf289216e26c81a4f16fe160ef38f2018b83f (patch)
tree5f561438d43078e2ccd57d0700bc2a6ab00b9254 /src/plugins/qmlprofiler/tests
parent69832a22d3824368bb6954bed09b9e51f83ecbba (diff)
QmlProfiler: Add tests for QmlEventType
Change-Id: Id2ee8250c0e89637733a1454de4a60df42612904 Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
Diffstat (limited to 'src/plugins/qmlprofiler/tests')
-rw-r--r--src/plugins/qmlprofiler/tests/qmleventtype_test.cpp141
-rw-r--r--src/plugins/qmlprofiler/tests/qmleventtype_test.h45
-rw-r--r--src/plugins/qmlprofiler/tests/tests.pri6
3 files changed, 190 insertions, 2 deletions
diff --git a/src/plugins/qmlprofiler/tests/qmleventtype_test.cpp b/src/plugins/qmlprofiler/tests/qmleventtype_test.cpp
new file mode 100644
index 00000000000..cfb34797654
--- /dev/null
+++ b/src/plugins/qmlprofiler/tests/qmleventtype_test.cpp
@@ -0,0 +1,141 @@
+/****************************************************************************
+**
+** 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 "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(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(type2.feature(), ProfileJavaScript);
+}
+
+void QmlEventTypeTest::testFeature()
+{
+ const ProfileFeature 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 }
+ };
+
+ 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(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 != type2);
+ rstream >> type2;
+
+ QCOMPARE(type2, type);
+}
+
+} // namespace Internal
+} // namespace QmlProfiler
diff --git a/src/plugins/qmlprofiler/tests/qmleventtype_test.h b/src/plugins/qmlprofiler/tests/qmleventtype_test.h
new file mode 100644
index 00000000000..f616eb05de9
--- /dev/null
+++ b/src/plugins/qmlprofiler/tests/qmleventtype_test.h
@@ -0,0 +1,45 @@
+/****************************************************************************
+**
+** 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.
+**
+****************************************************************************/
+#pragma once
+
+#include <QObject>
+
+namespace QmlProfiler {
+namespace Internal {
+
+class QmlEventTypeTest : public QObject
+{
+ Q_OBJECT
+public:
+ explicit QmlEventTypeTest(QObject *parent = 0);
+
+private slots:
+ void testAccessors();
+ void testFeature();
+ void testStreamOps();
+};
+
+} // namespace Internal
+} // namespace QmlProfiler
diff --git a/src/plugins/qmlprofiler/tests/tests.pri b/src/plugins/qmlprofiler/tests/tests.pri
index 6f938f8f81c..ca3fae33446 100644
--- a/src/plugins/qmlprofiler/tests/tests.pri
+++ b/src/plugins/qmlprofiler/tests/tests.pri
@@ -8,7 +8,8 @@ SOURCES += \
$$PWD/memoryusagemodel_test.cpp \
$$PWD/pixmapcachemodel_test.cpp \
$$PWD/qmlevent_test.cpp \
- $$PWD/qmleventlocation_test.cpp
+ $$PWD/qmleventlocation_test.cpp \
+ $$PWD/qmleventtype_test.cpp
HEADERS += \
$$PWD/debugmessagesmodel_test.h \
@@ -20,4 +21,5 @@ HEADERS += \
$$PWD/memoryusagemodel_test.h \
$$PWD/pixmapcachemodel_test.h \
$$PWD/qmlevent_test.h \
- $$PWD/qmleventlocation_test.h
+ $$PWD/qmleventlocation_test.h \
+ $$PWD/qmleventtype_test.h