on ac4b821 help sign in
unity8/tests/qmltests/Components/tst_AnimationControllerWithSignals.qml
142 lines 4.2 kB history raw
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17import QtQuick 2.0
18import QtTest 1.0
19import "../../../qml/Components"
21TestCase {
22 id: testCase
23 name: "AnimationControllerWithSignals"
25 property real someNumber: 0.0
27 NumberAnimation {
28 id: someNumberAnimation
29 target: testCase
30 properties: "someNumber"
31 from: 1.0
32 to: 100.0
33 }
35 Component {
36 id: testSubjectComponent
37 AnimationControllerWithSignals {}
38 }
40 Loader {
41 id: loader
42 asynchronous: false
43 }
45 SignalSpy {
46 id: signalSpy
47 }
49 function test_completeToEndWithSignal() {
50 loader.sourceComponent = testSubjectComponent;
51 var testSubject = loader.item;
53 testSubject.animation = someNumberAnimation;
54 testSubject.progress = 0;
56 signalSpy.signalName = "animationCompletedAtEnd";
57 signalSpy.target = testSubject;
58 signalSpy.clear();
60 compare(testSubject.completing, false)
61 compare(testSubject.completed, true)
63 testSubject.completeToEndWithSignal();
64 compare(testSubject.completing, true)
65 compare(testSubject.completed, true)
66 compare(signalSpy.count, 0);
68 testSubject.progress = 0.5;
69 compare(testSubject.completing, true)
70 compare(testSubject.completed, false)
71 compare(signalSpy.count, 0);
73 testSubject.progress = 1.0;
74 compare(testSubject.completing, false)
75 compare(testSubject.completed, true)
76 compare(signalSpy.count, 1);
78 testSubject.animation = null
79 loader.sourceComponent = undefined;
80 }
82 function test_completeToBeginningWithSignal() {
83 loader.sourceComponent = testSubjectComponent;
84 var testSubject = loader.item;
86 testSubject.animation = someNumberAnimation;
87 testSubject.progress = 1;
89 signalSpy.signalName = "animationCompletedAtBeginning";
90 signalSpy.target = testSubject;
91 signalSpy.clear();
93 compare(testSubject.completing, false)
94 compare(testSubject.completed, true)
96 testSubject.completeToBeginningWithSignal();
97 compare(testSubject.completing, true)
98 compare(testSubject.completed, true)
99 compare(signalSpy.count, 0);
101 testSubject.progress = 0.5;
102 compare(testSubject.completing, true)
103 compare(testSubject.completed, false)
104 compare(signalSpy.count, 0);
106 testSubject.progress = 0;
107 compare(testSubject.completing, false)
108 compare(testSubject.completed, true)
109 compare(signalSpy.count, 1);
111 testSubject.animation = null
112 loader.sourceComponent = undefined;
113 }
115 function test_settingProgressWithoutCallingCompleteWithSignal() {
116 loader.sourceComponent = testSubjectComponent;
117 var testSubject = loader.item;
119 testSubject.animation = someNumberAnimation;
120 testSubject.progress = 0;
122 signalSpy.signalName = "animationCompletedAtEnd";
123 signalSpy.target = testSubject;
124 signalSpy.clear();
126 compare(testSubject.completing, false)
127 compare(testSubject.completed, true)
129 testSubject.progress = 0.5;
130 compare(testSubject.completing, false)
131 compare(testSubject.completed, false)
132 compare(signalSpy.count, 0);
134 testSubject.progress = 1;
135 compare(testSubject.completing, false)
136 compare(testSubject.completed, true)
137 compare(signalSpy.count, 0);
139 testSubject.animation = null
140 loader.sourceComponent = undefined;
141 }