| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library multiple_timer_test; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 import '../../pkg/unittest/lib/unittest.dart'; | |
| 9 | |
| 10 const Duration TIMEOUT1 = const Duration(seconds: 1); | |
| 11 const Duration TIMEOUT2 = const Duration(seconds: 2); | |
| 12 const Duration TIMEOUT3 = const Duration(milliseconds: 500); | |
| 13 const Duration TIMEOUT4 = const Duration(milliseconds: 1500); | |
| 14 | |
| 15 main() { | |
| 16 test("multiple timer test", () { | |
| 17 Stopwatch _stopwatch1 = new Stopwatch(); | |
| 18 Stopwatch _stopwatch2 = new Stopwatch(); | |
| 19 Stopwatch _stopwatch3 = new Stopwatch(); | |
| 20 Stopwatch _stopwatch4 = new Stopwatch(); | |
| 21 List<int> _order; | |
| 22 int _message; | |
| 23 | |
| 24 void timeoutHandler1() { | |
| 25 // The stopwatch is more precise than the Timer. It can happen that | |
| 26 // the TIMEOUT triggers *slightly* too early. | |
| 27 expect(_stopwatch1.elapsedMilliseconds + 1, | |
| 28 greaterThanOrEqualTo(TIMEOUT1.inMilliseconds)); | |
| 29 expect(_order[_message], 0); | |
| 30 _message++; | |
| 31 } | |
| 32 | |
| 33 void timeoutHandler2() { | |
| 34 // The stopwatch is more precise than the Timer. It can happen that | |
| 35 // the TIMEOUT triggers *slightly* too early. | |
| 36 expect(_stopwatch2.elapsedMilliseconds + 1, | |
| 37 greaterThanOrEqualTo(TIMEOUT2.inMilliseconds)); | |
| 38 expect(_order[_message], 1); | |
| 39 _message++; | |
| 40 } | |
| 41 | |
| 42 void timeoutHandler3() { | |
| 43 // The stopwatch is more precise than the Timer. It can happen that | |
| 44 // the TIMEOUT triggers *slightly* too early. | |
| 45 expect(_stopwatch3.elapsedMilliseconds + 1, | |
| 46 greaterThanOrEqualTo(TIMEOUT3.inMilliseconds)); | |
| 47 expect(_order[_message], 2); | |
| 48 _message++; | |
| 49 } | |
| 50 | |
| 51 void timeoutHandler4() { | |
| 52 // The stopwatch is more precise than the Timer. It can happen that | |
| 53 // the TIMEOUT triggers *slightly* too early. | |
| 54 expect(_stopwatch4.elapsedMilliseconds + 1, | |
| 55 greaterThanOrEqualTo(TIMEOUT4.inMilliseconds)); | |
| 56 expect(_order[_message], 3); | |
| 57 _message++; | |
| 58 } | |
| 59 | |
| 60 _order = new List<int>(4); | |
| 61 _order[0] = 2; | |
| 62 _order[1] = 0; | |
| 63 _order[2] = 3; | |
| 64 _order[3] = 1; | |
| 65 _message = 0; | |
| 66 | |
| 67 _stopwatch1.start(); | |
| 68 new Timer(TIMEOUT1, expectAsync0(timeoutHandler1)); | |
| 69 _stopwatch2.start(); | |
| 70 new Timer(TIMEOUT2, expectAsync0(timeoutHandler2)); | |
| 71 _stopwatch3.start(); | |
| 72 new Timer(TIMEOUT3, expectAsync0(timeoutHandler3)); | |
| 73 _stopwatch4.start(); | |
| 74 new Timer(TIMEOUT4, expectAsync0(timeoutHandler4)); | |
| 75 }); | |
| 76 } | |
| OLD | NEW |