OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014, 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 import 'dart:async'; | |
6 import 'dart:convert'; | |
7 import 'dart:io'; | |
8 import 'dart:mirrors'; | |
9 | |
10 import 'package:expect/expect.dart'; | |
11 import 'package:async_helper/async_helper.dart'; | |
12 | |
13 Map lookupServiceObject(String path) { | |
14 var io = currentMirrorSystem().findLibrary(const Symbol('dart.io')); | |
15 var m = MirrorSystem.getSymbol('_serviceObjectHandler', io); | |
16 var paths = Uri.parse(path).pathSegments; | |
17 Expect.equals('io', paths.first); | |
18 return JSON.decode( | |
19 io.invoke(m, [paths.sublist(1), [], []]).reflectee); | |
20 } | |
21 | |
22 | |
23 String getServicePath(obj) { | |
24 var io = currentMirrorSystem().findLibrary(const Symbol('dart.io')); | |
25 var m = MirrorSystem.getSymbol('_getServicePath', io); | |
26 return io.invoke(m, [obj]).reflectee; | |
27 } | |
28 | |
29 | |
30 Future testHttpServer1() { | |
31 return HttpServer.bind('localhost', 0).then((server) { | |
32 var path = getServicePath(server); | |
33 var map = lookupServiceObject(path); | |
34 Expect.equals(map['type'], 'HttpServer'); | |
35 Expect.equals(map['id'], path); | |
36 Expect.equals(map['address'], 'localhost'); | |
37 Expect.equals(map['port'], server.port); | |
38 Expect.equals(map['closed'], false); | |
39 Expect.equals(map['idle'], 0); | |
40 Expect.equals(map['active'], 0); | |
41 var socket = map['socket']; | |
42 Expect.equals(socket['type'], '@Socket'); | |
43 Expect.equals(socket['kind'], 'Listening'); | |
44 // Validate owner back-ref. | |
45 socket = lookupServiceObject(socket['id']); | |
46 Expect.equals(socket['owner']['id'], path); | |
47 return server.close(); | |
48 }); | |
49 } | |
50 | |
51 | |
52 void main() { | |
53 final tests = [ | |
54 testHttpServer1(), | |
55 ]; | |
56 | |
57 asyncStart(); | |
58 // Run one test at a time. | |
59 Future.forEach(tests, (f) => f) | |
60 .then((_) { | |
61 asyncEnd(); | |
62 }); | |
63 } | |
OLD | NEW |