2015-01-30 19:57:40 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2017-01-09 16:13:48 +00:00
|
|
|
** Copyright (C) 2017 The Qt Company Ltd.
|
2015-01-30 19:57:40 +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 <QtQml>
|
|
|
|
#include <QtTest>
|
|
|
|
|
2015-04-09 14:27:44 +00:00
|
|
|
class tst_CreationTime : public QObject
|
2015-01-30 19:57:40 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private slots:
|
2015-07-06 17:37:02 +00:00
|
|
|
void init();
|
|
|
|
|
|
|
|
void controls();
|
|
|
|
void controls_data();
|
2015-01-30 19:57:40 +00:00
|
|
|
|
2015-11-15 15:11:58 +00:00
|
|
|
void material();
|
|
|
|
void material_data();
|
|
|
|
|
2015-10-17 15:34:31 +00:00
|
|
|
void universal();
|
|
|
|
void universal_data();
|
|
|
|
|
2015-07-06 17:37:02 +00:00
|
|
|
void calendar();
|
|
|
|
void calendar_data();
|
2015-01-30 19:57:40 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
QQmlEngine engine;
|
|
|
|
};
|
|
|
|
|
2015-07-06 17:37:02 +00:00
|
|
|
void tst_CreationTime::init()
|
2015-01-30 19:57:40 +00:00
|
|
|
{
|
|
|
|
engine.clearComponentCache();
|
|
|
|
}
|
|
|
|
|
2016-04-20 08:13:21 +00:00
|
|
|
static void addTestRows(QQmlEngine *engine, const QString &sourcePath, const QString &targetPath, const QStringList &skiplist = QStringList())
|
2015-07-06 17:37:02 +00:00
|
|
|
{
|
2015-11-15 15:11:58 +00:00
|
|
|
// We cannot use QQmlComponent to load QML files directly from the source tree.
|
|
|
|
// For styles that use internal QML types (eg. material/Ripple.qml), the source
|
|
|
|
// dir would be added as an "implicit" import path overriding the actual import
|
2016-04-21 12:19:23 +00:00
|
|
|
// path (qtbase/qml/QtQuick/Controls.2/Material). => The QML engine fails to load
|
2015-11-15 15:11:58 +00:00
|
|
|
// the style C++ plugin from the implicit import path (the source dir).
|
|
|
|
//
|
|
|
|
// Therefore we only use the source tree for finding out the set of QML files that
|
|
|
|
// a particular style implements, and then we locate the respective QML files in
|
|
|
|
// the engine's import path. This way we can use QQmlComponent to load each QML file
|
|
|
|
// for benchmarking.
|
|
|
|
|
2016-08-23 08:33:30 +00:00
|
|
|
const QFileInfoList entries = QDir(QQC2_IMPORT_PATH "/" + sourcePath).entryInfoList(QStringList("*.qml"), QDir::Files);
|
|
|
|
for (const QFileInfo &entry : entries) {
|
2015-11-15 15:11:58 +00:00
|
|
|
QString name = entry.baseName();
|
|
|
|
if (!skiplist.contains(name)) {
|
2016-08-23 08:33:30 +00:00
|
|
|
const auto importPathList = engine->importPathList();
|
|
|
|
for (const QString &importPath : importPathList) {
|
2016-01-04 17:15:33 +00:00
|
|
|
QString name = entry.dir().dirName() + "/" + entry.fileName();
|
2016-04-21 12:26:07 +00:00
|
|
|
QString filePath = importPath + "/" + targetPath + "/" + entry.fileName();
|
2015-11-15 15:11:58 +00:00
|
|
|
if (QFile::exists(filePath)) {
|
|
|
|
QTest::newRow(qPrintable(name)) << QUrl::fromLocalFile(filePath);
|
|
|
|
break;
|
2016-01-04 17:15:33 +00:00
|
|
|
} else if (QFile::exists(QQmlFile::urlToLocalFileOrQrc(filePath))) {
|
|
|
|
QTest::newRow(qPrintable(name)) << QUrl(filePath);
|
|
|
|
break;
|
2015-11-15 15:11:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-06 17:37:02 +00:00
|
|
|
}
|
2015-01-30 19:57:40 +00:00
|
|
|
|
2015-11-15 15:11:58 +00:00
|
|
|
static void doBenchmark(QQmlEngine *engine, const QUrl &url)
|
2015-07-06 17:37:02 +00:00
|
|
|
{
|
2015-11-15 15:11:58 +00:00
|
|
|
QQmlComponent component(engine);
|
|
|
|
component.loadUrl(url);
|
|
|
|
|
2015-01-30 19:57:40 +00:00
|
|
|
QObjectList objects;
|
2015-07-06 17:37:02 +00:00
|
|
|
objects.reserve(4096);
|
2015-01-30 19:57:40 +00:00
|
|
|
QBENCHMARK {
|
2015-11-15 15:11:58 +00:00
|
|
|
QObject *object = component.create();
|
|
|
|
QVERIFY2(object, qPrintable(component.errorString()));
|
2015-01-30 19:57:40 +00:00
|
|
|
objects += object;
|
|
|
|
}
|
|
|
|
qDeleteAll(objects);
|
|
|
|
}
|
|
|
|
|
2015-07-06 17:37:02 +00:00
|
|
|
void tst_CreationTime::controls()
|
2015-01-30 19:57:40 +00:00
|
|
|
{
|
2015-11-04 11:11:53 +00:00
|
|
|
QFETCH(QUrl, url);
|
2015-11-15 15:11:58 +00:00
|
|
|
doBenchmark(&engine, url);
|
2015-07-06 17:37:02 +00:00
|
|
|
}
|
2015-01-30 19:57:40 +00:00
|
|
|
|
2015-07-06 17:37:02 +00:00
|
|
|
void tst_CreationTime::controls_data()
|
|
|
|
{
|
2015-11-04 11:11:53 +00:00
|
|
|
QTest::addColumn<QUrl>("url");
|
2016-04-21 12:19:23 +00:00
|
|
|
addTestRows(&engine, "controls", "QtQuick/Controls.2", QStringList() << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator");
|
2015-11-15 15:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_CreationTime::material()
|
|
|
|
{
|
|
|
|
QFETCH(QUrl, url);
|
|
|
|
doBenchmark(&engine, url);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_CreationTime::material_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QUrl>("url");
|
2016-10-27 14:44:50 +00:00
|
|
|
addTestRows(&engine, "controls/material", "QtQuick/Controls.2/Material", QStringList() << "Ripple" << "SliderHandle" << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator" << "BoxShadow" << "ElevationEffect" << "CursorDelegate");
|
2015-01-30 19:57:40 +00:00
|
|
|
}
|
|
|
|
|
2015-10-17 15:34:31 +00:00
|
|
|
void tst_CreationTime::universal()
|
|
|
|
{
|
|
|
|
QFETCH(QUrl, url);
|
2015-11-15 15:11:58 +00:00
|
|
|
doBenchmark(&engine, url);
|
2015-10-17 15:34:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_CreationTime::universal_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QUrl>("url");
|
2016-04-21 12:19:23 +00:00
|
|
|
addTestRows(&engine, "controls/universal", "QtQuick/Controls.2/Universal", QStringList() << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator");
|
2015-10-17 15:34:31 +00:00
|
|
|
}
|
|
|
|
|
2015-07-06 17:37:02 +00:00
|
|
|
void tst_CreationTime::calendar()
|
2015-01-30 19:57:40 +00:00
|
|
|
{
|
2015-11-04 11:11:53 +00:00
|
|
|
QFETCH(QUrl, url);
|
2015-11-15 15:11:58 +00:00
|
|
|
doBenchmark(&engine, url);
|
2015-01-30 19:57:40 +00:00
|
|
|
}
|
|
|
|
|
2015-07-06 17:37:02 +00:00
|
|
|
void tst_CreationTime::calendar_data()
|
2015-01-30 19:57:40 +00:00
|
|
|
{
|
2015-11-04 11:11:53 +00:00
|
|
|
QTest::addColumn<QUrl>("url");
|
2016-04-21 12:26:07 +00:00
|
|
|
addTestRows(&engine, "calendar", "Qt/labs/calendar");
|
2015-07-06 17:37:02 +00:00
|
|
|
}
|
2015-01-30 19:57:40 +00:00
|
|
|
|
2015-04-09 14:27:44 +00:00
|
|
|
QTEST_MAIN(tst_CreationTime)
|
2015-01-30 19:57:40 +00:00
|
|
|
|
2015-04-09 14:27:44 +00:00
|
|
|
#include "tst_creationtime.moc"
|