1/****************************************************************************
2**
3** Copyright (C) 2020 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include <QtTest/QtTest>
30#include <QtQuickTest/quicktest.h>
31
32#include <QtQuick/qquickview.h>
33#include <QtQuick/private/qquickanimator_p.h>
34#include <QtQuick/private/qquickrepeater_p.h>
35#include <QtQuick/private/qquicktransition_p.h>
36
37#include "../../shared/util.h"
38#include "../shared/viewtestutil.h"
39
40using namespace QQuickViewTestUtil;
41
42class tst_Animators: public QQmlDataTest
43{
44 Q_OBJECT
45
46private slots:
47 void testMultiWinAnimator_data();
48 void testMultiWinAnimator();
49 void testTransitions();
50};
51
52void tst_Animators::testMultiWinAnimator_data()
53{
54 QTest::addColumn<int>(name: "count");
55
56 QTest::newRow(dataTag: "1") << 1;
57 QTest::newRow(dataTag: "10") << 10;
58}
59
60void tst_Animators::testMultiWinAnimator()
61{
62 QFETCH(int, count);
63
64 QQmlEngine engine;
65 QQmlComponent component(&engine, testFileUrl(fileName: "windowWithAnimator.qml"));
66
67 QList<QQuickWindow *> windows;
68 for (int i = 0; i < count; ++i) {
69 QQuickWindow *win = qobject_cast<QQuickWindow *>(object: component.create());
70 windows << win;
71
72 // As the windows are all the same size, if they are positioned at the
73 // same place only the top-most one will strictly be "exposed" and rendering
74 // for all the others will be disabled. Move the windows a little bit
75 // to ensure they are exposed and actually rendering.
76 if (i > 0) {
77 QPoint pos = win->position();
78 if (pos == windows.first()->position()) {
79 pos += QPoint(10 * i, 10 * i);
80 win->setPosition(pos);
81 }
82 }
83 }
84
85 // let all animations run their course...
86 while (true) {
87 QTest::qWait(ms: 200);
88 bool allDone = true;
89 for (int i=0; i<count; ++i) {
90 QQuickWindow *win = windows.at(i);
91 allDone = win->isExposed() && win->property(name: "animationDone").toBool();
92 }
93
94 if (allDone) {
95 for (int i=0; i<count; ++i) {
96 QQuickWindow *win = windows.at(i);
97 delete win;
98 }
99 break;
100 }
101 }
102 QVERIFY(true);
103}
104
105void tst_Animators::testTransitions()
106{
107 QScopedPointer<QQuickView> view(createView());
108 view->setSource(testFileUrl(fileName: "positionerWithAnimator.qml"));
109 view->show();
110 QVERIFY(QTest::qWaitForWindowExposed(view.data()));
111 QQuickItem *root = view->rootObject();
112 QVERIFY(root);
113
114 QQuickRepeater *repeater = root->property(name: "repeater").value<QQuickRepeater *>();
115 QVERIFY(repeater);
116
117 QQuickItem *child = repeater->itemAt(index: 0);
118 QVERIFY(child);
119 QCOMPARE(child->scale(), qreal(0));
120
121 QQuickTransition *transition = root->property(name: "transition").value<QQuickTransition *>();
122 QVERIFY(transition);
123
124 QTRY_VERIFY(transition->running());
125 QTRY_VERIFY(!transition->running());
126 QCOMPARE(child->scale(), qreal(1));
127}
128
129#include "tst_qquickanimators.moc"
130
131QTEST_MAIN(tst_Animators)
132
133

source code of qtdeclarative/tests/auto/quick/qquickanimators/tst_qquickanimators.cpp