| 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; |
| 13 | 15 int iteration; |
| 14 static void testRepeatTimer() { | 16 |
| 15 | 17 void timeoutHandler(Timer timer) { |
| 16 void timeoutHandler(Timer timer) { | 18 int endTime = (new Date.now()).millisecondsSinceEpoch; |
| 17 int endTime = (new Date.now()).millisecondsSinceEpoch; | 19 iteration++; |
| 18 _iteration++; | 20 if (iteration < ITERATIONS) { |
| 19 if (_iteration < _ITERATIONS) { | 21 startTime = (new Date.now()).millisecondsSinceEpoch; |
| 20 _startTime = (new Date.now()).millisecondsSinceEpoch; | 22 } else { |
| 21 } else { | 23 expect(iteration, ITERATIONS); |
| 22 Expect.equals(_iteration, _ITERATIONS); | 24 timer.cancel(); |
| 23 timer.cancel(); | |
| 24 } | |
| 25 } | 25 } |
| 26 | |
| 27 _iteration = 0; | |
| 28 _startTime = (new Date.now()).millisecondsSinceEpoch; | |
| 29 timer = new Timer.repeating(_TIMEOUT, timeoutHandler); | |
| 30 } | 26 } |
| 31 | 27 |
| 32 static void testMain() { | 28 main() { |
| 33 testRepeatTimer(); | 29 test("timer_repeat", () { |
| 34 } | 30 iteration = 0; |
| 35 | 31 startTime = new Date.now().millisecondsSinceEpoch; |
| 36 static Timer timer; | 32 timer = new Timer.repeating(TIMEOUT, |
| 37 static int _startTime; | 33 expectAsync1(timeoutHandler, count: ITERATIONS)); |
| 38 static int _iteration; | 34 }); |
| 39 } | 35 } |
| 40 | |
| 41 main() { | |
| 42 TimerRepeatTest.testMain(); | |
| 43 } | |
| OLD | NEW |