From af4179e3b1414420a77f10d7de1e244d7eceac4c Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Mon, 6 May 2019 15:11:49 +0200 Subject: Add tests Task-number: QDS-56 Change-Id: Iddbfc2cd9aaf1170a79a75bfd93f517f441d5f69 Reviewed-by: Tim Jenssen --- tests/auto/auto.pro | 2 +- tests/auto/qtquicktimeline/data/deltafunction.qml | 109 ++++++ .../auto/qtquicktimeline/data/parameterization.qml | 139 +++++++ tests/auto/qtquicktimeline/data/simpletest.qml | 158 ++++++++ tests/auto/qtquicktimeline/data/vectors.qml | 124 ++++++ tests/auto/qtquicktimeline/qtquicktimeline.pro | 9 + tests/auto/qtquicktimeline/tst_qtquicktimeline.cpp | 422 +++++++++++++++++++++ 7 files changed, 962 insertions(+), 1 deletion(-) create mode 100644 tests/auto/qtquicktimeline/data/deltafunction.qml create mode 100644 tests/auto/qtquicktimeline/data/parameterization.qml create mode 100644 tests/auto/qtquicktimeline/data/simpletest.qml create mode 100644 tests/auto/qtquicktimeline/data/vectors.qml create mode 100644 tests/auto/qtquicktimeline/qtquicktimeline.pro create mode 100644 tests/auto/qtquicktimeline/tst_qtquicktimeline.cpp diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index fce98ce..a36d8ea 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS = +SUBDIRS = qtquicktimeline diff --git a/tests/auto/qtquicktimeline/data/deltafunction.qml b/tests/auto/qtquicktimeline/data/deltafunction.qml new file mode 100644 index 0000000..7d5c143 --- /dev/null +++ b/tests/auto/qtquicktimeline/data/deltafunction.qml @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Timeline 1.0 + +Item { + width: 480 + height: 480 + + Timeline { + id: timeline + + objectName: "timeline" + + startFrame: 0 + endFrame: 100 + currentFrame: 0 + + enabled: true + + animations: [ + TimelineAnimation { + objectName: "animation" + id: animation + duration: 200 + loops: 1 + from: 0 + to: 100 + running: false + } + + ] + + KeyframeGroup { + objectName: "group01" + target: text + property: "text" + + Keyframe { + frame: 0 + value: "frame0" + } + + Keyframe { + frame: 50 + value: "frame50" + } + + Keyframe { + frame: 100 + value: "frame100" + } + } + } + + Text { + id: text + objectName: "text" + text: "no timeline" + } +} diff --git a/tests/auto/qtquicktimeline/data/parameterization.qml b/tests/auto/qtquicktimeline/data/parameterization.qml new file mode 100644 index 0000000..1f8d91c --- /dev/null +++ b/tests/auto/qtquicktimeline/data/parameterization.qml @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Timeline 1.0 + +Item { + id: item1 + + Timeline { + objectName: "timeline" + id: timeline + enabled: true + + startFrame: 0 + endFrame: 200 + currentFrame: input.text + KeyframeGroup { + objectName: "group01" + target: needle + property: "rotation" + Keyframe { + frame: 0 + value: 0 + } + + Keyframe { + frame: 100 + value: 90 + } + Keyframe { + frame: 200 + value: 180 + } + } + + KeyframeGroup { + target: needle + property: "color" + Keyframe { + frame: 0 + value: "blue" + } + + Keyframe { + frame: 100 + value: "green" + } + Keyframe { + frame: 200 + value: "red" + } + } + + } + + Rectangle { + id: rectangle + x: 220 + y: 140 + width: 300 + height: 300 + color: "#000000" + radius: 150 + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + + Rectangle { + objectName: "needle" + id: needle + x: 0 + y: 148 + width: 150 + height: 4 + color: "#c41616" + transformOrigin: Item.Right + } + } + + TextInput { + objectName: "textInput" + id: input + x: 207 + y: 392 + width: 227 + height: 65 + text: "10" + anchors.horizontalCenter: parent.horizontalCenter + horizontalAlignment: Text.AlignHCenter + font.pointSize: 14 + } +} diff --git a/tests/auto/qtquicktimeline/data/simpletest.qml b/tests/auto/qtquicktimeline/data/simpletest.qml new file mode 100644 index 0000000..5f88cca --- /dev/null +++ b/tests/auto/qtquicktimeline/data/simpletest.qml @@ -0,0 +1,158 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Timeline 1.0 + +Item { + Item { + width: 480 + height: 480 + + Timeline { + id: timeline + + objectName: "timeline" + + startFrame: 0 + endFrame: 100 + currentFrame: 50 + + enabled: true + + animations: [ + TimelineAnimation { + objectName: "animation" + id: animation + duration: 200 + loops: 1 + from: 0 + to: 100 + running: false + } + + ] + + KeyframeGroup { + objectName: "group01" + target: rectangle + property: "x" + + Keyframe { + frame: 0 + value: 0 + } + + Keyframe { + objectName: "keyframe" + frame: 50 + value: 100 + } + + Keyframe { + frame: 100 + value: 200 + } + } + + KeyframeGroup { + target: rectangle + property: "y" + + Keyframe { + frame: 0 + value: 0 + } + + Keyframe { + frame: 50 + value: 100 + } + + Keyframe { + objectName: "easingBounce" + frame: 100 + value: 200 + easing.type: Easing.InBounce + } + } + + KeyframeGroup { + target: rectangle + property: "color" + + Keyframe { + frame: 0 + value: "red" + } + + Keyframe { + frame: 50 + value: "blue" + } + + Keyframe { + frame: 100 + value: "yellow" + } + } + } + + Rectangle { + id: rectangle + + objectName: "rectangle" + + width: 20 + height: 20 + color: "red" + } + } +} diff --git a/tests/auto/qtquicktimeline/data/vectors.qml b/tests/auto/qtquicktimeline/data/vectors.qml new file mode 100644 index 0000000..2c9e7c0 --- /dev/null +++ b/tests/auto/qtquicktimeline/data/vectors.qml @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Timeline 1.0 + +Item { + id: item1 + + Timeline { + objectName: "timeline" + id: timeline + enabled: true + + startFrame: 0 + endFrame: 200 + currentFrame: 0 + KeyframeGroup { + objectName: "group01" + target: rotation + property: "axis.x" + Keyframe { + frame: 0 + value: 0 + } + + Keyframe { + frame: 50 + value: 1 + } + Keyframe { + frame: 100 + value: 0 + } + } + + KeyframeGroup { + target: rotation + property: "origin.x" + Keyframe { + frame: 0 + value: 0 + } + + Keyframe { + frame: 50 + value: 10 + } + Keyframe { + frame: 100 + value: 20 + } + } + + } + + Text { + id: rectangle + x: 220 + y: 140 + width: 300 + height: 300 + transform: Rotation { + id: rotation + objectName: "rotation" + origin.x: 30 + origin.y: 30 + axis.x: 0 + axis.y: 1 + axis.z: 0 + angle: 18 + } + + + } + +} diff --git a/tests/auto/qtquicktimeline/qtquicktimeline.pro b/tests/auto/qtquicktimeline/qtquicktimeline.pro new file mode 100644 index 0000000..9930a15 --- /dev/null +++ b/tests/auto/qtquicktimeline/qtquicktimeline.pro @@ -0,0 +1,9 @@ +CONFIG += testcase +QT += testlib qml quick qml-private quick-private + +TARGET = tst_qtquicktimeline + +SOURCES += \ + tst_qtquicktimeline.cpp + +DEFINES += SRCDIR=\\\"$$PWD/\\\" diff --git a/tests/auto/qtquicktimeline/tst_qtquicktimeline.cpp b/tests/auto/qtquicktimeline/tst_qtquicktimeline.cpp new file mode 100644 index 0000000..abdee2b --- /dev/null +++ b/tests/auto/qtquicktimeline/tst_qtquicktimeline.cpp @@ -0,0 +1,422 @@ +/****************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtMqtt module. +** +** $QT_BEGIN_LICENSE:GPL$ +** 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 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** 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$ +** +******************************************************************************/ + +#include +#include +#include + +#include +#include + +class Tst_QtQuickTimeline : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void checkImport(); + void simpleTest(); + void parameterization(); + void vectors(); + void deltaFunction(); + void keyframeUpdate(); + void easingcurveInterpolation(); +}; + +inline QUrl testFileUrl(const QString &fileName) +{ + static const QString dir = QTest::qFindTestData("data"); + + QString result = dir; + result += QLatin1Char('/'); + result += fileName; + + return QUrl::fromLocalFile(result); +} + +void Tst_QtQuickTimeline::checkImport() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.setData("import QtQuick 2.0; import QtQuick.Timeline 1.0; Item { }", QUrl()); + + QScopedPointer object(component.create()); + QVERIFY2(!object.isNull(), qPrintable(component.errorString())); +} + +void Tst_QtQuickTimeline::simpleTest() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("simpletest.qml")); + + QScopedPointer object(component.create()); + QVERIFY2(!object.isNull(), qPrintable(component.errorString())); + + auto *rectangle = object->findChild("rectangle"); + QVERIFY(rectangle); + + QCOMPARE(rectangle->property("width").toInt(), 20); + QCOMPARE(rectangle->property("height").toInt(), 20); + QCOMPARE(rectangle->property("color").value(), QColor("blue")); + QCOMPARE(rectangle->property("x").toInt(), 100); + QCOMPARE(rectangle->property("y").toInt(), 100); + + auto *timeline = object->findChild("timeline"); + QVERIFY(timeline); + + QCOMPARE(timeline->property("enabled").toBool(), true); + QCOMPARE(timeline->property("startFrame").toInt(), 0); + QCOMPARE(timeline->property("endFrame").toInt(), 100); + QCOMPARE(timeline->property("currentFrame").toInt(), 50); + + auto *animation = object->findChild("animation"); + QVERIFY(animation); + + QCOMPARE(animation->property("running").toBool(), false); + QCOMPARE(animation->property("duration").toInt(), 200); + QCOMPARE(animation->property("loops").toInt(), 1); + QCOMPARE(animation->property("from").toInt(), 0); + QCOMPARE(animation->property("to").toInt(), 100); + + auto *group = object->findChild("group01"); + QVERIFY(group); + + QCOMPARE(group->property("target").value(), rectangle); + + timeline->setProperty("currentFrame", 0); + + QCOMPARE(rectangle->property("color").value(), QColor("red")); + QCOMPARE(rectangle->property("x").toInt(), 0); + QCOMPARE(rectangle->property("y").toInt(), 0); + + timeline->setProperty("currentFrame", 100); + + QCOMPARE(rectangle->property("color").value(), QColor("yellow")); + QCOMPARE(rectangle->property("x").toInt(), 200); + QCOMPARE(rectangle->property("y").toInt(), 200); + + timeline->setProperty("enabled", false); + QCOMPARE(rectangle->property("color").value(), QColor("red")); + QCOMPARE(rectangle->property("x").toInt(), 0); + QCOMPARE(rectangle->property("y").toInt(), 0); + + timeline->setProperty("currentFrame", 0); + timeline->setProperty("enabled", true); + + animation->setProperty("running", true); + QCOMPARE(animation->property("running").toBool(), true); + + QTest::qWait(220); + + animation->setProperty("running", false); + QCOMPARE(timeline->property("currentFrame").toInt(), 100); +} + +void Tst_QtQuickTimeline::parameterization() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("parameterization.qml")); + + QScopedPointer object(component.create()); + QVERIFY2(!object.isNull(), qPrintable(component.errorString())); + + auto *timeline = object->findChild("timeline"); + QVERIFY(timeline); + + QCOMPARE(timeline->property("enabled").toBool(), true); + QCOMPARE(timeline->property("startFrame").toInt(), 0); + QCOMPARE(timeline->property("endFrame").toInt(), 200); + QCOMPARE(timeline->property("currentFrame").toInt(), 10); + + auto *needle = object->findChild("needle"); + QVERIFY(needle); + + QCOMPARE(needle->property("width").toInt(), 150); + QCOMPARE(needle->property("height").toInt(), 4); + QCOMPARE(needle->property("x").toInt(), 0); + QCOMPARE(needle->property("y").toInt(), 148); + + auto *group = object->findChild("group01"); + QVERIFY(group); + + QCOMPARE(group->property("target").value(), needle); + + auto *textInput = object->findChild("textInput"); + QVERIFY(textInput); + + QCOMPARE(textInput->property("text").toString(), "10"); + + textInput->setProperty("text", "0"); + + QCOMPARE(needle->property("color").value(), QColor("blue")); + + timeline->setProperty("enabled", false); + QCOMPARE(needle->property("color").value(), QColor("#c41616")); + QCOMPARE(needle->property("rotation").toInt(), 0); + timeline->setProperty("enabled", true); + + textInput->setProperty("text", "100"); + QCOMPARE(needle->property("color").value(), QColor("green")); + QCOMPARE(needle->property("rotation").toInt(), 90); + + + textInput->setProperty("text", "200"); + QCOMPARE(needle->property("color").value(), QColor("red")); + QCOMPARE(needle->property("rotation").toInt(), 180); +} + + +void Tst_QtQuickTimeline::Tst_QtQuickTimeline::vectors() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("vectors.qml")); + + QScopedPointer object(component.create()); + QVERIFY2(!object.isNull(), qPrintable(component.errorString())); + + auto *timeline = object->findChild("timeline"); + QVERIFY(timeline); + + QCOMPARE(timeline->property("enabled").toBool(), true); + QCOMPARE(timeline->property("startFrame").toInt(), 0); + QCOMPARE(timeline->property("endFrame").toInt(), 200); + QCOMPARE(timeline->property("currentFrame").toInt(), 0); + + auto *rotation = object->findChild("rotation"); + QVERIFY(rotation); + + auto vector = rotation->property("origin").value(); + + QVERIFY(!vector.isNull()); + QCOMPARE(vector.x(), 0.0); + QCOMPARE(vector.y(), 30.0); + + vector = rotation->property("axis").value(); + + QVERIFY(!vector.isNull()); + QCOMPARE(vector.x(), 0.0); + QCOMPARE(vector.y(), 1.0); + QCOMPARE(vector.z(), 0.0); + + timeline->setProperty("currentFrame", 50); + + vector = rotation->property("axis").value(); + + QVERIFY(!vector.isNull()); + QCOMPARE(vector.x(), 1.0); + QCOMPARE(vector.y(), 1.0); + QCOMPARE(vector.z(), 0.0); + + vector = rotation->property("origin").value(); + + QVERIFY(!vector.isNull()); + QCOMPARE(vector.x(), 10.0); + QCOMPARE(vector.y(), 30.0); + + timeline->setProperty("currentFrame", 100); + + vector = rotation->property("axis").value(); + + QVERIFY(!vector.isNull()); + QCOMPARE(vector.x(), 0.0); + QCOMPARE(vector.y(), 1.0); + QCOMPARE(vector.z(), 0.0); + + vector = rotation->property("origin").value(); + + QVERIFY(!vector.isNull()); + QCOMPARE(vector.x(), 20.0); + QCOMPARE(vector.y(), 30.0); + + timeline->setProperty("enabled", false); + + vector = rotation->property("origin").value(); + + QVERIFY(!vector.isNull()); + QCOMPARE(vector.x(), 30.0); + QCOMPARE(vector.y(), 30.0); +} + +void Tst_QtQuickTimeline::deltaFunction() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("deltafunction.qml")); + + QScopedPointer object(component.create()); + QVERIFY2(!object.isNull(), qPrintable(component.errorString())); + + auto *timeline = object->findChild("timeline"); + QVERIFY(timeline); + + QCOMPARE(timeline->property("enabled").toBool(), true); + QCOMPARE(timeline->property("startFrame").toInt(), 0); + QCOMPARE(timeline->property("endFrame").toInt(), 100); + QCOMPARE(timeline->property("currentFrame").toInt(), 0); + + auto *text = object->findChild("text"); + QVERIFY(text); + + QCOMPARE(text->property("text").toString(), "frame0"); + + auto *group = object->findChild("group01"); + QVERIFY(group); + + QCOMPARE(group->property("target").value(), text); + + timeline->setProperty("enabled", false); + QCOMPARE(text->property("text").toString(), "no timeline"); + + timeline->setProperty("enabled", true); + QCOMPARE(text->property("text").toString(), "frame0"); + + timeline->setProperty("currentFrame", 49); + QCOMPARE(text->property("text").toString(), "frame0"); + + timeline->setProperty("currentFrame", 50); + QCOMPARE(text->property("text").toString(), "frame50"); + + timeline->setProperty("currentFrame", 51); + QCOMPARE(text->property("text").toString(), "frame50"); + + timeline->setProperty("currentFrame", 49); + QCOMPARE(text->property("text").toString(), "frame0"); + + timeline->setProperty("currentFrame", 99); + QCOMPARE(text->property("text").toString(), "frame50"); + + timeline->setProperty("currentFrame", 100); + QCOMPARE(text->property("text").toString(), "frame100"); + + timeline->setProperty("currentFrame", 101); + QCOMPARE(text->property("text").toString(), "frame100"); +} + +void Tst_QtQuickTimeline::keyframeUpdate() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("simpletest.qml")); + + QScopedPointer object(component.create()); + QVERIFY2(!object.isNull(), qPrintable(component.errorString())); + + auto *timeline = object->findChild("timeline"); + QVERIFY(timeline); + + QCOMPARE(timeline->property("enabled").toBool(), true); + QCOMPARE(timeline->property("startFrame").toInt(), 0); + QCOMPARE(timeline->property("endFrame").toInt(), 100); + QCOMPARE(timeline->property("currentFrame").toInt(), 50); + + auto *rectangle = object->findChild("rectangle"); + QVERIFY(rectangle); + + QCOMPARE(rectangle->property("x").toInt(), 100); + + auto *keyframe = object->findChild("keyframe"); + QVERIFY(keyframe); + + QCOMPARE(keyframe->property("frame").toInt(), 50); + QCOMPARE(keyframe->property("value").toInt(), 100); + + keyframe->setProperty("value", 70); + QCOMPARE(keyframe->property("value").toInt(), 70); + QCOMPARE(rectangle->property("x").toInt(), 70); + + keyframe->setProperty("value", 90); + QCOMPARE(keyframe->property("value").toInt(), 90); + QCOMPARE(rectangle->property("x").toInt(), 90); +} + +void Tst_QtQuickTimeline::easingcurveInterpolation() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("simpletest.qml")); + + QScopedPointer object(component.create()); + QVERIFY2(!object.isNull(), qPrintable(component.errorString())); + + auto *timeline = object->findChild("timeline"); + QVERIFY(timeline); + + QCOMPARE(timeline->property("enabled").toBool(), true); + QCOMPARE(timeline->property("startFrame").toInt(), 0); + QCOMPARE(timeline->property("endFrame").toInt(), 100); + QCOMPARE(timeline->property("currentFrame").toInt(), 50); + + auto *rectangle = object->findChild("rectangle"); + QVERIFY(rectangle); + + QCOMPARE(rectangle->property("y").toInt(), 100); + + auto *keyframe = object->findChild("easingBounce"); + QVERIFY(keyframe); + + QCOMPARE(keyframe->property("frame").toInt(), 100); + QCOMPARE(keyframe->property("value").toInt(), 200); + + auto easingCurve = keyframe->property("easing").value(); + QCOMPARE(easingCurve.type(), QEasingCurve::InBounce); + + timeline->setProperty("currentFrame", 100); + QCOMPARE(rectangle->property("y").toInt(), 200); + + timeline->setProperty("currentFrame", 75); + qreal progress = easingCurve.valueForProgress(0.5); + qreal final = (1 - progress) * 100 + progress * 200; + QCOMPARE(rectangle->property("y").toReal(), final); + + timeline->setProperty("currentFrame", 90); + progress = easingCurve.valueForProgress(0.8); + final = (1 - progress) * 100 + progress * 200; + QCOMPARE(rectangle->property("y").toReal(), final); + + timeline->setProperty("currentFrame", 95); + progress = easingCurve.valueForProgress(0.9); + final = (1 - progress) * 100 + progress * 200; + QCOMPARE(rectangle->property("y").toReal(), final); + + timeline->setProperty("currentFrame", 55); + progress = easingCurve.valueForProgress(0.1); + final = (1 - progress) * 100 + progress * 200; + QCOMPARE(rectangle->property("y").toReal(), final); + + timeline->setProperty("currentFrame", 60); + progress = easingCurve.valueForProgress(0.2); + final = (1 - progress) * 100 + progress * 200; + QCOMPARE(rectangle->property("y").toReal(), final); +} + +QTEST_MAIN(Tst_QtQuickTimeline) + +#include "tst_qtquicktimeline.moc" -- cgit v1.2.3