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 // Dart test program for testing isolate communication with | 5 // Dart test program for testing isolate communication with |
6 // complex messages. | 6 // complex messages. |
7 | 7 |
8 library IsolateComplexMessagesTest; | 8 library IsolateComplexMessagesTest; |
| 9 |
9 import 'dart:isolate'; | 10 import 'dart:isolate'; |
10 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
11 import "remote_unittest_helper.dart"; | 12 import "remote_unittest_helper.dart"; |
12 | 13 |
13 void main([args, port]) { | 14 void main([args, port]) { |
14 if (testRemote(main, port)) return; | 15 if (testRemote(main, port)) return; |
15 test("complex messages are serialized correctly", () { | 16 test("complex messages are serialized correctly", () { |
16 ReceivePort local = new ReceivePort(); | 17 ReceivePort local = new ReceivePort(); |
17 Isolate.spawn(logMessages, local.sendPort); | 18 Isolate.spawn(logMessages, local.sendPort); |
18 var done = expectAsync((){}); | 19 var done = expectAsync(() {}); |
19 local.listen(expectAsync((msg) { | 20 local.listen(expectAsync((msg) { |
20 switch (msg[0]) { | 21 switch (msg[0]) { |
21 case "init": | 22 case "init": |
22 var remote = msg[1]; | 23 var remote = msg[1]; |
23 remote.send(1); | 24 remote.send(1); |
24 remote.send("Hello"); | 25 remote.send("Hello"); |
25 remote.send("World"); | 26 remote.send("World"); |
26 remote.send(const [null, 1, 2, 3, 4]); | 27 remote.send(const [null, 1, 2, 3, 4]); |
27 remote.send(const [1, 2.0, true, false, 0xffffffffff]); | 28 remote.send(const [1, 2.0, true, false, 0xffffffffff]); |
28 remote.send(const ["Hello", "World", 0xffffffffff]); | 29 remote.send(const ["Hello", "World", 0xffffffffff]); |
29 // Shutdown the LogRunner. | 30 // Shutdown the LogRunner. |
30 remote.send(-1); | 31 remote.send(-1); |
31 break; | 32 break; |
32 case "done": | 33 case "done": |
33 local.close(); | 34 local.close(); |
34 expect(msg[1], 6); | 35 expect(msg[1], 6); |
35 done(); | 36 done(); |
36 } | 37 } |
37 }, count: 2)); | 38 }, count: 2)); |
38 }); | 39 }); |
39 } | 40 } |
40 | 41 |
41 | |
42 void logMessages(mainPort) { | 42 void logMessages(mainPort) { |
43 int count = 0; | 43 int count = 0; |
44 ReceivePort port = new ReceivePort(); | 44 ReceivePort port = new ReceivePort(); |
45 mainPort.send(["init", port.sendPort]); | 45 mainPort.send(["init", port.sendPort]); |
46 port.listen((var message) { | 46 port.listen((var message) { |
47 if (message == -1) { | 47 if (message == -1) { |
48 port.close(); | 48 port.close(); |
49 mainPort.send(["done", count]); | 49 mainPort.send(["done", count]); |
50 } else { | 50 } else { |
51 switch (count) { | 51 switch (count) { |
(...skipping 26 matching lines...) Expand all Loading... |
78 expect(message.length, 3); | 78 expect(message.length, 3); |
79 expect(message[0], "Hello"); | 79 expect(message[0], "Hello"); |
80 expect(message[1], "World"); | 80 expect(message[1], "World"); |
81 expect(message[2], 0xffffffffff); | 81 expect(message[2], 0xffffffffff); |
82 break; | 82 break; |
83 } | 83 } |
84 count++; | 84 count++; |
85 } | 85 } |
86 }); | 86 }); |
87 } | 87 } |
OLD | NEW |