2012-08-03 07:24:29 +00:00
|
|
|
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
2011-10-05 06:22:36 +00:00
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
// Dart test program for testing isolate communication with
|
|
|
|
// typed objects.
|
2012-09-20 18:19:06 +00:00
|
|
|
// VMOptions=--checked
|
2011-10-05 06:22:36 +00:00
|
|
|
|
2012-11-30 23:20:01 +00:00
|
|
|
library TypedMessageTest;
|
2013-10-25 19:23:00 +00:00
|
|
|
import "dart:async";
|
2013-04-05 19:43:16 +00:00
|
|
|
import "package:expect/expect.dart";
|
2013-12-02 12:14:57 +00:00
|
|
|
import "package:async_helper/async_helper.dart";
|
2012-11-30 23:20:01 +00:00
|
|
|
import "dart:isolate";
|
2012-02-27 22:50:44 +00:00
|
|
|
|
2013-10-25 19:23:00 +00:00
|
|
|
void logMessages(SendPort replyTo) {
|
2012-08-03 07:24:29 +00:00
|
|
|
print("Starting log server.");
|
2013-10-25 19:23:00 +00:00
|
|
|
ReceivePort port = new ReceivePort();
|
|
|
|
replyTo.send(port.sendPort);
|
|
|
|
port.first.then((List<int> message) {
|
2012-08-03 07:24:29 +00:00
|
|
|
print("Log $message");
|
|
|
|
Expect.equals(5, message.length);
|
|
|
|
Expect.equals(0, message[0]);
|
|
|
|
Expect.equals(1, message[1]);
|
|
|
|
Expect.equals(2, message[2]);
|
|
|
|
Expect.equals(3, message[3]);
|
|
|
|
Expect.equals(4, message[4]);
|
|
|
|
port.close();
|
2013-10-25 19:23:00 +00:00
|
|
|
replyTo.send(1);
|
2012-08-03 07:24:29 +00:00
|
|
|
print("Stopping log server.");
|
|
|
|
});
|
2011-10-05 06:22:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
2013-12-02 12:14:57 +00:00
|
|
|
asyncStart();
|
2013-10-25 19:23:00 +00:00
|
|
|
ReceivePort receivePort = new ReceivePort();
|
|
|
|
Future<Isolate> remote = Isolate.spawn(logMessages, receivePort.sendPort);
|
2013-02-27 08:45:04 +00:00
|
|
|
List<int> msg = new List<int>(5);
|
2012-08-03 07:24:29 +00:00
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
msg[i] = i;
|
|
|
|
}
|
2013-10-25 19:23:00 +00:00
|
|
|
StreamIterator iterator = new StreamIterator(receivePort);
|
|
|
|
iterator.moveNext().then((b) {
|
|
|
|
SendPort sendPort = iterator.current;
|
|
|
|
sendPort.send(msg);
|
|
|
|
return iterator.moveNext();
|
|
|
|
}).then((b) {
|
|
|
|
Expect.equals(1, iterator.current);
|
|
|
|
receivePort.close();
|
2013-12-02 12:14:57 +00:00
|
|
|
asyncEnd();
|
2012-08-03 07:24:29 +00:00
|
|
|
});
|
2011-10-05 06:22:36 +00:00
|
|
|
}
|