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 #import("dart:io"); | |
6 | |
7 class MultipleTimerTest { | |
8 | |
9 static final int TIMEOUT1 = 1000; | |
10 static final int TIMEOUT2 = 2000; | |
11 static final int TIMEOUT3 = 500; | |
12 static final int TIMEOUT4 = 1500; | |
13 | |
14 static void testMultipleTimer() { | |
15 | |
16 void timeoutHandler1(Timer timer) { | |
17 int endTime = (new Date.now()).value; | |
18 Expect.equals(true, (endTime - _startTime1) >= TIMEOUT1); | |
19 Expect.equals(true, _order[_message] == 0); | |
20 _message++; | |
21 } | |
22 | |
23 void timeoutHandler2(Timer timer) { | |
24 int endTime = (new Date.now()).value; | |
25 Expect.equals(true, (endTime - _startTime2) >= TIMEOUT2); | |
26 Expect.equals(true, _order[_message] == 1); | |
27 _message++; | |
28 } | |
29 | |
30 void timeoutHandler3(Timer timer) { | |
31 int endTime = (new Date.now()).value; | |
32 Expect.equals(true, (endTime - _startTime3) >= TIMEOUT3); | |
33 Expect.equals(true, _order[_message] == 2); | |
34 _message++; | |
35 } | |
36 | |
37 void timeoutHandler4(Timer timer) { | |
38 int endTime = (new Date.now()).value; | |
39 Expect.equals(true, (endTime - _startTime4) >= TIMEOUT4); | |
40 Expect.equals(true, _order[_message] == 3); | |
41 _message++; | |
42 } | |
43 | |
44 _order = new List<int>(4); | |
45 _order[0] = 2; | |
46 _order[1] = 0; | |
47 _order[2] = 3; | |
48 _order[3] = 1; | |
49 _message = 0; | |
50 | |
51 _startTime1 = (new Date.now()).value; | |
52 new Timer(TIMEOUT1, timeoutHandler1); | |
53 _startTime2 = (new Date.now()).value; | |
54 new Timer(TIMEOUT2, timeoutHandler2); | |
55 _startTime3 = (new Date.now()).value; | |
56 new Timer(TIMEOUT3, timeoutHandler3); | |
57 _startTime4 = (new Date.now()).value; | |
58 new Timer(TIMEOUT4, timeoutHandler4); | |
59 } | |
60 | |
61 static void testMain() { | |
62 testMultipleTimer(); | |
63 } | |
64 | |
65 static int _startTime1; | |
66 static int _startTime2; | |
67 static int _startTime3; | |
68 static int _startTime4; | |
69 static List<int> _order; | |
70 static int _message; | |
71 } | |
72 | |
73 main() { | |
74 MultipleTimerTest.testMain(); | |
75 } | |
OLD | NEW |