981c4b11df
This means all imports of unittest in our test code had to change to include 'lib' in the path. While doing that change I changed the library/imports to the new syntax in the affected files. Review URL: https://codereview.chromium.org//11301046 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@14443 260f80e4-7a28-3924-810f-c04153c831b5
70 lines
1.9 KiB
Dart
70 lines
1.9 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.
|
|
|
|
// Dart test program for testing serialization of messages.
|
|
// VMOptions=--enable_type_checks --enable_asserts
|
|
|
|
library Message2Test;
|
|
import 'dart:isolate';
|
|
import '../../pkg/unittest/lib/unittest.dart';
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Message passing test 2.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
class MessageTest {
|
|
static void mapEqualsDeep(Map expected, Map actual) {
|
|
expect(expected, isMap);
|
|
expect(actual, isMap);
|
|
expect(actual.length, expected.length);
|
|
testForEachMap(key, value) {
|
|
if (value is List) {
|
|
listEqualsDeep(value, actual[key]);
|
|
} else {
|
|
expect(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) {
|
|
listEqualsDeep(expected[i], actual[i]);
|
|
} else if (expected[i] is Map) {
|
|
mapEqualsDeep(expected[i], actual[i]);
|
|
} else {
|
|
expect(actual[i], expected[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void pingPong() {
|
|
port.receive((var message, SendPort replyTo) {
|
|
if (message == -1) {
|
|
port.close();
|
|
} else {
|
|
// Bounce the received object back so that the sender
|
|
// can make sure that the object matches.
|
|
replyTo.send(message, null);
|
|
}
|
|
});
|
|
}
|
|
|
|
main() {
|
|
test("map is equal after it is sent back and forth", () {
|
|
SendPort remote = spawnFunction(pingPong);
|
|
Map m = new Map();
|
|
m[1] = "eins";
|
|
m[2] = "deux";
|
|
m[3] = "tre";
|
|
m[4] = "four";
|
|
remote.call(m).then(expectAsync1((var received) {
|
|
MessageTest.mapEqualsDeep(m, received);
|
|
remote.send(-1, null);
|
|
}));
|
|
});
|
|
}
|