Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #library('timer_cancel_test'); | 5 #library('timer_cancel_test'); |
| 6 | 6 |
| 7 #import("dart:isolate"); | 7 #import("dart:isolate"); |
| 8 | 8 #import('../../pkg/unittest/unittest.dart'); |
| 9 void testSimpleTimer() { | |
| 10 Timer cancelTimer; | |
| 11 int repeatTimer; | |
| 12 | |
| 13 void timeoutHandlerUnreachable(Timer timer) { | |
| 14 Expect.equals(true, false); | |
| 15 } | |
| 16 | |
| 17 void timeoutHandler(Timer timer) { | |
| 18 cancelTimer.cancel(); | |
| 19 } | |
| 20 | |
| 21 void timeoutHandlerRepeat(Timer timer) { | |
| 22 repeatTimer++; | |
| 23 timer.cancel(); | |
| 24 Expect.equals(true, repeatTimer == 1); | |
| 25 } | |
| 26 | |
| 27 cancelTimer = new Timer(1000, timeoutHandlerUnreachable); | |
| 28 cancelTimer.cancel(); | |
| 29 new Timer(1000, timeoutHandler); | |
| 30 cancelTimer = new Timer(2000, timeoutHandlerUnreachable); | |
| 31 repeatTimer = 0; | |
| 32 new Timer.repeating(1500, timeoutHandlerRepeat); | |
| 33 } | |
| 34 | |
| 35 void testCancelTimerWithSameTime() { | |
| 36 var t2; | |
| 37 var t1 = new Timer(0, (t) => t2.cancel()); | |
| 38 t2 = new Timer(0, (t) => t1.cancel()); | |
| 39 } | |
| 40 | 9 |
| 41 main() { | 10 main() { |
| 42 testSimpleTimer(); | 11 test("simple timer", () { |
| 43 testCancelTimerWithSameTime(); | 12 Timer cancelTimer; |
| 13 int repeatTimer; | |
| 14 | |
| 15 void timeoutHandlerUnreachable(Timer timer) { | |
| 16 print("timeoutHandlerUnreachable"); | |
| 17 expect(false, "should not be reached"); | |
| 18 } | |
| 19 | |
| 20 void timeoutHandler(Timer timer) { | |
| 21 print("timeoutHandler"); | |
| 22 cancelTimer.cancel(); | |
| 23 } | |
| 24 | |
| 25 void timeoutHandlerRepeat(Timer timer) { | |
| 26 print("timeoutHandlerRepeat"); | |
| 27 repeatTimer++; | |
| 28 timer.cancel(); | |
| 29 Expect.equals(true, repeatTimer == 1); | |
| 30 } | |
| 31 | |
| 32 cancelTimer = new Timer(1000, expectAsync1(timeoutHandlerUnreachable, count: 0)); | |
|
Siggi Cherem (dart-lang)
2012/10/08 21:50:07
80 col, the name for the callbacks are quite verbo
justinfagnani
2012/10/08 22:12:48
Done.
| |
| 33 cancelTimer.cancel(); | |
| 34 new Timer(1000, expectAsync1(timeoutHandler)); | |
| 35 cancelTimer = new Timer(2000, expectAsync1(timeoutHandlerUnreachable, count: 0)); | |
| 36 repeatTimer = 0; | |
| 37 new Timer.repeating(1500, expectAsync1(timeoutHandlerRepeat)); | |
| 38 }); | |
| 39 | |
| 40 test("cancel timer with same time", () { | |
| 41 var t2; | |
| 42 var t1 = new Timer(0, expectAsync1((t) => t2.cancel())); | |
| 43 t2 = new Timer(0, expectAsync1((t) => t1.cancel(), count: 0)); | |
| 44 }); | |
| 44 } | 45 } |
| OLD | NEW |