Commit d345755b authored by Ulf Hermann's avatar Ulf Hermann

QmlProfiler: Add test for flame graph view

Change-Id: I5207e03ad8955f2d291d4fc1b7e5d33b64207379
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@theqtcompany.com>
parent 5a3a879a
......@@ -80,6 +80,7 @@ QtcPlugin {
"debugmessagesmodel_test.cpp", "debugmessagesmodel_test.h",
"flamegraph_test.cpp", "flamegraph_test.h",
"flamegraphmodel_test.cpp", "flamegraphmodel_test.h",
"flamegraphview_test.cpp", "flamegraphview_test.h",
]
}
}
......@@ -33,6 +33,7 @@
#include "tests/debugmessagesmodel_test.h"
#include "tests/flamegraph_test.h"
#include "tests/flamegraphmodel_test.h"
#include "tests/flamegraphview_test.h"
#endif
#include <extensionsystem/pluginmanager.h>
......@@ -85,6 +86,7 @@ QList<QObject *> QmlProfiler::Internal::QmlProfilerPlugin::createTestObjects() c
tests << new DebugMessagesModelTest;
tests << new FlameGraphTest;
tests << new FlameGraphModelTest;
tests << new FlameGraphViewTest;
#endif
return tests;
}
......
......@@ -35,16 +35,15 @@ 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()
void FlameGraphModelTest::generateData(QmlProfilerModelManager *manager)
{
QCOMPARE(model.modelManager(), &manager);
// Notes only work with timeline models
QmlProfilerRangeModel *rangeModel = new QmlProfilerRangeModel(manager, Javascript, manager);
manager->notesModel()->addTimelineModel(rangeModel);
manager.startAcquiring();
manager->startAcquiring();
QmlEvent event;
QmlEventType type;
......@@ -65,38 +64,44 @@ void FlameGraphModelTest::initTestCase()
type.location.line = i;
type.location.column = 20 - i;
type.rangeType = static_cast<RangeType>(static_cast<int>(Javascript) - i);
typeIndex = manager.qmlModel()->addEventType(type);
typeIndex = manager->qmlModel()->addEventType(type);
} else {
typeIndex = typeIndices[i - 5];
}
event.setTypeIndex(typeIndex);
event.setTimestamp(++i);
event.setRangeStage(RangeStart);
manager.qmlModel()->addEvent(event);
manager->qmlModel()->addEvent(event);
typeIndices.push(typeIndex);
}
event.setRangeStage(RangeEnd);
event.setTimestamp(++i);
manager.qmlModel()->addEvent(event);
manager->qmlModel()->addEvent(event);
event.setRangeStage(RangeStart);
event.setTimestamp(++i);
manager.qmlModel()->addEvent(event);
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->qmlModel()->addEvent(event);
}
manager.acquiringDone();
manager->acquiringDone();
manager.notesModel()->setNotes(QVector<QmlNote>({QmlNote(0, 1, 20, "dings")}));
manager.notesModel()->loadData();
manager->notesModel()->setNotes(QVector<QmlNote>({QmlNote(0, 1, 20, "dings")}));
manager->notesModel()->loadData();
QCOMPARE(manager.state(), QmlProfilerModelManager::Done);
QCOMPARE(manager->state(), QmlProfilerModelManager::Done);
}
void FlameGraphModelTest::initTestCase()
{
QCOMPARE(model.modelManager(), &manager);
generateData(&manager);
}
void FlameGraphModelTest::testIndex()
......
......@@ -37,6 +37,7 @@ class FlameGraphModelTest : public QObject
Q_OBJECT
public:
FlameGraphModelTest(QObject *parent = nullptr);
static void generateData(QmlProfilerModelManager *manager);
private slots:
void initTestCase();
......
/****************************************************************************
**
** 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 "flamegraphview_test.h"
#include "flamegraphmodel_test.h"
#include <qmlprofiler/qmlprofilertool.h>
#include <QtTest>
#include <QMenu>
#include <QWindow>
namespace QmlProfiler {
namespace Internal {
FlameGraphViewTest::FlameGraphViewTest(QObject *parent) : QObject(parent), manager(&finder),
view(&manager)
{
}
void FlameGraphViewTest::initTestCase()
{
FlameGraphModelTest::generateData(&manager);
view.resize(500, 500);
view.show();
QTest::qWaitForWindowExposed(&view);
}
void FlameGraphViewTest::testSelection()
{
auto con1 = connect(&view, &QmlProfilerEventsView::gotoSourceLocation,
[](const QString &file, int line, int column) {
QCOMPARE(line, 0);
QCOMPARE(column, 20);
QCOMPARE(file, QLatin1String("somefile.js"));
});
auto con2 = connect(&view, &QmlProfilerEventsView::typeSelected, [](int selected) {
QCOMPARE(selected, 0);
});
QSignalSpy spy(&view, SIGNAL(typeSelected(int)));
QTest::mouseClick(view.childAt(250, 250), Qt::LeftButton, Qt::NoModifier, QPoint(5, 495));
if (spy.isEmpty())
QVERIFY(spy.wait());
// External setting of type should not send gotoSourceLocation or typeSelected
view.selectByTypeId(1);
QCOMPARE(spy.count(), 1);
// Click in empty area shouldn't change anything, either
QTest::mouseClick(view.childAt(250, 250), Qt::LeftButton, Qt::NoModifier, QPoint(495, 5));
QCOMPARE(spy.count(), 1);
view.onVisibleFeaturesChanged(1 << ProfileBinding);
QCOMPARE(spy.count(), 1); // External event: still doesn't change anything
disconnect(con1);
disconnect(con2);
// The mouse click will select a different event now, as the JS category has been hidden
con1 = connect(&view, &QmlProfilerEventsView::gotoSourceLocation,
[](const QString &file, int line, int column) {
QCOMPARE(file, QLatin1String("somefile.js"));
QCOMPARE(line, 2);
QCOMPARE(column, 18);
});
con2 = connect(&view, &QmlProfilerEventsView::typeSelected, [](int selected) {
QCOMPARE(selected, 2);
});
QTest::mouseClick(view.childAt(250, 250), Qt::LeftButton, Qt::NoModifier, QPoint(5, 495));
if (spy.count() == 1)
QVERIFY(spy.wait());
disconnect(con1);
disconnect(con2);
}
void FlameGraphViewTest::testContextMenu()
{
int targetWidth = 0;
int targetHeight = 0;
{
QMenu testMenu;
testMenu.addActions(QmlProfilerTool::profilerContextMenuActions());
testMenu.addSeparator();
testMenu.show();
QTest::qWaitForWindowExposed(testMenu.window());
targetWidth = testMenu.width() / 2;
int prevHeight = testMenu.height();
QAction dummy(QString("target"), this);
testMenu.addAction(&dummy);
targetHeight = (testMenu.height() + prevHeight) / 2;
}
connect(view.windowHandle(), &QWindow::activeChanged, this, [&]() {
if (view.windowHandle()->isActive())
return;
QTest::qWaitForWindowExposed(qApp->activePopupWidget());
QTest::mouseMove(qApp->activePopupWidget(), QPoint(targetWidth, targetHeight));
QTest::mouseClick(qApp->activePopupWidget(), Qt::LeftButton, Qt::NoModifier,
QPoint(targetWidth, targetHeight));
if (!manager.isRestrictedToRange()) {
// click somewhere else to remove the menu and return to outer function
QTest::mouseClick(qApp->activePopupWidget(), Qt::LeftButton, Qt::NoModifier,
QPoint(500, 500));
}
});
QTest::mouseMove(&view, QPoint(250, 250));
QSignalSpy spy(&view, SIGNAL(showFullRange()));
QContextMenuEvent event(QContextMenuEvent::Mouse, QPoint(250, 250));
QVERIFY(qApp->notify(&view, &event));
QCOMPARE(spy.count(), 0);
manager.restrictToRange(1, 10);
QVERIFY(qApp->notify(&view, &event));
if (spy.count() != 1)
QTRY_COMPARE(spy.count(), 1);
}
void FlameGraphViewTest::cleanupTestCase()
{
manager.clear();
}
} // namespace Internal
} // namespace QmlProfiler
/****************************************************************************
**
** 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/flamegraphview.h>
#include <qmlprofiler/qmlprofilermodelmanager.h>
#include <QObject>
namespace QmlProfiler {
namespace Internal {
class FlameGraphViewTest : public QObject
{
Q_OBJECT
public:
FlameGraphViewTest(QObject *parent = nullptr);
private slots:
void initTestCase();
void testSelection();
void testContextMenu();
void cleanupTestCase();
private:
Utils::FileInProjectFinder finder;
QmlProfilerModelManager manager;
FlameGraphView view;
};
} // namespace Internal
} // namespace QmlProfiler
SOURCES += \
$$PWD/debugmessagesmodel_test.cpp \
$$PWD/flamegraph_test.cpp \
$$PWD/flamegraphmodel_test.cpp
$$PWD/flamegraphmodel_test.cpp \
$$PWD/flamegraphview_test.cpp
HEADERS += \
$$PWD/debugmessagesmodel_test.h \
$$PWD/flamegraph_test.h \
$$PWD/flamegraphmodel_test.h
$$PWD/flamegraphmodel_test.h \
$$PWD/flamegraphview_test.h
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