| 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 import 'dart:isolate'; | 9 import 'dart:isolate'; |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| 11 import '../../pkg/unittest/lib/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
| 12 import "remote_unittest_helper.dart"; |
| 12 | 13 |
| 13 // --------------------------------------------------------------------------- | 14 // --------------------------------------------------------------------------- |
| 14 // Message passing test. | 15 // Message passing test. |
| 15 // --------------------------------------------------------------------------- | 16 // --------------------------------------------------------------------------- |
| 16 | 17 |
| 17 class MessageTest { | 18 class MessageTest { |
| 18 static const List list1 = const ["Hello", "World", "Hello", 0xfffffffffff]; | 19 static const List list1 = const ["Hello", "World", "Hello", 0xfffffffffff]; |
| 19 static const List list2 = const [null, list1, list1, list1, list1]; | 20 static const List list2 = const [null, list1, list1, list1, list1]; |
| 20 static const List list3 = const [list2, 2.0, true, false, 0xfffffffffff]; | 21 static const List list3 = const [list2, 2.0, true, false, 0xfffffffffff]; |
| 21 static const Map map1 = const { | 22 static const Map map1 = const { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 }); | 87 }); |
| 87 replyTo.send(port.sendPort); | 88 replyTo.send(port.sendPort); |
| 88 } | 89 } |
| 89 | 90 |
| 90 Future remoteCall(SendPort port, message) { | 91 Future remoteCall(SendPort port, message) { |
| 91 ReceivePort receivePort = new ReceivePort(); | 92 ReceivePort receivePort = new ReceivePort(); |
| 92 port.send([message, receivePort.sendPort]); | 93 port.send([message, receivePort.sendPort]); |
| 93 return receivePort.first; | 94 return receivePort.first; |
| 94 } | 95 } |
| 95 | 96 |
| 96 main() { | 97 void main([args, port]) { |
| 98 if (testRemote(main, port)) return; |
| 97 test("send objects and receive them back", () { | 99 test("send objects and receive them back", () { |
| 98 ReceivePort port = new ReceivePort(); | 100 ReceivePort port = new ReceivePort(); |
| 99 Isolate.spawn(pingPong, port.sendPort); | 101 Isolate.spawn(pingPong, port.sendPort); |
| 100 port.first.then(expectAsync1((remote) { | 102 port.first.then(expectAsync1((remote) { |
| 101 // Send objects and receive them back. | 103 // Send objects and receive them back. |
| 102 for (int i = 0; i < MessageTest.elms.length; i++) { | 104 for (int i = 0; i < MessageTest.elms.length; i++) { |
| 103 var sentObject = MessageTest.elms[i]; | 105 var sentObject = MessageTest.elms[i]; |
| 104 remoteCall(remote, sentObject).then(expectAsync1((var receivedObject) { | 106 remoteCall(remote, sentObject).then(expectAsync1((var receivedObject) { |
| 105 MessageTest.VerifyObject(i, receivedObject); | 107 MessageTest.VerifyObject(i, receivedObject); |
| 106 })); | 108 })); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 130 expect(replyObject[0][3], equals(replyObject[4][4])); | 132 expect(replyObject[0][3], equals(replyObject[4][4])); |
| 131 }); | 133 }); |
| 132 | 134 |
| 133 // Shutdown the MessageServer. | 135 // Shutdown the MessageServer. |
| 134 remoteCall(remote, -1).then(expectAsync1((int message) { | 136 remoteCall(remote, -1).then(expectAsync1((int message) { |
| 135 expect(message, MessageTest.elms.length + 1); | 137 expect(message, MessageTest.elms.length + 1); |
| 136 })); | 138 })); |
| 137 })); | 139 })); |
| 138 }); | 140 }); |
| 139 } | 141 } |
| OLD | NEW |