2012-08-03 07:24:29 +00:00
|
|
|
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
2011-10-07 08:31:35 +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 serialization of messages.
|
|
|
|
// VMOptions=--enable_type_checks --enable_asserts
|
|
|
|
|
2012-11-01 23:09:47 +00:00
|
|
|
library Message2Test;
|
|
|
|
import 'dart:isolate';
|
2013-11-25 08:19:53 +00:00
|
|
|
import 'package:unittest/unittest.dart';
|
|
|
|
import "remote_unittest_helper.dart";
|
2011-10-07 08:31:35 +00:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// Message passing test 2.
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class MessageTest {
|
|
|
|
static void mapEqualsDeep(Map expected, Map actual) {
|
2012-11-01 23:09:47 +00:00
|
|
|
expect(expected, isMap);
|
|
|
|
expect(actual, isMap);
|
|
|
|
expect(actual.length, expected.length);
|
2011-10-07 08:31:35 +00:00
|
|
|
testForEachMap(key, value) {
|
|
|
|
if (value is List) {
|
|
|
|
listEqualsDeep(value, actual[key]);
|
|
|
|
} else {
|
2012-11-01 23:09:47 +00:00
|
|
|
expect(actual[key], value);
|
2011-10-07 08:31:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
expected.forEach(testForEachMap);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void listEqualsDeep(List expected, List actual) {
|
|
|
|
for (int i = 0; i < expected.length; i++) {
|
|
|
|
if (expected[i] is List) {
|
|
|
|
listEqualsDeep(expected[i], actual[i]);
|
|
|
|
} else if (expected[i] is Map) {
|
|
|
|
mapEqualsDeep(expected[i], actual[i]);
|
|
|
|
} else {
|
2012-11-01 23:09:47 +00:00
|
|
|
expect(actual[i], expected[i]);
|
2011-10-07 08:31:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 19:23:00 +00:00
|
|
|
void pingPong(replyPort) {
|
|
|
|
ReceivePort port = new ReceivePort();
|
|
|
|
port.listen((message) {
|
|
|
|
if (message == null) {
|
2012-08-03 07:24:29 +00:00
|
|
|
port.close();
|
|
|
|
} else {
|
|
|
|
// Bounce the received object back so that the sender
|
|
|
|
// can make sure that the object matches.
|
2013-10-25 19:23:00 +00:00
|
|
|
message[1].send(message[0]);
|
2012-08-03 07:24:29 +00:00
|
|
|
}
|
|
|
|
});
|
2013-10-25 19:23:00 +00:00
|
|
|
replyPort.send(port.sendPort);
|
2011-10-07 08:31:35 +00:00
|
|
|
}
|
|
|
|
|
2013-11-25 08:19:53 +00:00
|
|
|
void main([args, port]) {
|
|
|
|
if (testRemote(main, port)) return;
|
2012-04-25 22:31:04 +00:00
|
|
|
test("map is equal after it is sent back and forth", () {
|
2013-10-25 19:23:00 +00:00
|
|
|
ReceivePort port = new ReceivePort();
|
|
|
|
Isolate.spawn(pingPong, port.sendPort);
|
2014-03-31 18:33:18 +00:00
|
|
|
port.first.then(expectAsync((remote) {
|
2013-10-25 19:23:00 +00:00
|
|
|
Map m = new Map();
|
|
|
|
m[1] = "eins";
|
|
|
|
m[2] = "deux";
|
|
|
|
m[3] = "tre";
|
|
|
|
m[4] = "four";
|
|
|
|
ReceivePort replyPort = new ReceivePort();
|
|
|
|
remote.send([m, replyPort.sendPort]);
|
2014-03-31 18:33:18 +00:00
|
|
|
replyPort.first.then(expectAsync((var received) {
|
2013-10-25 19:23:00 +00:00
|
|
|
MessageTest.mapEqualsDeep(m, received);
|
|
|
|
remote.send(null);
|
|
|
|
}));
|
2011-10-07 08:31:35 +00:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|