| 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 MessageTest; | 8 library MessageTest; |
| 9 |
| 9 import 'dart:isolate'; | 10 import 'dart:isolate'; |
| 10 import 'dart:async'; | 11 import 'dart:async'; |
| 11 import 'package:unittest/unittest.dart'; | 12 import 'package:unittest/unittest.dart'; |
| 12 import "remote_unittest_helper.dart"; | 13 import "remote_unittest_helper.dart"; |
| 13 | 14 |
| 14 // --------------------------------------------------------------------------- | 15 // --------------------------------------------------------------------------- |
| 15 // Message passing test. | 16 // Message passing test. |
| 16 // --------------------------------------------------------------------------- | 17 // --------------------------------------------------------------------------- |
| 17 | 18 |
| 18 class MessageTest { | 19 class MessageTest { |
| 19 static const List list1 = const ["Hello", "World", "Hello", 0xfffffffffff]; | 20 static const List list1 = const ["Hello", "World", "Hello", 0xfffffffffff]; |
| 20 static const List list2 = const [null, list1, list1, list1, list1]; | 21 static const List list2 = const [null, list1, list1, list1, list1]; |
| 21 static const List list3 = const [list2, 2.0, true, false, 0xfffffffffff]; | 22 static const List list3 = const [list2, 2.0, true, false, 0xfffffffffff]; |
| 22 static const Map map1 = const { | 23 static const Map map1 = const { |
| 23 "a=1" : 1, "b=2" : 2, "c=3" : 3, | 24 "a=1": 1, |
| 25 "b=2": 2, |
| 26 "c=3": 3, |
| 24 }; | 27 }; |
| 25 static const Map map2 = const { | 28 static const Map map2 = const { |
| 26 "list1" : list1, "list2" : list2, "list3" : list3, | 29 "list1": list1, |
| 30 "list2": list2, |
| 31 "list3": list3, |
| 27 }; | 32 }; |
| 28 static const List list4 = const [map1, map2]; | 33 static const List list4 = const [map1, map2]; |
| 29 static const List elms = const [ | 34 static const List elms = const [ |
| 30 list1, list2, list3, list4, | 35 list1, |
| 36 list2, |
| 37 list3, |
| 38 list4, |
| 31 ]; | 39 ]; |
| 32 | 40 |
| 33 static void VerifyMap(Map expected, Map actual) { | 41 static void VerifyMap(Map expected, Map actual) { |
| 34 expect(expected, isMap); | 42 expect(expected, isMap); |
| 35 expect(actual, isMap); | 43 expect(actual, isMap); |
| 36 expect(actual.length, expected.length); | 44 expect(actual.length, expected.length); |
| 37 testForEachMap(key, value) { | 45 testForEachMap(key, value) { |
| 38 if (value is List) { | 46 if (value is List) { |
| 39 VerifyList(value, actual[key]); | 47 VerifyList(value, actual[key]); |
| 40 } else { | 48 } else { |
| 41 expect(actual[key], value); | 49 expect(actual[key], value); |
| 42 } | 50 } |
| 43 } | 51 } |
| 52 |
| 44 expected.forEach(testForEachMap); | 53 expected.forEach(testForEachMap); |
| 45 } | 54 } |
| 46 | 55 |
| 47 static void VerifyList(List expected, List actual) { | 56 static void VerifyList(List expected, List actual) { |
| 48 for (int i = 0; i < expected.length; i++) { | 57 for (int i = 0; i < expected.length; i++) { |
| 49 if (expected[i] is List) { | 58 if (expected[i] is List) { |
| 50 VerifyList(expected[i], actual[i]); | 59 VerifyList(expected[i], actual[i]); |
| 51 } else if (expected[i] is Map) { | 60 } else if (expected[i] is Map) { |
| 52 VerifyMap(expected[i], actual[i]); | 61 VerifyMap(expected[i], actual[i]); |
| 53 } else { | 62 } else { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 // Send objects and receive them back. | 112 // Send objects and receive them back. |
| 104 for (int i = 0; i < MessageTest.elms.length; i++) { | 113 for (int i = 0; i < MessageTest.elms.length; i++) { |
| 105 var sentObject = MessageTest.elms[i]; | 114 var sentObject = MessageTest.elms[i]; |
| 106 remoteCall(remote, sentObject).then(expectAsync((var receivedObject) { | 115 remoteCall(remote, sentObject).then(expectAsync((var receivedObject) { |
| 107 MessageTest.VerifyObject(i, receivedObject); | 116 MessageTest.VerifyObject(i, receivedObject); |
| 108 })); | 117 })); |
| 109 } | 118 } |
| 110 | 119 |
| 111 // Send recursive objects and receive them back. | 120 // Send recursive objects and receive them back. |
| 112 List local_list1 = ["Hello", "World", "Hello", 0xffffffffff]; | 121 List local_list1 = ["Hello", "World", "Hello", 0xffffffffff]; |
| 113 List local_list2 = [null, local_list1, local_list1 ]; | 122 List local_list2 = [null, local_list1, local_list1]; |
| 114 List local_list3 = [local_list2, 2.0, true, false, 0xffffffffff]; | 123 List local_list3 = [local_list2, 2.0, true, false, 0xffffffffff]; |
| 115 List sendObject = new List(5); | 124 List sendObject = new List(5); |
| 116 sendObject[0] = local_list1; | 125 sendObject[0] = local_list1; |
| 117 sendObject[1] = sendObject; | 126 sendObject[1] = sendObject; |
| 118 sendObject[2] = local_list2; | 127 sendObject[2] = local_list2; |
| 119 sendObject[3] = sendObject; | 128 sendObject[3] = sendObject; |
| 120 sendObject[4] = local_list3; | 129 sendObject[4] = local_list3; |
| 121 remoteCall(remote, sendObject).then((var replyObject) { | 130 remoteCall(remote, sendObject).then((var replyObject) { |
| 122 expect(sendObject, isList); | 131 expect(sendObject, isList); |
| 123 expect(replyObject, isList); | 132 expect(replyObject, isList); |
| 124 expect(sendObject.length, equals(replyObject.length)); | 133 expect(sendObject.length, equals(replyObject.length)); |
| 125 expect(replyObject[1], same(replyObject)); | 134 expect(replyObject[1], same(replyObject)); |
| 126 expect(replyObject[3], same(replyObject)); | 135 expect(replyObject[3], same(replyObject)); |
| 127 expect(replyObject[0], same(replyObject[2][1])); | 136 expect(replyObject[0], same(replyObject[2][1])); |
| 128 expect(replyObject[0], same(replyObject[2][2])); | 137 expect(replyObject[0], same(replyObject[2][2])); |
| 129 expect(replyObject[2], same(replyObject[4][0])); | 138 expect(replyObject[2], same(replyObject[4][0])); |
| 130 expect(replyObject[0][0], same(replyObject[0][2])); | 139 expect(replyObject[0][0], same(replyObject[0][2])); |
| 131 // Bigint literals are not canonicalized so do a == check. | 140 // Bigint literals are not canonicalized so do a == check. |
| 132 expect(replyObject[0][3], equals(replyObject[4][4])); | 141 expect(replyObject[0][3], equals(replyObject[4][4])); |
| 133 }); | 142 }); |
| 134 | 143 |
| 135 // Shutdown the MessageServer. | 144 // Shutdown the MessageServer. |
| 136 remoteCall(remote, -1).then(expectAsync((int message) { | 145 remoteCall(remote, -1).then(expectAsync((int message) { |
| 137 expect(message, MessageTest.elms.length + 1); | 146 expect(message, MessageTest.elms.length + 1); |
| 138 })); | 147 })); |
| 139 })); | 148 })); |
| 140 }); | 149 }); |
| 141 } | 150 } |
| OLD | NEW |