f8086c81ae
Collects files from `package:async_helper` and `tests/language` that are generally useful, so that all test-related helpers are in `package:expect`. Moves the two libraries from `package:async_helper` into `package:expect`, and the `tests/language/static_type_helper.dart` file too. Deprecates `async_minitest.dart`, to follow `minitest.dart`, expecting the Flutter use of it to have been fixed to not break on deprecation (I believe Flutter no longer breaks builds on deprecations at all). Patch 1 is the actual change. Patch 2+4+8 is changing all existing references to the files. Patch 6 ignores deprecation in files still using `async_minitest.dart`. 3+5+7+9 are updating this text to make the numbers match. Then it's just test-expectations and small tweaks from there. Change-Id: I1b665135b5fef9b9a0c3b340ffe9daf874d0174c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373120 Reviewed-by: Nate Bosch <nbosch@google.com> Reviewed-by: Devon Carew <devoncarew@google.com> Commit-Queue: Lasse Nielsen <lrn@google.com>
88 lines
2.4 KiB
Dart
88 lines
2.4 KiB
Dart
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// 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.
|
|
|
|
// VMOptions=--no-enable-fast-object-copy
|
|
// VMOptions=--enable-fast-object-copy
|
|
|
|
// Dart test program for testing serialization of messages.
|
|
// VMOptions=--enable_type_checks --enable_asserts
|
|
|
|
library Message2Test;
|
|
|
|
import 'dart:isolate';
|
|
import 'package:expect/async_helper.dart';
|
|
import 'package:expect/expect.dart';
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Message passing test 2.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
class MessageTest {
|
|
static void mapEqualsDeep(Map expected, Map actual) {
|
|
Expect.equals(actual.length, expected.length);
|
|
testForEachMap(key, value) {
|
|
if (value is List) {
|
|
listEqualsDeep(value, actual[key]);
|
|
} else {
|
|
Expect.equals(actual[key], value);
|
|
}
|
|
}
|
|
|
|
expected.forEach(testForEachMap);
|
|
}
|
|
|
|
static void listEqualsDeep(List expected, List actual) {
|
|
for (int i = 0; i < expected.length; i++) {
|
|
if (expected[i] is List) {
|
|
Expect.type<List>(actual[i]);
|
|
listEqualsDeep(expected[i], actual[i]);
|
|
} else if (expected[i] is Map) {
|
|
Expect.type<Map>(actual[i]);
|
|
mapEqualsDeep(expected[i], actual[i]);
|
|
} else {
|
|
Expect.equals(actual[i], expected[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void pingPong(replyPort) {
|
|
ReceivePort port = new ReceivePort();
|
|
port.listen((message) {
|
|
if (message is SendPort) {
|
|
message.send('done');
|
|
port.close();
|
|
} else {
|
|
// Bounce the received object back so that the sender
|
|
// can make sure that the object matches.
|
|
message[1].send(message[0]);
|
|
}
|
|
});
|
|
replyPort.send(port.sendPort);
|
|
}
|
|
|
|
void main([args, port]) {
|
|
ReceivePort port = new ReceivePort();
|
|
Isolate.spawn(pingPong, port.sendPort);
|
|
asyncStart();
|
|
port.first.then((remote) {
|
|
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]);
|
|
replyPort.listen((var received) {
|
|
if (received == 'done') {
|
|
replyPort.close();
|
|
asyncEnd();
|
|
} else {
|
|
MessageTest.mapEqualsDeep(m, received);
|
|
remote.send(replyPort.sendPort);
|
|
}
|
|
});
|
|
});
|
|
}
|