| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 // Dart test program for testing serialization of messages. | |
| 6 // VMOptions=--enable_type_checks --enable_asserts | |
| 7 | |
| 8 #library('Message2Test'); | |
| 9 #import("dart:isolate"); | |
| 10 | |
| 11 #import('../../../lib/unittest/unittest.dart'); | |
| 12 | |
| 13 // --------------------------------------------------------------------------- | |
| 14 // Message passing test 2. | |
| 15 // --------------------------------------------------------------------------- | |
| 16 | |
| 17 class MessageTest { | |
| 18 static void mapEqualsDeep(Map expected, Map actual) { | |
| 19 Expect.equals(true, expected is Map); | |
| 20 Expect.equals(true, actual is Map); | |
| 21 Expect.equals(expected.length, actual.length); | |
| 22 testForEachMap(key, value) { | |
| 23 if (value is List) { | |
| 24 listEqualsDeep(value, actual[key]); | |
| 25 } else { | |
| 26 Expect.equals(value, actual[key]); | |
| 27 } | |
| 28 } | |
| 29 expected.forEach(testForEachMap); | |
| 30 } | |
| 31 | |
| 32 static void listEqualsDeep(List expected, List actual) { | |
| 33 for (int i = 0; i < expected.length; i++) { | |
| 34 if (expected[i] is List) { | |
| 35 listEqualsDeep(expected[i], actual[i]); | |
| 36 } else if (expected[i] is Map) { | |
| 37 mapEqualsDeep(expected[i], actual[i]); | |
| 38 } else { | |
| 39 Expect.equals(expected[i], actual[i]); | |
| 40 } | |
| 41 } | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 class PingPongServer extends Isolate { | |
| 46 PingPongServer() : super.heavy(); | |
| 47 | |
| 48 void main() { | |
| 49 this.port.receive((var message, SendPort replyTo) { | |
| 50 if (message == -1) { | |
| 51 this.port.close(); | |
| 52 } else { | |
| 53 // Bounce the received object back so that the sender | |
| 54 // can make sure that the object matches. | |
| 55 replyTo.send(message, null); | |
| 56 } | |
| 57 }); | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 main() { | |
| 62 test("map is equal after it is sent back and forth", () { | |
| 63 new PingPongServer().spawn().then(expectAsync1((SendPort remote) { | |
| 64 Map m = new Map(); | |
| 65 m[1] = "eins"; | |
| 66 m[2] = "deux"; | |
| 67 m[3] = "tre"; | |
| 68 m[4] = "four"; | |
| 69 remote.call(m).then(expectAsync1((var received) { | |
| 70 MessageTest.mapEqualsDeep(m, received); | |
| 71 remote.send(-1, null); | |
| 72 })); | |
| 73 })); | |
| 74 }); | |
| 75 } | |
| OLD | NEW |