diff --git a/src/plugins/qmlprofiler/qmlprofiler.qbs b/src/plugins/qmlprofiler/qmlprofiler.qbs index c37f6b7828c..de95c238568 100644 --- a/src/plugins/qmlprofiler/qmlprofiler.qbs +++ b/src/plugins/qmlprofiler/qmlprofiler.qbs @@ -87,6 +87,7 @@ QtcPlugin { "pixmapcachemodel_test.cpp", "pixmapcachemodel_test.h", "qmlevent_test.cpp", "qmlevent_test.h", "qmleventlocation_test.cpp", "qmleventlocation_test.h", + "qmleventtype_test.cpp", "qmleventtype_test.h", ] } } diff --git a/src/plugins/qmlprofiler/qmlprofilerplugin.cpp b/src/plugins/qmlprofiler/qmlprofilerplugin.cpp index 8bfc8c05d98..872cb1fb977 100644 --- a/src/plugins/qmlprofiler/qmlprofilerplugin.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerplugin.cpp @@ -40,6 +40,7 @@ #include "tests/pixmapcachemodel_test.h" #include "tests/qmlevent_test.h" #include "tests/qmleventlocation_test.h" +#include "tests/qmleventtype_test.h" #endif #include @@ -97,6 +98,7 @@ QList QmlProfiler::Internal::QmlProfilerPlugin::createTestObjects() c tests << new PixmapCacheModelTest; tests << new QmlEventTest; tests << new QmlEventLocationTest; + tests << new QmlEventTypeTest; #endif return tests; } 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 + +#include + +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(i), MaximumRangeType, j); + QCOMPARE(type.feature(), features[i][j]); + } + } + + for (int i = 0; i < MaximumRangeType; ++i) { + QmlEventType type(MaximumMessage, static_cast(i)); + QCOMPARE(type.feature(), featureFromRangeType(static_cast(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 + +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