2022-05-13 13:12:05 +00:00
|
|
|
// Copyright (C) 2017 The Qt Company Ltd.
|
2024-02-22 14:51:16 +00:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
2015-02-09 13:44:21 +00:00
|
|
|
|
2025-04-10 12:00:44 +00:00
|
|
|
#include <QTest>
|
2015-02-09 13:44:21 +00:00
|
|
|
#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-10-20 13:11:12 +00:00
|
|
|
// Calendar is excluded because it's a singleton and can't be created.
|
2021-11-19 16:00:10 +00:00
|
|
|
// TreeViewDelegate is excluded since it's a delegate that can only be created by TreeView.
|
2024-10-15 14:33:58 +00:00
|
|
|
// TableViewDelegate is excluded since it's a delegate that can only be created by TableView.
|
2024-12-06 11:15:40 +00:00
|
|
|
// Horizontal/VerticalHeaderViewDelegate is excluded since it's a delegate
|
|
|
|
// that can only be created by Horizontal/VerticalHeaderView.
|
2021-10-20 13:11:12 +00:00
|
|
|
addTestRowForEachControl(engine, QQC2_IMPORT_PATH, "basic", "QtQuick/Controls/Basic",
|
2024-12-06 11:15:40 +00:00
|
|
|
QStringList() << "Calendar"
|
|
|
|
<< "TreeViewDelegate"
|
|
|
|
<< "TableViewDelegate"
|
|
|
|
<< "HorizontalHeaderViewDelegate"
|
|
|
|
<< "VerticalHeaderViewDelegate");
|
|
|
|
addTestRowForEachControl(
|
|
|
|
engine, QQC2_IMPORT_PATH, "fusion", "QtQuick/Controls/Fusion",
|
|
|
|
QStringList() << "ButtonPanel" << "CheckIndicator" << "RadioIndicator" << "SliderGroove"
|
|
|
|
<< "SliderHandle" << "SwitchIndicator" << "TreeViewDelegate"
|
|
|
|
<< "HorizontalHeaderViewDelegate"
|
|
|
|
<< "VerticalHeaderViewDelegate");
|
|
|
|
addTestRowForEachControl(engine, QQC2_IMPORT_PATH, "imagine", "QtQuick/Controls/Imagine",
|
|
|
|
QStringList() << "HorizontalHeaderViewDelegate"
|
|
|
|
<< "VerticalHeaderViewDelegate");
|
2021-08-06 10:27:35 +00:00
|
|
|
addTestRowForEachControl(engine, QQC2_IMPORT_PATH, "material", "QtQuick/Controls/Material",
|
2024-12-06 11:15:40 +00:00
|
|
|
QStringList() << "Ripple" << "SliderHandle" << "CheckIndicator"
|
|
|
|
<< "RadioIndicator"
|
|
|
|
<< "SwitchIndicator" << "BoxShadow" << "ElevationEffect"
|
|
|
|
<< "CursorDelegate" << "TreeViewDelegate"
|
|
|
|
<< "HorizontalHeaderViewDelegate"
|
|
|
|
<< "VerticalHeaderViewDelegate");
|
2021-08-06 10:27:35 +00:00
|
|
|
addTestRowForEachControl(engine, QQC2_IMPORT_PATH, "universal", "QtQuick/Controls/Universal",
|
2024-12-06 11:15:40 +00:00
|
|
|
QStringList()
|
|
|
|
<< "CheckIndicator" << "RadioIndicator" << "SwitchIndicator"
|
|
|
|
<< "HorizontalHeaderViewDelegate"
|
|
|
|
<< "VerticalHeaderViewDelegate");
|
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;
|
2022-10-06 09:30:50 +00:00
|
|
|
for (QObject *object : std::as_const(*qt_qobjects())) {
|
2017-05-16 06:25:52 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
Port from container::count() and length() to size() - V5
This is a semantic patch using ClangTidyTransformator as in
qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to
handle typedefs and accesses through pointers, too:
const std::string o = "object";
auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); };
auto derivedFromAnyOfClasses = [&](ArrayRef<StringRef> classes) {
auto exprOfDeclaredType = [&](auto decl) {
return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o);
};
return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))));
};
auto renameMethod = [&] (ArrayRef<StringRef> classes,
StringRef from, StringRef to) {
return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)),
callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))),
changeTo(cat(access(o, cat(to)), "()")),
cat("use '", to, "' instead of '", from, "'"));
};
renameMethod(<classes>, "count", "size");
renameMethod(<classes>, "length", "size");
except that on() was replaced with a matcher that doesn't ignoreParens().
a.k.a qt-port-to-std-compatible-api V5 with config Scope: 'Container'.
Change-Id: I58e1b41b91c34d2e860dbb5847b3752edbfc6fc9
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-10-08 17:56:03 +00:00
|
|
|
QTest::setBenchmarkResult(objects.size(), 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"
|