| OLD | NEW |
| (Empty) |
| 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 | |
| 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 import '../../pkg/unittest/lib/unittest.dart'; | |
| 11 | |
| 12 // --------------------------------------------------------------------------- | |
| 13 // Message passing test 2. | |
| 14 // --------------------------------------------------------------------------- | |
| 15 | |
| 16 class MessageTest { | |
| 17 static void mapEqualsDeep(Map expected, Map actual) { | |
| 18 expect(expected, isMap); | |
| 19 expect(actual, isMap); | |
| 20 expect(actual.length, expected.length); | |
| 21 testForEachMap(key, value) { | |
| 22 if (value is List) { | |
| 23 listEqualsDeep(value, actual[key]); | |
| 24 } else { | |
| 25 expect(actual[key], value); | |
| 26 } | |
| 27 } | |
| 28 expected.forEach(testForEachMap); | |
| 29 } | |
| 30 | |
| 31 static void listEqualsDeep(List expected, List actual) { | |
| 32 for (int i = 0; i < expected.length; i++) { | |
| 33 if (expected[i] is List) { | |
| 34 listEqualsDeep(expected[i], actual[i]); | |
| 35 } else if (expected[i] is Map) { | |
| 36 mapEqualsDeep(expected[i], actual[i]); | |
| 37 } else { | |
| 38 expect(actual[i], expected[i]); | |
| 39 } | |
| 40 } | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 void pingPong() { | |
| 45 bool isFirst = true; | |
| 46 IsolateSink replyTo; | |
| 47 stream.listen((var message) { | |
| 48 if (isFirst) { | |
| 49 isFirst = false; | |
| 50 replyTo = message; | |
| 51 return; | |
| 52 } | |
| 53 // Bounce the received object back so that the sender | |
| 54 // can make sure that the object matches. | |
| 55 replyTo.add(message); | |
| 56 }); | |
| 57 } | |
| 58 | |
| 59 main() { | |
| 60 test("map is equal after it is sent back and forth", () { | |
| 61 IsolateSink remote = streamSpawnFunction(pingPong); | |
| 62 Map m = new Map(); | |
| 63 m[1] = "eins"; | |
| 64 m[2] = "deux"; | |
| 65 m[3] = "tre"; | |
| 66 m[4] = "four"; | |
| 67 MessageBox box = new MessageBox(); | |
| 68 remote.add(box.sink); | |
| 69 remote.add(m); | |
| 70 box.stream.listen(expectAsync1((var received) { | |
| 71 MessageTest.mapEqualsDeep(m, received); | |
| 72 remote.close(); | |
| 73 box.stream.close(); | |
| 74 })); | |
| 75 }); | |
| 76 } | |
| OLD | NEW |