@@ -18,156 +18,200 @@ public void Dispose()
1818 // TODO: Add tear down code.
1919 }
2020
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+
2341 [ Test ]
2442 public void TestEmptyConstructor ( )
2543 {
26- var s = new TestableQAbstractAnimation ( ) ;
44+ using ( new TestableQAbstractAnimation1 ( ) )
45+ {
46+ }
2747 }
28-
48+
2949 [ Test ]
3050 public void TestCurrentLoop ( )
3151 {
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+ }
3556 }
3657
3758 [ Test ]
3859 public void TestCurrentLoopTime ( )
3960 {
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+ }
4365 }
4466
4567 [ Test ]
4668 public void TestCurrentTime ( )
4769 {
48- var anim = new TestableQAbstractAnimation ( ) ;
49- Assert . AreEqual ( 0 , anim . CurrentTime ) ;
70+ using ( var anim = new TestableQAbstractAnimation ( ) )
71+ {
72+ Assert . AreEqual ( 0 , anim . CurrentTime ) ;
5073
51- anim . CurrentTime = 10 ;
52- Assert . AreEqual ( 10 , anim . CurrentTime ) ;
74+ anim . CurrentTime = 10 ;
75+ Assert . AreEqual ( 10 , anim . CurrentTime ) ;
76+ }
5377 }
5478
5579 [ Test ]
5680 public void TestDirection ( )
5781 {
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 ( ) ) ;
6185
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 ( ) ) ;
6488
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+ }
6792 }
6893
6994 [ Test ]
7095 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+ }
78104 }
79-
105+
80106 [ Test ]
81107 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 ) ;
85112
86- anim . LoopCount = 10 ;
87- Assert . AreEqual ( 10 , anim . LoopCount ) ;
113+ anim . LoopCount = 10 ;
114+ Assert . AreEqual ( 10 , anim . LoopCount ) ;
115+ }
88116 }
89117
90118 [ Test ]
91119 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+ }
95125 }
96126
97127 [ Test ]
98128 public void TestTotalDuration ( )
99129 {
100- var anim = new TestableQAbstractAnimation ( ) ;
101- Assert . AreEqual ( 10 , anim . TotalDuration ) ;
130+ using ( var anim = new TestableQAbstractAnimation ( ) )
131+ {
132+ Assert . AreEqual ( 10 , anim . TotalDuration ) ;
102133
103- anim . LoopCount = 5 ;
104- Assert . AreEqual ( 50 , anim . TotalDuration ) ;
134+ anim . LoopCount = 5 ;
135+ Assert . AreEqual ( 50 , anim . TotalDuration ) ;
136+ }
105137 }
106138
107139 [ Test ]
108140 public void TestAvoidJumpAtStart ( )
109141 {
110- var anim = new TestableQAbstractAnimation ( ) ;
111- anim . SetDuration ( 1000 ) ;
142+ using ( var anim = new TestableQAbstractAnimation ( ) )
143+ {
144+ anim . SetDuration ( 1000 ) ;
112145
113- anim . Start ( ) ;
146+ anim . Start ( ) ;
114147
115- System . Threading . Thread . Sleep ( 300 ) ;
148+ System . Threading . Thread . Sleep ( 300 ) ;
116149
117- QCoreApplication . ProcessEvents ( ) ;
118- Assert . Less ( anim . CurrentTime , 50 ) ;
150+ QCoreApplication . ProcessEvents ( ) ;
151+ Assert . Less ( anim . CurrentTime , 50 ) ;
152+ }
119153 }
120154
121155 [ Test ]
122156 public void TestAvoidJumpAtStartWithStop ( )
123157 {
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+ }
145184 }
146185
147186 [ Test ]
148187 public void TestAvoidJumpAtStartWithRunning ( )
149188 {
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+ }
171215
172216 private class TestableQAbstractAnimation : QAbstractAnimation
173217 {
0 commit comments