2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2018 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2018-06-06 19:23:15 +02:00
|
|
|
|
2021-06-29 00:07:35 +02:00
|
|
|
#include "testflamegraphmodel.h"
|
2021-06-18 16:19:24 +02:00
|
|
|
|
2018-06-06 19:23:15 +02:00
|
|
|
#include <tracing/flamegraph.h>
|
|
|
|
|
#include <tracing/timelinetheme.h>
|
2022-02-08 18:22:14 +01:00
|
|
|
#include <utils/hostosinfo.h>
|
2018-06-06 19:23:15 +02:00
|
|
|
#include <utils/theme/theme_p.h>
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include <QQmlContext>
|
2022-07-19 17:26:34 +02:00
|
|
|
#include <QQmlEngine>
|
2018-06-06 19:23:15 +02:00
|
|
|
#include <QQuickWidget>
|
|
|
|
|
#include <QtTest>
|
|
|
|
|
|
|
|
|
|
class DummyTheme : public Utils::Theme
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
DummyTheme() : Utils::Theme(QLatin1String("dummy"))
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < d->colors.count(); ++i) {
|
|
|
|
|
d->colors[i] = QPair<QColor, QString>(
|
2021-06-09 11:36:10 +02:00
|
|
|
QColor::fromRgb(QRandomGenerator::global()->bounded(256),
|
|
|
|
|
QRandomGenerator::global()->bounded(256),
|
|
|
|
|
QRandomGenerator::global()->bounded(256)),
|
2018-06-06 19:23:15 +02:00
|
|
|
QString::number(i));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class tst_FlameGraphView : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
tst_FlameGraphView() { Utils::setCreatorTheme(&theme); }
|
|
|
|
|
|
2022-02-08 18:22:14 +01:00
|
|
|
static void initMain();
|
|
|
|
|
|
2018-06-06 19:23:15 +02:00
|
|
|
private slots:
|
|
|
|
|
void initTestCase();
|
|
|
|
|
void testZoom();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
static const int sizeRole = Qt::UserRole + 1;
|
|
|
|
|
static const int dataRole = Qt::UserRole + 2;
|
|
|
|
|
TestFlameGraphModel model;
|
|
|
|
|
QQuickWidget widget;
|
|
|
|
|
DummyTheme theme;
|
|
|
|
|
};
|
|
|
|
|
|
2022-02-08 18:22:14 +01:00
|
|
|
void tst_FlameGraphView::initMain()
|
|
|
|
|
{
|
2022-07-17 13:43:49 +02:00
|
|
|
if (Utils::HostOsInfo::isWindowsHost())
|
2022-02-08 18:22:14 +01:00
|
|
|
qputenv("QSG_RHI_BACKEND", "opengl");
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-06 19:23:15 +02:00
|
|
|
void tst_FlameGraphView::initTestCase()
|
|
|
|
|
{
|
|
|
|
|
model.fill();
|
|
|
|
|
|
2022-07-19 17:26:34 +02:00
|
|
|
widget.engine()->addImportPath(":/qt/qml/");
|
2018-06-06 19:23:15 +02:00
|
|
|
Timeline::TimelineTheme::setupTheme(widget.engine());
|
|
|
|
|
|
|
|
|
|
widget.rootContext()->setContextProperty(QStringLiteral("flameGraphModel"), &model);
|
2021-06-18 16:19:24 +02:00
|
|
|
widget.setSource(QUrl(QStringLiteral(
|
2022-07-19 17:26:34 +02:00
|
|
|
"qrc:/qt/qml/QtCreator/TstTracingFlameGraphView/TestFlameGraphView.qml")));
|
2018-06-06 19:23:15 +02:00
|
|
|
|
|
|
|
|
widget.setResizeMode(QQuickWidget::SizeRootObjectToView);
|
|
|
|
|
widget.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
|
widget.resize(800, 600);
|
|
|
|
|
|
|
|
|
|
widget.show();
|
2021-01-15 11:49:44 +01:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(widget.windowHandle()));
|
2018-06-06 19:23:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void tst_FlameGraphView::testZoom()
|
|
|
|
|
{
|
|
|
|
|
auto selectedTypeId = [&]() {
|
2022-07-18 00:09:07 +02:00
|
|
|
const QQuickItem *item = widget.rootObject();
|
|
|
|
|
return item ? item->property("selectedTypeId").toInt() : -1;
|
2018-06-06 19:23:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QWindow *window = widget.windowHandle();
|
|
|
|
|
|
|
|
|
|
QCOMPARE(selectedTypeId(), -1);
|
2022-08-04 09:43:10 +02:00
|
|
|
QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(widget.width() - 25,
|
|
|
|
|
widget.height() - 25));
|
2018-06-06 19:23:15 +02:00
|
|
|
QTRY_VERIFY(selectedTypeId() != -1);
|
|
|
|
|
const int typeId1 = selectedTypeId();
|
|
|
|
|
|
2022-08-04 09:43:10 +02:00
|
|
|
QTest::mouseDClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(25, widget.height() - 25));
|
2018-06-06 19:23:15 +02:00
|
|
|
QTRY_VERIFY(selectedTypeId() != typeId1);
|
|
|
|
|
QVERIFY(selectedTypeId() != -1);
|
|
|
|
|
|
|
|
|
|
QTest::mouseDClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(widget.width() / 2,
|
|
|
|
|
widget.height() / 2));
|
|
|
|
|
QTRY_COMPARE(selectedTypeId(), -1);
|
2022-08-04 09:43:10 +02:00
|
|
|
QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(widget.width() - 25,
|
|
|
|
|
widget.height() - 25));
|
2018-06-06 19:23:15 +02:00
|
|
|
QTRY_COMPARE(selectedTypeId(), typeId1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTEST_MAIN(tst_FlameGraphView)
|
|
|
|
|
|
|
|
|
|
#include "tst_flamegraphview.moc"
|