2015-02-09 13:44:21 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2017-01-09 16:13:48 +00:00
|
|
|
** Copyright (C) 2017 The Qt Company Ltd.
|
2015-02-09 13:44:21 +00:00
|
|
|
** Contact: http://www.qt.io/licensing/
|
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL3$
|
|
|
|
** 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 http://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at http://www.qt.io/contact-us.
|
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 3 requirements
|
|
|
|
** will be met: https://www.gnu.org/licenses/lgpl.html.
|
|
|
|
**
|
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 2.0 or later as published by the Free
|
|
|
|
** Software Foundation and appearing in the file LICENSE.GPL included in
|
|
|
|
** the packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU General Public License version 2.0 requirements will be
|
|
|
|
** met: http://www.gnu.org/licenses/gpl-2.0.html.
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <QtTest>
|
|
|
|
#include <QtQuick>
|
|
|
|
#include <QtCore/private/qhooks_p.h>
|
2015-11-25 22:23:47 +00:00
|
|
|
#include <iostream>
|
2021-08-06 10:27:35 +00:00
|
|
|
#include <QtQuickTestUtils/private/visualtestutils_p.h>
|
|
|
|
#include <QtQuickControlsTestUtils/private/controlstestutils_p.h>
|
2018-04-12 08:58:08 +00:00
|
|
|
|
2021-08-06 10:27:35 +00:00
|
|
|
using namespace QQuickVisualTestUtils;
|
|
|
|
using namespace QQuickControlsTestUtils;
|
2015-02-09 13:44:21 +00:00
|
|
|
|
2021-08-13 14:00:13 +00:00
|
|
|
static int qt_verbose = qEnvironmentVariableIntValue("VERBOSE") != 0;
|
2015-06-06 13:25:26 +00:00
|
|
|
|
2015-02-09 13:44:21 +00:00
|
|
|
Q_GLOBAL_STATIC(QObjectList, qt_qobjects)
|
|
|
|
|
|
|
|
extern "C" Q_DECL_EXPORT void qt_addQObject(QObject *object)
|
|
|
|
{
|
|
|
|
qt_qobjects->append(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" Q_DECL_EXPORT void qt_removeQObject(QObject *object)
|
|
|
|
{
|
|
|
|
qt_qobjects->removeAll(object);
|
|
|
|
}
|
|
|
|
|
2015-04-09 14:27:44 +00:00
|
|
|
class tst_ObjectCount : public QObject
|
2015-02-09 13:44:21 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
2017-05-16 06:25:52 +00:00
|
|
|
void qobjects();
|
|
|
|
void qobjects_data();
|
2015-11-04 16:17:30 +00:00
|
|
|
|
2017-05-16 06:25:52 +00:00
|
|
|
void qquickitems();
|
|
|
|
void qquickitems_data();
|
2015-10-17 15:34:31 +00:00
|
|
|
|
2015-02-09 13:44:21 +00:00
|
|
|
private:
|
|
|
|
QQmlEngine engine;
|
|
|
|
};
|
|
|
|
|
2015-04-09 14:27:44 +00:00
|
|
|
void tst_ObjectCount::init()
|
2015-02-09 13:44:21 +00:00
|
|
|
{
|
|
|
|
qtHookData[QHooks::AddQObject] = reinterpret_cast<quintptr>(&qt_addQObject);
|
|
|
|
qtHookData[QHooks::RemoveQObject] = reinterpret_cast<quintptr>(&qt_removeQObject);
|
|
|
|
|
|
|
|
// warmup
|
|
|
|
QQmlComponent component(&engine);
|
2020-09-04 08:38:35 +00:00
|
|
|
component.setData("import QtQuick; import QtQuick.Controls; Item { Button {} }", QUrl());
|
2015-02-09 13:44:21 +00:00
|
|
|
delete component.create();
|
|
|
|
}
|
|
|
|
|
2015-04-09 14:27:44 +00:00
|
|
|
void tst_ObjectCount::cleanup()
|
2015-02-09 13:44:21 +00:00
|
|
|
{
|
|
|
|
qtHookData[QHooks::AddQObject] = 0;
|
|
|
|
qtHookData[QHooks::RemoveQObject] = 0;
|
|
|
|
}
|
|
|
|
|
2017-05-16 06:25:52 +00:00
|
|
|
static void initTestRows(QQmlEngine *engine)
|
|
|
|
{
|
2021-08-06 10:27:35 +00:00
|
|
|
addTestRowForEachControl(engine, QQC2_IMPORT_PATH, "basic", "QtQuick/Controls/Basic");
|
|
|
|
addTestRowForEachControl(engine, QQC2_IMPORT_PATH, "fusion", "QtQuick/Controls/Fusion",
|
|
|
|
QStringList() << "ButtonPanel" << "CheckIndicator" << "RadioIndicator" << "SliderGroove" << "SliderHandle" << "SwitchIndicator");
|
|
|
|
addTestRowForEachControl(engine, QQC2_IMPORT_PATH, "imagine", "QtQuick/Controls/Imagine");
|
|
|
|
addTestRowForEachControl(engine, QQC2_IMPORT_PATH, "material", "QtQuick/Controls/Material",
|
|
|
|
QStringList() << "Ripple" << "SliderHandle" << "CheckIndicator" << "RadioIndicator"
|
|
|
|
<< "SwitchIndicator" << "BoxShadow" << "ElevationEffect" << "CursorDelegate");
|
|
|
|
addTestRowForEachControl(engine, QQC2_IMPORT_PATH, "universal", "QtQuick/Controls/Universal",
|
|
|
|
QStringList() << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator");
|
2017-05-16 06:25:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2015-11-04 16:17:30 +00:00
|
|
|
static void doBenchmark(QQmlEngine *engine, const QUrl &url)
|
|
|
|
{
|
|
|
|
QQmlComponent component(engine);
|
2015-06-06 13:47:45 +00:00
|
|
|
|
2015-11-04 16:17:30 +00:00
|
|
|
qt_qobjects->clear();
|
2015-06-06 13:47:45 +00:00
|
|
|
|
2015-11-04 16:17:30 +00:00
|
|
|
component.loadUrl(url);
|
|
|
|
QScopedPointer<QObject> object(component.create());
|
|
|
|
QVERIFY2(object.data(), qPrintable(component.errorString()));
|
2015-02-09 13:44:21 +00:00
|
|
|
|
2017-05-16 06:25:52 +00:00
|
|
|
QObjectList objects;
|
|
|
|
for (QObject *object : qAsConst(*qt_qobjects())) {
|
|
|
|
if (qobject_cast<T *>(object))
|
|
|
|
objects += object;
|
2015-02-09 13:44:21 +00:00
|
|
|
}
|
2015-11-04 16:17:30 +00:00
|
|
|
|
2017-05-16 07:50:32 +00:00
|
|
|
if (qt_verbose) {
|
|
|
|
for (QObject *object : objects)
|
|
|
|
qInfo() << "\t" << object;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTest::setBenchmarkResult(objects.count(), QTest::Events);
|
2015-11-15 15:11:58 +00:00
|
|
|
}
|
|
|
|
|
2017-05-16 06:25:52 +00:00
|
|
|
void tst_ObjectCount::qobjects()
|
2015-11-15 15:11:58 +00:00
|
|
|
{
|
|
|
|
QFETCH(QUrl, url);
|
2017-05-16 06:25:52 +00:00
|
|
|
doBenchmark<QObject>(&engine, url);
|
2015-11-15 15:11:58 +00:00
|
|
|
}
|
|
|
|
|
2017-05-16 06:25:52 +00:00
|
|
|
void tst_ObjectCount::qobjects_data()
|
2015-11-15 15:11:58 +00:00
|
|
|
{
|
|
|
|
QTest::addColumn<QUrl>("url");
|
2017-05-16 06:25:52 +00:00
|
|
|
initTestRows(&engine);
|
2015-02-09 13:44:21 +00:00
|
|
|
}
|
|
|
|
|
2017-05-16 06:25:52 +00:00
|
|
|
void tst_ObjectCount::qquickitems()
|
2015-10-17 15:34:31 +00:00
|
|
|
{
|
|
|
|
QFETCH(QUrl, url);
|
2017-05-16 06:25:52 +00:00
|
|
|
doBenchmark<QQuickItem>(&engine, url);
|
2015-10-17 15:34:31 +00:00
|
|
|
}
|
|
|
|
|
2017-05-16 06:25:52 +00:00
|
|
|
void tst_ObjectCount::qquickitems_data()
|
2015-10-17 15:34:31 +00:00
|
|
|
{
|
|
|
|
QTest::addColumn<QUrl>("url");
|
2017-05-16 06:25:52 +00:00
|
|
|
initTestRows(&engine);
|
2015-10-17 15:34:31 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 14:27:44 +00:00
|
|
|
QTEST_MAIN(tst_ObjectCount)
|
2015-02-09 13:44:21 +00:00
|
|
|
|
2015-04-09 14:27:44 +00:00
|
|
|
#include "tst_objectcount.moc"
|