forked from qt-creator/qt-creator
QmlProfiler: Add test for animations model
Change-Id: I0227d9c97b2b61d68ae5ed9e3f2f7e3776075338 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -89,6 +89,7 @@ QtcPlugin {
|
|||||||
"qmleventlocation_test.cpp", "qmleventlocation_test.h",
|
"qmleventlocation_test.cpp", "qmleventlocation_test.h",
|
||||||
"qmleventtype_test.cpp", "qmleventtype_test.h",
|
"qmleventtype_test.cpp", "qmleventtype_test.h",
|
||||||
"qmlnote_test.cpp", "qmlnote_test.h",
|
"qmlnote_test.cpp", "qmlnote_test.h",
|
||||||
|
"qmlprofileranimationsmodel_test.cpp", "qmlprofileranimationsmodel_test.h",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -160,17 +160,17 @@ QVariantList QmlProfilerAnimationsModel::labels() const
|
|||||||
|
|
||||||
if (m_maxGuiThreadAnimations > 0) {
|
if (m_maxGuiThreadAnimations > 0) {
|
||||||
QVariantMap element;
|
QVariantMap element;
|
||||||
element.insert(QLatin1String("displayName"), QVariant(tr("Animations")));
|
element.insert(QLatin1String("displayName"), tr("Animations"));
|
||||||
element.insert(QLatin1String("description"), QVariant(tr("GUI Thread")));
|
element.insert(QLatin1String("description"), tr("GUI Thread"));
|
||||||
element.insert(QLatin1String("id"), QVariant(GuiThread));
|
element.insert(QLatin1String("id"), GuiThread);
|
||||||
result << element;
|
result << element;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_maxRenderThreadAnimations > 0) {
|
if (m_maxRenderThreadAnimations > 0) {
|
||||||
QVariantMap element;
|
QVariantMap element;
|
||||||
element.insert(QLatin1String("displayName"), QVariant(tr("Animations")));
|
element.insert(QLatin1String("displayName"), tr("Animations"));
|
||||||
element.insert(QLatin1String("description"), QVariant(tr("Render Thread")));
|
element.insert(QLatin1String("description"), tr("Render Thread"));
|
||||||
element.insert(QLatin1String("id"), QVariant(RenderThread));
|
element.insert(QLatin1String("id"), RenderThread);
|
||||||
result << element;
|
result << element;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,9 +184,9 @@ QVariantMap QmlProfilerAnimationsModel::details(int index) const
|
|||||||
result.insert(QStringLiteral("displayName"), displayName());
|
result.insert(QStringLiteral("displayName"), displayName());
|
||||||
result.insert(tr("Duration"), QmlProfilerDataModel::formatTime(duration(index)));
|
result.insert(tr("Duration"), QmlProfilerDataModel::formatTime(duration(index)));
|
||||||
result.insert(tr("Framerate"), QString::fromLatin1("%1 FPS").arg(m_data[index].framerate));
|
result.insert(tr("Framerate"), QString::fromLatin1("%1 FPS").arg(m_data[index].framerate));
|
||||||
result.insert(tr("Animations"), QString::fromLatin1("%1").arg(m_data[index].animationcount));
|
result.insert(tr("Animations"), QString::number(m_data[index].animationcount));
|
||||||
result.insert(tr("Context"), tr(selectionId(index) == GuiThread ? "GUI Thread" :
|
result.insert(tr("Context"), selectionId(index) == GuiThread ? tr("GUI Thread") :
|
||||||
"Render Thread"));
|
tr("Render Thread"));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ public:
|
|||||||
QVariantList labels() const override;
|
QVariantList labels() const override;
|
||||||
QVariantMap details(int index) const override;
|
QVariantMap details(int index) const override;
|
||||||
|
|
||||||
protected:
|
|
||||||
bool accepted(const QmlEventType &type) const override;
|
bool accepted(const QmlEventType &type) const override;
|
||||||
void loadEvent(const QmlEvent &event, const QmlEventType &type) override;
|
void loadEvent(const QmlEvent &event, const QmlEventType &type) override;
|
||||||
void finalize() override;
|
void finalize() override;
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
#include "tests/qmleventlocation_test.h"
|
#include "tests/qmleventlocation_test.h"
|
||||||
#include "tests/qmleventtype_test.h"
|
#include "tests/qmleventtype_test.h"
|
||||||
#include "tests/qmlnote_test.h"
|
#include "tests/qmlnote_test.h"
|
||||||
|
#include "tests/qmlprofileranimationsmodel_test.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
@@ -101,6 +102,7 @@ QList<QObject *> QmlProfiler::Internal::QmlProfilerPlugin::createTestObjects() c
|
|||||||
tests << new QmlEventLocationTest;
|
tests << new QmlEventLocationTest;
|
||||||
tests << new QmlEventTypeTest;
|
tests << new QmlEventTypeTest;
|
||||||
tests << new QmlNoteTest;
|
tests << new QmlNoteTest;
|
||||||
|
tests << new QmlProfilerAnimationsModelTest;
|
||||||
#endif
|
#endif
|
||||||
return tests;
|
return tests;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,150 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 "qmlprofileranimationsmodel_test.h"
|
||||||
|
#include <QtTest>
|
||||||
|
|
||||||
|
namespace QmlProfiler {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
QmlProfilerAnimationsModelTest::QmlProfilerAnimationsModelTest(QObject *parent) :
|
||||||
|
QObject(parent), manager(nullptr), model(&manager)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static int frameRate(int i)
|
||||||
|
{
|
||||||
|
return i * 7 - 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlProfilerAnimationsModelTest::initTestCase()
|
||||||
|
{
|
||||||
|
manager.startAcquiring();
|
||||||
|
|
||||||
|
QmlEventType type(Event, MaximumRangeType, AnimationFrame);
|
||||||
|
QmlEvent event;
|
||||||
|
event.setTypeIndex(manager.qmlModel()->addEventType(type));
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
event.setTimestamp(i);
|
||||||
|
event.setNumbers<int>({frameRate(i), 20 - i, (i % 2) ? RenderThread : GuiThread});
|
||||||
|
manager.qmlModel()->addEvent(event);
|
||||||
|
}
|
||||||
|
manager.acquiringDone();
|
||||||
|
QCOMPARE(manager.state(), QmlProfilerModelManager::Done);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlProfilerAnimationsModelTest::testAccepted()
|
||||||
|
{
|
||||||
|
QVERIFY(!model.accepted(QmlEventType()));
|
||||||
|
QVERIFY(!model.accepted(QmlEventType(Event)));
|
||||||
|
QVERIFY(!model.accepted(QmlEventType(Event, MaximumRangeType)));
|
||||||
|
QVERIFY(model.accepted(QmlEventType(Event, MaximumRangeType, AnimationFrame)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlProfilerAnimationsModelTest::testRowMaxValue()
|
||||||
|
{
|
||||||
|
QCOMPARE(model.rowMaxValue(0), 0);
|
||||||
|
QCOMPARE(model.rowMaxValue(1), 20);
|
||||||
|
QCOMPARE(model.rowMaxValue(2), 19);
|
||||||
|
}
|
||||||
|
|
||||||
|
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(), QmlProfilerAnimationsModel::tr("Animations"));
|
||||||
|
QCOMPARE(label0["description"].toString(), QmlProfilerAnimationsModel::tr("GUI Thread"));
|
||||||
|
QCOMPARE(label0["id"].toInt(), static_cast<int>(GuiThread));
|
||||||
|
|
||||||
|
QVariantMap label1 = labels[1].toMap();
|
||||||
|
QCOMPARE(label1["displayName"].toString(), QmlProfilerAnimationsModel::tr("Animations"));
|
||||||
|
QCOMPARE(label1["description"].toString(), QmlProfilerAnimationsModel::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[QmlProfilerAnimationsModel::tr("Duration")].toString(),
|
||||||
|
QmlProfilerDataModel::formatTime(1));
|
||||||
|
QCOMPARE(details[QmlProfilerAnimationsModel::tr("Framerate")].toString(),
|
||||||
|
QString::fromLatin1("%1 FPS").arg(frameRate(i)));
|
||||||
|
QCOMPARE(details[QmlProfilerAnimationsModel::tr("Animations")].toString(),
|
||||||
|
QString::number(20 - i));
|
||||||
|
QCOMPARE(details[QmlProfilerAnimationsModel::tr("Context")].toString(), i % 2 ?
|
||||||
|
QmlProfilerAnimationsModel::tr("Render Thread") :
|
||||||
|
QmlProfilerAnimationsModel::tr("GUI Thread"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlProfilerAnimationsModelTest::cleanupTestCase()
|
||||||
|
{
|
||||||
|
model.clear();
|
||||||
|
QCOMPARE(model.count(), 0);
|
||||||
|
QCOMPARE(model.expandedRowCount(), 1);
|
||||||
|
QCOMPARE(model.collapsedRowCount(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace QmlProfiler
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 <qmlprofiler/qmlprofileranimationsmodel.h>
|
||||||
|
#include <qmlprofiler/qmlprofilermodelmanager.h>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
namespace QmlProfiler {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
class QmlProfilerAnimationsModelTest : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit QmlProfilerAnimationsModelTest(QObject *parent = 0);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void initTestCase();
|
||||||
|
void testAccepted();
|
||||||
|
void testRowMaxValue();
|
||||||
|
void testRowNumbers();
|
||||||
|
void testTypeId();
|
||||||
|
void testColor();
|
||||||
|
void testRelativeHeight();
|
||||||
|
void testLabels();
|
||||||
|
void testDetails();
|
||||||
|
void cleanupTestCase();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QmlProfilerModelManager manager;
|
||||||
|
QmlProfilerAnimationsModel model;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace QmlProfiler
|
||||||
@@ -10,7 +10,8 @@ SOURCES += \
|
|||||||
$$PWD/qmlevent_test.cpp \
|
$$PWD/qmlevent_test.cpp \
|
||||||
$$PWD/qmleventlocation_test.cpp \
|
$$PWD/qmleventlocation_test.cpp \
|
||||||
$$PWD/qmleventtype_test.cpp \
|
$$PWD/qmleventtype_test.cpp \
|
||||||
$$PWD/qmlnote_test.cpp
|
$$PWD/qmlnote_test.cpp \
|
||||||
|
$$PWD/qmlprofileranimationsmodel_test.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$PWD/debugmessagesmodel_test.h \
|
$$PWD/debugmessagesmodel_test.h \
|
||||||
@@ -24,4 +25,5 @@ HEADERS += \
|
|||||||
$$PWD/qmlevent_test.h \
|
$$PWD/qmlevent_test.h \
|
||||||
$$PWD/qmleventlocation_test.h \
|
$$PWD/qmleventlocation_test.h \
|
||||||
$$PWD/qmleventtype_test.h \
|
$$PWD/qmleventtype_test.h \
|
||||||
$$PWD/qmlnote_test.h
|
$$PWD/qmlnote_test.h \
|
||||||
|
$$PWD/qmlprofileranimationsmodel_test.h
|
||||||
|
|||||||
Reference in New Issue
Block a user