Commit bae8f22a authored by Ulf Hermann's avatar Ulf Hermann

QmlProfiler: Add test for input events model

Change-Id: I5af5c090312173cdfdb01f88923bfde1667e799b
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@theqtcompany.com>
parent d345755b
......@@ -81,6 +81,7 @@ QtcPlugin {
"flamegraph_test.cpp", "flamegraph_test.h",
"flamegraphmodel_test.cpp", "flamegraphmodel_test.h",
"flamegraphview_test.cpp", "flamegraphview_test.h",
"inputeventsmodel_test.cpp", "inputeventsmodel_test.h",
]
}
}
......@@ -34,6 +34,7 @@
#include "tests/flamegraph_test.h"
#include "tests/flamegraphmodel_test.h"
#include "tests/flamegraphview_test.h"
#include "tests/inputeventsmodel_test.h"
#endif
#include <extensionsystem/pluginmanager.h>
......@@ -87,6 +88,7 @@ QList<QObject *> QmlProfiler::Internal::QmlProfilerPlugin::createTestObjects() c
tests << new FlameGraphTest;
tests << new FlameGraphModelTest;
tests << new FlameGraphViewTest;
tests << new InputEventsModelTest;
#endif
return tests;
}
......
/****************************************************************************
**
** 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 "inputeventsmodel_test.h"
#include "timeline/timelinemodel_p.h"
#include <QtTest>
namespace QmlProfiler {
namespace Internal {
InputEventsModelTest::InputEventsModelTest(QObject *parent) :
QObject(parent), manager(nullptr), model(&manager)
{
QmlEventType type;
type.message = Event;
type.rangeType = MaximumRangeType;
type.detailType = Key;
keyTypeId = manager.qmlModel()->addEventType(type);
type.detailType = Mouse;
mouseTypeId = manager.qmlModel()->addEventType(type);
}
void InputEventsModelTest::initTestCase()
{
manager.startAcquiring();
QmlEvent event;
for (int i = 0; i < 10; ++i) {
event.setTimestamp(i);
InputEventType type = static_cast<InputEventType>(i % MaximumInputEventType);
event.setTypeIndex(type <= InputKeyUnknown ? keyTypeId : mouseTypeId);
event.setNumbers({static_cast<qint32>(type),
(i * 32) % 256,
static_cast<qint32>((i * 0x02000000) & Qt::KeyboardModifierMask)});
manager.qmlModel()->addEvent(event);
}
manager.acquiringDone();
QCOMPARE(manager.state(), QmlProfilerModelManager::Done);
}
void InputEventsModelTest::testAccepted()
{
QmlEventType type;
QVERIFY(!model.accepted(type));
type.message = Event;
QVERIFY(!model.accepted(type));
type.rangeType = MaximumRangeType;
QVERIFY(!model.accepted(type));
type.detailType = Key;
QVERIFY(model.accepted(type));
type.detailType = Mouse;
QVERIFY(model.accepted(type));
}
void InputEventsModelTest::testTypeId()
{
for (int i = 0; i < 10; ++i) {
InputEventType type = static_cast<InputEventType>(i % MaximumInputEventType);
QCOMPARE(model.typeId(i), type <= InputKeyUnknown ? keyTypeId : mouseTypeId);
}
}
void InputEventsModelTest::testColor()
{
QColor keyColor;
QColor mouseColor;
for (int i = 0; i < 10; ++i) {
InputEventType type = static_cast<InputEventType>(i % MaximumInputEventType);
int selectionId = (type <= InputKeyUnknown ? Key : Mouse);
QCOMPARE(selectionId, model.selectionId(i));
QColor &expectedColor = selectionId == Key ? keyColor : mouseColor;
if (expectedColor.isValid())
QCOMPARE(model.color(i), expectedColor);
else
expectedColor = model.color(i);
}
}
void InputEventsModelTest::testLabels()
{
QVariantList labels = model.labels();
QVariantMap mouseLabel = labels[0].toMap();
QCOMPARE(mouseLabel[QString("description")].toString(), model.tr("Mouse Events"));
QCOMPARE(mouseLabel[QString("id")].toInt(), static_cast<int>(Mouse));
QVariantMap keyLabel = labels[1].toMap();
QCOMPARE(keyLabel[QString("description")].toString(), model.tr("Keyboard Events"));
QCOMPARE(keyLabel[QString("id")].toInt(), static_cast<int>(Key));
}
void InputEventsModelTest::testDetails()
{
for (int i = 0; i < 10; ++i) {
const QVariantMap details = model.details(i);
QCOMPARE(details[model.tr("Timestamp")].toString(), QmlProfilerDataModel::formatTime(i));
QString displayName = details[QString("displayName")].toString();
QVERIFY(!displayName.isEmpty());
switch (static_cast<InputEventType>(i % MaximumInputEventType)) {
case InputKeyPress:
QCOMPARE(displayName, model.tr("Key Press"));
if (i == 0) {
// all the numbers are 0 here, so no other members
QVERIFY(!details.contains(model.tr("Key")));
QVERIFY(!details.contains(model.tr("Modifiers")));
} else {
QCOMPARE(details[model.tr("Key")].toString(), QString("Key_Space"));
QCOMPARE(details[model.tr("Modifiers")].toString(),
QString("ShiftModifier|MetaModifier"));
}
break;
case InputKeyRelease:
QCOMPARE(displayName, model.tr("Key Release"));
QCOMPARE(details[model.tr("Modifiers")].toString(), QString("ShiftModifier"));
QCOMPARE(details[model.tr("Key")].toString(), QString("Key_Space"));
break;
case InputKeyUnknown:
QCOMPARE(displayName, model.tr("Keyboard Event"));
QVERIFY(!details.contains(model.tr("Key")));
QVERIFY(!details.contains(model.tr("Modifiers")));
break;
case InputMousePress:
QCOMPARE(displayName, model.tr("Mouse Press"));
// 0x60 is not a valid mouse button
QVERIFY(details.contains(model.tr("Button")));
QVERIFY(details[model.tr("Button")].toString().isEmpty());
QCOMPARE(details[model.tr("Result")].toString(),
QString("ExtraButton23|MaxMouseButton"));
break;
case InputMouseRelease:
QCOMPARE(displayName, model.tr("Mouse Release"));
QCOMPARE(details[model.tr("Button")].toString(), QString("ExtraButton5"));
QVERIFY(details.contains(model.tr("Result")));
QVERIFY(details[model.tr("Result")].toString().isEmpty());
break;
case InputMouseMove:
QCOMPARE(displayName, model.tr("Mouse Move"));
QCOMPARE(details[model.tr("X")].toString(), QString("160"));
QCOMPARE(details[model.tr("Y")].toString(), QString("167772160"));
break;
case InputMouseDoubleClick:
QCOMPARE(displayName, model.tr("Double Click"));
QVERIFY(details.contains(model.tr("Button")));
QVERIFY(details[model.tr("Button")].toString().isEmpty());
QCOMPARE(details[model.tr("Result")].toString(), QString("MaxMouseButton"));
break;
case InputMouseWheel:
QCOMPARE(displayName, model.tr("Mouse Wheel"));
QCOMPARE(details[model.tr("Angle X")].toString(), QString("224"));
QCOMPARE(details[model.tr("Angle Y")].toString(), QString("234881024"));
break;
case InputMouseUnknown:
QCOMPARE(displayName, model.tr("Mouse Event"));
QVERIFY(!details.contains(model.tr("X")));
QVERIFY(!details.contains(model.tr("Y")));
QVERIFY(!details.contains(model.tr("Angle X")));
QVERIFY(!details.contains(model.tr("Angle Y")));
QVERIFY(!details.contains(model.tr("Button")));
QVERIFY(!details.contains(model.tr("Result")));
break;
default:
Q_UNREACHABLE();
break;
}
}
}
void InputEventsModelTest::testExpandedRow()
{
for (int i = 0; i < 10; ++i) {
InputEventType type = static_cast<InputEventType>(i % MaximumInputEventType);
QCOMPARE(model.expandedRow(i), (type <= InputKeyUnknown ? 2 : 1));
}
}
void InputEventsModelTest::testCollapsedRow()
{
for (int i = 0; i < 10; ++i)
QCOMPARE(model.collapsedRow(i), 1);
}
void InputEventsModelTest::cleanupTestCase()
{
model.clear();
QCOMPARE(model.count(), 0);
QCOMPARE(model.expandedRowCount(), 1);
QCOMPARE(model.collapsedRowCount(), 1);
}
} // namespace Internal
} // namespace QmlProfiler
/****************************************************************************
**
** 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/inputeventsmodel.h>
#include <qmlprofiler/qmlprofilermodelmanager.h>
#include <QObject>
namespace QmlProfiler {
namespace Internal {
class InputEventsModelTest : public QObject
{
Q_OBJECT
public:
InputEventsModelTest(QObject *parent = 0);
private slots:
void initTestCase();
void testAccepted();
void testTypeId();
void testColor();
void testLabels();
void testDetails();
void testExpandedRow();
void testCollapsedRow();
void cleanupTestCase();
private:
QmlProfilerModelManager manager;
InputEventsModel model;
int mouseTypeId = -1;
int keyTypeId = -1;
};
} // namespace Internal
} // namespace QmlProfiler
......@@ -2,10 +2,12 @@ SOURCES += \
$$PWD/debugmessagesmodel_test.cpp \
$$PWD/flamegraph_test.cpp \
$$PWD/flamegraphmodel_test.cpp \
$$PWD/flamegraphview_test.cpp
$$PWD/flamegraphview_test.cpp \
$$PWD/inputeventsmodel_test.cpp
HEADERS += \
$$PWD/debugmessagesmodel_test.h \
$$PWD/flamegraph_test.h \
$$PWD/flamegraphmodel_test.h \
$$PWD/flamegraphview_test.h
$$PWD/flamegraphview_test.h \
$$PWD/inputeventsmodel_test.h
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment