Commit 13910a11 authored by Ulf Hermann's avatar Ulf Hermann

QmlProfiler: Accept unknown input events

We might get more event types in the future and filtering them is harder
than just displaying them. Also, traces might contain invalid input
events which would trigger the assert.

Change-Id: I9b38422af953ebb65363fc2b7a91facb7f757976
Reviewed-by: default avatarMilian Wolff <milian.wolff@kdab.com>
parent cacb6b17
......@@ -126,7 +126,7 @@ QVariantMap InputEventsModel::details(int index) const
type = tr("Mouse Event");
break;
default:
Q_UNREACHABLE();
type = tr("Unknown");
break;
}
......
......@@ -32,6 +32,11 @@
namespace QmlProfiler {
namespace Internal {
static InputEventType inputType(int i)
{
return static_cast<InputEventType>(i % (MaximumInputEventType + 1));
}
InputEventsModelTest::InputEventsModelTest(QObject *parent) :
QObject(parent), manager(nullptr), model(&manager)
{
......@@ -48,13 +53,14 @@ void InputEventsModelTest::initTestCase()
for (int i = 0; i < 10; ++i) {
event.setTimestamp(i);
InputEventType type = static_cast<InputEventType>(i % MaximumInputEventType);
InputEventType type = inputType(i);
event.setTypeIndex(type <= InputKeyUnknown ? keyTypeId : mouseTypeId);
event.setNumbers({static_cast<qint32>(type),
(i * 32) % 256,
static_cast<qint32>((i * 0x02000000) & Qt::KeyboardModifierMask)});
manager.addEvent(event);
}
manager.acquiringDone();
QCOMPARE(manager.state(), QmlProfilerModelManager::Done);
}
......@@ -71,7 +77,7 @@ void InputEventsModelTest::testAccepted()
void InputEventsModelTest::testTypeId()
{
for (int i = 0; i < 10; ++i) {
InputEventType type = static_cast<InputEventType>(i % MaximumInputEventType);
InputEventType type = inputType(i);
QCOMPARE(model.typeId(i), type <= InputKeyUnknown ? keyTypeId : mouseTypeId);
}
}
......@@ -81,7 +87,7 @@ void InputEventsModelTest::testColor()
QRgb keyColor = 0;
QRgb mouseColor = 0;
for (int i = 0; i < 10; ++i) {
InputEventType type = static_cast<InputEventType>(i % MaximumInputEventType);
InputEventType type = inputType(i);
int selectionId = (type <= InputKeyUnknown ? Key : Mouse);
QCOMPARE(selectionId, model.selectionId(i));
......@@ -112,7 +118,7 @@ void InputEventsModelTest::testDetails()
QCOMPARE(details[model.tr("Timestamp")].toString(), Timeline::formatTime(i));
QString displayName = details[QString("displayName")].toString();
QVERIFY(!displayName.isEmpty());
switch (static_cast<InputEventType>(i % MaximumInputEventType)) {
switch (inputType(i)) {
case InputKeyPress:
QCOMPARE(displayName, model.tr("Key Press"));
if (i == 0) {
......@@ -177,7 +183,7 @@ void InputEventsModelTest::testDetails()
QVERIFY(!details.contains(model.tr("Result")));
break;
default:
Q_UNREACHABLE();
QCOMPARE(displayName, model.tr("Unknown"));
break;
}
}
......@@ -186,7 +192,7 @@ void InputEventsModelTest::testDetails()
void InputEventsModelTest::testExpandedRow()
{
for (int i = 0; i < 10; ++i) {
InputEventType type = static_cast<InputEventType>(i % MaximumInputEventType);
InputEventType type = inputType(i);
QCOMPARE(model.expandedRow(i), (type <= InputKeyUnknown ? 2 : 1));
}
}
......
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