@@ -18,156 +18,200 @@ public void Dispose()
18
18
// TODO: Add tear down code.
19
19
}
20
20
21
- // BUG: disposing of any of the animations crashes - the function pointer is null; there's something wrong when constructing custom classes
22
-
21
+ private class TestableQAbstractAnimation1 : QAbstractAnimation
22
+ {
23
+ private int duration = 10 ;
24
+
25
+ public override int Duration
26
+ {
27
+ get { return this . duration ; }
28
+ }
29
+
30
+ protected override void UpdateCurrentTime ( int value )
31
+ {
32
+
33
+ }
34
+
35
+ public void SetDuration ( int val )
36
+ {
37
+ this . duration = val ;
38
+ }
39
+ }
40
+
23
41
[ Test ]
24
42
public void TestEmptyConstructor ( )
25
43
{
26
- var s = new TestableQAbstractAnimation ( ) ;
44
+ using ( new TestableQAbstractAnimation1 ( ) )
45
+ {
46
+ }
27
47
}
28
-
48
+
29
49
[ Test ]
30
50
public void TestCurrentLoop ( )
31
51
{
32
- var anim = new TestableQAbstractAnimation ( ) ;
33
-
34
- Assert . AreEqual ( 0 , anim . CurrentLoop ) ;
52
+ using ( var anim = new TestableQAbstractAnimation ( ) )
53
+ {
54
+ Assert . AreEqual ( 0 , anim . CurrentLoop ) ;
55
+ }
35
56
}
36
57
37
58
[ Test ]
38
59
public void TestCurrentLoopTime ( )
39
60
{
40
- var anim = new TestableQAbstractAnimation ( ) ;
41
-
42
- Assert . AreEqual ( 0 , anim . CurrentLoopTime ) ;
61
+ using ( var anim = new TestableQAbstractAnimation ( ) )
62
+ {
63
+ Assert . AreEqual ( 0 , anim . CurrentLoopTime ) ;
64
+ }
43
65
}
44
66
45
67
[ Test ]
46
68
public void TestCurrentTime ( )
47
69
{
48
- var anim = new TestableQAbstractAnimation ( ) ;
49
- Assert . AreEqual ( 0 , anim . CurrentTime ) ;
70
+ using ( var anim = new TestableQAbstractAnimation ( ) )
71
+ {
72
+ Assert . AreEqual ( 0 , anim . CurrentTime ) ;
50
73
51
- anim . CurrentTime = 10 ;
52
- Assert . AreEqual ( 10 , anim . CurrentTime ) ;
74
+ anim . CurrentTime = 10 ;
75
+ Assert . AreEqual ( 10 , anim . CurrentTime ) ;
76
+ }
53
77
}
54
78
55
79
[ Test ]
56
80
public void TestDirection ( )
57
81
{
58
- var anim = new TestableQAbstractAnimation ( ) ;
59
-
60
- Assert . AreEqual ( QAbstractAnimation . Direction . Forward . ToString ( ) , anim . direction . ToString ( ) ) ;
82
+ using ( var anim = new TestableQAbstractAnimation ( ) )
83
+ {
84
+ Assert . AreEqual ( QAbstractAnimation . Direction . Forward . ToString ( ) , anim . direction . ToString ( ) ) ;
61
85
62
- anim . direction = QAbstractAnimation . Direction . Backward ;
63
- Assert . AreEqual ( QAbstractAnimation . Direction . Backward . ToString ( ) , anim . direction . ToString ( ) ) ;
86
+ anim . direction = QAbstractAnimation . Direction . Backward ;
87
+ Assert . AreEqual ( QAbstractAnimation . Direction . Backward . ToString ( ) , anim . direction . ToString ( ) ) ;
64
88
65
- anim . direction = QAbstractAnimation . Direction . Forward ;
66
- Assert . AreEqual ( QAbstractAnimation . Direction . Forward . ToString ( ) , anim . direction . ToString ( ) ) ;
89
+ anim . direction = QAbstractAnimation . Direction . Forward ;
90
+ Assert . AreEqual ( QAbstractAnimation . Direction . Forward . ToString ( ) , anim . direction . ToString ( ) ) ;
91
+ }
67
92
}
68
93
69
94
[ Test ]
70
95
public void TestGroup ( )
71
- {
72
- var anim = new TestableQAbstractAnimation ( ) ;
73
- var group = new DummyQAnimationGroup ( ) ;
74
-
75
- group . AddAnimation ( anim ) ;
76
-
77
- Assert . AreSame ( group , anim . Group ) ;
96
+ {
97
+ var anim = new TestableQAbstractAnimation ( ) ;
98
+ using ( var group = new DummyQAnimationGroup ( ) )
99
+ {
100
+ @group . AddAnimation ( anim ) ;
101
+
102
+ Assert . AreSame ( @group , anim . Group ) ;
103
+ }
78
104
}
79
-
105
+
80
106
[ Test ]
81
107
public void TestLoopCount ( )
82
- {
83
- var anim = new TestableQAbstractAnimation ( ) ;
84
- Assert . AreEqual ( 1 , anim . LoopCount ) ;
108
+ {
109
+ using ( var anim = new TestableQAbstractAnimation ( ) )
110
+ {
111
+ Assert . AreEqual ( 1 , anim . LoopCount ) ;
85
112
86
- anim . LoopCount = 10 ;
87
- Assert . AreEqual ( 10 , anim . LoopCount ) ;
113
+ anim . LoopCount = 10 ;
114
+ Assert . AreEqual ( 10 , anim . LoopCount ) ;
115
+ }
88
116
}
89
117
90
118
[ Test ]
91
119
public void TestState ( )
92
- {
93
- var anim = new TestableQAbstractAnimation ( ) ;
94
- Assert . AreEqual ( QAbstractAnimation . State . Stopped , anim . state ) ;
120
+ {
121
+ using ( var anim = new TestableQAbstractAnimation ( ) )
122
+ {
123
+ Assert . AreEqual ( QAbstractAnimation . State . Stopped , anim . state ) ;
124
+ }
95
125
}
96
126
97
127
[ Test ]
98
128
public void TestTotalDuration ( )
99
129
{
100
- var anim = new TestableQAbstractAnimation ( ) ;
101
- Assert . AreEqual ( 10 , anim . TotalDuration ) ;
130
+ using ( var anim = new TestableQAbstractAnimation ( ) )
131
+ {
132
+ Assert . AreEqual ( 10 , anim . TotalDuration ) ;
102
133
103
- anim . LoopCount = 5 ;
104
- Assert . AreEqual ( 50 , anim . TotalDuration ) ;
134
+ anim . LoopCount = 5 ;
135
+ Assert . AreEqual ( 50 , anim . TotalDuration ) ;
136
+ }
105
137
}
106
138
107
139
[ Test ]
108
140
public void TestAvoidJumpAtStart ( )
109
141
{
110
- var anim = new TestableQAbstractAnimation ( ) ;
111
- anim . SetDuration ( 1000 ) ;
142
+ using ( var anim = new TestableQAbstractAnimation ( ) )
143
+ {
144
+ anim . SetDuration ( 1000 ) ;
112
145
113
- anim . Start ( ) ;
146
+ anim . Start ( ) ;
114
147
115
- System . Threading . Thread . Sleep ( 300 ) ;
148
+ System . Threading . Thread . Sleep ( 300 ) ;
116
149
117
- QCoreApplication . ProcessEvents ( ) ;
118
- Assert . Less ( anim . CurrentTime , 50 ) ;
150
+ QCoreApplication . ProcessEvents ( ) ;
151
+ Assert . Less ( anim . CurrentTime , 50 ) ;
152
+ }
119
153
}
120
154
121
155
[ Test ]
122
156
public void TestAvoidJumpAtStartWithStop ( )
123
157
{
124
- var anim = new TestableQAbstractAnimation ( ) ;
125
- anim . SetDuration ( 1000 ) ;
126
-
127
- var anim2 = new TestableQAbstractAnimation ( ) ;
128
- anim2 . SetDuration ( 1000 ) ;
129
-
130
- var anim3 = new TestableQAbstractAnimation ( ) ;
131
- anim3 . SetDuration ( 1000 ) ;
132
-
133
- anim . Start ( ) ;
134
- System . Threading . Thread . Sleep ( 300 ) ;
135
- anim . Stop ( ) ;
136
-
137
- anim2 . Start ( ) ;
138
- System . Threading . Thread . Sleep ( 300 ) ;
139
- anim3 . Start ( ) ;
140
-
141
-
142
- QCoreApplication . ProcessEvents ( ) ;
143
- Assert . Less ( anim2 . CurrentTime , 50 ) ;
144
- Assert . Less ( anim3 . CurrentTime , 50 ) ;
158
+ using ( var anim = new TestableQAbstractAnimation ( ) )
159
+ {
160
+ anim . SetDuration ( 1000 ) ;
161
+
162
+ using ( var anim2 = new TestableQAbstractAnimation ( ) )
163
+ {
164
+ anim2 . SetDuration ( 1000 ) ;
165
+
166
+ using ( var anim3 = new TestableQAbstractAnimation ( ) )
167
+ {
168
+ anim3 . SetDuration ( 1000 ) ;
169
+
170
+ anim . Start ( ) ;
171
+ System . Threading . Thread . Sleep ( 300 ) ;
172
+ anim . Stop ( ) ;
173
+
174
+ anim2 . Start ( ) ;
175
+ System . Threading . Thread . Sleep ( 300 ) ;
176
+ anim3 . Start ( ) ;
177
+
178
+ QCoreApplication . ProcessEvents ( ) ;
179
+ Assert . Less ( anim2 . CurrentTime , 50 ) ;
180
+ Assert . Less ( anim3 . CurrentTime , 50 ) ;
181
+ }
182
+ }
183
+ }
145
184
}
146
185
147
186
[ Test ]
148
187
public void TestAvoidJumpAtStartWithRunning ( )
149
188
{
150
- var anim = new TestableQAbstractAnimation ( ) ;
151
- anim . SetDuration ( 2000 ) ;
152
-
153
- var anim2 = new TestableQAbstractAnimation ( ) ;
154
- anim2 . SetDuration ( 1000 ) ;
155
-
156
- var anim3 = new TestableQAbstractAnimation ( ) ;
157
- anim3 . SetDuration ( 1000 ) ;
158
-
159
- anim . Start ( ) ;
160
- System . Threading . Thread . Sleep ( 300 ) ;
161
-
162
- anim2 . Start ( ) ;
163
- System . Threading . Thread . Sleep ( 300 ) ;
164
- anim3 . Start ( ) ;
165
-
166
-
167
- QCoreApplication . ProcessEvents ( ) ;
168
- Assert . Less ( anim2 . CurrentTime , 50 ) ;
169
- Assert . Less ( anim3 . CurrentTime , 50 ) ;
170
- }
189
+ using ( var anim = new TestableQAbstractAnimation ( ) )
190
+ {
191
+ anim . SetDuration ( 2000 ) ;
192
+
193
+ using ( var anim2 = new TestableQAbstractAnimation ( ) )
194
+ {
195
+ anim2 . SetDuration ( 1000 ) ;
196
+
197
+ using ( var anim3 = new TestableQAbstractAnimation ( ) )
198
+ {
199
+ anim3 . SetDuration ( 1000 ) ;
200
+
201
+ anim . Start ( ) ;
202
+ System . Threading . Thread . Sleep ( 300 ) ;
203
+
204
+ anim2 . Start ( ) ;
205
+ System . Threading . Thread . Sleep ( 300 ) ;
206
+ anim3 . Start ( ) ;
207
+
208
+ QCoreApplication . ProcessEvents ( ) ;
209
+ Assert . Less ( anim2 . CurrentTime , 50 ) ;
210
+ Assert . Less ( anim3 . CurrentTime , 50 ) ;
211
+ }
212
+ }
213
+ }
214
+ }
171
215
172
216
private class TestableQAbstractAnimation : QAbstractAnimation
173
217
{
0 commit comments