| 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 serialization of messages. | 5 // Dart test program for testing serialization of messages. |
| 6 // VMOptions=--enable_type_checks --enable_asserts | 6 // VMOptions=--enable_type_checks --enable_asserts |
| 7 | 7 |
| 8 library Message2Test; | 8 library Message2Test; |
| 9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
| 10 import '../../pkg/unittest/lib/unittest.dart'; | 10 import '../../pkg/unittest/lib/unittest.dart'; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 listEqualsDeep(expected[i], actual[i]); | 34 listEqualsDeep(expected[i], actual[i]); |
| 35 } else if (expected[i] is Map) { | 35 } else if (expected[i] is Map) { |
| 36 mapEqualsDeep(expected[i], actual[i]); | 36 mapEqualsDeep(expected[i], actual[i]); |
| 37 } else { | 37 } else { |
| 38 expect(actual[i], expected[i]); | 38 expect(actual[i], expected[i]); |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 | 43 |
| 44 void pingPong() { | 44 void pingPong(replyPort) { |
| 45 port.receive((var message, SendPort replyTo) { | 45 ReceivePort port = new ReceivePort(); |
| 46 if (message == -1) { | 46 port.listen((message) { |
| 47 if (message == null) { |
| 47 port.close(); | 48 port.close(); |
| 48 } else { | 49 } else { |
| 49 // Bounce the received object back so that the sender | 50 // Bounce the received object back so that the sender |
| 50 // can make sure that the object matches. | 51 // can make sure that the object matches. |
| 51 replyTo.send(message, null); | 52 message[1].send(message[0]); |
| 52 } | 53 } |
| 53 }); | 54 }); |
| 55 replyPort.send(port.sendPort); |
| 54 } | 56 } |
| 55 | 57 |
| 56 main() { | 58 main() { |
| 57 test("map is equal after it is sent back and forth", () { | 59 test("map is equal after it is sent back and forth", () { |
| 58 SendPort remote = spawnFunction(pingPong); | 60 ReceivePort port = new ReceivePort(); |
| 59 Map m = new Map(); | 61 Isolate.spawn(pingPong, port.sendPort); |
| 60 m[1] = "eins"; | 62 port.first.then(expectAsync1((remote) { |
| 61 m[2] = "deux"; | 63 Map m = new Map(); |
| 62 m[3] = "tre"; | 64 m[1] = "eins"; |
| 63 m[4] = "four"; | 65 m[2] = "deux"; |
| 64 remote.call(m).then(expectAsync1((var received) { | 66 m[3] = "tre"; |
| 65 MessageTest.mapEqualsDeep(m, received); | 67 m[4] = "four"; |
| 66 remote.send(-1, null); | 68 ReceivePort replyPort = new ReceivePort(); |
| 69 remote.send([m, replyPort.sendPort]); |
| 70 replyPort.first.then(expectAsync1((var received) { |
| 71 MessageTest.mapEqualsDeep(m, received); |
| 72 remote.send(null); |
| 73 })); |
| 67 })); | 74 })); |
| 68 }); | 75 }); |
| 69 } | 76 } |
| OLD | NEW |