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("CountTest"); | 5 library CountTest; |
6 #import('dart:isolate'); | 6 import '../../pkg/unittest/lib/unittest.dart'; |
7 #import('../../pkg/unittest/unittest.dart'); | 7 import 'dart:isolate'; |
8 | 8 |
9 void countMessages() { | 9 void countMessages() { |
10 int count = 0; | 10 int count = 0; |
11 port.receive((int message, SendPort replyTo) { | 11 port.receive((int message, SendPort replyTo) { |
12 if (message == -1) { | 12 if (message == -1) { |
13 Expect.equals(10, count); | 13 expect(count, 10); |
14 replyTo.send(-1, null); | 14 replyTo.send(-1, null); |
15 port.close(); | 15 port.close(); |
16 return; | 16 return; |
17 } | 17 } |
18 Expect.equals(count, message); | 18 expect(message, count); |
19 count++; | 19 count++; |
20 replyTo.send(message * 2, null); | 20 replyTo.send(message * 2, null); |
21 }); | 21 }); |
22 } | 22 } |
23 | 23 |
24 void main() { | 24 void main() { |
25 test("count 10 consecutive messages", () { | 25 test("count 10 consecutive messages", () { |
26 int count = 0; | 26 int count = 0; |
27 SendPort remote = spawnFunction(countMessages); | 27 SendPort remote = spawnFunction(countMessages); |
28 ReceivePort local = new ReceivePort(); | 28 ReceivePort local = new ReceivePort(); |
29 SendPort reply = local.toSendPort(); | 29 SendPort reply = local.toSendPort(); |
30 | 30 |
31 local.receive(expectAsync2((int message, SendPort replyTo) { | 31 local.receive(expectAsync2((int message, SendPort replyTo) { |
32 if (message == -1) { | 32 if (message == -1) { |
33 Expect.equals(11, count); | 33 expect(count, 11); |
34 local.close(); | 34 local.close(); |
35 return; | 35 return; |
36 } | 36 } |
37 | 37 |
38 Expect.equals((count - 1) * 2, message); | 38 expect(message, (count - 1) * 2); |
39 remote.send(count++, reply); | 39 remote.send(count++, reply); |
40 if (count == 10) { | 40 if (count == 10) { |
41 remote.send(-1, reply); | 41 remote.send(-1, reply); |
42 } | 42 } |
43 }, 11)); | 43 }, 11)); |
44 remote.send(count++, reply); | 44 remote.send(count++, reply); |
45 }); | 45 }); |
46 } | 46 } |
OLD | NEW |