diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-02-15 01:00:06 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2019-02-15 10:41:32 +0100 |
commit | 1ffb45a3682c864f8071b8b19da49c9a7761dd5e (patch) | |
tree | b714f329d1e2a1ecccc0d5c13fb829f924f0d801 /tests/auto/quick | |
parent | 3dcc9dde65c780fb87ff9feef60dfb16d6748eb0 (diff) | |
parent | d96a700cc3611480ff76023287cb06f455a37b02 (diff) |
Merge remote-tracking branch 'origin/5.12' into 5.13
Conflicts:
src/qml/qml/qqmlpropertycache.cpp
Change-Id: Ie7727499700b85cc0959ef3abb30d55dc728b659
Diffstat (limited to 'tests/auto/quick')
3 files changed, 168 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickcanvasitem/data/tst_strokeStyle.qml b/tests/auto/quick/qquickcanvasitem/data/tst_strokeStyle.qml index 22803a19ce..a3f1ab0a9b 100644 --- a/tests/auto/quick/qquickcanvasitem/data/tst_strokeStyle.qml +++ b/tests/auto/quick/qquickcanvasitem/data/tst_strokeStyle.qml @@ -3,6 +3,8 @@ import QtQuick 2.0 CanvasTestCase { id:testCase name: "strokeStyle" + property color anotherColor: "#0000ff" + property color emptyColor function init_data() { return testData("2d"); } function test_default(row) { var canvas = createCanvasObject(row); @@ -46,4 +48,37 @@ CanvasTestCase { comparePixel(ctx,0,0,255,255,255,255); canvas.destroy() } + function test_colorFromObjectToString(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + + ctx.reset(); + ctx.strokeStyle = anotherColor + ctx.strokeStyle = "red"; + compare(ctx.strokeStyle, "#ff0000"); + + ctx.strokeStyle = anotherColor + ctx.strokeStyle = "black"; + compare(ctx.strokeStyle, "#000000"); + + ctx.strokeStyle = "white"; + ctx.strokeStyle = anotherColor + compare(ctx.strokeStyle, "#0000ff"); + canvas.destroy() + } + function test_withInvalidColor(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + + ctx.reset(); + ctx.strokeStyle = emptyColor + compare(ctx.strokeStyle, "#000000"); + ctx.strokeStyle = "red"; + compare(ctx.strokeStyle, "#ff0000"); + ctx.strokeStyle = emptyColor + compare(ctx.strokeStyle, "#000000"); + ctx.strokeStyle = anotherColor; + compare(ctx.strokeStyle, "#0000ff"); + canvas.destroy() + } } diff --git a/tests/auto/quick/qquickvisualdatamodel/data/externalManagedModel.qml b/tests/auto/quick/qquickvisualdatamodel/data/externalManagedModel.qml new file mode 100644 index 0000000000..44c157b824 --- /dev/null +++ b/tests/auto/quick/qquickvisualdatamodel/data/externalManagedModel.qml @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the tests of the QtQuick module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** 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. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick.Window 2.2 +import QtQuick 2.6 +import QtQml.Models 2.11 +import example 1.0 + +Window { + visible: true + property bool running: rebuildTimer.running + ListView { + anchors.fill: parent + model: delegateModel + } + + DelegateModel { + id: delegateModel + model: objectsProvider.objects + delegate: Item {} + } + + Timer { + id: rebuildTimer + running: true + repeat: true + interval: 1 + + property int count: 0 + onTriggered: { + objectsProvider.rebuild(); + if (++count === 10) + running = false; + } + } + + ObjectsProvider { + id: objectsProvider + } +} diff --git a/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp index 1b8654ecdd..fac8283e2c 100644 --- a/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp +++ b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp @@ -431,6 +431,7 @@ private slots: void asynchronousMove_data(); void asynchronousCancel(); void invalidContext(); + void externalManagedModel(); private: template <int N> void groups_verify( @@ -4234,6 +4235,73 @@ void tst_qquickvisualdatamodel::invalidContext() QVERIFY(!item); } +class ObjectsProvider : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQmlListProperty<QObject> objects READ objects NOTIFY objectsChanged) + +public: + explicit ObjectsProvider(QObject *parent = nullptr) : QObject(parent) {} + + Q_INVOKABLE void rebuild() + { + for (auto old: m_objects) + old->deleteLater(); + + m_objects.clear(); + emit objectsChanged(); + + const int size = std::rand() & 0xff; + for (int i = 0; i < size; ++i) { + auto newElement = new QObject(this); + QQmlEngine::setObjectOwnership(newElement, QQmlEngine::CppOwnership); + m_objects.push_back(newElement); + } + emit objectsChanged(); + } + + Q_INVOKABLE QQmlListProperty<QObject> objects() + { + return QQmlListProperty<QObject>(this, nullptr, &ObjectsProvider::listLength, + &ObjectsProvider::listAt); + } + + static int listLength(QQmlListProperty<QObject> *property) + { + auto objectsProvider = qobject_cast<ObjectsProvider*>(property->object); + return objectsProvider ? objectsProvider->m_objects.length() : 0; + } + + static QObject* listAt(QQmlListProperty<QObject> *property, int index) + { + auto objectsProvider = qobject_cast<ObjectsProvider*>(property->object); + return objectsProvider ? objectsProvider->m_objects.at(index) : nullptr; + } + +signals: + void objectsChanged(); + +private: + QList<QObject *> m_objects; +}; + +void tst_qquickvisualdatamodel::externalManagedModel() +{ + qmlRegisterType<ObjectsProvider>("example", 1, 0, "ObjectsProvider"); + + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("externalManagedModel.qml")); + QVERIFY(component.isReady()); + + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); + + QVERIFY(object->property("running").toBool()); + + // Make sure it runs to completion without crashing. + QTRY_VERIFY(!object->property("running").toBool()); +} + QTEST_MAIN(tst_qquickvisualdatamodel) #include "tst_qquickvisualdatamodel.moc" |