OLD | NEW |
1 // Copyright (c) 2011, 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 | 10 |
11 #import('../../lib/unittest/unittest.dart'); | 11 #import('../../lib/unittest/unittest.dart'); |
(...skipping 23 matching lines...) Expand all Loading... |
35 listEqualsDeep(expected[i], actual[i]); | 35 listEqualsDeep(expected[i], actual[i]); |
36 } else if (expected[i] is Map) { | 36 } else if (expected[i] is Map) { |
37 mapEqualsDeep(expected[i], actual[i]); | 37 mapEqualsDeep(expected[i], actual[i]); |
38 } else { | 38 } else { |
39 Expect.equals(expected[i], actual[i]); | 39 Expect.equals(expected[i], actual[i]); |
40 } | 40 } |
41 } | 41 } |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 class PingPongServer extends Isolate { | 45 void pingPong() { |
46 PingPongServer() : super.heavy(); | 46 port.receive((var message, SendPort replyTo) { |
47 | 47 if (message == -1) { |
48 void main() { | 48 port.close(); |
49 this.port.receive((var message, SendPort replyTo) { | 49 } else { |
50 if (message == -1) { | 50 // Bounce the received object back so that the sender |
51 this.port.close(); | 51 // can make sure that the object matches. |
52 } else { | 52 replyTo.send(message, null); |
53 // Bounce the received object back so that the sender | 53 } |
54 // can make sure that the object matches. | 54 }); |
55 replyTo.send(message, null); | |
56 } | |
57 }); | |
58 } | |
59 } | 55 } |
60 | 56 |
61 main() { | 57 main() { |
62 test("map is equal after it is sent back and forth", () { | 58 test("map is equal after it is sent back and forth", () { |
63 new PingPongServer().spawn().then(expectAsync1((SendPort remote) { | 59 SendPort remote = spawnFunction(pingPong); |
64 Map m = new Map(); | 60 Map m = new Map(); |
65 m[1] = "eins"; | 61 m[1] = "eins"; |
66 m[2] = "deux"; | 62 m[2] = "deux"; |
67 m[3] = "tre"; | 63 m[3] = "tre"; |
68 m[4] = "four"; | 64 m[4] = "four"; |
69 remote.call(m).then(expectAsync1((var received) { | 65 remote.call(m).then(expectAsync1((var received) { |
70 MessageTest.mapEqualsDeep(m, received); | 66 MessageTest.mapEqualsDeep(m, received); |
71 remote.send(-1, null); | 67 remote.send(-1, null); |
72 })); | |
73 })); | 68 })); |
74 }); | 69 }); |
75 } | 70 } |
OLD | NEW |