diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2016-05-30 17:40:19 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2016-06-01 09:23:28 +0000 |
commit | 3174c36ab1fadc62e17b5793910e8f00f8350b54 (patch) | |
tree | aa4a18a98336a8e210658bb14e3a28877633aa31 /src/plugins/qmlprofiler/tests | |
parent | 12f160b1f31dfea797c3f29035f766ce90ca23c7 (diff) | |
download | qt-creator-3174c36ab1fadc62e17b5793910e8f00f8350b54.tar.gz |
QmlProfiler: Add tests for flamegraph model
Change-Id: I185d06a059314f27fe48c5c2f2b92623b6611309
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
Diffstat (limited to 'src/plugins/qmlprofiler/tests')
-rw-r--r-- | src/plugins/qmlprofiler/tests/flamegraphmodel_test.cpp | 201 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/tests/flamegraphmodel_test.h | 57 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/tests/tests.pri | 6 |
3 files changed, 262 insertions, 2 deletions
diff --git a/src/plugins/qmlprofiler/tests/flamegraphmodel_test.cpp b/src/plugins/qmlprofiler/tests/flamegraphmodel_test.cpp new file mode 100644 index 0000000000..c7b9851b2a --- /dev/null +++ b/src/plugins/qmlprofiler/tests/flamegraphmodel_test.cpp @@ -0,0 +1,201 @@ +/**************************************************************************** +** +** 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 "flamegraphmodel_test.h" + +#include <qmlprofiler/qmlprofilerrangemodel.h> + +#include <QtTest> + +namespace QmlProfiler { +namespace Internal { + +FlameGraphModelTest::FlameGraphModelTest(QObject *parent) : + QObject(parent), manager(&finder), model(&manager) +{ + // Notes only work with timeline models + QmlProfilerRangeModel *rangeModel = new QmlProfilerRangeModel(&manager, Javascript, this); + manager.notesModel()->addTimelineModel(rangeModel); +} + +void FlameGraphModelTest::initTestCase() +{ + QCOMPARE(model.modelManager(), &manager); + + manager.startAcquiring(); + QmlEvent event; + QmlEventType type; + + event.setTypeIndex(-1); + type.location.filename = QLatin1String("somefile.js"); + type.displayName.clear(); + type.data = QLatin1String("funcfunc"); + type.rangeType = MaximumRangeType; + type.detailType = -1; + type.message = MaximumMessage; + + QStack<int> typeIndices; + + int i = 0; + while (i < 10) { + int typeIndex = -1; + if (i < 5) { + type.location.line = i; + type.location.column = 20 - i; + type.rangeType = static_cast<RangeType>(static_cast<int>(Javascript) - i); + typeIndex = manager.qmlModel()->addEventType(type); + } else { + typeIndex = typeIndices[i - 5]; + } + event.setTypeIndex(typeIndex); + event.setTimestamp(++i); + event.setRangeStage(RangeStart); + manager.qmlModel()->addEvent(event); + typeIndices.push(typeIndex); + } + + event.setRangeStage(RangeEnd); + event.setTimestamp(++i); + manager.qmlModel()->addEvent(event); + + event.setRangeStage(RangeStart); + event.setTimestamp(++i); + manager.qmlModel()->addEvent(event); + + for (int j = 0; !typeIndices.isEmpty(); ++j) { + event.setTimestamp(i + j); + event.setRangeStage(RangeEnd); + event.setTypeIndex(typeIndices.pop()); + manager.qmlModel()->addEvent(event); + } + + manager.acquiringDone(); + + manager.notesModel()->setNotes(QVector<QmlNote>({QmlNote(0, 1, 20, "dings")})); + manager.notesModel()->loadData(); + + QCOMPARE(manager.state(), QmlProfilerModelManager::Done); +} + +void FlameGraphModelTest::testIndex() +{ + QModelIndex index; + QModelIndex parent = index; + for (int i = 0; i < 5; ++i) { + index = model.index(0, 0, index); + QVERIFY(index.isValid()); + QCOMPARE(model.parent(index), parent); + parent = index; + } + QVERIFY(!model.parent(QModelIndex()).isValid()); +} + +void FlameGraphModelTest::testCounts() +{ + QCOMPARE(model.rowCount(), 1); + QCOMPARE(model.rowCount(model.index(0, 0)), 1); + QCOMPARE(model.columnCount(), 1); +} + +void FlameGraphModelTest::testData() +{ + const QVector<QString> typeRoles({ + FlameGraphModel::tr("JavaScript"), + FlameGraphModel::tr("Signal"), + FlameGraphModel::tr("Binding"), + FlameGraphModel::tr("Create"), + FlameGraphModel::tr("Compile"), + }); + + QModelIndex index = model.index(0, 0); + QCOMPARE(model.data(index, FlameGraphModel::TypeIdRole).toInt(), 0); + QCOMPARE(model.data(index, FlameGraphModel::TypeRole).toString(), + FlameGraphModel::tr("JavaScript")); + QCOMPARE(model.data(index, FlameGraphModel::DurationRole).toLongLong(), 20); + QCOMPARE(model.data(index, FlameGraphModel::CallCountRole).toInt(), 1); + QCOMPARE(model.data(index, FlameGraphModel::DetailsRole).toString(), + QLatin1String("funcfunc")); + QCOMPARE(model.data(index, FlameGraphModel::FilenameRole).toString(), + QLatin1String("somefile.js")); + QCOMPARE(model.data(index, FlameGraphModel::LineRole).toInt(), 0); + QCOMPARE(model.data(index, FlameGraphModel::ColumnRole).toInt(), 20); + QCOMPARE(model.data(index, FlameGraphModel::NoteRole).toString(), QString("dings")); + QCOMPARE(model.data(index, FlameGraphModel::TimePerCallRole).toLongLong(), 20); + QCOMPARE(model.data(index, FlameGraphModel::TimeInPercentRole).toInt(), 100); + QCOMPARE(model.data(index, FlameGraphModel::RangeTypeRole).toInt(), + static_cast<int>(Javascript)); + QCOMPARE(model.data(index, FlameGraphModel::LocationRole).toString(), + QLatin1String("somefile.js:0")); + QVERIFY(!model.data(index, -10).isValid()); + QVERIFY(!model.data(QModelIndex(), FlameGraphModel::LineRole).isValid()); + + for (int i = 1; i < 10; ++i) { + index = model.index(0, 0, index); + QCOMPARE(model.data(index, FlameGraphModel::TypeRole).toString(), + typeRoles[i % typeRoles.length()]); + QCOMPARE(model.data(index, FlameGraphModel::NoteRole).toString(), + (i % typeRoles.length() == 0) ? QString("dings") : QString()); + } + QCOMPARE(model.data(index, FlameGraphModel::CallCountRole).toInt(), 2); +} + +void FlameGraphModelTest::testRoleNames() +{ + auto names = model.roleNames(); + QCOMPARE(names[FlameGraphModel::TypeIdRole], QByteArray("typeId")); + QCOMPARE(names[FlameGraphModel::TypeRole], QByteArray("type")); + QCOMPARE(names[FlameGraphModel::DurationRole], QByteArray("duration")); + QCOMPARE(names[FlameGraphModel::CallCountRole], QByteArray("callCount")); + QCOMPARE(names[FlameGraphModel::DetailsRole], QByteArray("details")); + QCOMPARE(names[FlameGraphModel::FilenameRole], QByteArray("filename")); + QCOMPARE(names[FlameGraphModel::LineRole], QByteArray("line")); + QCOMPARE(names[FlameGraphModel::ColumnRole], QByteArray("column")); + QCOMPARE(names[FlameGraphModel::NoteRole], QByteArray("note")); + QCOMPARE(names[FlameGraphModel::TimePerCallRole], QByteArray("timePerCall")); + QCOMPARE(names[FlameGraphModel::TimeInPercentRole], QByteArray("timeInPercent")); + QCOMPARE(names[FlameGraphModel::RangeTypeRole], QByteArray("rangeType")); +} + +void FlameGraphModelTest::testNotes() +{ + manager.notesModel()->add(2, 1, QString("blubb")); + QCOMPARE(model.data(model.index(0, 0), FlameGraphModel::NoteRole).toString(), + QString("dings\nblubb")); + manager.notesModel()->remove(0); + QCOMPARE(model.data(model.index(0, 0), FlameGraphModel::NoteRole).toString(), + QString("blubb")); + manager.notesModel()->remove(0); + QCOMPARE(model.data(model.index(0, 0), FlameGraphModel::NoteRole).toString(), + QString()); +} + +void FlameGraphModelTest::cleanupTestCase() +{ + manager.clear(); + QCOMPARE(model.rowCount(), 0); +} + +} // namespace Internal +} // namespace QmlProfiler diff --git a/src/plugins/qmlprofiler/tests/flamegraphmodel_test.h b/src/plugins/qmlprofiler/tests/flamegraphmodel_test.h new file mode 100644 index 0000000000..371e5a705c --- /dev/null +++ b/src/plugins/qmlprofiler/tests/flamegraphmodel_test.h @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** 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/flamegraphmodel.h> +#include <qmlprofiler/qmlprofilermodelmanager.h> +#include <QObject> + +namespace QmlProfiler { +namespace Internal { + +class FlameGraphModelTest : public QObject +{ + Q_OBJECT +public: + FlameGraphModelTest(QObject *parent = nullptr); + +private slots: + void initTestCase(); + void testIndex(); + void testCounts(); + void testData(); + void testRoleNames(); + void testNotes(); + void cleanupTestCase(); + +private: + Utils::FileInProjectFinder finder; + QmlProfilerModelManager manager; + FlameGraphModel model; +}; + +} // namespace Internal +} // namespace QmlProfiler diff --git a/src/plugins/qmlprofiler/tests/tests.pri b/src/plugins/qmlprofiler/tests/tests.pri index 969b956dc5..48c6ca0dd6 100644 --- a/src/plugins/qmlprofiler/tests/tests.pri +++ b/src/plugins/qmlprofiler/tests/tests.pri @@ -1,7 +1,9 @@ SOURCES += \ $$PWD/debugmessagesmodel_test.cpp \ - $$PWD/flamegraph_test.cpp + $$PWD/flamegraph_test.cpp \ + $$PWD/flamegraphmodel_test.cpp HEADERS += \ $$PWD/debugmessagesmodel_test.h \ - $$PWD/flamegraph_test.h + $$PWD/flamegraph_test.h \ + $$PWD/flamegraphmodel_test.h |