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_repeat_test'); | 5 #library('timer_repeat_test'); |
| 6 | 6 |
| 7 #import("dart:isolate"); | 7 #import("dart:isolate"); |
| 8 #import('../../pkg/unittest/unittest.dart'); | |
| 8 | 9 |
| 9 class TimerRepeatTest { | 10 const int _TIMEOUT = 500; |
| 11 const int _ITERATIONS = 5; | |
| 10 | 12 |
| 11 static const int _TIMEOUT = 500; | 13 Timer timer; |
| 12 static const int _ITERATIONS = 5; | 14 int _startTime; |
| 15 int _iteration; | |
| 16 | |
| 17 void timeoutHandler(Timer timer) { | |
| 18 int endTime = (new Date.now()).millisecondsSinceEpoch; | |
| 19 _iteration++; | |
| 20 if (_iteration < _ITERATIONS) { | |
| 21 _startTime = (new Date.now()).millisecondsSinceEpoch; | |
| 22 } else { | |
| 23 expect(_iteration, _ITERATIONS); | |
| 24 timer.cancel(); | |
| 25 } | |
| 26 } | |
| 13 | 27 |
| 14 static void testRepeatTimer() { | 28 main() { |
| 15 | 29 test("timer_repeat", () { |
| 16 void timeoutHandler(Timer timer) { | |
| 17 int endTime = (new Date.now()).millisecondsSinceEpoch; | |
| 18 _iteration++; | |
| 19 if (_iteration < _ITERATIONS) { | |
| 20 _startTime = (new Date.now()).millisecondsSinceEpoch; | |
| 21 } else { | |
| 22 Expect.equals(_iteration, _ITERATIONS); | |
| 23 timer.cancel(); | |
| 24 } | |
| 25 } | |
| 26 | |
| 27 _iteration = 0; | 30 _iteration = 0; |
| 28 _startTime = (new Date.now()).millisecondsSinceEpoch; | 31 _startTime = (new Date.now()).millisecondsSinceEpoch; |
| 29 timer = new Timer.repeating(_TIMEOUT, timeoutHandler); | 32 timer = new Timer.repeating(_TIMEOUT, expectAsync1(timeoutHandler, count: _I TERATIONS)); |
|
Siggi Cherem (dart-lang)
2012/10/08 21:50:07
80 col
justinfagnani
2012/10/08 22:12:48
Done.
| |
| 30 } | 33 }); |
| 31 | |
| 32 static void testMain() { | |
| 33 testRepeatTimer(); | |
| 34 } | |
| 35 | |
| 36 static Timer timer; | |
| 37 static int _startTime; | |
| 38 static int _iteration; | |
| 39 } | 34 } |
| 40 | |
| 41 main() { | |
| 42 TimerRepeatTest.testMain(); | |
| 43 } | |
| OLD | NEW |