aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmlprofiler/tests
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2016-05-30 16:28:19 +0200
committerUlf Hermann <ulf.hermann@qt.io>2016-06-01 09:23:22 +0000
commit12f160b1f31dfea797c3f29035f766ce90ca23c7 (patch)
treefb416efaf3019b1897955c7095f8528df4e1506a /src/plugins/qmlprofiler/tests
parent652846c5c7d083974a2fd31fa813575cd132408d (diff)
QmlProfiler: Add tests for FlameGraph
Change-Id: I1eadb2675e16fcc61e073ea1a730ab065456f964 Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
Diffstat (limited to 'src/plugins/qmlprofiler/tests')
-rw-r--r--src/plugins/qmlprofiler/tests/flamegraph_test.cpp123
-rw-r--r--src/plugins/qmlprofiler/tests/flamegraph_test.h69
-rw-r--r--src/plugins/qmlprofiler/tests/tests.pri6
3 files changed, 196 insertions, 2 deletions
diff --git a/src/plugins/qmlprofiler/tests/flamegraph_test.cpp b/src/plugins/qmlprofiler/tests/flamegraph_test.cpp
new file mode 100644
index 00000000000..001aaf60f99
--- /dev/null
+++ b/src/plugins/qmlprofiler/tests/flamegraph_test.cpp
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** 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 "flamegraph_test.h"
+#include <QtTest>
+#include <QQuickItem>
+
+namespace QmlProfiler {
+namespace Internal {
+
+void FlameGraphTest::initTestCase()
+{
+ flameGraph.setDelegate(&delegate);
+ flameGraph.setModel(&model);
+ flameGraph.setSizeRole(sizeRole);
+ flameGraph.setWidth(100);
+ flameGraph.setHeight(100);
+ flameGraph.setSizeThreshold(0.01);
+
+ QCOMPARE(flameGraph.delegate(), &delegate);
+ QCOMPARE(flameGraph.model(), &model);
+ QCOMPARE(flameGraph.sizeRole(), Qt::UserRole + 1);
+ QCOMPARE(flameGraph.sizeThreshold(), 0.01);
+}
+
+void FlameGraphTest::testRebuild()
+{
+ flameGraph.setModel(nullptr);
+ qreal sum = 0;
+ for (int i = 1; i < 10; ++i) {
+ QStandardItem *item = new QStandardItem;
+ item->setData(i, sizeRole);
+ item->setData(100 / i, dataRole);
+
+ for (int j = 1; j < i; ++j) {
+ QStandardItem *item2 = new QStandardItem;
+ item2->setData(1, sizeRole);
+ for (int k = 0; k < 10; ++k) {
+ QStandardItem *skipped = new QStandardItem;
+ skipped->setData(0.001, sizeRole);
+ item2->appendRow(skipped);
+ }
+ item->appendRow(item2);
+ }
+
+ model.appendRow(item);
+ sum += i;
+ }
+ model.invisibleRootItem()->setData(sum, sizeRole);
+ flameGraph.setModel(nullptr);
+ flameGraph.setModel(&model);
+ QCOMPARE(flameGraph.depth(), 3);
+ qreal i = 0;
+ qreal position = 0;
+ foreach (QQuickItem *child, flameGraph.childItems()) {
+ FlameGraphAttached *attached = FlameGraph::qmlAttachedProperties(child);
+ QCOMPARE(attached->relativeSize(), (++i) / sum);
+ QCOMPARE(attached->relativePosition(), position / sum);
+ QCOMPARE(attached->data(dataRole).toInt(), 100 / static_cast<int>(i));
+ QVERIFY(attached->isDataValid());
+
+ qreal j = 0;
+ foreach (QQuickItem *grandchild, child->childItems()) {
+ FlameGraphAttached *attached2 = FlameGraph::qmlAttachedProperties(grandchild);
+ QCOMPARE(attached2->relativeSize(), 1.0 / i);
+ QCOMPARE(attached2->relativePosition(), (j++) / i);
+ QCOMPARE(grandchild->childItems().count(), 1);
+ FlameGraphAttached *skipped =
+ FlameGraph::qmlAttachedProperties(grandchild->childItems()[0]);
+ QCOMPARE(skipped->relativePosition(), 0.0);
+ QCOMPARE(skipped->relativeSize(), 0.001 * 10);
+ }
+
+ position += i;
+ }
+ QCOMPARE(i, 9.0);
+}
+
+void FlameGraphTest::cleanupTestCase()
+{
+
+}
+
+QObject *DelegateComponent::create(QQmlContext *context)
+{
+ QObject *ret = beginCreate(context);
+ completeCreate();
+ return ret;
+}
+
+QObject *DelegateComponent::beginCreate(QQmlContext *)
+{
+ return new DelegateObject;
+}
+
+void DelegateComponent::completeCreate()
+{
+}
+
+} // namespace Internal
+} // namespace QmlProfiler
diff --git a/src/plugins/qmlprofiler/tests/flamegraph_test.h b/src/plugins/qmlprofiler/tests/flamegraph_test.h
new file mode 100644
index 00000000000..bcfeb43b393
--- /dev/null
+++ b/src/plugins/qmlprofiler/tests/flamegraph_test.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** 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/flamegraph.h>
+#include <QObject>
+#include <QStandardItemModel>
+#include <QQmlComponent>
+#include <QQuickItem>
+
+namespace QmlProfiler {
+namespace Internal {
+
+class DelegateObject : public QQuickItem
+{
+ Q_OBJECT
+};
+
+class DelegateComponent : public QQmlComponent
+{
+ Q_OBJECT
+public:
+ QObject *create(QQmlContext *context) override;
+ QObject *beginCreate(QQmlContext *) override;
+ void completeCreate() override;
+};
+
+class FlameGraphTest : public QObject
+{
+ Q_OBJECT
+private slots:
+ void initTestCase();
+ void testRebuild();
+ void cleanupTestCase();
+
+private:
+ static const int sizeRole = Qt::UserRole + 1;
+ static const int dataRole = Qt::UserRole + 2;
+ FlameGraph flameGraph;
+ QStandardItemModel model;
+ DelegateComponent delegate;
+};
+
+
+} // namespace Internal
+} // namespace QmlProfiler
diff --git a/src/plugins/qmlprofiler/tests/tests.pri b/src/plugins/qmlprofiler/tests/tests.pri
index 476296b5cdd..969b956dc52 100644
--- a/src/plugins/qmlprofiler/tests/tests.pri
+++ b/src/plugins/qmlprofiler/tests/tests.pri
@@ -1,5 +1,7 @@
SOURCES += \
- $$PWD/debugmessagesmodel_test.cpp
+ $$PWD/debugmessagesmodel_test.cpp \
+ $$PWD/flamegraph_test.cpp
HEADERS += \
- $$PWD/debugmessagesmodel_test.h
+ $$PWD/debugmessagesmodel_test.h \
+ $$PWD/flamegraph_test.h