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 // negative test to ensure that APIv2_unresolvedPortsTest works. | 5 // negative test to ensure that APIv2_unresolvedPortsTest works. |
6 #library('unresolved_ports'); | 6 #library('unresolved_ports'); |
7 #import('dart:isolate'); | 7 #import('dart:isolate'); |
8 #import('../../lib/unittest/unittest.dart'); | 8 #import('../../lib/unittest/unittest.dart'); |
9 | 9 |
10 bethIsolate() { | 10 bethIsolate() { |
11 port.receive((msg, reply) => msg[1].send( | 11 port.receive((msg, reply) => msg[1].send( |
12 '${msg[0]}\nBeth says: Tim are you coming? And Bob?', reply)); | 12 '${msg[0]}\nBeth says: Tim are you coming? And Bob?', reply)); |
13 } | 13 } |
14 | 14 |
15 timIsolate() { | 15 timIsolate() { |
16 SendPort bob = spawnFunction(bobIsolate); | 16 SendPort bob = spawnFunction(bobIsolate); |
17 port.receive((msg, reply) => bob.send( | 17 port.receive((msg, reply) => bob.send( |
18 '$msg\nTim says: Can you tell "main" that we are all coming?', reply)); | 18 '$msg\nTim says: Can you tell "main" that we are all coming?', reply)); |
19 } | 19 } |
20 | 20 |
21 bobIsolate() { | 21 bobIsolate() { |
22 port.receive((msg, reply) => reply.send( | 22 port.receive((msg, reply) => reply.send( |
23 '$msg\nBob says: we are all coming!')); | 23 '$msg\nBob says: we are all coming!')); |
24 } | 24 } |
25 | 25 |
26 main() { | 26 main() { |
27 test('Message chain with unresolved ports', () { | 27 test('Message chain with unresolved ports', () { |
28 ReceivePort port = new ReceivePort(); | 28 ReceivePort port = new ReceivePort(); |
29 port.receive(expectAsync2((msg, _) { | 29 port.receive(expectAsync2((msg, _) { |
30 expect(msg).equals('main says: Beth, find out if Tim is coming.' | 30 expect(msg, equals('main says: Beth, find out if Tim is coming.' |
31 + '\nBeth says: Tim are you coming? And Bob?' | 31 + '\nBeth says: Tim are you coming? And Bob?' |
32 + '\nTim says: Can you tell "main" that we are all coming?' | 32 + '\nTim says: Can you tell "main" that we are all coming?' |
33 + '\nBob says: we are NOT coming!'); // should be 'all', not 'NOT' | 33 + '\nBob says: we are NOT coming!')); // should be 'all', not 'NOT' |
34 port.close(); | 34 port.close(); |
35 })); | 35 })); |
36 | 36 |
37 SendPort tim = spawnFunction(timIsolate); | 37 SendPort tim = spawnFunction(timIsolate); |
38 SendPort beth = spawnFunction(bethIsolate); | 38 SendPort beth = spawnFunction(bethIsolate); |
39 | 39 |
40 beth.send( | 40 beth.send( |
41 // because tim is created asynchronously, here we are sending an | 41 // because tim is created asynchronously, here we are sending an |
42 // unresolved port: | 42 // unresolved port: |
43 ['main says: Beth, find out if Tim is coming.', tim], | 43 ['main says: Beth, find out if Tim is coming.', tim], |
44 port.toSendPort()); | 44 port.toSendPort()); |
45 }); | 45 }); |
46 } | 46 } |
OLD | NEW |