| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 // Dart test program for testing serialization of messages with static | |
| 6 // native functions. | |
| 7 | |
| 8 library MessageTest; | |
| 9 | |
| 10 import 'dart:async'; | |
| 11 import 'dart:collection'; | |
| 12 import 'dart:isolate'; | |
| 13 import 'package:async_helper/async_helper.dart'; | |
| 14 import 'package:expect/expect.dart'; | |
| 15 | |
| 16 void echoMain(msg) { | |
| 17 SendPort replyTo = msg[0]; | |
| 18 SendPort pong = msg[1]; | |
| 19 ReceivePort port = new ReceivePort(); | |
| 20 replyTo.send(port.sendPort); | |
| 21 port.listen((msg) { | |
| 22 if (msg == "halt") { | |
| 23 port.close(); | |
| 24 } else { | |
| 25 pong.send(msg); | |
| 26 } | |
| 27 }); | |
| 28 } | |
| 29 | |
| 30 void runTests(SendPort ping, Queue checks) { | |
| 31 ping.send("abc"); | |
| 32 checks.add((x) => Expect.equals("abc", x)); | |
| 33 | |
| 34 ping.send(int.parse); | |
| 35 checks.add((x) => Expect.identical(int.parse, x)); | |
| 36 | |
| 37 ping.send(identityHashCode); | |
| 38 checks.add((x) => Expect.identical(identityHashCode, x)); | |
| 39 | |
| 40 ping.send(identical); | |
| 41 checks.add((x) => Expect.identical(identical, x)); | |
| 42 } | |
| 43 | |
| 44 void main() async { | |
| 45 asyncStart(); | |
| 46 Queue checks = new Queue(); | |
| 47 ReceivePort testPort = new ReceivePort(); | |
| 48 Completer completer = new Completer(); | |
| 49 | |
| 50 testPort.listen((msg) { | |
| 51 Function check = checks.removeFirst(); | |
| 52 check(msg); | |
| 53 if (checks.isEmpty) { | |
| 54 completer.complete(); | |
| 55 testPort.close(); | |
| 56 } | |
| 57 }); | |
| 58 | |
| 59 ReceivePort initialReplyPort = new ReceivePort(); | |
| 60 | |
| 61 Isolate i = await Isolate | |
| 62 .spawn(echoMain, [initialReplyPort.sendPort, testPort.sendPort]); | |
| 63 SendPort ping = await initialReplyPort.first; | |
| 64 runTests(ping, checks); | |
| 65 Expect.isTrue(checks.length > 0); | |
| 66 await completer.future; | |
| 67 ping.send("halt"); | |
| 68 asyncEnd(); | |
| 69 } | |
| OLD | NEW |