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 '../../pkg/unittest/lib/unittest.dart'; | |
7 import 'dart:isolate'; | 6 import 'dart:isolate'; |
| 7 import 'package:unittest/unittest.dart'; |
| 8 import "remote_unittest_helper.dart"; |
8 | 9 |
9 void countMessages(replyTo) { | 10 void countMessages(replyTo) { |
10 int count = 0; | 11 int count = 0; |
11 var port = new ReceivePort(); | 12 var port = new ReceivePort(); |
12 replyTo.send(["init", port.sendPort]); | 13 replyTo.send(["init", port.sendPort]); |
13 port.listen((int message) { | 14 port.listen((int message) { |
14 if (message == -1) { | 15 if (message == -1) { |
15 expect(count, 10); | 16 expect(count, 10); |
16 replyTo.send(["done"]); | 17 replyTo.send(["done"]); |
17 port.close(); | 18 port.close(); |
18 return; | 19 return; |
19 } | 20 } |
20 count++; | 21 count++; |
21 expect(message, count); | 22 expect(message, count); |
22 replyTo.send(["count", message * 2]); | 23 replyTo.send(["count", message * 2]); |
23 }); | 24 }); |
24 } | 25 } |
25 | 26 |
26 void main() { | 27 void main([args, port]) { |
| 28 if (testRemote(main, port)) return; |
27 test("count 10 consecutive messages", () { | 29 test("count 10 consecutive messages", () { |
28 ReceivePort local = new ReceivePort(); | 30 ReceivePort local = new ReceivePort(); |
29 Isolate.spawn(countMessages, local.sendPort); | 31 Isolate.spawn(countMessages, local.sendPort); |
30 SendPort remote; | 32 SendPort remote; |
31 int count = 0; | 33 int count = 0; |
32 var done = expectAsync0((){}); | 34 var done = expectAsync0((){}); |
33 local.listen((msg) { | 35 local.listen((msg) { |
34 switch (msg[0]) { | 36 switch (msg[0]) { |
35 case "init": | 37 case "init": |
36 expect(remote, null); | 38 expect(remote, null); |
(...skipping 12 matching lines...) Expand all Loading... |
49 expect(count, 10); | 51 expect(count, 10); |
50 local.close(); | 52 local.close(); |
51 done(); | 53 done(); |
52 break; | 54 break; |
53 default: | 55 default: |
54 fail("unreachable: ${msg[0]}"); | 56 fail("unreachable: ${msg[0]}"); |
55 } | 57 } |
56 }); | 58 }); |
57 }); | 59 }); |
58 } | 60 } |
OLD | NEW |