| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2016 The Qt Company Ltd. |
| 4 |
** Contact: https://www.qt.io/licensing/ |
| 5 |
** |
| 6 |
** This file is part of the test suite module 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 <QtWidgets> |
| 30 |
#include <qtest.h> |
| 31 |
|
| 32 |
#include "dummyobject.h" |
| 33 |
#include "dummyanimation.h" |
| 34 |
#include "rectanimation.h" |
| 35 |
|
| 36 |
#define ITERATION_COUNT 10e3 |
| 37 |
|
| 38 |
class tst_qanimation : public QObject |
| 39 |
{ |
| 40 |
Q_OBJECT |
| 41 |
private slots: |
| 42 |
void itemPropertyAnimation(); |
| 43 |
void itemPropertyAnimation_data() { data();} |
| 44 |
void dummyAnimation(); |
| 45 |
void dummyAnimation_data() { data();} |
| 46 |
void dummyPropertyAnimation(); |
| 47 |
void dummyPropertyAnimation_data() { data();} |
| 48 |
void rectAnimation(); |
| 49 |
void rectAnimation_data() { data();} |
| 50 |
|
| 51 |
void floatAnimation_data() { data(); } |
| 52 |
void floatAnimation(); |
| 53 |
|
| 54 |
private: |
| 55 |
void data(); |
| 56 |
}; |
| 57 |
|
| 58 |
|
| 59 |
void tst_qanimation::data() |
| 60 |
{ |
| 61 |
QTest::addColumn<bool>("started"); |
| 62 |
QTest::newRow("NotRunning") << false; |
| 63 |
QTest::newRow("Running") << true; |
| 64 |
} |
| 65 |
|
| 66 |
void tst_qanimation::itemPropertyAnimation() |
| 67 |
{ |
| 68 |
QFETCH(bool, started); |
| 69 |
QGraphicsWidget item; |
| 70 |
|
| 71 |
//then the property animation |
| 72 |
{ |
| 73 |
QPropertyAnimation anim(&item, "pos"); |
| 74 |
anim.setDuration(ITERATION_COUNT); |
| 75 |
anim.setStartValue(QPointF(0,0)); |
| 76 |
anim.setEndValue(QPointF(ITERATION_COUNT,ITERATION_COUNT)); |
| 77 |
if (started) |
| 78 |
anim.start(); |
| 79 |
QBENCHMARK { |
| 80 |
for(int i = 0; i < ITERATION_COUNT; ++i) { |
| 81 |
anim.setCurrentTime(i); |
| 82 |
} |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
} |
| 87 |
|
| 88 |
void tst_qanimation::dummyAnimation() |
| 89 |
{ |
| 90 |
QFETCH(bool, started); |
| 91 |
DummyObject dummy; |
| 92 |
|
| 93 |
//first the dummy animation |
| 94 |
{ |
| 95 |
DummyAnimation anim(&dummy); |
| 96 |
anim.setDuration(ITERATION_COUNT); |
| 97 |
anim.setStartValue(QRect(0, 0, 0, 0)); |
| 98 |
anim.setEndValue(QRect(0, 0, ITERATION_COUNT,ITERATION_COUNT)); |
| 99 |
if (started) |
| 100 |
anim.start(); |
| 101 |
QBENCHMARK { |
| 102 |
for(int i = 0; i < anim.duration(); ++i) { |
| 103 |
anim.setCurrentTime(i); |
| 104 |
} |
| 105 |
} |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
void tst_qanimation::dummyPropertyAnimation() |
| 110 |
{ |
| 111 |
QFETCH(bool, started); |
| 112 |
DummyObject dummy; |
| 113 |
|
| 114 |
//then the property animation |
| 115 |
{ |
| 116 |
QPropertyAnimation anim(&dummy, "rect"); |
| 117 |
anim.setDuration(ITERATION_COUNT); |
| 118 |
anim.setStartValue(QRect(0, 0, 0, 0)); |
| 119 |
anim.setEndValue(QRect(0, 0, ITERATION_COUNT,ITERATION_COUNT)); |
| 120 |
if (started) |
| 121 |
anim.start(); |
| 122 |
QBENCHMARK { |
| 123 |
for(int i = 0; i < ITERATION_COUNT; ++i) { |
| 124 |
anim.setCurrentTime(i); |
| 125 |
} |
| 126 |
} |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
void tst_qanimation::rectAnimation() |
| 131 |
{ |
| 132 |
//this is the simplest animation you can do |
| 133 |
QFETCH(bool, started); |
| 134 |
DummyObject dummy; |
| 135 |
|
| 136 |
//then the property animation |
| 137 |
{ |
| 138 |
RectAnimation anim(&dummy); |
| 139 |
anim.setDuration(ITERATION_COUNT); |
| 140 |
anim.setStartValue(QRect(0, 0, 0, 0)); |
| 141 |
anim.setEndValue(QRect(0, 0, ITERATION_COUNT,ITERATION_COUNT)); |
| 142 |
if (started) |
| 143 |
anim.start(); |
| 144 |
QBENCHMARK { |
| 145 |
for(int i = 0; i < ITERATION_COUNT; ++i) { |
| 146 |
anim.setCurrentTime(i); |
| 147 |
} |
| 148 |
} |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
void tst_qanimation::floatAnimation() |
| 153 |
{ |
| 154 |
//this is the simplest animation you can do |
| 155 |
QFETCH(bool, started); |
| 156 |
DummyObject dummy; |
| 157 |
|
| 158 |
//then the property animation |
| 159 |
{ |
| 160 |
QPropertyAnimation anim(&dummy, "opacity"); |
| 161 |
anim.setDuration(ITERATION_COUNT); |
| 162 |
anim.setStartValue(0.f); |
| 163 |
anim.setEndValue(1.f); |
| 164 |
if (started) |
| 165 |
anim.start(); |
| 166 |
QBENCHMARK { |
| 167 |
for(int i = 0; i < ITERATION_COUNT; ++i) { |
| 168 |
anim.setCurrentTime(i); |
| 169 |
} |
| 170 |
} |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
QTEST_MAIN(tst_qanimation) |
| 177 |
|
| 178 |
#include "main.moc" |