From 13910a1176bd8f2385e36d7b7e9f34286d7235e5 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 8 Sep 2017 17:18:39 +0200 Subject: [PATCH] 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: Milian Wolff --- src/plugins/qmlprofiler/inputeventsmodel.cpp | 2 +- .../tests/inputeventsmodel_test.cpp | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/plugins/qmlprofiler/inputeventsmodel.cpp b/src/plugins/qmlprofiler/inputeventsmodel.cpp index 0c7e9b50fc8..2c8be86fe43 100644 --- a/src/plugins/qmlprofiler/inputeventsmodel.cpp +++ b/src/plugins/qmlprofiler/inputeventsmodel.cpp @@ -126,7 +126,7 @@ QVariantMap InputEventsModel::details(int index) const type = tr("Mouse Event"); break; default: - Q_UNREACHABLE(); + type = tr("Unknown"); break; } diff --git a/src/plugins/qmlprofiler/tests/inputeventsmodel_test.cpp b/src/plugins/qmlprofiler/tests/inputeventsmodel_test.cpp index 781a14d4e9b..0d24d359ace 100644 --- a/src/plugins/qmlprofiler/tests/inputeventsmodel_test.cpp +++ b/src/plugins/qmlprofiler/tests/inputeventsmodel_test.cpp @@ -32,6 +32,11 @@ namespace QmlProfiler { namespace Internal { +static InputEventType inputType(int i) +{ + return static_cast(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(i % MaximumInputEventType); + InputEventType type = inputType(i); event.setTypeIndex(type <= InputKeyUnknown ? keyTypeId : mouseTypeId); event.setNumbers({static_cast(type), (i * 32) % 256, static_cast((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(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(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(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(i % MaximumInputEventType); + InputEventType type = inputType(i); QCOMPARE(model.expandedRow(i), (type <= InputKeyUnknown ? 2 : 1)); } }