forked from qt-creator/qt-creator
QmlProfiler: Add tests for QmlEventType
Change-Id: Id2ee8250c0e89637733a1454de4a60df42612904 Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
This commit is contained in:
@@ -87,6 +87,7 @@ QtcPlugin {
|
||||
"pixmapcachemodel_test.cpp", "pixmapcachemodel_test.h",
|
||||
"qmlevent_test.cpp", "qmlevent_test.h",
|
||||
"qmleventlocation_test.cpp", "qmleventlocation_test.h",
|
||||
"qmleventtype_test.cpp", "qmleventtype_test.h",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "tests/pixmapcachemodel_test.h"
|
||||
#include "tests/qmlevent_test.h"
|
||||
#include "tests/qmleventlocation_test.h"
|
||||
#include "tests/qmleventtype_test.h"
|
||||
#endif
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
@@ -97,6 +98,7 @@ QList<QObject *> QmlProfiler::Internal::QmlProfilerPlugin::createTestObjects() c
|
||||
tests << new PixmapCacheModelTest;
|
||||
tests << new QmlEventTest;
|
||||
tests << new QmlEventLocationTest;
|
||||
tests << new QmlEventTypeTest;
|
||||
#endif
|
||||
return tests;
|
||||
}
|
||||
|
||||
141
src/plugins/qmlprofiler/tests/qmleventtype_test.cpp
Normal file
141
src/plugins/qmlprofiler/tests/qmleventtype_test.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 "qmleventtype_test.h"
|
||||
#include <qmlprofiler/qmleventtype.h>
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
namespace QmlProfiler {
|
||||
namespace Internal {
|
||||
|
||||
QmlEventTypeTest::QmlEventTypeTest(QObject *parent) : QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void QmlEventTypeTest::testAccessors()
|
||||
{
|
||||
QmlEventType type;
|
||||
QCOMPARE(type.message(), MaximumMessage);
|
||||
QCOMPARE(type.rangeType(), MaximumRangeType);
|
||||
QCOMPARE(type.detailType(), -1);
|
||||
QVERIFY(!type.location().isValid());
|
||||
QVERIFY(type.data().isEmpty());
|
||||
QVERIFY(type.displayName().isEmpty());
|
||||
QCOMPARE(type.feature(), MaximumProfileFeature);
|
||||
|
||||
type.setLocation(QmlEventLocation("blah.js", 12, 13));
|
||||
QCOMPARE(type.location().filename(), QString("blah.js"));
|
||||
QCOMPARE(type.location().line(), 12);
|
||||
QCOMPARE(type.location().column(), 13);
|
||||
|
||||
type.setData("dadada");
|
||||
QCOMPARE(type.data(), QString("dadada"));
|
||||
|
||||
type.setDisplayName("disdis");
|
||||
QCOMPARE(type.displayName(), QString("disdis"));
|
||||
|
||||
QmlEventType type2(MaximumMessage, Javascript, 12, QmlEventLocation("lala.js", 2, 3), "nehhh",
|
||||
"brbr");
|
||||
QCOMPARE(type2.message(), MaximumMessage);
|
||||
QCOMPARE(type2.rangeType(), Javascript);
|
||||
QCOMPARE(type2.detailType(), 12);
|
||||
QCOMPARE(type2.location(), QmlEventLocation("lala.js", 2, 3));
|
||||
QCOMPARE(type2.data(), QString("nehhh"));
|
||||
QCOMPARE(type2.displayName(), QString("brbr"));
|
||||
QCOMPARE(type2.feature(), ProfileJavaScript);
|
||||
}
|
||||
|
||||
void QmlEventTypeTest::testFeature()
|
||||
{
|
||||
const ProfileFeature features[][MaximumEventType] = {
|
||||
// Event
|
||||
{ MaximumProfileFeature, ProfileInputEvents, ProfileInputEvents,
|
||||
ProfileAnimations, MaximumProfileFeature, MaximumProfileFeature },
|
||||
// RangeStart
|
||||
{ MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature,
|
||||
MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature },
|
||||
// RangeData
|
||||
{ MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature,
|
||||
MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature },
|
||||
// RangeLocation
|
||||
{ MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature,
|
||||
MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature },
|
||||
// RangeEnd
|
||||
{ MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature,
|
||||
MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature },
|
||||
// Complete
|
||||
{ MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature,
|
||||
MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature },
|
||||
// PixmapCacheEvent
|
||||
{ ProfilePixmapCache, ProfilePixmapCache, ProfilePixmapCache,
|
||||
ProfilePixmapCache, ProfilePixmapCache, ProfilePixmapCache },
|
||||
// SceneGraphFrame
|
||||
{ ProfileSceneGraph, ProfileSceneGraph, ProfileSceneGraph,
|
||||
ProfileSceneGraph, ProfileSceneGraph, ProfileSceneGraph },
|
||||
// MemoryAllocation
|
||||
{ ProfileMemory, ProfileMemory, ProfileMemory,
|
||||
ProfileMemory, ProfileMemory, ProfileMemory },
|
||||
// DebugMessage
|
||||
{ ProfileDebugMessages, ProfileDebugMessages, ProfileDebugMessages,
|
||||
ProfileDebugMessages, ProfileDebugMessages, ProfileDebugMessages }
|
||||
};
|
||||
|
||||
for (int i = 0; i < MaximumMessage; ++i) {
|
||||
for (int j = 0; j < MaximumEventType; ++j) {
|
||||
QmlEventType type(static_cast<Message>(i), MaximumRangeType, j);
|
||||
QCOMPARE(type.feature(), features[i][j]);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < MaximumRangeType; ++i) {
|
||||
QmlEventType type(MaximumMessage, static_cast<RangeType>(i));
|
||||
QCOMPARE(type.feature(), featureFromRangeType(static_cast<RangeType>(i)));
|
||||
}
|
||||
}
|
||||
|
||||
void QmlEventTypeTest::testStreamOps()
|
||||
{
|
||||
QmlEventType type(MaximumMessage, Javascript, -1, QmlEventLocation("socken.js", 12, 13),
|
||||
"lalala", "lelele");
|
||||
|
||||
QBuffer wbuffer;
|
||||
wbuffer.open(QIODevice::WriteOnly);
|
||||
QDataStream wstream(&wbuffer);
|
||||
wstream << type;
|
||||
|
||||
QBuffer rbuffer;
|
||||
rbuffer.setData(wbuffer.data());
|
||||
rbuffer.open(QIODevice::ReadOnly);
|
||||
QDataStream rstream(&rbuffer);
|
||||
|
||||
QmlEventType type2;
|
||||
QVERIFY(type != type2);
|
||||
rstream >> type2;
|
||||
|
||||
QCOMPARE(type2, type);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QmlProfiler
|
||||
45
src/plugins/qmlprofiler/tests/qmleventtype_test.h
Normal file
45
src/plugins/qmlprofiler/tests/qmleventtype_test.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 <QObject>
|
||||
|
||||
namespace QmlProfiler {
|
||||
namespace Internal {
|
||||
|
||||
class QmlEventTypeTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QmlEventTypeTest(QObject *parent = 0);
|
||||
|
||||
private slots:
|
||||
void testAccessors();
|
||||
void testFeature();
|
||||
void testStreamOps();
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QmlProfiler
|
||||
@@ -8,7 +8,8 @@ SOURCES += \
|
||||
$$PWD/memoryusagemodel_test.cpp \
|
||||
$$PWD/pixmapcachemodel_test.cpp \
|
||||
$$PWD/qmlevent_test.cpp \
|
||||
$$PWD/qmleventlocation_test.cpp
|
||||
$$PWD/qmleventlocation_test.cpp \
|
||||
$$PWD/qmleventtype_test.cpp
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/debugmessagesmodel_test.h \
|
||||
@@ -20,4 +21,5 @@ HEADERS += \
|
||||
$$PWD/memoryusagemodel_test.h \
|
||||
$$PWD/pixmapcachemodel_test.h \
|
||||
$$PWD/qmlevent_test.h \
|
||||
$$PWD/qmleventlocation_test.h
|
||||
$$PWD/qmleventlocation_test.h \
|
||||
$$PWD/qmleventtype_test.h
|
||||
|
||||
Reference in New Issue
Block a user