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 | 10 import '../../pkg/unittest/lib/unittest.dart'; |
11 #import('../../pkg/unittest/unittest.dart'); | |
12 | 11 |
13 // --------------------------------------------------------------------------- | 12 // --------------------------------------------------------------------------- |
14 // Message passing test 2. | 13 // Message passing test 2. |
15 // --------------------------------------------------------------------------- | 14 // --------------------------------------------------------------------------- |
16 | 15 |
17 class MessageTest { | 16 class MessageTest { |
18 static void mapEqualsDeep(Map expected, Map actual) { | 17 static void mapEqualsDeep(Map expected, Map actual) { |
19 Expect.equals(true, expected is Map); | 18 expect(expected, isMap); |
20 Expect.equals(true, actual is Map); | 19 expect(actual, isMap); |
21 Expect.equals(expected.length, actual.length); | 20 expect(actual.length, expected.length); |
22 testForEachMap(key, value) { | 21 testForEachMap(key, value) { |
23 if (value is List) { | 22 if (value is List) { |
24 listEqualsDeep(value, actual[key]); | 23 listEqualsDeep(value, actual[key]); |
25 } else { | 24 } else { |
26 Expect.equals(value, actual[key]); | 25 expect(actual[key], value); |
27 } | 26 } |
28 } | 27 } |
29 expected.forEach(testForEachMap); | 28 expected.forEach(testForEachMap); |
30 } | 29 } |
31 | 30 |
32 static void listEqualsDeep(List expected, List actual) { | 31 static void listEqualsDeep(List expected, List actual) { |
33 for (int i = 0; i < expected.length; i++) { | 32 for (int i = 0; i < expected.length; i++) { |
34 if (expected[i] is List) { | 33 if (expected[i] is List) { |
35 listEqualsDeep(expected[i], actual[i]); | 34 listEqualsDeep(expected[i], actual[i]); |
36 } else if (expected[i] is Map) { | 35 } else if (expected[i] is Map) { |
37 mapEqualsDeep(expected[i], actual[i]); | 36 mapEqualsDeep(expected[i], actual[i]); |
38 } else { | 37 } else { |
39 Expect.equals(expected[i], actual[i]); | 38 expect(actual[i], expected[i]); |
40 } | 39 } |
41 } | 40 } |
42 } | 41 } |
43 } | 42 } |
44 | 43 |
45 void pingPong() { | 44 void pingPong() { |
46 port.receive((var message, SendPort replyTo) { | 45 port.receive((var message, SendPort replyTo) { |
47 if (message == -1) { | 46 if (message == -1) { |
48 port.close(); | 47 port.close(); |
49 } else { | 48 } else { |
(...skipping 11 matching lines...) Expand all Loading... |
61 m[1] = "eins"; | 60 m[1] = "eins"; |
62 m[2] = "deux"; | 61 m[2] = "deux"; |
63 m[3] = "tre"; | 62 m[3] = "tre"; |
64 m[4] = "four"; | 63 m[4] = "four"; |
65 remote.call(m).then(expectAsync1((var received) { | 64 remote.call(m).then(expectAsync1((var received) { |
66 MessageTest.mapEqualsDeep(m, received); | 65 MessageTest.mapEqualsDeep(m, received); |
67 remote.send(-1, null); | 66 remote.send(-1, null); |
68 })); | 67 })); |
69 }); | 68 }); |
70 } | 69 } |
OLD | NEW |